提交 fef219ce authored 作者: Matrix's avatar Matrix

[缓存] 更新缓存

上级 812cbe3a
......@@ -39,9 +39,11 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
/**
* ObjTransUtil.
......@@ -328,7 +330,8 @@ public class ObjTransUtil {
List<String> devCheckList = Lists.newArrayList(checkDetail.split(","));
long start = System.currentTimeMillis();
Map<Integer, DeviceLibrary> map = dlcService.getDevicesMap();
Map<Integer, DeviceLibrary> map = dlcService.getAllDeviceLibraryList().stream()
.collect(toMap(DeviceLibrary::getId, Function.identity()));
for (String detail : devCheckList) {
if (StringUtils.isEmpty(detail)) {
continue;
......
......@@ -18,10 +18,4 @@ public interface DeviceLibraryCacheService {
*/
List<DeviceLibrary> getAllDeviceLibraryList();
/**
*
* 以Map的形式获得所有装备列表
* @return key = 装备主键id , Value = {@link DeviceLibrary}
*/
Map<Integer, DeviceLibrary> getDevicesMap();
}
......@@ -19,6 +19,5 @@ public class MyInitializer implements ApplicationListener<ApplicationReadyEvent>
public void onApplicationEvent(ApplicationReadyEvent event) {
log.info("[缓存模块] 加载装备缓存模块...");
cacheLibraryService.getAllDeviceLibraryList();
cacheLibraryService.getDevicesMap();
}
}
......@@ -35,17 +35,4 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
System.out.println("缓存时间"+(System.currentTimeMillis()-l));
return all;
}
/**
* 以Map的形式获得所有装备列表
*
* @return key = 装备主键id , Value = {@link DeviceLibrary}
*/
@Override
@Cacheable(key = "'device'")
public Map<Integer, DeviceLibrary> getDevicesMap() {
return deviceLibraryDao.findAll().stream()
.collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
}
}
......@@ -317,15 +317,16 @@ public class TaskServiceImpl implements TaskService {
@ExceptionHandler(Exception.class)
@Log
public TaskBto start(TaskBto taskBto) {
Task task = taskDao.save(taskBto.toDo());
Task t = taskBto.toDo();
Task task = taskDao.saveAndFlush(t);
myWebSocket.sendMessage1();
Task task1 = taskDao.findById(task.getId()).get();
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Task task1 = taskDao.findById(task.getId()).get();
BcHash bcText = blockChainUtil.sendHash(1000, JacksonUtil.toJSon(task1));
String recordId = bcText.getData().getRecordID();
task1.setRecordId(recordId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论