add:收货增加交货单同步
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.nl.wms.ext_manage.sap.api;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -14,20 +15,38 @@ import org.nl.wms.ext_manage.sap.api.dto.ProductionOutboundRequest;
|
||||
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.nl.wms.pm_manage.sap.sapDelivery.service.SapDeliveryService;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.DeliveryOrderDTO;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapBody;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapHeader;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapItemBody;
|
||||
import org.nl.wms.system_manage.service.param.ISysParamService;
|
||||
import org.nl.wms.system_manage.service.param.dao.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SapApi {
|
||||
private static final DateTimeFormatter REQUEST_TIME_FMT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
|
||||
@Autowired
|
||||
private ISysParamService sysParamService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private SapDeliveryService sapDeliveryService;
|
||||
|
||||
//TODO 系统参数添加
|
||||
private static String BASIC_AUTH_USER = "sb-44f42158-6589-470d-94e2-cb4ff68ff64e!b6440|it-rt-prd-mc97okah!b39";
|
||||
private static String BASIC_AUTH_PASSWORD = "07c6eebc-1ff3-4f73-a4d8-870757951649$WTL_Vf-jxg8aWRlTvxP8BC8oloOYosae2JzQykImlpg=";
|
||||
@@ -106,6 +125,129 @@ public class SapApi {
|
||||
return postQuery("SAP库存查询[" + SapConstant.INTF_MM027 + "]", buildStockQueryRequest(matnr, werks, lgort));
|
||||
}
|
||||
|
||||
/**
|
||||
* MM067 交货单查询。按交货单号拉取 SAP 交货单明细,并调用 {@code insertSapJhd} 落库。
|
||||
*
|
||||
* @param vbeln 交货单号
|
||||
*/
|
||||
public JSONObject deliveryQuery(String vbeln) {
|
||||
if (StrUtil.isBlank(vbeln)) {
|
||||
throw new BadRequestException("SAP交货单查询失败:交货单号为空");
|
||||
}
|
||||
String deliveryNo = vbeln.trim();
|
||||
JSONObject response = postQuery("SAP交货单查询[" + SapConstant.INTF_MM067 + "]", buildDeliveryQueryRequest(deliveryNo));
|
||||
final JSONObject header = response.getJSONObject("header");
|
||||
final JSONObject body = response.getJSONObject("body").getJSONObject("data");
|
||||
final JSONArray item = body.getJSONArray("item");
|
||||
final SapBody sapBody = body.toJavaObject(SapBody.class);
|
||||
sapBody.setBody(item.toJavaList(SapItemBody.class));
|
||||
sapBody.setBldat(DateUtil.today());
|
||||
sapBody.setLfdat(DateUtil.today());
|
||||
sapBody.setLifnr("调拨收货");
|
||||
final DeliveryOrderDTO orderDTO = new DeliveryOrderDTO();
|
||||
orderDTO.setHeader(header.toJavaObject(SapHeader.class));
|
||||
orderDTO.setBody(Arrays.asList(sapBody));
|
||||
return sapDeliveryService.insertSapJhd(orderDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 MM067 交货单查询deliveryOrderDTO = {DeliveryOrderDTO@15376} "DeliveryOrderDTO(header=null, body=[SapBody(vbeln=80000052, bldat=null, lifnr=, wadat=null, lfdat=null, lfart=null, wadatIst=null, body=[SapItemBody(vbeln=80000052, posnr=000010, material=256814011002, matl_desc=变速箱(中柴), deliv_qty=12.0, unit=PCS, po_number=null, po_item=null, werks=1040, lgort=R002, ntgew=null, brgew=null, gewei=null, volum=null, voleh=null, uebtk=null, uebto=null, untto=null, lifexpos=null, body=null, rs_items=null)])])"请求。除交货单号外,报文头按接口约定固定。
|
||||
*/
|
||||
private JSONObject buildDeliveryQueryRequest(String vbeln) {
|
||||
JSONObject header = new JSONObject();
|
||||
header.put("intf_id", SapConstant.INTF_MM067);
|
||||
header.put("src_system", SapConstant.SRC_SYSTEM);
|
||||
header.put("dest_system", SapConstant.DEST_SYSTEM);
|
||||
header.put("src_msgid", "");
|
||||
header.put("requesttime", LocalDateTime.now().format(REQUEST_TIME_FMT));
|
||||
header.put("backup1", "");
|
||||
header.put("backup2", "");
|
||||
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("vbeln", vbeln);
|
||||
JSONArray body = new JSONArray();
|
||||
body.add(item);
|
||||
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("header", header);
|
||||
request.put("BODY", body);
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 MM067 响应解析为交货单同步报文。
|
||||
* body 为对象:status/message 表示结果,明细在 body.data,行项目在 body.data.item。
|
||||
*/
|
||||
private DeliveryOrderDTO parseDeliveryOrder(JSONObject response, String vbeln) {
|
||||
if (response == null) {
|
||||
throw new BadRequestException("SAP交货单查询失败:响应为空");
|
||||
}
|
||||
JSONObject body = response.getJSONObject("body");
|
||||
if (body == null) {
|
||||
throw new BadRequestException("SAP交货单查询失败:响应缺少body");
|
||||
}
|
||||
if ("E".equalsIgnoreCase(body.getString("status"))) {
|
||||
throw new BadRequestException(StrUtil.blankToDefault(body.getString("message"), "SAP交货单查询失败"));
|
||||
}
|
||||
JSONObject data = body.getJSONObject("data");
|
||||
if (data == null) {
|
||||
throw new BadRequestException("SAP交货单查询失败:未查询到交货单" + vbeln + "的明细");
|
||||
}
|
||||
String deliveryNo = StrUtil.blankToDefault(StrUtil.trim(data.getString("vbeln")), vbeln);
|
||||
List<SapItemBody> items = parseDeliveryItems(data.get("item"), deliveryNo);
|
||||
if (items.isEmpty()) {
|
||||
throw new BadRequestException("SAP交货单查询失败:未查询到交货单" + deliveryNo + "的明细");
|
||||
}
|
||||
|
||||
SapBody order = new SapBody();
|
||||
order.setVbeln(deliveryNo);
|
||||
order.setLifnr(StrUtil.trim(data.getString("lifnr")));
|
||||
order.setBody(items);
|
||||
|
||||
DeliveryOrderDTO deliveryOrderDTO = new DeliveryOrderDTO();
|
||||
deliveryOrderDTO.setBody(Collections.singletonList(order));
|
||||
return deliveryOrderDTO;
|
||||
}
|
||||
|
||||
private List<SapItemBody> parseDeliveryItems(Object itemValue, String vbeln) {
|
||||
JSONArray items = toJsonArray(itemValue);
|
||||
List<SapItemBody> result = new ArrayList<>();
|
||||
if (items == null) {
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
JSONObject one = items.getJSONObject(i);
|
||||
if (one == null) {
|
||||
continue;
|
||||
}
|
||||
SapItemBody line = new SapItemBody();
|
||||
line.setVbeln(StrUtil.blankToDefault(StrUtil.trim(one.getString("vbeln")), vbeln));
|
||||
line.setPosnr(StrUtil.trim(one.getString("posnr")));
|
||||
line.setMaterial(StrUtil.trim(one.getString("material")));
|
||||
line.setMatl_desc(StrUtil.trim(one.getString("matl_desc")));
|
||||
line.setDeliv_qty(one.getDouble("deliv_qty"));
|
||||
line.setUnit(StrUtil.trim(one.getString("unit")));
|
||||
line.setPo_number(StrUtil.trim(one.getString("po_number")));
|
||||
line.setPo_item(StrUtil.trim(one.getString("po_item")));
|
||||
line.setWerks(StrUtil.trim(one.getString("werks")));
|
||||
line.setLgort(StrUtil.trim(one.getString("lgort")));
|
||||
result.add(line);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private JSONArray toJsonArray(Object value) {
|
||||
if (value instanceof JSONArray) {
|
||||
return (JSONArray) value;
|
||||
}
|
||||
if (value instanceof JSONObject) {
|
||||
JSONArray array = new JSONArray();
|
||||
array.add(value);
|
||||
return array;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* MDG004 供应商主数据查询(按供应商编码,返回体与写入类接口一致,body 为数组)
|
||||
*
|
||||
|
||||
@@ -24,6 +24,9 @@ public class SapConstant {
|
||||
/** 接口编号:委外出库倒冲 */
|
||||
public static final String INTF_MM065 = "MM065";
|
||||
|
||||
/** 接口编号:交货单查询(按交货单号拉取明细) */
|
||||
public static final String INTF_MM067 = "MM067";
|
||||
|
||||
/** 接口编号:销售退货出库(采购订单) */
|
||||
public static final String INTF_MM021 = "MM021";
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.nl.common.base.ResponseData;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.SapDeliveryService;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryConfirmDto;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryOrderDto;
|
||||
@@ -35,6 +36,7 @@ import java.util.List;
|
||||
public class SapDeliveryController {
|
||||
|
||||
private final SapDeliveryService sapDeliveryService;
|
||||
private final SapApi sapApi;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询SAP交货单")
|
||||
@@ -66,6 +68,15 @@ public class SapDeliveryController {
|
||||
return ResponseData.build();
|
||||
}
|
||||
|
||||
@PostMapping("/sync")
|
||||
@Log("MM067收货单同步")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> sync(@RequestBody JSONObject request) {
|
||||
String vbeln = request == null ? null : request.getString("vbeln");
|
||||
JSONObject result = sapApi.deliveryQuery(vbeln);
|
||||
return ResponseData.build(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/confirmReceipt")
|
||||
@Log("SAP交货单收货确认")
|
||||
@SaIgnore
|
||||
|
||||
@@ -41,6 +41,15 @@
|
||||
:disabled="isConfirmDisabled()"
|
||||
@click="handleConfirmReceipt"
|
||||
>收货确认</el-button>
|
||||
<el-button
|
||||
slot="right"
|
||||
class="filter-item"
|
||||
type="primary"
|
||||
icon="el-icon-refresh"
|
||||
size="mini"
|
||||
:loading="syncing"
|
||||
@click="openSyncDialog"
|
||||
>收货单同步</el-button>
|
||||
</crudOperation>
|
||||
|
||||
<el-dialog
|
||||
@@ -230,6 +239,23 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:visible.sync="syncVisible"
|
||||
title="收货单同步"
|
||||
width="460px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form size="mini" label-width="90px" label-suffix=":" @submit.native.prevent>
|
||||
<el-form-item label="收货单号">
|
||||
<el-input v-model.trim="syncVbeln" placeholder="请输入收货单号" @keyup.enter.native="submitSync" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button size="mini" @click="syncVisible = false">取消</el-button>
|
||||
<el-button size="mini" type="primary" :loading="syncing" @click="submitSync">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:visible.sync="detailVisible"
|
||||
title="交货单明细"
|
||||
@@ -316,7 +342,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import crudSapDelivery, { getDetail, confirmReceipt } from './sapDelivery'
|
||||
import crudSapDelivery, { getDetail, confirmReceipt, syncSapJhd } from './sapDelivery'
|
||||
import { getStor } from '@/views/wms/basedata/bsrealstorattr/bsrealstorattr'
|
||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||
import crudOperation from '@crud/CRUD.operation.vue'
|
||||
@@ -379,6 +405,9 @@ export default {
|
||||
],
|
||||
multipleSelection: [],
|
||||
confirming: false,
|
||||
syncing: false,
|
||||
syncVisible: false,
|
||||
syncVbeln: '',
|
||||
confirmVisible: false,
|
||||
confirmVbelns: [],
|
||||
batchLgort: false,
|
||||
@@ -523,6 +552,26 @@ export default {
|
||||
this.confirmLgort = ''
|
||||
this.confirmVisible = true
|
||||
},
|
||||
openSyncDialog() {
|
||||
this.syncVbeln = (this.query.vbeln || '').trim()
|
||||
this.syncVisible = true
|
||||
},
|
||||
submitSync() {
|
||||
const vbeln = (this.syncVbeln || '').trim()
|
||||
if (!vbeln) {
|
||||
this.crud.notify('请输入收货单号', CRUD.NOTIFICATION_TYPE.INFO)
|
||||
return
|
||||
}
|
||||
this.syncing = true
|
||||
syncSapJhd(vbeln).then(res => {
|
||||
const result = res.data || {}
|
||||
this.crud.notify(result.respMsg || '收货单同步成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||
this.syncVisible = false
|
||||
this.crud.toQuery()
|
||||
}).finally(() => {
|
||||
this.syncing = false
|
||||
})
|
||||
},
|
||||
submitConfirmReceipt() {
|
||||
if (!this.confirmVbelns.length) {
|
||||
this.confirmVisible = false
|
||||
|
||||
@@ -45,4 +45,16 @@ export function confirmReceipt(vbelns, lgort) {
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del, getDetail, confirmReceipt }
|
||||
/**
|
||||
* MM067 按收货单号从 SAP 同步交货单
|
||||
* @param {String} vbeln 收货单号
|
||||
*/
|
||||
export function syncSapJhd(vbeln) {
|
||||
return request({
|
||||
url: 'api/sapDelivery/sync',
|
||||
method: 'post',
|
||||
data: { vbeln }
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del, getDetail, confirmReceipt, syncSapJhd }
|
||||
|
||||
Reference in New Issue
Block a user