采购退货接入SAP接口
This commit is contained in:
parent
70e9fba808
commit
a0320c9206
@ -239,4 +239,16 @@ public class DocumentSfc extends Model<DocumentSfc> {
|
||||
@ApiModelProperty(value="mes库存")
|
||||
private String mesInventory;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String salesOrder;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String inventorySpecialMarking;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer externalSeq;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer salesOrderSeq;
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.common.utils.HandleBoProcessor;
|
||||
import com.foreverwin.iep.integration.feign.RemoteFssm007Service;
|
||||
import com.foreverwin.iep.integration.feign.RemoteFssm0081Service;
|
||||
import com.foreverwin.iep.integration.feign.RemoteFssm0082Service;
|
||||
import com.foreverwin.iep.integration.feign.RemoteInvokeService;
|
||||
import com.foreverwin.iep.prd.domain.GenerateNextNumberRequest;
|
||||
import com.foreverwin.iep.prd.domain.GenerateNextNumberResponse;
|
||||
@ -127,6 +128,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
private final RemotePrintService remotePrintService;
|
||||
private final RemoteFssm007Service remoteFssm007Service;
|
||||
private final RemoteFssm0081Service remoteFssm0081Service;
|
||||
private final RemoteFssm0082Service remoteFssm0082Service;
|
||||
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
@ -4241,8 +4243,8 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
detaileds.add(detailed);
|
||||
}
|
||||
|
||||
// 调用ERP交货单创建接口
|
||||
this.sapDeliveryOrderCreation(site, documents, user, documents_);
|
||||
// 调用ERP交货单创建接口
|
||||
this.sapDeliveryOrderCreation(site, documents, user, documents_);
|
||||
|
||||
documentDetailedService.updateBatchById(detaileds);
|
||||
this.updateBatchById(documents_);
|
||||
@ -4257,8 +4259,8 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
* @param user
|
||||
* @param documents_
|
||||
*/
|
||||
@Override
|
||||
public void sapDeliveryOrderCreation(String site, List<Document> documents, String user, List<Document> documents_) {
|
||||
@Override
|
||||
public void sapDeliveryOrderCreation(String site, List<Document> documents, String user, List<Document> documents_) {
|
||||
// ERP报文开始#
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
jsonBody.put("RFC_FUNCTION", "ZMM_MES_DELIVERY_CREATE1");
|
||||
@ -4279,17 +4281,17 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
// 研发订单退料
|
||||
bwart = "Z02";
|
||||
} else if (Constant.DOCUMENT_STOR_REQUEST.equals(documentType)) {
|
||||
// 生产入库单
|
||||
// 如果 documents.get(0).getStorageStatus()等于1001,则 bwart = '311'; 若等于 1004 ,则 bwart = '323';
|
||||
if ("1004".equals(documents.get(0).getStorageStatus())) {
|
||||
bwart = "323";
|
||||
} else {
|
||||
bwart = "311";
|
||||
}
|
||||
} else if (Constant.DOCUMENT_STORES_REQUISITION.equals(documentType) || Constant.DOCUMENT_STORES_RETURNED.equals(documentType) || Constant.DOCUMENT_LOCAL_TRANSFER.equals(documentType)) {
|
||||
//生产领料/生产退料/库存调拨
|
||||
bwart = "311";
|
||||
} else if (Constant.DOCUMENT_ATTRIBUTE_TRANSFER.equals(documentType)) {
|
||||
// 生产入库单
|
||||
// 如果 documents.get(0).getStorageStatus()等于1001,则 bwart = '311'; 若等于 1004 ,则 bwart = '323';
|
||||
if ("1004".equals(documents.get(0).getStorageStatus())) {
|
||||
bwart = "323";
|
||||
} else {
|
||||
bwart = "311";
|
||||
}
|
||||
} else if (Constant.DOCUMENT_STORES_REQUISITION.equals(documentType) || Constant.DOCUMENT_STORES_RETURNED.equals(documentType) || Constant.DOCUMENT_LOCAL_TRANSFER.equals(documentType)) {
|
||||
//生产领料/生产退料/库存调拨
|
||||
bwart = "311";
|
||||
} else if (Constant.DOCUMENT_ATTRIBUTE_TRANSFER.equals(documentType)) {
|
||||
// 特殊库存转移
|
||||
if (StrUtil.isBlank(documents.get(0).getDocumentDetailedList().get(0).getTargetSalesOrder()) && StrUtil.isBlank(documents.get(0).getDocumentDetailedList().get(0).getTargetSalesOrderSeq())) {
|
||||
// 只有来源销售订单和行号
|
||||
@ -5735,7 +5737,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
documentNo,
|
||||
null,
|
||||
storageBinBindInventory.getStorageBinBo(),
|
||||
Collections.singletonList(parentInventoryId + "-1"), null, null,false
|
||||
Collections.singletonList(parentInventoryId + "-1"), null, null, false
|
||||
).get(0);
|
||||
inventoryService.update(Wrappers.lambdaUpdate(Inventory.class)
|
||||
.eq(Inventory::getHandle, Inventory.genHandle(site, freezeInventoryId))
|
||||
@ -6471,7 +6473,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
|
||||
if (Constant.DOCUMENT_STATUS_SUBMIT.equals(document.getState())) {
|
||||
updateDocumentAndDetailStatus(user, documentBo, now, Constant.DOCUMENT_STATUS_PICKING);
|
||||
if(!"PURCHASE_RETURN".equals(document.getDocumentType())){
|
||||
if (!"PURCHASE_RETURN".equals(document.getDocumentType())) {
|
||||
//FSMM007-MES B
|
||||
if (StringUtil.isEmpty(document.getExternalDocumentNo())) {
|
||||
throw BusinessException.build("交货单号不可为空");
|
||||
@ -6496,7 +6498,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
if (Constant.DOCUMENT_STATUS_PICKING.equals(document.getState()) || Constant.DOCUMENT_STATUS_TBC.equals(document.getState())) {
|
||||
pickingService.lambdaUpdate().eq(Picking::getSite, site).eq(Picking::getDocumentNo, documentNo).in(CollectionUtil.isNotEmpty(seqList), Picking::getSeq, seqList).remove();
|
||||
updateDocumentAndDetailStatus(user, documentBo, null, Constant.DOCUMENT_STATUS_SUBMIT);
|
||||
if(!"PURCHASE_RETURN".equals(document.getDocumentType())){
|
||||
if (!"PURCHASE_RETURN".equals(document.getDocumentType())) {
|
||||
//FSMM007-MES 空
|
||||
if (StringUtil.isEmpty(document.getExternalDocumentNo())) {
|
||||
throw BusinessException.build("交货单号不可为空");
|
||||
@ -6533,7 +6535,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
if (Constant.DOCUMENT_STATUS_PICKING.equals(document.getState())) {
|
||||
updatePickingStatus(site, user, documentNo, now, Constant.PICKING_STATUS_TBC);
|
||||
updateDocumentAndDetailStatus(user, documentBo, now, Constant.DOCUMENT_STATUS_TBC);
|
||||
if(!"PURCHASE_RETURN".equals(document.getDocumentType())){
|
||||
if (!"PURCHASE_RETURN".equals(document.getDocumentType())) {
|
||||
//FSMM007-MES C
|
||||
if (StringUtil.isEmpty(document.getExternalDocumentNo())) {
|
||||
throw BusinessException.build("交货单号不可为空");
|
||||
@ -6635,16 +6637,48 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
if (StringUtil.isEmpty(document.getExternalDocumentNo())) {
|
||||
throw BusinessException.build("交货单号不可为空");
|
||||
}
|
||||
if("PURCHASE_RETURN".equals(document.getDocumentType())){
|
||||
// 用008-2接口传送 @TODO 接口里面的明细字段传值映射待定
|
||||
|
||||
}else{
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
if ("PURCHASE_RETURN".equals(document.getDocumentType())) {
|
||||
// 用008-2接口传送
|
||||
JSONObject sapJsonBody = assemble0082RequestBody(document, user, documentSfcs);
|
||||
resultMap = remoteFssm0082Service.doExecute(sapJsonBody).getData();
|
||||
} else {
|
||||
JSONObject sapJsonBody = assembleRequestBody(document, user, documentSfcs, types);
|
||||
Map<String, String> resultMap = remoteFssm0081Service.doExecute(sapJsonBody).getData();
|
||||
if ("E".equals(resultMap.get("RESULT"))) {
|
||||
throw BusinessException.build(resultMap.get("MSG"));
|
||||
}
|
||||
resultMap = remoteFssm0081Service.doExecute(sapJsonBody).getData();
|
||||
}
|
||||
if ("E".equals(resultMap.get("RESULT"))) {
|
||||
throw BusinessException.build("SAP错误:" + resultMap.get("MSG"));
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject assemble0082RequestBody(Document document, String user, List<DocumentSfc> documentSfcs) {
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
JSONObject jsonHead = new JSONObject();
|
||||
jsonHead.put("ZPARTNER", user);
|
||||
jsonHead.put("BUDAT", LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
jsonBody.put("IS_HEAD", jsonHead);
|
||||
JSONArray itemArray = new JSONArray();
|
||||
for (DocumentSfc documentSfc : documentSfcs) {
|
||||
JSONObject minJson = new JSONObject();
|
||||
minJson.put("MATNR", documentSfc.getItem()); // 物料编号
|
||||
minJson.put("WERKS", documentSfc.getSite()); // 工厂
|
||||
minJson.put("LGORT", documentSfc.getSourceWarehouse()); // 存储地点 来源仓库
|
||||
minJson.put("CHARG", documentSfc.getBatchNumber()); // 批次编号
|
||||
minJson.put("BWART", "101"); // 移动类型(库存管理)
|
||||
minJson.put("EBELN", document.getExternalDocumentNo()); // 采购订单号 PO单号(即外部单号)
|
||||
minJson.put("EBELP", documentSfc.getExternalSeq()); // 采购凭证的项目编号 PO单行号(即外部单行号)
|
||||
minJson.put("MEINS", documentSfc.getUnitOfMeasure()); // 基本计量单位
|
||||
minJson.put("MENGE", documentSfc.getQty()); // 基本计量数量
|
||||
String specialMarking = documentSfc.getInventorySpecialMarking();
|
||||
minJson.put("SOBKZ", specialMarking); // 特殊库存标识,若是E库存的条,需要传输这个
|
||||
String matKdauf = "E".equals(specialMarking) ? documentSfc.getSalesOrder() : "";
|
||||
Integer matKdpos = "E".equals(specialMarking) ? documentSfc.getSalesOrderSeq() : null;
|
||||
minJson.put("MAT_KDAUF", matKdauf); // 接收销售订单 若是E库存的条,需要传输这个
|
||||
minJson.put("MAT_KDPOS", matKdpos); // 接收销售订单行号 若是E库存的条,需要传输这个
|
||||
itemArray.add(minJson);
|
||||
}
|
||||
jsonBody.put("IT_ITEM", itemArray);
|
||||
return jsonBody;
|
||||
}
|
||||
|
||||
private JSONObject assembleRequestBody(Document document, String user, List<DocumentSfc> documentSfcs, String types) {
|
||||
@ -6980,7 +7014,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
throw BusinessException.build("原采购订单" + po + "和行" + seq + "数据不存在");
|
||||
}
|
||||
poOrderDetail.setRegisteredQty(poOrderDetail.getRegisteredQty().subtract(sumQty));
|
||||
if(poOrderDetail.getCompletedQty() == null){
|
||||
if (poOrderDetail.getCompletedQty() == null) {
|
||||
throw BusinessException.build("原采购订单" + po + "和行" + seq + "的完成数量为空");
|
||||
}
|
||||
poOrderDetail.setCompletedQty(poOrderDetail.getCompletedQty().subtract(sumQty));
|
||||
@ -7059,7 +7093,7 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
throw BusinessException.build("原采购订单" + po + "和行" + seq + "数据不存在");
|
||||
}
|
||||
poOrderDetail.setRegisteredQty(poOrderDetail.getRegisteredQty().subtract(detailed.getApplicationsQuantity()));
|
||||
if(poOrderDetail.getCompletedQty() == null){
|
||||
if (poOrderDetail.getCompletedQty() == null) {
|
||||
throw BusinessException.build("原采购订单" + po + "和行" + seq + "的完成数量为空");
|
||||
}
|
||||
poOrderDetail.setCompletedQty(poOrderDetail.getCompletedQty().subtract(detailed.getApplicationsQuantity()));
|
||||
|
||||
@ -36,6 +36,10 @@
|
||||
<result property="modifyCause" column="MODIFY_CAUSE"/>
|
||||
<result property="storageBin" column="STORAGE_BIN"/>
|
||||
<result property="mesInventory" column="MES_INVENTORY"/>
|
||||
<result property="externalSeq" column="EXTERNAL_SEQ"/>
|
||||
<result property="salesOrder" column="SALES_ORDER"/>
|
||||
<result property="salesOrderSeq" column="SALES_ORDER_SEQ"/>
|
||||
<result property="inventorySpecialMarking" column="INVENTORY_SPECIAL_MARKING"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
@ -69,15 +73,16 @@
|
||||
</select>
|
||||
|
||||
<select id="findDocumentSfcList" resultMap="documentSfcMap">
|
||||
select distinct st.*, zdd.TARGET_WAREHOUSE, zdd.SOURCE_WAREHOUSE, i.UNIT_OF_MEASURE
|
||||
select distinct st.*, zdd.TARGET_WAREHOUSE, zdd.SOURCE_WAREHOUSE, i.UNIT_OF_MEASURE,
|
||||
zdd.EXTERNAL_SEQ,zdd.SALES_ORDER,zdd.SALES_ORDER_SEQ,zdd.INVENTORY_SPECIAL_MARKING
|
||||
from (select ct.DOCUMENT_NO, ct.SEQ, ct.ITEM, SUM(ct.QTY) QTY, ct.BATCH_NUMBER, ct.SITE
|
||||
from (select zds.DOCUMENT_NO, zds.SITE, zds.SFC, zds.SEQ, zds.ITEM, zds.QTY, wi.BATCH_NO BATCH_NUMBER
|
||||
from z_document_sfc zds
|
||||
left join wms_inventory wi on wi.INVENTORY_ID = zds.SFC and wi.SITE = zds.SITE
|
||||
where zds.DOCUMENT_NO = #{documentNo}
|
||||
and zds.SITE = #{site}) ct
|
||||
group by ct.DOCUMENT_NO, ct.SEQ, ct.ITEM, ct.QTY, ct.BATCH_NUMBER, ct.SITE) st
|
||||
left join z_document_detailed zdd on zdd.DOCUMENT_NO = st.DOCUMENT_NO and zdd.SITE = st.SITE
|
||||
group by ct.DOCUMENT_NO, ct.SEQ, ct.ITEM, ct.BATCH_NUMBER, ct.SITE) st
|
||||
left join z_document_detailed zdd on zdd.DOCUMENT_NO = st.DOCUMENT_NO and zdd.SITE = st.SITE and zdd.SEQ = st.SEQ
|
||||
left join wip.item i on i.ITEM = st.ITEM and i.SITE = st.SITE and i.CURRENT_REVISION = 'Y'
|
||||
</select>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user