add:增加生产退库
This commit is contained in:
@@ -187,8 +187,13 @@ public class MesToWmsController {
|
||||
@PostMapping("app/restful/api/v3/wms/mesProductReturnSync")
|
||||
@SaIgnore
|
||||
@Log("新增生产投料退料")
|
||||
public ResponseEntity<Object> mesProductReturnSync(@Valid @RequestBody PmProductReturnParam param) {
|
||||
mesToWmsService.mesProductReturnSync(param);
|
||||
public ResponseEntity<Object> mesProductReturnSync(@Valid @RequestBody List<PmProductReturnParam> param) {
|
||||
if (!CollectionUtils.isEmpty(param)){
|
||||
for (PmProductReturnParam pmProductReturnParam : param) {
|
||||
mesToWmsService.mesProductReturnSync(pmProductReturnParam);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,153 +15,116 @@ import org.nl.wms.ext_manage.sap.api.dto.ReceiptConfirmRequest;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.SubcontractConfirmRequest;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.SubcontractReverseRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SapApi {
|
||||
|
||||
private static final String BASIC_AUTH_USER = "sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39";
|
||||
private static final String BASIC_AUTH_PASSWORD = "e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=";
|
||||
|
||||
/**
|
||||
* MM054 交货单收货确认
|
||||
*/
|
||||
public JSONObject receiptConfirm(ReceiptConfirmRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP MM054收货确认请求:{}", param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.RECEIPT_CONFIRM_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=")
|
||||
.body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP MM054收货确认响应:{}", resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP收货确认");
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP收货确认失败:" + e.getMessage());
|
||||
}
|
||||
return postInbound("SAP收货确认", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* MM064 委外交货确认
|
||||
*/
|
||||
public JSONObject subcontractDeliveryConfirm(SubcontractConfirmRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP MM064委外交货确认请求:{}", param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.SUBCONTRACT_CONFIRM_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=") .body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP MM064委外交货确认响应:{}", resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP委外交货确认");
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP委外交货确认失败:" + e.getMessage());
|
||||
}
|
||||
return postInbound("SAP委外交货确认", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* MM065 委外出库单倒冲
|
||||
*/
|
||||
public JSONObject subcontractDeliveryReverse(SubcontractReverseRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP MM065委外出库倒冲请求:{}", param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.RECEIPT_CONFIRM_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=") .body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP MM065委外出库倒冲响应:{}", resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP委外出库倒冲");
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP委外出库倒冲失败:" + e.getMessage());
|
||||
}
|
||||
return postInbound("SAP委外出库倒冲", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* MM057 物料转储(同厂库存地点转移)
|
||||
*/
|
||||
public JSONObject materialTransfer(MaterialTransferRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP MM057物料转储请求:{}", param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.MATERIAL_TRANSFER_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=")
|
||||
.body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP MM057物料转储响应:{}", resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP物料转储");
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP物料转储失败:" + e.getMessage());
|
||||
}
|
||||
return postInbound("SAP物料转储", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* PP055 生产投料(生产订单发料)生产退料(从订单退出返回仓库)
|
||||
*/
|
||||
public JSONObject productionOutbound(ProductionOutboundRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP PP055生产投料/退库请求:{}", param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.PRODUCTION_OUTBOUND_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=")
|
||||
.body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP PP055生产投料/退库响应:{}", resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP生产投料/退库");
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP生产投料/退库失败:" + e.getMessage());
|
||||
}
|
||||
return postInbound("SAP生产投料/退库", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* PP066 生产入库(生产订单收货)
|
||||
*/
|
||||
public JSONObject productionInbound(ProductionInboundRequest request) {
|
||||
String param = JSON.toJSONString(request);
|
||||
log.info("SAP PP066生产入库请求:{}", param);
|
||||
return postInbound("SAP生产入库", request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按已落库的 SAP 请求 JSON 直接回传(手动回传)
|
||||
*/
|
||||
public JSONObject upload(JSONObject requestData) {
|
||||
JSONObject request = extractRequest(requestData);
|
||||
String intfId = resolveIntfId(request);
|
||||
String bizLabel = StringUtils.hasText(intfId) ? "SAP回传[" + intfId + "]" : "SAP回传";
|
||||
return postInbound(bizLabel, request);
|
||||
}
|
||||
|
||||
private JSONObject postInbound(String bizLabel, Object request) {
|
||||
String param = request instanceof String ? (String) request : JSON.toJSONString(request);
|
||||
log.info("{}请求:{}", bizLabel, param);
|
||||
try {
|
||||
String resultMsg = HttpRequest.post(SapConstant.PRODUCTION_INBOUND_URL)
|
||||
.basicAuth("sb-164b126d-0398-4635-9d0d-8be99d6e3fdd!b6436|it-rt-dev-12nylocm!b39",
|
||||
"e3530ba3-2243-4c09-9320-db961c08d04c$aVQJe8yGKZmbkvqE9a1opQU0P2uwRLkGMqHJvrrvmH8=")
|
||||
String resultMsg = HttpRequest.post(SapConstant.SAP_INBOUND_URL)
|
||||
.basicAuth(BASIC_AUTH_USER, BASIC_AUTH_PASSWORD)
|
||||
.body(param)
|
||||
.execute()
|
||||
.body();
|
||||
log.info("SAP PP066生产入库响应:{}", resultMsg);
|
||||
log.info("{}响应:{}", bizLabel, resultMsg);
|
||||
JSONObject result = JSONObject.parseObject(resultMsg);
|
||||
assertSapSuccess(result, "SAP生产入库");
|
||||
assertSapSuccess(result, bizLabel);
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("SAP生产入库失败:" + e.getMessage());
|
||||
throw new BadRequestException(bizLabel + "失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容成功后落库的 {request, response} 结构,以及失败时仅存请求体的结构
|
||||
*/
|
||||
private JSONObject extractRequest(JSONObject requestData) {
|
||||
if (requestData == null) {
|
||||
throw new BadRequestException("SAP回传失败:请求数据为空");
|
||||
}
|
||||
JSONObject nested = requestData.getJSONObject("request");
|
||||
if (nested != null && nested.get("header") != null) {
|
||||
return nested;
|
||||
}
|
||||
if (requestData.get("header") != null) {
|
||||
return requestData;
|
||||
}
|
||||
throw new BadRequestException("SAP回传失败:无法识别请求报文,缺少 header");
|
||||
}
|
||||
|
||||
private String resolveIntfId(JSONObject request) {
|
||||
JSONObject header = request.getJSONObject("header");
|
||||
if (header == null) {
|
||||
return null;
|
||||
}
|
||||
String intfId = header.getString("intf_id");
|
||||
if (!StringUtils.hasText(intfId)) {
|
||||
intfId = header.getString("intfId");
|
||||
}
|
||||
return intfId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 SAP 响应:body[].status = S 成功,E 失败并抛出 message
|
||||
*/
|
||||
|
||||
@@ -2,20 +2,8 @@ package org.nl.wms.ext_manage.sap.enums;
|
||||
|
||||
public class SapConstant {
|
||||
|
||||
/** SAP 收货确认(MM054)接口地址 */
|
||||
public static final String RECEIPT_CONFIRM_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
|
||||
/** SAP 委外交货确认(MM064)接口地址 */
|
||||
public static final String SUBCONTRACT_CONFIRM_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
|
||||
/** SAP 物料转储(MM057)接口地址 */
|
||||
public static final String MATERIAL_TRANSFER_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
|
||||
/** SAP 生产入库(PP066)接口地址 */
|
||||
public static final String PRODUCTION_INBOUND_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
|
||||
/** SAP 生产投料(PP055)接口地址 */
|
||||
public static final String PRODUCTION_OUTBOUND_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
/** SAP CPI Inbound 统一接口地址(各业务接口共用,通过 header.intf_id 区分) */
|
||||
public static final String SAP_INBOUND_URL = "https://dev-12nylocm.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/ERP/Inbound";
|
||||
|
||||
/** 接口编号:交货单确认 */
|
||||
public static final String INTF_MM054 = "MM054";
|
||||
|
||||
@@ -114,7 +114,7 @@ public class FeedingRecordPushDto {
|
||||
private BigDecimal finishedQty;
|
||||
|
||||
@JsonProperty("SeqNo")
|
||||
private Integer seqNo;
|
||||
private String seqNo;
|
||||
|
||||
@JsonProperty("Attr01")
|
||||
private String attr01;
|
||||
|
||||
@@ -1030,11 +1030,6 @@ public class MesToWmsServiceImpl implements MesToWmsService {
|
||||
if (iPmProductReturnService.getById(param.getId()) != null) {
|
||||
throw new BadRequestException("当前生产退料单已存在");
|
||||
}
|
||||
WorkOrderDao workOrder = workOrderService.getOne(new LambdaQueryWrapper<WorkOrderDao>()
|
||||
.eq(WorkOrderDao::getOrder_code, param.getWorkOrderCode()));
|
||||
if (workOrder == null) {
|
||||
throw new BadRequestException("WMS不存在工单:" + param.getWorkOrderCode());
|
||||
}
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(param.getSkuCode());
|
||||
if (material == null) {
|
||||
throw new BadRequestException("当前物料信息不存在" + param.getSkuCode());
|
||||
|
||||
@@ -411,7 +411,7 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
|
||||
}
|
||||
final List<ReceiveOutRequest.Entrys> entrys = new ArrayList<>();
|
||||
List<FeedingRecordBom> feedingRecordBoms = feedingRecordBomMapper.selectList(new LambdaQueryWrapper<FeedingRecordBom>()
|
||||
.eq(FeedingRecordBom::getWorkOrderCode, param.getWorkOrder()));
|
||||
.eq(FeedingRecordBom::getWork_order_code, param.getWorkOrder()));
|
||||
|
||||
for (WorkOrderBomItem bomItem : workOrderBomItems) {
|
||||
final String materialCode = bomItem.getMaterialCode();
|
||||
@@ -419,7 +419,7 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
|
||||
if (bomQty == null || bomQty.intValue() == 0){
|
||||
continue;
|
||||
}
|
||||
boolean hasBom = feedingRecordBoms.stream().anyMatch(i -> Objects.equals(i.getMaterialCode(), bomItem.getMaterialCode()));
|
||||
boolean hasBom = feedingRecordBoms.stream().anyMatch(i -> Objects.equals(i.getMaterial_code(), bomItem.getMaterialCode()));
|
||||
final BigDecimal qty = bomQty.multiply(param.getReportedQty()).setScale(0, RoundingMode.HALF_UP);
|
||||
ReceiveOutRequest.Entrys entry = new ReceiveOutRequest.Entrys();
|
||||
if (hasBom) entry.setStatus(StockReturnStatusEnum.IGNORE.getCode());
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;import org.nl.common.base.ResponseData;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ERP回传管理 控制层
|
||||
* SAP回传管理 控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -31,34 +31,34 @@ PmStockReturnController {
|
||||
private IPmStockReturnService pmStockReturnService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询ERP回传管理")
|
||||
@Log("查询SAP回传管理")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
|
||||
return ResponseData.build(pmStockReturnService.queryAll(whereJson, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增ERP回传管理")
|
||||
@Log("新增SAP回传管理")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody PmStockReturn stockReturn) {
|
||||
pmStockReturnService.save(stockReturn);
|
||||
return ResponseData.build(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改ERP回传管理")
|
||||
@Log("修改SAP回传管理")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody PmStockReturn stockReturn) {
|
||||
pmStockReturnService.update(stockReturn);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除ERP回传管理")
|
||||
@Log("删除SAP回传管理")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Integer> ids) {
|
||||
pmStockReturnService.delete(ids);
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
@Log("ERP回传")
|
||||
@Log("SAP回传")
|
||||
public ResponseEntity<Object> upload(@RequestBody JSONObject whereJson) {
|
||||
pmStockReturnService.upload(whereJson);
|
||||
return ResponseData.build();
|
||||
|
||||
@@ -12,85 +12,85 @@ public class FeedingRecord {
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
private String orderId;
|
||||
private String order_id;
|
||||
|
||||
private String orderCode;
|
||||
private String order_code;
|
||||
|
||||
private String orderStatus;
|
||||
private String order_status;
|
||||
|
||||
private String orgCode;
|
||||
private String org_code;
|
||||
|
||||
private String bizDeptCode;
|
||||
private String biz_dept_code;
|
||||
|
||||
private String bizDeptName;
|
||||
private String biz_dept_name;
|
||||
|
||||
private String orderType;
|
||||
private String order_type;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String createdBy;
|
||||
private String created_by;
|
||||
|
||||
private String modifiedBy;
|
||||
private String modified_by;
|
||||
|
||||
private String checkedBy;
|
||||
private String checked_by;
|
||||
|
||||
private String createdOn;
|
||||
private String created_on;
|
||||
|
||||
private String modifiedOn;
|
||||
private String modified_on;
|
||||
|
||||
private String modifiedTime;
|
||||
private String modified_time;
|
||||
|
||||
private String bomCode;
|
||||
private String bom_code;
|
||||
|
||||
private BigDecimal orderQty;
|
||||
private BigDecimal order_qty;
|
||||
|
||||
private BigDecimal finishedQty;
|
||||
private BigDecimal finished_qty;
|
||||
|
||||
private String finishedRate;
|
||||
private String finished_rate;
|
||||
|
||||
private String planStartedOn;
|
||||
private String plan_started_on;
|
||||
|
||||
private String planFinishedOn;
|
||||
private String plan_finished_on;
|
||||
|
||||
private String actualStartedOn;
|
||||
private String actual_started_on;
|
||||
|
||||
private String actualFinishedOn;
|
||||
private String actual_finished_on;
|
||||
|
||||
private String defaultWarehouseCode;
|
||||
private String default_warehouse_code;
|
||||
|
||||
private String defaultWarehouseName;
|
||||
private String default_warehouse_name;
|
||||
|
||||
private String trackNo;
|
||||
private String track_no;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String bizDate;
|
||||
private String biz_date;
|
||||
|
||||
private String productCode;
|
||||
private String product_code;
|
||||
|
||||
private String productName;
|
||||
private String product_name;
|
||||
|
||||
private String productSpec;
|
||||
private String product_spec;
|
||||
|
||||
private String colorCode;
|
||||
private String color_code;
|
||||
|
||||
private String snDetail;
|
||||
private String sn_detail;
|
||||
|
||||
private String processPlan;
|
||||
private String process_plan;
|
||||
|
||||
private String stepCode;
|
||||
private String step_code;
|
||||
|
||||
private String lotNumber;
|
||||
private String lot_number;
|
||||
|
||||
private String productionStatus;
|
||||
private String production_status;
|
||||
|
||||
private String workArea;
|
||||
private String work_area;
|
||||
|
||||
private String workAreaType;
|
||||
private String work_area_type;
|
||||
|
||||
private String teamName;
|
||||
private String team_name;
|
||||
|
||||
private Integer seqNo;
|
||||
private String seq_no;
|
||||
|
||||
private String attr01;
|
||||
private String attr02;
|
||||
@@ -99,21 +99,21 @@ public class FeedingRecord {
|
||||
private String attr05;
|
||||
private String attr06;
|
||||
|
||||
private Integer serNo;
|
||||
private Integer ser_no;
|
||||
|
||||
private String srcOrderCode;
|
||||
private String src_order_code;
|
||||
|
||||
private String factory;
|
||||
|
||||
private String workshop;
|
||||
|
||||
private String productType;
|
||||
private String product_type;
|
||||
|
||||
private String layoutCode;
|
||||
private String layout_code;
|
||||
|
||||
private String externalId;
|
||||
private String external_id;
|
||||
|
||||
private String createTime;
|
||||
private String create_time;
|
||||
|
||||
private String updateTime;
|
||||
private String update_time;
|
||||
}
|
||||
|
||||
@@ -12,47 +12,47 @@ public class FeedingRecordBom {
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
private String itemId;
|
||||
private String item_id;
|
||||
|
||||
private Integer itemNo;
|
||||
private Integer item_no;
|
||||
|
||||
private String materialCode;
|
||||
private String material_code;
|
||||
|
||||
private String materialName;
|
||||
private String material_name;
|
||||
|
||||
private String spec;
|
||||
|
||||
private String unit;
|
||||
|
||||
private String baseUnit;
|
||||
private String base_unit;
|
||||
|
||||
private BigDecimal bomQty;
|
||||
private BigDecimal bom_qty;
|
||||
|
||||
private String workCenter;
|
||||
private String work_center;
|
||||
|
||||
private String loadPort;
|
||||
private String load_port;
|
||||
|
||||
private String deptCode;
|
||||
private String dept_code;
|
||||
|
||||
private String supOrgCode;
|
||||
private String sup_org_code;
|
||||
|
||||
private String warehouseCode;
|
||||
private String warehouse_code;
|
||||
|
||||
private String warehouseName;
|
||||
private String warehouse_name;
|
||||
|
||||
private String stockerCode;
|
||||
private String stocker_code;
|
||||
|
||||
private String stockerName;
|
||||
private String stocker_name;
|
||||
|
||||
private String workOrderCode;
|
||||
private String work_order_code;
|
||||
|
||||
private String linePod;
|
||||
private String line_pod;
|
||||
|
||||
private String bomProp1;
|
||||
private String bom_prop1;
|
||||
|
||||
private String bomProp2;
|
||||
private String bom_prop2;
|
||||
|
||||
private String bomProp3;
|
||||
private String bom_prop3;
|
||||
|
||||
private String attr01;
|
||||
private String attr02;
|
||||
@@ -61,13 +61,13 @@ public class FeedingRecordBom {
|
||||
private String attr05;
|
||||
private String attr06;
|
||||
|
||||
private String trackNo;
|
||||
private String track_no;
|
||||
|
||||
private BigDecimal wmsQty;
|
||||
private BigDecimal wms_qty;
|
||||
|
||||
private BigDecimal eas5Qty;
|
||||
private BigDecimal eas5_qty;
|
||||
|
||||
private BigDecimal eas4Qty;
|
||||
private BigDecimal eas4_qty;
|
||||
|
||||
private String matkl;
|
||||
|
||||
@@ -117,9 +117,9 @@ public class FeedingRecordBom {
|
||||
|
||||
private String backup4;
|
||||
|
||||
private String externalId;
|
||||
private String external_id;
|
||||
|
||||
private String createTime;
|
||||
private String create_time;
|
||||
|
||||
private String updateTime;
|
||||
private String update_time;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,204 @@
|
||||
package org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.ProductionOutboundBody;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.ProductionOutboundHeader;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.ProductionOutboundRequest;
|
||||
import org.nl.wms.ext_manage.sap.enums.SapConstant;
|
||||
import org.nl.wms.ext_manage.service.dto.FeedingRecordPushDto;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.dao.FeedingRecord;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.dao.FeedingRecordBom;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.mapper.FeedingRecordBomMapper;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.mapper.FeedingRecordMapper;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.service.IFeedingRecordService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FeedingRecordServiceImpl extends ServiceImpl<FeedingRecordMapper, FeedingRecord> implements IFeedingRecordService {
|
||||
|
||||
private static final DateTimeFormatter DATE_BASIC = DateTimeFormatter.BASIC_ISO_DATE;
|
||||
|
||||
@Autowired
|
||||
private FeedingRecordBomMapper feedingRecordBomMapper;
|
||||
@Autowired
|
||||
private SapApi sapApi;
|
||||
@Autowired
|
||||
private IPmStockReturnService iPmStockReturnService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void pushFeedingBill(FeedingRecordPushDto param) {
|
||||
log.info("-----收到投料记录推送:{}", JSON.toJSONString(param));
|
||||
FeedingRecord feedingRecord = new FeedingRecord();
|
||||
BeanUtils.copyProperties(param,feedingRecord);
|
||||
BeanUtil.copyProperties(param, feedingRecord, CopyOptions.create()
|
||||
.setFieldNameEditor(StrUtil::toUnderlineCase)
|
||||
.setIgnoreProperties("bom", "workOrderBomList", "workOrderSnList"));
|
||||
if (StringUtils.isEmpty(feedingRecord.getId())) {
|
||||
feedingRecord.setId(IdUtil.getStringId());
|
||||
}
|
||||
this.saveOrUpdate(feedingRecord);
|
||||
List<FeedingRecordPushDto.FeedingRecordPushBomDto> bom = param.getBom();
|
||||
for (FeedingRecordPushDto.FeedingRecordPushBomDto bomDto : bom) {
|
||||
FeedingRecordBom feedingRecordBom = new FeedingRecordBom();
|
||||
BeanUtils.copyProperties(bomDto,feedingRecordBom);
|
||||
if (StringUtils.isEmpty(feedingRecordBom.getId())){
|
||||
feedingRecordBom.setId(IdUtil.getStringId());
|
||||
if (!CollectionUtils.isEmpty(bom)) {
|
||||
for (FeedingRecordPushDto.FeedingRecordPushBomDto bomDto : bom) {
|
||||
FeedingRecordBom feedingRecordBom = new FeedingRecordBom();
|
||||
BeanUtil.copyProperties(bomDto, feedingRecordBom, CopyOptions.create()
|
||||
.setFieldNameEditor(StrUtil::toUnderlineCase));
|
||||
if (StringUtils.isEmpty(feedingRecordBom.getId())) {
|
||||
feedingRecordBom.setId(IdUtil.getStringId());
|
||||
}
|
||||
feedingRecordBomMapper.insert(feedingRecordBom);
|
||||
}
|
||||
feedingRecordBomMapper.insert(feedingRecordBom);
|
||||
}
|
||||
// MES 投料数据回传 SAP PP055,结果落库 stockReturn
|
||||
callbackSapProductionOutbound(param, feedingRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 MES 投料清单调用 SAP PP055 生产投料,回传结果保存到 pm_stock_return
|
||||
*/
|
||||
private void callbackSapProductionOutbound(FeedingRecordPushDto param, FeedingRecord feedingRecord) {
|
||||
if (param == null || CollectionUtils.isEmpty(param.getBom())) {
|
||||
log.warn("MES投料回传SAP跳过:BOM为空, orderCode={}", feedingRecord != null ? feedingRecord.getOrder_code() : null);
|
||||
return;
|
||||
}
|
||||
String orderCode = StrUtil.blankToDefault(param.getOrderCode(), feedingRecord.getOrder_code());
|
||||
ProductionOutboundRequest request = buildPp055Request(param, feedingRecord);
|
||||
if (CollectionUtils.isEmpty(request.getBody())) {
|
||||
log.warn("MES投料回传SAP跳过:无有效投料行, orderCode={}", orderCode);
|
||||
return;
|
||||
}
|
||||
PmStockReturn stockReturn = new PmStockReturn();
|
||||
stockReturn.setRequest_Id(StrUtil.blankToDefault(feedingRecord.getId(), orderCode));
|
||||
stockReturn.setRequest_type(IOSEnum.BILL_TYPE.code("生产出库"));
|
||||
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode());
|
||||
stockReturn.setCreate_time(DateUtil.now());
|
||||
stockReturn.setRequest_data(JSON.toJSONString(request));
|
||||
try {
|
||||
JSONObject sapResult = sapApi.productionOutbound(request);
|
||||
stockReturn.setStatus(StockReturnStatusEnum.SUCESS.getCode());
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
JSONObject record = new JSONObject();
|
||||
record.put("request", request);
|
||||
record.put("response", sapResult);
|
||||
stockReturn.setRequest_data(record.toJSONString());
|
||||
} catch (Exception e) {
|
||||
log.error("MES投料工单{}回传SAP PP055失败", orderCode, e);
|
||||
String errorMsg = e.getMessage();
|
||||
if (errorMsg != null && errorMsg.length() > 255) {
|
||||
errorMsg = errorMsg.substring(0, 255);
|
||||
}
|
||||
stockReturn.setError_msg(errorMsg);
|
||||
stockReturn.setStatus(StockReturnStatusEnum.FAIL.getCode());
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
}
|
||||
iPmStockReturnService.save(stockReturn);
|
||||
}
|
||||
|
||||
private ProductionOutboundRequest buildPp055Request(FeedingRecordPushDto param, FeedingRecord feedingRecord) {
|
||||
String postDate = resolveSapDate(param.getBizDate());
|
||||
String docno = StrUtil.blankToDefault(param.getOrderCode(), "FEED" + System.currentTimeMillis());
|
||||
String aufnr = StrUtil.blankToDefault(param.getOrderCode(), feedingRecord.getOrder_code());
|
||||
String werks = StrUtil.blankToDefault(param.getFactory(), SapConstant.WERKS);
|
||||
String defaultLgort = StrUtil.blankToDefault(param.getDefaultWarehouseCode(), "");
|
||||
|
||||
ProductionOutboundRequest request = new ProductionOutboundRequest();
|
||||
ProductionOutboundHeader header = new ProductionOutboundHeader();
|
||||
header.setIntfId(SapConstant.INTF_PP055);
|
||||
header.setSrcSystem(SapConstant.SRC_SYSTEM);
|
||||
header.setDestSystem(SapConstant.DEST_SYSTEM);
|
||||
header.setRequesttime(System.currentTimeMillis());
|
||||
request.setHeader(header);
|
||||
|
||||
List<ProductionOutboundBody> bodyList = new ArrayList<>();
|
||||
for (FeedingRecordPushDto.FeedingRecordPushBomDto bom : param.getBom()) {
|
||||
if (bom == null || StrUtil.isBlank(bom.getMaterialCode())) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal qty = resolveQty(bom);
|
||||
if (qty.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
continue;
|
||||
}
|
||||
ProductionOutboundBody body = new ProductionOutboundBody();
|
||||
body.setDocno(docno);
|
||||
body.setBudat(postDate);
|
||||
body.setBldat(postDate);
|
||||
body.setMatnr(bom.getMaterialCode());
|
||||
body.setWerks(werks);
|
||||
body.setLgort(StrUtil.blankToDefault(bom.getWarehouseCode(), defaultLgort));
|
||||
body.setAufnr(StrUtil.blankToDefault(bom.getWorkOrderCode(), aufnr));
|
||||
body.setErfmg(qty.doubleValue());
|
||||
body.setRsnum(StrUtil.blankToDefault(bom.getRsnum(), ""));
|
||||
body.setRspos(StrUtil.blankToDefault(bom.getRspos(), ""));
|
||||
body.setTl("");
|
||||
body.setBackup1(StrUtil.blankToDefault(bom.getBackup1(), ""));
|
||||
body.setBackup2(StrUtil.blankToDefault(bom.getBackup2(), ""));
|
||||
body.setBackup3(StrUtil.blankToDefault(bom.getBackup3(), ""));
|
||||
body.setBackup4(StrUtil.blankToDefault(bom.getBackup4(), ""));
|
||||
body.setBackup5("");
|
||||
bodyList.add(body);
|
||||
}
|
||||
request.setBody(bodyList);
|
||||
return request;
|
||||
}
|
||||
|
||||
private BigDecimal resolveQty(FeedingRecordPushDto.FeedingRecordPushBomDto bom) {
|
||||
if (bom.getEnmng() != null && bom.getEnmng().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return bom.getEnmng();
|
||||
}
|
||||
if (bom.getWmsQty() != null && bom.getWmsQty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return bom.getWmsQty();
|
||||
}
|
||||
if (bom.getBomQty() != null && bom.getBomQty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return bom.getBomQty();
|
||||
}
|
||||
if (bom.getEas5Qty() != null && bom.getEas5Qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return bom.getEas5Qty();
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private String resolveSapDate(String bizDate) {
|
||||
String today = LocalDate.now().format(DATE_BASIC);
|
||||
if (StrUtil.isBlank(bizDate)) {
|
||||
return today;
|
||||
}
|
||||
String value = bizDate.trim();
|
||||
if (value.matches("\\d{8}")) {
|
||||
return value;
|
||||
}
|
||||
if (value.matches("\\d{4}-\\d{2}-\\d{2}.*")) {
|
||||
return value.substring(0, 10).replace("-", "");
|
||||
}
|
||||
try {
|
||||
return LocalDate.parse(value.substring(0, Math.min(10, value.length()))).format(DATE_BASIC);
|
||||
} catch (DateTimeParseException e) {
|
||||
log.warn("MES投料业务日期格式转换失败,使用当天。原始值={}", bizDate);
|
||||
return today;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ERP回传管理 服务类
|
||||
* SAP回传管理 服务类
|
||||
*/
|
||||
public interface IPmStockReturnService extends IService<PmStockReturn> {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ERP回传管理
|
||||
* SAP回传管理
|
||||
*/
|
||||
@Data
|
||||
@TableName("pm_stock_return")
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.ext_manage.service.WmsToErpService;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||
@@ -23,13 +23,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ERP回传管理 服务实现类
|
||||
* SAP回传管理 服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class PmStockReturnServiceImpl extends ServiceImpl<PmStockReturnMapper, PmStockReturn> implements IPmStockReturnService {
|
||||
|
||||
@Resource
|
||||
private WmsToErpService wmsToErpService;
|
||||
private SapApi sapApi;
|
||||
|
||||
@Override
|
||||
public IPage<PmStockReturn> queryAll(Map whereJson, PageQuery page) {
|
||||
@@ -90,7 +90,16 @@ public class PmStockReturnServiceImpl extends ServiceImpl<PmStockReturnMapper, P
|
||||
}
|
||||
try {
|
||||
JSONObject requestData = parseRequestData(stockReturn.getRequest_data());
|
||||
wmsToErpService.uploadErp(requestData);
|
||||
JSONObject sapResult = sapApi.upload(requestData);
|
||||
JSONObject record = new JSONObject();
|
||||
JSONObject request = requestData.getJSONObject("request");
|
||||
if (request != null && request.get("header") != null) {
|
||||
record.put("request", request);
|
||||
} else {
|
||||
record.put("request", requestData);
|
||||
}
|
||||
record.put("response", sapResult);
|
||||
stockReturn.setRequest_data(record.toJSONString());
|
||||
stockReturn.setStatus(StockReturnStatusEnum.SUCESS.getCode());
|
||||
stockReturn.setError_msg(null);
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
|
||||
/**
|
||||
* ERP回传管理 Mapper
|
||||
* SAP回传管理 Mapper
|
||||
*/
|
||||
public interface PmStockReturnMapper extends BaseMapper<PmStockReturn> {
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" min-width="90" :formatter="formatStatus" />
|
||||
<el-table-column prop="error_msg" label="ERP处理失败记录" min-width="220" show-overflow-tooltip />
|
||||
<el-table-column prop="error_msg" label="SAP处理失败记录" min-width="220" show-overflow-tooltip />
|
||||
<el-table-column prop="create_time" label="单据创建时间" min-width="160" />
|
||||
<el-table-column prop="process_time" label="成功时间" min-width="160" />
|
||||
<el-table-column label="回传JSON数据" min-width="120" align="center">
|
||||
@@ -140,7 +140,7 @@ export default {
|
||||
components: { crudOperation, rrOperation, pagination },
|
||||
cruds() {
|
||||
return CRUD({
|
||||
title: 'ERP回传管理', idField: 'id', url: 'api/stockReturn', crudMethod: { ...inandoutreturn },
|
||||
title: 'SAP回传管理', idField: 'id', url: 'api/stockReturn', crudMethod: { ...inandoutreturn },
|
||||
optShow: {
|
||||
add: false,
|
||||
edit: false,
|
||||
|
||||
Reference in New Issue
Block a user