diff --git a/src/main/java/com/gaotao/modules/outsourcing/controller/OutsourcingNotifyController.java b/src/main/java/com/gaotao/modules/outsourcing/controller/OutsourcingNotifyController.java index 19f14b16..207e628c 100644 --- a/src/main/java/com/gaotao/modules/outsourcing/controller/OutsourcingNotifyController.java +++ b/src/main/java/com/gaotao/modules/outsourcing/controller/OutsourcingNotifyController.java @@ -1,12 +1,19 @@ package com.gaotao.modules.outsourcing.controller; +import com.gaotao.common.utils.PageUtils; +import com.gaotao.common.utils.PartAttributeUtil; import com.gaotao.common.utils.R; import com.gaotao.modules.api.entity.IfsShopOrder; +import com.gaotao.modules.base.entity.SOScheduledRoutingData; import com.gaotao.modules.notify.entity.SOIssueNotifyHeaderData; import com.gaotao.modules.notify.entity.SOIssueNotifyOrderListData; +import com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListData; +import com.gaotao.modules.notify.entity.dto.NewSoIssueNotifyDto; import com.gaotao.modules.notify.entity.vo.ShopOrderAndMaterialVo; import com.gaotao.modules.outsourcing.entity.dto.IfsOutsourcingOrderDto; +import com.gaotao.modules.outsourcing.entity.dto.OutsourcingIssueNotifyDto; +import com.gaotao.modules.outsourcing.entity.vo.OutsourcingAndMaterialVo; import com.gaotao.modules.outsourcing.service.OutsourcingNotifyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -20,6 +27,8 @@ public class OutsourcingNotifyController { @Autowired private OutsourcingNotifyService outsourcingNotifyService; + @Autowired + private PartAttributeUtil partAttributeUtil; @PostMapping(value="/getUserNotifyPo") @ResponseBody @@ -44,11 +53,78 @@ public class OutsourcingNotifyController { @PostMapping(value="/getShopOrderAndMaterialByShoporder") public R getShopOrderAndMaterialByShoporder(@RequestBody IfsOutsourcingOrderDto data) throws Exception { - List rows = outsourcingNotifyService.getShopOrderAndMaterialByShoporder(data); + List rows = outsourcingNotifyService.getShopOrderAndMaterialByShoporder(data); if(rows != null && rows.size() > 0){ return R.ok().put("rows", rows); } return R.error("未找到对应的工单物料信息"); } + @PostMapping(value="/deleteOutsourcingNotifyHeader") + @ResponseBody + public R deleteOutsourcingNotifyHeader(@RequestBody SOIssueNotifyHeaderData data) { + outsourcingNotifyService.deleteOutsourcingNotifyHeader(data); + return R.ok("删除成功"); + } + + @PostMapping(value="/saveNewOutsourcingIssueNotify") + public R saveNewOutsourcingIssueNotify(@RequestBody OutsourcingIssueNotifyDto data) throws Exception { + String rows = outsourcingNotifyService.saveNewOutsourcingIssueNotify(data); + if("200".equals(rows)){ + return R.ok("操作成功"); + } + return R.error("操作失败"); + } + + @PostMapping(value="/getOutsouringForIssureNew") + @ResponseBody + public R getOutsouringForIssureNew(@RequestBody SOScheduledRoutingData data) throws Exception{ + List rows = outsourcingNotifyService.getOutsouringForIssureNew(data); + if(rows != null && rows.size() > 0){ + // 提前赋值:用componentPartNo赋值给partQuery,partNo保持原值不变 - rqrq + for (SOIssueNotifyOrderMaterialListData row : rows) { + row.setPartQuery(row.getComponentPartNo()); // componentPartNo用于fillIsInWh查询 - rqrq + } + + // 批量填充isInWh字段 - rqrq + partAttributeUtil.fillIsInWh(rows); + + } + return R.ok().put("rows", rows); + } + + @PostMapping(value="/saveMaterialDetail") + @ResponseBody + public R saveMaterialDetail(@RequestBody List data) { + outsourcingNotifyService.saveMaterialDetail(data); + return R.ok(); + } + + @PostMapping(value="/deleteNotifySOS") + @ResponseBody + public R deleteNotifySOS(@RequestBody SOIssueNotifyOrderListData data) { + outsourcingNotifyService.deleteNotifySOS(data); + return R.ok(); + } + + @PostMapping(value="/xiadaNotify") + @ResponseBody + public R xiadaNotifyHeader(@RequestBody SOIssueNotifyHeaderData data) { + outsourcingNotifyService.xiadaNotifyHeader(data); + return R.ok(); + } + + @PostMapping(value="/searchNotifyHeaderNew") + public R searchNotifyHeaderNew(@RequestBody SOIssueNotifyHeaderData data) { + PageUtils page = outsourcingNotifyService.searchNotifyHeaderNew(data); + return R.ok().put("page", page); + } + + @PostMapping(value="/deleteNotifySOSPlus") + @ResponseBody + public R deleteNotifySOSPlus(@RequestBody SOIssueNotifyOrderListData data) throws Exception{ + outsourcingNotifyService.deleteNotifySOSPlus(data); + return R.ok("刪除成功"); + + } } diff --git a/src/main/java/com/gaotao/modules/outsourcing/dao/OutsourcingNotifyMapper.java b/src/main/java/com/gaotao/modules/outsourcing/dao/OutsourcingNotifyMapper.java index 71cce74e..a5c9b079 100644 --- a/src/main/java/com/gaotao/modules/outsourcing/dao/OutsourcingNotifyMapper.java +++ b/src/main/java/com/gaotao/modules/outsourcing/dao/OutsourcingNotifyMapper.java @@ -1,11 +1,14 @@ package com.gaotao.modules.outsourcing.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.gaotao.modules.notify.entity.SOIssueNotifyHeader; -import com.gaotao.modules.notify.entity.SOIssueNotifyHeaderData; -import com.gaotao.modules.notify.entity.SOIssueNotifyOrderListData; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.gaotao.modules.base.entity.SOScheduledRoutingData; +import com.gaotao.modules.notify.entity.*; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; @Mapper @@ -13,4 +16,30 @@ public interface OutsourcingNotifyMapper extends BaseMapper SOIssueNotifyHeaderData getUserNotifyPo(SOIssueNotifyHeaderData data); List getNotifyPoDetail(SOIssueNotifyHeaderData data); + + int deleteOutsourcingNotifyHeader(SOIssueNotifyHeaderData data); + + BigDecimal getNextItemForSOIssueNotifyOrderList(SOIssueNotifyOrderList parentData); + + String getProductAreaByPlanner(@Param("site") String site,@Param("planner")String planner); + + int saveSOIssueNotifyOrderList(SOIssueNotifyOrderList parentItem); + + int deleteSOIssueNotifyOrderMaterialInList(@Param("notifyNo") String notifyNo,@Param("site") String site,@Param("items") List items); + + int batchSaveSOIssueNotifyOrderMaterialList(List childList); + + List getSOSBOMForIssureNew(SOScheduledRoutingData data); + + int deleteOutNotifyOrderMaterialListData(SOIssueNotifyOrderMaterialListData soIssueNotifyOrderMaterialListData); + + void batchSaveOutNotifyOrderMaterialListData(@Param("data")List data); + + int deleteNotifySOS(SOIssueNotifyOrderListData data); + + int deleteSOIssueNotifyOrderMaterialListData(SOIssueNotifyOrderMaterialListData deleteData); + + int xiadaNotifyHeader(SOIssueNotifyHeaderData data); + + IPage searchNotifyHeaderNew(Page page, @Param("query") SOIssueNotifyHeaderData data); } diff --git a/src/main/java/com/gaotao/modules/outsourcing/entity/dto/OutsourcingIssueNotifyDto.java b/src/main/java/com/gaotao/modules/outsourcing/entity/dto/OutsourcingIssueNotifyDto.java new file mode 100644 index 00000000..18c9d1a3 --- /dev/null +++ b/src/main/java/com/gaotao/modules/outsourcing/entity/dto/OutsourcingIssueNotifyDto.java @@ -0,0 +1,14 @@ +package com.gaotao.modules.outsourcing.entity.dto; + +import com.gaotao.modules.outsourcing.entity.vo.OutsourcingAndMaterialVo; +import lombok.Data; + +import java.util.List; + +@Data +public class OutsourcingIssueNotifyDto { + private String site; + private String outsourcingNo; + private String notifyNo; + List materialList; +} diff --git a/src/main/java/com/gaotao/modules/outsourcing/entity/vo/OutsourcingAndMaterialVo.java b/src/main/java/com/gaotao/modules/outsourcing/entity/vo/OutsourcingAndMaterialVo.java new file mode 100644 index 00000000..ef361834 --- /dev/null +++ b/src/main/java/com/gaotao/modules/outsourcing/entity/vo/OutsourcingAndMaterialVo.java @@ -0,0 +1,167 @@ +package com.gaotao.modules.outsourcing.entity.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class OutsourcingAndMaterialVo { + /**--------------------------------------详情Materical---------------------------------------------*/ + // 订单编号(关联的父订单编号) + private String orderNo; + + // 合同编号(所属合同标识) + private String contract; + + // 行号(在订单中的行项目编号) + private String lineNo; + + // 释放编号(订单释放的批次编号) + private String releaseNo; + + // 结构行号(在BOM结构中的行号,null表示无结构关联) + private String lineItemNo; + + // 组件物料编号(所需物料的编码) + private String componentPartNo; + + // 组件物料描述(所需物料的详细说明) + private String componentPartDescription; + + // 需求数量(该物料的总需求量) + private BigDecimal qtyRequired; + + // 已预留数量(已从库存中预留的数量) + private BigDecimal reservedQty; + + // 计量单位(数量的计量单位) + private String uom; + + // 需求日期(物料需要到位的日期时间) + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date dateRequired; + + // 已发放数量(已实际发放的物料数量) + private BigDecimal qtyIssued; + + // 倒冲标识(是否启用倒冲领料,FALSE表示不启用) + private String backflush; + + // 单位数量(可能表示每个父项所需的子项数量) + private BigDecimal qpa; + + // 组件损耗率(物料在生产过程中的损耗百分比) + private BigDecimal componentScrap; + + // 报废因子(可能用于计算损耗的系数) + private BigDecimal scrapFactor; + + private BigDecimal applyQty; + /**----------------------------------------PurchaseOrderLine-------------------------------------------*/ + // 转换因子(不同单位间的转换比例) + private BigDecimal convFactor; + + // 物料描述(物料的详细说明信息) + private String description; + + // 库存数量(当前库存中的物料数量) + private BigDecimal inventoryQty; + + // 库存单位(库存数量的计量单位) + private String inventoryUOM; + + // 待接收库存数量(需要接收至库存的数量) + private BigDecimal invQtyToReceive; + + // 物料编号(采购的物料编码) + private String partNo; + + // 计划交货日期(物料的计划交付日期时间) + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date plannedDeliveryDate; + + // 采购数量(订单中该物料的总采购数量) + private BigDecimal purchaseQty; + + // 采购单位(采购数量的计量单位) + private String purchaseUOM; + + // 待接收数量(需要接收的物料总数量) + private BigDecimal qtyToReceive; + + // 接收方式(文字描述的接收处理方式) + private String receiveCase; + + // 站点编号(业务所属的站点/组织) + private String site; + + // 状态(行项目的当前状态) + private String status; + + // 接收方式代码(数据库中存储的接收方式编码) + private String receiveCaseDB; + + // 订单状态(所属订单的整体状态) + private String orderStatus; + + // 库存物料标识(是否为库存物料的文字标识) + private String inventoryPartDB; + + // 需求类型(文字描述的需求类型) + private String demandCode; + + // 需求类型代码(数据库中存储的需求类型编码) + private String demandCodeDB; + + private String samplePercent; + + private String sampleQty; + /**--------------------------------------------PurchaseOrder--------------------------------------------------*/ + // 供应商编号(提供货物的供应商编码) + private String supplierNo; + + // 供应商名称(提供货物的供应商全称) + private String supplierName; + + // 收货日期(货物接收的日期时间) + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date receiptDate; + + // 采购员编码(负责该订单的采购员标识) + private String buyerCode; + + // 地址1(供应商/收货地址第一行信息) + private String address1; + + // 地址2(供应商/收货地址第二行信息) + private String address2; + + // 地址3(供应商/收货地址第三行信息) + private String address3; + + // 地址4(供应商/收货地址第四行信息) + private String address4; + + // 地址5(供应商/收货地址第五行信息) + private String address5; + + // 地址6(供应商/收货地址第六行信息) + private String address6; + + // 城市(所在城市) + private String city; + + // 邮政编码(地址对应的邮政编码) + private String zipCode; + + // 对象状态(与status可能一致,部分系统用于内部状态管理) + private String objstate; + + private String authorizationRequired; +} diff --git a/src/main/java/com/gaotao/modules/outsourcing/service/OutsourcingNotifyService.java b/src/main/java/com/gaotao/modules/outsourcing/service/OutsourcingNotifyService.java index 5eaf4504..cba83d88 100644 --- a/src/main/java/com/gaotao/modules/outsourcing/service/OutsourcingNotifyService.java +++ b/src/main/java/com/gaotao/modules/outsourcing/service/OutsourcingNotifyService.java @@ -1,10 +1,15 @@ package com.gaotao.modules.outsourcing.service; +import com.gaotao.common.utils.PageUtils; import com.gaotao.modules.api.entity.IfsShopOrder; +import com.gaotao.modules.base.entity.SOScheduledRoutingData; import com.gaotao.modules.notify.entity.SOIssueNotifyHeaderData; import com.gaotao.modules.notify.entity.SOIssueNotifyOrderListData; +import com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListData; import com.gaotao.modules.notify.entity.vo.ShopOrderAndMaterialVo; import com.gaotao.modules.outsourcing.entity.dto.IfsOutsourcingOrderDto; +import com.gaotao.modules.outsourcing.entity.dto.OutsourcingIssueNotifyDto; +import com.gaotao.modules.outsourcing.entity.vo.OutsourcingAndMaterialVo; import java.util.List; @@ -15,5 +20,21 @@ public interface OutsourcingNotifyService { List getNotifyPoDetail(SOIssueNotifyHeaderData data); - List getShopOrderAndMaterialByShoporder(IfsOutsourcingOrderDto data)throws Exception; + List getShopOrderAndMaterialByShoporder(IfsOutsourcingOrderDto data)throws Exception; + + void deleteOutsourcingNotifyHeader(SOIssueNotifyHeaderData data); + + String saveNewOutsourcingIssueNotify(OutsourcingIssueNotifyDto data) throws Exception; + + List getOutsouringForIssureNew(SOScheduledRoutingData data)throws Exception; + + void saveMaterialDetail(List data); + + void deleteNotifySOS(SOIssueNotifyOrderListData data); + + void xiadaNotifyHeader(SOIssueNotifyHeaderData data); + + PageUtils searchNotifyHeaderNew(SOIssueNotifyHeaderData data); + + void deleteNotifySOSPlus(SOIssueNotifyOrderListData data)throws Exception; } diff --git a/src/main/java/com/gaotao/modules/outsourcing/service/impl/OutsourcingNotifyServiceImpl.java b/src/main/java/com/gaotao/modules/outsourcing/service/impl/OutsourcingNotifyServiceImpl.java index 2314d1d3..5b1dfc86 100644 --- a/src/main/java/com/gaotao/modules/outsourcing/service/impl/OutsourcingNotifyServiceImpl.java +++ b/src/main/java/com/gaotao/modules/outsourcing/service/impl/OutsourcingNotifyServiceImpl.java @@ -1,27 +1,44 @@ package com.gaotao.modules.outsourcing.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.gaotao.common.utils.PageUtils; +import com.gaotao.modules.api.entity.IfsInventoryPart; import com.gaotao.modules.api.entity.IfsShopOrder; import com.gaotao.modules.api.entity.issueAndReturnVo.POLineSupplierMaterialVo; import com.gaotao.modules.api.entity.issueAndReturnVo.PurchaseOrderLineVo; import com.gaotao.modules.api.entity.issueAndReturnVo.PurchaseOrderVo; import com.gaotao.modules.api.service.IfsApiIssueAndReturnService; -import com.gaotao.modules.notify.entity.SOIssueNotifyHeaderData; -import com.gaotao.modules.notify.entity.SOIssueNotifyOrderListData; +import com.gaotao.modules.api.service.IfsApiService; +import com.gaotao.modules.base.entity.SOScheduledRoutingData; +import com.gaotao.modules.notify.entity.*; +import com.gaotao.modules.notify.entity.dto.GroupKey; +import com.gaotao.modules.notify.entity.dto.NewSoIssueNotifyDto; +import com.gaotao.modules.notify.entity.dto.ShoporderAndMaterialDto; import com.gaotao.modules.notify.entity.vo.ShopOrderAndMaterialVo; +import com.gaotao.modules.notify.entity.vo.ShopOrderMaterialVo; import com.gaotao.modules.outsourcing.dao.OutsourcingNotifyMapper; import com.gaotao.modules.outsourcing.entity.dto.IfsOutsourcingOrderDto; +import com.gaotao.modules.outsourcing.entity.dto.OutsourcingIssueNotifyDto; +import com.gaotao.modules.outsourcing.entity.vo.OutsourcingAndMaterialVo; import com.gaotao.modules.outsourcing.service.OutsourcingNotifyService; import com.gaotao.modules.sys.entity.SysUserEntity; import com.gaotao.modules.trans.entity.TransNoControl; import com.gaotao.modules.trans.service.Consts; import com.gaotao.modules.trans.service.TransNoControlService; +import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import java.util.Date; -import java.util.List; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; @Service public class OutsourcingNotifyServiceImpl implements OutsourcingNotifyService { @@ -31,6 +48,8 @@ public class OutsourcingNotifyServiceImpl implements OutsourcingNotifyService { private TransNoControlService transNoService; @Autowired private IfsApiIssueAndReturnService ifsApiIssueAndReturnService; + @Autowired + private IfsApiService ifsApiService; @Override public SOIssueNotifyHeaderData getUserNotifyPo(SOIssueNotifyHeaderData data) { SOIssueNotifyHeaderData headerData = outsourcingNotifyMapper.getUserNotifyPo(data); @@ -72,17 +91,376 @@ public class OutsourcingNotifyServiceImpl implements OutsourcingNotifyService { } @Override - public List getShopOrderAndMaterialByShoporder(IfsOutsourcingOrderDto data) throws Exception{ + public List getShopOrderAndMaterialByShoporder(IfsOutsourcingOrderDto data) throws Exception{ List purchaseOrder = ifsApiIssueAndReturnService.getPurchaseOrder(data.getOutsourcingNo(), data.getSite()); List purchaseOrderLine = ifsApiIssueAndReturnService.getPurchaseOrderLine(data.getOutsourcingNo(), data.getSite()); + List resultList = new ArrayList<>(); + if(purchaseOrderLine != null && purchaseOrderLine.size()>0) { List poLineSupplierMaterial = ifsApiIssueAndReturnService.getPOLineSupplierMaterial(data.getOutsourcingNo(), data.getSite()); - for(POLineSupplierMaterialVo materialVo:poLineSupplierMaterial){ + + // 建立 purchaseOrderLine 的索引,用于快速查找 + // key: orderNo + "|" + site + "|" + releaseNo + "|" + lineNo + Map purchaseOrderLineMap = purchaseOrderLine.stream() + .collect(Collectors.toMap( + line -> line.getOrderNo() + "|" + line.getSite() + "|" + + (line.getReleaseNo() != null ? line.getReleaseNo() : "") + "|" + + (line.getLineNo() != null ? line.getLineNo() : ""), + line -> line, + (existing, replacement) -> existing + )); + + // 建立 purchaseOrder 的索引,用于快速查找 + // key: orderNo + "|" + site + Map purchaseOrderMap = purchaseOrder.stream() + .collect(Collectors.toMap( + order -> order.getOrderNo() + "|" + order.getSite(), + order -> order, + (existing, replacement) -> existing + )); + + // 遍历最小的子类 poLineSupplierMaterial,关联父类数据 + for(POLineSupplierMaterialVo materialVo : poLineSupplierMaterial) { + // 构建查找 purchaseOrderLine 的 key + // 关联条件:子类的orderNo=父类的orderNo 且 子类的contract=父类的site 且 子类releaseNo=父类releaseNo 且 子类lineItemNo=父类lineNo + String lineKey = materialVo.getOrderNo() + "|" + + (materialVo.getContract() != null ? materialVo.getContract() : "") + "|" + + (materialVo.getReleaseNo() != null ? materialVo.getReleaseNo() : "") + "|" + + (materialVo.getLineItemNo() != null ? materialVo.getLineItemNo() : ""); + + PurchaseOrderLineVo matchedLine = purchaseOrderLineMap.get(lineKey); + + if(matchedLine != null) { + // 通过 purchaseOrderLine 查找 purchaseOrder + // 关联条件:purchaseOrderLine.orderNo = purchaseOrder.orderNo 且 purchaseOrderLine.site = purchaseOrder.site + String orderKey = matchedLine.getOrderNo() + "|" + matchedLine.getSite(); + PurchaseOrderVo matchedOrder = purchaseOrderMap.get(orderKey); + + // 创建返回对象 + OutsourcingAndMaterialVo vo = new OutsourcingAndMaterialVo(); + + // 从最小的子类 poLineSupplierMaterial 复制数据 + BeanUtils.copyProperties(materialVo, vo); + + /*vo.setOrderNo(materialVo.getOrderNo()); + vo.setReleaseNo(materialVo.getReleaseNo()); + vo.setContract(materialVo.getContract()); + vo.setLineNo(materialVo.getLineNo()); + if(materialVo.getLineItemNo() != null) { + try { + vo.setLineItemNo(materialVo.getLineItemNo()); + } catch (NumberFormatException e) { + // 如果转换失败,设置为null + vo.setLineItemNo(null); + } + } + vo.setComponentPartNo(materialVo.getComponentPartNo()); + vo.setComponentPartDescription(materialVo.getComponentPartDescription()); + vo.setQtyRequired(materialVo.getQtyRequired()); + vo.setReservedQty(materialVo.getReservedQty()); + vo.setQtyIssued(materialVo.getQtyIssued()); + vo.setUom(materialVo.getUom()); + if(materialVo.getDateRequired() != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + vo.setDateRequired(materialVo.getDateRequired()); + }*/ + + // 从 purchaseOrderLine 复制数据 + vo.setConvFactor(matchedLine.getConvFactor()); + vo.setDescription(matchedLine.getDescription()); + vo.setInventoryQty(matchedLine.getInventoryQty()); + vo.setInventoryUOM(matchedLine.getInventoryUOM()); + vo.setInvQtyToReceive(matchedLine.getInvQtyToReceive()); + if(matchedLine.getPartNo() != null) { + vo.setPartNo(matchedLine.getPartNo()); + } + if(matchedLine.getPlannedDeliveryDate() != null) { + vo.setPlannedDeliveryDate(matchedLine.getPlannedDeliveryDate()); + } + vo.setPurchaseQty(matchedLine.getPurchaseQty()); + vo.setPurchaseUOM(matchedLine.getPurchaseUOM()); + vo.setQtyToReceive(matchedLine.getQtyToReceive()); + vo.setReceiveCase(matchedLine.getReceiveCase()); + vo.setReceiveCaseDB(matchedLine.getReceiveCaseDB()); + + if(matchedLine.getStatus() != null) { + vo.setStatus(matchedLine.getStatus()); + } + vo.setSite(matchedLine.getSite()); + vo.setOrderStatus(matchedLine.getOrderStatus()); + vo.setInventoryPartDB(matchedLine.getInventoryPartDB()); + vo.setDemandCode(matchedLine.getDemandCode()); + vo.setDemandCodeDB(matchedLine.getDemandCodeDB()); + + + // 从 purchaseOrder 复制数据(如果需要) + if(matchedOrder != null) { + if(StringUtils.isBlank(vo.getStatus()) && matchedOrder.getStatus() != null) { + vo.setStatus(matchedOrder.getStatus()); + } + if(matchedOrder.getObjstate() != null) { + vo.setObjstate(matchedOrder.getObjstate()); + } + if(matchedOrder.getAuthorizationRequired() != null) { + vo.setAuthorizationRequired(matchedOrder.getAuthorizationRequired()); + } + vo.setSupplierNo(matchedOrder.getSupplierNo()); + vo.setSupplierName(matchedOrder.getSupplierName()); + vo.setReceiptDate(matchedOrder.getReceiptDate()); + vo.setBuyerCode(matchedOrder.getBuyerCode()); + vo.setAddress1(matchedOrder.getAddress1()); + vo.setAddress2(matchedOrder.getAddress2()); + vo.setAddress3(matchedOrder.getAddress3()); + vo.setAddress4(matchedOrder.getAddress4()); + vo.setAddress5(matchedOrder.getAddress5()); + vo.setAddress6(matchedOrder.getAddress6()); + vo.setCity(matchedOrder.getCity()); + vo.setZipCode(matchedOrder.getZipCode()); + vo.setCity(matchedOrder.getCity()); + } + + + resultList.add(vo); + } + } + } + + return resultList; + } + + @Override + public void deleteOutsourcingNotifyHeader(SOIssueNotifyHeaderData data) { + outsourcingNotifyMapper.deleteOutsourcingNotifyHeader(data); + } + + @Transactional + @Override + public String saveNewOutsourcingIssueNotify(OutsourcingIssueNotifyDto data) throws Exception { + if(data.getMaterialList() != null && data.getMaterialList().size() > 0){ + Map> mainGroupMap = data.getMaterialList().stream() + .collect(Collectors.groupingBy( + dto -> new GroupKey( + dto.getOrderNo(), + dto.getReleaseNo(), + dto.getLineItemNo() + ) + )); + + // 用于存储最终结果:父集合和子集合 + List parentList = new ArrayList<>(); + List childList = new ArrayList<>(); + int num = 0; + BigDecimal nextItem=BigDecimal.ZERO; + // 步骤2:遍历每个分组,生成父对象和子对象 + for (Map.Entry> entry : mainGroupMap.entrySet()) { + GroupKey groupKey = entry.getKey(); + List groupDtos = entry.getValue(); + + // 2.1 生成父对象的唯一 itemNo(确保全局唯一,这里用 UUID 简化) + if(num == 0){ + SOIssueNotifyOrderList parentData = new SOIssueNotifyOrderList(); + parentData.setSite(data.getSite()); + parentData.setNotifyNo(data.getNotifyNo()); + nextItem = outsourcingNotifyMapper.getNextItemForSOIssueNotifyOrderList(parentData); + }else{ + nextItem = nextItem.add(BigDecimal.ONE); + } + + + // 2.2 构建SOIssueNotifyOrderList + SOIssueNotifyOrderList parent = buildParent(data.getNotifyNo(),data.getSite(),groupKey, groupDtos, nextItem); + parentList.add(parent); + + // 2.3 遍历分组内的 dto,按 lineItemNo 生成子对象(SOIssueNotifyOrderMaterialList) + List children = buildChildren(data.getNotifyNo(),data.getSite(),groupDtos, nextItem,parent.getOrderType()); + childList.addAll(children); + + num++; + } + + List items= new ArrayList<>(); + // 保存父类 + for(SOIssueNotifyOrderList parentItem : parentList){ + IfsInventoryPart inventoryPart = new IfsInventoryPart(); + inventoryPart.setSite(parentItem.getSite()); + inventoryPart.setPartNo(parentItem.getFgPartNo()); + List rows = null; + try { + rows = ifsApiService.getIfsInventoryPart(inventoryPart); + } catch (Exception e) { + throw new RuntimeException(e); + } + String productionArea; + if(parentItem.getFgPartNo().startsWith("3")||parentItem.getFgPartNo().startsWith("7")) { + productionArea = "Z112"; + }else { + productionArea = outsourcingNotifyMapper.getProductAreaByPlanner(parentItem.getSite(), rows.get(0).getPlannerBuyer()); + } + parentItem.setProductionArea(productionArea!=null?productionArea:"Z301"); + parentItem.setPushWmsFlag("N"); + parentItem.setTransportFlag("N"); + parentItem.setOutWorkOrderFlag("N"); + int i = outsourcingNotifyMapper.saveSOIssueNotifyOrderList(parentItem); + + items.add(parentItem.getItemNo().toString()); } + //保存子类 + outsourcingNotifyMapper.deleteSOIssueNotifyOrderMaterialInList(data.getNotifyNo(),data.getSite(),items); + + outsourcingNotifyMapper.batchSaveSOIssueNotifyOrderMaterialList(childList); + return "200"; }else{ + throw new RuntimeException("物料列表不能为空"); + } + } + + private static SOIssueNotifyOrderList buildParent(String notifyNo,String site,GroupKey groupKey, List groupDtos, BigDecimal parentItemNo) { + SOIssueNotifyOrderList parent = new SOIssueNotifyOrderList(); + parent.setNotifyNo(notifyNo); + parent.setSite(site); + parent.setItemNo(parentItemNo); + parent.setSoorderNo(groupKey.getOrderNo()); + parent.setReleaseNo(groupKey.getReleaseNo()); + parent.setSequenceNo(groupKey.getSequenceNo()); + // 从分组内第一个 dto 提取共同属性(假设同一分组内这些属性一致) + OutsourcingAndMaterialVo firstDto = groupDtos.get(0); + parent.setFgPartNo(firstDto.getPartNo()); + parent.setNeedDate(firstDto.getPlannedDeliveryDate()); + parent.setTransportFlag("N"); + parent.setOrderType("poorder"); + + return parent; + } + + /** + * 构建子对象列表(SOIssueNotifyOrderMaterialList),关联父对象的 itemNo + */ + private static List buildChildren(String notifyNo,String site,List groupDtos, BigDecimal parentItemNo,String parentType) { + return groupDtos.stream() + .map(dto -> { + SOIssueNotifyOrderMaterialList child = new SOIssueNotifyOrderMaterialList(); + child.setNotifyNo(notifyNo); + child.setSite(site); + child.setItemNo(parentItemNo); + // 设置细分核心字段(lineItemNo) + child.setBOMItemNo(dto.getLineItemNo().toString()); + // 提取详细属性 + child.setComponentPartNo(dto.getComponentPartNo()); + child.setQtyToIssue(dto.getApplyQty()); + if( dto.getApplyQty()!=null){ + child.setQtyToIssueOriginal(dto.getApplyQty()); + } + child.setIssueType("BOM物料"); + if(StringUtils.isNotBlank(parentType)){ + child.setOrderType(parentType); + }else{ + child.setOrderType("shoporder"); + } + return child; + }) + // 按 lineItemNo 排序(可选,确保子项顺序) + .sorted(Comparator.comparing(SOIssueNotifyOrderMaterialList::getBOMItemNo)) + .collect(Collectors.toList()); + } + + @Override + public List getOutsouringForIssureNew(SOScheduledRoutingData data) throws Exception{ + IfsShopOrder apiData=new IfsShopOrder(); + apiData.setSite(data.getSite()); + apiData.setOrderNo(data.getOrderNo()); + //获取IFS SOBOM + List poLineSupplierMaterial = ifsApiIssueAndReturnService.getPOLineSupplierMaterial(apiData.getOrderNo(), apiData.getSite()); + //获取已有信息 + List list = outsourcingNotifyMapper.getSOSBOMForIssureNew(data); + List result= new ArrayList<>(); + for (int i = 0; i < poLineSupplierMaterial.size(); i++) { + SOIssueNotifyOrderMaterialListData entity = new SOIssueNotifyOrderMaterialListData(); + entity.setSite(data.getSite()); + entity.setNotifyNo(data.getNotifyNo()); + entity.setItemNo(BigDecimal.valueOf(data.getItemNo())); + entity.setBOMItemNo(poLineSupplierMaterial.get(i).getLineItemNo().toString()); + entity.setQtyRequired(poLineSupplierMaterial.get(i).getQtyRequired()); + entity.setComponentPartNo(poLineSupplierMaterial.get(i).getComponentPartNo()); + entity.setComponentPartDesc(poLineSupplierMaterial.get(i).getComponentPartDescription()); + entity.setIssueType("BOM物料"); + if(!list.isEmpty()){ + SOIssueNotifyOrderMaterialListData selectOne=list.stream() + .filter(item -> + entity.getBOMItemNo().equals(item.getBOMItemNo()) && + entity.getComponentPartNo().equals(item.getComponentPartNo()) + ) + .findFirst() + .orElse(null); + if(selectOne!=null){ + entity.setQtyToIssue(selectOne.getQtyToIssue()); + entity.setQtyToIssueOriginal(selectOne.getQtyToIssueOriginal()); + entity.setRemark(selectOne.getRemark()); + } + } + result.add( entity); + } + return result; + } + + @Override + public void saveMaterialDetail(List data) { + outsourcingNotifyMapper.deleteOutNotifyOrderMaterialListData(data.get(0)); + for (int i = 0; i < data.size(); i++) { + data.get(i).setIssueType("BOM物料"); + data.get(i).setItemNo(data.get(0).getItemNo()); + if( data.get(i).getQtyToIssue()!=null){ + data.get(i).setQtyToIssueOriginal(data.get(i).getQtyToIssue()); + } } - return null; + outsourcingNotifyMapper.batchSaveOutNotifyOrderMaterialListData(data); + } + + @Override + public void deleteNotifySOS(SOIssueNotifyOrderListData data) { + outsourcingNotifyMapper.deleteNotifySOS(data); + SOIssueNotifyOrderMaterialListData deleteData=new SOIssueNotifyOrderMaterialListData(); + deleteData.setNotifyNo(data.getNotifyNo()); + deleteData.setSite(data.getSite()); + deleteData.setItemNo(data.getItemNo()); + outsourcingNotifyMapper.deleteSOIssueNotifyOrderMaterialListData(deleteData); + } + + @Override + public void xiadaNotifyHeader(SOIssueNotifyHeaderData data){ + outsourcingNotifyMapper.xiadaNotifyHeader(data); + } + + @Override + public PageUtils searchNotifyHeaderNew(SOIssueNotifyHeaderData data) { + System.out.println("开始查询申请单主表 - AI制作"); + Page page = new Page<>(data.getPage(), data.getLimit()); + + // 按照原有模式进行分页查询 + IPage resultList = outsourcingNotifyMapper.searchNotifyHeaderNew(page , data); + PageUtils pageResult = new PageUtils(resultList); + + System.out.println("查询申请单主表完成,共" + resultList.getTotal() + "条记录"); + + return pageResult; + } + + @Override + public void deleteNotifySOSPlus(SOIssueNotifyOrderListData data) throws Exception{ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("notify_no",data.getNotifyNo()); + queryWrapper.eq("site",data.getSite()); + SOIssueNotifyHeader soIssueNotifyHeader = outsourcingNotifyMapper.selectOne(queryWrapper); + if(!"未推送".equals(soIssueNotifyHeader.getPushWcsFlag())){ + throw new Exception("当前行不是未推送状态,不能删除!"); + } + + outsourcingNotifyMapper.deleteNotifySOS(data); + SOIssueNotifyOrderMaterialListData deleteData=new SOIssueNotifyOrderMaterialListData(); + deleteData.setNotifyNo(data.getNotifyNo()); + deleteData.setSite(data.getSite()); + deleteData.setItemNo(data.getItemNo()); + outsourcingNotifyMapper.deleteSOIssueNotifyOrderMaterialListData(deleteData); } } diff --git a/src/main/resources/mapper/outsourcing/OutsourcingNotifyMapper.xml b/src/main/resources/mapper/outsourcing/OutsourcingNotifyMapper.xml index 61b273d8..d25925c8 100644 --- a/src/main/resources/mapper/outsourcing/OutsourcingNotifyMapper.xml +++ b/src/main/resources/mapper/outsourcing/OutsourcingNotifyMapper.xml @@ -1,6 +1,7 @@ + + + + + + + delete from SOIssueNotifyHeader where site=#{site} and notify_no=#{notifyNo} + + + + insert into SOIssueNotifyOrderList(notify_no,site,item_no,fgpart_no,soorder_no,issure_qty,out_work_order_flag,need_date,release_no,sequence_no, + push_wms_flag,production_area,transport_flag,order_type) + values(#{notifyNo},#{site},#{itemNo},#{fgPartNo},#{soorderNo},#{issureQty,jdbcType=DECIMAL},#{outWorkOrderFlag} + ,#{needDate},#{releaseNo},#{sequenceNo},#{pushWmsFlag},#{productionArea},#{transportFlag},#{orderType}) + + + DELETE FROM SOIssueNotifyOrderMaterialList + WHERE + notify_no = #{notifyNo} + AND site = #{site} + AND item_no IN + + #{item} + + + + + insert into SOIssueNotifyOrderMaterialList (notify_no,site,item_no,BOM_item_no,component_part_no,qty_to_issue,qty_to_issue_original,issue_type,remark,order_type) + values + + (#{item.notifyNo},#{item.site},#{item.itemNo},#{item.bOMItemNo},#{item.componentPartNo},#{item.qtyToIssue,jdbcType=DECIMAL},#{item.qtyToIssueOriginal,jdbcType=DECIMAL},#{item.issueType},rtrim(#{item.remark}),#{item.orderType}) + + + + + + + + delete from SOIssueNotifyOrderMaterialList where site=#{site} and notify_no=#{notifyNo} and item_no=#{itemNo} + + + + insert into SOIssueNotifyOrderMaterialList (notify_no,site,item_no,BOM_item_no,component_part_no,qty_to_issue,qty_to_issue_original,issue_type,remark,order_type) + values + + (#{item.notifyNo},#{item.site},#{item.itemNo},#{item.bOMItemNo},#{item.componentPartNo},#{item.qtyToIssue,jdbcType=DECIMAL},#{item.qtyToIssueOriginal,jdbcType=DECIMAL},#{item.issueType},rtrim(#{item.remark}),#{item.orderType}) + + + + delete from SOIssueNotifyOrderList where site=#{site} and notify_no=#{notifyNo} and item_no=#{itemNo} + + + delete from SOIssueNotifyOrderMaterialList where site=#{site} and notify_no=#{notifyNo} and item_no=#{itemNo} + + + UPDATE SOIssueNotifyHeader WITH (ROWLOCK) + SET plan_issue_date = #{planIssueDate}, remark = #{remark}, status = 'ISSUE' + WHERE site = #{site} AND notify_no = #{notifyNo} + + \ No newline at end of file