jiangqs
2023-06-18 c00d0d3bc399b6648145dfd955cedbea90f5f99d
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java
@@ -1,15 +1,33 @@
package com.ruoyi.system.service.impl.config;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.api.constant.ConfigEnum;
import com.ruoyi.system.domain.dto.MgtServiceMobileEditDto;
import com.ruoyi.system.api.domain.poji.config.Activeness;
import com.ruoyi.system.api.domain.vo.MgtBulletinBoardVo;
import com.ruoyi.system.api.service.RemoteActivityService;
import com.ruoyi.system.api.service.RemoteMemberService;
import com.ruoyi.system.api.service.RemoteOrderService;
import com.ruoyi.system.api.service.RemoteShopService;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.pojo.config.Advert;
import com.ruoyi.system.domain.pojo.config.CustomConfig;
import com.ruoyi.system.domain.vo.MgtActivenessVo;
import com.ruoyi.system.domain.vo.MgtAllCustomConfigVo;
import com.ruoyi.system.domain.vo.MgtCustomConfigVo;
import com.ruoyi.system.domain.vo.MgtOperLogPageVo;
import com.ruoyi.system.mapper.config.CustomConfigMapper;
import com.ruoyi.system.service.config.ActivenessService;
import com.ruoyi.system.service.config.AdvertService;
import com.ruoyi.system.service.config.CustomConfigService;
import com.ruoyi.system.service.config.RecommendCooperationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * <p>
@@ -25,25 +43,45 @@
    @Resource
    private CustomConfigMapper customConfigMapper;
    @Resource
    private AdvertService advertService;
    @Resource
    private ActivenessService activenessService;
    @Resource
    private RemoteMemberService remoteMemberService;
    @Resource
    private RecommendCooperationService recommendCooperationService;
    @Resource
    private RemoteShopService remoteShopService;
    @Resource
    private RemoteOrderService remoteOrderService;
    @Resource
    private RemoteActivityService remoteActivityService;
    /**
     * @description  通过key获取系统自定义配置
     * @author  jqs
     * @date    2023/6/6 11:55
     * @param key
     * @return  CustomConfig
     * @return CustomConfig
     * @description 通过key获取系统自定义配置
     * @author jqs
     * @date 2023/6/6 11:55
     */
    @Override
    public CustomConfig getByKey(String key){
    public CustomConfig getByKey(String key) {
        return customConfigMapper.getByKey(key);
    }
    /**
     * @description  修改客服号码
     * @author  jqs
     * @date    2023/6/6 11:53
     * @param mgtServiceMobileEditDto
     * @return  void
     * @return void
     * @description 修改客服号码
     * @author jqs
     * @date 2023/6/6 11:53
     */
    @Override
    public void editServiceMobile(MgtServiceMobileEditDto mgtServiceMobileEditDto) {
@@ -53,14 +91,446 @@
        if (customConfig == null) {
            customConfig = new CustomConfig();
            customConfig.setCreateTime(new Date());
            customConfig.setDelFlag(0);
        }
        // 设置配置的类型、键、名称、值和更新时间
        customConfig.setType(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyType());
        customConfig.setKey(ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
        customConfig.setName(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyName());
        customConfig.setValue(mgtServiceMobileEditDto.getServiceMobile());
        customConfig.setConfigType(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyType());
        customConfig.setConfigKey(ConfigEnum.PLATFORM_SERVICE_PHONE.getKey());
        customConfig.setConfigName(ConfigEnum.PLATFORM_SERVICE_PHONE.getKeyName());
        customConfig.setConfigValue(mgtServiceMobileEditDto.getServiceMobile());
        customConfig.setUpdateTime(new Date());
        // 保存或更新配置
        this.saveOrUpdate(customConfig);
    }
    /**
     * @param
     * @return MgtCustomConfigVo
     * @description 平台获取自定义配置
     * @author jqs
     * @date 2023/6/7 15:02
     */
    @Override
    public MgtAllCustomConfigVo getAllCustomConfig() {
        MgtAllCustomConfigVo mgtAllCustomConfigVo = new MgtAllCustomConfigVo();
        //获取自定义配置
        List<CustomConfig> customConfigList = customConfigMapper.selectList(new LambdaQueryWrapper<CustomConfig>().eq(CustomConfig::getDelFlag, 0));
        Optional.ofNullable(customConfigList).ifPresent(list -> {
            Map<String, CustomConfig> configMap = list.stream().collect(Collectors.toMap(CustomConfig::getConfigKey, Function.identity()));
            // 遍历配置映射,设置相应的属性值
            configMap.forEach((key, value) -> {
                switch (key) {
                    case "SHARE_INTEGRAL":
                        mgtAllCustomConfigVo.setShareIntegral(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "SUGGEST_PLATFORM_INTEGRAL":
                        mgtAllCustomConfigVo.setSuggestPlatformIntegral(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "SIGN_IN_INTEGRAL":
                        mgtAllCustomConfigVo.setSignInIntegral(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "SUGGEST_SHOP_INTEGRAL":
                        mgtAllCustomConfigVo.setSuggestShopIntegral(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "PAY_MONEY_INTEGRAL":
                        mgtAllCustomConfigVo.setPayMoneyIntegral(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "ORDER_AUTO_CANCEL_TIME":
                        mgtAllCustomConfigVo.setOrderAutoCancelTime(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "HOME_STYLE":
                        mgtAllCustomConfigVo.setHomeStyle(Integer.valueOf(value.getConfigValue()));
                        break;
                    case "SHOP_EMERGENCY_DEGREE":
                        mgtAllCustomConfigVo.setShopEmergencyDegree(value.getConfigValue());
                        break;
                    case "SHOP_FOLLOW_TYPE":
                        mgtAllCustomConfigVo.setShopFollowType(value.getConfigValue());
                        break;
                    case "SHOP_CUSTOM_STATUS":
                        mgtAllCustomConfigVo.setShopCustomStatus(value.getConfigValue());
                        break;
                    case "SHOP_SOURCE_CHANNEL":
                        mgtAllCustomConfigVo.setShopSourceChannel(value.getConfigValue());
                        break;
                    case "MEMBER_SOURCE_CHANNEL":
                        mgtAllCustomConfigVo.setMemberSourceChannel(value.getConfigValue());
                        break;
                    case "MEMBER_CHARACTER":
                        mgtAllCustomConfigVo.setMemberCharacter(value.getConfigValue());
                        break;
                    case "MEMBER_LEVEL":
                        mgtAllCustomConfigVo.setMemberLevel(value.getConfigValue());
                        break;
                    case "MEMBER_TYPE":
                        mgtAllCustomConfigVo.setMemberType(value.getConfigValue());
                        break;
                    case "NURSE_PROBLEM":
                        mgtAllCustomConfigVo.setNurseProblem(value.getConfigValue());
                        break;
                    default:
                        break;
                }
            });
        });
        //获取广告配置
        Advert advert = advertService.getAdvert();
        if (advert != null) {
            mgtAllCustomConfigVo.setHomeSlogan(advert.getAdContent());
            mgtAllCustomConfigVo.setHomeLogo(advert.getLogoUrl());
            mgtAllCustomConfigVo.setAdUrl(advert.getAdUrl());
            mgtAllCustomConfigVo.setTargetType(advert.getTargetType());
            mgtAllCustomConfigVo.setLinkUrl(advert.getLinkUrl());
            mgtAllCustomConfigVo.setJumpType(advert.getJumpType());
            mgtAllCustomConfigVo.setJumpId(advert.getJumpId());
        }
        //获取活跃度配置
        List<Activeness> activenessList = activenessService.listActiveness();
        if (activenessList != null && !activenessList.isEmpty()) {
            List<MgtActivenessVo> mgtActivenessVoList = activenessList.stream()
                    .map(activeness -> {
                        MgtActivenessVo mgtActivenessVo = new MgtActivenessVo();
                        mgtActivenessVo.setActivenessId(activeness.getActivenessId());
                        mgtActivenessVo.setActivenessName(activeness.getActivenessName());
                        mgtActivenessVo.setStartDay(activeness.getStartDay());
                        mgtActivenessVo.setEndDay(activeness.getEndDay());
                        return mgtActivenessVo;
                    })
                    .collect(Collectors.toList());
            mgtAllCustomConfigVo.setMgtActivenessVoList(mgtActivenessVoList);
        }
        return mgtAllCustomConfigVo;
    }
    /**
     * @param mgtOtherConfigEditDto
     * @return void
     * @description 修改其他设置
     * @author jqs
     * @date 2023/6/7 16:07
     */
    @Override
    public void editOtherConfig(MgtOtherConfigEditDto mgtOtherConfigEditDto) {
        // 获取当前时间
        Date updateTime = new Date();
        // 删除历史配置
        deletePastConfig(updateTime);
        // 新建配置
        createNewConfig(mgtOtherConfigEditDto, updateTime);
    }
    /**
     * @param updateTime
     * @return void
     * @description 删除历史配置
     * @author jqs
     * @date 2023/6/7 16:37
     */
    private void deletePastConfig(Date updateTime) {
        List<CustomConfig> customConfigList = customConfigMapper.selectList(new LambdaQueryWrapper<CustomConfig>()
                .eq(CustomConfig::getDelFlag, 0)
                .eq(CustomConfig::getConfigType, 2));
        for (CustomConfig customConfig : customConfigList) {
            customConfig.setDelFlag(1);
            customConfig.setUpdateTime(updateTime);
        }
        this.saveOrUpdateBatch(customConfigList);
    }
    /**
     * @param mgtOtherConfigEditDto
     * @param updateTime
     * @return void
     * @description 新建配置
     * @author jqs
     * @date 2023/6/7 16:37
     */
    private void createNewConfig(MgtOtherConfigEditDto mgtOtherConfigEditDto, Date updateTime) {
        for (ConfigEnum configEnum : ConfigEnum.values()) {
            CustomConfig customConfig = new CustomConfig();
            customConfig.setDelFlag(0);
            customConfig.setConfigType(configEnum.getKeyType());
            customConfig.setConfigKey(configEnum.getKey());
            customConfig.setConfigName(configEnum.getKeyName());
            customConfig.setCreateTime(updateTime);
            customConfig.setUpdateTime(updateTime);
            switch (configEnum) {
                case SHARE_INTEGRAL:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getShareIntegral().toString());
                    this.saveOrUpdate(customConfig);
                case SUGGEST_PLATFORM_INTEGRAL:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getSuggestPlatformIntegral().toString());
                    this.saveOrUpdate(customConfig);
                case SIGN_IN_INTEGRAL:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getSignInIntegral().toString());
                    this.saveOrUpdate(customConfig);
                case SUGGEST_SHOP_INTEGRAL:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getSuggestShopIntegral().toString());
                    this.saveOrUpdate(customConfig);
                case ORDER_AUTO_CANCEL_TIME:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getOrderAutoCancelTime().toString());
                    this.saveOrUpdate(customConfig);
                case PAY_MONEY_INTEGRAL:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getPayMoneyIntegral().toString());
                    this.saveOrUpdate(customConfig);
                case HOME_STYLE:
                    customConfig.setConfigValue(mgtOtherConfigEditDto.getHomeStyle().toString());
                    this.saveOrUpdate(customConfig);
                default:
                    break;
            }
        }
    }
    /**
     * @param mgtShopConfigEditDto
     * @return void
     * @description 修改合作商配置
     * @author jqs
     * @date 2023/6/7 16:41
     */
    @Override
    public void editShopConfig(MgtShopConfigEditDto mgtShopConfigEditDto) {
        // 获取当前时间
        Date updateTime = new Date();
        // 查询所有未删除、类型为3的自定义配置
        List<CustomConfig> customConfigList = customConfigMapper.selectList(
                new LambdaQueryWrapper<CustomConfig>()
                        .eq(CustomConfig::getDelFlag, 0)
                        .eq(CustomConfig::getConfigType, 3)
        );
        if (customConfigList != null && !customConfigList.isEmpty()) {
            String key;
            String oldValue;
            String newValue = null;
            List<CustomConfig> updatedCustomConfigs = new ArrayList<>();
            // 遍历配置列表,根据 key 更新配置值
            for (CustomConfig customConfig : customConfigList) {
                key = customConfig.getConfigKey();
                oldValue = customConfig.getConfigValue();
                switch (key) {
                    case "SHOP_EMERGENCY_DEGREE":
                        newValue = mgtShopConfigEditDto.getShopEmergencyDegree();
                        break;
                    case "SHOP_FOLLOW_TYPE":
                        newValue = mgtShopConfigEditDto.getShopFollowType();
                        break;
                    case "SHOP_CUSTOM_STATUS":
                        newValue = mgtShopConfigEditDto.getShopCustomStatus();
                        break;
                    case "SHOP_SOURCE_CHANNEL":
                        newValue = mgtShopConfigEditDto.getShopSourceChannel();
                        break;
                    default:
                        break;
                }
                customConfig.setConfigValue(newValue);
                customConfig.setUpdateTime(updateTime);
                handleChangeConfig(oldValue, newValue, key);
                updatedCustomConfigs.add(customConfig);
            }
            this.saveOrUpdateBatch(updatedCustomConfigs);
        } else {
            // 如果没有配置,则创建新配置
            createNewConfig(ConfigEnum.SHOP_EMERGENCY_DEGREE, mgtShopConfigEditDto.getShopEmergencyDegree(), updateTime);
            createNewConfig(ConfigEnum.SHOP_FOLLOW_TYPE, mgtShopConfigEditDto.getShopFollowType(), updateTime);
            createNewConfig(ConfigEnum.SHOP_CUSTOM_STATUS, mgtShopConfigEditDto.getShopCustomStatus(), updateTime);
            createNewConfig(ConfigEnum.SHOP_SOURCE_CHANNEL, mgtShopConfigEditDto.getShopSourceChannel(), updateTime);
        }
    }
    /**
     * @description  修改会员配置
     * @author  jqs
     * @date    2023/6/7 17:16
     * @param mgtMemberConfigEditDto
     * @return  void
     */
    @Override
    public void editMemberConfig(MgtMemberConfigEditDto mgtMemberConfigEditDto){
        // 获取当前时间
        Date updateTime = new Date();
        // 查询所有未删除、类型为3的自定义配置
        List<CustomConfig> customConfigList = customConfigMapper.selectList(
                new LambdaQueryWrapper<CustomConfig>()
                        .eq(CustomConfig::getDelFlag, 0)
                        .eq(CustomConfig::getConfigType, 4)
        );
        if (customConfigList != null && !customConfigList.isEmpty()) {
            String key;
            String oldValue;
            String newValue = null;
            List<CustomConfig> updatedCustomConfigs = new ArrayList<>();
            // 遍历配置列表,根据 key 更新配置值
            for (CustomConfig customConfig : customConfigList) {
                key = customConfig.getConfigKey();
                oldValue = customConfig.getConfigValue();
                switch (key) {
                    case "MEMBER_SOURCE_CHANNEL":
                        newValue = mgtMemberConfigEditDto.getMemberSourceChannel();
                        break;
                    case "MEMBER_CHARACTER":
                        newValue = mgtMemberConfigEditDto.getMemberCharacter();
                        break;
                    case "MEMBER_LEVEL":
                        newValue = mgtMemberConfigEditDto.getMemberLevel();
                        break;
                    case "MEMBER_TYPE":
                        newValue = mgtMemberConfigEditDto.getMemberType();
                        break;
                    case "NURSE_PROBLEM":
                        newValue = mgtMemberConfigEditDto.getNurseProblem();
                        break;
                    default:
                        break;
                }
                customConfig.setConfigValue(newValue);
                customConfig.setUpdateTime(updateTime);
                handleChangeConfig(oldValue, newValue, key);
                updatedCustomConfigs.add(customConfig);
            }
            this.saveOrUpdateBatch(updatedCustomConfigs);
        } else {
            // 如果没有配置,则创建新配置
            createNewConfig(ConfigEnum.MEMBER_SOURCE_CHANNEL, mgtMemberConfigEditDto.getMemberSourceChannel(), updateTime);
            createNewConfig(ConfigEnum.MEMBER_CHARACTER, mgtMemberConfigEditDto.getMemberCharacter(), updateTime);
            createNewConfig(ConfigEnum.MEMBER_LEVEL, mgtMemberConfigEditDto.getMemberLevel(), updateTime);
            createNewConfig(ConfigEnum.MEMBER_TYPE, mgtMemberConfigEditDto.getMemberType(), updateTime);
            createNewConfig(ConfigEnum.NURSE_PROBLEM, mgtMemberConfigEditDto.getNurseProblem(), updateTime);
        }
    }
    /**
     * @description  新建配置
     * @author  jqs
     * @date    2023/6/7 17:06
     * @param configEnum
     * @param value
     * @param updateTime
     * @return  void
     */
    private void createNewConfig(ConfigEnum configEnum, String value, Date updateTime) {
        CustomConfig customConfig = new CustomConfig();
        customConfig.setDelFlag(0);
        customConfig.setConfigType(configEnum.getKeyType());
        customConfig.setConfigKey(configEnum.getKey());
        customConfig.setConfigName(configEnum.getKeyName());
        customConfig.setConfigValue(value);
        customConfig.setCreateTime(updateTime);
        customConfig.setUpdateTime(updateTime);
        this.saveOrUpdate(customConfig);
    }
    /**
     * @description  处理变动
     * @author  jqs
     * @date    2023/6/7 17:06
     * @param oldValue
     * @param newValue
     * @param key
     * @return  void
     */
    private void handleChangeConfig(String oldValue, String newValue, String key) {
        Set<String> oldSet = new HashSet<>(Arrays.asList(oldValue.split(",")));
        Set<String> newSet = new HashSet<>(Arrays.asList(newValue.split(",")));
        List<String> changeList = new ArrayList<>(oldSet);
        changeList.removeAll(newSet);
        if(changeList!=null&&!changeList.isEmpty()){
            switch(key){
                case "SHOP_EMERGENCY_DEGREE":
                    break;
                case "SHOP_FOLLOW_TYPE":
                    break;
                case "SHOP_CUSTOM_STATUS":
                    break;
                case "SHOP_SOURCE_CHANNEL":
                    break;
                case "MEMBER_SOURCE_CHANNEL":
                    break;
                case "MEMBER_CHARACTER":
                    break;
                case "MEMBER_LEVEL":
                    break;
                case "MEMBER_TYPE":
                    break;
                case "NURSE_PROBLEM":
                    break;
                default:
                    break;
            }
        }
    }
    /**
     * @description  分页获取操作日志
     * @author  jqs
     * @date    2023/6/8 11:52
     * @param page
     * @param mgtOperLogPageDto
     * @return  List<MgtOperLogPageVo>
     */
    @Override
    public List<MgtOperLogPageVo> pageOperLog(Page page, MgtOperLogPageDto mgtOperLogPageDto){
        return customConfigMapper.pageOperLog(page, mgtOperLogPageDto);
    }
    /**
     * @description  获取单个自定义配置
     * @author  jqs
     * @date    2023/6/9 15:40
     * @param mgtCustomConfigDto
     * @return  MgtCustomConfigVo
     */
    @Override
    public MgtCustomConfigVo getCustomConfig(MgtCustomConfigDto mgtCustomConfigDto){
        CustomConfig customConfig = this.getByKey(mgtCustomConfigDto.getConfigType());
        MgtCustomConfigVo mgtCustomConfigVo = new MgtCustomConfigVo();
        if(customConfig!=null){
            mgtCustomConfigVo.setCustomConfig(customConfig.getConfigValue());
            mgtCustomConfigVo.setConfigType(mgtCustomConfigDto.getConfigType());
        }
        return mgtCustomConfigVo;
    }
    /**
     * @description getBulletinBoard
     * @param
     * @return MgtBulletinBoardVo
     * @author jqs34
     * @date 2023/6/18 16:41
     */
    @Override
    public MgtBulletinBoardVo getBulletinBoard(){
        // 创建 MgtBulletinBoardVo 对象
        MgtBulletinBoardVo mgtBulletinBoardVo = new MgtBulletinBoardVo();
        // 获取会员信息
        MgtBulletinBoardVo mgtBulletinBoardVoMember = remoteMemberService.boardMemberTotal().getData();
        mgtBulletinBoardVo.setMemberTotal(mgtBulletinBoardVoMember.getMemberTotal());
        mgtBulletinBoardVo.setMemberToday(mgtBulletinBoardVoMember.getMemberToday());
        // 获取推荐合作信息
        MgtBulletinBoardVo mgtBulletinBoardVoCustom = recommendCooperationService.boardMemberTotal();
        mgtBulletinBoardVo.setCustomTotal(mgtBulletinBoardVoCustom.getCustomTotal());
        mgtBulletinBoardVo.setCustomToday(mgtBulletinBoardVoCustom.getCustomToday());
        // 获取店铺信息
        MgtBulletinBoardVo mgtBulletinBoardVoShop = remoteShopService.boardShopTotal().getData();
        mgtBulletinBoardVo.setShopTotal(mgtBulletinBoardVoShop.getShopTotal());
        mgtBulletinBoardVo.setAgencyTotal(mgtBulletinBoardVoShop.getAgencyTotal());
        mgtBulletinBoardVo.setDealerTotal(mgtBulletinBoardVoShop.getDealerTotal());
        mgtBulletinBoardVo.setFollowShopToday(mgtBulletinBoardVoShop.getFollowShopToday());
        mgtBulletinBoardVo.setFollowUserToday(0);
        // 获取订单信息
        MgtBulletinBoardVo mgtBulletinBoardVoOrder = remoteOrderService.boardOrderTotal().getData();
        mgtBulletinBoardVo.setSalesTotal(mgtBulletinBoardVoOrder.getSalesTotal());
        mgtBulletinBoardVo.setUnUseOrderTotal(mgtBulletinBoardVoOrder.getUnUseOrderTotal());
        mgtBulletinBoardVo.setActivityOrderTotal(mgtBulletinBoardVoOrder.getActivityOrderTotal());
        // 获取活动信息
        MgtBulletinBoardVo mgtBulletinBoardVoActivity = remoteActivityService.boardActivityTotal().getData();
        mgtBulletinBoardVo.setActivityUserTotal(mgtBulletinBoardVoActivity.getActivityUserTotal());
        // 返回 MgtBulletinBoardVo 对象
        return mgtBulletinBoardVo;
    }
}