提交 0a91f018 authored 作者: Matrix's avatar Matrix

[核查模块] 优化了detail的测试

上级 46692d0d
...@@ -10,6 +10,7 @@ import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat; ...@@ -10,6 +10,7 @@ import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.device.confirmcheck.entity.vo.*; import com.tykj.dev.device.confirmcheck.entity.vo.*;
import com.tykj.dev.device.file.service.FilesUtil; import com.tykj.dev.device.file.service.FilesUtil;
import com.tykj.dev.device.library.repository.DeviceLibraryDao; 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 com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.packing.service.PackingLibraryService; import com.tykj.dev.device.packing.service.PackingLibraryService;
import com.tykj.dev.device.task.repository.TaskDao; import com.tykj.dev.device.task.repository.TaskDao;
...@@ -27,6 +28,7 @@ import com.tykj.dev.misc.base.BeanHelper; ...@@ -27,6 +28,7 @@ import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.base.BusinessEnum; import com.tykj.dev.misc.base.BusinessEnum;
import com.tykj.dev.misc.exception.ApiException; import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.JacksonUtil; import com.tykj.dev.misc.utils.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -48,6 +50,7 @@ import static java.util.stream.Collectors.toList; ...@@ -48,6 +50,7 @@ import static java.util.stream.Collectors.toList;
* @since 2020/8/17 at 8:45 下午 * @since 2020/8/17 at 8:45 下午
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
@Slf4j
@Component @Component
public class ObjTransUtil { public class ObjTransUtil {
...@@ -72,6 +75,9 @@ public class ObjTransUtil { ...@@ -72,6 +75,9 @@ public class ObjTransUtil {
@Autowired @Autowired
private TaskDao taskDao; private TaskDao taskDao;
@Autowired
private DeviceLibraryCacheService dlcService;
@Resource(name = "unMap") @Resource(name = "unMap")
private Map<String, AreaUnit> unMap; private Map<String, AreaUnit> unMap;
...@@ -320,6 +326,9 @@ public class ObjTransUtil { ...@@ -320,6 +326,9 @@ public class ObjTransUtil {
List<DeviceNotInLibVo> notInLibVoList = new ArrayList<>(); List<DeviceNotInLibVo> notInLibVoList = new ArrayList<>();
String checkDetail = detailDo.getCheckDetail(); String checkDetail = detailDo.getCheckDetail();
List<String> devCheckList = Lists.newArrayList(checkDetail.split(",")); List<String> devCheckList = Lists.newArrayList(checkDetail.split(","));
long start = System.currentTimeMillis();
Map<Integer, DeviceLibrary> map = dlcService.getDevicesMap();
for (String detail : devCheckList) { for (String detail : devCheckList) {
if (StringUtils.isEmpty(detail)) { if (StringUtils.isEmpty(detail)) {
continue; continue;
...@@ -328,8 +337,12 @@ public class ObjTransUtil { ...@@ -328,8 +337,12 @@ public class ObjTransUtil {
Integer deviceId = Integer.valueOf(array[0]); Integer deviceId = Integer.valueOf(array[0]);
int proofResult = Integer.parseInt(array[1]); int proofResult = Integer.parseInt(array[1]);
// 搜索装备 // 搜索装备
DeviceLibrary device = deviceRepo.findById(deviceId).orElseThrow( DeviceLibrary device = Optional.ofNullable(map.get(deviceId))
() -> new ApiException(ResponseEntity.badRequest().body(String.format("检查到装备序号为%d的装备不在资料库中,请先执行入库操作!", deviceId)))).setConfigName(); .orElseThrow(() -> new ApiException(
ResponseEntity.badRequest().body(String.format("检查到装备序号为%d的装备不在资料库中,请先执行入库操作!", deviceId)))).setConfigName();
// DeviceLibrary device = deviceRepo.findById(deviceId).orElseThrow(
// () -> new ApiException(ResponseEntity.badRequest().body(String.format("检查到装备序号为%d的装备不在资料库中,请先执行入库操作!", deviceId)))).setConfigName();
//依据proofResult的个位数 判断是否是在库装备 //依据proofResult的个位数 判断是否是在库装备
int digit = proofResult % 10; int digit = proofResult % 10;
if (digit == 3) { if (digit == 3) {
...@@ -341,6 +354,10 @@ public class ObjTransUtil { ...@@ -341,6 +354,10 @@ public class ObjTransUtil {
inLibVoList.add(toCheckInLibVo(device, proofResult)); inLibVoList.add(toCheckInLibVo(device, proofResult));
} }
} }
long end = System.currentTimeMillis();
log.info("[性能测试] 装备搜索耗时 {} ms", end - start);
// detailDo -> detailVo // detailDo -> detailVo
ModelMapper modelMapper = BeanHelper.getUserMapper(); ModelMapper modelMapper = BeanHelper.getUserMapper();
CheckDetailVo detailVo = modelMapper.map(detailDo, CheckDetailVo.class); CheckDetailVo detailVo = modelMapper.map(detailDo, CheckDetailVo.class);
......
package com.tykj.dev.device.library.service; package com.tykj.dev.device.library.service;
import com.oracle.tools.packager.mac.MacAppBundler;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* DATE:2021-8-11 * DATE:2021-8-11
...@@ -13,6 +15,14 @@ public interface DeviceLibraryCacheService { ...@@ -13,6 +15,14 @@ public interface DeviceLibraryCacheService {
/** /**
* 查询全部 * 查询全部
* @return List形式的DeviceLibrary
*/ */
List<DeviceLibrary> getAllDeviceLibraryList(); List<DeviceLibrary> getAllDeviceLibraryList();
/**
*
* 以Map的形式获得所有装备列表
* @return key = 装备主键id , Value = {@link DeviceLibrary}
*/
Map<Integer, DeviceLibrary> getDevicesMap();
} }
package com.tykj.dev.device.library.service; package com.tykj.dev.device.library.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -10,11 +11,14 @@ import org.springframework.stereotype.Component; ...@@ -10,11 +11,14 @@ import org.springframework.stereotype.Component;
* Author:zsp * Author:zsp
*/ */
@Component @Component
@Slf4j
public class MyInitializer implements ApplicationListener<ApplicationReadyEvent> { public class MyInitializer implements ApplicationListener<ApplicationReadyEvent> {
@Autowired @Autowired
private DeviceLibraryCacheService cacheLibraryService; private DeviceLibraryCacheService cacheLibraryService;
@Override @Override
public void onApplicationEvent(ApplicationReadyEvent event) { public void onApplicationEvent(ApplicationReadyEvent event) {
log.info("[缓存模块] 加载装备缓存模块...");
cacheLibraryService.getAllDeviceLibraryList(); cacheLibraryService.getAllDeviceLibraryList();
cacheLibraryService.getDevicesMap();
} }
} }
...@@ -9,6 +9,9 @@ import org.springframework.cache.annotation.Cacheable; ...@@ -9,6 +9,9 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/** /**
* DATE:2021-8-11 * DATE:2021-8-11
...@@ -33,4 +36,15 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService { ...@@ -33,4 +36,15 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
return all; return all;
} }
/**
* 以Map的形式获得所有装备列表
*
* @return key = 装备主键id , Value = {@link DeviceLibrary}
*/
@Override
public Map<Integer, DeviceLibrary> getDevicesMap() {
return deviceLibraryDao.findAll().stream()
.collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论