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

[缓存] 更新缓存

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