package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.entity.DocType; import com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.Mat; import com.zy.asrs.entity.Order; import com.zy.asrs.service.*; import com.zy.asrs.task.handler.AutoReplenishmentHandler; import com.zy.common.entity.Parameter; 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.List; import java.util.Set; @Slf4j @Component public class AutoReplenishmentScheduler { @Autowired private OrderService orderService; @Autowired private DocTypeService docTypeService; @Autowired private AutoReplenishmentHandler autoReplenishmentHandler; @Autowired private MatService matService; @Autowired private AgvLocDetlService agvLocDetlService; @Autowired private LocDetlService locDetlService; /* 定时遍历库存,生成自动补货单据 */ @Scheduled(cron = "0 */1 * * * ? ") public void createOrder(){ if(!"Y".equals(Parameter.get().getAutoReplenishment())){ return; } //检测是否有未完成的补货单据 DocType docType = docTypeService.selectOne(new EntityWrapper().eq("doc_name", "自动补货单")); int count = orderService.selectCount(new EntityWrapper() .eq("doc_type", docType.getDocId()) .andNew().eq("settle",2) .or().eq("settle",1)); if(count > 0){ return; } //查询所有需要补货的物料 List matList = matService.selectList(new EntityWrapper().gt( "store_min", 0)); if(!Cools.isEmpty(matList)){ for (Mat mat : matList){ //查询当前物料是否在agv库小于库存上限 Double anfmeSum = agvLocDetlService.selectSumAnfmeByMatnr(mat.getMatnr()); if(Cools.isEmpty(anfmeSum)){ anfmeSum = 0.0; } //当前物料不需要补货 if(anfmeSum > mat.getStoreMin()){ continue; } //查询当前物料四项库是否存在,并且托盘不含有非料箱物料 if(Cools.isEmpty(locDetlService.selectOne(new EntityWrapper().eq("matnr", mat.getMatnr())))){ continue; } Set locNosSearch = locDetlService.selectLocNos(mat.getMatnr()); //是否含有可补货出库的库位 boolean flag = false; for (String locNo : locNosSearch){ //log.info("需要拣料的货位:" + locNo +",需要补货的物料:" + mat.getMatnr()); if(Cools.isEmpty(locDetlService.selectByLocWithoutContainer(locNo))){ flag = true; continue; } } if(flag){ autoReplenishmentHandler.create(mat,mat.getStoreMax() - anfmeSum); break; } } } } /* 定时处理自动补货单据 */ //@Scheduled(cron = "0/10 * * * * ? ") public void excuteOrder(){ DocType docType = docTypeService.selectOne(new EntityWrapper().eq("doc_name", "自动补货单")); List orderList = orderService.selectList(new EntityWrapper() .eq("doc_type", docType.getDocId()) .eq("settle",1)); if(!Cools.isEmpty(orderList)){ orderList.forEach(order -> { autoReplenishmentHandler.start(order); }); } } }