|
@@ -0,0 +1,133 @@
|
|
|
+package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.RankAwardConfigDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.AddRankAwardConfigParams;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.EditRankAwardConfigParams;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.QueryRankAwardConfigParam;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.RankAwardConfigMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.RankAwardConfig;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.RankAwardConfigService;
|
|
|
+import com.chelvc.framework.base.exception.ResourceUnavailableException;
|
|
|
+import com.chelvc.framework.common.model.Pagination;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
+@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.RankAwardConfigService.class)
|
|
|
+public class RankAwardConfigServiceImpl extends ServiceImpl<RankAwardConfigMapper, RankAwardConfig> implements
|
|
|
+ RankAwardConfigService, com.chelvc.cloud.vehicle.api.service.RankAwardConfigService{
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(AddRankAwardConfigParams params) {
|
|
|
+ Integer rank = params.getRank();
|
|
|
+ Integer regionLevel = params.getRegionLevel();
|
|
|
+ Integer type = params.getType();
|
|
|
+ Integer platformType = params.getPlatformType();
|
|
|
+ LambdaQueryWrapper<RankAwardConfig> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(RankAwardConfig::getRank, rank);
|
|
|
+ wrapper.eq(RankAwardConfig::getStatus, 0);
|
|
|
+ wrapper.eq(RankAwardConfig::getPlatformType, platformType);
|
|
|
+ wrapper.eq(RankAwardConfig::getType, type);
|
|
|
+ wrapper.eq(RankAwardConfig::getRegionLevel, regionLevel);
|
|
|
+ if(baseMapper.selectCount(wrapper) > 0){
|
|
|
+ throw new ResourceUnavailableException("当前排名配置已存在");
|
|
|
+ }
|
|
|
+ RankAwardConfig config = new RankAwardConfig();
|
|
|
+ config.setName(params.getName());
|
|
|
+ config.setRatio(params.getRatio());
|
|
|
+ config.setType(params.getType());
|
|
|
+ config.setRank(rank);
|
|
|
+ config.setRegionLevel(regionLevel);
|
|
|
+ config.setCommissionRatio(params.getCommissionRatio());
|
|
|
+ config.setPlatformType(params.getPlatformType());
|
|
|
+ config.setStatus(0);
|
|
|
+ config.setCreateTime(new Date());
|
|
|
+ config.setUpdateTime(new Date());
|
|
|
+ config.setCreator(params.getUserId());
|
|
|
+ config.setUpdater(params.getUserId());
|
|
|
+ baseMapper.insert(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(EditRankAwardConfigParams params) {
|
|
|
+ RankAwardConfig config = baseMapper.selectById(params.getId());
|
|
|
+ if(config == null){
|
|
|
+ throw new ResourceUnavailableException("该配置不存在");
|
|
|
+ }
|
|
|
+ Integer status = params.getStatus();
|
|
|
+ if(status == 1){
|
|
|
+ config.setStatus(1);
|
|
|
+ config.setUpdater(params.getUserId());
|
|
|
+ config.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(config);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer rank = params.getRank();
|
|
|
+ Integer regionLevel = params.getRegionLevel();
|
|
|
+ LambdaQueryWrapper<RankAwardConfig> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(RankAwardConfig::getRank, rank);
|
|
|
+ wrapper.eq(RankAwardConfig::getStatus, 0);
|
|
|
+ wrapper.eq(RankAwardConfig::getPlatformType, config.getPlatformType());
|
|
|
+ wrapper.eq(RankAwardConfig::getType, config.getType());
|
|
|
+ wrapper.eq(RankAwardConfig::getRegionLevel, regionLevel);
|
|
|
+ wrapper.ne(RankAwardConfig::getId, config.getId());
|
|
|
+ if(baseMapper.selectCount(wrapper) > 0){
|
|
|
+ throw new ResourceUnavailableException("当前排名配置已存在");
|
|
|
+ }
|
|
|
+ config.setName(params.getName());
|
|
|
+ config.setRank(rank);
|
|
|
+ config.setRegionLevel(regionLevel);
|
|
|
+ config.setCommissionRatio(params.getCommissionRatio());
|
|
|
+ config.setStatus(params.getStatus());
|
|
|
+ config.setRatio(params.getRatio());
|
|
|
+ config.setUpdater(params.getUserId());
|
|
|
+ config.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delete(Long id, Long userId) {
|
|
|
+ RankAwardConfig config = baseMapper.selectById(id);
|
|
|
+ if(config == null){
|
|
|
+ throw new ResourceUnavailableException("该配置不存在");
|
|
|
+ }
|
|
|
+ Integer status = config.getStatus();
|
|
|
+ if(status == 0){
|
|
|
+ throw new ResourceUnavailableException("请先停用该配置");
|
|
|
+ }
|
|
|
+ config.setUpdater(userId);
|
|
|
+ config.setUpdateTime(new Date());
|
|
|
+ baseMapper.update(config, null);
|
|
|
+ baseMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<RankAwardConfigDTO> queryPageList(QueryRankAwardConfigParam param, Long pageNum, Long pageSize) {
|
|
|
+ Page<RankAwardConfigDTO> page = new Page<>(pageNum, pageSize);
|
|
|
+ QueryWrapper<RankAwardConfig> wrapper = Wrappers.query();
|
|
|
+ wrapper.eq(param.getType() != null, "type", param.getType());
|
|
|
+ wrapper.eq(param.getPlatformType() != null, "platform_type", param.getPlatformType());
|
|
|
+ wrapper.eq(param.getStatus() != null, "status", param.getStatus());
|
|
|
+ wrapper.orderByAsc("rank_high");
|
|
|
+ IPage<RankAwardConfigDTO> result = baseMapper.queryPageList(page, wrapper);
|
|
|
+ return Pagination.<RankAwardConfigDTO>builder().total(result.getTotal()).pages(result.getPages())
|
|
|
+ .records(result.getRecords()).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RankAwardConfig queryById(Long id) {
|
|
|
+ return baseMapper.selectById(id);
|
|
|
+ }
|
|
|
+}
|