Commit df5c75e6 by zhangxingmin

push

parent 3c18106b
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/yd-csf-api/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/yd-csf-api/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/yd-csf-feign/src/main/java" charset="UTF-8" />
......
......@@ -25,6 +25,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Function;
......@@ -152,7 +153,22 @@ public class ApiExpectedFortuneAsyncService {
agentAccumulatedFyc = filterList.get(0);
}
//积分解冻时间
LocalDateTime thawingTime = resDto.getThawingTime();
for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) {
if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) <= 0) {
//判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否小于等于当前时间(年月日时分秒)
//如果小于等于当前时间,不用走定时任务来解冻积分,应该及时生效积分
//业务员积分明细表唯一业务ID
String detailFycBizId = RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_AGENT_DETAIL_FYC.getCode());
//新增积分明细
//status 定时任务0-冻结。非定时任务1-生效
addAgentDetailFyc(resDto,policyNo,algorithmResDto,detailFycBizId,agentAccumulatedFyc,1);
}else if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) > 0){
//判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否大于当前时间(年月日时分秒)
//如果大于当前时间,走定时任务来解冻积分。
CalmTask calmTask = new CalmTask();
//保单号
calmTask.setPolicyNo(policyNo);
......@@ -185,12 +201,14 @@ public class ApiExpectedFortuneAsyncService {
iCalmTaskService.saveOrUpdate(calmTask);
//新增积分明细
addAgentDetailFyc(resDto,policyNo,algorithmResDto,detailFycBizId,agentAccumulatedFyc);
//status 定时任务0-冻结。非定时任务1-生效
addAgentDetailFyc(resDto,policyNo,algorithmResDto,detailFycBizId,agentAccumulatedFyc,0);
//创建XXL-Job定时任务
xxlJobService.addScheduleJob(calmTask.getCalmTaskBizId(),"冷静期定时发送任务-","calmSendJobHandler",Date.from(resDto.getThawingTime().atZone(ZoneId.systemDefault()).toInstant()));
}
}
}
//更新积分总表的值
updateAgentAccumulatedFyc(accumulatedFycList,filteredCollectResDtos);
......@@ -204,12 +222,14 @@ public class ApiExpectedFortuneAsyncService {
* @param algorithmResDto
* @param detailFycBizId
* @param agentAccumulatedFyc
* @param status 定时任务0-冻结。非定时任务1-生效
*/
public void addAgentDetailFyc(AlgorithmCollectResDto resDto,
String policyNo,
AlgorithmResDto algorithmResDto,
String detailFycBizId,
AgentAccumulatedFyc agentAccumulatedFyc) {
AgentAccumulatedFyc agentAccumulatedFyc,
Integer status) {
//新增积分明细
AgentDetailFyc agentDetailFyc = new AgentDetailFyc();
//积分来源类型
......@@ -224,7 +244,7 @@ public class ApiExpectedFortuneAsyncService {
agentDetailFyc.setDetailFycBizId(detailFycBizId);
//状态(0:停用(冻结) 1:启用(生效))
//冻结
agentDetailFyc.setStatus(0);
agentDetailFyc.setStatus(status);
//积分解冻时间
agentDetailFyc.setThawingTime(resDto.getThawingTime());
//变化前的业务员总FYC积分(已生效+未生效)
......@@ -254,51 +274,105 @@ public class ApiExpectedFortuneAsyncService {
));
// 构建每个转介人本次的积分增量 Map
// 未生效累计积分增量
Map<String, BigDecimal> noEffectDeltaMap = new HashMap<>();
// 未生效首期佣金增量
// 未生效个人累计积分增量(定时(冻结))
Map<String, BigDecimal> noDeltaMap = new HashMap<>();
// 未生效首期佣金增量(定时(冻结))
Map<String, BigDecimal> noFirstCommissionDeltaMap = new HashMap<>();
// 未生效非首期佣金增量
// 未生效非首期佣金增量(定时(冻结))
Map<String, BigDecimal> noRycDeltaMap = new HashMap<>();
// 已生效个人累计积分增量(非定时(生效))
Map<String, BigDecimal> deltaMap = new HashMap<>();
// 已生效首期佣金增量(非定时(生效))
Map<String, BigDecimal> firstCommissionDeltaMap = new HashMap<>();
// 已生效非首期佣金增量(非定时(生效))
Map<String, BigDecimal> rycDeltaMap = new HashMap<>();
for (AlgorithmCollectResDto resDto : filteredCollectResDtos) {
String agentId = resDto.getClientUserBizId();
Integer fortunePeriod = resDto.getFortunePeriod();
//积分解冻时间
LocalDateTime thawingTime = resDto.getThawingTime();
for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) {
BigDecimal val = algorithmResDto.getCalculatedValue();
if (val == null) continue;
// 累加 noEffect 增量
noEffectDeltaMap.merge(agentId, val, BigDecimal::add);
if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) <= 0) {
//判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否小于等于当前时间(年月日时分秒)
//如果小于等于当前时间,不用走定时任务来解冻积分,应该及时生效积分
// 已生效个人累计积分增量(非定时(生效))
deltaMap.merge(agentId, val, BigDecimal::add);
// 根据期数判断佣金类型
if (fortunePeriod != null && fortunePeriod == 1) {
//已生效首期佣金增量(非定时(生效))
firstCommissionDeltaMap.merge(agentId, val, BigDecimal::add);
} else {
//未生效非首期佣金增量(定时(冻结))
noRycDeltaMap.merge(agentId, val, BigDecimal::add);
//已生效非首期佣金增量(非定时(生效))
rycDeltaMap.merge(agentId, val, BigDecimal::add);
}
}else if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) > 0){
//判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否大于当前时间(年月日时分秒)
//如果大于当前时间,走定时任务来解冻积分。
// 未生效个人累计积分增量(定时(冻结))
noDeltaMap.merge(agentId, val, BigDecimal::add);
}
// 根据期数判断佣金类型
if (fortunePeriod != null && fortunePeriod == 1) {
//未生效首期佣金增量(定时(冻结))
noFirstCommissionDeltaMap.merge(agentId, val, BigDecimal::add);
//已生效首期佣金增量(非定时(生效))
firstCommissionDeltaMap.merge(agentId, val, BigDecimal::add);
} else {
//未生效非首期佣金增量(定时(冻结))
noRycDeltaMap.merge(agentId, val, BigDecimal::add);
//已生效非首期佣金增量(非定时(生效))
rycDeltaMap.merge(agentId, val, BigDecimal::add);
}
}
}
// 更新或新建累计积分记录
List<AgentAccumulatedFyc> toUpdateList = new ArrayList<>();
for (String agentId : noEffectDeltaMap.keySet()) {
BigDecimal noEffectDelta = noEffectDeltaMap.get(agentId);
for (String agentId : deltaMap.keySet()) {
//个人累计积分增量(定时(冻结)和 未定时(生效)场景)
BigDecimal delta = deltaMap.get(agentId);
//未生效首期佣金增量(定时(冻结))
BigDecimal noFirstDelta = noFirstCommissionDeltaMap.getOrDefault(agentId, BigDecimal.ZERO);
//未生效非首期佣金增量(定时(冻结))
BigDecimal noRycDelta = noRycDeltaMap.getOrDefault(agentId, BigDecimal.ZERO);
//已生效首期佣金增量(非定时(生效))
BigDecimal firstDelta = firstCommissionDeltaMap.getOrDefault(agentId, BigDecimal.ZERO);
//已生效非首期佣金增量(非定时(生效))
BigDecimal rycDelta = rycDeltaMap.getOrDefault(agentId, BigDecimal.ZERO);
AgentAccumulatedFyc fyc = fycMap.get(agentId);
if (fyc == null) {
continue;
}
// 应用增量
//未生效累计积分(不限业务场景)
fyc.setNoEffect(fyc.getNoEffect().add(noEffectDelta));
fyc.setNoEffect(fyc.getNoEffect().add(delta));
//未生效累计首期佣金积分值(佣金场景)
fyc.setNoFirstCommission(fyc.getNoFirstCommission().add(noFirstDelta));
//未生效累计非首期佣金积分值(佣金场景)
fyc.setNoRyc(fyc.getNoRyc().add(noRycDelta));
//已生效累计积分(不限业务场景)
fyc.setNoEffect(fyc.getNoEffect().add(delta));
//已生效累计首期佣金积分值(佣金场景)
fyc.setNoFirstCommission(fyc.getNoFirstCommission().add(noFirstDelta));
//已生效累计非首期佣金积分值(佣金场景)
fyc.setNoRyc(fyc.getNoRyc().add(noRycDelta));
//累计积分 = 未生效累计积分 + 已生效累计积分
fyc.setTotalFyc(fyc.getNoEffect().add(fyc.getEffect()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment