1、事务问题
This commit is contained in:
parent
4ddd6d1505
commit
e76f8bd2e6
|
|
@ -47,7 +47,6 @@ public class PublishMaterialService {
|
|||
MaterialService materialService;
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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 ){
|
||||
return ResultVO.error(StrUtil.format("{} 暂存数据查询到",optionalEbomPublishAddDTO.getRowId()));
|
||||
if (configEntity == null) {
|
||||
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 ){
|
||||
return ResultVO.error(StrUtil.format("{} 设备数据未查询到",configEntity.getParentRowId()));
|
||||
if (mainEntity == null) {
|
||||
return ResultVO.error(StrUtil.format("{} 设备数据未查询到", configEntity.getParentRowId()));
|
||||
}
|
||||
|
||||
//整机物料名称和物料描述=机型+机型名称+机台号+.0
|
||||
|
|
@ -73,7 +72,7 @@ public class PublishMaterialService {
|
|||
mainEntity.getDeviceNo(),
|
||||
mainEntity.getDeviceName(),
|
||||
optionalEbomPublishAddDTO.getMachineNo()
|
||||
).concat(".0"));
|
||||
).concat(".0"));
|
||||
|
||||
//电控发货物料生成规则: 规则:物料名称和物料描述=(机型+机台号+.0)
|
||||
optionalEbomPublishAddDTO.setElectricDesc(StrUtil.format("{}{}",
|
||||
|
|
@ -82,43 +81,35 @@ public class PublishMaterialService {
|
|||
).concat(".0"));
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
List<OptionalMbomMaterialEntity> 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() );
|
||||
List<OptionalMbomMaterialEntity> 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);
|
||||
PublisMaterial publisMaterial = new PublisMaterial(optionalEbomPublishAddDTO, mainEntity.getRowId());
|
||||
materialList = publisMaterial.buildMaterialList(optionList);
|
||||
|
||||
boolean ok = optionalMbomMaterialService.saveBatch(materialList);
|
||||
boolean ok = optionalMbomMaterialService.saveBatch(materialList);
|
||||
|
||||
if (ok) {
|
||||
//物料数据保存更改状态
|
||||
OptionalEbomConfigEntity optionalEbomConfigEntity = new OptionalEbomConfigEntity();
|
||||
optionalEbomConfigEntity.setRowId(optionalEbomPublishAddDTO.getRowId());
|
||||
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());
|
||||
optionalEbomConfigEntity.setEditStatus(OptionalBomConstant.PublishEnum.PUBLISH.getValue());
|
||||
optionalEbomConfigService.updateById(optionalEbomConfigEntity);
|
||||
}
|
||||
|
||||
|
||||
return ResultVO.success("发布成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
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 ){
|
||||
return ResultVO.error(StrUtil.format("{} 暂存数据查询到",optionalEbomPublishAddDTO.getRowId()));
|
||||
if (configEntity == null) {
|
||||
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 ){
|
||||
return ResultVO.error(StrUtil.format("{} 设备数据未查询到",configEntity.getParentRowId()));
|
||||
if (mainEntity == null) {
|
||||
return ResultVO.error(StrUtil.format("{} 设备数据未查询到", configEntity.getParentRowId()));
|
||||
}
|
||||
|
||||
//整机物料名称和物料描述=机型+机型名称+机台号+.0
|
||||
|
|
@ -162,7 +153,7 @@ public class PublishMaterialService {
|
|||
//电控部分
|
||||
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);
|
||||
|
||||
|
|
@ -217,16 +208,16 @@ public class PublishMaterialService {
|
|||
// String data = materialService.addMaterial("", sendPack.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
|
||||
//
|
||||
// sendPack.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.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());
|
||||
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
|
||||
String materialNo=mMap.get(key).getMaterialNo();
|
||||
String materialNo = mMap.get(key).getMaterialNo();
|
||||
sendPack.setMaterialNo(materialNo);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
@ -259,10 +250,8 @@ public class PublishMaterialService {
|
|||
// 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.setMaterialName(makePack.getMaterialName());
|
||||
toM.setDrawingNo(makePack.getMaterialName());
|
||||
|
|
@ -270,11 +259,10 @@ public class PublishMaterialService {
|
|||
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
|
||||
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
|
||||
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
|
||||
String materialNo=mMap.get(key).getMaterialNo();
|
||||
String materialNo = mMap.get(key).getMaterialNo();
|
||||
makePack.setMaterialNo(materialNo);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new NflgBusinessException(STATE.Error, "机型制作," + e.getMessage());
|
||||
}
|
||||
|
|
@ -284,7 +272,7 @@ public class PublishMaterialService {
|
|||
throw new NflgBusinessException(STATE.Error, "机型制作物料编码申请失败");
|
||||
}
|
||||
|
||||
if ( materialList!=null) {
|
||||
if (materialList != null) {
|
||||
materialList.add(sendPack);
|
||||
materialList.add(makePack);
|
||||
}
|
||||
|
|
@ -306,35 +294,34 @@ public class PublishMaterialService {
|
|||
* @param materialList
|
||||
* @param rootRowId
|
||||
* @param parentId
|
||||
|
||||
* @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);
|
||||
String result = materialNoList.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||
|
||||
String signMd5 = MD5.create().digestHex(result);
|
||||
QueryWrapper<OptionalMbomCompareEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(OptionalMbomCompareEntity::getSignMd5, signMd5);
|
||||
OptionalMbomCompareEntity optionalMbomCompareEntity= optionalMbomCompareService.getOne(queryWrapper);
|
||||
OptionalMbomCompareEntity optionalMbomCompareEntity = optionalMbomCompareService.getOne(queryWrapper);
|
||||
OptionalMbomMaterialEntity material;
|
||||
if (optionalMbomCompareEntity == null) {
|
||||
material = new OptionalMbomMaterialEntity();
|
||||
OptionalEbomMainEntity desc= SpringUtil.getBean(OptionalEbomMainService.class).getById(deviceRowId);
|
||||
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("(机械部分)");
|
||||
String drawingNo = StrUtil.format("{}-{}", desc.getDeviceNo(), OrderNoUtil.orderNo2Str(desc.getSerialNo())).concat("-NF");
|
||||
String materialName = drawingNo.concat("(机械部分)");
|
||||
material.setRowId(IdWorker.getId());
|
||||
|
||||
material.setParentRowId(parentId);
|
||||
material.setRootRowId(rootRowId);
|
||||
material.setCreatedBy(SessionUtil.getUserCode());
|
||||
material.setRealName(SessionUtil.getRealName());
|
||||
material .setDeptName(SessionUtil.getDepartName());
|
||||
material.setDeptName(SessionUtil.getDepartName());
|
||||
material.setCreatedTime(DateUtil.now());
|
||||
material.setMaterialName(materialName);
|
||||
material.setMaterialDesc(materialName);
|
||||
|
|
@ -343,8 +330,8 @@ public class PublishMaterialService {
|
|||
material.setCategoryType(OptionalBomConstant.CategoryTypeEnum.TYPE_5.getValue());
|
||||
try {
|
||||
|
||||
AddVirtrualMaterialDTO toM =new AddVirtrualMaterialDTO();
|
||||
String key=String.valueOf(IdWorker.getId()) ;
|
||||
AddVirtrualMaterialDTO toM = new AddVirtrualMaterialDTO();
|
||||
String key = String.valueOf(IdWorker.getId());
|
||||
toM.setKey(key);
|
||||
toM.setMaterialName(material.getMaterialName());
|
||||
toM.setDrawingNo(drawingNo);
|
||||
|
|
@ -352,7 +339,7 @@ public class PublishMaterialService {
|
|||
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory());
|
||||
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.MACHINE.getProjectType());
|
||||
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
|
||||
String materialNo=mMap.get(key).getMaterialNo();
|
||||
String materialNo = mMap.get(key).getMaterialNo();
|
||||
material.setMaterialNo(materialNo);
|
||||
|
||||
// String data = materialService.addMaterial(material.getDrawingNo(), material.getMaterialName(), OptionalBomConstant.PublishMaterialEnum.MACHINE.getCategory());
|
||||
|
|
@ -374,9 +361,9 @@ public class PublishMaterialService {
|
|||
optionalMbomCompareService.save(optionalMbomCompareEntity);
|
||||
|
||||
//更新序列号
|
||||
OptionalEbomMainEntity updateDevice=new OptionalEbomMainEntity();
|
||||
OptionalEbomMainEntity updateDevice = new OptionalEbomMainEntity();
|
||||
updateDevice.setRowId(desc.getRowId());
|
||||
updateDevice.setSerialNo(desc.getSerialNo()+1);
|
||||
updateDevice.setSerialNo(desc.getSerialNo() + 1);
|
||||
SpringUtil.getBean(OptionalEbomMainService.class).updateById(updateDevice);
|
||||
|
||||
}
|
||||
|
|
@ -387,7 +374,6 @@ public class PublishMaterialService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
} else { //同物料号
|
||||
material = Convert.convert(new TypeReference<OptionalMbomMaterialEntity>() {
|
||||
}, optionalMbomCompareEntity);
|
||||
|
|
@ -406,7 +392,7 @@ public class PublishMaterialService {
|
|||
}
|
||||
|
||||
|
||||
materialList.add(material);
|
||||
materialList.add(material);
|
||||
List<OptionalMbomMaterialEntity> optionConvertList = Convert.toList(OptionalMbomMaterialEntity.class, optionList);
|
||||
optionConvertList.forEach(item -> {
|
||||
item.setRowId(null);
|
||||
|
|
@ -448,8 +434,8 @@ public class PublishMaterialService {
|
|||
makePack.setRowId(IdWorker.getId());
|
||||
makePack.setParentRowId(parentId);
|
||||
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);
|
||||
|
|
@ -464,10 +450,8 @@ public class PublishMaterialService {
|
|||
// 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.setMaterialName(makePack.getMaterialName());
|
||||
toM.setDrawingNo(makePack.getMaterialName());
|
||||
|
|
@ -475,7 +459,7 @@ public class PublishMaterialService {
|
|||
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
|
||||
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
|
||||
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
|
||||
String materialNo=mMap.get(key).getMaterialNo();
|
||||
String materialNo = mMap.get(key).getMaterialNo();
|
||||
makePack.setMaterialNo(materialNo);
|
||||
|
||||
|
||||
|
|
@ -494,7 +478,7 @@ public class PublishMaterialService {
|
|||
sendPack.setRowId(IdWorker.getId());
|
||||
sendPack.setParentRowId(makePack.getRowId());
|
||||
sendPack.setCreatedBy(SessionUtil.getUserCode());
|
||||
sendPack .setRealName(SessionUtil.getRealName());
|
||||
sendPack.setRealName(SessionUtil.getRealName());
|
||||
sendPack.setDeptName(SessionUtil.getDepartName());
|
||||
sendPack.setCreatedTime(DateUtil.now());
|
||||
sendPack.setMaterialName(sendMaterialName);
|
||||
|
|
@ -509,9 +493,8 @@ public class PublishMaterialService {
|
|||
// sendPack.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.setMaterialName(sendPack.getMaterialName());
|
||||
toM.setDrawingNo(sendPack.getMaterialName());
|
||||
|
|
@ -519,18 +502,18 @@ public class PublishMaterialService {
|
|||
toM.setMaterialCategoryCode(OptionalBomConstant.PublishMaterialEnum.OTHER.getCategory());
|
||||
toM.setProjectType(OptionalBomConstant.PublishMaterialEnum.OTHER.getProjectType());
|
||||
Map<String, AddVirtrualMaterialDTO> mMap = materialService.batchAddMaterial(ImmutableList.of(toM));
|
||||
String materialNo=mMap.get(key).getMaterialNo();
|
||||
String materialNo = mMap.get(key).getMaterialNo();
|
||||
sendPack.setMaterialNo(materialNo);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new NflgBusinessException(STATE.Error, "电控发货,"+e.getMessage());
|
||||
throw new NflgBusinessException(STATE.Error, "电控发货," + e.getMessage());
|
||||
}
|
||||
|
||||
if (StrUtil.isEmpty(sendPack.getMaterialNo())) {
|
||||
throw new NflgBusinessException(STATE.Error, "电控发货物料编码申请失败");
|
||||
}
|
||||
if(materialList!=null){
|
||||
if (materialList != null) {
|
||||
materialList.add(makePack);
|
||||
materialList.add(sendPack);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue