物料消耗+报工

philip 4 years ago
parent 5ccb35cb4a
commit bbd12432d5

@ -61,6 +61,8 @@ public interface Constants {
String ACTION_CODE_LOAD="1";
//卸料
String ACTION_CODE_UNLOAD="2";
//消耗
String ACTION_CODE_CONSUMPTION="3";
//--------------------检验项目|任务-----------------------------------------------------------------------------------
// 新建

@ -692,7 +692,7 @@
</select>
<select id = "getSfcBomComponent" resultType="com.foreverwin.mesnac.meapi.dto.BomComponentDto">
SELECT RS.STEP_ID,OP.OPERATION,BC.COMPONENT_GBO,TP.VALUE ACCESSORY_TYPE
SELECT BC.handle,BC.qty,RS.STEP_ID,OP.OPERATION,BC.COMPONENT_GBO,TP.VALUE ACCESSORY_TYPE
FROM SFC SFC
JOIN SFC_ROUTING SRI ON SRI.SFC_BO =SFC.HANDLE
JOIN SFC_ROUTER SR ON SRI.HANDLE =SR.SFC_ROUTING_BO

@ -3,10 +3,12 @@ package com.foreverwin.mesnac.production.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.foreverwin.mesnac.meapi.dto.WorkCenterDto;
import com.foreverwin.mesnac.meapi.model.Inventory;
import com.foreverwin.mesnac.production.dto.LoadInventoryDto;
import com.foreverwin.mesnac.production.model.LoadInventory;
import com.foreverwin.modular.core.util.FrontPage;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
@ -34,4 +36,7 @@ public interface LoadInventoryService extends IService<LoadInventory> {
void loadInventory(LoadInventory loadInventory);
void unLoadInventory(List<LoadInventoryDto> inventoryDtoList);
Inventory consumption(LoadInventory loadInventory, BigDecimal costQty);
}

@ -1,6 +1,7 @@
package com.foreverwin.mesnac.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.foreverwin.mesnac.common.constant.Constants;
@ -171,5 +172,39 @@ public class LoadInventoryServiceImpl extends ServiceImpl<LoadInventoryMapper, L
}
}
@Override
public Inventory consumption(LoadInventory loadInventory, BigDecimal costQty) {
String site = CommonMethods.getSite();
String user = CommonMethods.getUser();
String inventoryId = loadInventory.getInventoryId();
BigDecimal qtyOnHand = loadInventory.getQtyOnHand();
Inventory inventory = inventoryService.getById(HandleEnum.INVENTORY.getHandle(site, inventoryId));
LoadInventoryLog loadInventoryLog=new LoadInventoryLog();
BeanUtils.copyProperties(loadInventory,loadInventoryLog);
loadInventoryLog.setActionCode(Constants.ACTION_CODE_CONSUMPTION);
loadInventoryLog.setCreatedDateTime(LocalDateTime.now());
loadInventoryLog.setCreateUser(user);
loadInventoryLog.setHandle(UUID.randomUUID().toString());
if (inventory==null){
throw new BaseException("库存"+inventoryId+"不存在");
}
if (costQty.compareTo(qtyOnHand)>=0){
//删除卸料数据
removeById(loadInventory.getHandle());
}else {
//减少设备数量
loadInventoryLog.setQtyOnHand(costQty);
LoadInventory entity = new LoadInventory();
entity.setQtyOnHand(qtyOnHand.subtract(costQty));
UpdateWrapper<LoadInventory> updateWrapper=new UpdateWrapper<>();
updateWrapper.eq(LoadInventory.HANDLE,loadInventory.getHandle());
update(entity, updateWrapper);
}
//增加库存
commonService.updateInventory(site,inventoryId,inventory.getQtyOnHand().add(costQty));
loadInventoryLogService.save(loadInventoryLog);
return inventory;
}
}

