对比新文件 |
| | |
| | | package com.gk.firework.Scheduls.WarningTask; |
| | | |
| | | import com.gk.firework.Domain.Enterprise; |
| | | import com.gk.firework.Domain.StockInfo; |
| | | import com.gk.firework.Domain.Vo.NoEntryVo; |
| | | import com.gk.firework.Domain.WarnContentInfo; |
| | | import com.gk.firework.Service.EnterpriseService; |
| | | import com.gk.firework.Service.StockService; |
| | | import com.gk.firework.Service.WarnContentService; |
| | | 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.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author : jingjy |
| | | * @date : 2021/6/16 15:55 |
| | | */ |
| | | @Configuration |
| | | @EnableScheduling |
| | | @ConditionalOnProperty(prefix = "scheduling",name = "enabled",havingValue = "true") |
| | | public class NoEntryWarnTask { |
| | | |
| | | private static final String WARN_TYPE = "超期未入库"; |
| | | private static final String WARN_LEVEL = "预警"; |
| | | private static final Integer WARN_PERIOD = 30; |
| | | @Autowired |
| | | private EnterpriseService enterpriseService; |
| | | @Autowired |
| | | private WarnContentService warnContentService; |
| | | @Autowired |
| | | private StockService stockService; |
| | | |
| | | @Scheduled(cron = "0 0 2 * * ?") //每天凌晨两点执行一次 |
| | | // @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次 |
| | | private void noEntryWarn(){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | Date date = new Date(); |
| | | List<NoEntryVo> noEntryVos = stockService.selectNoEntryCount(calendar.getTime(),WARN_PERIOD); |
| | | for (NoEntryVo noEntryVo : noEntryVos){ |
| | | insertWarnContent(noEntryVo,date); |
| | | } |
| | | } |
| | | |
| | | private void insertWarnContent(NoEntryVo noEntryVo, Date date) { |
| | | Enterprise enterprise = enterpriseService.selectEnterpriseByName(noEntryVo.getName()); |
| | | 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 = noEntryVo.getName()+"有 "+noEntryVo.getNumber()+" 个产品出库超过30天没有进行入库操作!"; |
| | | warnContentInfo.setWarncontent(content); |
| | | |
| | | WarnContentInfo warnContentInfoExist = warnContentService.selectByWarn(WARN_TYPE,WARN_LEVEL,null,content); |
| | | if (warnContentInfoExist == null){ |
| | | warnContentService.save(warnContentInfo); |
| | | }else { |
| | | warnContentInfoExist.setModifieddate(new Date()); |
| | | warnContentService.updateById(warnContentInfoExist); |
| | | } |
| | | } |
| | | } |