package com.rzyc.service; import com.common.utils.DateUtils; import com.common.utils.RandomNumber; import com.common.utils.encryption.MD5; import com.common.utils.model.SingleResult; import com.rzyc.bean.check.CheckPerform; import com.rzyc.controller.BaseController; import com.rzyc.model.*; import com.rzyc.model.check.BookEntHT; import com.rzyc.model.check.BookenthtCompany; import com.rzyc.model.ent.SysEnterprise; import com.rzyc.model.user.SysUser; import org.junit.Test; import org.springframework.stereotype.Service; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; @Service public class TaskService extends BaseController { /** * 定时任务 */ public void task(){ try { //隐患 configureTasks(); //自查隐患 configureTasksEditCompanySelfDangerState(); //履职任务提醒 performTask(); //隐患超时 configureTasksEditDanger(); }catch (Exception e){ e.printStackTrace(); } } /** * 定时任务 */ private void configureTasks() { try { System.err.println("--------------------定时任务 start --------------------------------"); //先查询 List entHTs = bookEntHTMapper.findByHTStateByTime(); if(null != entHTs && entHTs.size() > 0){ for (BookEntHT entHT : entHTs){ //添加通知 addNotice(entHT.getSysenterpriseid(),entHT.getHiddenarea()); } //修改整改状态 bookEntHTMapper.changeHTStateByTime(); } System.err.println("--------------------定时任务 end --------------------------------"); }catch (Exception e){ e.printStackTrace(); } } /** * 添加隐患通知 * @param entId * @throws Exception */ private void addNotice(String entId,String dangerContent)throws Exception{ List dutyTrees = dutyTreeMapper.findByTargetId(entId); if(null != dutyTrees && dutyTrees.size() > 0 ){ List notices = new ArrayList<>(); String content = ""; SysEnterprise enterprise = sysEnterpriseMapper.selectByPrimaryKey(entId); if(null != enterprise){ content = enterprise.getEntname()+"的"; } content += "隐患<"+dangerContent+">,"; content += "已变为未整改。"; for (DutyTree dutyTree : dutyTrees){ Notice notice = new Notice(); notice.setId(RandomNumber.getUUid()); notice.setTitle("隐患变更"); notice.setCompanyid(entId); notice.setCheckuserid(dutyTree.getUserId()); notice.setContent(content); notice.setReadState(1+""); notice.setType(1); notice.setCreateTime(new Date()); notices.add(notice); } noticeMapper.insertList(notices); } } private void configureTasksEditCompanySelfDangerState() { try { System.err.println("--------------------定时任务 start --------------------------------"); //先查询 List entHTs = bookenthtCompanyMapper.findByHTStateByTime(); if(null != entHTs && entHTs.size() > 0){ //修改整改状态 bookenthtCompanyMapper.changeHTStateByTime(); } System.err.println("--------------------定时任务 end --------------------------------"); }catch (Exception e){ e.printStackTrace(); } } /** * 机构隐患超过整改期限 */ public void configureTasksEditDanger(){ System.err.println("--------------------定时任务 start --------------------------------"); orgDangerMapper.outDateOrgDanger(); System.err.println("--------------------定时任务 end --------------------------------"); } /** * 履职定时任务 */ public void performTask(){ try { Calendar nowTime = Calendar.getInstance(); //当月天数 Integer monthDay = DateUtils.getMonthLastDay(nowTime.get(Calendar.YEAR),nowTime.get(Calendar.MONTH)+1); //当前天数 Integer day = nowTime.get(Calendar.DAY_OF_MONTH); Integer days = monthDay - day; System.out.println("days -> "+days); if(5 == days){ //5天前提醒 List users = sysUserMapper.allGovUser(); if(null != users){ for (SysUser user : users){ CheckPerform checkPerform = getCheckPerform(user); if(checkPerform.getCheckList().size() > 0 && checkPerform.getCompletionRate() < 100){ Notice notice = new Notice(); notice.setId(RandomNumber.getUUid()); notice.setTitle("履职提醒"); notice.setCompanyid(""); notice.setCheckuserid(user.getSysuserid()); String content = "您的检查履职还未完成,请完成。"; notice.setContent(content); notice.setReadState(1+""); notice.setType(5); notice.setCreateTime(new Date()); noticeMapper.insert(notice); } } } } }catch (Exception e){ e.printStackTrace(); } } public void deviceInspectionCycleCheck(){ new DeviceInspectionCycle(entDeviceInsCycleMapper,entDeviceMapper).run(); } public void scheduleUpdateState(){ System.out.println("证件过期定时任务开始"); entCertificatesMapper.scheduleUpdateStateDueSoon(); entCertificatesMapper.scheduleUpdateState(); System.out.println("证件过期定时任务结束"); } public static void main(String[] args) { try { System.out.println(MD5.md5("170929")); }catch (Exception e){ e.printStackTrace(); } } public void test(){ System.out.println("---------------------"); } }