| | |
| | | import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
| | | 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; |
| | |
| | | private MmItemOutputDao mmItemOutputDao; |
| | | |
| | | private static Map<String, MmItemOutputEntity> outputMap = new ConcurrentHashMap<>(); |
| | | |
| | | private static Map<String, List<MmItemOutputEntity>> itemMap = new ConcurrentHashMap<>(); |
| | | |
| | | @Override |
| | | public void saveMmItemOutput(List<MmItemOutputEntity> mmItemOutput) { |
| | | mmItemOutput.forEach(e -> { |
| | | e.setId(e.getId().replace("+","").replace("-","")); |
| | | }); |
| | | mmItemOutputDao.insert(mmItemOutput); |
| | | // 清空缓存 |
| | | outputMap.clear(); |
| | | clearCache(); |
| | | } |
| | | |
| | | @Override |
| | | public void update(MmItemOutputEntity mmItemOutput) { |
| | | mmItemOutputDao.updateById(mmItemOutput); |
| | | // 清空缓存 |
| | | outputMap.clear(); |
| | | 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 List<MmItemOutputEntity> getByItemid(String 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"); |
| | | queryWrapper.eq("itemid", itemId).orderByAsc("outputorder"); |
| | | List<MmItemOutputEntity> list = mmItemOutputDao.selectList(queryWrapper); |
| | | return list; |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | itemMap.put(itemId, list); |
| | | return itemMap.get(itemId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void deleteByItemId(String itemId) { |
| | | QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper(); |
| | | QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("itemid", itemId); |
| | | mmItemOutputDao.delete(queryWrapper); |
| | | } |