package com.doumee.service.system.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.utils.Constants; import com.doumee.dao.system.SystemDictMapper; import com.doumee.dao.system.dto.PlatformConfigDTO; import com.doumee.dao.system.model.SystemDict; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.dao.system.SystemDictDataMapper; import com.doumee.dao.system.dto.QuerySystemDictDataDTO; import com.doumee.dao.system.model.SystemDictData; import com.doumee.dao.system.vo.SystemDictDataListVO; import com.doumee.service.system.SystemDictDataService; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** * 字典数据Service实现 * @author Eva.Caesar Liu * @date 2023/03/21 14:49 */ @Service public class SystemDictDataServiceImpl implements SystemDictDataService { @Autowired private SystemDictDataMapper systemDictDataMapper; @Autowired private SystemDictMapper systemDictMapper; @Override public Integer create(SystemDictData systemDictData) { systemDictDataMapper.insert(systemDictData); return systemDictData.getId(); } @Override public void deleteById(Integer id) { SystemDictData systemDictData = new SystemDictData(); systemDictData.setId(id); systemDictData.setDeleted(Boolean.TRUE); this.updateById(systemDictData); } @Override @Transactional public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } for (Integer id : ids) { this.deleteById(id); } } @Override public void updateById(SystemDictData systemDictData) { systemDictDataMapper.updateById(systemDictData); } @Override @Transactional public void updateByIdInBatch(List systemDictDatas) { if (CollectionUtils.isEmpty(systemDictDatas)) { return; } for (SystemDictData systemDictData: systemDictDatas) { this.updateById(systemDictData); } } @Override public SystemDictData findById(Integer id) { return systemDictDataMapper.selectById(id); } @Override public SystemDictData findOne(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectOne(wrapper); } @Override public List findList(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); return PageData.from(new PageInfo<>(systemDictDataMapper.selectManageList(pageWrap.getModel()))); } @Override public long count(SystemDictData systemDictData) { Wrapper wrapper = new QueryWrapper<>(systemDictData); return systemDictDataMapper.selectCount(wrapper); } @Override public List findList(Integer dicId,List codes) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(Objects.nonNull(dicId),SystemDictData::getDictId,dicId) .in(SystemDictData::getLabel,codes); return systemDictDataMapper.selectList(wrapper); } @Override public PlatformConfigDTO getPlatformConfigDTO(){ PlatformConfigDTO platformConfigDTO = new PlatformConfigDTO(); platformConfigDTO.setRegIntegralReward(new BigDecimal(0)); platformConfigDTO.setRegCouponRewardStatus(0); platformConfigDTO.setRegCouponRewardList(new ArrayList<>()); platformConfigDTO.setRegIntegralRewardStatus(0); platformConfigDTO.setShareIntegralReward(new BigDecimal(0)); platformConfigDTO.setShareCouponRewardList(new ArrayList<>()); platformConfigDTO.setShareIntegralRewardStatus(0); platformConfigDTO.setShareCouponRewardStatus(0); platformConfigDTO.setReturnMemberIntegral(new BigDecimal(0)); platformConfigDTO.setReturnShopIntegral(new BigDecimal(0)); platformConfigDTO.setReturnMemberIntegralStatus(0); platformConfigDTO.setReturnShopIntegralStatus(0); platformConfigDTO.setMinIntegralPriceLimit(new BigDecimal(0)); platformConfigDTO.setDeductIntegralLimit(0); platformConfigDTO.setIntegralRuleInfo(""); platformConfigDTO.setIntegralInvalidType(0); platformConfigDTO.setIntegralInvalidCircle(0); platformConfigDTO.setTotalRate(new BigDecimal(0)); /* SystemDict dict = systemDictMapper.selectOne(new QueryWrapper().lambda() .eq(SystemDict::getCode,Constants.ORDER_SET).last("limit 1")); if(dict == null){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"数据字典配置数据有误,请联系系统管理员处理!"); } */ List systemDictDataList = systemDictDataMapper.selectJoinList(SystemDictData.class,new MPJLambdaWrapper() .selectAll(SystemDictData.class) .leftJoin(SystemDict.class,SystemDict::getId,SystemDictData::getDictId) .in(SystemDict::getCode,Constants.ORDER_SET,Constants.INTEGRAL_SET) ); if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictDataList)){ for (SystemDictData systemDictData:systemDictDataList) { if(systemDictData.getLabel().equals(Constants.ORDERSET_REG_INTEGRAL_REWARD)){ platformConfigDTO.setRegIntegralReward(getDecimalValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_REG_COUPON_REWARD_STATUS)){ platformConfigDTO.setRegCouponRewardStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_REG_COUPON_REWARD_LIST)){ platformConfigDTO.setRegCouponRewardList(getListValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_REG_INTEGRAL_REWARD_STATUS)){ platformConfigDTO.setRegIntegralRewardStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_INTEGRAL_REWARD)){ platformConfigDTO.setShareIntegralReward(getDecimalValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_COUPON_REWARD_LIST)){ platformConfigDTO.setShareCouponRewardList(getListValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_INTEGRAL_REWARD_STATUS)){ platformConfigDTO.setShareIntegralRewardStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_COUPON_REWARD_STATUS)){ platformConfigDTO.setShareCouponRewardStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_MEMBER_INTEGRAL)){ platformConfigDTO.setReturnMemberIntegral(getDecimalValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_SHOP_INTEGRAL)){ platformConfigDTO.setReturnShopIntegral(getDecimalValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_MEMBER_INTEGRAL_STATUS)){ platformConfigDTO.setReturnMemberIntegralStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_SHOP_INTEGRAL_STATUS)){ platformConfigDTO.setReturnShopIntegralStatus(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.ORDERSET_TOTAL_RATE)) { platformConfigDTO.setTotalRate(getDecimalValByStr(systemDictData.getCode())); } else if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALINVALIDTYPE)) { platformConfigDTO.setIntegralInvalidType(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALINVALIDCIRCLE)) { platformConfigDTO.setIntegralInvalidCircle(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALRULEINFO)) { platformConfigDTO.setIntegralRuleInfo(systemDictData.getCode()); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_DEDUCTINTEGRALLIMIT)) { platformConfigDTO.setDeductIntegralLimit(getIntegerValByStr(systemDictData.getCode())); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_MININTEGRALPRICELIMIT)) { platformConfigDTO.setMinIntegralPriceLimit(getDecimalValByStr(systemDictData.getCode())); } } } return platformConfigDTO; } private Integer getIntegerValByStr(String code) { try { return Integer.parseInt(code); }catch (Exception e){ } return 0; } private BigDecimal getDecimalValByStr(String code) { try { return new BigDecimal(code); }catch (Exception e){ } return new BigDecimal(0); } private List getListValByStr(String code) { try { return JSONObject.parseObject(code,new TypeReference>(){}); }catch (Exception e){ } return new ArrayList(); } @Override @Transactional(rollbackFor = {Exception.class, BusinessException.class}) public void updPlatformConfig(PlatformConfigDTO platformConfigDTO) { if (platformConfigDTO.getDictCode() == null) { throw new BusinessException(ResponseStatus.BAD_REQUEST); } List systemDictDataList = systemDictDataMapper.selectJoinList(SystemDictData.class,new MPJLambdaWrapper() .selectAll(SystemDictData.class) .leftJoin(SystemDict.class,SystemDict::getId,SystemDictData::getDictId) .eq(SystemDict::getCode,platformConfigDTO.getDictCode()) ); if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(systemDictDataList)) { for (SystemDictData systemDictData : systemDictDataList) { if(StringUtils.equals(platformConfigDTO.getDictCode(),Constants.ORDER_SET)){ if (systemDictData.getLabel().equals(Constants.ORDERSET_REG_INTEGRAL_REWARD_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getRegIntegralRewardStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_INTEGRAL_REWARD_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getShareIntegralRewardStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_REG_COUPON_REWARD_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getRegCouponRewardStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_COUPON_REWARD_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getShareCouponRewardStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_REG_INTEGRAL_REWARD)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getRegIntegralReward()).doubleValue() + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_INTEGRAL_REWARD)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getShareIntegralReward()).doubleValue() + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_REG_COUPON_REWARD_LIST)) { systemDictData.setCode(JSONObject.toJSONString(platformConfigDTO.getRegCouponRewardList() == null ? new ArrayList() : platformConfigDTO.getRegCouponRewardList())); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_SHARE_COUPON_REWARD_LIST)) { systemDictData.setCode(JSONObject.toJSONString(platformConfigDTO.getShareCouponRewardList() == null ? new ArrayList() : platformConfigDTO.getShareCouponRewardList())); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_MEMBER_INTEGRAL_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getReturnMemberIntegralStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_SHOP_INTEGRAL_STATUS)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getReturnShopIntegralStatus()) + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_MEMBER_INTEGRAL)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getReturnMemberIntegral()).doubleValue() + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_RETURN_SHOP_INTEGRAL)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getReturnShopIntegral()).doubleValue() + ""); } else if (systemDictData.getLabel().equals(Constants.ORDERSET_TOTAL_RATE)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getTotalRate()).doubleValue() + ""); } } if(StringUtils.equals(platformConfigDTO.getDictCode(),Constants.INTEGRAL_SET)){ if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALINVALIDTYPE)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getIntegralInvalidType()) + ""); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALINVALIDCIRCLE)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getIntegralInvalidCircle()) + ""); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_INTEGRALRULEINFO)) { systemDictData.setCode(platformConfigDTO.getIntegralRuleInfo()); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_DEDUCTINTEGRALLIMIT)) { systemDictData.setCode(Constants.formatIntegerNum(platformConfigDTO.getDeductIntegralLimit()) + ""); }else if(systemDictData.getLabel().equals(Constants.INTERALSET_MININTEGRALPRICELIMIT)) { systemDictData.setCode(Constants.formatBigdecimal(platformConfigDTO.getMinIntegralPriceLimit()).doubleValue() + ""); } } systemDictDataMapper.update(new UpdateWrapper().lambda() .set(SystemDictData::getCode, systemDictData.getCode()) .eq(SystemDictData::getId, systemDictData.getId())); } } } }