| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.StaDesc; |
| | | import com.zy.asrs.entity.WaitPakin; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.mapper.WaitPakinMapper; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.StaDescService; |
| | | import com.zy.asrs.service.WrkDetlService; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.CrnStatusType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.thread.DevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | /** |
| | |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.InSta inSta : devp.getInSta()) { |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | // 获取条码 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | String barcode = barcodeThread.getBarcode(); |
| | |
| | | StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInreq1() |
| | | && !staProtocol.isEmptyMk() && staProtocol.isInreq1() && staProtocol.getWorkNO() ==0 |
| | | && !staProtocol.isEmptyMk() && staProtocol.isInreq1() && staProtocol.getWorkNo() ==0 |
| | | && staProtocol.isPakMk() && !Cools.isEmpty(barcode)) { |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); |
| | |
| | | |
| | | // 更新站点信息 且 下发plc命令 |
| | | barcodeThread.setBarcode(""); |
| | | staProtocol.setWorkNO(workNo); |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(startupDto.getStaNo()); |
| | | staProtocol.setPakMk(false); |
| | | staProtocol.setInreq1(false); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 拣料、并板、盘点再入库 |
| | | */ |
| | | public void stnToCrnStnPick(){ |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历拣料入库口 |
| | | for (DevpSlave.Sta pickSta : devp.getPickSta()) { |
| | | // 获取拣料入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo()); |
| | | |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInreq1() |
| | | && staProtocol.getWorkNo() > 0 && staProtocol.isPakMk()){ |
| | | WrkMast wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo()); |
| | | if (wrkMast == null) { |
| | | // 无拣料数据 |
| | | continue; |
| | | } |
| | | if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 1070) |
| | | || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo()) ) { |
| | | continue; |
| | | } |
| | | // 保存工作明细档历史档 |
| | | if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) { |
| | | throw new CoolException("保存工作明细档历史档失败"); |
| | | } |
| | | // 保存工作主档历史档 |
| | | if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) { |
| | | throw new CoolException("保存工作主档历史档失败"); |
| | | } |
| | | // 获取目标站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", wrkMast.getIoType() - 50) |
| | | .eq("stn_no", wrkMast.getStaNo()) // 作业站点 = 拣料出库的目标站 |
| | | .eq("crn_no", wrkMast.getCrnNo()); // 堆垛机号 |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | throw new CoolException("入库路径不存在"); |
| | | } |
| | | // 堆垛机站点(目标站) |
| | | Integer staNo = staDesc.getCrnStn(); |
| | | // 更新工作档数据状态 |
| | | wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57 |
| | | wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走 |
| | | wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站 |
| | | wrkMast.setStaNo(staNo); // 目标站 |
| | | wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位 |
| | | wrkMast.setSourceLocNo(""); // 源库位清空 |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | throw new CoolException("更新工作档数据状态失败"); |
| | | } |
| | | // 修改库位状态 Q.拣料/盘点/并板再入库 |
| | | LocMast locMast = locMastService.selectById(wrkMast.getLocNo()); |
| | | locMast.setLocSts("Q"); |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("修改库位状态失败"); |
| | | } |
| | | |
| | | // 更新站点信息 且 下发plc命令 |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo()); |
| | | staProtocol.setStaNo(wrkMast.getStaNo()); |
| | | staProtocol.setPakMk(false); |
| | | staProtocol.setInreq1(false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task<>(4, staProtocol)); |
| | | if (!result) { |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 堆垛机站出库到出库站 |
| | | */ |
| | | public void crnStnToOutStn() { |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历拣料入库口 |
| | | for (DevpSlave.Sta outSta : devp.getOutSta()) { |
| | | // 获取堆垛机出库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo()); |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { |
| | | // 查询工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(staProtocol.getSiteId()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | // 判断工作档条件 |
| | | if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) { |
| | | continue; |
| | | } |
| | | // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) { |
| | | // 移动中 |
| | | continue; |
| | | } |
| | | // 更新工作档状态为14失败 todo:luxiaotao |
| | | if (crnProtocol.mode == 3 && crnProtocol.getTaskNo() == wrkMast.getWrkNo() |
| | | && crnProtocol.statusType == CrnStatusType.IDLE |
| | | && crnProtocol.forkPos==0) { |
| | | wrkMast.setWrkSts(14L); |
| | | wrkMast.setCrnEndTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | throw new CoolException("更新工作档的工作状态为14失败,工作号"+wrkMast.getWrkNo()); |
| | | } |
| | | } |
| | | |
| | | // 更新堆垛机信息 且 下发plc命令 todo:luxiaotao |
| | | crnProtocol.setStatus(CrnStatusType.IDLE); |
| | | crnProtocol.setTaskNo((short)0); |
| | | boolean result = MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(4, crnProtocol)); |
| | | if (!result) { |
| | | throw new CoolException("更新堆垛机信息失败"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 执行对工作档的入库完成 |
| | | */ |
| | | public void storeFinished() { |
| | | for (Slave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol.status == ) |
| | | |
| | | } |
| | | } |
| | | |
| | | } |