@ -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();
@ -84,7 +102,7 @@ public class PodTemplateServiceImpl implements PodTemplateService {
throw new BaseException("资源 " + resrce + " 与车间不匹配");
}
//查询在该设备存在活动中的SFC
List<SfcDto> sfcList = sfcCrossService.getSfcListByResrce(site,resrce);
List<SfcDto> sfcList = sfcCrossService.getSfcListByResrce(site, resrce);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("SFC_LIST", sfcList);
return resultMap;
@ -130,17 +148,17 @@ public class PodTemplateServiceImpl implements PodTemplateService {
String isCreateZ = "N";
resultMap.put("IS_CREATE_W", "N");
List<InspectionItemDetail> inspectionItemDetails = inspectionItemService.selectQualityInspection(sfc, operationBySfcBo.getOperation(), operationBySfcBo.getStepId(), Constants.INSPECTION_TYPE_H);
if (inspectionItemDetails.size()>0&&inspectionItemDetails.get(0)!=null) {
if (inspectionItemDetails.size() > 0 && inspectionItemDetails.get(0) != null) {
InspectionTask createTask = inspectionTaskService.isCreateTask(site, Constants.INSPECTION_TYPE_H, sfc, operationBySfcBo.getOperation(), operationBySfcBo.getStepId());
if (createTask==null ||!createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)){
isCreateH="Y";
if (createTask == null || !createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)) {
isCreateH = "Y";
}
}
inspectionItemDetails = inspectionItemService.selectQualityInspection(sfc, operationBySfcBo.getOperation(), operationBySfcBo.getStepId(), Constants.INSPECTION_TYPE_Z);
if (inspectionItemDetails.size()>0&& inspectionItemDetails.get(0)!=null) {
if (inspectionItemDetails.size() > 0 && inspectionItemDetails.get(0) != null) {
InspectionTask createTask = inspectionTaskService.isCreateTask(site, Constants.INSPECTION_TYPE_Z, sfc, operationBySfcBo.getOperation(), operationBySfcBo.getStepId());
if (createTask==null ||!createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)){
if (createTask == null || !createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)) {
isCreateZ = "Y";
}
}
@ -162,14 +180,15 @@ 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();
if (sfcDtoList==null||sfcDtoList.size()<1){
if (sfcDtoList == null || sfcDtoList.size() < 1) {
throw new BaseException("作业列表不能为空");
}
if (StringUtil.isBlank(resrce)){
if (StringUtil.isBlank(resrce)) {
throw new BaseException("资源不能为空");
}
//是否设备点检
@ -181,39 +200,41 @@ public class PodTemplateServiceImpl implements PodTemplateService {
String stepId = sfcDto.getStepId();
String dispatchNo = sfcDto.getDispatchNo();
Sfc sfcServiceById = sfcService.getById(HandleEnum.SFC.getHandle(site, sfc));
BigDecimal qty=new BigDecimal(sfcServiceById.getQty().toString());
BigDecimal qty = new BigDecimal(sfcServiceById.getQty().toString());
//是否有互检检验项目
List<InspectionItemDetail> inspectionItemDetails = inspectionItemService.selectQualityInspection(sfc, operation, stepId, Constants.INSPECTION_TYPE_H);
if (inspectionItemDetails.size()>0&&inspectionItemDetails.get(0)!=null) {
if (inspectionItemDetails.size() > 0 && inspectionItemDetails.get(0) != null) {
//是否有互检检验任务及已完成
InspectionTask createTask = inspectionTaskService.isCreateTask(site, Constants.INSPECTION_TYPE_H, sfc, operation, stepId);
if (createTask==null ||!createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)){
if (createTask == null || !createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)) {
throw new BaseException("请完成互检检验任务");
}
if (!createTask.getResult().equals(Constants.RSESULT_OK)){
if (!createTask.getResult().equals(Constants.RSESULT_OK)) {
throw new BaseException("互检任务不合格,不能开始请检查");
}
}
try {
sfcCrossService.startAction(site, currentRevisionRef.getHandle(),resrce,sfcServiceById.getHandle(),qty);
sfcCrossService.startAction(site, currentRevisionRef.getHandle(), resrce, sfcServiceById.getHandle(), qty);
} catch (Exception e) {
ExceptionUtil.throwException(e);
}
//更改派工单状态
sfcDispatchCommonService.updateSfcDispatchStatus(site,CommonMethods.getUser(),dispatchNo, DispatchStatusEnum.START.getCode());
sfcDispatchCommonService.updateSfcDispatchStatus(site, CommonMethods.getUser(), dispatchNo, DispatchStatusEnum.START.getCode());
});
}
@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){
if (sfcDtoList == null || sfcDtoList.size() < 1) {
throw new BaseException("作业列表不能为空");
}
if (StringUtil.isBlank(resrce)){
if (StringUtil.isBlank(resrce)) {
throw new BaseException("资源不能为空");
}
@ -226,36 +247,127 @@ public class PodTemplateServiceImpl implements PodTemplateService {
String dispatchNo = sfcDto.getDispatchNo();
Sfc sfcServiceById = sfcService.getById(HandleEnum.SFC.getHandle(site, sfc));
BigDecimal qty=new BigDecimal(sfcServiceById.getQty().toString());
BigDecimal qty = new BigDecimal(sfcServiceById.getQty().toString());
//是否有自检检验项目
List<InspectionItemDetail> inspectionItemDetails = inspectionItemService.selectQualityInspection(sfc, operation, stepId, Constants.INSPECTION_TYPE_Z);
if (inspectionItemDetails.size()>0&&inspectionItemDetails.get(0)!=null) {
if (inspectionItemDetails.size() > 0 && inspectionItemDetails.get(0) != null) {
//是否有自检检验任务
InspectionTask createTask = inspectionTaskService.isCreateTask(site, Constants.INSPECTION_TYPE_Z, sfc, operation, stepId);
if (createTask==null ||!createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)){
if (createTask == null || !createTask.getStatus().equals(Constants.INSPECTION_TASK_STATUS_COMPLETE)) {
throw new BaseException("请完成自检检验任务");
}
if (!createTask.getResult().equals(Constants.RSESULT_OK)){
if (!createTask.getResult().equals(Constants.RSESULT_OK)) {
throw new BaseException("自检任务不合格,不能完成请检查");
}
}
//物料消耗
materialConsumption(site, operation, HandleEnum.SFC.getHandle(site, sfc), stepId, resrce);
try {
sfcCrossService.completeAction(site, currentRevisionRef.getHandle(),resrce,sfcServiceById.getHandle(),qty);
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

@ -144,6 +144,7 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
DispositionSelection dispositionSelection=new DispositionSelection();
dispositionSelection.setRouterRef(routerBo);
dispositionSfcsRequest.setDispositionSelection(dispositionSelection);
dispositionSfcsRequest.setProdCtx(new ProductionContext());
ncProductionService.dispositionMultipleSfcs(dispositionSfcsRequest);
SplitSfc splitSfc=new SplitSfc();
String newSfc = StringUtil.trimHandle(newSfcRef);

Loading…
Cancel
Save