提交 ab38952f authored 作者: zhoushaopan's avatar zhoushaopan

[缓存]新增根据id查询缓存

上级 7fefc582
......@@ -18,4 +18,10 @@ public interface DeviceLibraryCacheService {
*/
List<DeviceLibrary> getAllDeviceLibraryList();
/**
* 根据多个id查询
* @return
*/
List<DeviceLibrary> findByIds(List<Integer> ids);
}
......@@ -3,11 +3,13 @@ package com.tykj.dev.device.library.service.impl;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.service.DeviceLibraryCacheService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import jdk.nashorn.internal.ir.IfNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
......@@ -26,7 +28,8 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
// @Autowired
// private ConcurrentMapCacheManager mapCacheManager;
@Autowired
private DeviceLibraryCacheService deviceLibraryCacheService;
@Override
@Cacheable(key = "'device'")
public List<DeviceLibrary> getAllDeviceLibraryList() {
......@@ -35,4 +38,21 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
System.out.println("缓存时间"+(System.currentTimeMillis()-l));
return all;
}
@Override
@Cacheable(key = "'deviceByIds'")
public List<DeviceLibrary> findByIds(List<Integer> ids) {
List<DeviceLibrary> deviceLibraries = deviceLibraryCacheService.getAllDeviceLibraryList();
Map<Integer, DeviceLibrary> map = deviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
List<DeviceLibrary> libraryList = new ArrayList<>();
ids.forEach(
id->{
if (map.containsKey(id)){
DeviceLibrary deviceLibrary = map.get(id);
libraryList.add(deviceLibrary);
}
}
);
return libraryList;
}
}
......@@ -60,8 +60,6 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
@Autowired
private DeviceLibraryCacheService cacheLibraryService;
@Autowired
private CacheLibraryController cacheLibraryController;
@Override
public DeviceLibrary addEntity(DeviceLibrary deviceLibraryEntity) {
DeviceLibrary deviceLibrary = deviceLibraryDao.save(deviceLibraryEntity);
......@@ -655,12 +653,13 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
public Map<Integer,List<DeviceLibrary>> findAllByPackingId3() {
//筛选出当前单位在库的装备
long l = System.currentTimeMillis();
List<DeviceLibrary> deviceLibraryList = cacheLibraryController.getAll();
// List<DeviceLibrary> deviceLibraryList = cacheLibraryService.getAllDeviceLibraryList();
// List<DeviceLibrary> deviceLibraryList = cacheLibraryController.getAll();
List<DeviceLibrary> deviceLibraryList = cacheLibraryService.getAllDeviceLibraryList();
System.out.println("查询在库时间ggg"+(System.currentTimeMillis()-l));
String currentUserUnitName = userUtils.getCurrentUserUnitName();
List<DeviceLibrary> deviceLibraries = deviceLibraryList.stream().filter(deviceLibrary -> deviceLibrary.getLifeStatus() == 2)
// .filter(deviceLibrary -> deviceLibrary.getLocationUnit().equals(userUtils.getCurrentUserUnitName())
// || deviceLibrary.getOwnUnit().equals(userUtils.getCurrentUserUnitName()))
.filter(deviceLibrary -> deviceLibrary.getLocationUnit().equals(currentUserUnitName)
|| deviceLibrary.getOwnUnit().equals(currentUserUnitName))
.collect(Collectors.toList());
//转为列装id的map
Map<Integer,List<DeviceLibrary>> map = deviceLibraries.stream().collect(groupingBy(DeviceLibrary::getPackingId));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论