| | |
| | | package com.mzl.flower.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | | import com.mzl.flower.dto.request.configParam.ConfigParamDTO; |
| | | import com.mzl.flower.dto.request.configParam.QueryConfigParamDTO; |
| | | import com.mzl.flower.dto.request.configParam.UpdateConfigParamDTO; |
| | | import com.mzl.flower.dto.response.configParam.ConfigCustomerServiceVO; |
| | | import com.mzl.flower.dto.response.configParam.ConfigParamVO; |
| | | import com.mzl.flower.entity.configParam.ConfigParamDO; |
| | | import com.mzl.flower.enums.ConfigParamEnum; |
| | | import com.mzl.flower.mapper.configParam.ConfigParamMapper; |
| | | import com.mzl.flower.mapper.configParam.ConfigParamMapperCustom; |
| | | import com.mzl.flower.service.ConfigParamService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.redisson.api.RBucket; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | * @since 2024-12-02 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class ConfigParamServiceImpl extends ServiceImpl<ConfigParamMapper, ConfigParamDO> implements ConfigParamService { |
| | | |
| | | @Autowired |
| | | private ConfigParamMapperCustom configParamMapperCustom; |
| | | private final ConfigParamMapperCustom configParamMapperCustom; |
| | | |
| | | private final ConfigParamMapper configParamMapper; |
| | | private final RedissonClient redissonClient; |
| | | private static final String CONFIG_PARAM= "com.mzl.flower.service.impl:config_param:%s"; |
| | | |
| | | @Override |
| | | public List<ConfigParamDO> getList(QueryConfigParamDTO dto) { |
| | |
| | | throw new ValidationException(String.format("ID:{}不存在!", configParamDO.getId())); |
| | | } |
| | | configParamForUpdate.setParamValue(configParamDO.getParamValue()); |
| | | |
| | | //更新订单自动取消(分钟); 订单自动收货(天) |
| | | if ("order".equals(configParamForUpdate.getParamGroup())) { |
| | | // 设置值到 Redis |
| | | RBucket<String> bucket = redissonClient.getBucket(CONFIG_PARAM + configParamForUpdate.getParamGroup() + configParamForUpdate.getParamKey()); |
| | | bucket.set(configParamForUpdate.getParamValue()); |
| | | } |
| | | |
| | | return configParamForUpdate; |
| | | }).collect(Collectors.toList()); |
| | | |
| | |
| | | |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public String getBaseString(String paramGroup, String paramKey) { |
| | | |
| | | String bucketName = CONFIG_PARAM + paramGroup + paramKey; |
| | | RBucket<String> bucket = redissonClient.getBucket(bucketName); |
| | | String value = bucket.get(); |
| | | |
| | | if (StringUtils.isNotBlank(value)) { |
| | | return value; |
| | | } else { |
| | | String baseString = configParamMapper.getBaseString(paramGroup, paramKey); |
| | | if (StringUtils.isNotBlank(baseString)) { |
| | | return baseString; |
| | | } else { |
| | | if ("order_cancel_time".equals(paramKey) && "order".equals(paramGroup)) { |
| | | // 默认15分钟 |
| | | return "15"; |
| | | } |
| | | if ("order_auto_receive".equals(paramKey) && "order".equals(paramGroup)) { |
| | | // 默认5前的订单自动收货 |
| | | return "5"; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void saveConfigParam(ConfigParamDTO dto) { |
| | | ConfigParamDO configParamDO = new ConfigParamDO(); |
| | | BeanUtils.copyProperties(dto, configParamDO); |
| | | configParamDO.create(SecurityUtils.getUserId()); |
| | | configParamMapper.insert(configParamDO); |
| | | } |
| | | |
| | | @Override |
| | | public void updateConfigParam(ConfigParamDTO dto) { |
| | | ConfigParamDO configParamDO = configParamMapper.selectById(dto.getId()); |
| | | BeanUtils.copyProperties(dto, configParamDO); |
| | | configParamDO.update(SecurityUtils.getUserId()); |
| | | configParamMapper.updateById(configParamDO); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteConfigParam(Long id) { |
| | | configParamMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Page<ConfigParamVO> queryPage(QueryConfigParamDTO dto, Page page) { |
| | | List<ConfigParamVO> list = configParamMapper.queryPage(dto, page); |
| | | page.setRecords(list); |
| | | return page; |
| | | } |
| | | |
| | | } |