6、生产报工事务冲销针对报工行报工
7、增加物料消耗报工冲销接口的实现 8、增加完工入库报工冲销接口的实现
This commit is contained in:
parent
ad57f120c7
commit
fa29d8d6c3
@ -8,10 +8,7 @@ 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.ShopOrderStatisticTransCancelService;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.ShopOrderStatisticTransService;
|
||||
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.RegisterDocumentService;
|
||||
@ -31,11 +28,15 @@ import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@ -65,6 +66,10 @@ public class ShopOrderStatisticTransController {
|
||||
private final RegisterDocumentService registerDocumentService;
|
||||
private final LotMaterialMapper lotMaterialMapper;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ZMM_MES_GOODMVT_REVERSE") // 通过 Bean 名称注入
|
||||
private GoodMvtReverseService goodMvtReverseService;
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-工单报工", notes = "生产管理报工平台-工单报工")
|
||||
@SysLog("生产管理报工平台-工单报工")
|
||||
@PostMapping("/callErp")
|
||||
@ -416,10 +421,12 @@ public class ShopOrderStatisticTransController {
|
||||
@PostMapping("/callErpLot")
|
||||
public R callErpLot(@RequestBody List<ZLotMaterialCompleteTransaction> zLotMaterialCompleteTransactions) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
List<ZLotMaterialCompleteTransaction> newList = new ArrayList<>();
|
||||
List<ZLotMaterialCompleteTransaction> newOneZeroOneList = new ArrayList<>();
|
||||
List<ZLotMaterialCompleteTransaction> newFiveThreeOneList = new ArrayList<>();
|
||||
String site = "";
|
||||
String postingDate = "";
|
||||
JSONArray itemList = new JSONArray();
|
||||
JSONArray oneZeroOneList = new JSONArray();
|
||||
JSONArray fiveThreeOneList = new JSONArray();
|
||||
List<ZLotMaterialCompleteTransaction> srcList = new ArrayList<>();
|
||||
for (ZLotMaterialCompleteTransaction completeTransaction : zLotMaterialCompleteTransactions) {
|
||||
// 重新校验一遍是否已经报过工,防止重复报工
|
||||
@ -466,38 +473,20 @@ public class ShopOrderStatisticTransController {
|
||||
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 ("101".equals(completeTransaction.getProductType())) {
|
||||
oneZeroOneList.add(jsonObject);
|
||||
newOneZeroOneList.add(targetObj);
|
||||
} else if ("531".equals(completeTransaction.getProductType())) {
|
||||
fiveThreeOneList.add(jsonObject);
|
||||
newFiveThreeOneList.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 = updateLotComplete(invokeResponse.getObjectResponse(), srcList, invokeResponse);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
if (oneZeroOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, oneZeroOneList, postingDate, newOneZeroOneList);
|
||||
}
|
||||
if ("S".equals(invokeResponse.getResult()) && fiveThreeOneList.size() > 0) {
|
||||
invokeResponse = sendSap(invokeResponse, site, fiveThreeOneList, postingDate, newFiveThreeOneList);
|
||||
}
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
@ -506,6 +495,37 @@ 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");
|
||||
@ -528,4 +548,105 @@ public class ShopOrderStatisticTransController {
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-物料消耗冲销", notes = "生产管理报工平台-物料消耗冲销")
|
||||
@SysLog("生产管理报工平台-物料消耗冲销")
|
||||
@PostMapping("/callErpLotCancel")
|
||||
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())){
|
||||
InvokeResponse invokeResponse = sendSapToCancel(targetObj.getSyncVoucherNo());
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
}else{
|
||||
// 更新lotMaterial表
|
||||
targetObj.setErpReverse("Y");
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
LotMaterial lotMaterial = lotMaterialMapper.selectById(targetObj.getLotMaterialSid());
|
||||
if (lotMaterial != null) {
|
||||
lotMaterial.setQty(BigDecimal.ZERO);
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "还未报工,不可冲销");
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-完工入库冲销", notes = "生产管理报工平台-完工入库冲销")
|
||||
@SysLog("生产管理报工平台-完工入库冲销")
|
||||
@PostMapping("/callErpLotInStockCancel")
|
||||
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())){
|
||||
InvokeResponse invokeResponse = sendSapToCancel(targetObj.getSyncVoucherNo());
|
||||
if (!"S".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:" + invokeResponse.getMessageContent());
|
||||
}else{
|
||||
// 更新冲销标识
|
||||
targetObj.setErpReverse("Y");
|
||||
zLotMaterialCompleteTransactionMapper.updateById(targetObj);
|
||||
}
|
||||
}else{
|
||||
throw BusinessException.build("批次" + targetObj.getLotNo() + "还未报工,不可冲销");
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
private InvokeResponse sendSapToCancel(String syncVoucherNo) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
// 传参对象
|
||||
try {
|
||||
String messageId = "ZMM_MES_GOODMVT_REVERSE";
|
||||
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(TenantContextHolder.getTenantId());
|
||||
invokeRequest.setMessageId(messageId);
|
||||
|
||||
String postingDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
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 isInput = new JSONObject();
|
||||
isInput.put("MBLNR", syncVoucherNo); // 物料凭证编号
|
||||
isInput.put("ZPARTNER", SecurityUtils.getUserName()); // 员工BP编号
|
||||
isInput.put("BUDAT", postingDate); // 凭证中的过账日期
|
||||
bodyRe.put("IS_INPUT", isInput);
|
||||
jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String jsonObjectStr = SapUtil.appendHead(jsonObject.toJSONString());
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(nowTime);
|
||||
invokeRequest.setRetry(false);
|
||||
invokeResponse = goodMvtReverseService.call(invokeRequest);
|
||||
} catch (Exception e) {
|
||||
// 不用回滚,将错误抛出
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user