|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.foreverwin.mesnac.production.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.foreverwin.mesnac.common.constant.Constants;
|
|
|
|
@ -18,19 +19,23 @@ import com.foreverwin.mesnac.common.service.SfcDispatchCommonService;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.ERPAPI;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.ExceptionUtil;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.StringUtil;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.dto.BomComponentDto;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.dto.SfcDto;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.dto.WorkCenterDto;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.Operation;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.Resrce;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.Sfc;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.OperationService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.ResrceService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.SfcService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.*;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.*;
|
|
|
|
|
import com.foreverwin.mesnac.production.mapper.SfcCrossMapper;
|
|
|
|
|
import com.foreverwin.mesnac.production.model.LoadInventory;
|
|
|
|
|
import com.foreverwin.mesnac.production.service.LoadInventoryService;
|
|
|
|
|
import com.foreverwin.mesnac.production.service.PodTemplateService;
|
|
|
|
|
import com.foreverwin.mesnac.production.service.SfcCrossService;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BaseException;
|
|
|
|
|
import com.foreverwin.modular.core.meext.MEServices;
|
|
|
|
|
import com.foreverwin.modular.core.util.CommonMethods;
|
|
|
|
|
import com.sap.me.production.AssembleComponentsRequest;
|
|
|
|
|
import com.sap.me.production.AssemblyComponent;
|
|
|
|
|
import com.sap.me.production.AssemblyDataField;
|
|
|
|
|
import com.sap.me.production.AssemblyServiceInterface;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -52,6 +57,14 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcService sfcService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BomService bomService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RouterService routerService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ItemService itemService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcBomService sfcBomService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonService commonService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcCrossMapper sfcCrossMapper;
|
|
|
|
@ -60,11 +73,16 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private OperationService operationService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BomComponentService bomComponentService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private InspectionTaskService inspectionTaskService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private InspectionItemService inspectionItemService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SfcDispatchCommonService sfcDispatchCommonService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private LoadInventoryService loadInventoryService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> resrceEnter(WorkCenterDto workCenterDto) {
|
|
|
|
|
String site = CommonMethods.getSite();
|
|
|
|
@ -162,7 +180,8 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
public void sfcStart(Map<String, Object> map) {
|
|
|
|
|
List<SfcDto> sfcDtoList = (List<SfcDto>) map.get("sfcDtoList");
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
sfcDtoList = mapper.convertValue(sfcDtoList, new TypeReference<List<SfcDto>>() {});
|
|
|
|
|
sfcDtoList = mapper.convertValue(sfcDtoList, new TypeReference<List<SfcDto>>() {
|
|
|
|
|
});
|
|
|
|
|
String resrce = (String) map.get("resrce");
|
|
|
|
|
String site = CommonMethods.getSite();
|
|
|
|
|
|
|
|
|
@ -204,11 +223,13 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sfcComplete(Map<String, Object> map) {
|
|
|
|
|
List<SfcDto> sfcDtoList = (List<SfcDto>) map.get("sfcDtoList");
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
sfcDtoList = mapper.convertValue(sfcDtoList, new TypeReference<List<SfcDto>>() {});
|
|
|
|
|
sfcDtoList = mapper.convertValue(sfcDtoList, new TypeReference<List<SfcDto>>() {
|
|
|
|
|
});
|
|
|
|
|
String resrce = (String) map.get("resrce");
|
|
|
|
|
if (sfcDtoList == null || sfcDtoList.size() < 1) {
|
|
|
|
|
throw new BaseException("作业列表不能为空");
|
|
|
|
@ -239,23 +260,114 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
throw new BaseException("自检任务不合格,不能完成请检查");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//物料消耗
|
|
|
|
|
materialConsumption(site, operation, HandleEnum.SFC.getHandle(site, sfc), stepId, resrce);
|
|
|
|
|
try {
|
|
|
|
|
sfcCrossService.completeAction(site, currentRevisionRef.getHandle(), resrce, sfcServiceById.getHandle(), qty);
|
|
|
|
|
//更改派工单状态
|
|
|
|
|
sfcDispatchCommonService.updateSfcDispatchStatus(site, CommonMethods.getUser(), dispatchNo, DispatchStatusEnum.COMPLETE.getCode());
|
|
|
|
|
//报工
|
|
|
|
|
sendErp(sfc, stepId, qty);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
ExceptionUtil.throwException(e);
|
|
|
|
|
}
|
|
|
|
|
//更改派工单状态
|
|
|
|
|
sfcDispatchCommonService.updateSfcDispatchStatus(site,CommonMethods.getUser(),dispatchNo, DispatchStatusEnum.COMPLETE.getCode());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void materialConsumption(String site, String operation, String sfcBo, String stepId, String resource) {
|
|
|
|
|
Sfc sfcServiceById = sfcService.getById(sfcBo);
|
|
|
|
|
SfcBom queryEntity = new SfcBom();
|
|
|
|
|
queryEntity.setSfcBo(sfcBo);
|
|
|
|
|
List<SfcBom> sfcBoms = sfcBomService.selectList(queryEntity);
|
|
|
|
|
if (sfcBoms.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//查询bom组件
|
|
|
|
|
List<BomComponentDto> bomComponents = bomComponentService.getSfcBomComponent(sfcBo);
|
|
|
|
|
if (bomComponents.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (BomComponentDto BomComponentDto : bomComponents) {
|
|
|
|
|
String accessoryType = BomComponentDto.getAccessoryType();
|
|
|
|
|
String componentGbo = BomComponentDto.getComponentGbo();
|
|
|
|
|
Item currentReversionItem = itemService.selectCurrent(site, StringUtil.trimHandle(componentGbo));
|
|
|
|
|
//消耗辅料类型为空或null
|
|
|
|
|
if ((accessoryType == null || accessoryType.equals("0")) && stepId.equals(BomComponentDto.getStepId())) {
|
|
|
|
|
//查询设备上的料
|
|
|
|
|
QueryWrapper<LoadInventory> wrapper = new QueryWrapper<>();
|
|
|
|
|
wrapper.eq(LoadInventory.RESRCE, resource);
|
|
|
|
|
wrapper.eq(LoadInventory.ITEM, StringUtil.trimHandle(componentGbo));
|
|
|
|
|
wrapper.orderByAsc(LoadInventory.CREATED_DATE_TIME);
|
|
|
|
|
List<LoadInventory> inventoryList = loadInventoryService.list(wrapper);
|
|
|
|
|
if (inventoryList.isEmpty()) {
|
|
|
|
|
throw new BaseException("设备没有上" + StringUtil.trimHandle(componentGbo) + "/" + currentReversionItem.getDescription() + "料");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal needQty = new BigDecimal(BomComponentDto.getQty()).multiply(new BigDecimal(sfcServiceById.getQty()));
|
|
|
|
|
for (LoadInventory loadInventory : inventoryList) {
|
|
|
|
|
BigDecimal qtyOnHand = loadInventory.getQtyOnHand();
|
|
|
|
|
BigDecimal costQty;
|
|
|
|
|
if (needQty.doubleValue() > qtyOnHand.doubleValue()) {
|
|
|
|
|
costQty = qtyOnHand;
|
|
|
|
|
needQty = needQty.subtract(costQty);
|
|
|
|
|
} else {
|
|
|
|
|
costQty = needQty;
|
|
|
|
|
needQty = BigDecimal.ZERO;
|
|
|
|
|
}
|
|
|
|
|
//删除上料数据
|
|
|
|
|
Inventory inventory = loadInventoryService.consumption(loadInventory, costQty);
|
|
|
|
|
//消耗
|
|
|
|
|
try {
|
|
|
|
|
assembly(site, BomComponentDto.getHandle(), operation, inventory, sfcBo, resource, costQty, stepId, sfcServiceById.getShopOrderBo());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
ExceptionUtil.throwException(e);
|
|
|
|
|
}
|
|
|
|
|
if (needQty.doubleValue() == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (needQty.doubleValue() > 0) {
|
|
|
|
|
throw new BaseException("组件[" + StringUtil.trimHandle(componentGbo) + "]耗用数量差[" + needQty + "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void assembly(String site, String BomComponentRef, String operation, Inventory inventory, String sfcBo, String resource, BigDecimal costQty, String stepId, String shopOrderBo) throws Exception {
|
|
|
|
|
//装配
|
|
|
|
|
AssemblyServiceInterface assemblyServiceInterface = MEServices.create("com.sap.me.production", "AssemblyService", site);
|
|
|
|
|
AssembleComponentsRequest assembleComponentsRequest = new AssembleComponentsRequest();
|
|
|
|
|
List<AssemblyComponent> assemblyComponentList = new ArrayList<>();
|
|
|
|
|
String itemBo = inventory.getItemBo();
|
|
|
|
|
AssemblyComponent assemblyComponent = new AssemblyComponent();
|
|
|
|
|
assemblyComponent.setBomComponentRef(BomComponentRef);
|
|
|
|
|
assemblyComponent.setTimeBased(false);
|
|
|
|
|
assemblyComponent.setQty(costQty);
|
|
|
|
|
assemblyComponent.setActualComponentRef(itemBo);
|
|
|
|
|
List<AssemblyDataField> assemblyDataFieldList = new ArrayList<>();
|
|
|
|
|
AssemblyDataField assemblyDataField = new AssemblyDataField();
|
|
|
|
|
assemblyDataField.setAttribute("INVENTORY_ID_SFC");
|
|
|
|
|
assemblyDataField.setValue(inventory.getInventoryId());
|
|
|
|
|
assemblyDataFieldList.add(assemblyDataField);
|
|
|
|
|
|
|
|
|
|
void senErp() throws RemoteException {
|
|
|
|
|
String shopOrder = "SO20210714";
|
|
|
|
|
String stepId = "OP001";
|
|
|
|
|
assemblyComponent.setAssemblyDataFields(assemblyDataFieldList);
|
|
|
|
|
assemblyComponentList.add(assemblyComponent);
|
|
|
|
|
assembleComponentsRequest.setComponentList(assemblyComponentList);
|
|
|
|
|
assembleComponentsRequest.setSfcRef(sfcBo);
|
|
|
|
|
assembleComponentsRequest.setOperationRef(operationService.getCurrentRevisionRef(site, operation).getHandle());
|
|
|
|
|
assembleComponentsRequest.setShopOrderRef(shopOrderBo);
|
|
|
|
|
assembleComponentsRequest.setResourceRef(HandleEnum.RESOURCE.getHandle(site, resource));
|
|
|
|
|
assembleComponentsRequest.setRouterRef(routerService.getRouterBySfcBo(sfcBo).getHandle());
|
|
|
|
|
assembleComponentsRequest.setStepId(stepId);
|
|
|
|
|
assembleComponentsRequest.setQuantity(costQty);
|
|
|
|
|
assembleComponentsRequest.setEvent("baseFinished:AssemblyPoint");
|
|
|
|
|
assemblyServiceInterface.assembleByComponents(assembleComponentsRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendErp(String sfc, String stepId, BigDecimal qty) throws RemoteException {
|
|
|
|
|
Sfc sfcServiceById = sfcService.getById(HandleEnum.SFC.getHandle(CommonMethods.getSite(),sfc));
|
|
|
|
|
String shopOrderBo = sfcServiceById.getShopOrderBo();
|
|
|
|
|
String shopOrder = StringUtil.trimHandle(shopOrderBo);
|
|
|
|
|
//请求参数
|
|
|
|
|
ZprodordconfStruIn[] ins = new ZprodordconfStruIn[1];
|
|
|
|
|
|
|
|
|
@ -266,17 +378,17 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
struIn.setVornr(stepId);
|
|
|
|
|
struIn.setAueru("1");
|
|
|
|
|
//良品数量
|
|
|
|
|
struIn.setLmnga(new BigDecimal(10));
|
|
|
|
|
struIn.setLmnga(qty);
|
|
|
|
|
//报废数量
|
|
|
|
|
struIn.setXmnga(new BigDecimal(1));
|
|
|
|
|
struIn.setXmnga(BigDecimal.ZERO);
|
|
|
|
|
//机器工时
|
|
|
|
|
struIn.setIsm01(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm01(BigDecimal.ZERO);
|
|
|
|
|
//人工工时
|
|
|
|
|
struIn.setIsm02(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm03(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm04(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm05(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm06(new BigDecimal(1));
|
|
|
|
|
struIn.setIsm02(BigDecimal.ZERO);
|
|
|
|
|
struIn.setIsm03(BigDecimal.ZERO);
|
|
|
|
|
struIn.setIsm04(BigDecimal.ZERO);
|
|
|
|
|
struIn.setIsm05(BigDecimal.ZERO);
|
|
|
|
|
struIn.setIsm06(BigDecimal.ZERO);
|
|
|
|
|
ins[0] = struIn;
|
|
|
|
|
TableOfZprodordconfStruInHolder inHolder = new TableOfZprodordconfStruInHolder(ins);
|
|
|
|
|
|
|
|
|
@ -298,6 +410,10 @@ public class PodTemplateServiceImpl implements PodTemplateService {
|
|
|
|
|
String status = outHolder.value[1].getRet();
|
|
|
|
|
String message = outHolder.value[1].getMsg();
|
|
|
|
|
System.out.println("ERP接口返回:状态:" + status + ",消息:" + message);
|
|
|
|
|
if (status.equals("E")) {
|
|
|
|
|
throw new BaseException("ERP接口返回:状态:" + status + ",消息:" + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|