Commit 966afa02 by 翁国栋

保单过期定时器

parent 5797c743
package cn.timer.api.controller.insure.task;
import cn.hutool.core.date.DateUtil;
import cn.timer.api.bean.insure.InsureLog;
import cn.timer.api.bean.insure.InsurePolicy;
import cn.timer.api.bean.insure.InsureUser;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.dao.insure.InsurePolicyMapper;
import cn.timer.api.dao.insure.InsureUserMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Description TODO
* @Author wgd
* @Date 2022/5/5 11:20
*/
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class InsureTaskTiming {
@Autowired
private InsureUserMapper insureUserMapper;
@Autowired
private YgglMainEmpMapper ygglMainEmpMapper;
@Scheduled(cron = "0 0 0 1 * ?")//每月第一天
public void updateInsureStatusTask() throws ParseException {
Date now = DateUtil.date();
/*获取正常的保单*/
List<InsurePolicy> insurePolicyList = InsurePolicy.builder().build().selectList(new QueryWrapper<InsurePolicy>().lambda().eq(InsurePolicy::getStatus, "1").lt(InsurePolicy::getPolicyDateEnd,now));
if (insurePolicyList.size() > 0) {
/*获取已经过期保单*/
for (InsurePolicy insurePolicy : insurePolicyList) {
List<InsureUser> insureUsersList = InsureUser.builder().build().selectList(new QueryWrapper<InsureUser>().lambda()
.eq(InsureUser::getPolicyId, insurePolicy.getId()).eq(InsureUser::getStatus, 1)
.eq(InsureUser::getInsureStatus, 1));
if (insureUsersList.size() > 0) {
int count = ygglMainEmpMapper.updateInsure(insureUsersList.stream().map(InsureUser::getUserId).toArray(Integer[]::new));
log.info("总共更新员工投保状态", count);
int uCount = insureUserMapper.updateInsure(insurePolicyList.stream().map(InsurePolicy::getId).toArray(Integer[]::new));
log.info("总共更新投保人投保状态", uCount);
}
insurePolicy.setStatus("3");
insurePolicy.updateById();
}
}
log.error("暂无过期保单");
}
}
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