diff --git a/dispatch/src/main/resources/mapper/SfcDispatchMapper.xml b/dispatch/src/main/resources/mapper/SfcDispatchMapper.xml index c3892c91..3101bdc7 100644 --- a/dispatch/src/main/resources/mapper/SfcDispatchMapper.xml +++ b/dispatch/src/main/resources/mapper/SfcDispatchMapper.xml @@ -1099,6 +1099,11 @@ diff --git a/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcDataAssembleController.java b/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcDataAssembleController.java index 4587ec1e..b649f94b 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcDataAssembleController.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcDataAssembleController.java @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** * @@ -35,6 +36,11 @@ public class SfcDataAssembleController { public R loadSfcAssemble(SfcDto sfcDto) { return R.ok(sfcDataAssembleService.loadSfcAssemble(sfcDto)); } + @ResponseBody + @PostMapping("/assembleInventory") + public R loadSfcAssemble(@RequestBody Map paramMap) { + return R.ok(sfcDataAssembleService.assembleInventory(paramMap)); + } /** * 根据id查询 * diff --git a/production/src/main/java/com/foreverwin/mesnac/production/service/SfcDataAssembleService.java b/production/src/main/java/com/foreverwin/mesnac/production/service/SfcDataAssembleService.java index ae4f100f..b9183859 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/service/SfcDataAssembleService.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/service/SfcDataAssembleService.java @@ -29,7 +29,7 @@ public interface SfcDataAssembleService extends IService { List selectList(SfcDataAssemble sfcDataAssemble); - Object loadSfcAssemble(SfcDto sfcDto); + Map loadSfcAssemble(SfcDto sfcDto); Map assembleInventory(Map paramMap) throws BaseException; } \ No newline at end of file diff --git a/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcDataAssembleServiceImpl.java b/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcDataAssembleServiceImpl.java index 5f9e8fef..84837632 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcDataAssembleServiceImpl.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcDataAssembleServiceImpl.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.foreverwin.mesnac.common.dto.SfcDispatchDto; import com.foreverwin.mesnac.common.enums.DispatchStatusEnum; -import com.foreverwin.mesnac.common.enums.HandleEnum; import com.foreverwin.mesnac.common.service.SfcDispatchCommonService; import com.foreverwin.mesnac.common.util.ExceptionUtil; import com.foreverwin.mesnac.meapi.dto.SfcDto; @@ -20,8 +19,6 @@ import com.foreverwin.modular.core.exception.BaseException; import com.foreverwin.modular.core.meext.MEServices; import com.foreverwin.modular.core.util.CommonMethods; import com.foreverwin.modular.core.util.FrontPage; -import com.sap.me.inventory.InventoryServiceInterface; -import com.sap.me.inventory.InventoryValidateAndAddRequest; import com.sap.me.production.AssembleComponentsRequest; import com.sap.me.production.AssemblyComponent; import com.sap.me.production.AssemblyDataField; @@ -57,6 +54,7 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl selectPage(FrontPage frontPage, SfcDataAssemble sfcDataAssemble) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -72,7 +70,7 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl loadSfcAssemble(SfcDto sfcDto) { //构造参数 String site = CommonMethods.getSite(); String user = CommonMethods.getUser(); @@ -81,19 +79,23 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl resultMap = new HashMap(); //查询装配数据 List> assembleList = sfcDataAssembleMapper.querySfcAssemble(sfcDispatchBySfc.getHandle()); + if (assembleList == null) { + throw new BaseException("没有装配物料"); + } + resultMap.put("SfcDispatchBO", sfcDispatchBySfc.getHandle()); resultMap.put("ASSEMBLE_LIST", assembleList); return resultMap; } @@ -101,218 +103,118 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl assembleInventory(Map paramMap) throws BaseException { - String site = (String) paramMap.get("SITE"); - String user = (String) paramMap.get("USER"); + String site = CommonMethods.getSite(); + String user = CommonMethods.getUser(); String inventoryId = (String) paramMap.get("INVENTORY_ID"); - String sfcDispatchBo = (String) paramMap.get("SFC_DATA_MAIN_BO"); + String sfcDispatchBo = (String) paramMap.get("SfcDispatchBo"); String sfc = (String) paramMap.get("SFC"); String barCode = inventoryId; + BigDecimal assembleQty = new BigDecimal((String) paramMap.get("QTY")); - SfcDispatchDto sfcDispatch=new SfcDispatchDto(); + + SfcDispatchDto sfcDispatch = new SfcDispatchDto(); + sfcDispatch.setHandle(sfcDispatchBo); SfcDispatchDto sfcDataMain = sfcDispatchCommonService.findSfcDispatchBySfc(sfcDispatch); //判断条码是否存在 Inventory inv = inventoryService.getById("InventoryBO:" + site + "," + inventoryId); - /*if(inv.getQtyOnHand() <= 0){ - throw new BaseException("物料条码["+inventoryId+"]已无库存数量,无法装配!"); - }*/ - - String[] inventoryIds = null; - if(inv == null){ - //一定为拆机,扫描的条码格式为 派工单*步骤标识*物料*SFC*BOM组件顺序 - int result1 = inventoryId.indexOf("*"); - if (result1 == -1) { - throw new BaseException("物料条码[" + barCode + "]不存在!"); - } - inventoryIds = inventoryId.split("\\*"); - if (inventoryIds.length != 5) { - throw new BaseException("物料条码[" + barCode + "]不存在!"); - } - //判断扫描的条码是否符合 - Map sfcDismantling = sfcDataAssembleMapper.querySfcDismantling(sfcDispatchBo); - if(!inventoryIds[0].equals(sfcDismantling.get("DISPATCH_NO")) || !inventoryIds[1].equals(sfcDismantling.get("STEP_ID")) - || !inventoryIds[3].equals(sfcDismantling.get("SFC"))){ - throw new BaseException("物料条码[" + barCode + "]不在装配列表中!"); - } + if (inv == null) { + throw new BaseException("物料条码[" + barCode + "]不存在!"); } //获取需装配数据,判断是为拆机还是装配 List> assembleList = sfcDataAssembleMapper.querySfcAssemble(sfcDispatchBo); String isFlag = "N";//是否在装配列表中 String isAssemble = "";//装配情况,按颜色区分,GREEN:已装配/拆机完成,YELLOW:未装配/拆机完成,WHITE:未进行装配/拆机完成 String item = "";//物料 - String isDismantling = "N";//是否为拆机 String itemBo = ""; String bomCompBo = ""; double seq = 0; BigDecimal qty = BigDecimal.ZERO; - BigDecimal assembleQty = BigDecimal.ZERO; - //for循环判断是否为拆机 - for(int i = 0; i < assembleList.size(); i++){ - if(inv != null && assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())){ - //为装配或拆机 - isDismantling = (String) assembleList.get(i).get("IS_DISMANTLING"); - isFlag = "Y"; - }else if(inv == null && HandleEnum.ITEM.getPart((String) assembleList.get(i).get("ITEM_BO"),1).equals(inventoryIds[2]) - && "Y".equals(assembleList.get(i).get("IS_DISMANTLING"))){ - //一定为拆机 - isFlag = "Y"; - isDismantling = "Y"; - } - } - if(isFlag.equals("N")){ - throw new BaseException("物料条码["+barCode+"]不在装配列表中!"); - } + BigDecimal assembledQty = BigDecimal.ZERO; - //条码不存在且为装配组件提示报错 - if(inv == null && "N".equals(isDismantling)){ - throw new BaseException("物料条码["+barCode+"]不存在!"); - } //for循环构造数据 isFlag = "N"; - for(int i = 0; i < assembleList.size(); i++){ - if("N".equals(isDismantling)) { - //装配 - if (assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())) { - isFlag = "Y"; - qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY")))); - assembleQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY")))); - item = (String) assembleList.get(i).get("ITEM"); - isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE"); - seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue(); - itemBo = (String) assembleList.get(i).get("ITEM_BO"); - bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO"); - } - }else{ - //拆机 - if(inv != null){ - //条码存在 - throw new BaseException("物料条码["+barCode+"]已被拆机,无法再次进行拆机!"); - }else{ - if(HandleEnum.ITEM.getPart((String) assembleList.get(i).get("ITEM_BO"),1).equals(inventoryIds[2]) && inventoryIds[4].equals(String.valueOf(assembleList.get(i).get("SEQ")))){ - isFlag = "Y"; - qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY")))); - assembleQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY")))); - item = (String) assembleList.get(i).get("ITEM"); - isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE"); - seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue(); - itemBo = (String) assembleList.get(i).get("ITEM_BO"); - bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO"); - } - } + for (int i = 0; i < assembleList.size(); i++) { + //装配 + if (assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())) { + isFlag = "Y"; + qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY")))); + assembledQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY")))); + item = (String) assembleList.get(i).get("ITEM"); + isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE"); + seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue(); + itemBo = (String) assembleList.get(i).get("ITEM_BO"); + bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO"); } } - if(isFlag.equals("N")){ - throw new BaseException("物料条码["+barCode+"]不在装配列表中!"); + if (isFlag.equals("N")) { + throw new BaseException("物料条码[" + barCode + "]不在装配列表中!"); } - if(isAssemble.equals("GREEN")){ - String dismantlingDesc = "N".equals(isDismantling) ? "装配" : "拆机"; - throw new BaseException("物料["+item+"]已"+ dismantlingDesc +"完成,无需再进行"+ dismantlingDesc +"!"); + if (isAssemble.equals("GREEN")) { + throw new BaseException("物料[" + item + "]已装配完成,无需再进行装配!"); } //装配 - if("N".equals(isDismantling)) { - if(inv.getQtyOnHand().doubleValue() <= 0){ - throw new BaseException("物料条码["+barCode+"]已无库存数量,无法装配!"); - } - //校验 - List> validateList = sfcDataAssembleMapper.validateSfcAssemble(site, inventoryId, sfcDispatchBo); - if (validateList.size() > 0) { - for (int i = 0; i < validateList.size(); i++) { - Map validateMap = validateList.get(i); - String statusMess = (String) validateMap.get("STATUS_MESS"); - String status = statusMess.substring(0, 1); - if ("N".equals(status)) { - String mess = statusMess.substring(2, statusMess.length()); - throw new BaseException(mess); - } - } - } - //物料消耗,添加装配数据,无需扣减库存 - BigDecimal qtyOnHand = BigDecimal.ZERO; - if (inv.getQtyOnHand().subtract (qty.subtract(assembleQty) ).doubleValue() > 0) { - qtyOnHand = inv.getQtyOnHand() .subtract (qty.subtract(assembleQty)); - } - BigDecimal assembleSfcQty = inv.getQtyOnHand() .subtract(qtyOnHand) ; - //inv.setQtyOnHand(qtyOnHand); - //inventoryService.saveOrUpdate(inv); - //标准物料消耗 - AssembleComponentsRequest assembleComponentsRequest = new AssembleComponentsRequest(); - List componentList = new ArrayList(); - List adf = new ArrayList(); - AssemblyComponent ac = new AssemblyComponent(); - String[] str = {"INVENTORY_ID_SFC", "SLOT_QTY"}; - for (int j = 0; j < str.length; j++) { - AssemblyDataField ad = new AssemblyDataField(); - ad.setAttribute(str[j]); - String value = inv.getInventoryId(); - if ("SLOT_QTY".equals(str[j])) { - value = String.valueOf(assembleSfcQty); - } - ad.setValue(value); - adf.add(ad); - } - ac.setActualComponentRef(inv.getItemBo()); - ac.setTimeBased(false); - ac.setBomComponentRef(bomCompBo); - ac.setAssemblyDataFields(adf); - ac.setQty(assembleSfcQty); - ac.setSetErpSentFlag(false); - componentList.add(ac); - - assembleComponentsRequest.setResourceRef("ResourceBO:" + site + "," + sfcDataMain.getResrce()); - assembleComponentsRequest.setStepId(sfcDataMain.getStepId()); - String operationBo = operationService.getCurrentRevisionRef(site, sfcDataMain.getOperation()).getHandle(); - assembleComponentsRequest.setOperationRef(operationBo); - assembleComponentsRequest.setEvent("baseFinished:AssemblyPoint"); - assembleComponentsRequest.setComponentList(componentList); - assembleComponentsRequest.setSfcRef("SFCBO:" + site + "," + sfc); - try { - AssemblyServiceInterface assemblyService = null; - assemblyService = MEServices.create("com.sap.me.production", "AssemblyService", site); - assemblyService.assembleComponents(assembleComponentsRequest); - } catch (Exception e) { - ExceptionUtil.throwException(e); + if (inv.getQtyOnHand().doubleValue() <= 0) { + throw new BaseException("物料条码[" + barCode + "]已无库存数量,无法装配!"); + } + //标准物料消耗 + AssembleComponentsRequest assembleComponentsRequest = new AssembleComponentsRequest(); + List componentList = new ArrayList(); + List adf = new ArrayList<>(); + AssemblyComponent ac = new AssemblyComponent(); + String[] str = {"INVENTORY_ID_SFC", "SLOT_QTY"}; + for (int j = 0; j < str.length; j++) { + AssemblyDataField ad = new AssemblyDataField(); + ad.setAttribute(str[j]); + String value = inv.getInventoryId(); + if ("SLOT_QTY".equals(str[j])) { + value = String.valueOf(assembleQty); } + ad.setValue(value); + adf.add(ad); + } + ac.setActualComponentRef(inv.getItemBo()); + ac.setTimeBased(false); + ac.setBomComponentRef(bomCompBo); + ac.setAssemblyDataFields(adf); + ac.setQty(assembleQty); + ac.setSetErpSentFlag(false); + componentList.add(ac); + + assembleComponentsRequest.setResourceRef("ResourceBO:" + site + "," + sfcDataMain.getResrce()); + assembleComponentsRequest.setStepId(sfcDataMain.getStepId()); + String operationBo = operationService.getCurrentRevisionRef(site, sfcDataMain.getOperation()).getHandle(); + assembleComponentsRequest.setOperationRef(operationBo); + assembleComponentsRequest.setEvent("baseFinished:AssemblyPoint"); + assembleComponentsRequest.setComponentList(componentList); + assembleComponentsRequest.setSfcRef("SFCBO:" + site + "," + sfc); + try { + AssemblyServiceInterface assemblyService = null; + assemblyService = MEServices.create("com.sap.me.production", "AssemblyService", site); + assemblyService.assembleByComponents(assembleComponentsRequest); + } catch (Exception e) { + ExceptionUtil.throwException(e); + } - SfcDataAssemble assemble = new SfcDataAssemble(); - assemble.setHandle("SfcDataAssembleBO:" + site + "," + UUID.randomUUID().toString()); - assemble.setSite(site); - assemble.setSfcDispatchBo(sfcDispatchBo); - assemble.setStatus("A"); - assemble.setInventoryBo(inv.getHandle()); - assemble.setSeq(seq); - assemble.setItemBo(inv.getItemBo()); - assemble.setAssembleQty(assembleSfcQty); - assemble.setCreatedUser(user); - assemble.setCreatedDateTime(LocalDateTime.now()); - assemble.setModifiedDateTime(LocalDateTime.now()); - assemble.setModifyUser(user); - sfcDataAssembleMapper.insert(assemble); - }else{ + SfcDataAssemble assemble = new SfcDataAssemble(); + assemble.setHandle("SfcDataAssembleBO:" + site + "," + UUID.randomUUID().toString()); + assemble.setSite(site); + assemble.setSfcDispatchBo(sfcDispatchBo); + assemble.setStatus("A"); + assemble.setInventoryBo(inv.getHandle()); + assemble.setSeq(seq); + assemble.setItemBo(inv.getItemBo()); + assemble.setAssembleQty(assembleQty); + assemble.setCreatedUser(user); + assemble.setCreatedDateTime(LocalDateTime.now()); + assemble.setModifiedDateTime(LocalDateTime.now()); + assemble.setModifyUser(user); + sfcDataAssembleMapper.insert(assemble); - BigDecimal assembleSfcQty = qty; - //生成库存 - InventoryServiceInterface inventoryServiceInterface = null; - try { - inventoryServiceInterface = MEServices.create("com.sap.me.inventory", "InventoryService", site); - } catch (ClassNotFoundException e) { - throw new BaseException(e.getMessage()); - } - InventoryValidateAndAddRequest invAddRequest = new InventoryValidateAndAddRequest(); - invAddRequest.setInventoryId(inventoryId); - invAddRequest.setQuantityOnHand(assembleSfcQty); - invAddRequest.setItemRef(itemBo); - String shopOrderBo = HandleEnum.SHOP_ORDER.getHandle(site, sfcDataMain.getShopOrder()); - invAddRequest.setShopOrderLocationRef(shopOrderBo); - try { - inventoryServiceInterface.validateAndAdd(invAddRequest); - } catch (com.sap.me.frame.domain.BusinessException e) { - ExceptionUtil.throwException( e); - } - } return null; } diff --git a/production/src/main/resources/mapper/SfcDataAssembleMapper.xml b/production/src/main/resources/mapper/SfcDataAssembleMapper.xml index df24fcd9..314c88b5 100644 --- a/production/src/main/resources/mapper/SfcDataAssembleMapper.xml +++ b/production/src/main/resources/mapper/SfcDataAssembleMapper.xml @@ -436,12 +436,11 @@ WHERE DA.SFC_DISPATCH_BO = #{sfcDispatchBo} GROUP BY DA.ITEM_BO, DA.SEQ ) - SELECT CASE WHEN CF2.VALUE='Y' THEN N'-' ELSE N'+' END || N'物料:'||I.ITEM||'/'||I.REVISION||N' 数量:'|| S.QTY * BC.QTY ITEM_REVISION, + SELECT '物料:'||I.ITEM||'/'||I.REVISION||N' 数量:'|| S.QTY * BC.QTY ITEM_REVISION, S.QTY * BC.QTY QTY,NVL(SD.ASSEMBLE_QTY,0) ASSEMBLE_QTY,I.HANDLE ITEM_BO,I.ITEM,IT.DESCRIPTION ITEM_DESC, CASE WHEN NVL(SD.ASSEMBLE_QTY,0) = 0 THEN 'WHITE' WHEN NVL(SD.ASSEMBLE_QTY,0) = S.QTY * BC.QTY THEN 'GREEN' - ELSE 'YELLOW' END IS_ASSEMBLE,BC.HANDLE BOM_COMPONENT_BO, - CASE WHEN CF2.VALUE='Y' THEN 'Y' ELSE 'N' END IS_DISMANTLING, BC."SEQUENCE" SEQ + ELSE 'YELLOW' END IS_ASSEMBLE,BC.HANDLE BOM_COMPONENT_BO, BC."SEQUENCE" SEQ FROM Z_SFC_DISPATCH DM INNER JOIN SFC S ON S.SITE = DM.SITE AND S.SFC = DM.SFC INNER JOIN SFC_BOM SB ON SB.SFC_BO = S.HANDLE @@ -449,8 +448,6 @@ INNER JOIN ITEM I ON I.HANDLE = BC.COMPONENT_GBO LEFT JOIN ITEM_T IT ON IT.ITEM_BO = I.HANDLE AND IT.LOCALE ='zh' INNER JOIN CUSTOM_FIELDS I_CF ON I_CF.HANDLE = I.HANDLE AND I_CF."ATTRIBUTE" = 'ACCESSORY_TYPE' AND I_CF.VALUE ='9' - INNER JOIN BOM_OPERATION BO ON BO.BOM_COMPONENT_BO = BC.HANDLE - AND BO.OPERATION_BO = 'OperationBO:'||S.SITE||','||DM.OPERATION||',#' INNER JOIN CUSTOM_FIELDS CF ON CF.HANDLE = BC.HANDLE AND CF."ATTRIBUTE" = 'STEP_ID' AND CF.VALUE = DM.STEP_ID LEFT JOIN SFC_DATA SD ON SD.ITEM_BO = I.HANDLE AND BC."SEQUENCE" = SD.SEQ WHERE DM.HANDLE = #{sfcDispatchBo}