物料消耗261页面和定时器跑统一方法体
This commit is contained in:
parent
825e20a799
commit
f9339e91b7
@ -275,83 +275,7 @@ public class ShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-物料消耗报工")
|
||||
@PostMapping("/callErpMaterial")
|
||||
public R callErpMaterial(@RequestBody List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactions) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialConsumptionTransaction> newList = new ArrayList<>();
|
||||
String site = "";
|
||||
String postingDate = "";
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialConsumptionTransaction> srcList = new ArrayList<>();
|
||||
for (ZLotMaterialConsumptionTransaction consumptionTransaction : zLotMaterialConsumptionTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialConsumptionTransaction targetObj = zLotMaterialConsumptionTransactionMapper.selectById(consumptionTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "消耗已经报工,不可重复报工");
|
||||
} else {
|
||||
postingDate = consumptionTransaction.getSyncPostingDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
targetObj.setSyncPostingDate(consumptionTransaction.getSyncPostingDate());
|
||||
srcList.add(targetObj);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
site = consumptionTransaction.getSite();
|
||||
jsonObject.put("ZEILE", ""); // 物料凭证中的项目
|
||||
jsonObject.put("MATNR", consumptionTransaction.getErpItem()); // 物料编号
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", consumptionTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", consumptionTransaction.getSapBatchNo()); // 批次号
|
||||
jsonObject.put("BWART", "261"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", consumptionTransaction.getShopOrder()); // 订单号
|
||||
jsonObject.put("EBELN", ""); // 采购订单号
|
||||
jsonObject.put("EBELP", ""); // 采购凭证的项目编号
|
||||
jsonObject.put("MENGE", consumptionTransaction.getMainQty()); // 数量
|
||||
jsonObject.put("MEINS", consumptionTransaction.getMainUom()); // 基本计量单位
|
||||
if (StringUtils.isEmpty(consumptionTransaction.getSubUom()) || consumptionTransaction.getSubQty() == null) {
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
} else {
|
||||
jsonObject.put("ERFMG", consumptionTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", consumptionTransaction.getSubUom()); // 录入单位
|
||||
}
|
||||
jsonObject.put("MAT_KDAUF", ""); // 评估销售定单库存的销售定单号
|
||||
jsonObject.put("MAT_KDPOS", ""); // 评估销售订单库存的销售订单项目
|
||||
jsonObject.put("UMWRK", ""); // 收货工厂/发货工厂
|
||||
jsonObject.put("UMLGO", ""); // 收货/发货库存地点
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", consumptionTransaction.getReservedNo()); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", consumptionTransaction.getReservedLine()); // 预留 / 相关需求的项目编号
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
}
|
||||
if (itemList.size() > 0) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialConsumption(zLotMaterialConsumptionTransactions, false,"");
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
} else {
|
||||
@ -359,55 +283,6 @@ public class ShopOrderStatisticTransController {
|
||||
}
|
||||
}
|
||||
|
||||
public InvokeResponse updateMaterialConsumption(JSONObject jsonObject, List<ZLotMaterialConsumptionTransaction> 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 (ZLotMaterialConsumptionTransaction targetObj : srcList) {
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMsgText(message);
|
||||
targetObj.setSyncMsgNo(msgno);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
// 如果报工成功,就更新消耗表的erp标识为Y
|
||||
if ("S".equalsIgnoreCase(result)) {
|
||||
LotMaterial lotMaterial = lotMaterialMapper.selectById(targetObj.getLotMaterialSid());
|
||||
if (lotMaterial != null) {
|
||||
lotMaterial.setErpFlag("Y");
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
// 凭证中的过账日期 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();
|
||||
}
|
||||
|
||||
// --------------------------------- 批次完工入库报工开始 -----------------------------------------------
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-批次完工入库获取SAP批次号", notes = "生产管理报工平台-批次完工入库获取SAP批次号")
|
||||
|
||||
@ -2,22 +2,15 @@ package com.foreverwin.iep.integration.handler.def.job;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
import com.foreverwin.iep.common.faas.common.util.StringUtils;
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.GoodMvtCreateService;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.SapUtil;
|
||||
import com.foreverwin.iep.integration.service.LotMaterialDealSendSapService;
|
||||
import com.foreverwin.iep.integration.utils.JS;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialCompleteTransaction;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialConsumptionTransaction;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialCompleteTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialConsumptionTransactionMapper;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
@ -25,9 +18,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,180 +28,61 @@ import java.util.Map;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class SapMaterialConsumptionJob {
|
||||
|
||||
private final ZLotMaterialConsumptionTransactionMapper zLotMaterialConsumptionTransactionMapper;
|
||||
private final GoodMvtCreateService goodMvtCreateService;
|
||||
|
||||
@XxlJob("sapMaterialConsumptionJobHandler")
|
||||
public ReturnT<String> sapMaterialConsumptionJobHandler() {
|
||||
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 +",开始261物料消耗同步至ERP************************");
|
||||
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
|
||||
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
|
||||
List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactionList = zLotMaterialConsumptionTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialConsumptionTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialConsumptionTransaction::getSite, site).ne(
|
||||
ZLotMaterialConsumptionTransaction::getSyncStatus, "S")
|
||||
.gt(ZLotMaterialConsumptionTransaction::getDateCreate, startDate)
|
||||
.lt(ZLotMaterialConsumptionTransaction::getDateCreate, endDate));
|
||||
if (CollectionUtils.isEmpty(zLotMaterialConsumptionTransactionList)) {
|
||||
XxlJobHelper.log("WARN:没有需要同步的261物料消耗数据!!!");
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
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())) {
|
||||
XxlJobHelper.log("ERROR:批次" + targetObj.getLotNo() + "已经报消耗,不可重复报消耗");
|
||||
} else {
|
||||
LocalDate syncPostingDate = consumptionTransaction.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 = consumptionTransaction.getSite();
|
||||
jsonObject.put("ZEILE", ""); // 物料凭证中的项目
|
||||
jsonObject.put("MATNR", consumptionTransaction.getErpItem()); // 物料编号
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", consumptionTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", consumptionTransaction.getSapBatchNo()); // 批次号
|
||||
jsonObject.put("BWART", "261"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", consumptionTransaction.getShopOrder()); // 订单号
|
||||
jsonObject.put("EBELN", ""); // 采购订单号
|
||||
jsonObject.put("EBELP", ""); // 采购凭证的项目编号
|
||||
jsonObject.put("MENGE", consumptionTransaction.getMainQty()); // 数量
|
||||
jsonObject.put("MEINS", consumptionTransaction.getMainUom()); // 基本计量单位
|
||||
if(consumptionTransaction.getSubQty()!=null){
|
||||
jsonObject.put("ERFMG", consumptionTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", consumptionTransaction.getSubUom()); // 录入单位
|
||||
}else{
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
}
|
||||
jsonObject.put("MAT_KDAUF", ""); // 评估销售定单库存的销售定单号
|
||||
jsonObject.put("MAT_KDPOS", ""); // 评估销售订单库存的销售订单项目
|
||||
jsonObject.put("UMWRK", ""); // 收货工厂/发货工厂
|
||||
jsonObject.put("UMLGO", ""); // 收货/发货库存地点
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", consumptionTransaction.getReservedNo()); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", consumptionTransaction.getReservedLine()); // 预留 / 相关需求的项目编号
|
||||
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 = 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.handleFail("ERROR:101完工入库同步ERP失败:" + e);
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
}
|
||||
public InvokeResponse updateMaterialConsumption(JSONObject jsonObject, List<ZLotMaterialConsumptionTransaction> 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 (ZLotMaterialConsumptionTransaction targetObj : srcList) {
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMsgText(message);
|
||||
targetObj.setSyncMsgNo(msgno);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setUpdater(SecurityUtils.getUserName());
|
||||
targetObj.setDateUpdate(LocalDateTime.now());
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
// 凭证中的过账日期 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();
|
||||
}
|
||||
private final ZLotMaterialConsumptionTransactionMapper zLotMaterialConsumptionTransactionMapper;
|
||||
private final LotMaterialDealSendSapService lotMaterialDealSendSapService;
|
||||
|
||||
@XxlJob("sapMaterialConsumptionJobHandler")
|
||||
public ReturnT<String> sapMaterialConsumptionJobHandler() {
|
||||
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 + ",开始261物料消耗同步至ERP************************");
|
||||
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
|
||||
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
|
||||
List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactionList = zLotMaterialConsumptionTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialConsumptionTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialConsumptionTransaction::getSite, site).ne(
|
||||
ZLotMaterialConsumptionTransaction::getSyncStatus, "S")
|
||||
.gt(ZLotMaterialConsumptionTransaction::getDateCreate, startDate)
|
||||
.lt(ZLotMaterialConsumptionTransaction::getDateCreate, endDate));
|
||||
if (CollectionUtils.isEmpty(zLotMaterialConsumptionTransactionList)) {
|
||||
XxlJobHelper.log("WARN:没有需要同步的261物料消耗数据!!!");
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
if (StringUtils.isEmpty(postingDate)) {
|
||||
postingDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialConsumption(zLotMaterialConsumptionTransactionList, true, postingDate);
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("WARN:同步261物料消耗数据失败!!!" + invokeResponse.getMessageContent());
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.handleFail("ERROR:同步261物料消耗数据同步ERP失败:" + e);
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,12 +2,13 @@ package com.foreverwin.iep.integration.service;
|
||||
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialCompleteTransaction;
|
||||
import com.foreverwin.mom.wms.entity.Document;
|
||||
import com.foreverwin.mom.wms.entity.DocumentDetailed;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialConsumptionTransaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LotMaterialDealSendSapService {
|
||||
|
||||
InvokeResponse callLotMaterialComplete(List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactions, boolean isPass, String postingDate);
|
||||
|
||||
InvokeResponse callLotMaterialConsumption(List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactions, boolean isPass, String postingDate);
|
||||
}
|
||||
|
||||
@ -14,9 +14,11 @@ import com.foreverwin.iep.integration.service.IntInDataService;
|
||||
import com.foreverwin.iep.integration.service.LotMaterialDealSendSapService;
|
||||
import com.foreverwin.iep.integration.service.RegisterDocumentService;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialCompleteTransaction;
|
||||
import com.foreverwin.iep.prd.entity.ZLotMaterialConsumptionTransaction;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialCompleteTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialConsumptionTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZShoporderStatisticsTransactionMapper;
|
||||
import com.foreverwin.iep.wip.entity.LotMaterial;
|
||||
import com.foreverwin.iep.wip.mapper.LotMaterialMapper;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
@ -34,15 +36,9 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class LotMaterialDealSendSapServiceImpl implements LotMaterialDealSendSapService {
|
||||
|
||||
private final ZShoporderStatisticsTransactionMapper zShoporderStatisticsTransactionMapper;
|
||||
private final ShopOrderStatisticTransService shopOrderStatisticTransService;
|
||||
private final ShopOrderStatisticTransCancelService shopOrderStatisticTransCancelService;
|
||||
private final GoodMvtCreateService goodMvtCreateService;
|
||||
private final ZLotMaterialConsumptionTransactionMapper zLotMaterialConsumptionTransactionMapper;
|
||||
private final ZLotMaterialCompleteTransactionMapper zLotMaterialCompleteTransactionMapper;
|
||||
private final IntInDataService intInDataService;
|
||||
private final IntInDataLogService intInDataLogService;
|
||||
private final RegisterDocumentService registerDocumentService;
|
||||
private final LotMaterialMapper lotMaterialMapper;
|
||||
|
||||
private final String messageId = "ZMM_MES_GOODSMVT_CREATE";
|
||||
@ -198,4 +194,121 @@ public class LotMaterialDealSendSapServiceImpl implements LotMaterialDealSendSap
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------- 物料消耗报工开始 ----------------------------------------------------------
|
||||
@Override
|
||||
public InvokeResponse callLotMaterialConsumption(List<ZLotMaterialConsumptionTransaction> zLotMaterialConsumptionTransactions, boolean isPass, String postingDate) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialConsumptionTransaction> newList = new ArrayList<>();
|
||||
String site = "";
|
||||
JSONArray itemList = new JSONArray();
|
||||
List<ZLotMaterialConsumptionTransaction> srcList = new ArrayList<>();
|
||||
for (ZLotMaterialConsumptionTransaction consumptionTransaction : zLotMaterialConsumptionTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialConsumptionTransaction targetObj = zLotMaterialConsumptionTransactionMapper.selectById(consumptionTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "消耗已经报工,不可重复报工");
|
||||
} else {
|
||||
if (StringUtils.isEmpty(postingDate)) {
|
||||
postingDate = consumptionTransaction.getSyncPostingDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
} else {
|
||||
consumptionTransaction.setSyncPostingDate(LocalDate.parse(postingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
}
|
||||
targetObj.setSyncPostingDate(consumptionTransaction.getSyncPostingDate());
|
||||
srcList.add(targetObj);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
site = consumptionTransaction.getSite();
|
||||
jsonObject.put("ZEILE", ""); // 物料凭证中的项目
|
||||
jsonObject.put("MATNR", consumptionTransaction.getComponentItem()); // 物料编号
|
||||
jsonObject.put("MATKL", ""); // 物料组
|
||||
jsonObject.put("WERKS", site); // 工厂
|
||||
jsonObject.put("LGORT", consumptionTransaction.getErpInventory()); // 存储地点
|
||||
jsonObject.put("CHARG", consumptionTransaction.getSapBatchNo()); // 批次号
|
||||
jsonObject.put("BWART", "261"); // 移动类型
|
||||
jsonObject.put("SOBKZ", ""); // 特殊库存标识
|
||||
jsonObject.put("AUFNR", consumptionTransaction.getShopOrder()); // 订单号
|
||||
jsonObject.put("EBELN", ""); // 采购订单号
|
||||
jsonObject.put("EBELP", ""); // 采购凭证的项目编号
|
||||
jsonObject.put("MENGE", consumptionTransaction.getMainQty()); // 数量
|
||||
jsonObject.put("MEINS", consumptionTransaction.getMainUom()); // 基本计量单位
|
||||
if (StringUtils.isEmpty(consumptionTransaction.getSubUom()) || consumptionTransaction.getSubQty() == null) {
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
} else {
|
||||
jsonObject.put("ERFMG", consumptionTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", consumptionTransaction.getSubUom()); // 录入单位
|
||||
}
|
||||
jsonObject.put("MAT_KDAUF", ""); // 评估销售定单库存的销售定单号
|
||||
jsonObject.put("MAT_KDPOS", ""); // 评估销售订单库存的销售订单项目
|
||||
jsonObject.put("UMWRK", ""); // 收货工厂/发货工厂
|
||||
jsonObject.put("UMLGO", ""); // 收货/发货库存地点
|
||||
jsonObject.put("UMCHA", ""); // 收货/发货批量
|
||||
jsonObject.put("RSNUM", consumptionTransaction.getReservedNo()); // 预留/相关需求的编号
|
||||
jsonObject.put("RSPOS", consumptionTransaction.getReservedLine()); // 预留 / 相关需求的项目编号
|
||||
itemList.add(jsonObject);
|
||||
newList.add(targetObj);
|
||||
}
|
||||
}
|
||||
if (itemList.size() > 0) {
|
||||
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(messageId);
|
||||
|
||||
// 组装抛送的报完呢
|
||||
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());
|
||||
}
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
public InvokeResponse updateMaterialConsumption(JSONObject jsonObject, List<ZLotMaterialConsumptionTransaction> 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 (ZLotMaterialConsumptionTransaction targetObj : srcList) {
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMsgText(message);
|
||||
targetObj.setSyncMsgNo(msgno);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
// 如果报工成功,就更新消耗表的erp标识为Y
|
||||
if ("S".equalsIgnoreCase(result)) {
|
||||
LotMaterial lotMaterial = lotMaterialMapper.selectById(targetObj.getLotMaterialSid());
|
||||
if (lotMaterial != null) {
|
||||
lotMaterial.setErpFlag("Y");
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user