| | |
| | | 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 com.zy.common.model.OrderDto; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.model.enums.WorkNoType; |
| | | import com.zy.common.service.AgvCommonService; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/6/11 |
| | |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private AdjDetlService adjDetlService; |
| | | @Autowired |
| | | private AgvWrkMastLogService agvWrkMastLogService; |
| | | @Autowired |
| | | private AgvWrkDetlLogService agvWrkDetlLogService; |
| | | |
| | | |
| | | /* |
| | |
| | | throw new CoolException("选中的站点中含有货位状态不为F.在库的站点,请重新选择"); |
| | | } |
| | | |
| | | List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("zpallet", agvBasDevp.getBarcode())); |
| | | List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("supp_code", agvBasDevp.getBarcode())); |
| | | |
| | | //检索库位,选择合适的库位 |
| | | AgvLocMast agvLocMast = agvCommonService.getLocNo(agvWaitPakinList, agvBasDevp.getFloor()); |
| | |
| | | //生成工作档明细 |
| | | //createWrkDetlReWrite(agvWaitPakinList,wrkMast,userId); |
| | | agvWaitPakinList.forEach(wp -> { |
| | | createWrkDetlReWrite(wp.getMatnr(),wrkMast.getWrkNo(),wp.getOrderNo(),wp.getBatch(),wp.getAnfme(),wp.getZpallet(),now,userId,wp.getThreeCode(),wp.getDeadTime()); |
| | | createWrkDetlReWrite(wp.getMatnr(),wrkMast.getWrkNo(),wp.getOrderNo(),wp.getBatch(),wp.getAnfme(),wp.getSuppCode(),now,userId,wp.getThreeCode(),wp.getDeadTime()); |
| | | }); |
| | | //更新源站点信息 |
| | | updateAgvBasDevp(agvBasDevp,"R"); |
| | |
| | | long wrkSts = 21L; |
| | | String sourceLocNo = taskDto.getLocNo(); |
| | | String targetLocNo = taskDto.getAgvStaNo(); |
| | | String barcode = agvLocDetl.getZpallet(); |
| | | String barcode = agvLocDetl.getSuppCode(); |
| | | //明细档所需参数 |
| | | String mantr = taskDto.getLocDtos().get(0).getMatnr(); |
| | | String orderNo = taskDto.getLocDtos().get(0).getOrderNo(); |
| | |
| | | Date now = new Date(); |
| | | |
| | | //生成工作党 |
| | | AgvWrkMast wrkMast = createWrkMast(107, 21L, locDetl.getLocNo(), agvBasDevp.getDevNo(), agvLocDetl.getZpallet(), now, userId); |
| | | AgvWrkMast wrkMast = createWrkMast(107, 21L, locDetl.getLocNo(), agvBasDevp.getDevNo(), agvLocDetl.getSuppCode(), now, userId); |
| | | //生成工作明细档 |
| | | createWrkDetlReWrite(locDetl.getMatnr(),wrkMast.getWrkNo(),null,locDetl.getBatch(),locDetl.getCount(),wrkMast.getBarcode(),now,userId,agvLocDetl.getThreeCode(),agvLocDetl.getDeadTime()); |
| | | //修改库位信息 |
| | |
| | | |
| | | Date now = new Date(); |
| | | //生成移库工作档 |
| | | AgvWrkMast wrkMast = createWrkMast(11, 21L, sourceLocNo, targetLocNo, sourceLocDetl.getZpallet(), now, userId); |
| | | AgvWrkMast wrkMast = createWrkMast(11, 21L, sourceLocNo, targetLocNo, sourceLocDetl.getSuppCode(), now, userId); |
| | | //生成工作党明细 |
| | | createWrkDetlReWrite(sourceLocDetl.getMatnr(),wrkMast.getWrkNo(),null,sourceLocDetl.getBatch(),sourceLocDetl.getAnfme(),sourceLocDetl.getZpallet(),now,userId,sourceLocDetl.getThreeCode(),sourceLocDetl.getDeadTime()); |
| | | //修改目标库位状态 |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void completeWrkMast(String workNo, Long userId) { |
| | | AgvWrkMast wrkMast = agvWrkMastService.selectById(workNo); |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | } |
| | | if (wrkMast.getWrkSts() == 9 || wrkMast.getWrkSts() == 29) { |
| | | throw new CoolException("当前工作档已完成"); |
| | | } |
| | | // 入库 + 库位转移 |
| | | 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 |
| | | public void cancelWrkMast(String workNo, Long userId) { |
| | | AgvWrkMast wrkMast = agvWrkMastService.selectById(workNo); |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() == 200) { |
| | | //小车移库任务,直接删除工作档 |
| | | agvWrkMastService.deleteById(wrkMast); |
| | | return; |
| | | } |
| | | |
| | | String locNo = ""; // 待修改目标库位 |
| | | String locSts = ""; // 待修改目标库位状态 |
| | | // 入库取消(修改目标库位) |
| | | if (wrkMast.getWrkSts() < 9) { |
| | | locNo = wrkMast.getLocNo(); |
| | | locSts = "O"; |
| | | |
| | | // 库位转移 |
| | | 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 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); |
| | | } |
| | | locMast.setLocSts(locSts); |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(userId); |
| | | boolean locMastRes = agvLocMastService.updateById(locMast); |
| | | if (!wrkMastRes || !locMastRes) { |
| | | throw new CoolException("保存数据失败"); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | 更新目标库位信息 |
| | | */ |
| | |
| | | wrkDetl.setIoTime(now); |
| | | wrkDetl.setBatch(batch); |
| | | wrkDetl.setAnfme(anfme); // 数量 |
| | | wrkDetl.setZpallet(zpallet); // 托盘条码 |
| | | wrkDetl.setSuppCode(zpallet); // 托盘条码 |
| | | wrkDetl.setAppeUser(userId); |
| | | wrkDetl.setAppeTime(now); |
| | | wrkDetl.setModiUser(userId); |
| | |
| | | private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode, Date now, Long userId){ |
| | | AgvWrkMast wrkMast = new AgvWrkMast(); |
| | | //生成工作号 |
| | | int workNo = agvCommonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); |
| | | wrkMast.setWrkNo(workNo); |
| | | // int workNo = agvCommonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); |
| | | // wrkMast.setWrkNo(); |
| | | //工作状态 |
| | | wrkMast.setWrkSts(wrkSts); |
| | | //入出库类型 |
| | |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiUser(userId); |
| | | wrkMast.setModiTime(now); |
| | | if (!agvWrkMastService.insert(wrkMast)) { |
| | | |
| | | if (!agvWrkMastService.insertByIncrease(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | int i = agvWrkMastService.selectCount(new EntityWrapper<AgvWrkMast>()); |
| | | log.info(i + ""); |
| | | |
| | | |
| | | wrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locNo).eq("source_loc_no",sourceLocNo)); |
| | | |
| | | return wrkMast; |
| | | } |
| | |
| | | private AgvWrkMast createWrkMast(AgvBasDevp agvBasDevp,AgvLocMast agvLocMast, Date now, Long userId){ |
| | | AgvWrkMast wrkMast = new AgvWrkMast(); |
| | | //生成工作号 |
| | | int workNo = agvCommonService.getWorkNo(0); |
| | | wrkMast.setWrkNo(workNo); |
| | | //int workNo = agvCommonService.getWorkNo(0); |
| | | //wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | // 工作状态:201.生成入库任务ID |
| | | wrkMast.setWrkSts(201L); |