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

feat(自查模块): 优化了发起自查业务时间

优化了发起自查业务时间
上级 4fa5e7e1
package com.tykj.dev.device.selfcheck.config;
import com.tykj.dev.device.selfcheck.repository.HistoryDeviceBillDao;
import com.tykj.dev.device.selfcheck.subject.domin.HistoryDeviceBill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author zsp
* @create 2022/5/23 14:37
*/
@Component
@Slf4j
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HistoryDeviceBillRun {
@Resource
private HistoryDeviceBillDao deviceBillDao;
private Map<Integer, List<HistoryDeviceBill>> map =new HashMap<>();
@PostConstruct
private void initHistoryDeviceBill(){
log.info("历史自查存储数据表开始同步....");
this.map = deviceBillDao.findAll().stream().collect(Collectors.groupingBy(HistoryDeviceBill::getBillId));
log.info("历史自查存储数据表同步成功....");
}
}
...@@ -17,6 +17,7 @@ import com.tykj.dev.device.library.subject.domin.DeviceLibrary; ...@@ -17,6 +17,7 @@ import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.library.subject.vo.FileVo; import com.tykj.dev.device.library.subject.vo.FileVo;
import com.tykj.dev.device.library.subject.vo.SelfCheckVo; import com.tykj.dev.device.library.subject.vo.SelfCheckVo;
import com.tykj.dev.device.selfcheck.base.SelfCheckSchedulerTask; import com.tykj.dev.device.selfcheck.base.SelfCheckSchedulerTask;
import com.tykj.dev.device.selfcheck.config.HistoryDeviceBillRun;
import com.tykj.dev.device.selfcheck.repository.SelfCheckBillDao; import com.tykj.dev.device.selfcheck.repository.SelfCheckBillDao;
import com.tykj.dev.device.selfcheck.service.HistoryDeviceBillService; import com.tykj.dev.device.selfcheck.service.HistoryDeviceBillService;
import com.tykj.dev.device.selfcheck.service.SelfCheckBillService; import com.tykj.dev.device.selfcheck.service.SelfCheckBillService;
...@@ -131,7 +132,7 @@ public class SelfCheckController { ...@@ -131,7 +132,7 @@ public class SelfCheckController {
private HistoryDeviceBillService historyDeviceBillService; private HistoryDeviceBillService historyDeviceBillService;
@Resource @Resource
private JdbcTemplate jdbcTemplate; private HistoryDeviceBillRun historyDeviceBillRun;
/** /**
* 月度 * 月度
...@@ -413,6 +414,11 @@ public class SelfCheckController { ...@@ -413,6 +414,11 @@ public class SelfCheckController {
//批量保存 //批量保存
batchSave(historyDeviceBillList); batchSave(historyDeviceBillList);
// historyDeviceBillService.batchSave(historyDeviceBillList); // historyDeviceBillService.batchSave(historyDeviceBillList);
//将数据转换成map放在缓存中
Map<Integer, List<HistoryDeviceBill>> map = historyDeviceBillList.stream()
.collect(Collectors.groupingBy(HistoryDeviceBill::getBillId));
Map<Integer, List<HistoryDeviceBill>> listMap = historyDeviceBillRun.getMap();
listMap.putAll(map);
} }
}else { }else {
// 是0 和1 // 是0 和1
...@@ -435,7 +441,11 @@ public class SelfCheckController { ...@@ -435,7 +441,11 @@ public class SelfCheckController {
}); });
//保存 //保存
batchSave(historyDeviceBillList); batchSave(historyDeviceBillList);
//将数据转换成map放在缓存中
Map<Integer, List<HistoryDeviceBill>> map = historyDeviceBillList.stream()
.collect(Collectors.groupingBy(HistoryDeviceBill::getBillId));
Map<Integer, List<HistoryDeviceBill>> listMap = historyDeviceBillRun.getMap();
listMap.putAll(map);
// historyDeviceBillService.batchSave(historyDeviceBillList); // historyDeviceBillService.batchSave(historyDeviceBillList);
// executor.execute(()->{ // executor.execute(()->{
// historyDeviceBillService.batchSave(historyDeviceBillList); // historyDeviceBillService.batchSave(historyDeviceBillList);
...@@ -460,7 +470,11 @@ public class SelfCheckController { ...@@ -460,7 +470,11 @@ public class SelfCheckController {
}); });
//保存 //保存
batchSave(historyDeviceBillList); batchSave(historyDeviceBillList);
//将数据转换成map放在缓存中
Map<Integer, List<HistoryDeviceBill>> map = historyDeviceBillList.stream()
.collect(Collectors.groupingBy(HistoryDeviceBill::getBillId));
Map<Integer, List<HistoryDeviceBill>> listMap = historyDeviceBillRun.getMap();
listMap.putAll(map);
// historyDeviceBillService.batchSave(historyDeviceBillList); // historyDeviceBillService.batchSave(historyDeviceBillList);
// executor.execute(()->{ // executor.execute(()->{
// historyDeviceBillService.batchSave(historyDeviceBillList); // historyDeviceBillService.batchSave(historyDeviceBillList);
...@@ -755,9 +769,16 @@ public class SelfCheckController { ...@@ -755,9 +769,16 @@ public class SelfCheckController {
// 2.添加新增不在系统的装备 // 2.添加新增不在系统的装备
list.add(newDeviceList); list.add(newDeviceList);
//根据业务id和业务类型查询 //根据业务id和业务类型查询
List<HistoryDeviceBill> historyDeviceBillList = List<HistoryDeviceBill> historyDeviceBillList;
Map<Integer, List<HistoryDeviceBill>> map1 = historyDeviceBillRun.getMap();
if (map1.containsKey(billId)){
historyDeviceBillList = map1.get(billId);
}else {
historyDeviceBillList =
historyDeviceBillService.selectByBillId(billId); historyDeviceBillService.selectByBillId(billId);
//将数据放在缓存中
map1.put(billId,historyDeviceBillList);
}
//3.添加自查装备 //3.添加自查装备
// list.add(libraryEntities1); // list.add(libraryEntities1);
list.add(historyDeviceBillList); list.add(historyDeviceBillList);
......
...@@ -26,6 +26,7 @@ import com.tykj.dev.device.repair.service.RepairBackBillService; ...@@ -26,6 +26,7 @@ import com.tykj.dev.device.repair.service.RepairBackBillService;
import com.tykj.dev.device.repair.service.RepairBillService; import com.tykj.dev.device.repair.service.RepairBillService;
import com.tykj.dev.device.repair.subject.domin.RepairBackBill; import com.tykj.dev.device.repair.subject.domin.RepairBackBill;
import com.tykj.dev.device.repair.subject.domin.RepairBill; import com.tykj.dev.device.repair.subject.domin.RepairBill;
import com.tykj.dev.device.selfcheck.config.HistoryDeviceBillRun;
import com.tykj.dev.device.selfcheck.service.HistoryDeviceBillService; import com.tykj.dev.device.selfcheck.service.HistoryDeviceBillService;
import com.tykj.dev.device.selfcheck.service.SelfCheckBillService; import com.tykj.dev.device.selfcheck.service.SelfCheckBillService;
import com.tykj.dev.device.selfcheck.subject.domin.HistoryDeviceBill; import com.tykj.dev.device.selfcheck.subject.domin.HistoryDeviceBill;
...@@ -52,9 +53,11 @@ import com.tykj.dev.misc.utils.StringSplitUtil; ...@@ -52,9 +53,11 @@ import com.tykj.dev.misc.utils.StringSplitUtil;
//import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineLibraryService; //import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineLibraryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.Area; import org.checkerframework.checker.units.qual.Area;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -72,6 +75,7 @@ import static java.util.stream.Collectors.toMap; ...@@ -72,6 +75,7 @@ import static java.util.stream.Collectors.toMap;
@Api(tags = "业务模块", description = "业务模块") @Api(tags = "业务模块", description = "业务模块")
@AutoDocument @AutoDocument
@RequestMapping("/business") @RequestMapping("/business")
@Slf4j
public class TaskSelectController { public class TaskSelectController {
@Autowired @Autowired
...@@ -135,6 +139,9 @@ public class TaskSelectController { ...@@ -135,6 +139,9 @@ public class TaskSelectController {
@Resource @Resource
private UserCache userCache; private UserCache userCache;
@Resource
private HistoryDeviceBillRun historyDeviceBillRun;
@ApiOperation(value = "查询业务对应页面的数据", notes = "可以通过这个接口查询业务对应页面的数据") @ApiOperation(value = "查询业务对应页面的数据", notes = "可以通过这个接口查询业务对应页面的数据")
@GetMapping("/manage/detail/{id}") @GetMapping("/manage/detail/{id}")
public ResponseEntity selectData(@PathVariable("id") int taskId) { public ResponseEntity selectData(@PathVariable("id") int taskId) {
...@@ -357,10 +364,22 @@ public class TaskSelectController { ...@@ -357,10 +364,22 @@ public class TaskSelectController {
// libraryEntities1.add(deviceLibraryEntity); // libraryEntities1.add(deviceLibraryEntity);
// } // }
// } // }
List<HistoryDeviceBill> historyDeviceBillList =
historyDeviceBillService.selectByBillId(billId);
List<HistoryDeviceBill> historyDeviceBillList;
StopWatch stopWatch = new StopWatch("查询历史表的时间");
stopWatch.start();
//过滤出1的 //过滤出1的
Map<Integer, List<HistoryDeviceBill>> map1 = historyDeviceBillRun.getMap();
if (map1.containsKey(billId)){
historyDeviceBillList = map1.get(billId);
}else {
historyDeviceBillList =
historyDeviceBillService.selectByBillId(billId);
//将数据放在缓存中
map1.put(billId,historyDeviceBillList);
}
stopWatch.stop();
log.info("查询历史表的时间:{}",stopWatch.getTotalTimeMillis()+"ms");
List<HistoryDeviceBill> billList1 = List<HistoryDeviceBill> billList1 =
historyDeviceBillList.stream().filter(historyDeviceBill -> historyDeviceBill.getCheckResult() == 1) historyDeviceBillList.stream().filter(historyDeviceBill -> historyDeviceBill.getCheckResult() == 1)
.collect(Collectors.toList()); .collect(Collectors.toList());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论