package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.core.common.R; import com.zy.asrs.entity.AgvBasDevp; import com.zy.asrs.entity.WrkMastExecute; import com.zy.asrs.service.AgvBasDevpService; import com.zy.asrs.service.WrkMastExecuteService; import com.zy.asrs.task.handler.AutoMoveTwoAndThreeGoOneHandler; 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.Date; import java.util.List; // 自动移库 @Slf4j @Component public class AutoMoveTwoAndThreeGoOneScheduler { @Autowired private WrkMastExecuteService wrkMastExecuteService; @Autowired private AutoMoveTwoAndThreeGoOneHandler autoMoveTwoAndThreeGoOneHandler; @Autowired private AgvBasDevpService agvBasDevpService; /** * 执行agv_wrk_mast_execute任务 */ // @Scheduled(cron = "0/2 * * * * ? ") private void autoMove(){ List wrkMastExecuteList = wrkMastExecuteService.selectList(new EntityWrapper().eq("io_type", 121).eq("wrk_sts",0L)); for (WrkMastExecute wrkMastExecute:wrkMastExecuteList){ try{ if (true){ autoMoveTwoAndThreeGoOneHandler.start(wrkMastExecute); } }catch (Exception e){ log.error("执行agv_wrk_mast_execute任务异常===》异常原因:"+e.getMessage()); } } } /** * 下一步agv_wrk_mast_execute任务 */ // @Scheduled(cron = "0/2 * * * * ? ") private void autoMove2(){ List wrkMastExecuteList = wrkMastExecuteService.selectList(new EntityWrapper().eq("io_type", 121).eq("wrk_sts",3L)); for (WrkMastExecute wrkMastExecute:wrkMastExecuteList){ Date now = new Date(); try{ if (wrkMastExecute.getStatus()==2 && wrkMastExecute.getNowPosition()==1){ AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper().eq("dev_no", wrkMastExecute.getRoute()[1])); if (Cools.isEmpty(agvBasDevp) || !agvBasDevp.getLocSts().equals("F")){ continue; } //判断电梯忙不忙 int count = wrkMastExecuteService.selectCount(new EntityWrapper().eq("io_type", 121).eq("status", 2)); if(count<3){ wrkMastExecute.setStatus(3); wrkMastExecute.setWrkSts(0L); wrkMastExecute.setModiTime(now); wrkMastExecute.setEndPosition(4); wrkMastExecuteService.updateById(wrkMastExecute); updateAgvBasDevp(agvBasDevp,"R",agvBasDevp.getLocType2(),agvBasDevp.getBarcode()); } } }catch (Exception e){ log.error("执行agv_wrk_mast_execute任务异常===》异常原因:"+e.getMessage()); } } } /** * 下一步agv_wrk_mast_execute任务 */ // @Scheduled(cron = "0/2 * * * * ? ") private void autoMove3(){ List wrkMastExecuteList = wrkMastExecuteService.selectList(new EntityWrapper().eq("io_type", 121).eq("wrk_sts",2L)); for (WrkMastExecute wrkMastExecute:wrkMastExecuteList){ Date now = new Date(); try{ if (wrkMastExecute.getStatus()==2){ AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper().eq("dev_no", wrkMastExecute.getRoute()[wrkMastExecute.getEndPosition()])); if (Cools.isEmpty(agvBasDevp) || !agvBasDevp.getLocSts().equals("S")){ log.error("站点状态locsts参数有误:locSts:"+agvBasDevp.getLocSts$()); }else { wrkMastExecute.setWrkSts(wrkMastExecute.getWrkStsCode()); wrkMastExecute.setModiTime(now); wrkMastExecute.setNowPosition(wrkMastExecute.getEndPosition()); wrkMastExecuteService.updateById(wrkMastExecute); updateAgvBasDevp(agvBasDevp,"F",agvBasDevp.getLocType2(),agvBasDevp.getBarcode()); } }else if (wrkMastExecute.getStatus()==3 || wrkMastExecute.getStatus()==4){ AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper().eq("dev_no", wrkMastExecute.getRoute()[wrkMastExecute.getNowPosition()])); if (Cools.isEmpty(agvBasDevp) || !agvBasDevp.getLocSts().equals("R")){ log.error("站点状态locsts参数有误:locSts:"+agvBasDevp.getLocSts$()); }else { wrkMastExecute.setWrkSts(wrkMastExecute.getWrkStsCode()); wrkMastExecute.setModiTime(now); wrkMastExecute.setNowPosition(wrkMastExecute.getEndPosition()); wrkMastExecuteService.updateById(wrkMastExecute); agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvBasDevp.getDevNo(),"O","",(short)0); } }else if (wrkMastExecute.getStatus()==1){ wrkMastExecute.setWrkSts(wrkMastExecute.getWrkStsCode()); wrkMastExecute.setModiTime(now); wrkMastExecute.setNowPosition(wrkMastExecute.getEndPosition()); wrkMastExecuteService.updateById(wrkMastExecute); } }catch (Exception e){ log.error("执行agv_wrk_mast_execute任务异常===》异常原因:"+e.getMessage()); } } } private void updateAgvBasDevp(AgvBasDevp agvBasDevp, String locSts, Short continerType, String containerCode){ if(!Cools.isEmpty(agvBasDevp)){ agvBasDevp.setLocSts(locSts); agvBasDevp.setLocType2(continerType); agvBasDevp.setBarcode(containerCode); agvBasDevpService.updateById(agvBasDevp); } } }