New file |
| | |
| | | package com.zy.asrs.task.handler; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.WrkDetl; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.LocDetlService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkDetlService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.utils.VersionUtils; |
| | | import com.zy.common.service.CommonService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @Transactional |
| | | public class AutomaticLibraryTransferHandler extends AbstractHandler<String> { |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | |
| | | public ReturnT<String> startOne() { |
| | | List<LocMast> locMastsF=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","F").eq("lev1",1).orderBy("bay1",false)); |
| | | List<LocMast> locMastsO=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","O").eq("lev1",1).orderBy("bay1",false)); |
| | | if(Cools.isEmpty(locMastsO)){ |
| | | log.info("自动移库没有空库位,请关闭自动库位功能"); |
| | | return FAIL; |
| | | } |
| | | LocMast locMast1 = locMastsO.get(0); |
| | | |
| | | LocMast locMast2 = locMastsF.get(locMastsF.size()-1); |
| | | if(locMast2.getBay1()>locMast1.getBay1()){ |
| | | return FAIL; |
| | | } |
| | | |
| | | String locNo=null; |
| | | for(LocMast locMast:locMastsF){ |
| | | if(locMast.getBay1()<locMast1.getBay1()){ |
| | | locNo=locMast1.getLocNo(); |
| | | } |
| | | //生成移库任务 |
| | | if(locNo!=null){ |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(0L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(11); // 入出库状态: 11.库格移载 |
| | | wrkMast.setIoPri(10D); |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setFullPlt("Y"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setBarcode(locMast.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | if (locMast.getLocSts().equals("F")) { |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | for (LocDetl locDetl : locDetls) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.sync(locDetl); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setAnfme(locDetl.getAnfme()); |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts("R"); // R.出库预约 |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (locMast1.getLocSts().equals("O")) { |
| | | locMast1.setLocSts("S"); // S.入库预约 |
| | | locMast1.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast1)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | return SUCCESS; |
| | | } |
| | | public ReturnT<String> startTwo() { |
| | | List<LocMast> locMastsF=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","F").eq("lev1",2).orderBy("bay1",false)); |
| | | List<LocMast> locMastsO=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","O").eq("lev1",2).orderBy("bay1",false)); |
| | | if(Cools.isEmpty(locMastsO)){ |
| | | log.info("自动移库没有空库位,请关闭自动库位功能"); |
| | | return FAIL; |
| | | } |
| | | LocMast locMast1 = locMastsO.get(0); |
| | | |
| | | LocMast locMast2 = locMastsF.get(locMastsF.size()-1); |
| | | if(locMast2.getBay1()>locMast1.getBay1()){ |
| | | return FAIL; |
| | | } |
| | | |
| | | String locNo=null; |
| | | for(LocMast locMast:locMastsF){ |
| | | if(locMast.getBay1()<locMast1.getBay1()){ |
| | | locNo=locMast1.getLocNo(); |
| | | } |
| | | //生成移库任务 |
| | | if(locNo!=null){ |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(0L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(11); // 入出库状态: 11.库格移载 |
| | | wrkMast.setIoPri(10D); |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setFullPlt("Y"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setBarcode(locMast.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | if (locMast.getLocSts().equals("F")) { |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | for (LocDetl locDetl : locDetls) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setAnfme(locDetl.getAnfme()); |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts("R"); // R.出库预约 |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (locMast1.getLocSts().equals("O")) { |
| | | locMast1.setLocSts("S"); // S.入库预约 |
| | | locMast1.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast1)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | |
| | | public ReturnT<String> startThree() { |
| | | List<LocMast> locMastsF=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","D").eq("lev1",3).orderBy("bay1",true)); |
| | | List<LocMast> locMastsO=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","O").eq("lev1",3).orderBy("bay1",true)); |
| | | if(Cools.isEmpty(locMastsO)){ |
| | | log.info("自动移库没有空库位,请关闭自动库位功能"); |
| | | return FAIL; |
| | | } |
| | | LocMast locMast1 = locMastsO.get(0); |
| | | |
| | | LocMast locMast2 = locMastsF.get(locMastsF.size()-1); |
| | | if(locMast2.getBay1()>locMast1.getBay1()){ |
| | | return FAIL; |
| | | } |
| | | |
| | | String locNo=null; |
| | | for(LocMast locMast:locMastsF){ |
| | | if(locMast.getBay1()<locMast1.getBay1()){ |
| | | locNo=locMast1.getLocNo(); |
| | | } |
| | | //生成移库任务 |
| | | if(locNo!=null){ |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(0L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(11); // 入出库状态: 11.库格移载 |
| | | wrkMast.setIoPri(10D); |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setFullPlt("Y"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setBarcode(locMast.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | if (locMast.getLocSts().equals("F")) { |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | for (LocDetl locDetl : locDetls) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setAnfme(locDetl.getAnfme()); |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts("R"); // R.出库预约 |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (locMast1.getLocSts().equals("O")) { |
| | | locMast1.setLocSts("S"); // S.入库预约 |
| | | locMast1.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast1)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | public ReturnT<String> startAll() { |
| | | for(int i=1;i<=3;i++){ |
| | | boolean boo=false; |
| | | String sts="F"; |
| | | if(i==3){ |
| | | boo=true; |
| | | sts="D"; |
| | | } |
| | | List<LocMast> locMastsF=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts",sts).eq("lev1",i).orderBy("bay1",boo)); |
| | | List<LocMast> locMastsO=locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts",sts).eq("lev1",i).orderBy("bay1",boo)); |
| | | if(Cools.isEmpty(locMastsO)){ |
| | | log.info("自动移库没有空库位,请关闭自动库位功能"); |
| | | return FAIL; |
| | | } |
| | | LocMast locMast1 = locMastsO.get(0); |
| | | |
| | | LocMast locMast2 = locMastsF.get(locMastsF.size()-1); |
| | | if(locMast2.getBay1()>locMast1.getBay1()){ |
| | | return FAIL; |
| | | } |
| | | |
| | | String locNo=null; |
| | | for(LocMast locMast:locMastsF){ |
| | | if(locMast.getBay1()<locMast1.getBay1()){ |
| | | locNo=locMast1.getLocNo(); |
| | | } |
| | | //生成移库任务 |
| | | if(locNo!=null){ |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(0L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(11); // 入出库状态: 11.库格移载 |
| | | wrkMast.setIoPri(10D); |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setFullPlt("Y"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setBarcode(locMast.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | if (locMast.getLocSts().equals("F")) { |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | for (LocDetl locDetl : locDetls) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setAnfme(locDetl.getAnfme()); |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts("R"); // R.出库预约 |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (locMast1.getLocSts().equals("O")) { |
| | | locMast1.setLocSts("S"); // S.入库预约 |
| | | locMast1.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast1)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | if (locNo !=null){ |
| | | break; |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | } |
| | | |