1、事务问题

This commit is contained in:
大米 2024-06-13 14:52:42 +08:00
parent 4ddd6d1505
commit e76f8bd2e6
1 changed files with 65 additions and 82 deletions

View File

@ -47,7 +47,6 @@ public class PublishMaterialService {
MaterialService materialService; MaterialService materialService;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResultVO<String> publishWork(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) { public ResultVO<String> publishWork(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) {
@ -57,15 +56,15 @@ public class PublishMaterialService {
} }
OptionalEbomConfigEntity configEntity=SpringUtil.getBean(OptionalEbomConfigService.class).getById(optionalEbomPublishAddDTO.getRowId()); OptionalEbomConfigEntity configEntity = SpringUtil.getBean(OptionalEbomConfigService.class).getById(optionalEbomPublishAddDTO.getRowId());
if(configEntity ==null ){ if (configEntity == null) {
return ResultVO.error(StrUtil.format("{} 暂存数据查询到",optionalEbomPublishAddDTO.getRowId())); return ResultVO.error(StrUtil.format("{} 暂存数据查询到", optionalEbomPublishAddDTO.getRowId()));
} }
OptionalEbomMainEntity mainEntity=SpringUtil.getBean(OptionalEbomMainService.class).getById(configEntity.getParentRowId()); OptionalEbomMainEntity mainEntity = SpringUtil.getBean(OptionalEbomMainService.class).getById(configEntity.getParentRowId());
if(mainEntity ==null ){ if (mainEntity == null) {
return ResultVO.error(StrUtil.format("{} 设备数据未查询到",configEntity.getParentRowId())); return ResultVO.error(StrUtil.format("{} 设备数据未查询到", configEntity.getParentRowId()));
} }
//整机物料名称和物料描述=机型+机型名称+机台号+.0 //整机物料名称和物料描述=机型+机型名称+机台号+.0
@ -82,10 +81,7 @@ public class PublishMaterialService {
).concat(".0")); ).concat(".0"));
List<OptionalMbomMaterialEntity> materialList = null;
try {
List<OptionalMbomMaterialEntity> materialList=null ;
//第一层级 机型发货 和制作 //第一层级 机型发货 和制作
// Long parentId = genVirtualPackLevel1(materialList, optionalEbomPublishAddDTO.getRowId(), optionalEbomPublishAddDTO.getGoodsDesc()); // Long parentId = genVirtualPackLevel1(materialList, optionalEbomPublishAddDTO.getRowId(), optionalEbomPublishAddDTO.getGoodsDesc());
//电控部分 //电控部分
@ -94,8 +90,8 @@ public class PublishMaterialService {
// genVirtualPackMachineLevel2(materialList, optionList, optionalEbomPublishAddDTO.getRowId(), parentId,mainEntity.getRowId() ); // genVirtualPackMachineLevel2(materialList, optionList, optionalEbomPublishAddDTO.getRowId(), parentId,mainEntity.getRowId() );
PublisMaterial publisMaterial=new PublisMaterial(optionalEbomPublishAddDTO,mainEntity.getRowId()); PublisMaterial publisMaterial = new PublisMaterial(optionalEbomPublishAddDTO, mainEntity.getRowId());
materialList=publisMaterial.buildMaterialList(optionList); materialList = publisMaterial.buildMaterialList(optionList);
boolean ok = optionalMbomMaterialService.saveBatch(materialList); boolean ok = optionalMbomMaterialService.saveBatch(materialList);
@ -108,17 +104,12 @@ public class PublishMaterialService {
optionalEbomConfigService.updateById(optionalEbomConfigEntity); optionalEbomConfigService.updateById(optionalEbomConfigEntity);
} }
} catch (NflgBusinessException e) {
return ResultVO.error(e.getMsg());
}
return ResultVO.success("发布成功"); return ResultVO.success("发布成功");
} }
@Deprecated @Deprecated
public ResultVO<String> publishWorkOld(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) { public ResultVO<String> publishWorkOld(OptionalEbomPublishAddDTO optionalEbomPublishAddDTO) {
@ -128,15 +119,15 @@ public class PublishMaterialService {
} }
OptionalEbomConfigEntity configEntity=SpringUtil.getBean(OptionalEbomConfigService .class).getById(optionalEbomPublishAddDTO.getRowId()); OptionalEbomConfigEntity configEntity = SpringUtil.getBean(OptionalEbomConfigService.class).getById(optionalEbomPublishAddDTO.getRowId());
if(configEntity ==null ){ if (configEntity == null) {
return ResultVO.error(StrUtil.format("{} 暂存数据查询到",optionalEbomPublishAddDTO.getRowId())); return ResultVO.error(StrUtil.format("{} 暂存数据查询到", optionalEbomPublishAddDTO.getRowId()));
} }
OptionalEbomMainEntity mainEntity=SpringUtil.getBean(OptionalEbomMainService.class).getById(configEntity.getParentRowId()); OptionalEbomMainEntity mainEntity = SpringUtil.getBean(OptionalEbomMainService.class).getById(configEntity.getParentRowId());
if(mainEntity ==null ){ if (mainEntity == null) {
return ResultVO.error(StrUtil.format("{} 设备数据未查询到",configEntity.getParentRowId())); return ResultVO.error(StrUtil.format("{} 设备数据未查询到", configEntity.getParentRowId()));
} }
//整机物料名称和物料描述=机型+机型名称+机台号+.0 //整机物料名称和物料描述=机型+机型名称+机台号+.0
@ -162,7 +153,7 @@ public class PublishMaterialService {
//电控部分 //电控部分
genVirtualPackElectricLevel2(materialList, optionalEbomPublishAddDTO.getRowId(), parentId, optionalEbomPublishAddDTO.getElectricDesc()); genVirtualPackElectricLevel2(materialList, optionalEbomPublishAddDTO.getRowId(), parentId, optionalEbomPublishAddDTO.getElectricDesc());
//机械部分申请 //机械部分申请
genVirtualPackMachineLevel2(materialList, optionList, optionalEbomPublishAddDTO.getRowId(), parentId,mainEntity.getRowId() ); genVirtualPackMachineLevel2(materialList, optionList, optionalEbomPublishAddDTO.getRowId(), parentId, mainEntity.getRowId());
boolean ok = optionalMbomMaterialService.saveBatch(materialList); boolean ok = optionalMbomMaterialService.saveBatch(materialList);
@ -217,16 +208,16 @@ public class PublishMaterialService {
// String data = materialService.addMaterial("", sendPack.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); // String data = materialService.addMaterial("", sendPack.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
// //
// sendPack.setMaterialNo(data); // sendPack.setMaterialNo(data);
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
String key=String.valueOf(IdWorker.getId()) ; String key = String.valueOf(IdWorker.getId());
toM.setKey(key); toM.setKey(key);
toM.setMaterialName(sendPack.getMaterialName() ); toM.setMaterialName(sendPack.getMaterialName());
toM.setDrawingNo(sendPack.getMaterialName() ); toM.setDrawingNo(sendPack.getMaterialName());
toM.setMaterialDesc(sendPack.getMaterialName() ); toM.setMaterialDesc(sendPack.getMaterialName());
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM)); Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
String materialNo=mMap.get(key).getMaterialNo(); String materialNo = mMap.get(key).getMaterialNo();
sendPack.setMaterialNo(materialNo); sendPack.setMaterialNo(materialNo);
} catch (Exception e) { } catch (Exception e) {
@ -259,10 +250,8 @@ public class PublishMaterialService {
// makePack.setMaterialNo(data); // makePack.setMaterialNo(data);
AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
String key = String.valueOf(IdWorker.getId());
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO();
String key=String.valueOf(IdWorker.getId()) ;
toM.setKey(key); toM.setKey(key);
toM.setMaterialName(makePack.getMaterialName()); toM.setMaterialName(makePack.getMaterialName());
toM.setDrawingNo(makePack.getMaterialName()); toM.setDrawingNo(makePack.getMaterialName());
@ -270,11 +259,10 @@ public class PublishMaterialService {
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM)); Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
String materialNo=mMap.get(key).getMaterialNo(); String materialNo = mMap.get(key).getMaterialNo();
makePack.setMaterialNo(materialNo); makePack.setMaterialNo(materialNo);
} catch (Exception e) { } catch (Exception e) {
throw new NflgBusinessException(STATE.Error, "机型制作," + e.getMessage()); throw new NflgBusinessException(STATE.Error, "机型制作," + e.getMessage());
} }
@ -284,7 +272,7 @@ public class PublishMaterialService {
throw new NflgBusinessException(STATE.Error, "机型制作物料编码申请失败"); throw new NflgBusinessException(STATE.Error, "机型制作物料编码申请失败");
} }
if ( materialList!=null) { if (materialList != null) {
materialList.add(sendPack); materialList.add(sendPack);
materialList.add(makePack); materialList.add(makePack);
} }
@ -306,35 +294,34 @@ public class PublishMaterialService {
* @param materialList * @param materialList
* @param rootRowId * @param rootRowId
* @param parentId * @param parentId
* @return * @return
*/ */
private void genVirtualPackMachineLevel2(List<OptionalMbomMaterialEntity> materialList, List<OptionalEbomImportChildVO> optionList, Long rootRowId, Long parentId,Long deviceRowId) throws NflgBusinessException { private void genVirtualPackMachineLevel2(List<OptionalMbomMaterialEntity> materialList, List<OptionalEbomImportChildVO> optionList, Long rootRowId, Long parentId, Long deviceRowId) throws NflgBusinessException {
List<Long> materialNoList = optionList.stream().filter(u-> u.getPartType().equals(OptionalBomConstant.PartTypeEnum.PART_TYPE_RADIO.getValue()) ).map(OptionalEbomImportChildVO::getMaterialNo).map(Long::parseLong).collect(Collectors.toList()); List<Long> 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); Collections.sort(materialNoList);
String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(",")); String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(","));
String signMd5 = MD5.create().digestHex(result); String signMd5 = MD5.create().digestHex(result);
QueryWrapper<OptionalMbomCompareEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<OptionalMbomCompareEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5); queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5);
OptionalMbomCompareEntity optionalMbomCompareEntity= optionalMbomCompareService.getOne(queryWrapper); OptionalMbomCompareEntity optionalMbomCompareEntity = optionalMbomCompareService.getOne(queryWrapper);
OptionalMbomMaterialEntity material; OptionalMbomMaterialEntity material;
if (optionalMbomCompareEntity == null) { if (optionalMbomCompareEntity == null) {
material = new OptionalMbomMaterialEntity(); material = new OptionalMbomMaterialEntity();
OptionalEbomMainEntity desc= SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId); OptionalEbomMainEntity desc = SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId);
//物料名称和物料描述=机型+流水号+NF(机械部分) //物料名称和物料描述=机型+流水号+NF(机械部分)
//图号=机型+流水号+NF //图号=机型+流水号+NF
String drawingNo =StrUtil.format("{}-{}",desc.getDeviceNo(), OrderNoUtil.orderNo2Str(desc.getSerialNo())).concat("-NF"); String drawingNo = StrUtil.format("{}-{}", desc.getDeviceNo(), OrderNoUtil.orderNo2Str(desc.getSerialNo())).concat("-NF");
String materialName=drawingNo.concat("(机械部分)"); String materialName = drawingNo.concat("(机械部分)");
material.setRowId(IdWorker.getId()); material.setRowId(IdWorker.getId());
material.setParentRowId(parentId); material.setParentRowId(parentId);
material.setRootRowId(rootRowId); material.setRootRowId(rootRowId);
material.setCreatedBy(SessionUtil.getUserCode()); material.setCreatedBy(SessionUtil.getUserCode());
material.setRealName(SessionUtil.getRealName()); material.setRealName(SessionUtil.getRealName());
material .setDeptName(SessionUtil.getDepartName()); material.setDeptName(SessionUtil.getDepartName());
material.setCreatedTime(DateUtil.now()); material.setCreatedTime(DateUtil.now());
material.setMaterialName(materialName); material.setMaterialName(materialName);
material.setMaterialDesc(materialName); material.setMaterialDesc(materialName);
@ -343,8 +330,8 @@ public class PublishMaterialService {
material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue()); material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue());
try { try {
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
String key=String.valueOf(IdWorker.getId()) ; String key = String.valueOf(IdWorker.getId());
toM.setKey(key); toM.setKey(key);
toM.setMaterialName(material.getMaterialName()); toM.setMaterialName(material.getMaterialName());
toM.setDrawingNo(drawingNo); toM.setDrawingNo(drawingNo);
@ -352,7 +339,7 @@ public class PublishMaterialService {
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory());
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.MACHINE.getProjectType()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.MACHINE.getProjectType());
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM)); Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
String materialNo=mMap.get(key).getMaterialNo(); String materialNo = mMap.get(key).getMaterialNo();
material.setMaterialNo(materialNo); material.setMaterialNo(materialNo);
// String data = materialService.addMaterial(material.getDrawingNo(), material.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory()); // String data = materialService.addMaterial(material.getDrawingNo(), material.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory());
@ -374,9 +361,9 @@ public class PublishMaterialService {
optionalMbomCompareService.save(optionalMbomCompareEntity); optionalMbomCompareService.save(optionalMbomCompareEntity);
//更新序列号 //更新序列号
OptionalEbomMainEntity updateDevice=new OptionalEbomMainEntity(); OptionalEbomMainEntity updateDevice = new OptionalEbomMainEntity();
updateDevice.setRowId(desc.getRowId()); updateDevice.setRowId(desc.getRowId());
updateDevice.setSerialNo(desc.getSerialNo()+1); updateDevice.setSerialNo(desc.getSerialNo() + 1);
SpringUtil.getBean(OptionalEbomMainService.class).updateById(updateDevice); SpringUtil.getBean(OptionalEbomMainService.class).updateById(updateDevice);
} }
@ -387,7 +374,6 @@ public class PublishMaterialService {
} }
} else { //同物料号 } else { //同物料号
material = Convert.convert(new TypeReference<OptionalMbomMaterialEntity>() { material = Convert.convert(new TypeReference<OptionalMbomMaterialEntity>() {
}, optionalMbomCompareEntity); }, optionalMbomCompareEntity);
@ -448,8 +434,8 @@ public class PublishMaterialService {
makePack.setRowId(IdWorker.getId()); makePack.setRowId(IdWorker.getId());
makePack.setParentRowId(parentId); makePack.setParentRowId(parentId);
makePack.setCreatedBy(SessionUtil.getUserCode()); makePack.setCreatedBy(SessionUtil.getUserCode());
makePack .setRealName(SessionUtil.getRealName()); makePack.setRealName(SessionUtil.getRealName());
makePack .setDeptName(SessionUtil.getDepartName()); makePack.setDeptName(SessionUtil.getDepartName());
makePack.setCreatedTime(DateUtil.now()); makePack.setCreatedTime(DateUtil.now());
makePack.setMaterialName(makeMaterialName); makePack.setMaterialName(makeMaterialName);
makePack.setMaterialDesc(makeMaterialName); makePack.setMaterialDesc(makeMaterialName);
@ -464,10 +450,8 @@ public class PublishMaterialService {
// makePack.setMaterialNo(data); // makePack.setMaterialNo(data);
AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
String key = String.valueOf(IdWorker.getId());
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO();
String key=String.valueOf(IdWorker.getId()) ;
toM.setKey(key); toM.setKey(key);
toM.setMaterialName(makePack.getMaterialName()); toM.setMaterialName(makePack.getMaterialName());
toM.setDrawingNo(makePack.getMaterialName()); toM.setDrawingNo(makePack.getMaterialName());
@ -475,7 +459,7 @@ public class PublishMaterialService {
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM)); Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
String materialNo=mMap.get(key).getMaterialNo(); String materialNo = mMap.get(key).getMaterialNo();
makePack.setMaterialNo(materialNo); makePack.setMaterialNo(materialNo);
@ -494,7 +478,7 @@ public class PublishMaterialService {
sendPack.setRowId(IdWorker.getId()); sendPack.setRowId(IdWorker.getId());
sendPack.setParentRowId(makePack.getRowId()); sendPack.setParentRowId(makePack.getRowId());
sendPack.setCreatedBy(SessionUtil.getUserCode()); sendPack.setCreatedBy(SessionUtil.getUserCode());
sendPack .setRealName(SessionUtil.getRealName()); sendPack.setRealName(SessionUtil.getRealName());
sendPack.setDeptName(SessionUtil.getDepartName()); sendPack.setDeptName(SessionUtil.getDepartName());
sendPack.setCreatedTime(DateUtil.now()); sendPack.setCreatedTime(DateUtil.now());
sendPack.setMaterialName(sendMaterialName); sendPack.setMaterialName(sendMaterialName);
@ -509,9 +493,8 @@ public class PublishMaterialService {
// sendPack.setMaterialNo(data); // sendPack.setMaterialNo(data);
AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO(); String key = String.valueOf(IdWorker.getId());
String key=String.valueOf(IdWorker.getId()) ;
toM.setKey(key); toM.setKey(key);
toM.setMaterialName(sendPack.getMaterialName()); toM.setMaterialName(sendPack.getMaterialName());
toM.setDrawingNo(sendPack.getMaterialName()); toM.setDrawingNo(sendPack.getMaterialName());
@ -519,18 +502,18 @@ public class PublishMaterialService {
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory()); toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType()); toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM)); Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
String materialNo=mMap.get(key).getMaterialNo(); String materialNo = mMap.get(key).getMaterialNo();
sendPack.setMaterialNo(materialNo); sendPack.setMaterialNo(materialNo);
} catch (Exception e) { } catch (Exception e) {
throw new NflgBusinessException(STATE.Error, "电控发货,"+e.getMessage()); throw new NflgBusinessException(STATE.Error, "电控发货," + e.getMessage());
} }
if (StrUtil.isEmpty(sendPack.getMaterialNo())) { if (StrUtil.isEmpty(sendPack.getMaterialNo())) {
throw new NflgBusinessException(STATE.Error, "电控发货物料编码申请失败"); throw new NflgBusinessException(STATE.Error, "电控发货物料编码申请失败");
} }
if(materialList!=null){ if (materialList != null) {
materialList.add(makePack); materialList.add(makePack);
materialList.add(sendPack); materialList.add(sendPack);
} }