Commit df5c75e6 by zhangxingmin

push

parent 3c18106b
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding"> <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/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-api/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/yd-csf-feign/src/main/java" 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; ...@@ -25,6 +25,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
...@@ -152,43 +153,60 @@ public class ApiExpectedFortuneAsyncService { ...@@ -152,43 +153,60 @@ public class ApiExpectedFortuneAsyncService {
agentAccumulatedFyc = filterList.get(0); agentAccumulatedFyc = filterList.get(0);
} }
//积分解冻时间
LocalDateTime thawingTime = resDto.getThawingTime();
for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) { for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) {
CalmTask calmTask = new CalmTask(); if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) <= 0) {
//保单号 //判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否小于等于当前时间(年月日时分秒)
calmTask.setPolicyNo(policyNo); //如果小于等于当前时间,不用走定时任务来解冻积分,应该及时生效积分
//新单跟进唯一业务ID
calmTask.setPolicyBizId(policyFollow.getPolicyBizId()); //业务员积分明细表唯一业务ID
//执行时间(定时任务执行时间) = 积分解冻时间 String detailFycBizId = RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_AGENT_DETAIL_FYC.getCode());
calmTask.setExecutionTime(resDto.getThawingTime()); //新增积分明细
//冷静期天数 //status 定时任务0-冻结。非定时任务1-生效
calmTask.setCoolingOffDays(policyFollow.getCoolingOffDays()); addAgentDetailFyc(resDto,policyNo,algorithmResDto,detailFycBizId,agentAccumulatedFyc,1);
//保单冷静期定时任务表唯一业务ID
calmTask.setCalmTaskBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_CALM_TASK.getCode())); }else if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) > 0){
//执行状态(0-未执行,1-执行中,2-已执行,3-执行异常) //判断积分解冻时间(年月日 + 00:00:00)(冷静期时间 + 期数)是否大于当前时间(年月日时分秒)
//0-未执行 //如果大于当前时间,走定时任务来解冻积分。
calmTask.setExecutionStatus("0"); CalmTask calmTask = new CalmTask();
//转介人名称 //保单号
calmTask.setBrokerName(resDto.getClientUserName()); calmTask.setPolicyNo(policyNo);
//转介人业务id //新单跟进唯一业务ID
calmTask.setBrokerBizId(resDto.getClientUserBizId()); calmTask.setPolicyBizId(policyFollow.getPolicyBizId());
//佣金项目 //执行时间(定时任务执行时间) = 积分解冻时间
calmTask.setCommissionName(algorithmResDto.getItemName()); calmTask.setExecutionTime(resDto.getThawingTime());
//发佣期数 //冷静期天数
calmTask.setFortunePeriod(resDto.getFortunePeriod()); calmTask.setCoolingOffDays(policyFollow.getCoolingOffDays());
//佣金值(积分值) //保单冷静期定时任务表唯一业务ID
calmTask.setFyc(algorithmResDto.getCalculatedValue()); calmTask.setCalmTaskBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_CALM_TASK.getCode()));
//冷静期结束日期 //执行状态(0-未执行,1-执行中,2-已执行,3-执行异常)
calmTask.setCoolingOffEndDate(policyFollow.getCoolingOffEndDate()); //0-未执行
//业务员积分明细表唯一业务ID calmTask.setExecutionStatus("0");
String detailFycBizId = RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_AGENT_DETAIL_FYC.getCode()); //转介人名称
calmTask.setDetailFycBizId(detailFycBizId); calmTask.setBrokerName(resDto.getClientUserName());
iCalmTaskService.saveOrUpdate(calmTask); //转介人业务id
calmTask.setBrokerBizId(resDto.getClientUserBizId());
//新增积分明细 //佣金项目
addAgentDetailFyc(resDto,policyNo,algorithmResDto,detailFycBizId,agentAccumulatedFyc); calmTask.setCommissionName(algorithmResDto.getItemName());
//发佣期数
//创建XXL-Job定时任务 calmTask.setFortunePeriod(resDto.getFortunePeriod());
xxlJobService.addScheduleJob(calmTask.getCalmTaskBizId(),"冷静期定时发送任务-","calmSendJobHandler",Date.from(resDto.getThawingTime().atZone(ZoneId.systemDefault()).toInstant())); //佣金值(积分值)
calmTask.setFyc(algorithmResDto.getCalculatedValue());
//冷静期结束日期
calmTask.setCoolingOffEndDate(policyFollow.getCoolingOffEndDate());
//业务员积分明细表唯一业务ID
String detailFycBizId = RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_AGENT_DETAIL_FYC.getCode());
calmTask.setDetailFycBizId(detailFycBizId);
iCalmTaskService.saveOrUpdate(calmTask);
//新增积分明细
//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()));
}
} }
} }
...@@ -204,12 +222,14 @@ public class ApiExpectedFortuneAsyncService { ...@@ -204,12 +222,14 @@ public class ApiExpectedFortuneAsyncService {
* @param algorithmResDto * @param algorithmResDto
* @param detailFycBizId * @param detailFycBizId
* @param agentAccumulatedFyc * @param agentAccumulatedFyc
* @param status 定时任务0-冻结。非定时任务1-生效
*/ */
public void addAgentDetailFyc(AlgorithmCollectResDto resDto, public void addAgentDetailFyc(AlgorithmCollectResDto resDto,
String policyNo, String policyNo,
AlgorithmResDto algorithmResDto, AlgorithmResDto algorithmResDto,
String detailFycBizId, String detailFycBizId,
AgentAccumulatedFyc agentAccumulatedFyc) { AgentAccumulatedFyc agentAccumulatedFyc,
Integer status) {
//新增积分明细 //新增积分明细
AgentDetailFyc agentDetailFyc = new AgentDetailFyc(); AgentDetailFyc agentDetailFyc = new AgentDetailFyc();
//积分来源类型 //积分来源类型
...@@ -224,7 +244,7 @@ public class ApiExpectedFortuneAsyncService { ...@@ -224,7 +244,7 @@ public class ApiExpectedFortuneAsyncService {
agentDetailFyc.setDetailFycBizId(detailFycBizId); agentDetailFyc.setDetailFycBizId(detailFycBizId);
//状态(0:停用(冻结) 1:启用(生效)) //状态(0:停用(冻结) 1:启用(生效))
//冻结 //冻结
agentDetailFyc.setStatus(0); agentDetailFyc.setStatus(status);
//积分解冻时间 //积分解冻时间
agentDetailFyc.setThawingTime(resDto.getThawingTime()); agentDetailFyc.setThawingTime(resDto.getThawingTime());
//变化前的业务员总FYC积分(已生效+未生效) //变化前的业务员总FYC积分(已生效+未生效)
...@@ -254,51 +274,105 @@ public class ApiExpectedFortuneAsyncService { ...@@ -254,51 +274,105 @@ public class ApiExpectedFortuneAsyncService {
)); ));
// 构建每个转介人本次的积分增量 Map // 构建每个转介人本次的积分增量 Map
// 未生效累计积分增量 // 未生效个人累计积分增量(定时(冻结))
Map<String, BigDecimal> noEffectDeltaMap = new HashMap<>(); Map<String, BigDecimal> noDeltaMap = new HashMap<>();
// 未生效首期佣金增量 // 未生效首期佣金增量(定时(冻结))
Map<String, BigDecimal> noFirstCommissionDeltaMap = new HashMap<>(); Map<String, BigDecimal> noFirstCommissionDeltaMap = new HashMap<>();
// 未生效非首期佣金增量 // 未生效非首期佣金增量(定时(冻结))
Map<String, BigDecimal> noRycDeltaMap = 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) { for (AlgorithmCollectResDto resDto : filteredCollectResDtos) {
String agentId = resDto.getClientUserBizId(); String agentId = resDto.getClientUserBizId();
Integer fortunePeriod = resDto.getFortunePeriod(); Integer fortunePeriod = resDto.getFortunePeriod();
//积分解冻时间
LocalDateTime thawingTime = resDto.getThawingTime();
for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) { for (AlgorithmResDto algorithmResDto : resDto.getAlgorithmResDtoList()) {
BigDecimal val = algorithmResDto.getCalculatedValue(); BigDecimal val = algorithmResDto.getCalculatedValue();
if (val == null) continue; if (val == null) continue;
// 累加 noEffect 增量 if (thawingTime != null && thawingTime.compareTo(LocalDateTime.now()) <= 0) {
noEffectDeltaMap.merge(agentId, val, BigDecimal::add); //判断积分解冻时间(年月日 + 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) { if (fortunePeriod != null && fortunePeriod == 1) {
//未生效首期佣金增量(定时(冻结))
noFirstCommissionDeltaMap.merge(agentId, val, BigDecimal::add); noFirstCommissionDeltaMap.merge(agentId, val, BigDecimal::add);
//已生效首期佣金增量(非定时(生效))
firstCommissionDeltaMap.merge(agentId, val, BigDecimal::add);
} else { } else {
//未生效非首期佣金增量(定时(冻结))
noRycDeltaMap.merge(agentId, val, BigDecimal::add); noRycDeltaMap.merge(agentId, val, BigDecimal::add);
//已生效非首期佣金增量(非定时(生效))
rycDeltaMap.merge(agentId, val, BigDecimal::add);
} }
} }
} }
// 更新或新建累计积分记录 // 更新或新建累计积分记录
List<AgentAccumulatedFyc> toUpdateList = new ArrayList<>(); List<AgentAccumulatedFyc> toUpdateList = new ArrayList<>();
for (String agentId : noEffectDeltaMap.keySet()) { for (String agentId : deltaMap.keySet()) {
BigDecimal noEffectDelta = noEffectDeltaMap.get(agentId); //个人累计积分增量(定时(冻结)和 未定时(生效)场景)
BigDecimal delta = deltaMap.get(agentId);
//未生效首期佣金增量(定时(冻结))
BigDecimal noFirstDelta = noFirstCommissionDeltaMap.getOrDefault(agentId, BigDecimal.ZERO); BigDecimal noFirstDelta = noFirstCommissionDeltaMap.getOrDefault(agentId, BigDecimal.ZERO);
//未生效非首期佣金增量(定时(冻结))
BigDecimal noRycDelta = noRycDeltaMap.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); AgentAccumulatedFyc fyc = fycMap.get(agentId);
if (fyc == null) { if (fyc == null) {
continue; continue;
} }
// 应用增量 // 应用增量
//未生效累计积分(不限业务场景) //未生效累计积分(不限业务场景)
fyc.setNoEffect(fyc.getNoEffect().add(noEffectDelta)); fyc.setNoEffect(fyc.getNoEffect().add(delta));
//未生效累计首期佣金积分值(佣金场景) //未生效累计首期佣金积分值(佣金场景)
fyc.setNoFirstCommission(fyc.getNoFirstCommission().add(noFirstDelta)); fyc.setNoFirstCommission(fyc.getNoFirstCommission().add(noFirstDelta));
//未生效累计非首期佣金积分值(佣金场景) //未生效累计非首期佣金积分值(佣金场景)
fyc.setNoRyc(fyc.getNoRyc().add(noRycDelta)); 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())); 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