From 5cd0e43a9261153e6c6f2b03f14079a401707a4b Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Sun, 28 Sep 2025 11:14:20 +0800 Subject: [PATCH] =?UTF-8?q?2025-09-28=20pda=20=E5=85=B6=E5=AE=83=E5=85=A5?= =?UTF-8?q?=E5=BA=93=20=E5=85=B6=E5=AE=83=E5=87=BA=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OtherInboundController.java | 12 - .../entity/OtherInboundTransRequestDto.java | 30 +++ .../other/entity/OtherInboundTransSubDto.java | 23 ++ .../entity/OtherOutboundTransRequestDto.java | 30 +++ .../entity/OtherOutboundTransSubDto.java | 23 ++ .../other/service/OtherInboundService.java | 6 - .../service/impl/OtherInboundServiceImpl.java | 218 +++++++++++++----- .../impl/OtherOutboundServiceImpl.java | 188 +++++++++++++-- 8 files changed, 432 insertions(+), 98 deletions(-) create mode 100644 src/main/java/com/gaotao/modules/other/entity/OtherInboundTransRequestDto.java create mode 100644 src/main/java/com/gaotao/modules/other/entity/OtherInboundTransSubDto.java create mode 100644 src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransRequestDto.java create mode 100644 src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransSubDto.java diff --git a/src/main/java/com/gaotao/modules/other/controller/OtherInboundController.java b/src/main/java/com/gaotao/modules/other/controller/OtherInboundController.java index ca93e34..0f654cc 100644 --- a/src/main/java/com/gaotao/modules/other/controller/OtherInboundController.java +++ b/src/main/java/com/gaotao/modules/other/controller/OtherInboundController.java @@ -41,18 +41,6 @@ public class OtherInboundController { } } - /** - * 获取其它入库历史 - */ - @RequestMapping("/getOtherInboundHistory") - public R getOtherInboundHistory(@RequestBody OtherInboundRequestDto dto) { - try { - return R.ok().put("data", otherInboundService.getOtherInboundHistory(dto.getSite())); - } catch (Exception e) { - return R.error(e.getMessage()); - } - } - /** * 确认其它出库 */ diff --git a/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransRequestDto.java b/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransRequestDto.java new file mode 100644 index 0000000..c98e4b7 --- /dev/null +++ b/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransRequestDto.java @@ -0,0 +1,30 @@ +package com.gaotao.modules.other.entity; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@Data +public class OtherInboundTransRequestDto { + + @NotNull(message = "site is not null") + private String site; + + private String transNo; + + private String transTypeDb; + + @NotNull(message = "transType is not null") + private String transType; + + private String remark; + + private String status; + + private String workOrderNo; + + private String warehouseId; + + private List subList; +} diff --git a/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransSubDto.java b/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransSubDto.java new file mode 100644 index 0000000..17d21be --- /dev/null +++ b/src/main/java/com/gaotao/modules/other/entity/OtherInboundTransSubDto.java @@ -0,0 +1,23 @@ +package com.gaotao.modules.other.entity; + +import lombok.Data; + +@Data +public class OtherInboundTransSubDto { + private Double itemNo; + private String partNo; + + private String subNo; + + private String batchNo; + + private String warehouseId; + + private String locationId; + + private String transQty; + + private String direction; + + private String wdrNo; +} diff --git a/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransRequestDto.java b/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransRequestDto.java new file mode 100644 index 0000000..1f8423c --- /dev/null +++ b/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransRequestDto.java @@ -0,0 +1,30 @@ +package com.gaotao.modules.other.entity; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@Data +public class OtherOutboundTransRequestDto { + + @NotNull(message = "site is not null") + private String site; + + private String transNo; + + private String transTypeDb; + + @NotNull(message = "transType is not null") + private String transType; + + private String remark; + + private String status; + + private String workOrderNo; + + private String warehouseId; + + private List subList; +} diff --git a/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransSubDto.java b/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransSubDto.java new file mode 100644 index 0000000..9733368 --- /dev/null +++ b/src/main/java/com/gaotao/modules/other/entity/OtherOutboundTransSubDto.java @@ -0,0 +1,23 @@ +package com.gaotao.modules.other.entity; + +import lombok.Data; + +@Data +public class OtherOutboundTransSubDto { + private Double itemNo; + private String partNo; + + private String subNo; + + private String batchNo; + + private String warehouseId; + + private String locationId; + + private String transQty; + + private String direction; + + private String wdrNo; +} diff --git a/src/main/java/com/gaotao/modules/other/service/OtherInboundService.java b/src/main/java/com/gaotao/modules/other/service/OtherInboundService.java index 59ab60d..9525c45 100644 --- a/src/main/java/com/gaotao/modules/other/service/OtherInboundService.java +++ b/src/main/java/com/gaotao/modules/other/service/OtherInboundService.java @@ -16,11 +16,5 @@ public interface OtherInboundService { */ void confirmOtherInbound(OtherInboundRequestDto dto); - /** - * 获取其它入库历史记录 - * @param site 站点 - * @return 历史记录列表 - */ - List getOtherInboundHistory(String site); } diff --git a/src/main/java/com/gaotao/modules/other/service/impl/OtherInboundServiceImpl.java b/src/main/java/com/gaotao/modules/other/service/impl/OtherInboundServiceImpl.java index f20f067..ad80285 100644 --- a/src/main/java/com/gaotao/modules/other/service/impl/OtherInboundServiceImpl.java +++ b/src/main/java/com/gaotao/modules/other/service/impl/OtherInboundServiceImpl.java @@ -11,11 +11,16 @@ import com.gaotao.modules.other.entity.OtherInboundRequestDto; import com.gaotao.modules.other.entity.OtherTransactionIfsDto; import com.gaotao.modules.other.service.OtherInboundService; import com.gaotao.modules.sys.entity.SysUserEntity; -import com.gaotao.modules.trans.entity.TransCommonRequestDto; -import com.gaotao.modules.trans.entity.TransCommonSubDto; +import com.gaotao.modules.other.entity.OtherInboundTransRequestDto; +import com.gaotao.modules.other.entity.OtherInboundTransSubDto; import com.gaotao.modules.trans.entity.TransDetail; +import com.gaotao.modules.trans.entity.TransDetailSub; import com.gaotao.modules.trans.entity.TransHeader; +import com.gaotao.modules.trans.entity.TransNoControl; +import com.gaotao.modules.trans.dao.TransDetailMapper; +import com.gaotao.modules.trans.service.TransDetailSubService; import com.gaotao.modules.trans.service.TransHeaderService; +import com.gaotao.modules.trans.service.TransNoControlService; import com.gaotao.modules.warehouse.entity.Location; import com.gaotao.modules.warehouse.service.InventoryStockService; import com.gaotao.modules.warehouse.service.LocationService; @@ -26,9 +31,8 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * 其它入库服务实现类 @@ -39,6 +43,15 @@ public class OtherInboundServiceImpl implements OtherInboundService { @Autowired private TransHeaderService transHeaderService; + @Autowired + private TransNoControlService transNoControlService; + + @Autowired + private TransDetailMapper transDetailMapper; + + @Autowired + private TransDetailSubService transDetailSubService; + @Autowired private HandlingUnitService handlingUnitService; @@ -63,15 +76,15 @@ public class OtherInboundServiceImpl implements OtherInboundService { // 2. 验证HandlingUnit List handlingUnits = validateHandlingUnits(dto); - // 3. 构建TransCommonRequestDto - TransCommonRequestDto transRequest = buildTransCommonRequest(dto, currentUser); + // 3. 构建OtherInboundTransRequestDto + OtherInboundTransRequestDto transRequest = buildOtherInboundTransRequest(dto, currentUser); // 4. 构建subList(从HandlingUnit获取信息) - List subList = buildSubList(handlingUnits, dto); + List subList = buildOtherInboundSubList(handlingUnits, dto); transRequest.setSubList(subList); - // 5. 调用通用的出入库方法生成记录和变更库存 - List detailList = transHeaderService.genTransAndChangeInventoryStock(transRequest, "IN"); + // 5. 调用独立的其它入库方法生成记录和变更库存 + List detailList = genOtherInboundTransAndChangeStock(transRequest, "IN"); // 6. 调用IFS接口同步入库信息 // for (TransDetail detail : detailList) { @@ -109,35 +122,6 @@ public class OtherInboundServiceImpl implements OtherInboundService { } } - @Override - public List getOtherInboundHistory(String site) { - // 查询其它入库的历史记录 - // 通过TransHeader查询transType为"OI"的记录 - try { - // 这里应该通过Mapper查询数据库 - // 暂时返回模拟数据,实际项目中需要实现具体的查询逻辑 - List historyList = new ArrayList<>(); - - // 可以添加一些模拟数据用于测试 - OtherInboundHistoryDto history1 = new OtherInboundHistoryDto(); - history1.setTransNo("OI" + new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + "001"); - history1.setPartNo("P001-BOLT-M8"); - history1.setPartDesc("M8螺栓 不锈钢材质"); - history1.setInboundQty(new BigDecimal("250")); - history1.setTargetLocationId("A01-01-01"); - history1.setOperatorName("张三"); - history1.setInboundReason("其它入库测试"); - history1.setInboundDate(new Date()); - history1.setSite(site); - - historyList.add(history1); - - return historyList; - } catch (Exception e) { - throw new XJException("查询其它入库历史失败: " + e.getMessage()); - } - } - /** * 验证目标库位 */ @@ -186,35 +170,28 @@ public class OtherInboundServiceImpl implements OtherInboundService { } /** - * 构建TransCommonRequestDto + * 构建OtherInboundTransRequestDto */ - private TransCommonRequestDto buildTransCommonRequest(OtherInboundRequestDto dto, SysUserEntity currentUser) { - TransCommonRequestDto transRequest = new TransCommonRequestDto(); + private OtherInboundTransRequestDto buildOtherInboundTransRequest(OtherInboundRequestDto dto, SysUserEntity currentUser) { + OtherInboundTransRequestDto transRequest = new OtherInboundTransRequestDto(); transRequest.setSite(dto.getSite()); transRequest.setTransType("OI"); // 其它入库类型 transRequest.setStatus("C"); // 完成状态 - // 构建备注信息 - StringBuilder remark = new StringBuilder("其它入库"); - if (dto.getInboundReason() != null && !dto.getInboundReason().trim().isEmpty()) { - remark.append(" - ").append(dto.getInboundReason()); - } - remark.append(" - 操作员: ").append(dto.getOperatorName()); - remark.append(" - 操作时间: ").append(dto.getOperateTime()); - - transRequest.setRemark(remark.toString()); - + // 构建备注信息 入库原因 + transRequest.setRemark(dto.getInboundReason()); + return transRequest; } /** * 构建subList */ - private List buildSubList(List handlingUnits, OtherInboundRequestDto dto) { - List subList = new ArrayList<>(); + private List buildOtherInboundSubList(List handlingUnits, OtherInboundRequestDto dto) { + List subList = new ArrayList<>(); for (HandlingUnit hu : handlingUnits) { - TransCommonSubDto subDto = new TransCommonSubDto(); + OtherInboundTransSubDto subDto = new OtherInboundTransSubDto(); subDto.setPartNo(hu.getPartNo()); subDto.setSubNo(hu.getUnitId()); subDto.setBatchNo(hu.getBatchNo()); @@ -230,6 +207,137 @@ public class OtherInboundServiceImpl implements OtherInboundService { return subList; } + /** + * 其它入库独立的事务生成和库存变更方法 + */ + @Transactional + public List genOtherInboundTransAndChangeStock(OtherInboundTransRequestDto dto, String fangxiang) { + SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String direction = ""; + if("OUT".equals(fangxiang)){ + direction = "-"; + }else{ + direction = "+"; + } + + //添加出入库header信息 + TransNoControl transNo = transNoControlService.getTransNo(dto.getSite(), dto.getTransType(), 8); + TransHeader transHeader = new TransHeader(); + transHeader.setSite(dto.getSite()); + transHeader.setTransNo(transNo.getNewTransNo()); + transHeader.setTransDate(new Date()); + transHeader.setTransTypeDb(dto.getTransType()); + + transHeader.setWarehouseId(dto.getWarehouseId()); + transHeader.setUserId(currentUser.getUserId().toString()); + transHeader.setUserName(currentUser.getUserDisplay()); + transHeader.setRemark(dto.getRemark()); + + transHeader.setStatus(dto.getStatus()); + transHeader.setStatusDb(dto.getStatus()); + transHeader.setOrderRef1(dto.getWorkOrderNo()); + transHeaderService.save(transHeader); + + List detailList = new ArrayList<>(); + List detailSubs = new ArrayList<>(); + + //保存sub + for (OtherInboundTransSubDto subDto : dto.getSubList()){ + TransDetailSub detailSub = new TransDetailSub(); + detailSub.setSite(dto.getSite()); + detailSub.setTransNo(transHeader.getTransNo()); + detailSub.setItemNo(subDto.getItemNo()); + detailSub.setSubNo(subDto.getSubNo()); + detailSub.setSubQty(Double.valueOf(subDto.getTransQty())); + detailSub.setDirection(subDto.getDirection()); + detailSub.setPartNo(subDto.getPartNo()); + detailSub.setBatchNo(subDto.getBatchNo()); + detailSub.setLocationId(subDto.getLocationId()); + detailSub.setOrderRef3(subDto.getWdrNo()); + detailSub.setOrderRef4(subDto.getWarehouseId()); + + // 更新HandlingUnit状态 + HandlingUnit handlingUnit = handlingUnitService.lambdaQuery() + .eq(HandlingUnit::getSite, dto.getSite()) + .eq(HandlingUnit::getUnitId, subDto.getSubNo()) + .one(); + + if (handlingUnit != null) { + if("OUT".equals(fangxiang)){ + handlingUnit.setInStockFlag("N"); + }else{ + handlingUnit.setInStockFlag("Y"); + // 入库时更新库位到目标库位 + handlingUnit.setLocationId(subDto.getLocationId()); + } + handlingUnit.setModifiedDate(new Date()); + handlingUnit.setModifiedBy(currentUser.getUserDisplay()); + handlingUnitService.updateById(handlingUnit); + } + + detailSubs.add(detailSub); + } + + //总计sub数量添加到list + Map, Double> collect = detailSubs.stream().collect( + Collectors.groupingBy(item -> Arrays.asList( + item.getSite(), + item.getPartNo(), + item.getBatchNo(), + item.getLocationId(), + item.getOrderRef3(), + item.getOrderRef4() + ), Collectors.summingDouble(TransDetailSub::getSubQty))); + + Double index = 1.0; + for (Map.Entry, Double> entry : collect.entrySet()) { + List key = entry.getKey(); + Double totalQty = entry.getValue(); + + TransDetail detail = new TransDetail(); + detail.setSite(dto.getSite()); + detail.setTransNo(transHeader.getTransNo()); + detail.setItemNo(index); + detail.setPartNo(key.get(1)); + detail.setBatchNo(key.get(2)); + detail.setLocationId(key.get(3)); + detail.setWdrNo(key.get(4)); + detail.setOrderRef4(key.get(5)); + detail.setTransQty(new BigDecimal(totalQty)); + detail.setDirection(direction); + detailList.add(detail); + index++; + } + transDetailMapper.batchInsert(detailList); + + //回写itemNo + for (TransDetailSub sub : detailSubs){ + for (int i = 0; i < detailList.size(); i++){ + if(detailList.get(i).getSite().equals(sub.getSite()) + && detailList.get(i).getPartNo().equals(sub.getPartNo()) + && detailList.get(i).getBatchNo().equals(sub.getBatchNo()) + && detailList.get(i).getLocationId().equals(sub.getLocationId()) + && detailList.get(i).getWdrNo().equals(sub.getOrderRef3()) + && detailList.get(i).getOrderRef4().equals(sub.getOrderRef4()) + ){ + sub.setItemNo(detailList.get(i).getItemNo()); + break; + } + } + } + for (TransDetailSub sub : detailSubs){ + transDetailSubService.save(sub); + } + + for(TransDetail detail : detailList){ + // 变更库存 + inventoryStockService.changeInventoryStock(detail.getSite(), detail.getOrderRef4(), detail.getPartNo(), + detail.getBatchNo(), detail.getLocationId(), detail.getTransQty(), detail.getWdrNo(), fangxiang); + } + + return detailList; + } + /** * 更新HandlingUnit状态 */ diff --git a/src/main/java/com/gaotao/modules/other/service/impl/OtherOutboundServiceImpl.java b/src/main/java/com/gaotao/modules/other/service/impl/OtherOutboundServiceImpl.java index f8011c3..9fb092f 100644 --- a/src/main/java/com/gaotao/modules/other/service/impl/OtherOutboundServiceImpl.java +++ b/src/main/java/com/gaotao/modules/other/service/impl/OtherOutboundServiceImpl.java @@ -9,10 +9,16 @@ import com.gaotao.modules.other.entity.OtherOutboundRequestDto; import com.gaotao.modules.other.entity.OtherTransactionIfsDto; import com.gaotao.modules.other.service.OtherOutboundService; import com.gaotao.modules.sys.entity.SysUserEntity; -import com.gaotao.modules.trans.entity.TransCommonRequestDto; -import com.gaotao.modules.trans.entity.TransCommonSubDto; +import com.gaotao.modules.other.entity.OtherOutboundTransRequestDto; +import com.gaotao.modules.other.entity.OtherOutboundTransSubDto; import com.gaotao.modules.trans.entity.TransDetail; +import com.gaotao.modules.trans.entity.TransDetailSub; +import com.gaotao.modules.trans.entity.TransHeader; +import com.gaotao.modules.trans.entity.TransNoControl; +import com.gaotao.modules.trans.dao.TransDetailMapper; +import com.gaotao.modules.trans.service.TransDetailSubService; import com.gaotao.modules.trans.service.TransHeaderService; +import com.gaotao.modules.trans.service.TransNoControlService; import com.gaotao.modules.warehouse.entity.InventoryStock; import com.gaotao.modules.warehouse.service.InventoryStockService; import org.apache.shiro.SecurityUtils; @@ -22,9 +28,8 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * 其它出库服务实现类 @@ -35,6 +40,15 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { @Autowired private TransHeaderService transHeaderService; + @Autowired + private TransNoControlService transNoControlService; + + @Autowired + private TransDetailMapper transDetailMapper; + + @Autowired + private TransDetailSubService transDetailSubService; + @Autowired private HandlingUnitService handlingUnitService; @@ -56,15 +70,15 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { // 2. 验证库存是否足够 validateInventoryStock(handlingUnits); - // 3. 构建TransCommonRequestDto - TransCommonRequestDto transRequest = buildTransCommonRequest(dto, currentUser); + // 3. 构建OtherOutboundTransRequestDto + OtherOutboundTransRequestDto transRequest = buildOtherOutboundTransRequest(dto, currentUser); // 4. 构建subList(从HandlingUnit获取信息) - List subList = buildSubList(handlingUnits); + List subList = buildOtherOutboundSubList(handlingUnits); transRequest.setSubList(subList); - // 5. 调用通用的出入库方法生成记录和变更库存 - List detailList = transHeaderService.genTransAndChangeInventoryStock(transRequest, "OUT"); + // 5. 调用独立的其它出库方法生成记录和变更库存 + List detailList = genOtherOutboundTransAndChangeStock(transRequest, "OUT"); // // 6. 调用IFS接口同步出库信息 // for (TransDetail detail : detailList) { @@ -188,23 +202,16 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { } /** - * 构建TransCommonRequestDto + * 构建OtherOutboundTransRequestDto */ - private TransCommonRequestDto buildTransCommonRequest(OtherOutboundRequestDto dto, SysUserEntity currentUser) { - TransCommonRequestDto transRequest = new TransCommonRequestDto(); + private OtherOutboundTransRequestDto buildOtherOutboundTransRequest(OtherOutboundRequestDto dto, SysUserEntity currentUser) { + OtherOutboundTransRequestDto transRequest = new OtherOutboundTransRequestDto(); transRequest.setSite(dto.getSite()); transRequest.setTransType("OO"); // 其它出库类型 transRequest.setStatus("C"); // 完成状态 - // 构建备注信息 - StringBuilder remark = new StringBuilder("其它出库"); - if (dto.getOutboundReason() != null && !dto.getOutboundReason().trim().isEmpty()) { - remark.append(" - ").append(dto.getOutboundReason()); - } - remark.append(" - 操作员: ").append(dto.getOperatorName()); - remark.append(" - 操作时间: ").append(dto.getOperateTime()); - - transRequest.setRemark(remark.toString()); + // 备注信息 出库原因 + transRequest.setRemark(dto.getOutboundReason()); return transRequest; } @@ -212,11 +219,11 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { /** * 构建subList */ - private List buildSubList(List handlingUnits) { - List subList = new ArrayList<>(); + private List buildOtherOutboundSubList(List handlingUnits) { + List subList = new ArrayList<>(); for (HandlingUnit hu : handlingUnits) { - TransCommonSubDto subDto = new TransCommonSubDto(); + OtherOutboundTransSubDto subDto = new OtherOutboundTransSubDto(); subDto.setPartNo(hu.getPartNo()); subDto.setSubNo(hu.getUnitId()); subDto.setBatchNo(hu.getBatchNo()); @@ -232,6 +239,137 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { return subList; } + /** + * 其它出库独立的事务生成和库存变更方法 + */ + @Transactional + public List genOtherOutboundTransAndChangeStock(OtherOutboundTransRequestDto dto, String fangxiang) { + SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String direction = ""; + if("OUT".equals(fangxiang)){ + direction = "-"; + }else{ + direction = "+"; + } + + //添加出入库header信息 + TransNoControl transNo = transNoControlService.getTransNo(dto.getSite(), dto.getTransType(), 8); + TransHeader transHeader = new TransHeader(); + transHeader.setSite(dto.getSite()); + transHeader.setTransNo(transNo.getNewTransNo()); + transHeader.setTransDate(new Date()); + transHeader.setTransTypeDb(dto.getTransType()); + + transHeader.setWarehouseId(dto.getWarehouseId()); + transHeader.setUserId(currentUser.getUserId().toString()); + transHeader.setUserName(currentUser.getUserDisplay()); + transHeader.setRemark(dto.getRemark()); + + transHeader.setStatus(dto.getStatus()); + transHeader.setStatusDb(dto.getStatus()); + transHeader.setOrderRef1(dto.getWorkOrderNo()); + transHeaderService.save(transHeader); + + List detailList = new ArrayList<>(); + List detailSubs = new ArrayList<>(); + + //保存sub + for (OtherOutboundTransSubDto subDto : dto.getSubList()){ + TransDetailSub detailSub = new TransDetailSub(); + detailSub.setSite(dto.getSite()); + detailSub.setTransNo(transHeader.getTransNo()); + detailSub.setItemNo(subDto.getItemNo()); + detailSub.setSubNo(subDto.getSubNo()); + detailSub.setSubQty(Double.valueOf(subDto.getTransQty())); + detailSub.setDirection(subDto.getDirection()); + detailSub.setPartNo(subDto.getPartNo()); + detailSub.setBatchNo(subDto.getBatchNo()); + detailSub.setLocationId(subDto.getLocationId()); + detailSub.setOrderRef3(subDto.getWdrNo()); + detailSub.setOrderRef4(subDto.getWarehouseId()); + + // 更新HandlingUnit状态 + HandlingUnit handlingUnit = handlingUnitService.lambdaQuery() + .eq(HandlingUnit::getSite, dto.getSite()) + .eq(HandlingUnit::getUnitId, subDto.getSubNo()) + .one(); + + if (handlingUnit != null) { + if("OUT".equals(fangxiang)){ + handlingUnit.setInStockFlag("N"); + handlingUnit.setStatus("ISSUED"); // 设置为已出库状态 + handlingUnit.setStatusDb("I"); // 设置为已出库状态DB + }else{ + handlingUnit.setInStockFlag("Y"); + } + handlingUnit.setModifiedDate(new Date()); + handlingUnit.setModifiedBy(currentUser.getUserDisplay()); + handlingUnitService.updateById(handlingUnit); + } + + detailSubs.add(detailSub); + } + + //总计sub数量添加到list + Map, Double> collect = detailSubs.stream().collect( + Collectors.groupingBy(item -> Arrays.asList( + item.getSite(), + item.getPartNo(), + item.getBatchNo(), + item.getLocationId(), + item.getOrderRef3(), + item.getOrderRef4() + ), Collectors.summingDouble(TransDetailSub::getSubQty))); + + Double index = 1.0; + for (Map.Entry, Double> entry : collect.entrySet()) { + List key = entry.getKey(); + Double totalQty = entry.getValue(); + + TransDetail detail = new TransDetail(); + detail.setSite(dto.getSite()); + detail.setTransNo(transHeader.getTransNo()); + detail.setItemNo(index); + detail.setPartNo(key.get(1)); + detail.setBatchNo(key.get(2)); + detail.setLocationId(key.get(3)); + detail.setWdrNo(key.get(4)); + detail.setOrderRef4(key.get(5)); + detail.setTransQty(new BigDecimal(totalQty)); + detail.setDirection(direction); + detailList.add(detail); + index++; + } + transDetailMapper.batchInsert(detailList); + + //回写itemNo + for (TransDetailSub sub : detailSubs){ + for (int i = 0; i < detailList.size(); i++){ + if(detailList.get(i).getSite().equals(sub.getSite()) + && detailList.get(i).getPartNo().equals(sub.getPartNo()) + && detailList.get(i).getBatchNo().equals(sub.getBatchNo()) + && detailList.get(i).getLocationId().equals(sub.getLocationId()) + && detailList.get(i).getWdrNo().equals(sub.getOrderRef3()) + && detailList.get(i).getOrderRef4().equals(sub.getOrderRef4()) + ){ + sub.setItemNo(detailList.get(i).getItemNo()); + break; + } + } + } + for (TransDetailSub sub : detailSubs){ + transDetailSubService.save(sub); + } + + for(TransDetail detail : detailList){ + // 变更库存 + inventoryStockService.changeInventoryStock(detail.getSite(), detail.getOrderRef4(), detail.getPartNo(), + detail.getBatchNo(), detail.getLocationId(), detail.getTransQty(), detail.getWdrNo(), fangxiang); + } + + return detailList; + } + /** * 更新HandlingUnit状态 */