提交 df86e6a8 authored 作者: ljj's avatar ljj

refactor:重构核查快照的设计逻辑,提高查询效率

上级 5c965bca
...@@ -19,6 +19,7 @@ import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatDao; ...@@ -19,6 +19,7 @@ import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatDao;
import com.tykj.dev.device.confirmcheck.service.CheckUnitService; import com.tykj.dev.device.confirmcheck.service.CheckUnitService;
import com.tykj.dev.device.confirmcheck.service.ConfirmCheckService; import com.tykj.dev.device.confirmcheck.service.ConfirmCheckService;
import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService; import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService;
import com.tykj.dev.device.confirmcheck.task.ConfirmCheckTask;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil; import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
import com.tykj.dev.device.file.entity.FileRet; import com.tykj.dev.device.file.entity.FileRet;
import com.tykj.dev.device.file.service.FilesUtil; import com.tykj.dev.device.file.service.FilesUtil;
...@@ -90,6 +91,10 @@ import static java.util.stream.Collectors.*; ...@@ -90,6 +91,10 @@ import static java.util.stream.Collectors.*;
@Api(tags = "核查模块", description = "核查模块", position = 1) @Api(tags = "核查模块", description = "核查模块", position = 1)
public class DeviceCheckController { public class DeviceCheckController {
@Autowired
private ConfirmCheckTask confirmCheckTask;
final String CHECK_RESULT_WAIT = "等待省查阅"; final String CHECK_RESULT_WAIT = "等待省查阅";
final String CHECK_RESULT_DONE = "已查阅"; final String CHECK_RESULT_DONE = "已查阅";
Map<Integer, String> desMap = new HashMap<>(); Map<Integer, String> desMap = new HashMap<>();
...@@ -352,12 +357,25 @@ public class DeviceCheckController { ...@@ -352,12 +357,25 @@ public class DeviceCheckController {
.map(transUtil::CheckDetailDo2Vo) .map(transUtil::CheckDetailDo2Vo)
.orElse(null); .orElse(null);
List<DeviceInLibVo> in = confirmCheckTask.hisInLib.get(id);
long secondTime = System.currentTimeMillis(); if (in !=null) {
CheckDetailVo checkDetailVo = historyCheckDeviceService.replayHistoryDevice(detailVoList, id); detailVoList.setDevInLibrary(in);
log.info("[check] 查询快照的时间:{}", System.currentTimeMillis() - secondTime); }
List<DeviceNotInLibVo> notIn = confirmCheckTask.hisNotInLib.get(id);
if (notIn != null) {
detailVoList.setDevNotInLibrary(notIn);
}
return ResponseEntity.ok(new ResultObj<>(checkDetailVo)); if (in == null && notIn==null) {
// 理论上不会走到这一步
long secondTime = System.currentTimeMillis();
CheckDetailVo checkDetailVo = historyCheckDeviceService.replayHistoryDevice(detailVoList, id);
log.info("[check] 查询快照的时间:{}", System.currentTimeMillis() - secondTime);
return ResponseEntity.ok(new ResultObj<>(checkDetailVo));
}
return ResponseEntity.ok(new ResultObj<>(detailVoList));
} }
/** /**
...@@ -480,8 +498,8 @@ public class DeviceCheckController { ...@@ -480,8 +498,8 @@ public class DeviceCheckController {
CheckDetailVo cdVo = transUtil.CheckDetailDo2Vo(detail); CheckDetailVo cdVo = transUtil.CheckDetailDo2Vo(detail);
// 查询快照 // 查询快照
CheckDetailVo rs = historyCheckDeviceService.replayHistoryDevice(cdVo, id); // CheckDetailVo rs = historyCheckDeviceService.replayHistoryDevice(cdVo, id);
return ResponseEntity.ok(new ResultObj<>(rs)); return ResponseEntity.ok(new ResultObj<>(cdVo));
} }
/** /**
...@@ -857,7 +875,6 @@ public class DeviceCheckController { ...@@ -857,7 +875,6 @@ public class DeviceCheckController {
String detailString = transUtil.devLib2String(devLibVo.getDevInLibrary(), devLibVo.getDevNotInLibrary()); String detailString = transUtil.devLib2String(devLibVo.getDevInLibrary(), devLibVo.getDevNotInLibrary());
// 这边要根据检查信息,生成装备的历史记录 // 这边要根据检查信息,生成装备的历史记录
historyCheckDeviceService.createHistoryDevice(detailString, id);
User currentUser = Objects.requireNonNull(authenticationUtils.getAuthentication()).getCurrentUserInfo(); User currentUser = Objects.requireNonNull(authenticationUtils.getAuthentication()).getCurrentUserInfo();
long count = devLibVo.getDevInLibrary().stream() long count = devLibVo.getDevInLibrary().stream()
...@@ -870,6 +887,9 @@ public class DeviceCheckController { ...@@ -870,6 +887,9 @@ public class DeviceCheckController {
taskService.moveToNext(currentTask, assignUserId); taskService.moveToNext(currentTask, assignUserId);
log.info("[核查模块] A岗核查操作成功"); log.info("[核查模块] A岗核查操作成功");
historyCheckDeviceService.createHistoryDevice(detailString, id);
//3.将父级以及父级的父级的状态更改为正在进行 找到父级的stat对象 //3.将父级以及父级的父级的状态更改为正在进行 找到父级的stat对象
Integer fatherId = currentTask.getParentTaskId(); Integer fatherId = currentTask.getParentTaskId();
Task cityTask = taskRepo.findById(fatherId).get(); Task cityTask = taskRepo.findById(fatherId).get();
......
...@@ -8,6 +8,7 @@ import com.tykj.dev.device.confirmcheck.entity.vo.DeviceNotInLibVo; ...@@ -8,6 +8,7 @@ import com.tykj.dev.device.confirmcheck.entity.vo.DeviceNotInLibVo;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.HistoryCheckDeviceDao; import com.tykj.dev.device.confirmcheck.repository.HistoryCheckDeviceDao;
import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService; import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService;
import com.tykj.dev.device.confirmcheck.task.ConfirmCheckTask;
import com.tykj.dev.device.library.service.DeviceLibraryService; import com.tykj.dev.device.library.service.DeviceLibraryService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -27,6 +28,8 @@ import java.util.stream.Collectors; ...@@ -27,6 +28,8 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class HistoryCheckDeviceServiceImpl implements HistoryCheckDeviceService { public class HistoryCheckDeviceServiceImpl implements HistoryCheckDeviceService {
@Autowired
private ConfirmCheckTask confirmCheckTask;
@Autowired @Autowired
private HistoryCheckDeviceDao historyCheckDeviceDao; private HistoryCheckDeviceDao historyCheckDeviceDao;
@Autowired @Autowired
...@@ -83,6 +86,8 @@ public class HistoryCheckDeviceServiceImpl implements HistoryCheckDeviceService ...@@ -83,6 +86,8 @@ public class HistoryCheckDeviceServiceImpl implements HistoryCheckDeviceService
rs.add(build); rs.add(build);
} }
historyCheckDeviceDao.saveAll(rs); historyCheckDeviceDao.saveAll(rs);
confirmCheckTask.extracted(detailId);
} }
} }
......
package com.tykj.dev.device.confirmcheck.task; package com.tykj.dev.device.confirmcheck.task;
import com.tykj.dev.device.confirmcheck.controller.DeviceCheckController;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.entity.domain.HistoryCheckDevice;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckDetailVo;
import com.tykj.dev.device.confirmcheck.entity.vo.DeviceInLibVo;
import com.tykj.dev.device.confirmcheck.entity.vo.DeviceNotInLibVo;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.HistoryCheckDeviceDao;
import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService; import com.tykj.dev.device.confirmcheck.service.HistoryCheckDeviceService;
import com.tykj.dev.device.confirmcheck.service.impl.HistoryCheckDeviceServiceImpl;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.subject.domin.Task;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author: cnljj1995@gmail.com * @author: cnljj1995@gmail.com
* @Date: 2022/5/24 * @Date: 2022/5/24
...@@ -16,6 +31,18 @@ public class ConfirmCheckTask implements CommandLineRunner { ...@@ -16,6 +31,18 @@ public class ConfirmCheckTask implements CommandLineRunner {
@Autowired @Autowired
private HistoryCheckDeviceService historyCheckDeviceService; private HistoryCheckDeviceService historyCheckDeviceService;
@Autowired
private HistoryCheckDeviceDao historyCheckDeviceDao;
@Autowired
private DeviceCheckDetailDao detailDao;
@Autowired
private ObjTransUtil transUtil;
@Autowired
private TaskDao taskDao;
public Map<Integer, List<DeviceInLibVo>> hisInLib = new HashMap<>();;
public Map<Integer, List<DeviceNotInLibVo>> hisNotInLib = new HashMap<>();;
@Override @Override
public void run(String... args) { public void run(String... args) {
...@@ -24,5 +51,33 @@ public class ConfirmCheckTask implements CommandLineRunner { ...@@ -24,5 +51,33 @@ public class ConfirmCheckTask implements CommandLineRunner {
// historyCheckDeviceService.fixHistoryDevice(); // historyCheckDeviceService.fixHistoryDevice();
// log.info("[check] 纠正核查历史装备数据完成,用时:{}ms", System.currentTimeMillis() - start); // log.info("[check] 纠正核查历史装备数据完成,用时:{}ms", System.currentTimeMillis() - start);
log.info("[check] 启动加载完结的账单信息");
long startTime = System.currentTimeMillis();
List<Task> tasks = taskDao.findAllByBusinessTypeAndBillStatusNotIn(8, Arrays.asList(140, 160));
for (Task task : tasks) {
extracted(task.getBillId());
}
log.info("[check] 加载账单快照用时:{}ms", System.currentTimeMillis() - startTime);
}
public void extracted(Integer billId) {
Optional<DeviceCheckDetail> byId = detailDao.findById(billId);
if (byId.isPresent()) {
DeviceCheckDetail deviceCheckDetail = byId.get();
CheckDetailVo checkDetailVo = transUtil.CheckDetailDo2Vo(deviceCheckDetail);
CheckDetailVo vo2 = historyCheckDeviceService.replayHistoryDevice(checkDetailVo, deviceCheckDetail.getId());
List<DeviceInLibVo> devInLibrary = vo2.getDevInLibrary();
List<DeviceNotInLibVo> devNotInLibrary = vo2.getDevNotInLibrary();
hisInLib.put(deviceCheckDetail.getId(), devInLibrary);
hisNotInLib.put(deviceCheckDetail.getId(), devNotInLibrary);
}
} }
} }
...@@ -90,6 +90,7 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE ...@@ -90,6 +90,7 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE
List<Task> findAllByBusinessType(Integer businessType); List<Task> findAllByBusinessType(Integer businessType);
List<Task> findAllByBusinessTypeAndBillStatus(Integer businessType,Integer billStatus); List<Task> findAllByBusinessTypeAndBillStatus(Integer businessType,Integer billStatus);
List<Task> findAllByBusinessTypeAndBillStatusNotIn(Integer businessType,List<Integer> billStatus);
List<Task> findAllByBillIdInAndBusinessType(List<Integer> ids,Integer type); List<Task> findAllByBillIdInAndBusinessType(List<Integer> ids,Integer type);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论