package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.plugins.Page; import com.core.common.Cools; import com.core.common.DateUtils; import com.zy.asrs.entity.AgvBasDevp; import com.zy.asrs.entity.AgvWrkMast; import com.zy.asrs.service.AgvBasDevpService; import com.zy.asrs.service.AgvWrkMastService; import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.task.handler.AgvWrkMastHandler; 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.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 任务类型: *  putaway:上架。 *  carry:搬运,统指出库、移库、点到点搬运等。 *  scan:扫描盘点。 *  weight:称重盘点。 *  rfid:rfid盘点。 */ @Slf4j @Component public class AgvWrkMastScheduler { @Autowired AgvWrkMastHandler agvWrkMastHandler; @Autowired AgvWrkMastService agvWrkMastService; @Autowired AgvBasDevpService agvBasDevpService; /* 定时处理AGV工作档中工作状态为205.工作完成 且 (1.入库 || 53,拣料入库 || 57.盘点入库 || 10.空板入库 || 11.单层移库 || 12.跨层移库 || 108.自动调拨 || 109.手动调拨)的数据 */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 1000) public void excutePutwayWrk(){ List agvWrkMastList = agvWrkMastService.selectList(new EntityWrapper() .eq("wrk_sts", 205) .andNew().eq("io_type",53) .or().eq("io_type",1) .or().eq("io_type",57) .or().eq("io_type",58) .or().eq("io_type",10) .or().eq("io_type",11) .or().eq("io_type",12) .or().eq("io_type",108) .or().eq("io_type",109) .or().eq("io_type",111) .or().eq("io_type",112) .or().eq("io_type",113) .or().eq("io_type",114) .or().eq("io_type",121) ); if(!Cools.isEmpty(agvWrkMastList)){ agvWrkMastList.stream().forEach(agvWrkMast -> { try{ agvWrkMastHandler.completedPutWayWrk(agvWrkMast); } catch (Exception e){ log.error("工作号"+agvWrkMast.getWrkNo()+"定时处理AGV工作档中工作状态为205,处理失败:===》异常原因:"+e.getMessage()); } }); } } /* 定时处理AGV工作档中工作状态为206.出库完成 且 (101.出库 || 110.空板出库) */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 1000) public void excuteCarryWrk(){ List agvWrkMastList = agvWrkMastService.selectList(new EntityWrapper() .eq("wrk_sts", 206) .andNew().eq("io_type",110) .or().eq("io_type",101)); if(!Cools.isEmpty(agvWrkMastList)){ agvWrkMastList.stream().forEach(agvWrkMast -> { try{ agvWrkMastHandler.completedCarryWrk(agvWrkMast); } catch (Exception e){ //e.printStackTrace(); log.error("工作号"+agvWrkMast.getWrkNo()+"定时处理AGV工作档中工作状态为206,处理失败:===》异常原因:"+e.getMessage()); } }); } } /* 定时处理AGV工作档中工作状态为206.出库完成 且 (101.出库 || 110.空板出库) */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 1000) public void excuteCarryWrk2(){ List agvWrkMastList = agvWrkMastService.selectList(new EntityWrapper() .eq("wrk_sts", 208) .andNew().eq("io_type",110) .or().eq("io_type",101)); if(!Cools.isEmpty(agvWrkMastList)){ agvWrkMastList.stream().forEach(agvWrkMast -> { try{ agvWrkMastHandler.completedCarryWrk2(agvWrkMast); } catch (Exception e){ log.error("工作号"+agvWrkMast.getWrkNo()+"定时处理AGV工作档中工作状态为206,处理失败:===》异常原因:"+e.getMessage()); } }); } } /* putaway:上架 定时处理AGV工作档中工作状态为201.生成入库任务ID 且(出库类型为 53.拣料再入库 || 1.入库 || 10.空板入库栽 || 57.盘点再入库)的数据 */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 3000) public synchronized void startPutwayWrk(){ List agvWrkMastList = agvWrkMastService.selectPage(new Page<>(1, 50) ,new EntityWrapper() .eq("wrk_sts", 201) .andNew().eq("io_type", 53) .or().eq("io_type", 1) .or().eq("io_type", 10) .or().eq("io_type", 57) .or().eq("io_type", 58) .or().eq("io_type", 11) .or().eq("io_type", 12) .or().eq("io_type", 109) .or().eq("io_type", 108) .or().eq("io_type", 111) .or().eq("io_type", 112) .or().eq("io_type", 113) .or().eq("io_type", 114)).getRecords(); if(!Cools.isEmpty(agvWrkMastList)){ agvWrkMastList.forEach(agvWrkMast -> { try{ agvWrkMastHandler.startPutWayWrk(agvWrkMast); } catch (Exception e){ log.error("工作号"+agvWrkMast.getWrkNo()+"定时处理AGV工作档中工作状态为201,处理失败:===》异常原因:"+e.getMessage()); } }); } } /* putaway:上架 定时处理AGV工作档中工作状态为201.生成入库任务ID 且(出库类型为 53.拣料再入库 || 1.入库 || 10.空板入库栽 || 57.盘点再入库)的数据 */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 1000) public void startAllcationIn(){ List agvWrkMastList = agvWrkMastService.selectPage(new Page<>(1, 50) ,new EntityWrapper() .eq("wrk_sts", 211) .andNew().eq("io_type", 112)).getRecords(); if(!Cools.isEmpty(agvWrkMastList)){ agvWrkMastList.forEach(agvWrkMast -> { try { agvWrkMastHandler.startAllcationIn(agvWrkMast); } catch (IOException e) { log.error(e.getMessage()); } }); } } /* carry:搬运,统指出库、移库、点到点搬运等 定时处理AGV工作档中工作状态为21.生成出库任务 且(出库类型为 101.出库 || 103.拣料出库 || 11.库格移栽 || 110.空板出库 || 107.盘点出库)的数据 */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 2000) public void startCarryWrk(){ List agvWrkMastList = agvWrkMastService.selectPage(new Page<>(1, 50) ,new EntityWrapper() .eq("wrk_sts", 21) //.like("loc_no","@") .andNew().eq("io_type", 101) .or().eq("io_type", 103) .or().eq("io_type", 11) .or().eq("io_type", 110) .or().eq("io_type", 107) .or().eq("io_type", 109) .or().eq("io_type", 108)).getRecords(); if(!Cools.isEmpty(agvWrkMastList)){ List devNos = new ArrayList<>(); agvWrkMastList.forEach(agvWrkMast -> { try { //过滤该批工作档中重复的出站点 if (devNos.contains(agvWrkMast.getLocNo())){ return; } devNos.add(agvWrkMast.getLocNo()); //检测当前工作任务中的站点是否已有有作业中的任务 AgvWrkMast agvWrkMastWorking = agvWrkMastService.selectOne(new EntityWrapper() .eq("loc_no", agvWrkMast.getLocNo()) .ge("wrk_sts", 202L)); if(!Cools.isEmpty(agvWrkMastWorking)){ return; } agvWrkMastWorking = agvWrkMastService.selectOne(new EntityWrapper() .eq("source_loc_no",agvWrkMast.getLocNo()) .le("wrk_sts",204L)); if(!Cools.isEmpty(agvWrkMastWorking)){ return; } agvWrkMastHandler.startPutWayWrk(agvWrkMast); } catch (Exception e) { log.error("搬运,统指出库、移库、点到点搬运等"+e.getMessage()); } }); } } /* 定时处理等待执行的任务 工作状态为21.生成出库任务 且目标库位中不含@字符 */ //@Scheduled(cron = "0/10 * * * * ? ") public void dealWatiWrk(){ List agvWrkMastList = agvWrkMastService.selectReadyAgvWrkMast(); if(!Cools.isEmpty(agvWrkMastList)){ try { ReturnT returnT = agvWrkMastHandler.dealWatiWrk(agvWrkMastList); } catch (IOException e) { log.error(e.getMessage()); } } } /* 自动生成空板出库任务 */ //@Scheduled(cron = "0/1 * * * * ? ") @Scheduled(fixedDelay = 1000) public void autoEmptyOut(){ boolean packageEmptyAutoOUt = Cools.eq("Y",Parameter.get().getPackageEmptyAutoOUt()); boolean mateEmptyAutoOut = Cools.eq("Y",Parameter.get().getMateEmptyAutoOut()); boolean boxEmptyAutoOut = Cools.eq("Y",Parameter.get().getBoxEmptyAutoOut()); if(!packageEmptyAutoOUt && !mateEmptyAutoOut && !boxEmptyAutoOut){ return; } List locType1Condition = new ArrayList<>(); if(packageEmptyAutoOUt){ locType1Condition.add(1); } if(mateEmptyAutoOut){ locType1Condition.add(2); } if(boxEmptyAutoOut){ locType1Condition.add(3); } //找出需要补料的站点 Wrapper wrapper = new EntityWrapper() .eq("in_enable", "Y") .eq("loc_sts", "O") .in("loc_type1", locType1Condition); List agvBasDevpList = agvBasDevpService.selectList(wrapper); for (AgvBasDevp agvBasDevp : agvBasDevpList){ try { agvWrkMastHandler.autoEmptyOut(agvBasDevp); }catch (Exception e){ log.error(e.getMessage()); e.printStackTrace(); } } } }