fix(完工入库报工): 新增物料消耗报工job、完工入库过账日期自定义1.3
This commit is contained in:
parent
46193d0017
commit
558778b94b
@ -47,12 +47,7 @@ public class SapMaterialConsumptionJob {
|
||||
String site = null;
|
||||
String startDate = null;
|
||||
String endDate = null;
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialConsumptionTransaction> newList = new ArrayList<>();
|
||||
String postingDate = "";
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialConsumptionTransaction> srcList = new ArrayList<>();
|
||||
String jobParam = XxlJobHelper.getJobParam();
|
||||
String postingDate = null;String jobParam = XxlJobHelper.getJobParam();
|
||||
if (StrUtil.isNotBlank(jobParam)) {
|
||||
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
|
||||
site = paramMap.get("site");
|
||||
@ -70,6 +65,9 @@ public class SapMaterialConsumptionJob {
|
||||
startDate = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
endDate = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
XxlJobHelper.log("*************************站点:" + site +",开始261物料消耗同步至ERP************************");
|
||||
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
|
||||
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
|
||||
List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactionList = zLotMaterialConsumptionTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialConsumptionTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialConsumptionTransaction::getSite, site).ne(
|
||||
@ -82,10 +80,14 @@ public class SapMaterialConsumptionJob {
|
||||
}
|
||||
|
||||
for (ZLotMaterialConsumptionTransaction consumptionTransaction : zLotMaterialConsumptionTransactionList) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialConsumptionTransaction> srcList = new ArrayList<>();
|
||||
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialConsumptionTransaction targetObj = zLotMaterialConsumptionTransactionMapper.selectById(consumptionTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "消耗已经报工,不可重复报工");
|
||||
XxlJobHelper.log("ERROR:批次" + targetObj.getLotNo() + "已经报消耗,不可重复报消耗");
|
||||
} else {
|
||||
LocalDate syncPostingDate = consumptionTransaction.getSyncPostingDate();
|
||||
if (syncPostingDate != null) {
|
||||
@ -128,47 +130,43 @@ public class SapMaterialConsumptionJob {
|
||||
jsonObject.put("RSNUM", consumptionTransaction.getReservedNo()); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", consumptionTransaction.getReservedLine()); // 预留 / 相关需求的项目编号
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
}
|
||||
if (!itemList.isEmpty()) {
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
// 传参对象
|
||||
try {
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime);
|
||||
invokeRequest.setFromSystem("IEP");
|
||||
invokeRequest.setToSystem("ERP");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId("ZMM_MES_GOODSMVT_CREATE");
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String jsonObjectStr = SapUtil.appendHead(assembleMaterialMsgBody(itemList, postingDate));
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(nowTime);
|
||||
invokeRequest.setRetry(false);
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = goodMvtCreateService.call(invokeRequest);
|
||||
// 处理ERP返回的报文
|
||||
invokeResponse = updateMaterialConsumption(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
// 传参对象
|
||||
try {
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime);
|
||||
invokeRequest.setFromSystem("IEP");
|
||||
invokeRequest.setToSystem("ERP");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId("ZMM_MES_GOODSMVT_CREATE");
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String jsonObjectStr = SapUtil.appendHead(assembleMaterialMsgBody(itemList, postingDate));
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(nowTime);
|
||||
invokeRequest.setRetry(false);
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = goodMvtCreateService.call(invokeRequest);
|
||||
// 处理ERP返回的报文
|
||||
invokeResponse = updateMaterialConsumption(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("ERROR:批次" + targetObj.getLotNo() + ",消耗同步ERP失败或者异常:" + invokeResponse.getMessageContent());
|
||||
} else {
|
||||
XxlJobHelper.log("SUCCESS:批次" + targetObj.getLotNo() + ",消耗已同步ERP,时间:" + DateUtil.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("ERROR:" + invokeResponse.getMessageContent());
|
||||
return ReturnT.FAIL;
|
||||
} else {
|
||||
XxlJobHelper.log("SUCCESS:101完工入库同步ERP:" + DateUtil.now());
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.handleFail("ERROR:101完工入库同步ERP失败:" + e);
|
||||
@ -188,8 +186,8 @@ public class SapMaterialConsumptionJob {
|
||||
targetObj.setSyncMsgNo(msgno);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setUpdater(SecurityUtils.getUserName());
|
||||
targetObj.setDateUpdate(LocalDateTime.now());
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
|
||||
@ -48,189 +48,195 @@ import java.util.UUID;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class SapShopOrderCompleteJob {
|
||||
|
||||
private final ZLotMaterialCompleteTransactionMapper zLotMaterialCompleteTransactionMapper;
|
||||
private final GoodMvtCreateService goodMvtCreateService;
|
||||
|
||||
@XxlJob("sapShopOrderCompleteJobHandler")
|
||||
public ReturnT<String> sapShopOrderCompleteJobHandler() {
|
||||
try {
|
||||
String site = null;
|
||||
String startDate = null;
|
||||
String endDate = null;
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialCompleteTransaction> newList = new ArrayList<>();
|
||||
String postingDate = "";
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialCompleteTransaction> srcList = new ArrayList<>();
|
||||
String jobParam = XxlJobHelper.getJobParam();
|
||||
if (StrUtil.isNotBlank(jobParam)) {
|
||||
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
|
||||
site = paramMap.get("site");
|
||||
startDate = paramMap.get("startDate");
|
||||
endDate = paramMap.get("endDate");
|
||||
postingDate = paramMap.get("postingDate");
|
||||
}
|
||||
if (StrUtil.isBlank(site)) {
|
||||
XxlJobHelper.log("ERROR:未维护站点[site]参数");
|
||||
return ReturnT.FAIL;
|
||||
} else {
|
||||
TenantContextHolder.setTenantId(site);
|
||||
if (StrUtil.isBlank(startDate) && StrUtil.isBlank(endDate)) {
|
||||
// 没有昨天一天的数据,默认昨天
|
||||
startDate = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
endDate = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactionList = zLotMaterialCompleteTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialCompleteTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialCompleteTransaction::getSite, site).ne(
|
||||
ZLotMaterialCompleteTransaction::getSyncStatus, "S")
|
||||
.gt(ZLotMaterialCompleteTransaction::getDateCreate, startDate)
|
||||
.lt(ZLotMaterialCompleteTransaction::getDateCreate, endDate));
|
||||
if (CollectionUtils.isEmpty(zLotMaterialCompleteTransactionList)) {
|
||||
XxlJobHelper.log("WARN:没有需要同步的101完工入库数据!!!");
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : zLotMaterialCompleteTransactionList) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialCompleteTransaction targetObj = zLotMaterialCompleteTransactionMapper.selectById(completeTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "完工已经报工,不可重复报工");
|
||||
} else {
|
||||
LocalDate syncPostingDate = completeTransaction.getSyncPostingDate();
|
||||
if (syncPostingDate != null) {
|
||||
// 使用原来的过账日期
|
||||
postingDate = syncPostingDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
if (StrUtil.isBlank(postingDate)) {
|
||||
// 如果还不存在,默认为当天过账日期
|
||||
postingDate = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
|
||||
}
|
||||
targetObj.setSyncPostingDate(LocalDate.parse(postingDate));
|
||||
srcList.add(targetObj);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
site = completeTransaction.getSite();
|
||||
jsonObject.put("ZEILE", null); // 物料凭证中的项目
|
||||
jsonObject.put("MATNR", completeTransaction.getErpItem()); // 物料编号
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", completeTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", completeTransaction.getSapBatchNo()); // 批次号
|
||||
jsonObject.put("BWART", "101"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", completeTransaction.getShopOrder()); // 订单号
|
||||
jsonObject.put("EBELN", ""); // 采购订单号
|
||||
jsonObject.put("EBELP", ""); // 采购凭证的项目编号
|
||||
jsonObject.put("MENGE", completeTransaction.getMainQty()); // 数量
|
||||
jsonObject.put("MEINS", completeTransaction.getMainUom()); // 基本计量单位
|
||||
if(completeTransaction.getSubQty()!=null){
|
||||
jsonObject.put("ERFMG", completeTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", completeTransaction.getSubUom()); // 录入单位
|
||||
}else{
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
}
|
||||
jsonObject.put("MAT_KDAUF", completeTransaction.getSoNo()); // 评估销售定单库存的销售定单号
|
||||
if(StringUtils.isNotEmpty(completeTransaction.getSoLineNo())){
|
||||
jsonObject.put("MAT_KDPOS", Integer.valueOf(completeTransaction.getSoLineNo())); // 评估销售订单库存的销售订单项目
|
||||
}else{
|
||||
jsonObject.put("MAT_KDPOS", null); // 评估销售订单库存的销售订单项目
|
||||
}
|
||||
jsonObject.put("UMWRK", ""); // 收货工厂/发货工厂
|
||||
jsonObject.put("UMLGO", ""); // 收货/发货库存地点
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", ""); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", ""); // 预留 / 相关需求的项目编号
|
||||
jsonObject.put("Z_JH", completeTransaction.getLotNo()); // 卷号
|
||||
jsonObject.put("Z_CVN", completeTransaction.getExternalLot()); // 客户卷号
|
||||
jsonObject.put("Z_GRADE", completeTransaction.getQcGrade()); // 等级
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
}
|
||||
if (!itemList.isEmpty()) {
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
// 传参对象
|
||||
try {
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime); // 设定过账日期
|
||||
invokeRequest.setFromSystem("IEP");
|
||||
invokeRequest.setToSystem("ERP");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId("ZMM_MES_GOODSMVT_CREATE");
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String jsonObjectStr = SapUtil.appendHead(assembleMaterialMsgBody(itemList, postingDate));
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(nowTime);
|
||||
invokeRequest.setRetry(false);
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = goodMvtCreateService.call(invokeRequest);
|
||||
// 处理ERP返回的报文
|
||||
invokeResponse = updateLotComplete(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
}
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("ERROR:" + invokeResponse.getMessageContent());
|
||||
return ReturnT.FAIL;
|
||||
} else {
|
||||
XxlJobHelper.log("SUCCESS:101完工入库同步ERP:" + DateUtil.now());
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.handleFail("ERROR:101完工入库同步ERP失败:" + e);
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// 凭证中的过账日期 yyyy-MM-dd
|
||||
private String assembleMaterialMsgBody(JSONArray itemList, String postingDate) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GOODSMVT_CREATE");
|
||||
JSONObject headRe = new JSONObject();
|
||||
headRe.put("EXCHANGE_SYSTEM", "MES");
|
||||
headRe.put("EXCHANGE_ID", SapUtil.generateReqId());
|
||||
headRe.put("EXCHANGE_DOC", "iMES_Call_SAP");
|
||||
jsonObject.put("REQUEST_CONTEXT", headRe);
|
||||
JSONObject bodyRe = new JSONObject();
|
||||
JSONObject headBody = new JSONObject();
|
||||
headBody.put("ZPARTNER", SecurityUtils.getUserName()); // 员工BP编号
|
||||
headBody.put("BUDAT", postingDate); // 凭证中的过账日期
|
||||
bodyRe.put("IS_HEAD", headBody);
|
||||
bodyRe.put("IT_ITEM", itemList);
|
||||
jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
// 完成后修改结果
|
||||
public InvokeResponse updateLotComplete(JSONObject jsonObject, List<ZLotMaterialCompleteTransaction> srcList, InvokeResponse invokeResponse) {
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
String result = outJson.getString("MSGTY");
|
||||
String message = outJson.getString("MSGTX");
|
||||
String msgNo = outJson.getString("MSGNO");
|
||||
String mblnr = outJson.getString("MBLNR"); // 物料凭证编号
|
||||
for (ZLotMaterialCompleteTransaction targetObj : srcList) {
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMsgText(message);
|
||||
targetObj.setSyncMsgNo(msgNo);
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
zLotMaterialCompleteTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
|
||||
private final ZLotMaterialCompleteTransactionMapper zLotMaterialCompleteTransactionMapper;
|
||||
|
||||
private final GoodMvtCreateService goodMvtCreateService;
|
||||
|
||||
@XxlJob("sapShopOrderCompleteJobHandler")
|
||||
public ReturnT<String> sapShopOrderCompleteJobHandler() {
|
||||
try {
|
||||
String site = null;
|
||||
String startDate = null;
|
||||
String endDate = null;
|
||||
String postingDate = null;
|
||||
String jobParam = XxlJobHelper.getJobParam();
|
||||
if (StrUtil.isNotBlank(jobParam)) {
|
||||
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
|
||||
site = paramMap.get("site");
|
||||
startDate = paramMap.get("startDate");
|
||||
endDate = paramMap.get("endDate");
|
||||
postingDate = paramMap.get("postingDate");
|
||||
}
|
||||
if (StrUtil.isBlank(site)) {
|
||||
XxlJobHelper.log("ERROR:未维护站点[site]参数");
|
||||
return ReturnT.FAIL;
|
||||
} else {TenantContextHolder.setTenantId(site);
|
||||
if (StrUtil.isBlank(startDate) && StrUtil.isBlank(endDate)) {
|
||||
// 没有昨天一天的数据,默认昨天
|
||||
startDate = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
endDate = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
XxlJobHelper.log("*************************站点:" + site +",开始101完工入库同步至ERP************************");
|
||||
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
|
||||
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
|
||||
|
||||
List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactionList = zLotMaterialCompleteTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialCompleteTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialCompleteTransaction::getSite, site).ne(
|
||||
ZLotMaterialCompleteTransaction::getSyncStatus, "S")
|
||||
.gt(ZLotMaterialCompleteTransaction::getDateCreate, startDate)
|
||||
.lt(ZLotMaterialCompleteTransaction::getDateCreate, endDate));
|
||||
if (CollectionUtils.isEmpty(zLotMaterialCompleteTransactionList)) {
|
||||
XxlJobHelper.log("WARN:没有需要同步的101完工入库数据!!!");
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : zLotMaterialCompleteTransactionList) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialCompleteTransaction> srcList = new ArrayList<>();
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialCompleteTransaction targetObj = zLotMaterialCompleteTransactionMapper.selectById(
|
||||
completeTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
XxlJobHelper.log("ERROR:批次" + targetObj.getLotNo() + "已经报工,不可重复报工");
|
||||
} else {
|
||||
LocalDate syncPostingDate = completeTransaction.getSyncPostingDate();
|
||||
if (syncPostingDate != null) {
|
||||
// 使用原来的过账日期
|
||||
postingDate = syncPostingDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
if (StrUtil.isBlank(postingDate)) {
|
||||
// 如果还不存在,默认为当天过账日期
|
||||
postingDate = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
|
||||
}
|
||||
targetObj.setSyncPostingDate(LocalDate.parse(postingDate));
|
||||
srcList.add(targetObj);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
site = completeTransaction.getSite();
|
||||
jsonObject.put("ZEILE", null); // 物料凭证中的项目
|
||||
jsonObject.put("MATNR", completeTransaction.getErpItem()); // 物料编号
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", completeTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", completeTransaction.getSapBatchNo()); // 批次号
|
||||
jsonObject.put("BWART", "101"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", completeTransaction.getShopOrder()); // 订单号
|
||||
jsonObject.put("EBELN", ""); // 采购订单号
|
||||
jsonObject.put("EBELP", ""); // 采购凭证的项目编号
|
||||
jsonObject.put("MENGE", completeTransaction.getMainQty()); // 数量
|
||||
jsonObject.put("MEINS", completeTransaction.getMainUom()); // 基本计量单位
|
||||
if (completeTransaction.getSubQty() != null) {
|
||||
jsonObject.put("ERFMG", completeTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", completeTransaction.getSubUom()); // 录入单位
|
||||
} else {
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
}
|
||||
jsonObject.put("MAT_KDAUF", completeTransaction.getSoNo()); // 评估销售定单库存的销售定单号
|
||||
if (StringUtils.isNotEmpty(completeTransaction.getSoLineNo())) {
|
||||
jsonObject.put("MAT_KDPOS",
|
||||
Integer.valueOf(completeTransaction.getSoLineNo())); // 评估销售订单库存的销售订单项目
|
||||
} else {
|
||||
jsonObject.put("MAT_KDPOS", null); // 评估销售订单库存的销售订单项目
|
||||
}
|
||||
jsonObject.put("UMWRK", ""); // 收货工厂/发货工厂
|
||||
jsonObject.put("UMLGO", ""); // 收货/发货库存地点
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", ""); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", ""); // 预留 / 相关需求的项目编号
|
||||
jsonObject.put("Z_JH", completeTransaction.getLotNo()); // 卷号
|
||||
jsonObject.put("Z_CVN", completeTransaction.getExternalLot()); // 客户卷号
|
||||
jsonObject.put("Z_GRADE", completeTransaction.getQcGrade()); // 等级
|
||||
itemList.add(jsonObject);
|
||||
// 拼接报文
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
try {
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime); // 设定过账日期
|
||||
invokeRequest.setFromSystem("IEP");
|
||||
invokeRequest.setToSystem("ERP");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId("ZMM_MES_GOODSMVT_CREATE");
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String jsonObjectStr = SapUtil.appendHead(assembleMaterialMsgBody(itemList, postingDate));
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(nowTime);
|
||||
invokeRequest.setRetry(false);
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = goodMvtCreateService.call(invokeRequest);
|
||||
// 处理ERP返回的报文
|
||||
invokeResponse = updateLotComplete(invokeResponse.getObjectResponse(), srcList,
|
||||
invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("ERROR:批次" + targetObj.getLotNo() + ",同步ERP失败或者异常:" + invokeResponse.getMessageContent());
|
||||
} else {
|
||||
XxlJobHelper.log("SUCCESS:批次" + targetObj.getLotNo() + ",已同步ERP,时间:" + DateUtil.now());
|
||||
}
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.handleFail("ERROR:同步ERP,JOB执行失败:" + e);
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// 凭证中的过账日期 yyyy-MM-dd
|
||||
private String assembleMaterialMsgBody(JSONArray itemList, String postingDate) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GOODSMVT_CREATE");
|
||||
JSONObject headRe = new JSONObject();
|
||||
headRe.put("EXCHANGE_SYSTEM", "MES");
|
||||
headRe.put("EXCHANGE_ID", SapUtil.generateReqId());
|
||||
headRe.put("EXCHANGE_DOC", "iMES_Call_SAP");
|
||||
jsonObject.put("REQUEST_CONTEXT", headRe);
|
||||
JSONObject bodyRe = new JSONObject();
|
||||
JSONObject headBody = new JSONObject();
|
||||
headBody.put("ZPARTNER", SecurityUtils.getUserName()); // 员工BP编号
|
||||
headBody.put("BUDAT", postingDate); // 凭证中的过账日期
|
||||
bodyRe.put("IS_HEAD", headBody);
|
||||
bodyRe.put("IT_ITEM", itemList);
|
||||
jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
// 完成后修改结果
|
||||
public InvokeResponse updateLotComplete(JSONObject jsonObject, List<ZLotMaterialCompleteTransaction> srcList,
|
||||
InvokeResponse invokeResponse) {
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
String result = outJson.getString("MSGTY");
|
||||
String message = outJson.getString("MSGTX");
|
||||
String msgNo = outJson.getString("MSGNO");
|
||||
String mblnr = outJson.getString("MBLNR"); // 物料凭证编号
|
||||
for (ZLotMaterialCompleteTransaction targetObj : srcList) {
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMsgText(message);
|
||||
targetObj.setSyncMsgNo(msgNo);
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setUpdater(SecurityUtils.getUserName());
|
||||
targetObj.setDateUpdate(LocalDateTime.now());
|
||||
zLotMaterialCompleteTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user