| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.ruoyi.system.domain.pojo.CustomConfig; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.core.utils.page.BeanUtils; |
| | | import com.ruoyi.system.api.constants.ConfigEnum; |
| | | import com.ruoyi.system.api.domain.CustomConfig; |
| | | import com.ruoyi.system.domain.dto.MgtAfterSaleSettingDTO; |
| | | import com.ruoyi.system.domain.dto.PointsConfigDTO; |
| | | import com.ruoyi.system.domain.vo.CustomConfigVO; |
| | | import com.ruoyi.system.mapper.CustomConfigMapper; |
| | | import com.ruoyi.system.service.ICustomConfigService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class CustomConfigServiceImpl extends ServiceImpl<CustomConfigMapper, CustomConfig> implements ICustomConfigService { |
| | | |
| | | /** |
| | | * 保存积分设置 |
| | | * |
| | | * @param dto 积分配置数据传输对象 |
| | | */ |
| | | @Override |
| | | @Transactional(propagation = Propagation.REQUIRES_NEW) |
| | | public void savePointsSettings(PointsConfigDTO dto) { |
| | | Optional<CustomConfig> customConfigOptional = getCustomConfigByKey( |
| | | ConfigEnum.MEMBER_POINTS_MONEY.getKey()); |
| | | CustomConfig moneyConfig = customConfigOptional.orElseGet(() -> { |
| | | CustomConfig config = new CustomConfig(); |
| | | config.setConfigKey(ConfigEnum.MEMBER_POINTS_MONEY.getKey()); |
| | | config.setConfigType(ConfigEnum.MEMBER_POINTS_MONEY.getKeyType()); |
| | | config.setConfigName(ConfigEnum.MEMBER_POINTS_MONEY.getKeyName()); |
| | | return config; |
| | | }); |
| | | moneyConfig.setConfigValue(dto.getConsumeAmount().toString()); |
| | | Optional<CustomConfig> customConfigByKey = getCustomConfigByKey( |
| | | ConfigEnum.MEMBER_POINTS_POINTS.getKey()); |
| | | CustomConfig pointsConfig = customConfigByKey.orElseGet(() -> { |
| | | CustomConfig config = new CustomConfig(); |
| | | config.setConfigKey(ConfigEnum.MEMBER_POINTS_POINTS.getKey()); |
| | | config.setConfigType(ConfigEnum.MEMBER_POINTS_POINTS.getKeyType()); |
| | | config.setConfigName(ConfigEnum.MEMBER_POINTS_POINTS.getKeyName()); |
| | | return config; |
| | | }); |
| | | pointsConfig.setConfigValue(dto.getPoints().toString()); |
| | | this.saveOrUpdateBatch(Lists.newArrayList(moneyConfig, pointsConfig)); |
| | | } |
| | | |
| | | private Optional<CustomConfig> getCustomConfigByKey(String key) { |
| | | return this.lambdaQuery() |
| | | .eq(CustomConfig::getConfigType, key) |
| | | .eq(CustomConfig::getDelFlag, 0).oneOpt(); |
| | | } |
| | | |
| | | /** |
| | | * 获取积分设置 |
| | | * |
| | | * @return List<CustomConfigVO> |
| | | */ |
| | | @Override |
| | | public List<CustomConfigVO> getPointsConfig() { |
| | | List<CustomConfig> list = this.lambdaQuery() |
| | | .in(CustomConfig::getConfigType, ConfigEnum.MEMBER_POINTS_MONEY.getKey(), |
| | | ConfigEnum.MEMBER_POINTS_POINTS.getKey()) |
| | | .eq(CustomConfig::getDelFlag, 0).list(); |
| | | return BeanUtils.copyList(list, CustomConfigVO.class); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单说明设置 |
| | | * |
| | | * @return CustomConfigVO |
| | | */ |
| | | @Override |
| | | public CustomConfigVO getOrderDesc() { |
| | | CustomConfigVO vo; |
| | | CustomConfig customConfig = getCustomConfigByKey( |
| | | ConfigEnum.MALL_ORDER_DESCRIPTION.getKey()).orElse(new CustomConfig()); |
| | | vo = BeanUtils.copyBean(customConfig, CustomConfigVO.class); |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * 订单说明设置 |
| | | * |
| | | * @param description 订单说明 |
| | | */ |
| | | @Override |
| | | public void saveOrderDescription(String description) { |
| | | CustomConfig orderDescription = getCustomConfigByKey( |
| | | ConfigEnum.MALL_ORDER_DESCRIPTION.getKey()).orElseGet(() -> { |
| | | CustomConfig customConfig = new CustomConfig(); |
| | | customConfig.setConfigKey(ConfigEnum.MALL_ORDER_DESCRIPTION.getKey()); |
| | | customConfig.setConfigName(ConfigEnum.MALL_ORDER_DESCRIPTION.getKeyName()); |
| | | customConfig.setConfigType(ConfigEnum.MALL_ORDER_DESCRIPTION.getKeyType()); |
| | | return customConfig; |
| | | }); |
| | | orderDescription.setConfigValue(description); |
| | | this.saveOrUpdate(orderDescription); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | public void saveAfterSaleSetting(MgtAfterSaleSettingDTO dto) { |
| | | handleConfigSetting(dto.getReceiverName(), ConfigEnum.RETURN_ADDRESS_USER_NAME); |
| | | handleConfigSetting(dto.getReceiverPhone(), ConfigEnum.RETURN_ADDRESS_USER_PHONE); |
| | | handleConfigSetting(dto.getReceiverAddress(), ConfigEnum.RETURN_ADDRESS_USER_ADDRESS); |
| | | handleConfigSetting(dto.getReturnCycle().toString(), ConfigEnum.RETURN_CYCLE); |
| | | } |
| | | |
| | | private void handleConfigSetting(String value, ConfigEnum configEnum) { |
| | | Optional<CustomConfig> receiverNameConfigOptional = getCustomConfigByKey( |
| | | ConfigEnum.RETURN_ADDRESS_USER_NAME.getKey()); |
| | | CustomConfig receiverNameConfig = receiverNameConfigOptional.orElseGet(() -> { |
| | | CustomConfig config = new CustomConfig(); |
| | | config.setConfigKey(ConfigEnum.RETURN_ADDRESS_USER_NAME.getKey()); |
| | | config.setConfigType(ConfigEnum.RETURN_ADDRESS_USER_NAME.getKeyType()); |
| | | config.setConfigName(ConfigEnum.RETURN_ADDRESS_USER_NAME.getKeyName()); |
| | | return config; |
| | | }); |
| | | receiverNameConfig.setConfigValue(value); |
| | | this.saveOrUpdate(receiverNameConfig); |
| | | } |
| | | } |