| | |
| | | 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.asrs.entity.param.LocDetlAdjustParam; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.model.OrderDto; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.service.AgvCommonService; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/6/11 |
| | |
| | | 入库 |
| | | */ |
| | | @Transactional |
| | | public StartupDto createWaitPainWrkMastStart(List<AgvBasDevp> agvBasDevpList, Long userId) { |
| | | @Synchronized |
| | | public StartupDto createWaitPainWrkMastStart(List<AgvBasDevp> agvBasDevpList, Long userId, boolean isConveyor) { |
| | | |
| | | Date now = new Date(); |
| | | |
| | |
| | | AgvLocMast agvLocMast = agvCommonService.getLocNo(agvWaitPakinList, agvBasDevp.getFloor()); |
| | | //生成工作档 |
| | | //AgvWrkMast wrkMast = createWrkMast(agvBasDevp, agvLocMast, now, userId); |
| | | AgvWrkMast wrkMast = createWrkMast(1,201L,agvBasDevp.getDevNo(),agvLocMast.getLocNo(),agvBasDevp.getBarcode(),now,userId); |
| | | AgvWrkMast wrkMast = createWrkMast(1,201L,agvBasDevp.getDevNo(),agvLocMast.getLocNo(),agvBasDevp.getBarcode(),now,userId, isConveyor); |
| | | //标记是否为输送线入库 |
| | | wrkMast.setMk(isConveyor ? "Y" : "N"); |
| | | //生成工作档明细 |
| | | //createWrkDetlReWrite(agvWaitPakinList,wrkMast,userId); |
| | | agvWaitPakinList.forEach(wp -> { |
| | |
| | | //判断是否全板出库 |
| | | int ioType = isPakOut(sourceLocNo,anfme) ? 101 : 103; |
| | | //生成工作档 |
| | | AgvWrkMast wrkMast = createWrkMast(ioType,wrkSts,sourceLocNo,targetLocNo,barcode,now,userId); |
| | | AgvWrkMast wrkMast = createWrkMast(ioType,wrkSts,sourceLocNo,targetLocNo,barcode,now,userId,false); |
| | | //生成工作档明细 |
| | | createWrkDetlReWrite(mantr,wrkMast.getWrkNo(),orderNo,batch,anfme,barcode,now,userId,csocode,isoseq); |
| | | //修改订单信息 |
| | |
| | | //拣料入库 |
| | | if(ioType == 53){ |
| | | //修改工作党明细 |
| | | agvWrkDetl.setAnfme(agvLocDetl.getAnfme() - agvWrkDetl.getAnfme()); |
| | | agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>().eq("wrk_no",agvWrkDetl.getWrkNo())); |
| | | //agvWrkDetl.setAnfme(agvLocDetl.getAnfme() - agvWrkDetl.getAnfme()); |
| | | //agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>().eq("wrk_no",agvWrkDetl.getWrkNo())); |
| | | //修改库存信息 |
| | | agvLocDetl.setAnfme(agvWrkDetl.getAnfme()); |
| | | agvLocDetl.setAnfme(agvLocDetl.getAnfme() - agvWrkDetl.getAnfme()); |
| | | agvLocDetlService.update(agvLocDetl,new EntityWrapper<AgvLocDetl>().eq("loc_no",agvLocDetl.getLocNo())); |
| | | } |
| | | //修改库位信息 |
| | |
| | | Date now = new Date(); |
| | | |
| | | //生成工作党 |
| | | AgvWrkMast wrkMast = createWrkMast(107, 21L, locDetl.getLocNo(), agvBasDevp.getDevNo(), agvLocDetl.getSuppCode(), now, userId); |
| | | AgvWrkMast wrkMast = createWrkMast(107, 21L, locDetl.getLocNo(), agvBasDevp.getDevNo(), agvLocDetl.getSuppCode(), now, userId,false); |
| | | //生成工作明细档 |
| | | 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.getSuppCode(), now, userId); |
| | | AgvWrkMast wrkMast = createWrkMast(11, 21L, sourceLocNo, targetLocNo, sourceLocDetl.getSuppCode(), now, userId,false); |
| | | //生成工作党明细 |
| | | createWrkDetlReWrite(sourceLocDetl.getMatnr(),wrkMast.getWrkNo(),null,sourceLocDetl.getBatch(),sourceLocDetl.getAnfme(),sourceLocDetl.getZpallet(),now,userId,sourceLocDetl.getThreeCode(),sourceLocDetl.getDeadTime()); |
| | | //修改目标库位状态 |
| | |
| | | // 检索库位 |
| | | AgvLocMast locMast = agvCommonService.getLocNo(null, agvBasDevp.getFloor()); |
| | | // 生成工作档 10.空板入库 |
| | | createWrkMast(10,201L,agvBasDevp.getDevNo(),locMast.getLocNo(),null,now,userId); |
| | | createWrkMast(10,201L,agvBasDevp.getDevNo(),locMast.getLocNo(),null,now,userId,false); |
| | | //更新源站点状态 |
| | | updateAgvBasDevp(agvBasDevp,"R"); |
| | | //更新目标库位状态 |
| | |
| | | .eq("station_code", param.getStationCode()) |
| | | .eq("loc_sts", "O")); |
| | | //生成工作档 |
| | | createWrkMast(110,21L,locNo,agvBasDevp.getDevNo(),null,now,userId); |
| | | createWrkMast(110,21L,locNo,agvBasDevp.getDevNo(),null,now,userId,false); |
| | | //修改源库位状态 |
| | | updateAgvLocMast(agvLocMast,"R"); |
| | | //修改目标工作位状态 |
| | |
| | | adjDetl.setAppeTime(now); |
| | | adjDetl.setAppeUser(userId); |
| | | |
| | | UUID uuid = UUID.randomUUID(); |
| | | adjDetl.setOrderNo(uuid.toString()); |
| | | adjDetl.setOrderNo(Utils.generateAdjustOrderNo()); |
| | | |
| | | adjDetl.setCsocode(locDetl.getThreeCode()); |
| | | adjDetl.setIsoseq(locDetl.getDeadTime()); |
| | | |
| | |
| | | adjDetl.setModiUser(userId); |
| | | adjDetl.setAppeTime(now); |
| | | adjDetl.setAppeUser(userId); |
| | | adjDetl.setOrderNo(Utils.generateAdjustOrderNo()); |
| | | |
| | | adjDetlService.save(adjDetl, userId); |
| | | } |
| | |
| | | adjDetl.setAppeTime(now); |
| | | adjDetl.setAppeUser(userId); |
| | | |
| | | UUID uuid = UUID.randomUUID(); |
| | | adjDetl.setOrderNo(uuid.toString()); |
| | | adjDetl.setOrderNo(Utils.generateAdjustOrderNo()); |
| | | adjDetl.setCsocode(locDetl.getThreeCode()); |
| | | adjDetl.setIsoseq(locDetl.getDeadTime()); |
| | | |
| | |
| | | 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("删除失败,请联系管理员"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* |
| | |
| | | /* |
| | | 生成工作档 |
| | | */ |
| | | private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode, Date now, Long userId){ |
| | | private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode, Date now, Long userId, boolean isConveyor){ |
| | | AgvWrkMast wrkMast = new AgvWrkMast(); |
| | | //生成工作号 |
| | | // int workNo = agvCommonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); |
| | |
| | | wrkMast.setLocNo(locNo); |
| | | //容器编码 |
| | | wrkMast.setBarcode(barcode); |
| | | //标记是否为输送线入库 |
| | | wrkMast.setMk(isConveyor ? "Y" : "N"); |
| | | // 满板:Y |
| | | //wrkMast.setFullPlt("Y"); |
| | | // 拣料 |
| | |
| | | orderService.updateSettle(orderDetl.getOrderId(), 2L, userId); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |