package com.iailab.module.model.mcs.pre.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iailab.module.model.mcs.pre.dao.MmItemOutputDao; 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 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.concurrent.ConcurrentHashMap; /** * @author PanZhibao * @date 2021年04月27日 9:22 */ @Service public class MmItemOutputServiceImpl extends ServiceImpl implements MmItemOutputService { @Autowired private MmItemOutputDao mmItemOutputDao; private static Map outputMap = new ConcurrentHashMap<>(); private static Map> itemMap = new ConcurrentHashMap<>(); @Override public void saveMmItemOutput(List 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 queryWrapper = new QueryWrapper<>(); queryWrapper.in("itemid", itemIds); mmItemOutputDao.delete(queryWrapper); // 清空缓存 clearCache(); } private void clearCache() { outputMap.clear(); itemMap.clear(); } @Override public List getByItemid(String itemId) { if (itemMap.containsKey(itemId)) { return itemMap.get(itemId); } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("itemid", itemId).orderByAsc("outputorder"); List list = mmItemOutputDao.selectList(queryWrapper); if (CollectionUtils.isEmpty(list)) { return null; } itemMap.put(itemId, list); return itemMap.get(itemId); } @Override public MmItemOutputEntity getByItemid(String itemid, String resultstr, String resultIndex) { QueryWrapper 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 queryWrapper = new QueryWrapper<>(); queryWrapper.eq("itemid", itemId); mmItemOutputDao.delete(queryWrapper); } @Override public List queryList(Map params) { return mmItemOutputDao.queryList(params); } @Override public MmItemOutputEntity getOutPutById(String outputid) { if (outputMap.containsKey(outputid)) { return outputMap.get(outputid); } MmItemOutputEntity entity = mmItemOutputDao.selectById(outputid); outputMap.put(outputid, entity); return entity; } }