package com.gkhy.hazmat.framework.job; import com.gkhy.hazmat.common.enums.OperateStatusEnum; import com.gkhy.hazmat.system.domain.HzHazmat; import com.gkhy.hazmat.system.domain.HzHazmatFlow; import com.gkhy.hazmat.system.domain.HzWarning; import com.gkhy.hazmat.system.mapper.HzHazmatFlowMapper; import com.gkhy.hazmat.system.mapper.HzHazmatMapper; import com.gkhy.hazmat.system.mapper.HzWarningMapper; import com.gkhy.hazmat.system.service.HzWarningService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; /** * 考生考试超时处理job */ @Slf4j @Component public class WarningJob { @Autowired private HzHazmatMapper hazmatMapper; @Autowired private HzWarningMapper warningMapper; @Autowired private HzHazmatFlowMapper hazmatFlowMapper; @Autowired private HzWarningService warningService; /** * 建议:每天23点执行一次 */ @Scheduled(cron = "0 0 23 * * ?") // @Scheduled(cron = "0 37 17 * * ?") public void checkWarning() { for(int i=0;i<20;i++){ doCheckWarning(i); } } public void doCheckWarning(Integer slice) { Integer pageIndex=1; Integer pageSize=100; List warningList=new ArrayList<>(); try { while (true){ List hazmatList = hazmatMapper.selectWarningHazmatList(slice,(pageIndex - 1) * pageSize, pageSize); if(hazmatList.isEmpty()){ break; } for(HzHazmat hazmat:hazmatList){ HzWarning warning=new HzWarning(); warning.setHazmatId(hazmat.getId()); warning.setBasicId(hazmat.getBasicId()); HzHazmatFlow flow=hazmatFlowMapper.selectLastFlow(slice,hazmat.getId(), OperateStatusEnum.USING.getCode()); if(flow!=null){ warning.setUseTime(flow.getCreateTime()); warning.setCreateId(flow.getCreateId()); } warning.setCompanyId(hazmat.getCompanyId()); warning.setState(0); warningList.add(warning); } warningService.saveBatch(warningList); warningList.clear(); pageIndex++; } }catch (Exception e){ log.error("WarningJob checkWarning slice={}, error={}",slice,e.getMessage()); } } }