| | |
| | | package com.zy.asrs.wms.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.common.domain.dto.LocDto; |
| | | import com.zy.asrs.common.domain.dto.OrderDto; |
| | | import com.zy.asrs.common.domain.dto.ReportStockDto; |
| | | import com.zy.asrs.common.domain.dto.TaskDto; |
| | | import com.zy.asrs.common.sys.service.StaDescService; |
| | | import com.zy.asrs.common.web.BaseController; |
| | | import com.zy.asrs.common.wms.entity.LocDetl; |
| | | import com.zy.asrs.common.wms.entity.OrderDetl; |
| | | import com.zy.asrs.common.wms.entity.*; |
| | | import com.zy.asrs.common.wms.service.*; |
| | | import com.zy.asrs.framework.annotations.ManagerAuth; |
| | | import com.zy.asrs.framework.common.BaseRes; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 2022/3/26 |
| | |
| | | if (Cools.isEmpty(ids)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | Long hostId = getHostId(); |
| | | List<OrderDetl> orderDetls = orderDetlService.listByIds(ids); |
| | | List<LocDto> locDtos = new ArrayList<>(); |
| | | |
| | | Set<String> exist = new HashSet<>(); |
| | | |
| | | List<String> matnrs = new ArrayList<>(); |
| | | List<LocDto> locDtoss = new ArrayList<>(); |
| | | |
| | | //获取所有的物料名称 |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getOrigin(), exist); |
| | | LocDto locDto = new LocDto(); |
| | | matnrs.add(orderDetl.getMatnr()); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | locDto.setMatnr(orderDetl.getMatnr()); |
| | | locDto.setAnfme(issued); |
| | | locDto.setMaktx(orderDetl.getMaktx()); |
| | | locDto.setOrderNo(orderDetl.getOrderNo()); |
| | | locDtoss.add(locDto); |
| | | } |
| | | |
| | | //对物料数进行排序 |
| | | List<ReportStockDto> stock = locDetlService.getStock(matnrs); |
| | | |
| | | Boolean boo1 = false; |
| | | for (ReportStockDto reportStockDto : stock) { |
| | | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | .eq(LocDetl::getLocNo, reportStockDto.getLocNo()) |
| | | .eq(LocDetl::getHostId, hostId)); |
| | | if (Cools.isEmpty(locDetls)) { |
| | | continue; |
| | | } |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (!Cools.isEmpty(locDetl.getMemo())){ |
| | | continue; |
| | | } |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103); |
| | | locDto.setStaNos(staNos); |
| | | locDtos.add(locDto); |
| | | exist.add(locDetl.getLocNo()); |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } else { |
| | | if(Cools.isEmpty(locDtoss)){ |
| | | boo1=true; |
| | | break; |
| | | } |
| | | for (LocDto locDto1 : locDtoss) { |
| | | if (locDto1.getMatnr().equals(locDetl.getMatnr())) { |
| | | if (locDto1.getAnfme() <= 0.0D) { |
| | | continue; |
| | | } |
| | | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), locDto1.getOrderNo(), |
| | | locDto1.getAnfme() >= locDetl.getAnfme() ? locDetl.getAnfme() : locDto1.getAnfme()); |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), ((locDto1.getAnfme() >= locDetl.getAnfme()) && (reportStockDto.getAnfme() == 1)) ? 101 : 103, hostId); |
| | | locDto.setStaNos(staNos); |
| | | locDtos.add(locDto); |
| | | exist.add(locDetl.getLocNo()); |
| | | // 剩余待出数量递减 |
| | | if(locDto1.getAnfme() - locDetl.getAnfme()==0){ |
| | | locDtoss.remove(locDto1); |
| | | }else{ |
| | | locDto1.setAnfme(locDto1.getAnfme() - locDetl.getAnfme()); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDtos.add(locDto); |
| | | if(boo1){ |
| | | break; |
| | | } |
| | | } |
| | | if (!boo1) { |
| | | for(LocDto locDto : locDtoss){ |
| | | if (locDto.getAnfme() > 0) { |
| | | List<LocDetl> locDetls1 = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | .eq(LocDetl::getMatnr, locDto.getMatnr()).eq(LocDetl::getHostId, hostId)); |
| | | boolean boo = false; |
| | | if (Cools.isEmpty(locDetls1)) { |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDtos.add(locDto); |
| | | } else { |
| | | for (LocDetl locDetl : locDetls1 |
| | | ) { |
| | | String locNo = locDetl.getLocNo().substring(1, 2); |
| | | if (Integer.valueOf(locNo) > 4) { |
| | | boo = true; |
| | | // LocDto locDto = new LocDto("在平库", orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDto.setLocNo("在平库"); |
| | | locDtos.add(locDto); |
| | | break; |
| | | } |
| | | } |
| | | if (!boo) { |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | locDto.setLocNo(null); |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDtos.add(locDto); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok().add(locDtos); |
| | | } |
| | | |
| | | // @PostMapping("/out/pakout/preview/auth") |
| | | // @ManagerAuth |
| | | // public R pakoutPreview(@RequestBody List<Long> ids) { |
| | | // if (Cools.isEmpty(ids)) { |
| | | // return R.parse(BaseRes.PARAM); |
| | | // } |
| | | // Long hostId = getHostId(); |
| | | // List<OrderDetl> orderDetls = orderDetlService.listByIds(ids); |
| | | // List<LocDto> locDtos = new ArrayList<>(); |
| | | // |
| | | // Set<String> exist = new HashSet<>(); |
| | | // |
| | | // //标记库位 |
| | | // HashMap<String,Integer> hm = new HashMap<>(); |
| | | // |
| | | // for (OrderDetl orderDetl : orderDetls) { |
| | | // double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | // if (issued <= 0.0D) { |
| | | // continue; |
| | | // } |
| | | // if(!Cools.isEmpty(hm)){ |
| | | // for(HashMap.Entry<String,Integer> entry:hm.entrySet()){ |
| | | // List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | // .eq(LocDetl::getHostId, hostId) |
| | | // .eq(LocDetl::getLocNo, entry.getKey()) |
| | | // .eq(LocDetl::getMatnr, orderDetl.getMatnr())); |
| | | // for (LocDetl locDetl : locDetls) { |
| | | // List<LocDetl> locMats = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | // .eq(LocDetl::getLocNo, locDetl.getLocNo()) |
| | | // .eq(LocDetl::getHostId, hostId)); |
| | | // if (issued > 0) { |
| | | // LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | // issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), ((issued >= locDetl.getAnfme()) && (locMats.size() == 1)) ? 101 : 103, hostId); |
| | | // locDto.setStaNos(staNos); |
| | | // locDtos.add(locDto); |
| | | // exist.add(locDetl.getLocNo()); |
| | | // // 剩余待出数量递减 |
| | | // issued = issued - locDetl.getAnfme(); |
| | | // hm.put(locDetl.getLocNo(), 1); |
| | | // } else { |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // if (issued >0){ |
| | | // List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), hostId); |
| | | // for (LocDetl locDetl : locDetls) { |
| | | // //过滤掉在已被标记的库位号 |
| | | // boolean boo=false; |
| | | // for (HashMap.Entry<String,Integer> entry:hm.entrySet()) { |
| | | // if(locDetl.getLocNo().equals(entry.getKey())){ |
| | | // boo=true; |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (boo){ |
| | | // continue; |
| | | // } |
| | | // List<LocDetl> locMats = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | // .eq(LocDetl::getLocNo, locDetl.getLocNo()) |
| | | // .eq(LocDetl::getHostId, hostId)); |
| | | // if (issued > 0) { |
| | | // LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | // issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), ((issued >= locDetl.getAnfme()) && (locMats.size() == 1)) ? 101 : 103, hostId); |
| | | // locDto.setStaNos(staNos); |
| | | // locDtos.add(locDto); |
| | | // exist.add(locDetl.getLocNo()); |
| | | // // 剩余待出数量递减 |
| | | // issued = issued - locDetl.getAnfme(); |
| | | // hm.put(locDetl.getLocNo(), 1); |
| | | // } else { |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), hostId); |
| | | // for (LocDetl locDetl : locDetls) { |
| | | // List<LocDetl> locMats = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | // .eq(LocDetl::getLocNo, locDetl.getLocNo()) |
| | | // .eq(LocDetl::getHostId, hostId)); |
| | | // if (issued > 0) { |
| | | // LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | // issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), ((issued >= locDetl.getAnfme()) && (locMats.size() == 1)) ? 101 : 103, hostId); |
| | | // locDto.setStaNos(staNos); |
| | | // locDtos.add(locDto); |
| | | // exist.add(locDetl.getLocNo()); |
| | | // // 剩余待出数量递减 |
| | | // issued = issued - locDetl.getAnfme(); |
| | | // hm.put(locDetl.getLocNo(), 1); |
| | | // } else { |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // if (issued > 0) { |
| | | // List<LocDetl> locDetls1 = locDetlService.list(new LambdaQueryWrapper<LocDetl>() |
| | | // .eq(LocDetl::getMatnr, orderDetl.getMatnr()).eq(LocDetl::getHostId, hostId)); |
| | | // boolean boo = false; |
| | | // if (Cools.isEmpty(locDetls1)) { |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // locDto.setLack(Boolean.TRUE); |
| | | // locDtos.add(locDto); |
| | | // } else { |
| | | // for (LocDetl locDetl : locDetls1 |
| | | // ) { |
| | | // String locNo = locDetl.getLocNo().substring(1, 2); |
| | | // if (Integer.valueOf(locNo) > 4) { |
| | | // boo = true; |
| | | // LocDto locDto = new LocDto("在平库", orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // locDto.setLack(Boolean.TRUE); |
| | | // locDtos.add(locDto); |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (!boo) { |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // locDto.setLack(Boolean.TRUE); |
| | | // locDtos.add(locDto); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // return R.ok().add(locDtos); |
| | | // } |
| | | |
| | | @PostMapping("/out/pakout/auth") |
| | | @ManagerAuth(memo = "订单出库") |
| | | public synchronized R pakout(@RequestBody List<LocDto> locDtos) throws InterruptedException { |
| | | if (Cools.isEmpty(locDtos)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | Long hostId = getHostId(); |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | | } |
| | | } |
| | | if (lack) { |
| | | return R.error("库存不足"); |
| | | } |
| | | |
| | | Thread.sleep(500L); |
| | | |
| | | // 订单预校验 ===>> 1.订单状态; 2.订单带出数量 |
| | | List<OrderDto> orderDtos = new ArrayList<>(); |
| | | for (LocDto locDto : locDtos) { |
| | | if (Cools.isEmpty(locDto.getOrderNo())) { |
| | | continue; |
| | | } |
| | | OrderDto orderDto = new OrderDto(locDto.getOrderNo(), locDto.getMatnr(), locDto.getAnfme()); |
| | | if (OrderDto.has(orderDtos, orderDto)) { |
| | | OrderDto dto = OrderDto.find(orderDtos, orderDto); |
| | | assert dto != null; |
| | | dto.setAnfme(dto.getAnfme() + orderDto.getAnfme()); |
| | | } else { |
| | | orderDtos.add(orderDto); |
| | | } |
| | | } |
| | | for (OrderDto orderDto : orderDtos) { |
| | | Order order = orderService.selectByNo(orderDto.getOrderNo(), hostId); |
| | | if (order.getSettle() > 2) { |
| | | return R.error(orderDto.getOrderNo() + "订单已失效,请及时刷新页面"); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), orderDto.getMatnr(), null, getHostId()); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | return R.error("没有找到订单明细"); |
| | | } |
| | | int oerderDetlCount = orderDetlService.count(new LambdaQueryWrapper<OrderDetl>() |
| | | .eq(OrderDetl::getOrderId, order.getId()).eq(OrderDetl::getMatnr, orderDto.getMatnr()).eq(OrderDetl::getHostId, getHostId())); |
| | | if (oerderDetlCount > 1) { |
| | | return R.error("同一订单不允许有相同物料"); |
| | | } |
| | | if (orderDetl.getAnfme() - orderDetl.getQty() < orderDto.getAnfme()) { |
| | | return R.ok(orderDto.getOrderNo() + "订单已作业,请及时刷新页面"); |
| | | } |
| | | } |
| | | |
| | | List<TaskDto> taskDtos = new ArrayList<>(); |
| | | // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 |
| | | for (LocDto locDto : locDtos) { |
| | | if (locDto.isLack()) { |
| | | continue; |
| | | } |
| | | //2022-08-04 Add,防止前端页面提取库位信息后,在其他地方对该库位生成了出库任务(库位状态非F状态) |
| | | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>() |
| | | .eq(LocMast::getLocNo, locDto.getLocNo()) |
| | | .eq(LocMast::getHostId, hostId)); |
| | | if (locMast.getWhsType() != 0) { |
| | | continue; |
| | | } |
| | | if (!Cools.isEmpty(locMast) && !locMast.getLocSts().equals("F")) { |
| | | return R.error("库位号非在库状态,请重新选择出库库位===>>" + locDto.getLocNo()); |
| | | } |
| | | |
| | | TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto, hostId); |
| | | if (TaskDto.has(taskDtos, taskDto)) { |
| | | TaskDto dto = TaskDto.find(taskDtos, taskDto); |
| | | assert dto != null; |
| | | dto.getLocDtos().addAll(taskDto.getLocDtos()); |
| | | } else { |
| | | taskDtos.add(taskDto); |
| | | } |
| | | } |
| | | // ----------------------------------------------------------------------------------------------- |
| | | for (TaskDto taskDto : taskDtos) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo(), false, hostId); |
| | | workService.stockOut(staNo.getDevNo(), taskDto, getUserId(), hostId); |
| | | } |
| | | return R.ok("立体仓库生成出库任务成功,平库请使用PDA进行出库!!!"); |
| | | } |
| | | |
| | | } |