refactor(int-core): 优化报工平台功能
- 新增末工序校验功能 - 修复生产日期解析问题 - 优化库存记录处理流程 - 移除冗余代码和注释
This commit is contained in:
parent
f4faaa5c92
commit
988b15a7a4
@ -1,5 +1,6 @@
|
||||
package com.foreverwin.iep.integration.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
@ -15,15 +16,21 @@ import com.foreverwin.iep.integration.service.RegisterDocumentService;
|
||||
import com.foreverwin.iep.prd.entity.Item;
|
||||
import com.foreverwin.iep.prd.mapper.ZLotMaterialCompleteTransactionMapper;
|
||||
|
||||
import com.foreverwin.iep.wip.dto.OperationOutDTO;
|
||||
import com.foreverwin.iep.wip.dto.RouterStepOutDTO;
|
||||
import com.foreverwin.iep.wip.mapper.OperationOutMapper;
|
||||
import com.foreverwin.mom.common.core.constant.SecurityConstants;
|
||||
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.log.annotation.SysLog;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryLogService;
|
||||
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryRecordService;
|
||||
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryService;
|
||||
import com.foreverwin.mom.wms.constant.Constant;
|
||||
import com.foreverwin.mom.wms.entity.Inventory;
|
||||
import com.foreverwin.mom.wms.entity.InventoryLog;
|
||||
import com.foreverwin.mom.wms.entity.InventoryRecord;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -34,12 +41,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.rmi.Remote;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 生产管理报工平台
|
||||
@ -62,6 +68,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
private final RemoteWmsInventoryRecordService inventoryRecordMapper;
|
||||
private final InventoryRecordService inventoryRecordService;
|
||||
private final RemoteWmsInventoryService inventoryService;
|
||||
private final OperationOutMapper operationOutMapper;
|
||||
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-工单报工", notes = "生产管理报工平台-工单报工")
|
||||
@ -81,18 +88,8 @@ public class CopyShopOrderStatisticTransController {
|
||||
newList.add(inventoryRecord);
|
||||
}
|
||||
|
||||
// R<List<InventoryRecord>> listR = inventoryRecordMapper.selectBySyncStatus();
|
||||
// List<InventoryRecord> inventoryRecords = listR.getData();
|
||||
// for (InventoryRecord inventoryRecord : inventoryRecords) {
|
||||
//
|
||||
// processInventoryRecord(inventoryRecord, site);
|
||||
// }
|
||||
|
||||
|
||||
//========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
||||
|
||||
//========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
||||
|
||||
if (CollectionUtils.isNotEmpty(newList)) {
|
||||
// 传参对象
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
@ -100,7 +97,13 @@ public class CopyShopOrderStatisticTransController {
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
String shopOrder = "";
|
||||
try {
|
||||
//判断是否为末工序
|
||||
for (InventoryRecord inventoryRecord : newList){
|
||||
checkEndOperation(inventoryRecord.getShopOrder(),inventoryRecord.getOperation(),site);
|
||||
}
|
||||
for (InventoryRecord inventoryRecord : newList) {
|
||||
|
||||
|
||||
shopOrder = inventoryRecord.getShopOrder();
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime);
|
||||
@ -130,17 +133,38 @@ public class CopyShopOrderStatisticTransController {
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed(invokeResponse.getMessageContent());
|
||||
} else {
|
||||
// R<List<InventoryRecord>> listR = inventoryRecordMapper.selectBySyncStatus();
|
||||
// List<InventoryRecord> inventoryRecords = listR.getData();
|
||||
// for (InventoryRecord inventoryRecord : inventoryRecords) {
|
||||
//
|
||||
// processInventoryRecord(inventoryRecord, site);
|
||||
// }
|
||||
for (InventoryRecord inventoryRecord : inventoryRecordList) {
|
||||
processInventoryRecord(inventoryRecord, site);
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEndOperation(String shopOrder, String operation, String site) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
OperationOutDTO operationOutDTO = new OperationOutDTO();
|
||||
operationOutDTO.setShopOrder(shopOrder);
|
||||
operationOutDTO.setSite(site);
|
||||
List<RouterStepOutDTO> routerStepOutDTOS = operationOutMapper.readRouterStepCustom(operationOutDTO);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(routerStepOutDTOS)) {
|
||||
for (RouterStepOutDTO routerStepOutDTO : routerStepOutDTOS) {
|
||||
if (operation.equals(routerStepOutDTO.getOperation())) {
|
||||
if (StrUtil.isNotBlank(routerStepOutDTO.getEndOp())) {
|
||||
jsonObject.put("endOp", routerStepOutDTO.getEndOp());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Objects.equals("E", jsonObject.get("endOp"))) {
|
||||
throw BusinessException.build("工序" + operation + "不是末工序。");
|
||||
}
|
||||
}else {
|
||||
throw BusinessException.build("未根据订单号:" +shopOrder+"和站点:"+site+"找到对应工序");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String assembleMsgBody(InventoryRecord statisticsTransaction) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", "ZPP_MES_PRODORDCONF");
|
||||
@ -152,7 +176,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
JSONObject bodyRe = new JSONObject();
|
||||
JSONObject isInput = new JSONObject();
|
||||
isInput.put("AUFNR", statisticsTransaction.getShopOrder());//订单号
|
||||
isInput.put("VORNR", statisticsTransaction.getOperation());// 工序
|
||||
isInput.put("VORNR", statisticsTransaction.getSapOperation());// 工序
|
||||
isInput.put("PLNBEZ", statisticsTransaction.getWorkshopNumber());//物料号
|
||||
isInput.put("LMNGA", statisticsTransaction.getQtyDone());//完工数量
|
||||
isInput.put("XMNGA", statisticsTransaction.getQtyScrapped());//报废数量
|
||||
@ -173,80 +197,6 @@ public class CopyShopOrderStatisticTransController {
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
// --------------------------------------------- 生产报工取消开始 -----------------------------------------------------
|
||||
// @ApiOperation(value = "生产管理报工平台-工单取消报工", notes = "生产管理报工平台-工单取消报工")
|
||||
// @SysLog("生产管理报工平台-工单取消报工")
|
||||
// @PostMapping("/callErpCancel")
|
||||
// public R callErpCancel(@RequestBody List<ZShoporderStatisticsTransaction> shoporderStatisticsTransactionList) {
|
||||
// InvokeResponse invokeResponse = new InvokeResponse();
|
||||
// List<ZShoporderStatisticsTransaction> newList = new ArrayList<>();
|
||||
// for (ZShoporderStatisticsTransaction statisticsTransaction : shoporderStatisticsTransactionList) {
|
||||
// // 重新校验一遍是否已经报过工,防止重复报工
|
||||
// ZShoporderStatisticsTransaction targetObj = zShoporderStatisticsTransactionMapper.selectById(statisticsTransaction.getSid());
|
||||
// if (!"S".equals(targetObj.getSyncStatus())) {
|
||||
// throw BusinessException.build("工单" + targetObj.getShopOrder() + "还未报工无需取消报工");
|
||||
// } else {
|
||||
// newList.add(targetObj);
|
||||
// }
|
||||
// }
|
||||
// if (CollectionUtils.isNotEmpty(newList)) {
|
||||
// // 传参对象
|
||||
// InvokeRequest invokeRequest = new InvokeRequest();
|
||||
// LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
// String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
// String shopOrder = "";
|
||||
// try {
|
||||
// for (ZShoporderStatisticsTransaction statisticsTransaction : newList) {
|
||||
// String site = statisticsTransaction.getSite();
|
||||
// shopOrder = statisticsTransaction.getShopOrder();
|
||||
// invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
// invokeRequest.setTransTime(nowTime);
|
||||
// invokeRequest.setFromSystem("IEP");
|
||||
// invokeRequest.setToSystem("ERP");
|
||||
// invokeRequest.setSite(site);
|
||||
// invokeRequest.setMessageId("ZPP_MES_PRODOR_CANCEL");
|
||||
//
|
||||
// // 组装抛送的报完呢
|
||||
// String jsonObjectStr = SapUtil.appendHead(assembleCancelMsgBody(statisticsTransaction));
|
||||
// invokeRequest.setMessageContent(jsonObjectStr);
|
||||
// invokeRequest.setStart(nowTime);
|
||||
// invokeRequest.setKeyValue(shopOrder);
|
||||
// invokeRequest.setRetry(false);
|
||||
// TenantContextHolder.setTenantId(site);
|
||||
// invokeResponse = shopOrderStatisticTransCancelService.call(invokeRequest);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw BusinessException.build("工单" + shopOrder + "取消报工失败!");
|
||||
// } finally {
|
||||
// // 保存日志
|
||||
// saveLogData(invokeRequest, invokeResponse);
|
||||
// }
|
||||
// }
|
||||
// if ("E".equals(invokeResponse.getResult())) {
|
||||
// return R.failed(invokeResponse.getMessageContent());
|
||||
// } else {
|
||||
// return R.ok();
|
||||
// }
|
||||
// }
|
||||
|
||||
// private String assembleCancelMsgBody(ZShoporderStatisticsTransaction statisticsTransaction) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("RFC_FUNCTION", "ZPP_MES_PRODOR_CANCEL");
|
||||
// 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("AUFNR", statisticsTransaction.getShopOrder()); // 工单
|
||||
// isInput.put("RUECK", statisticsTransaction.getSyncTransBatch()); // 操作完成的确认编号
|
||||
// isInput.put("RMZHL", statisticsTransaction.getSyncTicketLine()); // 确认计算器
|
||||
// isInput.put("VORNR", statisticsTransaction.getSyncTicketNo()); // 活动编号
|
||||
// bodyRe.put("IS_INPUT", isInput);
|
||||
// jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
// return jsonObject.toJSONString();
|
||||
// }
|
||||
|
||||
private void saveLogData(InvokeRequest invokeRequest, InvokeResponse invokeResponse) {
|
||||
if (StringUtils.isNotEmpty(invokeRequest.getTransSid())) {
|
||||
@ -367,6 +317,11 @@ public class CopyShopOrderStatisticTransController {
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:"+invokeResponse.getMessageContent());
|
||||
} else {
|
||||
for (InventoryRecord targetObj : srcList) {
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -421,7 +376,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
@PostMapping("/api/getSapBatchNo")
|
||||
public R<String> getSapBatchNo(@RequestBody String erpItem) {
|
||||
String sapBatchNo = registerDocumentService.getSapBatchNo(erpItem);
|
||||
return R.ok(sapBatchNo);
|
||||
return R.ok(sapBatchNo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生产管理报工平台-批次完工入库报工", notes = "生产管理报工平台-批次完工入库报工")
|
||||
@ -521,6 +476,11 @@ public class CopyShopOrderStatisticTransController {
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed("SAP错误:"+invokeResponse.getMessageContent());
|
||||
} else {
|
||||
for (InventoryRecord targetObj : srcList) {
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -576,7 +536,6 @@ public class CopyShopOrderStatisticTransController {
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setSyncMessageRemark(msgid);
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
@ -585,9 +544,18 @@ public class CopyShopOrderStatisticTransController {
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
private void processInventoryRecord(InventoryRecord inventoryRecord, String site) {
|
||||
String user = SecurityUtils.getUserName();
|
||||
private void processInventoryRecord(InventoryRecord inventoryRecord,String site) {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
||||
String dataTime = inventoryRecord.getDateOfManufacture();
|
||||
LocalDateTime pdt = null;
|
||||
if (dataTime.contains("-")) {
|
||||
pdt = LocalDate.parse(dataTime, dateTimeFormatter).atTime(0, 0);
|
||||
} else {
|
||||
pdt = LocalDate.parse(dataTime, dateTimeFormatter2).atTime(0, 0);
|
||||
}
|
||||
|
||||
String user = SecurityUtils.getUserName();
|
||||
String erpInventory = inventoryRecord.getErpInventory();
|
||||
String barcode = inventoryRecord.getBarcode();
|
||||
String status = inventoryRecord.getStatus();
|
||||
@ -607,9 +575,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
inventory.setSite(site);
|
||||
inventory.setCreator(user);
|
||||
inventory.setCreateTime(LocalDateTime.now());
|
||||
R<Item> itemR = inventoryService.selectCurrentByMes(site, workshopNumber);
|
||||
Item itemObj = itemR.getData();
|
||||
|
||||
Item itemObj = inventoryService.selectCurrentByMes(site, workshopNumber).getData();
|
||||
inventory.setItemBo(itemObj.getHandle());
|
||||
inventory.setUnitOfMeasure(itemObj.getUnitOfMeasure());
|
||||
inventory.setErpStorageLocation(erpInventory);
|
||||
@ -620,15 +586,14 @@ public class CopyShopOrderStatisticTransController {
|
||||
BigDecimal qtyDones = new BigDecimal(qtyDone);
|
||||
inventory.setOriginalQty(qtyDones);
|
||||
inventory.setQtyOnHand(qtyDones);
|
||||
inventory.setProductionDate(pdt);
|
||||
|
||||
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
inventory.setProductionDate(LocalDate.parse(dateOfManufacture, dateTimeFormatter).atTime(0, 0));
|
||||
inventory.setQualityInspectionStatus(grade);
|
||||
|
||||
inventory.setRollType(uom);
|
||||
inventory.setAuxiliaryUnit(subUom);
|
||||
inventory.setAuxiliaryOty(subQty);
|
||||
|
||||
inventoryService.createInventory(inventory);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user