| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.service.impl.WorkServiceImpl; |
| | | import com.zy.asrs.utils.OutboundAllocationUtil; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.LocDetlDto; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.model.enums.IoWorkType; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | if (Cools.isEmpty(ids)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | |
| | | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); |
| | | List<LocDto> locDtos = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | if (orderDetl.getAnfme()-orderDetl.getWorkQty()-orderDetl.getQty()==0.0){ |
| | | continue; |
| | | } |
| | | LocDto locDto = new LocDto(orderDetl.getManu(), orderDetl.getMatnr(), orderDetl.getMaktx(),orderDetl.getModel(),orderDetl.getSpecs(), |
| | | orderDetl.getBatch(),orderDetl.getBrand(),orderDetl.getBarcode(), orderDetl.getOrderNo(),orderDetl.getAnfme()); |
| | | locDto.setOrderDetlId(orderDetl.getId()); |
| | | locDto.setTkType(orderDetl.getTkType()); |
| | | locDtos.add(locDto); |
| | | if (orderDetls.isEmpty()) { |
| | | return R.parse("请选择数据"); |
| | | } |
| | | |
| | | Order order = orderService.selectOne( |
| | | new EntityWrapper<Order>().eq("order_no", orderDetls.get(0).getOrderNo()) |
| | | ); |
| | | if (order == null) { |
| | | return R.parse("订单数据为空"); |
| | | } |
| | | |
| | | // 按包装组号分组处理 |
| | | Map<String, List<OrderDetl>> brandGroup = orderDetls.stream() |
| | | .collect(Collectors.groupingBy(OrderDetl::getBrand)); |
| | | |
| | | List<LocDto> locDtos = new ArrayList<>(); |
| | | |
| | | // Set<String> exist = new HashSet<>(); |
| | | // 每个包装组查一次库存 |
| | | for (Map.Entry<String, List<OrderDetl>> entry : brandGroup.entrySet()) { |
| | | String brand = entry.getKey(); |
| | | List<OrderDetl> brandOrderDetls = entry.getValue(); |
| | | |
| | | // for (OrderDetl orderDetl : orderDetls) { |
| | | // double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | // if (issued <= 0.0D) { continue; } |
| | | // List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist); |
| | | // for (LocDetl locDetl : locDetls) { |
| | | // 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) { |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // locDto.setLack(Boolean.TRUE); |
| | | // locDtos.add(locDto); |
| | | // } |
| | | // } |
| | | // 查这个包装组对应的所有库存 |
| | | List<LocDetl> locDetls = locDetlService.selectList( |
| | | new EntityWrapper<LocDetl>().eq("brand", brand) |
| | | ); |
| | | if (locDetls.isEmpty()) continue; |
| | | |
| | | // 获取出库口 |
| | | List<Integer> staNos = new ArrayList<>(); |
| | | if (order.getDocType() == 21) { |
| | | staNos.add(3077); staNos.add(3106); |
| | | } else if (order.getDocType() == 22) { |
| | | staNos.add(2041); |
| | | } else if (order.getDocType() == 23) { |
| | | staNos.add(3092); staNos.add(3102); staNos.add(3095); |
| | | } |
| | | |
| | | // 去重 key,避免相同 loc+unit+model 重复显示 |
| | | Set<String> seen = new HashSet<>(); |
| | | |
| | | for (LocDetl locDetl : locDetls) { |
| | | String key = locDetl.getLocNo() + "|" + locDetl.getUnit() + "|" + locDetl.getModel(); |
| | | if (seen.contains(key)) continue; |
| | | seen.add(key); |
| | | |
| | | // 对应多个明细时,分配到第一个明细(或你可以拆分多个) |
| | | OrderDetl firstDetl = brandOrderDetls.get(0); |
| | | |
| | | LocDto locDto = new LocDto(); |
| | | locDto.setLocNo(locDetl.getLocNo()); |
| | | locDto.setUnit(locDetl.getUnit()); |
| | | locDto.setModel(locDetl.getModel()); |
| | | locDto.setThreeCode(locDetl.getThreeCode()); |
| | | locDto.setBrand(brand); |
| | | locDto.setOrderNo(firstDetl.getOrderNo()); |
| | | locDto.setStaNos(staNos); |
| | | locDto.setOrderDetlId(firstDetl.getId()); |
| | | |
| | | locDtos.add(locDto); |
| | | } |
| | | } |
| | | |
| | | return R.ok().add(locDtos); |
| | | } |
| | | |
| | |
| | | @PostMapping("/out/pakout/auth") |
| | | @ManagerAuth(memo = "订单出库") |
| | | public synchronized R pakout(@RequestBody List<LocDto> locDtos) throws InterruptedException { |
| | | StockOutParam param = new StockOutParam(); |
| | | ArrayList<StockOutParam.LocDetl> locDetls = new ArrayList<>(); |
| | | for (LocDto locDto:locDtos){ |
| | | StockOutParam.LocDetl locDetl = new StockOutParam.LocDetl(); |
| | | locDetl.setBrand(locDto.getBrand()); |
| | | locDetl.setLocNo(locDto.getLocNo()); |
| | | locDetl.setAnfme(locDto.getAnfme()); |
| | | locDetl.setMatnr(locDto.getMatnr()); |
| | | locDetl.setBatch(locDto.getBatch()); |
| | | locDetl.setModel(locDto.getModel()); |
| | | locDetl.setSpecs(locDto.getSpecs()); |
| | | locDetl.setZpallet(locDto.getZpallet()); |
| | | |
| | | param.setOrderNo(locDto.getOrderNo()); |
| | | |
| | | locDetls.add(locDetl); |
| | | } |
| | | param.setLocDetls(locDetls); |
| | | |
| | | List<StockOutParam> stockOutParams = OutboundAllocationUtil.OutboundClassification(param); |
| | | for (StockOutParam stockOutParam : stockOutParams){ |
| | | workService.startupFullTakeStore(stockOutParam, getUserId()); |
| | | if (Cools.isEmpty(locDtos)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | |
| | | for (LocDto locDto:locDtos){ |
| | | OrderDetl orderDetl = orderDetlService.selectById(locDto.getOrderDetlId()); |
| | | orderDetl.setWorkQty(locDto.getAnfme()); |
| | | orderDetlService.updateById(orderDetl); |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | | } |
| | | } |
| | | if (lack) { |
| | | return R.error("库存不足"); |
| | | } |
| | | |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | order.setSettle(2L); |
| | | orderService.updateById(order); |
| | | Thread.sleep(1000L); |
| | | |
| | | List<StockOutParam> stockOutParams = new ArrayList<>(); |
| | | Map<Integer, StockOutParam> staNoMap = new HashMap<>(); |
| | | Set<String> processedKeys = new HashSet<>(); // 防止重复添加 brand+staNo |
| | | |
| | | // if (Cools.isEmpty(locDtos)) { |
| | | // return R.parse(BaseRes.PARAM); |
| | | // } |
| | | // boolean lack = true; |
| | | // for (LocDto locDto : locDtos) { |
| | | // if (!locDto.isLack()) { |
| | | // lack = false; |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (lack) { |
| | | // return R.error("库存不足"); |
| | | // } |
| | | // |
| | | // Thread.sleep(1000L); |
| | | // |
| | | // List<TaskDto> taskDtos = new ArrayList<>(); |
| | | // // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 |
| | | // for (LocDto locDto : locDtos) { |
| | | // if (locDto.isLack()) { continue; } |
| | | // TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto); |
| | | // 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()); |
| | | // workService.stockOut(staNo, taskDto, getUserId()); |
| | | // } |
| | | for (LocDto locDto : locDtos) { |
| | | Integer staNo = locDto.getStaNo(); |
| | | String brand = locDto.getBrand(); |
| | | String key = staNo + "_" + brand; |
| | | |
| | | // 获取或创建 StockOutParam(按出库口合并) |
| | | StockOutParam stockOutParam = staNoMap.get(staNo); |
| | | if (stockOutParam == null) { |
| | | stockOutParam = new StockOutParam(); |
| | | stockOutParam.setOutSite(staNo); |
| | | stockOutParam.setOrderNo(locDto.getOrderNo()); |
| | | stockOutParam.setLocDetls(new ArrayList<>()); |
| | | stockOutParams.add(stockOutParam); |
| | | staNoMap.put(staNo, stockOutParam); |
| | | } |
| | | |
| | | // 避免重复添加相同brand的数据 |
| | | if (processedKeys.contains(key)) continue; |
| | | processedKeys.add(key); |
| | | |
| | | List<LocDetl> locDetls1 = locDetlService.selectList( |
| | | new EntityWrapper<LocDetl>().eq("brand", brand)); |
| | | for (LocDetl locDetl : locDetls1) { |
| | | StockOutParam.LocDetl detl = new StockOutParam.LocDetl(); |
| | | detl.setLocNo(locDetl.getLocNo()); |
| | | detl.setBrand(locDetl.getBrand()); |
| | | detl.setModel(locDetl.getModel()); |
| | | detl.setCount(locDetl.getAnfme()); |
| | | stockOutParam.getLocDetls().add(detl); |
| | | } |
| | | } |
| | | |
| | | // 执行出库逻辑 |
| | | for (StockOutParam stockOutParam : stockOutParams) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(stockOutParam.getOutSite()); |
| | | |
| | | List<LocDetlDto> locDetlDtos = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl paramLocDetl : stockOutParam.getLocDetls()) { |
| | | LocDetl one = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", paramLocDetl.getLocNo()) |
| | | .eq("brand", paramLocDetl.getBrand()) |
| | | .eq("model", paramLocDetl.getModel())); |
| | | |
| | | if (one != null) { |
| | | // 判断是否为盘点单(docType == 23),如果不是则校验合格性 |
| | | Order order = orderService.selectByNo(stockOutParam.getOrderNo()); |
| | | if ( order.getDocType() != 23) { |
| | | if (!"合格".equals(one.getThreeCode())) { |
| | | throw new CoolException(one.getModel() + "卷不合格: " + one.getThreeCode()); |
| | | } |
| | | } |
| | | |
| | | locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount(), stockOutParam.getOrderNo())); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (!locDetlDtos.isEmpty()) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo())); |
| | | if ("F".equals(locMast.getLocSts()) || "D".equals(locMast.getLocSts())) { |
| | | Order order = orderService.selectByNo(stockOutParam.getOrderNo()); |
| | | workService.stockOut(staNo, locDetlDtos, |
| | | order.getDocType() != null && order.getDocType() == 23 |
| | | ? IoWorkType.CHECK_OUT : null, |
| | | getUserId()); |
| | | } else { |
| | | throw new CoolException("所选库位状态不为F/D,库位号:" + |
| | | locMast.getLocNo() + ",当前状态:" + |
| | | locMast.getLocSts() + "-" + locMast.getLocSts$()); |
| | | } |
| | | } else { |
| | | throw new CoolException("库存不存在"); |
| | | } |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/out/refund/loc/auth") |
| | | @ManagerAuth(memo = "订单出库") |
| | | public synchronized R refundLoc(@RequestBody List<LocDto> locDtos) throws InterruptedException { |