From 0cbbe2c1cbfbf73e02e1796d921c2911c96d370b Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 23 十二月 2024 11:46:31 +0800 Subject: [PATCH] Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java | 152 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 120 insertions(+), 32 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java index 4a44fde..0bd305c 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java @@ -1,6 +1,8 @@ package com.iailab.module.model.mcs.pre.service.impl; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.util.object.BeanUtils; @@ -10,10 +12,12 @@ import com.iailab.module.model.mcs.pre.enums.ItemIncreaseCodeEnum; import com.iailab.module.model.mcs.pre.enums.ItemTypeEnum; import com.iailab.module.model.mcs.pre.service.MmPredictItemService; -import com.iailab.module.model.mcs.pre.service.SequenceNumService; +import com.iailab.module.model.mcs.pre.service.MmSequenceNumService; import com.iailab.module.model.mcs.pre.vo.MmPredictItemPageReqVO; +import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; import com.iailab.module.model.mdk.vo.ItemVO; import com.iailab.module.model.mdk.vo.MergeItemVO; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -50,31 +54,31 @@ private MmItemTypeImpl mmItemTypeImpl; @Autowired - private SequenceNumService sequenceNumService; + private MmSequenceNumService sequenceNumService; @Autowired private MmPredictItemDao mmPredictItemDao; - @Override - public PageResult<MmPredictItemEntity> queryPage(MmPredictItemPageReqVO reqVO) { - return mmPredictItemDao.selectPage(reqVO); - } - -// @Override -// public void add(MmPredictItemEntity mmPredictItemEntity) { -// mmPredictItemDao.insert(mmPredictItemEntity); -// } - -// @Override -// public void update(MmPredictItemEntity mmPredictItemEntity) { -// mmPredictItemDao.updateById(mmPredictItemEntity); -// } + private static HashMap<String, ItemVO> itemVOHashMap = new HashMap<>(); @Override - public List<MmPredictItemEntity> list(Map<String, Object> params) { - return Collections.emptyList(); + public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) { + IPage<MmPredictItemRespVO> page = mmPredictItemDao.selectPage(reqVO); + + return new PageResult<>(page.getRecords(), page.getTotal()); } + @Override + public List<MmPredictItemRespVO> list(Map<String, Object> params) { + return mmPredictItemDao.queryList(params); + } + + @Override + public MmPredictItemEntity getById(String id) { + return mmPredictItemDao.selectById(id); + } + + @DSTransactional(rollbackFor = Exception.class) @Override public void add(MmPredictItemDTO mmPredictItemDto) { MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); @@ -84,12 +88,12 @@ MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { - SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); + MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString()); String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); predictItem.setItemno(sequenceNumEntity.getPrefix() + str); MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel(); - SequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); + MmSequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString()); String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum()); mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr); mmPredictModel.setItemid(predictItem.getId()); @@ -107,24 +111,39 @@ }); mmModelParamService.saveList(mmModelParamList); } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { - SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); + MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString()); String str = String.format("%010d", sequenceNumEntity.getSequenceNum()); predictItem.setItemno(sequenceNumEntity.getPrefix() + str); MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); mMmPredictMergeItem.setItemid(predictItem.getId()); mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem); + // 添加一条默认output + List<MmItemOutputEntity> mergeItemOutput = new ArrayList<>(1); + MmItemOutputEntity entity = new MmItemOutputEntity(); + entity.setPointid(mmPredictItemDto.getPointId()); + entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); + entity.setResultstr("result"); + mergeItemOutput.add(entity); + mmPredictItemDto.setMmItemOutputList(mergeItemOutput); } mmPredictItemDao.insert(predictItem); DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); dmModuleItem.setItemid(predictItem.getId()); dmModuleItemService.saveModuleItem(dmModuleItem); - MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); - mmItemOutput.setItemid(predictItem.getId()); + List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); + mmItemOutput.forEach(e -> { + e.setId(UUID.randomUUID().toString()); + e.setItemid(predictItem.getId()); + }); mmItemOutputService.saveMmItemOutput(mmItemOutput); + + // 清空缓存 + clearCatch(); } + @DSTransactional(rollbackFor = Exception.class) @Override public void update(MmPredictItemDTO mmPredictItemDto) { MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem(); @@ -149,23 +168,52 @@ } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem(); mmPredictMergeItemService.update(mMmPredictMergeItem); + // 修改默认output + List<MmItemOutputEntity> mmItemOutputList = mmPredictItemDto.getMmItemOutputList(); + if (CollectionUtils.isEmpty(mmItemOutputList)) { + mmItemOutputList = new ArrayList<>(1); + MmItemOutputEntity entity = new MmItemOutputEntity(); + entity.setPointid(mmPredictItemDto.getPointId()); + entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname()); + entity.setResultstr("result"); + mmItemOutputList.add(entity); + mmPredictItemDto.setMmItemOutputList(mmItemOutputList); + } else { + mmPredictItemDto.getMmItemOutputList().forEach(e -> e.setPointid(mmPredictItemDto.getPointId())); + } } DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem(); - if(!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null){ + if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) { dmModuleItemService.update(dmModuleItem); } - MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput(); - if(!"".equals(mmItemOutput.getId()) && dmModuleItem.getId() != null){ - mmItemOutputService.update(mmItemOutput); + mmItemOutputService.deleteByItemId(predictItem.getId()); + List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList(); + if (!CollectionUtils.isEmpty(mmItemOutput)) { + mmItemOutput.forEach(e -> { + // 尽量保存原有id + if (StringUtils.isBlank(e.getId())) { + e.setId(UUID.randomUUID().toString()); + } + e.setItemid(predictItem.getId()); + }); + mmItemOutputService.saveMmItemOutput(mmItemOutput); } + + + // 清空缓存 + clearCatch(); } + @DSTransactional(rollbackFor = Exception.class) @Override public void deleteBatch(String[] itemIds) { mmPredictItemDao.deleteBatchIds(Arrays.asList(itemIds)); mmPredictMergeItemService.deleteBatch(itemIds); mmPredictModelService.deleteBatch(itemIds); mmItemOutputService.deleteBatch(itemIds); + + // 清空缓存 + clearCatch(); } @Override @@ -174,15 +222,23 @@ MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class); mmPredictItemDto.setMmPredictItem(predictItem); mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id)); - mmPredictItemDto.setMmItemOutput(mmItemOutputService.getByItemid(id)); + mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id)); MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid()); if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); mmPredictItemDto.setMmPredictModel(mmPredictModel); - mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId())); + mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelId(mmPredictModel.getId())); mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); + mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { + mmPredictItemDto.setMmPredictModel(new MmPredictModelEntity()); + mmPredictItemDto.setMmModelArithSettingsList(new ArrayList<>()); + mmPredictItemDto.setMmModelParamList(new ArrayList<>()); + mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id)); + if (!CollectionUtils.isEmpty(mmPredictItemDto.getMmItemOutputList())) { + mmPredictItemDto.setPointId(mmPredictItemDto.getMmItemOutputList().get(0).getPointid()); + } } return mmPredictItemDto; } @@ -202,7 +258,7 @@ @Override public List<ItemVO> getByModuleId(String moduleId) { Map<String, Object> params = new HashMap<>(); - + params.put("MODULEID",moduleId); return mmPredictItemDao.getByModuleId(params); } @@ -221,11 +277,30 @@ } @Override - public ItemVO getItemById(String itemId) { + public void clearCatch() { + itemVOHashMap.clear(); + } + + @Override + public ItemVO getItemByIdFromCache(String itemId) { if (StringUtils.isBlank(itemId)) { return null; } - Map<String, Object> params = new HashMap(1); + if (!itemVOHashMap.containsKey(itemId)) { + Map<String, Object> params = new HashMap<>(1); + params.put("ITEMID", itemId); + List<ItemVO> list = mmPredictItemDao.getItem(params); + if (CollectionUtils.isEmpty(list)) { + return null; + } + itemVOHashMap.put(itemId, list.get(0)); + } + return itemVOHashMap.get(itemId); + } + + @Override + public ItemVO getItemById(String itemId) { + Map<String, Object> params = new HashMap<>(1); params.put("ITEMID", itemId); List<ItemVO> list = mmPredictItemDao.getItem(params); if (CollectionUtils.isEmpty(list)) { @@ -235,6 +310,19 @@ } @Override + public ItemVO getItemByOutPutId(String outPutId) { + if (StringUtils.isBlank(outPutId)) { + return null; + } + MmItemOutputEntity outPutById = mmItemOutputService.getOutPutById(outPutId); + if (ObjectUtils.isEmpty(outPutById)) { + return null; + } + String itemId = outPutById.getItemid(); + return getItemByIdFromCache(itemId); + } + + @Override public MergeItemVO getMergeItemByItemId(String itemId) { if (StringUtils.isBlank(itemId)) { return null; -- Gitblit v1.9.3