对比新文件 |
| | |
| | | package com.gk.firework.Scheduls.WarningTask; |
| | | |
| | | import com.gk.firework.Domain.*; |
| | | import com.gk.firework.Domain.Enum.CertificateStatus; |
| | | import com.gk.firework.Service.*; |
| | | import org.apache.log4j.LogManager; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author : jingjy |
| | | * @date : 2021/6/11 14:16 |
| | | */ |
| | | @Configuration |
| | | @EnableScheduling |
| | | @ConditionalOnProperty(prefix = "scheduling",name = "enabled",havingValue = "true") |
| | | public class TransportWarnTask { |
| | | private Logger logger = LogManager.getLogger(StockWarnTask.class); |
| | | private static final String WARN_TYPE = "运输证超期"; |
| | | private static final String WARN_LEVEL = "预警"; |
| | | private static final Integer WARN_PERIOD = 30; |
| | | @Autowired |
| | | private TransportCertService transportCertService; |
| | | @Autowired |
| | | private TransportCertificateService transportCertificateService; |
| | | @Autowired |
| | | private EnterpriseService enterpriseService; |
| | | @Autowired |
| | | private WarnContentService warnContentService; |
| | | @Autowired |
| | | private EntryService entryService; |
| | | |
| | | @Scheduled(cron = "0 0 2 * * ?") //每天凌晨两点执行一次 |
| | | private void transportWarn(){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | Date date = new Date(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.DATE,calendar.get(Calendar.DATE) - 15); |
| | | try { |
| | | List<TransportCert> transportCerts = transportCertService.selectWarnList(calendar.getTime(),date); |
| | | for (TransportCert transportCert : transportCerts){ |
| | | Boolean isEntry = entryService.isTransportCertEntry(transportCert.getCode()); |
| | | if (!isEntry && transportCert.getprocesstime().getTime() < date.getTime()){ |
| | | insertWarnContent(transportCert.getEnterprisenumber(),transportCert.getCreatebyname(),transportCert.getCode(), |
| | | transportCert.getprocesstime(),date); |
| | | } |
| | | } |
| | | |
| | | List<TransportCertificate> certificates = transportCertificateService.selectWarnList(calendar.getTime(),date); |
| | | for (TransportCertificate certificate : certificates){ |
| | | Boolean isEntry = entryService.isTransportCertEntry(certificate.getCode()); |
| | | if (!isEntry && certificate.getDeadline().getTime() < date.getTime()){ |
| | | insertWarnContent(certificate.getEnterprisenumber(),certificate.getCreatebyname(), |
| | | certificate.getCode(),certificate.getDeadline(),date); |
| | | } |
| | | } |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void insertWarnContent(String enterpriseNumber, String createByName, String code, Date deadline, Date date) { |
| | | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss"); |
| | | String deadlineStr = dateFormat.format(deadline); |
| | | Enterprise enterprise = enterpriseService.selectEnterpriseByNumber(enterpriseNumber); |
| | | WarnContentInfo warnContentInfo = new WarnContentInfo(); |
| | | warnContentInfo.setWarntype(WARN_TYPE); |
| | | warnContentInfo.setPeriod(WARN_PERIOD); |
| | | warnContentInfo.setEnterpriseid(enterprise.getId()); |
| | | warnContentInfo.setWarnlevel(WARN_LEVEL); |
| | | warnContentInfo.setCreateddate(date); |
| | | warnContentInfo.setModifieddate(date); |
| | | warnContentInfo.setModifiedby("系统生成"); |
| | | String content = createByName+"申请的运输证:" |
| | | +code+"预计送达时间:"+deadlineStr+",超期未入库!"; |
| | | warnContentInfo.setWarncontent(content); |
| | | |
| | | WarnContentInfo warnContentInfoExist = warnContentService.selectByWarn(WARN_TYPE,WARN_LEVEL,null,content); |
| | | if (warnContentInfoExist == null){ |
| | | warnContentService.save(warnContentInfo); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |