完工入库报工定时器和页面报工统一方法
This commit is contained in:
parent
e4e9faba2e
commit
825e20a799
@ -11,6 +11,7 @@ import com.foreverwin.iep.integration.entity.IntInDataLog;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.*;
|
||||
import com.foreverwin.iep.integration.service.IntInDataLogService;
|
||||
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;
|
||||
@ -65,6 +66,7 @@ public class ShopOrderStatisticTransController {
|
||||
private final IntInDataLogService intInDataLogService;
|
||||
private final RegisterDocumentService registerDocumentService;
|
||||
private final LotMaterialMapper lotMaterialMapper;
|
||||
private final LotMaterialDealSendSapService lotMaterialDealSendSapService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ZMM_MES_GOODMVT_REVERSE") // 通过 Bean 名称注入
|
||||
@ -420,76 +422,7 @@ public class ShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-批次完工入库报工")
|
||||
@PostMapping("/callErpLot")
|
||||
public R callErpLot(@RequestBody List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactions) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialCompleteTransaction> newOneZeroOneList = new ArrayList<>();
|
||||
List<ZLotMaterialCompleteTransaction> newFiveThreeOneList = new ArrayList<>();
|
||||
String site = "";
|
||||
String postingDate = "";
|
||||
JSONArray oneZeroOneList = new JSONArray();
|
||||
JSONArray fiveThreeOneList = new JSONArray();
|
||||
List<ZLotMaterialCompleteTransaction> srcList = new ArrayList<>();
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : zLotMaterialCompleteTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialCompleteTransaction targetObj = zLotMaterialCompleteTransactionMapper.selectById(completeTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "完工已经报工,不可重复报工");
|
||||
} else {
|
||||
postingDate = completeTransaction.getSyncPostingDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
targetObj.setSyncPostingDate(completeTransaction.getSyncPostingDate());
|
||||
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", completeTransaction.getProductType()); // 移动类型
|
||||
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 (StringUtils.isEmpty(completeTransaction.getSubUom()) || completeTransaction.getSubQty() == null) {
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
} else {
|
||||
jsonObject.put("ERFMG", completeTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", completeTransaction.getSubUom()); // 录入单位
|
||||
}
|
||||
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()); // 等级
|
||||
if ("101".equals(completeTransaction.getProductType())) {
|
||||
oneZeroOneList.add(jsonObject);
|
||||
newOneZeroOneList.add(targetObj);
|
||||
} else if ("531".equals(completeTransaction.getProductType())) {
|
||||
fiveThreeOneList.add(jsonObject);
|
||||
newFiveThreeOneList.add(targetObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oneZeroOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, oneZeroOneList, postingDate, newOneZeroOneList);
|
||||
}else{
|
||||
invokeResponse.setResult("S");
|
||||
}
|
||||
if ("S".equals(invokeResponse.getResult()) && fiveThreeOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, fiveThreeOneList, postingDate, newFiveThreeOneList);
|
||||
}
|
||||
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(zLotMaterialCompleteTransactions, false,"");
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
} else {
|
||||
@ -497,73 +430,20 @@ public class ShopOrderStatisticTransController {
|
||||
}
|
||||
}
|
||||
|
||||
private InvokeResponse sendSap(InvokeResponse invokeResponse, String site, JSONArray itemList, String postingDate, List<ZLotMaterialCompleteTransaction> srcList) {
|
||||
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());
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-物料消耗冲销", notes = "生产管理报工平台-物料消耗冲销")
|
||||
@SysLog("生产管理报工平台-物料消耗冲销")
|
||||
@PostMapping("/callErpLotCancel")
|
||||
public R callErpLotCancel(@RequestBody List<ZLotMaterialConsumptionTransaction> lotMaterialConsumptionTransactions){
|
||||
for (ZLotMaterialConsumptionTransaction consumptionTransaction: lotMaterialConsumptionTransactions){
|
||||
public R callErpLotCancel(@RequestBody List<ZLotMaterialConsumptionTransaction> lotMaterialConsumptionTransactions) {
|
||||
for (ZLotMaterialConsumptionTransaction consumptionTransaction : lotMaterialConsumptionTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialConsumptionTransaction targetObj = zLotMaterialConsumptionTransactionMapper.selectById(consumptionTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus()) && "Y".equals(targetObj.getErpReverse())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "完工已经报工且已冲销,不可重复冲销");
|
||||
} else if("S".equals(targetObj.getSyncStatus())){
|
||||
} else if ("S".equals(targetObj.getSyncStatus())) {
|
||||
InvokeResponse invokeResponse = sendSapToCancel(targetObj.getSyncVoucherNo());
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
}else{
|
||||
} else {
|
||||
// 更新lotMaterial表
|
||||
targetObj.setErpReverse("Y");
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
@ -573,7 +453,7 @@ public class ShopOrderStatisticTransController {
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "还未报工,不可冲销");
|
||||
}
|
||||
}
|
||||
@ -583,22 +463,22 @@ public class ShopOrderStatisticTransController {
|
||||
@ApiOperation(value = "生产管理报工平台-完工入库冲销", notes = "生产管理报工平台-完工入库冲销")
|
||||
@SysLog("生产管理报工平台-完工入库冲销")
|
||||
@PostMapping("/callErpLotInStockCancel")
|
||||
public R callErpLotInStockCancel(@RequestBody List<ZLotMaterialCompleteTransaction> lotMaterialCompleteTransactions){
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction: lotMaterialCompleteTransactions){
|
||||
public R callErpLotInStockCancel(@RequestBody List<ZLotMaterialCompleteTransaction> lotMaterialCompleteTransactions) {
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : lotMaterialCompleteTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialCompleteTransaction targetObj = zLotMaterialCompleteTransactionMapper.selectById(completeTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus()) && "Y".equals(targetObj.getErpReverse())) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "完工已经报工且已冲销,不可重复冲销");
|
||||
} else if("S".equals(targetObj.getSyncStatus())){
|
||||
} else if ("S".equals(targetObj.getSyncStatus())) {
|
||||
InvokeResponse invokeResponse = sendSapToCancel(targetObj.getSyncVoucherNo());
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
}else{
|
||||
} else {
|
||||
// 更新冲销标识
|
||||
targetObj.setErpReverse("Y");
|
||||
zLotMaterialCompleteTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "还未报工,不可冲销");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package com.foreverwin.iep.integration.handler.def.job;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
@ -9,23 +7,13 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.foreverwin.iep.common.faas.common.util.StringUtils;
|
||||
import com.foreverwin.iep.integration.component.Invoke;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.entity.IntInData;
|
||||
import com.foreverwin.iep.integration.entity.IntInDataLog;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.GoodMvtCreateService;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.SapUtil;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.ShopOrderStatisticTransService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataLogService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataService;
|
||||
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.ZShoporderStatisticsTransaction;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialCompleteTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZShoporderStatisticsTransactionMapper;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
@ -37,10 +25,8 @@ 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;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 101完工入库JOB
|
||||
@ -48,11 +34,11 @@ import java.util.UUID;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class SapShopOrderCompleteJob {
|
||||
|
||||
|
||||
private final ZLotMaterialCompleteTransactionMapper zLotMaterialCompleteTransactionMapper;
|
||||
|
||||
private final GoodMvtCreateService goodMvtCreateService;
|
||||
|
||||
private final LotMaterialDealSendSapService lotMaterialDealSendSapService;
|
||||
|
||||
@XxlJob("sapShopOrderCompleteJobHandler")
|
||||
public ReturnT<String> sapShopOrderCompleteJobHandler() {
|
||||
try {
|
||||
@ -71,16 +57,17 @@ public class SapShopOrderCompleteJob {
|
||||
if (StrUtil.isBlank(site)) {
|
||||
XxlJobHelper.log("ERROR:未维护站点[site]参数");
|
||||
return ReturnT.FAIL;
|
||||
} else {TenantContextHolder.setTenantId(site);
|
||||
} 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("*************************站点:" + site + ",开始101或531完工入库同步至ERP************************");
|
||||
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
|
||||
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
|
||||
|
||||
|
||||
List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactionList = zLotMaterialCompleteTransactionMapper.selectList(
|
||||
Wrappers.<ZLotMaterialCompleteTransaction>lambdaQuery().eq(
|
||||
ZLotMaterialCompleteTransaction::getSite, site).ne(
|
||||
@ -88,105 +75,16 @@ public class SapShopOrderCompleteJob {
|
||||
.gt(ZLotMaterialCompleteTransaction::getDateCreate, startDate)
|
||||
.lt(ZLotMaterialCompleteTransaction::getDateCreate, endDate));
|
||||
if (CollectionUtils.isEmpty(zLotMaterialCompleteTransactionList)) {
|
||||
XxlJobHelper.log("WARN:没有需要同步的101完工入库数据!!!");
|
||||
XxlJobHelper.log("WARN:没有需要同步的101或531完工入库数据!!!");
|
||||
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());
|
||||
}
|
||||
if (StringUtils.isEmpty(postingDate)) {
|
||||
postingDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(zLotMaterialCompleteTransactionList, true, postingDate);
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
XxlJobHelper.log("WARN:同步101或531完工入库数据失败!!!" + invokeResponse.getMessageContent());
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
@ -195,7 +93,7 @@ public class SapShopOrderCompleteJob {
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 凭证中的过账日期 yyyy-MM-dd
|
||||
private String assembleMaterialMsgBody(JSONArray itemList, String postingDate) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@ -214,7 +112,7 @@ public class SapShopOrderCompleteJob {
|
||||
jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
// 完成后修改结果
|
||||
public InvokeResponse updateLotComplete(JSONObject jsonObject, List<ZLotMaterialCompleteTransaction> srcList,
|
||||
InvokeResponse invokeResponse) {
|
||||
@ -238,5 +136,5 @@ public class SapShopOrderCompleteJob {
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,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 java.util.List;
|
||||
|
||||
public interface LotMaterialDealSendSapService {
|
||||
|
||||
InvokeResponse callLotMaterialComplete(List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactions, boolean isPass, String postingDate);
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
package com.foreverwin.iep.integration.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.common.faas.common.util.StringUtils;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
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.handler.def.sap.ShopOrderStatisticTransCancelService;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.ShopOrderStatisticTransService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataLogService;
|
||||
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.mapper.ZLotMaterialCompleteTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialConsumptionTransactionMapper;
|
||||
import com.foreverwin.iep.prd.mapper.ZShoporderStatisticsTransactionMapper;
|
||||
import com.foreverwin.iep.wip.mapper.LotMaterialMapper;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@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";
|
||||
|
||||
@Override
|
||||
public InvokeResponse callLotMaterialComplete(List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactions, boolean isPass, String postingDate) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialCompleteTransaction> newOneZeroOneList = new ArrayList<>();
|
||||
List<ZLotMaterialCompleteTransaction> newFiveThreeOneList = new ArrayList<>();
|
||||
String site = "";
|
||||
JSONArray oneZeroOneList = new JSONArray();
|
||||
JSONArray fiveThreeOneList = new JSONArray();
|
||||
List<ZLotMaterialCompleteTransaction> srcList = new ArrayList<>();
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : zLotMaterialCompleteTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
ZLotMaterialCompleteTransaction targetObj = zLotMaterialCompleteTransactionMapper.selectById(completeTransaction.getSid());
|
||||
if ("S".equals(targetObj.getSyncStatus()) && !isPass) {
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "完工已经报工,不可重复报工");
|
||||
} else {
|
||||
if (StringUtils.isEmpty(postingDate)) {
|
||||
postingDate = completeTransaction.getSyncPostingDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
} else {
|
||||
completeTransaction.setSyncPostingDate(LocalDate.parse(postingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
}
|
||||
targetObj.setSyncPostingDate(completeTransaction.getSyncPostingDate());
|
||||
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", completeTransaction.getProductType()); // 移动类型
|
||||
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 (com.foreverwin.iep.common.faas.common.util.StringUtils.isEmpty(completeTransaction.getSubUom()) || completeTransaction.getSubQty() == null) {
|
||||
jsonObject.put("ERFMG", null); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", ""); // 录入单位
|
||||
} else {
|
||||
jsonObject.put("ERFMG", completeTransaction.getSubQty()); // 以录入项单位表示的数量
|
||||
jsonObject.put("ERFME", completeTransaction.getSubUom()); // 录入单位
|
||||
}
|
||||
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()); // 等级
|
||||
if ("101".equals(completeTransaction.getProductType())) {
|
||||
oneZeroOneList.add(jsonObject);
|
||||
newOneZeroOneList.add(targetObj);
|
||||
} else if ("531".equals(completeTransaction.getProductType())) {
|
||||
fiveThreeOneList.add(jsonObject);
|
||||
newFiveThreeOneList.add(targetObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oneZeroOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, oneZeroOneList, postingDate, newOneZeroOneList);
|
||||
} else {
|
||||
invokeResponse.setResult("S");
|
||||
}
|
||||
if ("S".equals(invokeResponse.getResult()) && fiveThreeOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, fiveThreeOneList, postingDate, newFiveThreeOneList);
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
public InvokeResponse sendSap(InvokeResponse invokeResponse, String site, JSONArray itemList, String postingDate, List<ZLotMaterialCompleteTransaction> srcList) {
|
||||
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 = updateLotComplete(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
|
||||
// 凭证中的过账日期 yyyy-MM-dd
|
||||
private String assembleMaterialMsgBody(JSONArray itemList, String postingDate) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", messageId);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user