提交 71e5871f authored 作者: 吕本才's avatar 吕本才

增加关闭当前轮次 、初始化第二轮数据

上级 c24f59fd
......@@ -58,14 +58,12 @@ public class DealerBigScreenController extends BaseController {
/**
* 第二 按照分组获取分组合计的
* 第二 按照分组获取分组合计的
*
*/
@GetMapping("/group/region")
public AjaxResult groupTotalList() {
List<DealerBigScreenGroupResultRes> list = resultService.groupTotalList();
return success(list);
}
......
package com.ruoyi.web.controller.dealer;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dealer.service.DealerRoundInfoService;
import com.ruoyi.dealer.service.IDealerRoundResultService;
import com.ruoyi.system.domain.SysConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 经销商信息Controller
*
* @author ruoyi
*/
@RestController
@RequestMapping("/dealer/round")
public class DealerRoundController extends BaseController {
@Autowired
private DealerRoundInfoService dealerRoundInfoService;
@Autowired
private IDealerRoundResultService resultService;
@Log(title = "结束第一轮次或者第二轮次", businessType = BusinessType.INSERT)
@GetMapping(value = "/end")
public AjaxResult endRoundInfo() {
List<SysConfig> sysConfigs = dealerRoundInfoService.endRound();
return AjaxResult.success(sysConfigs);
}
/**
* 修改经销商信息
*/
@Log(title = "初始化第二轮数据", businessType = BusinessType.UPDATE)
@GetMapping("/init")
public AjaxResult initRoundInfo() {
return toAjax(resultService.initRoundInfo());
}
}
......@@ -66,10 +66,25 @@ public class DealerRoundResult {
* 经销商分类
*/
private String dealerCategory;
/**
* 第一轮分组+第二列分组
* 分组名称
*/
private String groupName;
private Integer goalTtlAct;
/**
* 预付款达成的百分比
*/
private BigDecimal paymentPercentage;
private Integer version;
/**
* 销售大区分组名称
* 第二轮分组使用,例如:华东组、华南组、华北一组、华北二组、华中组、西南组、西北组
*
*/
private String salesRegionGroupName;
}
......@@ -26,7 +26,8 @@ public interface DealerRoundResultMapper extends BaseMapper<DealerRoundResult> {
List<DealerBigScreenGroupResultRes> getGroupList(String categoryName);
@Select("select result.round_time, base.sales_region_group_name as group_Name , sum(result.payment_ttl) as payment_ttl,sum(result.goal_ttl_act) as goal_ttl_act , 100*sum(result.payment_ttl) / sum(result.goal_ttl_act) as payment_percentage from dealer_round_result result " +
"left join dealer_base_info base on result.dealer_id = base.dealer_id " +
"where round_time = 2 group by round_time ,sales_region_group_name order by payment_percentage desc limit 4")
"where round_time = 2 " +
"group by round_time ,base.sales_region_group_name order by payment_percentage desc ")
// 手动指定映射:column(数据库字段)→ property(Java属性)
@Results({
@Result(column = "round_time", property = "roundTime"),
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.dealer.domain.dto.DealerBigScreenDynamicRes;
import com.ruoyi.dealer.domain.dto.DealerRoundInfo;
import com.ruoyi.dealer.domain.dto.WechatDealerRoundInfoReq;
import com.ruoyi.system.domain.SysConfig;
import java.util.List;
......@@ -19,4 +20,6 @@ public interface DealerRoundInfoService extends IService<DealerRoundInfo> {
int saveRoundInfo(WechatDealerRoundInfoReq dealerRoundInfoReq);
List<DealerBigScreenDynamicRes> dynamicList(Integer roundId);
List<SysConfig> endRound();
}
......@@ -17,5 +17,7 @@ public interface IDealerRoundResultService extends IService<DealerRoundResult> {
List<DealerBigScreenGroupResultRes> groupTotalList();
List<DealerBigScreenGroupListRes> groupRoundList(Integer roundTime);
int initRoundInfo();
// 自定义业务方法声明(可选)
}
......@@ -7,18 +7,22 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.dealer.domain.DealerBaseInfo;
import com.ruoyi.dealer.domain.DealerRoundResult;
import com.ruoyi.dealer.domain.dto.DealerBigScreenDynamicRes;
import com.ruoyi.dealer.domain.dto.DealerRoundInfo;
import com.ruoyi.dealer.domain.dto.WechatDealerRoundInfoReq;
import com.ruoyi.dealer.mapper.DealerRoundInfoMapper;
import com.ruoyi.dealer.service.DealerRoundInfoService;
import com.ruoyi.dealer.service.IDealerBaseInfoService;
import com.ruoyi.dealer.service.IDealerRoundResultService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -35,6 +39,8 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
private IDealerRoundResultService roundResultService;
@Autowired
private ISysConfigService configService;
@Autowired
private IDealerBaseInfoService dealerBaseInfoService;
@Override
public DealerRoundInfo getByDealerId(Long dealerBaseInfoId) {
......@@ -46,8 +52,8 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
public int saveRoundInfo(WechatDealerRoundInfoReq dealerRoundInfoReq) {
String config = configService.selectConfigByKeyFromDb(Constants.DEALER_ROUND_OVER);
Boolean round = Boolean.parseBoolean(config);
if (round) {
Boolean roundOver = Boolean.parseBoolean(config);
if (roundOver) {
throw new ServiceException("当前轮次活动已经结束");
}
Long userId = SecurityUtils.getUserId();
......@@ -77,7 +83,6 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
//TODO 手机号传输? 是脱敏手机号
resultInfo.setPhone(dealerRoundInfoReq.getPhone());
resultInfo.setRoundTime(dealerRoundInfoReq.getRoundTime());
resultInfo.setPaymentTtl(dealerRoundInfoReq.getPaymentTtlNew());
resultInfo.setPaymentTtlPre(dealerRoundInfoReq.getPaymentTtl());
......@@ -86,6 +91,10 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
resultInfo.setDealerCategory(dealerRoundInfoReq.getDealerCategory());
resultInfo.setGroupName(dealerRoundInfoReq.getGroupName());
// 查询
DealerBaseInfo baseInfo = dealerBaseInfoService.getById(userId);
resultInfo.setSalesRegionGroupName(baseInfo.getSalesRegionGroupName());
// 查询当前经销商的结果
DealerRoundResult existResult = roundResultService.getOne(new LambdaQueryWrapper<DealerRoundResult>()
......@@ -94,14 +103,12 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
);
if (ObjectUtil.isNotEmpty(existResult)) {
// 修改结果表数据
resultInfo.setResultId(existResult.getResultId());
resultInfo.setVersion(existResult.getVersion()+1);
resultInfo.setVersion(existResult.getVersion() + 1);
} else {
// 第一次只能新增 新增结果表数据
resultInfo.setVersion(1);
}
roundResultService.saveOrUpdate(resultInfo);
......@@ -110,6 +117,7 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
/**
* 只有第一轮调用,第2轮不调用
*
* @param roundId
* @return
*/
......@@ -119,7 +127,7 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
// 返回经销商信息 名称 手机号 达成进度
Wrapper<DealerRoundInfo> query = new LambdaQueryWrapper<DealerRoundInfo>()
.eq(DealerRoundInfo::getRoundTime, 1)
.gt(ObjectUtil.isNotEmpty(roundId),DealerRoundInfo::getRoundId, roundId);
.gt(ObjectUtil.isNotEmpty(roundId), DealerRoundInfo::getRoundId, roundId);
List<DealerRoundInfo> infoList = this.list(query);
List<DealerBigScreenDynamicRes> list = infoList.stream().map(info -> {
......@@ -131,8 +139,8 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
res.setGoalTtlAct(info.getGoalTtlAct());
res.setPaymentTtl(info.getPaymentTtlNew());
res.setPhone(info.getPhone());
res.setPaymentChange(info.getPaymentTtlNew()>info.getPaymentTtlPre()?"up":"down");
res.setPaymentPercentage(new BigDecimal(info.getPaymentTtlNew()).multiply(new BigDecimal(100)).divide(new BigDecimal(info.getGoalTtlAct()), 0, BigDecimal.ROUND_HALF_UP)+"%");
res.setPaymentChange(info.getPaymentTtlNew() > info.getPaymentTtlPre() ? "up" : "down");
res.setPaymentPercentage(new BigDecimal(info.getPaymentTtlNew()).multiply(new BigDecimal(100)).divide(new BigDecimal(info.getGoalTtlAct()), 0, BigDecimal.ROUND_HALF_UP) + "%");
res.setRoundId(info.getRoundId());
return res;
......@@ -141,6 +149,19 @@ public class DealerRoundInfoServiceImpl extends ServiceImpl<DealerRoundInfoMappe
return list;
}
@Override
public List<SysConfig> endRound() {
SysConfig sysConfig = configService.selectConfigObjByKey(Constants.DEALER_ROUND_OVER);
sysConfig.setConfigValue("true");
configService.updateConfig(sysConfig);
SysConfig sysConfigRound = configService.selectConfigObjByKey(Constants.DEALER_ROUND);
List<SysConfig> list = new ArrayList<>();
list.add(sysConfigRound);
list.add(sysConfig);
return list;
}
}
......@@ -26,9 +26,9 @@ public class DealerRoundResultServiceImpl extends ServiceImpl<DealerRoundResultM
.eq(DealerRoundResult::getDealerCategory, CategoryName)
.eq(DealerRoundResult::getRoundTime, 1)
.orderByDesc(DealerRoundResult::getPaymentPercentage, DealerRoundResult::getPaymentTtl)
);
);
List<DealerBigScreenGroupListRes> list =new ArrayList<>();
List<DealerBigScreenGroupListRes> list = new ArrayList<>();
resultList.forEach(item -> {
DealerBigScreenGroupListRes res = new DealerBigScreenGroupListRes();
res.setDealerCategory(item.getDealerCategory());
......@@ -40,7 +40,7 @@ public class DealerRoundResultServiceImpl extends ServiceImpl<DealerRoundResultM
res.setGoalTtlAct(item.getGoalTtlAct());
res.setPaymentTtl(item.getPaymentTtl());
res.setPaymentPercentage(Math.round(item.getPaymentTtl() * 100.0 / item.getGoalTtlAct() ) + "%");
res.setPaymentPercentage(Math.round(item.getPaymentTtl() * 100.0 / item.getGoalTtlAct()) + "%");
list.add(res);
});
......@@ -89,4 +89,29 @@ public class DealerRoundResultServiceImpl extends ServiceImpl<DealerRoundResultM
return list;
}
@Override
public int initRoundInfo() {
List<DealerRoundResult> round2Results = this.list(new LambdaQueryWrapper<DealerRoundResult>()
.eq(DealerRoundResult::getRoundTime, 2)
);
if(round2Results.size()>0){
throw new RuntimeException("第二轮数据已存在");
}
// 获取所有经销商信息
List<DealerRoundResult> resultList = this.list(new LambdaQueryWrapper<DealerRoundResult>()
.eq(DealerRoundResult::getRoundTime, 1)
);
// 复制所有数据
// 先清空id
resultList.forEach(item -> {
item.setResultId(null);
item.setRoundTime(2);
// 覆盖字段
item.setGroupName(item.getSalesRegionGroupName());
});
this.saveBatch(resultList);
return 0;
}
}
......@@ -18,6 +18,8 @@ public interface ISysConfigService
*/
public SysConfig selectConfigById(Long configId);
SysConfig selectConfigObjByKey(String configKey);
/**
* 根据键名查询参数配置信息
*
......
......@@ -55,6 +55,21 @@ public class SysConfigServiceImpl implements ISysConfigService
return configMapper.selectConfig(config);
}
@Override
public SysConfig selectConfigObjByKey(String configKey)
{
SysConfig config = new SysConfig();
config.setConfigKey(configKey);
SysConfig retConfig = configMapper.selectConfig(config);
if (StringUtils.isNotNull(retConfig))
{
redisCache.setCacheObject(getCacheKey(configKey+":obj"), retConfig);
return retConfig;
}
return null;
}
/**
* 根据键名查询参数配置信息
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论