package com.zy.asrs.task.handler; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.entity.BasCrnp; import com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.*; import com.zy.asrs.task.AbstractHandler; import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.utils.Utils; import com.zy.common.properties.SlaveProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.List; /** * Created by vincent on 2020/7/6 */ @Service @Slf4j public class CheckDeepHandler extends AbstractHandler { @Value("${wcs-slave.doubleDeep}") private boolean confirmDeep; @Autowired private LocDetlService locDetlService; @Autowired private LocMastService locMastService; @Autowired private WorkService workService; @Autowired private WrkMastService wrkMastService; @Autowired private BasCrnpService basCrnpService; @Autowired private SlaveProperties slaveProperties; @Transactional public synchronized ReturnT start() { try { for (int crnNo = 1; crnNo < 3; crnNo++){ List wrkMasts = wrkMastService.selectList(new EntityWrapper() .eq("crn_no",crnNo) .last(" and wrk_sts in (2,3,4,11,12)") ); if (wrkMasts.size() > 0) continue; //暂停移库 BasCrnp crnp = basCrnpService.selectById(crnNo); if(!Cools.isEmpty(crnp) && !Cools.isEmpty(crnp.getTankQty()) && crnp.getTankQty()==0){ continue; } List locMasts = locMastService.queryShallowLocFMast(crnNo); if (null == locMasts) continue; for (LocMast sourceLoc : locMasts){ String deep = Utils.getDeepLoc(slaveProperties, sourceLoc.getLocNo()); LocMast destLoc = locMastService.selectById(deep); if(!Cools.isEmpty(sourceLoc) && !Cools.isEmpty(destLoc)) { //查找源库位是否有转移任务,如果有,不生成库位移转 WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper() .eq("source_loc_no", sourceLoc.getLocNo())); if (Cools.isEmpty(wrkMast) && destLoc.getLocSts().equals("O") && (sourceLoc.getLocSts().equals("F") || sourceLoc.getLocSts().equals("D"))) { workService.locMove(sourceLoc.getLocNo(), deep, 1L); } } } } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return FAIL.setMsg(e.getMessage()); } return SUCCESS; } /** * 遍历库存中,浅库位状态F,深库位状态O的数据,生成库位移转工作档将浅库位移转到对应深库位中去 */ // private void locMoveToDeep(int crnNo){ // if (!confirmDeep) return; // List locMasts = locMastService.queryShallowLocFMast(); // // // if (null == locMasts) return; // // for (LocMast sourceLoc : locMasts){ // String deep = Utils.getDeepLoc(slaveProperties, sourceLoc.getLocNo()); // LocMast destLoc = locMastService.selectById(deep); // // if(!Cools.isEmpty(sourceLoc) && !Cools.isEmpty(destLoc)) { // //查找源库位是否有转移任务,如果有,不生成库位移转 // WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper() // .eq("source_loc_no", sourceLoc.getLocNo())); // if (Cools.isEmpty(wrkMast) && destLoc.getLocSts().equals("O") && // (sourceLoc.getLocSts().equals("F") || sourceLoc.getLocSts().equals("D"))) { // workService.locMove(sourceLoc.getLocNo(), deep, 1L); // } // } // } // // } // @Transactional // public synchronized ReturnT start1() { // try { // for (int crnNo = 1; crnNo < 6; crnNo++){ // List wrkMasts = wrkMastService.selectList(new EntityWrapper() // .eq("crn_no",crnNo) // .last(" and wrk_sts in (2,3,4,11,12)") // ); // if (wrkMasts.size() > 0) continue; // // //暂停移库 // BasCrnp crnp = basCrnpService.selectById(crnNo); // if(!Cools.isEmpty(crnp) && crnp.getOrigin()!=0){ // continue; // } // // //遍历库存中,深浅库位状态都为F,物料不相同,或者浅库位入库日期比深库位早的库位,做库位移转移到新的深库位中去 // boolean flag0 = false; // List locMasts = locMastService.queryNeedMoveShallLoc(crnNo); // for (LocMast locMast : locMasts) { // //多笔明细的不做移转调整 // List shallowLocDetls = locDetlService.selectList(new EntityWrapper() // .eq("loc_no", locMast.getLocNo())); // String deepLoc = Utils.getDeepLoc(slaveProperties, locMast.getLocNo()); // List deepLocDetls = locDetlService.selectList(new EntityWrapper() // .eq("loc_no", deepLoc)); // // if ((!Cools.isEmpty(shallowLocDetls) && shallowLocDetls.size()>1) // || (!Cools.isEmpty(deepLocDetls) && deepLocDetls.size()>1)) { // continue; // } // // LocMast targetLoc = locMastService.queryEmptyDeepLoc(crnNo); // if(!Cools.isEmpty(targetLoc)) { // workService.locMove(locMast.getLocNo(), targetLoc.getLocNo(), 1L); // log.info("浅库位移转到深库位:生成库位移转任务成功[浅到深]===>>" + locMast.getLocNo() + "---" + targetLoc.getLocNo()); // flag0 = true; // } // break; // } // if(flag0) continue; // //// List ignoreLocs = new ArrayList<>(); // List allDeeps = locMastService.selectAllDeepLoc(crnNo); // for (LocMast sourceDeep : allDeeps) { // // LocDetl sourceLoc = locDetlService.selectOne(new EntityWrapper() // .eq("loc_no", sourceDeep.getLocNo()).orderBy("mat_no")); // if(Cools.isEmpty(sourceLoc)){ // continue; // } // // boolean moveFlag = false;//每次执行一笔 //// //如果这个库位已经被操作过了,直接跳过 //// Boolean flag = false; //// for (LocMast ignoreLoc : ignoreLocs) { //// if (ignoreLoc.getLocNo() == sourceDeep.getLocNo()) { //// flag = true; //// break; //// } //// } //// if (flag) { //// continue; //// } // // List allDeepsWithCrnNo = locMastService.selectAllDeepLocWithCrnNo(sourceDeep.getCrnNo(), // sourceLoc.getMatNo(), sourceLoc.getItemBatch(), sourceLoc.getSpecs()); // for (LocMast targetDeep : allDeepsWithCrnNo) { // if(targetDeep.getLocNo().equals(sourceDeep.getLocNo())){ // continue; // } //// LocDetl sourceLoc = locDetlService.selectOne(new EntityWrapper() //// .eq("loc_no", sourceDeep.getLocNo())); // // LocDetl targetLoc = locDetlService.selectOne(new EntityWrapper() // .eq("loc_no", targetDeep.getLocNo())); // //多笔明细的不做移转调整 // List sourceLocDetls = locDetlService.selectList(new EntityWrapper() // .eq("loc_no", sourceDeep.getLocNo())); // List targetLocDetls = locDetlService.selectList(new EntityWrapper() // .eq("loc_no", targetDeep.getLocNo())); // // if (Cools.isEmpty(targetLoc) // || (!Cools.isEmpty(sourceLocDetls) && sourceLocDetls.size()>1) // || (!Cools.isEmpty(targetLocDetls) && targetLocDetls.size()>1)) { // continue; // } // // //物料号相同,源库位入库日期早于目标库位对应深库位入库日期,库位状态都为F // if (sourceLoc.getMatNo().equals(targetLoc.getMatNo()) // && sourceLoc.getItemBatch().equals(targetLoc.getItemBatch()) // && sourceLoc.getSpecs().equals(targetLoc.getSpecs()) // && sourceLoc.getAppeTime().getTime() < targetLoc.getAppeTime().getTime() // && sourceDeep.getLocSts().equals("F") && targetDeep.getLocSts().equals("F")) { // //// System.out.println("成功: "+sourceDeep +"-----" +targetDeep); // String shallow = convertShallow(targetDeep.getLocNo()); // LocMast shallowLoc = locMastService.selectById(shallow); // if(!Cools.isEmpty(shallowLoc) && shallowLoc.getLocSts().equals("O")) { // workService.locMove(sourceDeep.getLocNo(), shallow, 1L); // log.info("深库位合并定时任务:生成库位移转任务成功[深到浅]===>>" + sourceDeep.getLocNo() + "---" + shallow); // moveFlag=true; //// ignoreLocs.add(sourceDeep); //// ignoreLocs.add(targetDeep); // break; // } // } // } // if(moveFlag) break; // } // // } // } catch (Exception e) { // e.printStackTrace(); // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // return FAIL.setMsg(e.getMessage()); // } // return SUCCESS; // } /** * 将深库位转为对应浅库位 * @param deep * @return */ private String convertShallow(String deep){ String shallLoc = ""; Integer mastInt = Integer.parseInt(deep.substring(0, 2)); if (mastInt % 2 == 0){ mastInt -= 1; }else if (mastInt % 2 == 1){ mastInt += 1; } if (mastInt <10){ shallLoc = "0" + mastInt+ deep.substring(2,7); }else { shallLoc = mastInt+ deep.substring(2,7); } return shallLoc; } }