1.HealthCheckController
@Resource
private ExpiryYwyGradeChangFlowScript expiryYwyGradeChangFlowScript;
@GetMapping("/expiry-ywy-grade-chang-flow")
private BaseResponse expiryYwyGradeChangFlow(@RequestParam Long latterGradeId, @RequestParam int relegationPeriod,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date expiryTime){
if (StringUtils.isEmpty(latterGradeId) || StringUtils.isEmpty(relegationPeriod) || expiryTime == null){
return BaseResponse.fail("缺少必要的参数");
}
try {
expiryYwyGradeChangFlowScript.expiryYwyGradeChangFlow(latterGradeId, relegationPeriod, expiryTime);
return BaseResponse.success();
} catch (Exception e) {
log.info("HealthCheckController.expiryYwyGradeChangFlow发生异常:{}", ExceptionUtils.getStackTrace(e));
return BaseResponse.fail();
}
}
2. GradeChangeFlowMapper
List selectByLatterGradeId(@Param("latterGradeId")Long latterGradeId, @Param("expiryTime")Date expiryTime);
Integer expiryGradeChangeFlowBatch(List list);
3. ExpiryYwyGradeChangFlowScript
@Component
@Slf4j
public class ExpiryYwyGradeChangFlowScript {
@Resource
private GradeChangeFlowMapper gradeChangeFlowMapper;
public void expiryYwyGradeChangFlow(Long latterGradeId, int relegationPeriod, Date expiryTime) {
log.info("延期业务员成长流水job开始执行,latterGradeId:{},relegationPeriod:{},expiryTime:{}",
latterGradeId, relegationPeriod, expiryTime);
//循环次数
int cycle = 0;
//总量
int count = 0;
while (true){
List gradeChangeFlows = gradeChangeFlowMapper.selectByLatterGradeId(latterGradeId, expiryTime);
//当流水表查询不到数据后者循环执行超过一定次数时,结束本次循环
if (CollectionUtils.isEmpty(gradeChangeFlows) || cycle > 400){
log.info("延期业务员成长流水job执行完成,cycle:{},count:{}", cycle, count);
break;
}
List updateBatch = new ArrayList<>();
gradeChangeFlows.stream().forEach(e -> {
GradeChangeFlow flow = new GradeChangeFlow();
flow.setId(e.getId());
//当前日期,延期一个保级周期的时长
flow.setExpiryTime(DateUtil.dateAddDayEnd(new Date(), relegationPeriod));
updateBatch.add(flow);
});
gradeChangeFlowMapper.expiryGradeChangeFlowBatch(updateBatch);
cycle++;
count = count + gradeChangeFlows.size();
}
}
}
4.GradeChangeFlowMapper
update grade_change_flow
when id = #{item.id} then #{item.expiryTime}
where id in
#{item.id}
5.