From f1fe397df175a7ee809ea28530419116af84af28 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期二, 31 十二月 2024 17:32:45 +0800 Subject: [PATCH] t_mm_item_result 索引优化 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java | 78 ++++++++++++++++++++++++++------------ 1 files changed, 53 insertions(+), 25 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java index 059ae27..0e3bdc7 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java @@ -6,14 +6,14 @@ import com.iailab.module.model.mcs.pre.dto.MmItemOutputDTO; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.MmItemOutputService; -import com.iailab.module.model.mdk.vo.MmItemOutputVO; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Map; -import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; /** * @author PanZhibao @@ -24,33 +24,70 @@ @Autowired private MmItemOutputDao mmItemOutputDao; + + private static Map<String, MmItemOutputEntity> outputMap = new ConcurrentHashMap<>(); + + private static Map<String, List<MmItemOutputEntity>> itemMap = new ConcurrentHashMap<>(); @Override - public void saveMmItemOutput(MmItemOutputEntity mmItemOutput) { - mmItemOutput.setId(UUID.randomUUID().toString()); + public void saveMmItemOutput(List<MmItemOutputEntity> mmItemOutput) { + mmItemOutput.forEach(e -> { + e.setId(e.getId().replace("+","").replace("-","")); + }); mmItemOutputDao.insert(mmItemOutput); + // 清空缓存 + clearCache(); } @Override public void update(MmItemOutputEntity mmItemOutput) { mmItemOutputDao.updateById(mmItemOutput); + // 清空缓存 + clearCache(); } public void deleteBatch(String[] itemIds) { - QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper(); + QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.in("itemid", itemIds); mmItemOutputDao.delete(queryWrapper); + // 清空缓存 + clearCache(); + } + + private void clearCache() { + outputMap.clear(); + itemMap.clear(); } @Override - public MmItemOutputEntity getByItemid(String itemid) { - QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper(); - queryWrapper.eq("itemid", itemid); + public List<MmItemOutputEntity> getByItemid(String itemId) { + if (itemMap.containsKey(itemId)) { + return itemMap.get(itemId); + } + QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("itemid", itemId).orderByAsc("outputorder"); List<MmItemOutputEntity> list = mmItemOutputDao.selectList(queryWrapper); if (CollectionUtils.isEmpty(list)) { - return new MmItemOutputEntity(); + return null; } - return list.get(0); + itemMap.put(itemId, list); + return itemMap.get(itemId); + } + + @Override + public MmItemOutputEntity getByItemid(String itemid, String resultstr, String resultIndex) { + QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("itemid", itemid) + .eq("resultstr", resultstr) + .eq(StringUtils.isNotBlank(resultIndex), "result_index", resultIndex); + return mmItemOutputDao.selectOne(queryWrapper); + } + + @Override + public void deleteByItemId(String itemId) { + QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("itemid", itemId); + mmItemOutputDao.delete(queryWrapper); } @Override @@ -59,21 +96,12 @@ } @Override - public MmItemOutputVO getOutPutById(String outputid) { - List<MmItemOutputVO> list = mmItemOutputDao.getOutPutById(outputid); - if (CollectionUtils.isEmpty(list)) { - return null; + public MmItemOutputEntity getOutPutById(String outputid) { + if (outputMap.containsKey(outputid)) { + return outputMap.get(outputid); } - return list.get(0); - } - - @Override - public List<MmItemOutputVO> getOutPutByItemId(String itemid) { - return mmItemOutputDao.getOutPutByItemId(itemid); - } - - @Override - public List<MmItemOutputVO> getOutPutByPointId(String pointid) { - return mmItemOutputDao.getOutPutByPointId(pointid); + MmItemOutputEntity entity = mmItemOutputDao.selectById(outputid); + outputMap.put(outputid, entity); + return entity; } } -- Gitblit v1.9.3