| | |
| | | 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.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<>(); |
| | | |
| | | //标记库位 |
| | | HashMap<String,Integer> hm = new HashMap<>(); |
| | | |
| | | 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); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (!Cools.isEmpty(locDetl.getMemo())){ |
| | | continue; |
| | | 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) { |
| | | 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 { |
| | | break; |
| | | if (issued >0){ |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), hostId); |
| | | for (LocDetl locDetl : locDetls) { |
| | | for (HashMap.Entry<String,Integer> entry:hm.entrySet()){ |
| | | if(locDetl.getLocNo().equals(entry.getKey())){ |
| | | 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) { |
| | | LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDtos.add(locDto); |
| | | 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进行出库!!!"); |
| | | } |
| | | |
| | | } |