From 1fc05375474ca0393d6c29fd2ab1d182c65a3eaa Mon Sep 17 00:00:00 2001 From: jiangqs <jiangqs> Date: 星期三, 07 六月 2023 17:20:18 +0800 Subject: [PATCH] 基础配置 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java | 407 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 396 insertions(+), 11 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java index 4c4c2f8..30c6560 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/config/CustomConfigServiceImpl.java @@ -1,15 +1,27 @@ package com.ruoyi.system.service.impl.config; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.system.api.constant.ConfigEnum; +import com.ruoyi.system.api.domain.poji.config.Activeness; +import com.ruoyi.system.domain.dto.MgtMemberConfigEditDto; +import com.ruoyi.system.domain.dto.MgtOtherConfigEditDto; import com.ruoyi.system.domain.dto.MgtServiceMobileEditDto; +import com.ruoyi.system.domain.dto.MgtShopConfigEditDto; +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.MgtCustomConfigVo; 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 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 +37,31 @@ @Resource private CustomConfigMapper customConfigMapper; + @Resource + private AdvertService advertService; + + @Resource + private ActivenessService activenessService; + + /** - * @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) { @@ -63,4 +81,371 @@ // 保存或更新配置 this.saveOrUpdate(customConfig); } + + /** + * @param + * @return MgtCustomConfigVo + * @description 平台获取自定义配置 + * @author jqs + * @date 2023/6/7 15:02 + */ + @Override + public MgtCustomConfigVo getCustomConfig() { + MgtCustomConfigVo mgtCustomConfigVo = new MgtCustomConfigVo(); + //获取自定义配置 + 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::getKey, Function.identity())); + // 遍历配置映射,设置相应的属性值 + configMap.forEach((key, value) -> { + switch (key) { + case "SHARE_INTEGRAL": + mgtCustomConfigVo.setShareIntegral(Integer.valueOf(value.getValue())); + break; + case "SUGGEST_PLATFORM_INTEGRAL": + mgtCustomConfigVo.setSuggestPlatformIntegral(Integer.valueOf(value.getValue())); + break; + case "SIGN_IN_INTEGRAL": + mgtCustomConfigVo.setSignInIntegral(Integer.valueOf(value.getValue())); + break; + case "SUGGEST_SHOP_INTEGRAL": + mgtCustomConfigVo.setSuggestShopIntegral(Integer.valueOf(value.getValue())); + break; + case "PAY_MONEY_INTEGRAL": + mgtCustomConfigVo.setPayMoneyIntegral(Integer.valueOf(value.getValue())); + break; + case "ORDER_AUTO_CANCEL_TIME": + mgtCustomConfigVo.setOrderAutoCancelTime(Integer.valueOf(value.getValue())); + break; + case "HOME_STYLE": + mgtCustomConfigVo.setHomeStyle(Integer.valueOf(value.getValue())); + break; + case "SHOP_EMERGENCY_DEGREE": + mgtCustomConfigVo.setShopEmergencyDegree(value.getValue()); + break; + case "SHOP_FOLLOW_TYPE": + mgtCustomConfigVo.setShopFollowType(value.getValue()); + break; + case "SHOP_CUSTOM_STATUS": + mgtCustomConfigVo.setShopCustomStatus(value.getValue()); + break; + case "SHOP_SOURCE_CHANNEL": + mgtCustomConfigVo.setShopSourceChannel(value.getValue()); + break; + case "MEMBER_SOURCE_CHANNEL": + mgtCustomConfigVo.setMemberSourceChannel(value.getValue()); + break; + case "MEMBER_CHARACTER": + mgtCustomConfigVo.setMemberCharacter(value.getValue()); + break; + case "MEMBER_LEVEL": + mgtCustomConfigVo.setMemberLevel(value.getValue()); + break; + case "MEMBER_TYPE": + mgtCustomConfigVo.setMemberType(value.getValue()); + break; + case "NURSE_PROBLEM": + mgtCustomConfigVo.setNurseProblem(value.getValue()); + break; + default: + break; + } + }); + }); + //获取广告配置 + Advert advert = advertService.getAdvert(); + if (advert != null) { + mgtCustomConfigVo.setHomeSlogan(advert.getAdContent()); + mgtCustomConfigVo.setHomeLogo(advert.getLogoUrl()); + mgtCustomConfigVo.setAdUrl(advert.getAdUrl()); + mgtCustomConfigVo.setTargetType(advert.getTargetType()); + mgtCustomConfigVo.setLinkUrl(advert.getLinkUrl()); + mgtCustomConfigVo.setJumpType(advert.getJumpType()); + mgtCustomConfigVo.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()); + mgtCustomConfigVo.setMgtActivenessVoList(mgtActivenessVoList); + } + return mgtCustomConfigVo; + } + + + /** + * @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::getType, 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.setType(configEnum.getKeyType()); + customConfig.setKey(configEnum.getKey()); + customConfig.setName(configEnum.getKeyName()); + customConfig.setValue(getConfigValue(configEnum, mgtOtherConfigEditDto)); + customConfig.setCreateTime(updateTime); + customConfig.setUpdateTime(updateTime); + this.saveOrUpdate(customConfig); + } + } + + /** + * @param configEnum + * @param mgtOtherConfigEditDto + * @return String + * @description 获取配置参数 + * @author jqs + * @date 2023/6/7 16:37 + */ + private String getConfigValue(ConfigEnum configEnum, MgtOtherConfigEditDto mgtOtherConfigEditDto) { + switch (configEnum) { + case SHARE_INTEGRAL: + return mgtOtherConfigEditDto.getShareIntegral().toString(); + case SUGGEST_PLATFORM_INTEGRAL: + return mgtOtherConfigEditDto.getSuggestPlatformIntegral().toString(); + case SIGN_IN_INTEGRAL: + return mgtOtherConfigEditDto.getSignInIntegral().toString(); + case SUGGEST_SHOP_INTEGRAL: + return mgtOtherConfigEditDto.getSuggestShopIntegral().toString(); + case ORDER_AUTO_CANCEL_TIME: + return mgtOtherConfigEditDto.getOrderAutoCancelTime().toString(); + case PAY_MONEY_INTEGRAL: + return mgtOtherConfigEditDto.getPayMoneyIntegral().toString(); + case HOME_STYLE: + return mgtOtherConfigEditDto.getHomeStyle().toString(); + default: + throw new IllegalArgumentException("Invalid ConfigEnum"); + } + } + + /** + * @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::getType, 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.getKey(); + oldValue = customConfig.getValue(); + 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.setValue(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::getType, 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.getKey(); + oldValue = customConfig.getValue(); + 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.setValue(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.setType(configEnum.getKeyType()); + customConfig.setKey(configEnum.getKey()); + customConfig.setName(configEnum.getKeyName()); + customConfig.setValue(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; + } + } + } + + } -- Gitblit v1.7.1