From fd604e40b8254a4b3de76693a8036f80faea95df Mon Sep 17 00:00:00 2001 From: jing's Date: Fri, 26 Jan 2024 15:50:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=A0=B4=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bomnew/api/user/OptionalEbomApi.java | 16 + .../service/OptionalEbomMainService.java | 27 ++ .../aggreg/PublishMaterialService.java | 104 ++++-- .../domain/OptionalEBom/PublisMaterial.java | 322 ++++++++++++------ 4 files changed, 339 insertions(+), 130 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/OptionalEbomApi.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/OptionalEbomApi.java index be5f5662..8b4e7ac7 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/OptionalEbomApi.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/OptionalEbomApi.java @@ -86,6 +86,22 @@ public class OptionalEbomApi extends BaseApi { } + @PostMapping("updateDevice") + @ApiOperation("编辑机型") + public ResultVO updateDevice(@RequestBody OptionalEbomMainDTO dto) { + + if(dto.getRowId()==null ){ + return ResultVO.error(STATE.ParamErr, "机型rowId不能空"); + } + if(StrUtil.isEmpty(dto.getDeviceName()) ){ + return ResultVO.error(STATE.ParamErr, "机型名称不能空"); + } + + return ResultVO.success(this.optionalEbomMainService.updateDeviceName(dto)); + + } + + @ApiOperation("导入excel数据") @PostMapping("importDeviceExcel") public ResultVO importData(@RequestParam(required = true, value = "file") MultipartFile file) throws IOException { diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/OptionalEbomMainService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/OptionalEbomMainService.java index b31e3e99..aadb2c9f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/OptionalEbomMainService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/OptionalEbomMainService.java @@ -1,12 +1,15 @@ package com.nflg.product.bomnew.service; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.base.core.vo.PageVO; import com.nflg.product.bomnew.constant.OptionalBomConstant; import com.nflg.product.bomnew.mapper.master.OptionalEbomMainMapper; @@ -21,6 +24,7 @@ import com.nflg.product.bomnew.pojo.query.OptionalEbomMainQuery; import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; import com.nflg.product.bomnew.pojo.vo.OptionalEbomMainVO; import com.nflg.product.bomnew.service.OptionalEbomMainService; +import nflg.product.common.constant.STATE; import org.apache.ibatis.annotations.Param; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -50,6 +54,29 @@ public class OptionalEbomMainService extends ServiceImpl previewOptionList = optionalEbomConfigService.getPreviewOptionList(rowId); - List materialNoList = previewOptionList.stream().map(OptionalEbomImportChildVO::getMaterialNo).collect(Collectors.toList()); - - Collections.sort(materialNoList); - - String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(",")); - - String signMd5 = MD5.create().digestHex(result); - - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5); - - OptionalMbomCompareEntity optionalMbomCompareEntity = optionalMbomCompareService.getOne(queryWrapper); - - System.out.println(result); - System.out.println(signMd5); - } */ - public ResultVO publishWork(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) { @@ -82,6 +56,77 @@ public class PublishMaterialService { } + OptionalEbomConfigEntity configEntity=SpringUtil.getBean(OptionalEbomConfigService.class).getById(optionalEbomPublishAddDTO.getRowId()); + + if(configEntity ==null ){ + return ResultVO.error(StrUtil.format("{} 暂存数据查询到",optionalEbomPublishAddDTO.getRowId())); + } + OptionalEbomMainEntity mainEntity=SpringUtil.getBean(OptionalEbomMainService.class).getById(configEntity.getParentRowId()); + + if(mainEntity ==null ){ + return ResultVO.error(StrUtil.format("{} 设备数据未查询到",configEntity.getParentRowId())); + } + + //整机物料名称和物料描述=机型+机型名称+机台号+.0 + optionalEbomPublishAddDTO.setGoodsDesc(StrUtil.format("{}{}{}", + mainEntity.getDeviceNo(), + mainEntity.getDeviceName(), + optionalEbomPublishAddDTO.getMachineNo() + ).concat(".0")); + + //电控发货物料生成规则: 规则:物料名称和物料描述=(机型+机台号+.0) + optionalEbomPublishAddDTO.setElectricDesc(StrUtil.format("{}{}", + mainEntity.getDeviceNo(), + optionalEbomPublishAddDTO.getMachineNo() + ).concat(".0")); + + + + try { + + List materialList=null ; + //第一层级 机型发货 和制作 + // Long parentId = genVirtualPackLevel1(materialList, optionalEbomPublishAddDTO.getRowId(), optionalEbomPublishAddDTO.getGoodsDesc()); + //电控部分 + // genVirtualPackElectricLevel2(materialList, optionalEbomPublishAddDTO.getRowId(), parentId, optionalEbomPublishAddDTO.getElectricDesc()); + //机械部分申请 + // genVirtualPackMachineLevel2(materialList, optionList, optionalEbomPublishAddDTO.getRowId(), parentId,mainEntity.getRowId() ); + + + PublisMaterial publisMaterial=new PublisMaterial(optionalEbomPublishAddDTO,mainEntity.getRowId()); + materialList=publisMaterial.buildMaterialList(optionList); + + boolean ok = optionalMbomMaterialService.saveBatch(materialList); + + if (ok) { + //物料数据保存更改状态 + OptionalEbomConfigEntity optionalEbomConfigEntity = new OptionalEbomConfigEntity(); + optionalEbomConfigEntity.setRowId(optionalEbomPublishAddDTO.getRowId()); + + optionalEbomConfigEntity.setEditStatus(OptionalBomConstant.PublishEnum.PUBLISH.getValue()); + optionalEbomConfigService.updateById(optionalEbomConfigEntity); + } + + } catch (NflgBusinessException e) { + return ResultVO.error(e.getMsg()); + } + + return ResultVO.success("发布成功"); + + } + + + + + @Deprecated + public ResultVO publishWorkOld(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) { + + List optionList = optionalEbomConfigService.getPreviewOptionList(optionalEbomPublishAddDTO.getRowId()); + if (CollectionUtil.isEmpty(optionList)) { + return ResultVO.error("发布未查询到物料数据"); + } + + OptionalEbomConfigEntity configEntity=SpringUtil.getBean(OptionalEbomConfigService .class).getById(optionalEbomPublishAddDTO.getRowId()); if(configEntity ==null ){ @@ -98,7 +143,7 @@ public class PublishMaterialService { mainEntity.getDeviceNo(), mainEntity.getDeviceName(), optionalEbomPublishAddDTO.getMachineNo() - ).concat(".0")); + ).concat(".0")); //电控发货物料生成规则: 规则:物料名称和物料描述=(机型+机台号+.0) optionalEbomPublishAddDTO.setElectricDesc(StrUtil.format("{}{}", @@ -124,7 +169,7 @@ public class PublishMaterialService { //物料数据保存更改状态 OptionalEbomConfigEntity optionalEbomConfigEntity = new OptionalEbomConfigEntity(); optionalEbomConfigEntity.setRowId(optionalEbomPublishAddDTO.getRowId()); - // optionalEbomConfigEntity.setUpdatedTime(new Date()); + // optionalEbomConfigEntity.setUpdatedTime(new Date()); optionalEbomConfigEntity.setEditStatus(OptionalBomConstant.PublishEnum.PUBLISH.getValue()); optionalEbomConfigService.updateById(optionalEbomConfigEntity); } @@ -137,7 +182,6 @@ public class PublishMaterialService { } - /** * 生成21虚拟物件 *

diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OptionalEBom/PublisMaterial.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OptionalEBom/PublisMaterial.java index fe11e6a0..b47336f2 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OptionalEBom/PublisMaterial.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OptionalEBom/PublisMaterial.java @@ -6,6 +6,7 @@ import cn.hutool.core.lang.TypeReference; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.digest.MD5; import cn.hutool.extra.spring.SpringUtil; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.google.common.collect.ImmutableList; @@ -18,10 +19,13 @@ import com.nflg.product.bomnew.pojo.entity.OptionalEbomMainEntity; import com.nflg.product.bomnew.pojo.entity.OptionalMbomCompareEntity; import com.nflg.product.bomnew.pojo.entity.OptionalMbomMaterialEntity; import com.nflg.product.bomnew.pojo.vo.OptionalEbomImportChildVO; +import com.nflg.product.bomnew.service.MaterialMainService; +import com.nflg.product.bomnew.service.MaterialService; import com.nflg.product.bomnew.service.OptionalEbomMainService; import com.nflg.product.bomnew.service.OptionalMbomCompareService; import com.nflg.product.bomnew.util.OrderNoUtil; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import nflg.product.common.constant.STATE; import java.util.ArrayList; @@ -30,21 +34,25 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +@Slf4j public class PublisMaterial { - private OptionalEbomPublishAddDTO publishAddDTO; -@Getter - private List materialList ; + private OptionalEbomPublishAddDTO publishAddDTO; + @Getter + private List materialList; -private Long deviceRowId; - public PublisMaterial(OptionalEbomPublishAddDTO dto,Long deviceRowId){ - this.publishAddDTO=dto; + private Long deviceRowId; + + public PublisMaterial(OptionalEbomPublishAddDTO dto, Long deviceRowId) { + this.publishAddDTO = dto; materialList = new ArrayList<>(); - this.deviceRowId=deviceRowId; + this.deviceRowId = deviceRowId; + + } - OptionalMbomMaterialEntity genVirtualPackLevelSend1( List oaList){ + OptionalMbomMaterialEntity genVirtualPackLevelSend1(List oaList) { //21机型发货 OptionalMbomMaterialEntity sendPack = new OptionalMbomMaterialEntity(); String sendMaterialName = publishAddDTO.getGoodsDesc().concat("(发货)"); @@ -61,22 +69,22 @@ private Long deviceRowId; sendPack.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_1.getValue()); - - AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); - String key=String.valueOf(sendPack.getRowId()); + AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO(); + String key = String.valueOf(sendPack.getRowId()); toM.setKey(key); - toM.setMaterialName(sendPack.getMaterialName() ); - toM.setDrawingNo(sendPack.getMaterialName() ); - toM.setMaterialDesc(sendPack.getMaterialName() ); + toM.setMaterialName(sendPack.getMaterialName()); + toM.setDrawingNo(sendPack.getMaterialName()); + toM.setMaterialDesc(sendPack.getMaterialName()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); oaList.add(toM); - return sendPack; + return sendPack; } - OptionalMbomMaterialEntity genVirtualPackLevelMake1(Long parentRowId,List oaList){ + + OptionalMbomMaterialEntity genVirtualPackLevelMake1(Long parentRowId, List oaList) { //21机型制作 OptionalMbomMaterialEntity makePack = new OptionalMbomMaterialEntity(); String makeMaterialName = publishAddDTO.getGoodsDesc().concat("(制作)"); @@ -93,8 +101,8 @@ private Long deviceRowId; makePack.setMaterialNo("");//申请物料号 makePack.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_2.getValue()); - AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); - String key=String.valueOf(makePack.getRowId()) ; + AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO(); + String key = String.valueOf(makePack.getRowId()); toM.setKey(key); toM.setMaterialName(makePack.getMaterialName()); toM.setDrawingNo(makePack.getMaterialName()); @@ -102,20 +110,20 @@ private Long deviceRowId; toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); oaList.add(toM); - return makePack; + return makePack; } /** * 电控制作 */ - void genVirtualPackElectricLevelMake2(Long parentRowId,List oaList){ + OptionalMbomMaterialEntity genVirtualPackElectricLevelMake2(Long parentRowId, List oaList) { OptionalMbomMaterialEntity makePack = new OptionalMbomMaterialEntity(); String makeMaterialName = StrUtil.format("({})", publishAddDTO.getElectricDesc()).concat("(电控系统)").concat("(制作)"); makePack.setRowId(IdWorker.getId()); makePack.setParentRowId(parentRowId); makePack.setCreatedBy(SessionUtil.getUserCode()); - makePack .setRealName(SessionUtil.getRealName()); - makePack .setDeptName(SessionUtil.getDepartName()); + makePack.setRealName(SessionUtil.getRealName()); + makePack.setDeptName(SessionUtil.getDepartName()); makePack.setCreatedTime(DateUtil.now()); makePack.setMaterialName(makeMaterialName); makePack.setMaterialDesc(makeMaterialName); @@ -124,8 +132,8 @@ private Long deviceRowId; makePack.setMaterialNo("");//申请物料号 makePack.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_4.getValue()); - AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); - String key=String.valueOf(makePack.getRowId()) ; + AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO(); + String key = String.valueOf(makePack.getRowId()); toM.setKey(key); toM.setMaterialName(makePack.getMaterialName()); toM.setDrawingNo(makePack.getMaterialName()); @@ -134,20 +142,21 @@ private Long deviceRowId; toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); oaList.add(toM); + return makePack; } /** * 电控发货 */ - void genVirtualPackElectricLevelSend2(Long parentRowId,List oaList){ + OptionalMbomMaterialEntity genVirtualPackElectricLevelSend2(Long parentRowId, List oaList) { OptionalMbomMaterialEntity sendPack = new OptionalMbomMaterialEntity(); - String sendMaterialName = StrUtil.format("({})", publishAddDTO.getElectricDesc()).concat("(电控系统)").concat("(发货)"); + String sendMaterialName = StrUtil.format("({})", publishAddDTO.getElectricDesc()).concat("(电控系统)").concat("(发货)"); sendPack.setRowId(IdWorker.getId()); sendPack.setParentRowId(parentRowId); sendPack.setCreatedBy(SessionUtil.getUserCode()); - sendPack .setRealName(SessionUtil.getRealName()); + sendPack.setRealName(SessionUtil.getRealName()); sendPack.setDeptName(SessionUtil.getDepartName()); sendPack.setCreatedTime(DateUtil.now()); sendPack.setMaterialName(sendMaterialName); @@ -157,8 +166,8 @@ private Long deviceRowId; sendPack.setMaterialNo("");//申请物料号 sendPack.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_3.getValue()); - AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); - String key=String.valueOf(sendPack.getRowId()) ; + AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO(); + String key = String.valueOf(sendPack.getRowId()); toM.setKey(key); toM.setMaterialName(sendPack.getMaterialName()); toM.setDrawingNo(sendPack.getMaterialName()); @@ -167,58 +176,62 @@ private Long deviceRowId; toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); oaList.add(toM); + return sendPack; + } + String optionMaterialGroupConcat(List optionList) { + List materialNoList = optionList.stream().filter(u -> u.getPartType().equals(OptionalBomConstant.PartTypeEnum.PART_TYPE_RADIO.getValue())).map(OptionalEbomImportChildVO::getMaterialNo).map(Long::parseLong).collect(Collectors.toList()); + Collections.sort(materialNoList); + String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(",")); + + return result; + } + OptionalMbomMaterialEntity genVirtualPackMachineLevel2(Long parentRowId, List optionList, List oaList) { + + String result = optionMaterialGroupConcat(optionList); + + String signMd5 = MD5.create().digestHex(result); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5); + OptionalMbomCompareEntity optionalMbomCompareEntity = SpringUtil.getBean(OptionalMbomCompareService.class).getOne(queryWrapper); + OptionalMbomMaterialEntity material; + if (optionalMbomCompareEntity == null) { + material = new OptionalMbomMaterialEntity(); + OptionalEbomMainEntity desc = SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId); + + //物料名称和物料描述=机型+流水号+NF(机械部分) + //图号=机型+流水号+NF + String drawingNo = StrUtil.format("{}-{}", desc.getDeviceNo(), OrderNoUtil.orderNo2Str(desc.getSerialNo())).concat("-NF"); + String materialName = drawingNo.concat("(机械部分)"); + material.setRowId(IdWorker.getId()); + + material.setParentRowId(parentRowId); + material.setRootRowId(publishAddDTO.getRowId()); + material.setCreatedBy(SessionUtil.getUserCode()); + material.setRealName(SessionUtil.getRealName()); + material.setDeptName(SessionUtil.getDepartName()); + material.setCreatedTime(DateUtil.now()); + material.setMaterialName(materialName); + material.setMaterialDesc(materialName); + material.setDrawingNo(drawingNo); + material.setMaterialNo("");//申请物料号 + material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue()); + + AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO(); + String key = String.valueOf(material.getRowId()); + toM.setKey(key); + toM.setMaterialName(material.getMaterialName()); + toM.setDrawingNo(drawingNo); + toM.setMaterialDesc(material.getMaterialName()); + toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory()); + toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.MACHINE.getProjectType()); + oaList.add(toM); - void genVirtualPackMachineLevel2(Long parentRowId , List optionList,List oaList){ -// List materialNoList = optionList.stream().filter(u-> u.getPartType().equals(OptionalBomConstant.PartTypeEnum.PART_TYPE_RADIO.getValue()) ).map(OptionalEbomImportChildVO::getMaterialNo).map(Long::parseLong).collect(Collectors.toList()); -// Collections.sort(materialNoList); -// String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(",")); -// -// String signMd5 = MD5.create().digestHex(result); -// QueryWrapper queryWrapper = new QueryWrapper<>(); -// queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5); -// OptionalMbomCompareEntity optionalMbomCompareEntity= SpringUtil.getBean(OptionalMbomCompareService.class).getOne(queryWrapper); -// OptionalMbomMaterialEntity material; -// if (optionalMbomCompareEntity == null) { -// material = new OptionalMbomMaterialEntity(); -// OptionalEbomMainEntity desc= SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId); -// -// //物料名称和物料描述=机型+流水号+NF(机械部分) -// //图号=机型+流水号+NF -// String drawingNo =StrUtil.format("{}-{}",desc.getDeviceNo(), OrderNoUtil.orderNo2Str(desc.getSerialNo())).concat("-NF"); -// String materialName=drawingNo.concat("(机械部分)"); -// material.setRowId(IdWorker.getId()); -// -// material.setParentRowId(parentRowId); -// material.setRootRowId(publishAddDTO.getRowId()); -// material.setCreatedBy(SessionUtil.getUserCode()); -// material.setRealName(SessionUtil.getRealName()); -// material.setDeptName(SessionUtil.getDepartName()); -// material.setCreatedTime(DateUtil.now()); -// material.setMaterialName(materialName); -// material.setMaterialDesc(materialName); -// material.setDrawingNo(drawingNo); -// material.setMaterialNo("");//申请物料号 -// material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue()); -// -// -// AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); -// String key=String.valueOf(material.getRowId()) ; -// toM.setKey(key); -// toM.setMaterialName(material.getMaterialName()); -// toM.setDrawingNo(drawingNo); -// toM.setMaterialDesc(material.getMaterialName()); -// toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory()); -// toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.MACHINE.getProjectType()); -// oaList.add(toM); -// -// -// // try { // //数据不存在保存 // if (StrUtil.isNotEmpty(material.getMaterialNo())) { @@ -242,40 +255,149 @@ private Long deviceRowId; // } catch (Exception e) { // e.printStackTrace(); // } -// -// -// -// } else { //同物料号 -// material = Convert.convert(new TypeReference() { -// }, optionalMbomCompareEntity); -// material.setRowId(IdWorker.getId()); -// material.setParentRowId(parentRowId); -// material.setRootRowId(publishAddDTO.getRowId()); -// material.setCreatedBy(SessionUtil.getUserCode()); -// material.setRealName(SessionUtil.getRealName()); -// material.setDeptName(SessionUtil.getDepartName()); -// material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue()); -// material.setCreatedTime(DateUtil.now()); -// } -// - - } - - public List buildMaterialList( List optionList ){ + } else { //重用同物料号 + material = Convert.convert(new TypeReference() { + }, optionalMbomCompareEntity); + material.setRowId(IdWorker.getId()); + material.setParentRowId(parentRowId); + material.setRootRowId(publishAddDTO.getRowId()); + material.setCreatedBy(SessionUtil.getUserCode()); + material.setRealName(SessionUtil.getRealName()); + material.setDeptName(SessionUtil.getDepartName()); + material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue()); + material.setCreatedTime(DateUtil.now()); + } - - List oaList=new ArrayList<>(); - - - - return null; + return material; } + void updateSameMaterial(OptionalMbomMaterialEntity material,List optionList) { + + try { + //数据不存在保存 + if (StrUtil.isNotEmpty(material.getMaterialNo())) { + + OptionalEbomMainEntity desc = SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId); + + OptionalMbomCompareEntity optionalMbomCompareEntity = Convert.convert(new TypeReference() { + }, material); + + String result = optionMaterialGroupConcat(optionList); + String signMd5 = MD5.create().digestHex(result); + optionalMbomCompareEntity.setRowId(null); + optionalMbomCompareEntity.setParentRowId(publishAddDTO.getRowId()); + optionalMbomCompareEntity.setSignMd5(signMd5); + optionalMbomCompareEntity.setCreatedTime(DateUtil.now()); + optionalMbomCompareEntity.setChildRowIds(result); + + SpringUtil.getBean(OptionalMbomCompareService.class).save(optionalMbomCompareEntity); + + //更新序列号 + OptionalEbomMainEntity updateDevice = new OptionalEbomMainEntity(); + updateDevice.setRowId(desc.getRowId()); + updateDevice.setSerialNo(desc.getSerialNo() + 1); + SpringUtil.getBean(OptionalEbomMainService.class).updateById(updateDevice); + + } + + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public List buildMaterialList(List optionList) throws NflgBusinessException { + + if (deviceRowId == null || StrUtil.isEmpty(publishAddDTO.getGoodsDesc()) || StrUtil.isEmpty(publishAddDTO.getElectricDesc())) { + throw new NflgBusinessException(STATE.BusinessError, "整机或电控数据不完整"); + } + + + List oaList = new ArrayList<>(); + List materialList=new ArrayList<>(); + + //整机发货 + OptionalMbomMaterialEntity genVirtualPackLevelSend1 = genVirtualPackLevelSend1(oaList); + //整机制作 + OptionalMbomMaterialEntity genVirtualPackLevelMake1 = genVirtualPackLevelMake1(genVirtualPackLevelSend1.getRowId(), oaList); + + + //电控制作 + OptionalMbomMaterialEntity genVirtualPackElectricLevelMake2 = genVirtualPackElectricLevelMake2(genVirtualPackLevelMake1.getRowId(), oaList); + //电控发货 + OptionalMbomMaterialEntity genVirtualPackElectricLevelSend2 = genVirtualPackElectricLevelSend2(genVirtualPackElectricLevelMake2.getRowId(), oaList); + + //机械 + OptionalMbomMaterialEntity genVirtualPackMachineLevel2 = genVirtualPackMachineLevel2(genVirtualPackLevelMake1.getRowId(), optionList, oaList); + + Map mMap = null; + //申请物料 + try { + mMap = SpringUtil.getBean(MaterialService.class).batchAddMaterial(oaList); + if (mMap == null) { + throw new Exception("申请物料编码出现异常"); + } + } catch (Exception e) { + throw new NflgBusinessException(STATE.Error, "操作失败,申请物料编码出现异常"); + } + + log.info("申请物料>>>"+JSON.toJSONString(mMap)); + genVirtualPackLevelSend1.setMaterialNo( mMap.get(String.valueOf(genVirtualPackLevelSend1.getRowId())).getMaterialNo()) ; + if (StrUtil.isEmpty(genVirtualPackLevelSend1.getMaterialNo())){ + throw new NflgBusinessException(STATE.Error, "机型发货物料编码申请失败"); + } + + genVirtualPackLevelMake1.setMaterialNo( mMap.get(String.valueOf(genVirtualPackLevelMake1.getRowId())).getMaterialNo()) ; + if (StrUtil.isEmpty(genVirtualPackLevelMake1.getMaterialNo())){ + throw new NflgBusinessException(STATE.Error, "机型制作物料编码申请失败"); + } + + genVirtualPackElectricLevelMake2.setMaterialNo( mMap.get(String.valueOf(genVirtualPackElectricLevelMake2.getRowId())).getMaterialNo()) ; + if (StrUtil.isEmpty(genVirtualPackElectricLevelMake2.getMaterialNo())){ + throw new NflgBusinessException(STATE.Error, "电控制作物料编码申请失败"); + } + + genVirtualPackElectricLevelSend2.setMaterialNo( mMap.get(String.valueOf(genVirtualPackElectricLevelSend2.getRowId())).getMaterialNo()) ; + if (StrUtil.isEmpty(genVirtualPackElectricLevelSend2.getMaterialNo())){ + throw new NflgBusinessException(STATE.Error, "电控发货物料编码申请失败"); + } + + + if(StrUtil.isEmpty(genVirtualPackMachineLevel2.getMaterialNo())){ + genVirtualPackMachineLevel2.setMaterialNo( mMap.get(String.valueOf(genVirtualPackMachineLevel2.getRowId())).getMaterialNo()) ; + if (StrUtil.isEmpty(genVirtualPackMachineLevel2.getMaterialNo())){ + throw new NflgBusinessException(STATE.Error, "机械部分物料编码申请失败"); + } + updateSameMaterial(genVirtualPackMachineLevel2,optionList); + } + + materialList.add(genVirtualPackLevelSend1); + materialList.add(genVirtualPackLevelMake1); + materialList.add(genVirtualPackElectricLevelMake2); + materialList.add(genVirtualPackElectricLevelSend2); + materialList.add(genVirtualPackMachineLevel2); + List optionConvertList = Convert.toList(OptionalMbomMaterialEntity.class, optionList); + optionConvertList.forEach(item -> { + item.setRowId(null); + item.setCreatedBy(SessionUtil.getUserCode()); + item.setRealName(SessionUtil.getRealName()); + item.setDeptName(SessionUtil.getDepartName()); + item.setCreatedTime(DateUtil.now()); + item.setRootRowId(publishAddDTO.getRowId()); + item.setParentRowId(genVirtualPackMachineLevel2.getRowId()); + item.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_6.getValue()); + materialList.add(item); + }); + + return materialList; + + } }