| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.EmptyPlateOutParam; |
| | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/6/11 |
| | |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | } |
| | | if (wrkMast.getWrkSts() == 9 || wrkMast.getWrkSts() == 29) { |
| | | throw new CoolException("当前工作档已完成"); |
| | | |
| | | if(wrkMast.getWrkSts() > 202){ |
| | | //修改AGV工作档的工作状态为205.工作完成 |
| | | agvWrkMastService.updateWrkStsByWrkNo(wrkMast.getWrkNo(),205); |
| | | |
| | | //出库任务 101.出库 || 103.拣料出库 || 107.盘点出库 |
| | | if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103 || wrkMast.getIoType() == 107){ |
| | | //修改出库站点状态 |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(wrkMast.getLocNo(),"F",wrkMast.getBarcode()); |
| | | } |
| | | //出库任务 110.空板出库 |
| | | if(wrkMast.getIoType() == 110){ |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(wrkMast.getLocNo(),"F",wrkMast.getBarcode()); |
| | | } |
| | | } |
| | | // 入库 + 库位转移 |
| | | if (wrkMast.getWrkSts() < 9 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType()==11)) { |
| | | wrkMast.setWrkSts(9L); |
| | | // 出库 |
| | | } else if (wrkMast.getWrkSts() > 20) { |
| | | wrkMast.setWrkSts(29L); |
| | | } |
| | | Date now = new Date(); |
| | | wrkMast.setCrnStrTime(DateUtils.calculate(now, 1L, TimeUnit.SECONDS, true)); |
| | | wrkMast.setCrnEndTime(now); |
| | | wrkMast.setModiTime(now); |
| | | wrkMast.setModiUser(userId); |
| | | // 完成操作人员记录 |
| | | wrkMast.setManuType("手动完成"); |
| | | if (!agvWrkMastService.updateById(wrkMast)) { |
| | | throw new CoolException("修改工作档失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() == 200) { |
| | | //小车移库任务,直接删除工作档 |
| | | agvWrkMastService.deleteById(wrkMast); |
| | | return; |
| | | //拣料入库 盘点入库不可取消 |
| | | if(wrkMast.getIoType() == 53 || wrkMast.getIoType() == 57){ |
| | | throw new CoolException("当前任务不可取消"); |
| | | } |
| | | |
| | | String locNo = ""; // 待修改目标库位 |
| | | String locSts = ""; // 待修改目标库位状态 |
| | | // 入库取消(修改目标库位) |
| | | if (wrkMast.getWrkSts() < 9) { |
| | | locNo = wrkMast.getLocNo(); |
| | | locSts = "O"; |
| | | //AGV机器人未取货前取消 |
| | | if(wrkMast.getWrkSts() < 203){ |
| | | //入库取消 |
| | | if(wrkMast.getIoType() == 1 || wrkMast.getIoType() == 10){ |
| | | //源站点 |
| | | String devNo = wrkMast.getSourceLocNo(); |
| | | //目标库位 |
| | | String locNo = wrkMast.getLocNo(); |
| | | agvLocMastService.updateLocStsByLocNo(locNo,"O"); |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(devNo,"F",wrkMast.getBarcode()); |
| | | |
| | | // 库位转移 |
| | | if (wrkMast.getIoType() == 11) { |
| | | // 库位转移:源库位 |
| | | AgvLocMast locMast = agvLocMastService.selectById(wrkMast.getSourceLocNo()); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消库位转移失败,源库位不存在:"+ wrkMast.getSourceLocNo()); |
| | | } |
| | | locMast.setLocSts("F"); |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(userId); |
| | | agvLocMastService.updateById(locMast); |
| | | //出库取消 |
| | | }else { |
| | | //源库位 |
| | | String locNo = wrkMast.getSourceLocNo(); |
| | | //目标站点 |
| | | String devNo = wrkMast.getLocNo(); |
| | | agvLocMastService.updateLocStsByLocNo(locNo,"F"); |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(devNo,"O",""); |
| | | } |
| | | // 出库取消(修改源库位) |
| | | } else if (wrkMast.getWrkSts() > 20) { |
| | | locNo = wrkMast.getSourceLocNo(); |
| | | // 出库 ===>> F.在库 |
| | | if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) { |
| | | locSts = "F"; |
| | | // 空板出库 ===>> D.空桶/空栈板 |
| | | } else if (wrkMast.getIoType() == 110) { |
| | | locSts = "D"; |
| | | // 库位转移 ===>> D.空桶/空栈板 |
| | | } else if (wrkMast.getIoType() == 11) { |
| | | locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"D":"F"; |
| | | // 库位转移:目标库位 |
| | | AgvLocMast locMast = agvLocMastService.selectById(wrkMast.getLocNo()); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消库位转移失败,目标库位不存在:"+ wrkMast.getSourceLocNo()); |
| | | } |
| | | locMast.setLocSts("O"); |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(userId); |
| | | agvLocMastService.updateById(locMast); |
| | | } |
| | | } else { |
| | | throw new CoolException("当前工作状态无法取消"); |
| | | } |
| | | // 订单关联 |
| | | List<AgvWrkDetl> wrkDetls = agvWrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); |
| | | for (AgvWrkDetl wrkDetl : wrkDetls) { |
| | | if (!Cools.isEmpty(wrkDetl.getOrderNo())) { |
| | | if (!BaseController.isJSON(wrkDetl.getOrderNo())) { |
| | | if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) { |
| | | throw new CoolException("订单数据回滚失败"); |
| | | } |
| | | } else { |
| | | // 订单合并出库 |
| | | |
| | | //实际取消的出库数量 |
| | | Double wrkDetlAnfme = wrkDetl.getAnfme(); |
| | | //订单实际出库数量 |
| | | Double orderAnfme; |
| | | |
| | | List<OrderDto> orderDtoList = JSON.parseArray(wrkDetl.getOrderNo(), OrderDto.class); |
| | | for (OrderDto orderDto : orderDtoList) { |
| | | |
| | | if(wrkDetlAnfme > orderDto.getAnfme()){ |
| | | orderAnfme = orderDto.getAnfme(); |
| | | wrkDetlAnfme -= orderAnfme; |
| | | }else { |
| | | orderAnfme = wrkDetlAnfme; |
| | | } |
| | | |
| | | if (!orderDetlService.decrease(orderDto.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), orderAnfme)) { |
| | | throw new CoolException("订单数据回滚失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 取消操作人员记录 |
| | | wrkMast.setManuType("手动取消"); |
| | | wrkMast.setModiUser(userId); |
| | | wrkMast.setModiTime(new Date()); |
| | | if (!agvWrkMastService.updateById(wrkMast)) { |
| | | throw new CoolException("取消工作档失败"); |
| | | } |
| | | // 保存工作主档历史档 |
| | | if (!agvWrkMastLogService.save(wrkMast)) { |
| | | throw new CoolException("保存工作历史档失败, workNo = " + wrkMast.getWrkNo()); |
| | | } |
| | | // 删除工作主档 |
| | | boolean wrkMastRes = agvWrkMastService.deleteById(wrkMast); |
| | | |
| | | if (wrkMast.getIoType() != 10 && wrkMast.getIoType() != 110) { |
| | | // 保存工作明细档历史档 |
| | | if (!agvWrkDetlLogService.save(wrkMast.getWrkNo())) { |
| | | // throw new CoolException("保存工作明细历史档失败, workNo = " + wrkMast.getWrkNo()); |
| | | } |
| | | // 删除工作档明细 |
| | | boolean wrkDetlRes = agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", workNo)); |
| | | } |
| | | |
| | | // 修改库位状态 |
| | | AgvLocMast locMast = agvLocMastService.selectById(locNo); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消工作档失败,库位不存在:"+ locNo); |
| | | //订单回滚 |
| | | AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).get(0); |
| | | if(!Cools.isEmpty(agvWrkDetl.getOrderNo())){ |
| | | OrderDetl orderDetl = orderDetlService.selectByOrderNoAndMatnr(agvWrkDetl.getOrderNo(),agvWrkDetl.getMatnr(),agvWrkDetl.getThreeCode(),agvWrkDetl.getDeadTime()); |
| | | orderDetl.setQty(orderDetl.getQty() - agvWrkDetl.getAnfme()); |
| | | orderDetlService.updateById(orderDetl); |
| | | } |
| | | locMast.setLocSts(locSts); |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(userId); |
| | | boolean locMastRes = agvLocMastService.updateById(locMast); |
| | | if (!wrkMastRes || !locMastRes) { |
| | | throw new CoolException("保存数据失败"); |
| | | |
| | | //保存工作档以及明细 |
| | | agvWrkMastLogService.save(wrkMast); |
| | | agvWrkDetlLogService.save(wrkMast.getWrkNo()); |
| | | |
| | | //删除工作档以及明细 |
| | | if(!agvWrkMastService.deleteByWrkNo(wrkMast.getWrkNo()) || !agvWrkDetlService.deleteByWrkNo(wrkMast.getWrkNo())){ |
| | | throw new CoolException("删除失败,请联系管理员"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* |