提交 0ed8ee32 authored 作者: ljj234's avatar ljj234

refactor: 修改核查模块,市自动转发个区

上级 af7fec8d
package com.tykj.dev.device.confirmcheck.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/10/21
*/
@Getter
@AllArgsConstructor
public enum CheckExamUnits {
PROVINCIAL(1,"省级"),
PROVINCIAL_UNDER(2, "省直属"),
CITY(3,"市级");
private final int id;
private final String name;
}
...@@ -18,6 +18,7 @@ import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao; ...@@ -18,6 +18,7 @@ import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckLinkDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckLinkDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatDao;
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.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;
...@@ -35,6 +36,7 @@ import com.tykj.dev.device.task.subject.domin.Task; ...@@ -35,6 +36,7 @@ import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.user.base.enums.AuExample; import com.tykj.dev.device.user.base.enums.AuExample;
import com.tykj.dev.device.user.base.ret.UserShenRe; import com.tykj.dev.device.user.base.ret.UserShenRe;
import com.tykj.dev.device.user.cache.AreaCache; import com.tykj.dev.device.user.cache.AreaCache;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.read.service.MessageService; import com.tykj.dev.device.user.read.service.MessageService;
import com.tykj.dev.device.user.read.subject.bto.MessageBto; import com.tykj.dev.device.user.read.subject.bto.MessageBto;
import com.tykj.dev.device.user.subject.dao.AreaDao; import com.tykj.dev.device.user.subject.dao.AreaDao;
...@@ -95,6 +97,9 @@ public class DeviceCheckController { ...@@ -95,6 +97,9 @@ public class DeviceCheckController {
private int specialDetailId = 0; private int specialDetailId = 0;
private List<String> specialUnits = new ArrayList<>(); private List<String> specialUnits = new ArrayList<>();
@Autowired
private UnitsCache unitsCache;
@Autowired @Autowired
private DeviceCheckLinkDao linkRepo; private DeviceCheckLinkDao linkRepo;
@Autowired @Autowired
...@@ -137,6 +142,8 @@ public class DeviceCheckController { ...@@ -137,6 +142,8 @@ public class DeviceCheckController {
private TaskLogService taskLogService; private TaskLogService taskLogService;
@Autowired @Autowired
private UnitsService unitsService; private UnitsService unitsService;
@Autowired
private CheckUnitService checkUnitService;
@GetMapping("/area/{fatherId}") @GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息") @ApiOperation(value = "查询指定区域下的所有区域信息")
...@@ -149,15 +156,14 @@ public class DeviceCheckController { ...@@ -149,15 +156,14 @@ public class DeviceCheckController {
* *
* @return type = 2 and level in (1,2) ,filter escrow = 1 的单位 * @return type = 2 and level in (1,2) ,filter escrow = 1 的单位
*/ */
@GetMapping("/unit") @GetMapping("/unit/old")
@ApiOperation(value = "查询默认的可以被核查单位的清单(省本直,省直属,市局),同时过滤掉那些已经被代管的单位") @ApiOperation(value = "查询默认的可以被核查单位的清单(省本直,省直属,市局),同时过滤掉那些已经被代管的单位")
public ResponseEntity findDefaultUnits() { public ResponseEntity findDefaultUnits() {
List<Units> units = unitsRepo.findAllByTypeInOrLevelIn(Lists.newArrayList(2), Lists.newArrayList(1, 2)) List<Units> units = unitsRepo.findAllByTypeInOrLevelIn(Lists.newArrayList(2), Lists.newArrayList(1, 2))
.stream().filter(Units::isNotEscrow) .stream()
.collect(toList()); .collect(toList());
// 需要去除掉被托管的单位 // 需要去除掉被托管的单位
return ResponseEntity.ok(new ResultObj<>(units)); return ResponseEntity.ok(new ResultObj<>(units));
} }
/** /**
...@@ -241,9 +247,7 @@ public class DeviceCheckController { ...@@ -241,9 +247,7 @@ public class DeviceCheckController {
@ApiOperation(value = "根据关键字分页查询核查统计数据") @ApiOperation(value = "根据关键字分页查询核查统计数据")
@PostMapping("/stat") @PostMapping("/stat")
public Page<CheckStatTableVo> findStatByKeyword( public Page<CheckStatTableVo> findStatByKeyword(@RequestBody CheckBillSelectVo checkBillSelectVo) {
@RequestBody CheckBillSelectVo checkBillSelectVo
) {
return ccService.findAllStatTable(checkBillSelectVo); return ccService.findAllStatTable(checkBillSelectVo);
} }
...@@ -256,6 +260,12 @@ public class DeviceCheckController { ...@@ -256,6 +260,12 @@ public class DeviceCheckController {
return ResponseEntity.ok(new ResultObj<>(detailVoList)); return ResponseEntity.ok(new ResultObj<>(detailVoList));
} }
/**
* 阅知
*
* @param taskId
* @return
*/
@ApiOperation(value = "提供taskId,该接口返回可以跳转到详情页面的数据", notes = "提供taskId,该接口返回可以跳转到详情页面的数据") @ApiOperation(value = "提供taskId,该接口返回可以跳转到详情页面的数据", notes = "提供taskId,该接口返回可以跳转到详情页面的数据")
@GetMapping("/msgLink") @GetMapping("/msgLink")
public ResponseEntity msgLink(@RequestParam Integer taskId) { public ResponseEntity msgLink(@RequestParam Integer taskId) {
...@@ -266,7 +276,6 @@ public class DeviceCheckController { ...@@ -266,7 +276,6 @@ public class DeviceCheckController {
} else if (task.getBusinessType().equals(CONFIRM_CHECK_DETAIL.id)) { } else if (task.getBusinessType().equals(CONFIRM_CHECK_DETAIL.id)) {
return findDetail(task.getBillId()); return findDetail(task.getBillId());
} }
return ResponseEntity.status(400).body("该businessType不在处理范围内!本接口处理的type = 7 ,8"); return ResponseEntity.status(400).body("该businessType不在处理范围内!本接口处理的type = 7 ,8");
} }
...@@ -355,6 +364,7 @@ public class DeviceCheckController { ...@@ -355,6 +364,7 @@ public class DeviceCheckController {
} }
} }
// todo
// 代管 - 如果当前自查为省本级自查,则需要将被代管的装备加入到省本级 // 代管 - 如果当前自查为省本级自查,则需要将被代管的装备加入到省本级
Units unit = unitsRepo.findByName(checkUnit); Units unit = unitsRepo.findByName(checkUnit);
boolean isProv = unit.getLevel() == 1 && unit.getType() == 1; boolean isProv = unit.getLevel() == 1 && unit.getType() == 1;
...@@ -498,9 +508,8 @@ public class DeviceCheckController { ...@@ -498,9 +508,8 @@ public class DeviceCheckController {
long end1 = System.currentTimeMillis(); long end1 = System.currentTimeMillis();
log.info("[性能分析] task id = {} cost {} ms", cct.getId(), end1 - start1); log.info("[性能分析] task id = {} cost {} ms", cct.getId(), end1 - start1);
} }
//
String areaName = auService.findOne(AuExample.UnitId, child.getOwnUnit()).getName(); String areaName = auService.findOne(AuExample.UnitId, child.getOwnUnit()).getName();
//
LinkCheckDetail lcd = cas2lcd(totalList, child, cctask, areaName); LinkCheckDetail lcd = cas2lcd(totalList, child, cctask, areaName);
lcd.setCheckUnit(unitName); lcd.setCheckUnit(unitName);
...@@ -566,38 +575,32 @@ public class DeviceCheckController { ...@@ -566,38 +575,32 @@ public class DeviceCheckController {
// 找到所有的子节点 // 找到所有的子节点
List<Task> childTask = taskRepo.findAllByParentTaskId(rootTask.getId()); List<Task> childTask = taskRepo.findAllByParentTaskId(rootTask.getId());
//核查组成员和名称 找到父亲级节点 然后找到父节点的统计节点 // 找到父亲级节点 然后找到父节点的统计节点
String[] checkArray = ctVo.getRemark().split("\\|");// x,a |x ,b
List<String> groupNames = new ArrayList<>();
List<String> userNames = new ArrayList<>();
for (String ca : checkArray) {
if (!ca.contains(",")) {
continue;
}
String[] carry = ca.split(",");
groupNames.add(carry[0]);
String uname = "";
for (int i = 1; i < carry.length; i++) {
uname += carry[i] + " ";
}
userNames.add(uname);
}
// 检查的节点都是自查 // 检查的节点都是自查
int i = 0;
for (Task child : childTask) { for (Task child : childTask) {
LinkExamDetail led = getLed(endTime, updateTime, child); // 这里只显示detail任务
if (child.getBusinessType() == CONFIRM_CHECK_STAT.id) {
// todo
lcdList.add(LinkCheckDetail.builder()
.checkResult("无误")
.checkUnit(unitsRepo.findById(child.getOwnUnit()).get().getName())
.checkSituation("211")
.id(child.getBillId())
.remark(1)
.build());
break;
}
LinkExamDetail led = getLed(endTime, updateTime, child);
//设置名称 //设置名称
led.setExamName(groupNames.get(i)); led.setExamName("默认检查组");
led.setExamUser(userNames.get(i)); led.setExamUser("默认检查人员");
ledList.add(led); ledList.add(led);
i++;
} }
i = 0;
linkVo.setLcDetail(lcdList); linkVo.setLcDetail(lcdList);
linkVo.setLeDetail(ledList); linkVo.setLeDetail(ledList);
...@@ -614,46 +617,6 @@ public class DeviceCheckController { ...@@ -614,46 +617,6 @@ public class DeviceCheckController {
} }
/**
* @param periodId 1-月度 2-季度 3-年度
* @return
*/
@ApiOperation(value = "更新自动核查周期", notes = "更新自动核查周期")
@PutMapping("/task/{periodId}")
public ResponseEntity updateTaskPeriod(
@PathVariable @ApiParam(value = "核查周期,1-月度 2-季度 3-年度", example = "1") Integer periodId) {
if (periodId < 1 || periodId > 3) {
return ResponseEntity.status(400).body(new ResultObj<>("提供了错误的周期参数!应该是 1/2/3 , 您提供的是" + periodId));
}
TaskPeriod period = TaskPeriod.values()[periodId - 1];
// 更新最新的周期
ccService.updateTaskPeriod(period);
// 结束当前任务,开启下轮任务
ccService.stopAutoCheckCron();
boolean startSuccess = ccService.startAutoCheckCron();
if (startSuccess) {
String nextTime = ccService.getNextTaskDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
return ResponseEntity.ok(new ResultObj<>(String.format("更新自动核查周期成功,下一次任务的执行时间为%s", nextTime)));
} else {
return ResponseEntity.status(400).body("自动核查更新周期失败了!");
}
}
@ApiOperation(value = "获取下一次自动核查任务执行的具体时间", notes = "获取下一次自动核查任务执行的具体时间")
@GetMapping("/task/next")
public Map<String, LocalDate> getNextTaskTime() {
return ImmutableMap.of("nextTaskTime", ccService.getNextTaskDate());
}
@ApiOperation(value = "获取当前自动核查的核查周期", notes = "monthly-月度,quarterly-季度,yearly-年度")
@GetMapping("/task/current")
public Map<String, String> getCurrentTaskPeriod() {
String periodName = ccService.getCurrentTaskPeriod().getCronExpression().name();
return ImmutableMap.of("currentTaskPeriod", periodName);
}
/** /**
* 发起检查时获取核查的标题 * 发起检查时获取核查的标题
* *
...@@ -672,13 +635,6 @@ public class DeviceCheckController { ...@@ -672,13 +635,6 @@ public class DeviceCheckController {
return ResponseEntity.ok(new CheckTitleAndTimeVo(title, deviceCheckStat.getEndTime(), remark)); return ResponseEntity.ok(new CheckTitleAndTimeVo(title, deviceCheckStat.getEndTime(), remark));
} }
@ApiOperation(value = "发起自动核查", notes = "发起自动核查")
@PostMapping("/auto")
public ResultObj<Map<String, List<Integer>>> startAutoCheck() {
Map<String, List<Integer>> resultIds = ccService.autoCheck();
return new ResultObj<>(resultIds, "自动核查任务发起成功");
}
@ApiOperation(value = "根据地区ID获取下级的单位", notes = "根据地区ID获取下级的单位") @ApiOperation(value = "根据地区ID获取下级的单位", notes = "根据地区ID获取下级的单位")
@GetMapping("/under/{areaId}") @GetMapping("/under/{areaId}")
public ResponseEntity getUnitsUnderAreaId(@PathVariable Integer areaId, @RequestParam(defaultValue = "true") boolean filter) { public ResponseEntity getUnitsUnderAreaId(@PathVariable Integer areaId, @RequestParam(defaultValue = "true") boolean filter) {
...@@ -690,13 +646,6 @@ public class DeviceCheckController { ...@@ -690,13 +646,6 @@ public class DeviceCheckController {
//2. 根据childId 获得对应的unit //2. 根据childId 获得对应的unit
List<Units> unitsList = unitsRepo.findAllByAreaIdIn(areaIds); List<Units> unitsList = unitsRepo.findAllByAreaIdIn(areaIds);
// 根据filter 决定是否将没有数据的装备给过滤掉
if (filter) {
unitsList = unitsList.stream()
.filter(unit -> deviceRepo.findAllByOwnUnit(unit.getName()).size() != 0)
.collect(toList());
}
return ResponseEntity.ok(unitsList); return ResponseEntity.ok(unitsList);
} }
...@@ -728,6 +677,11 @@ public class DeviceCheckController { ...@@ -728,6 +677,11 @@ public class DeviceCheckController {
@ApiOperation(value = "发起核查", notes = "对指定单位发起核查任务") @ApiOperation(value = "发起核查", notes = "对指定单位发起核查任务")
@PostMapping("/startCheck") @PostMapping("/startCheck")
public ResponseEntity startCheck(@RequestBody CheckCheckVo ccVO) { public ResponseEntity startCheck(@RequestBody CheckCheckVo ccVO) {
// 代管单位id
List<Integer> esIds = checkUnitService.findAllEscrow().stream().map(Units::getUnitId).collect(toList());
esIds.retainAll(ccVO.getUnitRange());
// 构建省的统计账单 // 构建省的统计账单
Integer startUnitId = ccVO.getUnitId(); Integer startUnitId = ccVO.getUnitId();
Units startUnit = unitsRepo.findById(startUnitId).get(); Units startUnit = unitsRepo.findById(startUnitId).get();
...@@ -756,6 +710,8 @@ public class DeviceCheckController { ...@@ -756,6 +710,8 @@ public class DeviceCheckController {
provStatTask = taskService.start(provStatTask); provStatTask = taskService.start(provStatTask);
desMap.put(provStatTask.getId(), ccVO.getRemark()); desMap.put(provStatTask.getId(), ccVO.getRemark());
//构建市的检查任务(level=2) //构建市的检查任务(level=2)
List<Units> examCheckUnits = checkedUnits.stream() List<Units> examCheckUnits = checkedUnits.stream()
.filter(units -> Arrays.asList(2).contains(units.getLevel())) .filter(units -> Arrays.asList(2).contains(units.getLevel()))
...@@ -763,7 +719,11 @@ public class DeviceCheckController { ...@@ -763,7 +719,11 @@ public class DeviceCheckController {
Map<Integer, Integer> cityExamIdMap = new HashMap<>(); Map<Integer, Integer> cityExamIdMap = new HashMap<>();
// 获取哪些市建立了统计任务
List<Integer> citys = new ArrayList<>();
for (Units unit : examCheckUnits) { for (Units unit : examCheckUnits) {
//构建市的统计账单 //构建市的统计账单
String cityTitle = unit.getName() + "检查统计"; String cityTitle = unit.getName() + "检查统计";
DeviceCheckStat cityCheckStat = initStatData(cityTitle, ccVO.getRemark(), 0, 0, unit.getName(), Collections.emptyList(), ccVO.getEndTime().atStartOfDay()); DeviceCheckStat cityCheckStat = initStatData(cityTitle, ccVO.getRemark(), 0, 0, unit.getName(), Collections.emptyList(), ccVO.getEndTime().atStartOfDay());
...@@ -780,9 +740,31 @@ public class DeviceCheckController { ...@@ -780,9 +740,31 @@ public class DeviceCheckController {
//将市的检查id记录下,以便设置市的自查任务的父级节点 //将市的检查id记录下,以便设置市的自查任务的父级节点
cityExamIdMap.put(unit.getUnitId(), cityStatTask.getId()); cityExamIdMap.put(unit.getUnitId(), cityStatTask.getId());
}
// 构建自查任务(levl = 0,1) tpye = 2 // 自动创建市里的任务
List<Units> inCitys = unitsCache.findByIdSubordinateAndOneself(unit.getUnitId());
CheckExamVo checkExamVo = new CheckExamVo();
checkExamVo.setDetail(Collections.singletonList(
CheckExamDetailVo.builder().
unitIds(
checkUnitService.findExistDevice(
inCitys.stream()
.filter(units -> units.getUnitId() != unit.getUnitId())
.map(Units::getUnitId)
.collect(toList())
)
)
.remark(ccVO.getRemark())
.build())
);
checkExamVo.setTitle(ccVO.getTitle());
checkExamVo.setUnitId(unit.getUnitId());
checkExamVo.setExamStatId(cityStatId);
checkExamVo.setEndTime(ccVO.getEndTime());
startExam(checkExamVo);
}
// 构建自核查任务(levl = 0,1) tpye = 2
List<Units> selfCheckUnits = checkedUnits.stream() List<Units> selfCheckUnits = checkedUnits.stream()
.filter(units -> Arrays.asList(0, 1).contains(units.getLevel()) || units.getType() == 2) .filter(units -> Arrays.asList(0, 1).contains(units.getLevel()) || units.getType() == 2)
.collect(toList()); .collect(toList());
...@@ -804,7 +786,7 @@ public class DeviceCheckController { ...@@ -804,7 +786,7 @@ public class DeviceCheckController {
for (Units unit : selfCheckUnits) { for (Units unit : selfCheckUnits) {
//核查组成员名称用当前登录用户 //核查组成员名称用当前登录用户
String names = loginUser.getName(); String names = "默认检查组";
// 如果是市level=2 的话,father Id为市的检查id // 如果是市level=2 的话,father Id为市的检查id
Integer fatherId = 0; Integer fatherId = 0;
...@@ -826,11 +808,13 @@ public class DeviceCheckController { ...@@ -826,11 +808,13 @@ public class DeviceCheckController {
initStatusId = CHECK_DETAIL_REGION_0.id; initStatusId = CHECK_DETAIL_REGION_0.id;
} }
// 3-1 构建被查单位的 自查账单 // 3-1 构建被查单位的 自核查账单
DeviceCheckDetail unitDetailDoc = DeviceCheckDetail.EmptyWithChecker(names + "|" + "默认备注", ccVO.getRemark(), 0, 0, 0, 0, unit.getName(), DeviceCheckDetail unitDetailDoc = DeviceCheckDetail
// todo 后期续检查获取UnitI的是否可行 .EmptyWithChecker(names + "|" + "默认备注", ccVO.getRemark(),
0, 0, 0, 0, unit.getName(),
unitsRepo.findByName(unit.getName()).getUnitId(), unitsRepo.findByName(unit.getName()).getUnitId(),
devInLib.getOrDefault(unit.getName(), new ArrayList<>()), devNotInLib.getOrDefault(unit.getName(), new ArrayList<>())); devInLib.getOrDefault(unit.getName(), new ArrayList<>()),
devNotInLib.getOrDefault(unit.getName(), new ArrayList<>()));
unitDetailDoc.setVar2(String.valueOf(initStatusId)); unitDetailDoc.setVar2(String.valueOf(initStatusId));
DeviceCheckDetail detail = detailRepo.save(unitDetailDoc); DeviceCheckDetail detail = detailRepo.save(unitDetailDoc);
// 将id放入统计中去 model -> areaName -> detailId // 将id放入统计中去 model -> areaName -> detailId
...@@ -848,10 +832,8 @@ public class DeviceCheckController { ...@@ -848,10 +832,8 @@ public class DeviceCheckController {
//处理ownUnit的代码 - 如果省直属有账号发给省直属的,没有账号就发给省做 用于处理没有账号的单位的可见性 //处理ownUnit的代码 - 如果省直属有账号发给省直属的,没有账号就发给省做 用于处理没有账号的单位的可见性
Integer ownUnitId = 0; Integer ownUnitId = 0;
List<User> userList = userService.findAllByUnite(unit.getUnitId()); boolean notHasAccount = unit.getEscrow() == 1;
boolean notHasAccount = userList.size() == 0; if (notHasAccount) {
if (unit.getType() == 2 && notHasAccount) {
ownUnitId = 1; ownUnitId = 1;
} else { } else {
ownUnitId = unit.getUnitId(); ownUnitId = unit.getUnitId();
...@@ -866,6 +848,7 @@ public class DeviceCheckController { ...@@ -866,6 +848,7 @@ public class DeviceCheckController {
return ResponseEntity.ok(ImmutableMap.of("msg", "发起核查成功")); return ResponseEntity.ok(ImmutableMap.of("msg", "发起核查成功"));
} }
/** /**
* 发起检查 * 发起检查
* <li>1. 添加发起核查bill记录</> * <li>1. 添加发起核查bill记录</>
...@@ -875,15 +858,22 @@ public class DeviceCheckController { ...@@ -875,15 +858,22 @@ public class DeviceCheckController {
* @param ceVo 核查发起对象 * @param ceVo 核查发起对象
*/ */
@ApiOperation(value = "发起检查", notes = "手动发起核查,需要指定参数") @ApiOperation(value = "发起检查", notes = "手动发起核查,需要指定参数")
@PostMapping("/startExam") @PostMapping("/startExam/old")
public ResponseEntity<ResultObj> startExam(@RequestBody CheckExamVo ceVo) { public ResponseEntity<ResultObj> startExam(@RequestBody CheckExamVo ceVo) {
//设置为
// 获取需要处理的代管单位集合
List<Integer> esIds = checkUnitService.findAllEscrow().stream().map(Units::getUnitId).collect(toList());
esIds.retainAll(ceVo.getDetail().get(0).getUnitIds());
//设置截止时间
ceVo.setEndTime(LocalDateTime.of(ceVo.getEndTime(), LocalTime.MAX).toLocalDate()); ceVo.setEndTime(LocalDateTime.of(ceVo.getEndTime(), LocalTime.MAX).toLocalDate());
//初始化数据结构 //初始化数据结构
List<Integer> detailIds = new ArrayList<>(); List<Integer> detailIds = new ArrayList<>();
Integer startUnitId = ceVo.getUnitId(); Integer startUnitId = ceVo.getUnitId();
Units startUnit = unitsRepo.findById(startUnitId).get(); Units startUnit = unitsRepo.findById(startUnitId).get();
List<CheckExamDetailVo> examDetailVos = ceVo.getDetail(); List<CheckExamDetailVo> examDetailVos = new ArrayList<>(ceVo.getDetail());
//如果是create检查,那么不需要添加自己单位的自查,如果是update检查,那么需要添加单位的自查 //如果是create检查,那么不需要添加自己单位的自查,如果是update检查,那么需要添加单位的自查
if (ceVo.getExamStatId() != 0) { if (ceVo.getExamStatId() != 0) {
//update //update
...@@ -891,14 +881,8 @@ public class DeviceCheckController { ...@@ -891,14 +881,8 @@ public class DeviceCheckController {
examDetailVos.add(examDetailVos.get(0).copy(startUnitId, "由省核查发起的自检查")); examDetailVos.add(examDetailVos.get(0).copy(startUnitId, "由省核查发起的自检查"));
} }
List<String> tmpString = new ArrayList<>();
// 拼接检查组和检查组成员 // 拼接检查组和检查组成员
for (CheckExamDetailVo vo : examDetailVos) { String groupUserString = "默认检查组,默认人员";
for (Integer u : vo.getUnitIds()) {
tmpString.add(vo.getGroupName() + "," + vo.getUserNames().stream().collect(joining(",")));
}
}
String groupUserString = tmpString.stream().collect(joining("|"));
List<Integer> unitIds = examDetailVos.stream().flatMap(cv -> cv.getUnitIds().stream()).collect(toList()); List<Integer> unitIds = examDetailVos.stream().flatMap(cv -> cv.getUnitIds().stream()).collect(toList());
List<Units> checkedUnits = unitsRepo.findAllById(unitIds); List<Units> checkedUnits = unitsRepo.findAllById(unitIds);
...@@ -909,6 +893,7 @@ public class DeviceCheckController { ...@@ -909,6 +893,7 @@ public class DeviceCheckController {
//根据examStatId来判断是update还是create 此时初始化的为指定检查区域的数据 //根据examStatId来判断是update还是create 此时初始化的为指定检查区域的数据
DeviceCheckStat initCheckStat = initStatData(checkedUnitNames, ceVo.getTitle(), groupUserString, 0, 0, startUnit.getName(), checkedUnits, ceVo.getEndTime().atStartOfDay()); DeviceCheckStat initCheckStat = initStatData(checkedUnitNames, ceVo.getTitle(), groupUserString, 0, 0, startUnit.getName(), checkedUnits, ceVo.getEndTime().atStartOfDay());
if (ceVo.getExamStatId() != 0) { if (ceVo.getExamStatId() != 0) {
// 这里是市转发给区的逻辑
DeviceCheckStat oriCheckStat = statRepo.findById(ceVo.getExamStatId()).get(); DeviceCheckStat oriCheckStat = statRepo.findById(ceVo.getExamStatId()).get();
oriCheckStat.setRemark(initCheckStat.getRemark()); oriCheckStat.setRemark(initCheckStat.getRemark());
oriCheckStat.setStatInfo(initCheckStat.getStatInfo()); oriCheckStat.setStatInfo(initCheckStat.getStatInfo());
...@@ -922,9 +907,6 @@ public class DeviceCheckController { ...@@ -922,9 +907,6 @@ public class DeviceCheckController {
provinceCheckStat.setCheckType(CheckType.CT_EXAM); provinceCheckStat.setCheckType(CheckType.CT_EXAM);
Integer statId = statRepo.save(provinceCheckStat).getId(); Integer statId = statRepo.save(provinceCheckStat).getId();
List<CheckDeviceStatVo> deviceStatVos = Arrays.stream(
Objects.requireNonNull(JacksonUtil.readValue(provinceCheckStat.getStatInfo(), CheckDeviceStatVo[].class)))
.collect(toList());
// 2-2 构建发起单位的 统计任务 // 2-2 构建发起单位的 统计任务
// 根据examStatId来判断要不要重新创建任务 // 根据examStatId来判断要不要重新创建任务
...@@ -933,7 +915,6 @@ public class DeviceCheckController { ...@@ -933,7 +915,6 @@ public class DeviceCheckController {
if (ceVo.getExamStatId() == 0) { if (ceVo.getExamStatId() == 0) {
cityStatTask = new Task(CHECK_EXAM_STAT_1.id, getUnitDateString(startUnit, ceVo.getTitle()), 0, ".0.", CONFIRM_CHECK_STAT.id, statId, startUnitId) cityStatTask = new Task(CHECK_EXAM_STAT_1.id, getUnitDateString(startUnit, ceVo.getTitle()), 0, ".0.", CONFIRM_CHECK_STAT.id, statId, startUnitId)
.parse2Bto(); .parse2Bto();
// cityStatTask.setRemark(String.valueOf(CHECK_EXAM_STAT_1.id));
cityStatTask.setCustomInfo("exam"); cityStatTask.setCustomInfo("exam");
cityStatTask.getInvolveUserIdList().add(currentUserId); cityStatTask.getInvolveUserIdList().add(currentUserId);
// 检查变为待办 // 检查变为待办
...@@ -957,13 +938,11 @@ public class DeviceCheckController { ...@@ -957,13 +938,11 @@ public class DeviceCheckController {
// 获取所有在库装备 ls == 2 or ls == 14 // 获取所有在库装备 ls == 2 or ls == 14
Map<String, List<DeviceLibrary>> devInLib = dcService.getAllDeviceLibraryList().stream() Map<String, List<DeviceLibrary>> devInLib = dcService.getAllDeviceLibraryList().stream()
.filter(d -> d.getLifeStatus() == 2 || d.getLifeStatus() == 14) .filter(d -> d.getLifeStatus() == 2 || d.getLifeStatus() == 14)
// .filter(device -> device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit)); .collect(groupingBy(DeviceLibrary::getOwnUnit));
// 非在库装备 ls !=2 and ls !=14 // 非在库装备 ls !=2 and ls !=14
Map<String, List<DeviceLibrary>> devNotInLib = dcService.getAllDeviceLibraryList().stream() Map<String, List<DeviceLibrary>> devNotInLib = dcService.getAllDeviceLibraryList().stream()
.filter(d -> d.getLifeStatus() != 2 && d.getLifeStatus() != 14) .filter(d -> d.getLifeStatus() != 2 && d.getLifeStatus() != 14)
// .filter(device -> !device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit)); .collect(groupingBy(DeviceLibrary::getOwnUnit));
// 3. 构建被核查单位的详情账单与Task // 3. 构建被核查单位的详情账单与Task
...@@ -976,7 +955,7 @@ public class DeviceCheckController { ...@@ -976,7 +955,7 @@ public class DeviceCheckController {
for (Integer u : uid) { for (Integer u : uid) {
Units unit = unitsRepo.findById(u).get(); Units unit = unitsRepo.findById(u).get();
String names = ed.getUserNames().stream().collect(joining(",")); String names = "默认名称";
// 根据发起人决定初始状态id 省发起人- 160 其他发起人 被查的市160 被查的是区140 // 根据发起人决定初始状态id 省发起人- 160 其他发起人 被查的市160 被查的是区140
int initTaskStatusId = 0; int initTaskStatusId = 0;
...@@ -993,23 +972,19 @@ public class DeviceCheckController { ...@@ -993,23 +972,19 @@ public class DeviceCheckController {
; ;
// 3-1 构建被查单位的 自查账单 // 3-1 构建被查单位的 自查账单
DeviceCheckDetail unitDetailDoc = DeviceCheckDetail.EmptyWithChecker(names + "|" + ed.getRemark(), ceVo.getTitle() + "%^&" + ed.getRemark(), 0, 0, 0, 0, unit.getName(), DeviceCheckDetail unitDetailDoc = DeviceCheckDetail.EmptyWithChecker(
// todo 后期需要检查是否可以根据单位名称得到unitId,检查逻辑 names + "|" + ed.getRemark(),
ceVo.getTitle() + "%^&" + ed.getRemark(),
0, 0, 0, 0,
unit.getName(),
unitsRepo.findByName(unit.getName()).getUnitId(), unitsRepo.findByName(unit.getName()).getUnitId(),
devInLib.getOrDefault(unit.getName(), new ArrayList<>()), devNotInLib.getOrDefault(unit.getName(), new ArrayList<>())); devInLib.getOrDefault(unit.getName(), new ArrayList<>()),
devNotInLib.getOrDefault(unit.getName(), new ArrayList<>()));
unitDetailDoc.setVar2(String.valueOf(initTaskStatusId)); unitDetailDoc.setVar2(String.valueOf(initTaskStatusId));
DeviceCheckDetail detail = detailRepo.save(unitDetailDoc); DeviceCheckDetail detail = detailRepo.save(unitDetailDoc);
detailIds.add(detail.getId()); detailIds.add(detail.getId());
// 将id放入统计中去 model -> areaName -> detailId // 将id放入统计中去 model -> areaName -> detailId
String areaName = auService.findOne(AuExample.UnitId, unit.getUnitId()).getName(); String areaName = auService.findOne(AuExample.UnitId, unit.getUnitId()).getName();
for (CheckDeviceStatVo statVo : deviceStatVos) {
for (CheckAreaStatVo asv : statVo.getAreaStatList()) {
if (asv.getAreaName().equals(areaName)) {
asv.setAreaStatId(statId);
asv.setAreaDetailId(detail.getId());
}
}
}
// 3-2 构建被查单位的 自查任务 (根据被查单位的级别来区分是县级状态是市级状态) // 3-2 构建被查单位的 自查任务 (根据被查单位的级别来区分是县级状态是市级状态)
...@@ -1020,12 +995,9 @@ public class DeviceCheckController { ...@@ -1020,12 +995,9 @@ public class DeviceCheckController {
desBillMap.put(detail.getId(), ed.getRemark()); desBillMap.put(detail.getId(), ed.getRemark());
desMap.put(checkedTask.getId(), ed.getRemark()); desMap.put(checkedTask.getId(), ed.getRemark());
} }
} }
// 4. 重新设置并保存统计账单 // 4. 重新设置并保存统计账单
provinceCheckStat.setStatInfo(JacksonUtil.toJSon(deviceStatVos));
statRepo.save(provinceCheckStat); statRepo.save(provinceCheckStat);
log.info("[核查模块] {}单位成功发起对 {} 单位的检查任务分发", startUnit.getName(), checkedUnitNames); log.info("[核查模块] {}单位成功发起对 {} 单位的检查任务分发", startUnit.getName(), checkedUnitNames);
return ResponseEntity.ok(new ResultObj<>( return ResponseEntity.ok(new ResultObj<>(
...@@ -1071,7 +1043,12 @@ public class DeviceCheckController { ...@@ -1071,7 +1043,12 @@ public class DeviceCheckController {
* 2. 更新task状态 * 2. 更新task状态
* 3. 更新job状态(完成A的job,同时发起b的job) * 3. 更新job状态(完成A的job,同时发起b的job)
* *
* @param id detail id
* @param assignUserId 指定专管员B来接受这件事 * @param assignUserId 指定专管员B来接受这件事
* @param checkResult
* @param terminalInfo
* @param detailVo
* @return
*/ */
@ApiOperation(value = "专管员A核查详情单") @ApiOperation(value = "专管员A核查详情单")
@PutMapping("/detail/A/{id}") @PutMapping("/detail/A/{id}")
...@@ -1171,6 +1148,7 @@ public class DeviceCheckController { ...@@ -1171,6 +1148,7 @@ public class DeviceCheckController {
@RequestParam int checkStatus, @RequestParam int checkStatus,
@RequestParam(required = false, defaultValue = "0") int checkUserAId, @RequestParam(required = false, defaultValue = "0") int checkUserAId,
@RequestParam(required = false, defaultValue = "0") int checkUserBId, @RequestParam(required = false, defaultValue = "0") int checkUserBId,
@RequestParam(required = false, defaultValue = "") String checkUserCName,
@RequestParam(required = false, defaultValue = "0") int isUpdate, @RequestParam(required = false, defaultValue = "0") int isUpdate,
@RequestParam String checkResult, @RequestParam String checkResult,
@RequestBody DetailVo detailVo @RequestBody DetailVo detailVo
...@@ -1185,7 +1163,7 @@ public class DeviceCheckController { ...@@ -1185,7 +1163,7 @@ public class DeviceCheckController {
//先更新checkUser //先更新checkUser
if (checkUserAId > 0 && checkUserBId > 0) { if (checkUserAId > 0 && checkUserBId > 0) {
detailRepo.updateCheckUser(id, checkUserAId, checkUserBId); detailRepo.updateCheckUserAbc(id, checkUserAId, checkUserBId, checkUserCName);
} }
// 审核通过与不通过的逻辑不同 // 审核通过与不通过的逻辑不同
...@@ -1298,7 +1276,7 @@ public class DeviceCheckController { ...@@ -1298,7 +1276,7 @@ public class DeviceCheckController {
removeDetailFromDcs(currentDetail, dcs); removeDetailFromDcs(currentDetail, dcs);
//撤销时恢复市统计任务; //撤销时恢复市统计任务;
if(END.id.equals(fatherTask.getBillStatus())) { if (END.id.equals(fatherTask.getBillStatus())) {
fatherTask.setBillStatus(StatusEnum.CHECK_EXAM_STAT_1.id); fatherTask.setBillStatus(StatusEnum.CHECK_EXAM_STAT_1.id);
taskService.update(fatherTask); taskService.update(fatherTask);
} }
...@@ -1332,7 +1310,7 @@ public class DeviceCheckController { ...@@ -1332,7 +1310,7 @@ public class DeviceCheckController {
@ApiOperation(value = "查询还有哪些单位的自查没有完成,给出单位名称") @ApiOperation(value = "查询还有哪些单位的自查没有完成,给出单位名称")
@GetMapping("/stat/shutdown/{statId}") @GetMapping("/stat/shutdown/{statId}")
public ResponseEntity queryNotFinish(@PathVariable Integer statId){ public ResponseEntity queryNotFinish(@PathVariable Integer statId) {
Task checkTask = taskRepo.findByBillIdAndBusinessType(statId, CONFIRM_CHECK_STAT.id).get(); Task checkTask = taskRepo.findByBillIdAndBusinessType(statId, CONFIRM_CHECK_STAT.id).get();
List<Task> l1Childs = taskRepo.findAllByParentTaskId(checkTask.getId()); List<Task> l1Childs = taskRepo.findAllByParentTaskId(checkTask.getId());
...@@ -1341,7 +1319,7 @@ public class DeviceCheckController { ...@@ -1341,7 +1319,7 @@ public class DeviceCheckController {
for (Task c1 : l1Childs) { for (Task c1 : l1Childs) {
if (predNodeType(c1).equals(CcNodeType.EXAM)) { if (predNodeType(c1).equals(CcNodeType.EXAM)) {
List<Task> detailTaskList = taskRepo.findAllByParentTaskId(c1.getId()); List<Task> detailTaskList = taskRepo.findAllByParentTaskId(c1.getId());
if(detailTaskList.isEmpty()) { if (detailTaskList.isEmpty()) {
unitNames.add(unitsRepo.findById(c1.getOwnUnit()).get().getName()); unitNames.add(unitsRepo.findById(c1.getOwnUnit()).get().getName());
} else { } else {
List<String> notEndUnitNames = detailTaskList List<String> notEndUnitNames = detailTaskList
...@@ -1350,7 +1328,7 @@ public class DeviceCheckController { ...@@ -1350,7 +1328,7 @@ public class DeviceCheckController {
.collect(toList()); .collect(toList());
unitNames.addAll(notEndUnitNames); unitNames.addAll(notEndUnitNames);
} }
}else if (predNodeType(c1).equals(CcNodeType.MANUAL)&& !c1.getBillStatus().equals(END.id)){ } else if (predNodeType(c1).equals(CcNodeType.MANUAL) && !c1.getBillStatus().equals(END.id)) {
String unitName = unitsRepo.findById(c1.getOwnUnit()).get().getName(); String unitName = unitsRepo.findById(c1.getOwnUnit()).get().getName();
unitNames.add(unitName); unitNames.add(unitName);
} }
...@@ -1364,7 +1342,7 @@ public class DeviceCheckController { ...@@ -1364,7 +1342,7 @@ public class DeviceCheckController {
public ResponseEntity shutDown(@PathVariable Integer statId) { public ResponseEntity shutDown(@PathVariable Integer statId) {
log.info("[核查模块] 终止任务 - 正在终止statId = {} 的统计任务", statId); log.info("[核查模块] 终止任务 - 正在终止statId = {} 的统计任务", statId);
Task checkTask = taskRepo.findByBillIdAndBusinessType(statId, CONFIRM_CHECK_STAT.id).get(); Task checkTask = taskRepo.findByBillIdAndBusinessType(statId, CONFIRM_CHECK_STAT.id).get();
// 将该stat任务置为20000,即终止 // 将该stat任务置为20001,即终止
unionLink(7, statId); unionLink(7, statId);
taskService.moveToSpecial(checkTask.parse2Bto(), CHECK_SHUT_DOWN); taskService.moveToSpecial(checkTask.parse2Bto(), CHECK_SHUT_DOWN);
supplyLogMsg(checkTask); supplyLogMsg(checkTask);
...@@ -1721,8 +1699,11 @@ public class DeviceCheckController { ...@@ -1721,8 +1699,11 @@ public class DeviceCheckController {
// 2级结构 - 检查统计 发起人单位是省,结果为等待省审核,发起人是市则是无 // 2级结构 - 检查统计 发起人单位是省,结果为等待省审核,发起人是市则是无
if (isTwoLevel) { if (isTwoLevel) {
Integer startUnitId = userService.findById(task.getCreateUserId()).getUnitsId(); Integer startUnitId = userService.findById(task.getCreateUserId()).getUnitsId();
if (startUnitId != 1) { Units units = unitsRepo.findById(startUnitId).get();
if (units.getLevel() != 1) {
if (units.getType() != 1) {
checkResult = "无"; checkResult = "无";
}
} else { } else {
//根据detail userC为省且任务状态是完结状态时 变为无误 否则是等待省审核 //根据detail userC为省且任务状态是完结状态时 变为无误 否则是等待省审核
Integer detailId = task.getBillId(); Integer detailId = task.getBillId();
...@@ -1854,6 +1835,15 @@ public class DeviceCheckController { ...@@ -1854,6 +1835,15 @@ public class DeviceCheckController {
messageService.add(msgBto); messageService.add(msgBto);
} }
private void supplyLogMsg2(Task node) {
// 手动补充终结日志
String adminUser = authenticationUtils.getAuthentication().getCurrentUserInfo().getName();
String shutDownMsg = String.format("专管员[%s]终止了该任务", adminUser);
TaskLogBto taskLog = new TaskLogBto(node.getId(), shutDownMsg);
taskLogService.addLog(taskLog);
}
/** /**
* 将detail里的detailString里的检查数字该为指定数值 * 将detail里的detailString里的检查数字该为指定数值
* *
...@@ -2343,36 +2333,11 @@ public class DeviceCheckController { ...@@ -2343,36 +2333,11 @@ public class DeviceCheckController {
* @return * @return
*/ */
private DeviceCheckStat initStatData(List<String> initUnitNames, String title, String remark, Integer checkAId, Integer checkBId, String startUnitName, List<Units> unitsList, LocalDateTime endTime) { private DeviceCheckStat initStatData(List<String> initUnitNames, String title, String remark, Integer checkAId, Integer checkBId, String startUnitName, List<Units> unitsList, LocalDateTime endTime) {
//获得要被统计的单位名列表
List<String> unitNameList = unitsList.stream()
.map(Units::getName)
.collect(toList());
List<AreaUnit> auList = unitsList.stream()
.map(units -> auService.findOne(AuExample.UnitId, units.getUnitId()))
.collect(toList());
List<CheckDeviceStatVo> cdv = dcService.getAllDeviceLibraryList()
.stream()
.filter(dev -> unitNameList.contains(dev.getOwnUnit()))
.filter(dev -> initUnitNames.contains(dev.getOwnUnit()))
// .filter(d->d.getLifeStatus() != 2 & d.getLifeStatus() != 14)
.map(transUtil::device2InitStatVo)
.collect(toList());
Map<String, List<CheckDeviceStatVo>> map = cdv.stream()
.collect(groupingBy(d -> d.getDeviceModel() + d.getDeviceName()));
Collection<CheckDeviceStatVo> statVos = cdv.stream()
.collect(toMap(d -> d.getDeviceModel() + d.getDeviceName(), Function.identity(), CheckDeviceStatVo::reduce))
.values();
return new DeviceCheckStat( return new DeviceCheckStat(
CheckType.CT_EXAM, CheckType.CT_EXAM,
title, title,
startUnitName + "待核查装备统计单", startUnitName + "待核查装备统计单",
JacksonUtil.toJSon(new ArrayList<>(statVos)), "[]",
checkAId, checkAId,
checkBId, checkBId,
remark, remark,
...@@ -2474,7 +2439,7 @@ public class DeviceCheckController { ...@@ -2474,7 +2439,7 @@ public class DeviceCheckController {
} }
//comprogress合并逻辑 if all 0->0 2->2 3->3 else 1 //comprogress合并逻辑 if all 0->0 2->2 3findBySystem->3 else 1
boolean isDone = casList.stream() boolean isDone = casList.stream()
.mapToInt(CheckAreaStatVo::getComProgress) .mapToInt(CheckAreaStatVo::getComProgress)
...@@ -2512,12 +2477,14 @@ public class DeviceCheckController { ...@@ -2512,12 +2477,14 @@ public class DeviceCheckController {
/** /**
* find unit's name by detail's unitId * find unit's name by detail's unitId
*
* @param deviceCheckDetail detail obj * @param deviceCheckDetail detail obj
* @return unit's name * @return unit's name
*/ */
private String findUnitName(DeviceCheckDetail deviceCheckDetail) { private String findUnitName(DeviceCheckDetail deviceCheckDetail) {
return unitsRepo.findById(deviceCheckDetail.getCheckUnitId()).get().getName(); return unitsRepo.findById(deviceCheckDetail.getCheckUnitId()).get().getName();
} }
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.tykj.dev.device.confirmcheck.controller;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.confirmcheck.common.CheckType;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.device.confirmcheck.entity.vo.*;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckLinkDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatDao;
import com.tykj.dev.device.confirmcheck.service.CheckUnitService;
import com.tykj.dev.device.confirmcheck.service.ConfirmCheckService;
import com.tykj.dev.device.confirmcheck.service.EscrowService;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
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.selfcheck.controller.SelfCheckController;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.service.TaskLogService;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.user.base.enums.AuExample;
import com.tykj.dev.device.user.cache.AreaCache;
import com.tykj.dev.device.user.read.service.MessageService;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import com.tykj.dev.device.user.subject.service.AuService;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.device.user.subject.service.UserService;
import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.misc.base.ResultObj;
import com.tykj.dev.misc.utils.JacksonUtil;
import com.tykj.dev.socket.MyWebSocket;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.function.Function;
import static com.tykj.dev.misc.base.BusinessEnum.CONFIRM_CHECK_DETAIL;
import static com.tykj.dev.misc.base.BusinessEnum.CONFIRM_CHECK_STAT;
import static com.tykj.dev.misc.base.StatusEnum.*;
import static com.tykj.dev.misc.base.StatusEnum.CHECK_DETAIL_CITY_0;
import static java.util.stream.Collectors.*;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/10/21
*/
@RestController
@RequestMapping(value = "/check")
@AutoDocument
@Slf4j
@Api(tags = "核查模块(检查)", description = "检查模块", position = 1)
public class ExamController {
@Autowired
private EscrowService escrowService;
@Autowired
private UnitsDao unitsRepo;
final String CHECK_RESULT_WAIT = "等待省查阅";
final String CHECK_RESULT_DONE = "已查阅";
Map<Integer, String> desMap = new HashMap<>();
Map<Integer, String> desBillMap = new HashMap<>();
private int specialDetailId = 0;
private List<String> specialUnits = new ArrayList<>();
@Autowired
private DeviceCheckLinkDao linkRepo;
@Autowired
private DeviceCheckStatDao statRepo;
@Autowired
private DeviceCheckBillDao billRepo;
@Autowired
private AreaDao areaRepo;
@Autowired
private DeviceLibraryDao deviceRepo;
@Autowired
private DeviceCheckDetailDao detailRepo;
@Autowired
private DeviceLibraryCacheService dcService;
@Autowired
private ObjTransUtil transUtil;
@Autowired
private TaskDao taskRepo;
@Autowired
private TaskService taskService;
@Autowired
private AuthenticationUtils authenticationUtils;
@Autowired
private AreaCache areaCache;
@Autowired
private AuService auService;
@Autowired
private ConfirmCheckService ccService;
@Autowired
private UserService userService;
@Autowired
private MyWebSocket myWebSocket;
@Autowired
private SelfCheckController selfCheckController;
@Autowired
private MessageService messageService;
@Autowired
private TaskLogService taskLogService;
@Autowired
private UnitsService unitsService;
@Autowired
private CheckUnitService checkUnitService;
@GetMapping("/escrow/unit")
@ApiOperation(value = "查询所有的代管单位,true_过滤无装备的单位,false_不过滤无装备的单位")
public ResponseEntity findEscrowUnit(@RequestParam(defaultValue = "false") boolean filter) {
return ResponseEntity.ok(new ResultObj<>(escrowService.findAllEscrowUnit(filter)));
}
@ApiOperation(value = "检查地区是否可以发起核查", notes = "检查地区是否可以发起核查")
@PostMapping("/checkPossible")
public ResponseEntity checkPossible(@RequestBody UnitIds unitIds) {
return ResponseEntity.ok(escrowService.checkPossible());
}
@GetMapping("/confirm/unit")
@ApiOperation(value = "查询默认的可以被核查单位的清单(省本直,省直属,市局),同时过滤掉那些已经被代管的单位")
public ResponseEntity findDefaultUnits(@RequestParam(defaultValue = "false") boolean province) {
Map<Integer, List<Units>> checkUnit = checkUnitService.findCheckUnit(province);
// 需要去除掉被托管的单位
ArrayList<Units> units = new ArrayList<>();
units.addAll(checkUnit.get(1));
units.addAll(checkUnit.get(2));
units.addAll(checkUnit.get(3));
return ResponseEntity.ok(new ResultObj<>(units));
}
/**
* 发起检查
* <li>1. 添加发起核查bill记录</>
* <li>2. 构建发起单位的统计账单与Task</>
* <li>3. 构建被核查单位的详情账单与Task</li>
*
* @param ceVo 核查发起对象
*/
@ApiOperation(value = "发起检查", notes = "手动发起核查,需要指定参数")
@PostMapping("/confirm/startExam")
public ResponseEntity<ResultObj> startExam(@RequestBody CheckExamVo ceVo) {
// 获取需要处理的代管单位集合
List<Integer> esIds = checkUnitService.findAllEscrow().stream().map(Units::getUnitId).collect(toList());
esIds.retainAll(ceVo.getDetail().get(0).getUnitIds());
//设置截止时间
ceVo.setEndTime(LocalDateTime.of(ceVo.getEndTime(), LocalTime.MAX).toLocalDate());
//初始化数据结构
List<Integer> detailIds = new ArrayList<>();
Integer startUnitId = ceVo.getUnitId();
Units startUnit = unitsRepo.findById(startUnitId).get();
List<CheckExamDetailVo> examDetailVos = new ArrayList<>(ceVo.getDetail());
//如果是create检查,那么不需要添加自己单位的自查,如果是update检查,那么需要添加单位的自查
if (ceVo.getExamStatId() != 0) {
//update
log.info("[核查模块] update核查,自动添加id = {}市的自核查任务", startUnitId);
examDetailVos.add(examDetailVos.get(0).copy(startUnitId, "由省核查发起的自检查"));
}
// 拼接检查组和检查组成员
String groupUserString = "默认检查组,默认人员";
List<Integer> unitIds = examDetailVos.stream().flatMap(cv -> cv.getUnitIds().stream()).collect(toList());
List<Units> checkedUnits = unitsRepo.findAllById(unitIds);
List<String> checkedUnitNames = checkedUnits.stream().map(Units::getName).collect(toList());
// 2-1 构建发起单位的 统计账单
DeviceCheckStat provinceCheckStat;
//根据examStatId来判断是update还是create 此时初始化的为指定检查区域的数据
DeviceCheckStat initCheckStat = initStatData(checkedUnitNames, ceVo.getTitle(), groupUserString, 0, 0, startUnit.getName(), checkedUnits, ceVo.getEndTime().atStartOfDay());
if (ceVo.getExamStatId() != 0) {
// 这里是市转发给区的逻辑
DeviceCheckStat oriCheckStat = statRepo.findById(ceVo.getExamStatId()).get();
oriCheckStat.setRemark(initCheckStat.getRemark());
oriCheckStat.setStatInfo(initCheckStat.getStatInfo());
provinceCheckStat = oriCheckStat;
} else {
provinceCheckStat = initCheckStat;
}
log.info("[核查模块]发起手动检查,发起单位为{},被查单位为{}", startUnit.getName(), checkedUnitNames);
provinceCheckStat.setCheckType(CheckType.CT_EXAM);
// statId 该任务为最上级的stat任务,如果是省发起就是省最上级的统计,市发起,则是市最上级的统计
Integer statId = statRepo.save(provinceCheckStat).getId();
// 2-2 构建发起单位的 统计任务
// 2-2-1 如果是省级账户发起的检查,需要构建省局、省直属、市级的统计任务
// 根据examStatId来判断要不要重新创建任务
Integer currentUserId = authenticationUtils.getAuthentication().getCurrentUserInfo().getUserId();
TaskBto cityStatTask;
if (ceVo.getExamStatId() == 0) {
cityStatTask = new Task(CHECK_EXAM_STAT_1.id,
getUnitDateString(startUnit, ceVo.getTitle()),
0, ".0.", CONFIRM_CHECK_STAT.id, statId, startUnitId)
.parse2Bto();
cityStatTask.setCustomInfo("exam");
cityStatTask.getInvolveUserIdList().add(currentUserId);
// 检查变为待办
cityStatTask.getInvolveUserIdList().add(0);
cityStatTask.setCurrentPoint(1);
cityStatTask = taskService.start(cityStatTask);
} else {
// 将原来的待办改为跟踪
cityStatTask = taskRepo.findByBillIdAndBusinessType(ceVo.getExamStatId(), CONFIRM_CHECK_STAT.id).get().parse2Bto();
//检查变为待办
cityStatTask.getInvolveUserIdList().add(0);
// cityStatTask.setRemark(String.valueOf(CHECK_EXAM_STAT_1.id));
cityStatTask.setCustomInfo("exam");
cityStatTask.setCurrentPoint(cityStatTask.getCurrentPoint() + 1);
cityStatTask.setCreateUserId(currentUserId);
cityStatTask.setBillStatus(CHECK_EXAM_STAT_1.id);
taskService.update(cityStatTask);
}
// 3 构建被查单位的 自查账单 与 自查任务
// 获取所有在库装备 ls == 2 or ls == 14
Map<String, List<DeviceLibrary>> devInLib = dcService.getAllDeviceLibraryList().stream()
.filter(d -> d.getLifeStatus() == 2 || d.getLifeStatus() == 14)
.collect(groupingBy(DeviceLibrary::getOwnUnit));
// 非在库装备 ls !=2 and ls !=14
Map<String, List<DeviceLibrary>> devNotInLib = dcService.getAllDeviceLibraryList().stream()
.filter(d -> d.getLifeStatus() != 2 && d.getLifeStatus() != 14)
.collect(groupingBy(DeviceLibrary::getOwnUnit));
// 3. 构建被核查单位的详情账单与Task
// 对每个需要核查的单位构建其detail账单与task
boolean isProvUser = authenticationUtils.getAuthentication()
.getCurrentUserInfo().getUnitsId() == 1;
for (CheckExamDetailVo ed : examDetailVos) {
List<Integer> uid = ed.getUnitIds();
for (Integer u : uid) {
Units unit = unitsRepo.findById(u).get();
String names = "默认名称";
// 根据发起人决定初始状态id 省发起人- 160 其他发起人 被查的市160 被查的是区140
int initTaskStatusId = 0;
if (isProvUser) {
initTaskStatusId = CHECK_DETAIL_CITY_0.id;
} else {
//再根据被查单位的级别 level = 3 区140 level =2市 160
if (unit.getLevel() == 3) {
initTaskStatusId = CHECK_DETAIL_REGION_0.id;
} else {
initTaskStatusId = CHECK_DETAIL_CITY_0.id;
}
}
// 3-1 构建被查单位的 自查账单
DeviceCheckDetail unitDetailDoc = DeviceCheckDetail.EmptyWithChecker(
names + "|" + ed.getRemark(),
ceVo.getTitle() + "%^&" + ed.getRemark(),
0, 0, 0, 0,
unit.getName(),
unitsRepo.findByName(unit.getName()).getUnitId(),
devInLib.getOrDefault(unit.getName(), new ArrayList<>()),
devNotInLib.getOrDefault(unit.getName(), new ArrayList<>()));
unitDetailDoc.setVar2(String.valueOf(initTaskStatusId));
DeviceCheckDetail detail = detailRepo.save(unitDetailDoc);
detailIds.add(detail.getId());
// 将id放入统计中去 model -> areaName -> detailId
String areaName = auService.findOne(AuExample.UnitId, unit.getUnitId()).getName();
// 3-2 构建被查单位的 自查任务 (根据被查单位的级别来区分是县级状态是市级状态)
TaskBto checkedTask = new TaskBto(
initTaskStatusId,
getUnitDateString(unit, ceVo.getTitle()),
cityStatTask.getId(),
addNode(cityStatTask.getNodeIdDetail(), cityStatTask.getId()),
CONFIRM_CHECK_DETAIL.id,
detail.getId(),
unit.getUnitId(),
0);
// checkedTask.setRemark(String.valueOf(CHECK_EXAM_DETAIL_0.id));
checkedTask.setCustomInfo("manual");
checkedTask = taskService.start(checkedTask);
desBillMap.put(detail.getId(), ed.getRemark());
desMap.put(checkedTask.getId(), ed.getRemark());
}
}
// 4. 构建直属单位的统计,只有省会发起直属单位的检查/核查,不涉及转发,因此examStatId = 0,且unit 的level = 1,type =1时才会触发
if (ceVo.getExamStatId() == 0 && startUnit.getType() == 1 && startUnit.getLevel() == 1) {
DeviceCheckStat escrowStat = initStatData(
checkedUnitNames,
ceVo.getTitle(),
groupUserString,
0,
0,
startUnit.getName(),
checkedUnits,
ceVo.getEndTime().atStartOfDay()
);
escrowStat.setSubtitle("省直属单位待核查装备统计单");
DeviceCheckStat EsSaveStat = statRepo.save(escrowStat);
TaskBto esTaskBto;
esTaskBto = new Task(CHECK_EXAM_STAT_0.id,
"[省直属单位]" + ceVo.getTitle(),
cityStatTask.getId(), ".0.", CONFIRM_CHECK_STAT.id, EsSaveStat.getId(), startUnitId)
.parse2Bto();
esTaskBto.setCustomInfo("exam");
esTaskBto.getInvolveUserIdList().add(currentUserId);
// 检查变为待办
esTaskBto.getInvolveUserIdList().add(0);
esTaskBto.setCurrentPoint(1);
TaskBto start = taskService.start(esTaskBto);
Optional<List<Task>> esTask = taskRepo.findAllByOwnUnitInAndParentTaskId(esIds, cityStatTask.getId());
if (esTask.isPresent()) {
List<Task> tasks = esTask.get();
tasks.forEach(o -> o.setParentTaskId(start.getId()));
taskRepo.saveAll(tasks);
}
}
// 构建
if (ceVo.getExamStatId() == 0 && startUnit.getType() == 1 && startUnit.getLevel() == 1) {
}
// 5. 重新设置并保存统计账单
statRepo.save(provinceCheckStat);
log.info("[核查模块] {}单位成功发起对 {} 单位的检查任务分发", startUnit.getName(), checkedUnitNames);
return ResponseEntity.ok(new ResultObj<>(
ImmutableMap.of("statIds", statId, "detailIds", detailIds),
String.format("[核查模块] [%s]单位成功发起对 [%s] 单位的检查任务分发", startUnit.getName(), checkedUnitNames)
));
}
/**
* @param initUnitNames 初始化指定单位的数据
* @return
*/
private DeviceCheckStat initStatData(List<String> initUnitNames, String title, String remark, Integer checkAId, Integer checkBId, String startUnitName, List<Units> unitsList, LocalDateTime endTime) {
return new DeviceCheckStat(
CheckType.CT_EXAM,
title,
startUnitName + "待核查装备统计单",
"[]",
checkAId,
checkBId,
remark,
endTime);
}
private String getUnitDateString(Units units, String title) {
return "[" + units.getUnitDesc() + "]" + title;
}
private String addNode(String originalNode, Integer fatherId) {
return originalNode + fatherId + ".";
}
}
...@@ -161,6 +161,9 @@ public class DeviceCheckDetail extends BaseEntity { ...@@ -161,6 +161,9 @@ public class DeviceCheckDetail extends BaseEntity {
@Transient @Transient
private List<FileRet> checkFileList = new ArrayList<>(); private List<FileRet> checkFileList = new ArrayList<>();
@ApiModelProperty(value = "手持终端信息字段")
private String checkCName = "";
/** /**
* 用于生成市级的核查详情账单的构造函数 * 用于生成市级的核查详情账单的构造函数
*/ */
......
...@@ -55,7 +55,7 @@ public class DeviceCheckStat extends BaseEntity { ...@@ -55,7 +55,7 @@ public class DeviceCheckStat extends BaseEntity {
private String statInfo; private String statInfo;
/** /**
* 检查类型,数据库里的数据结构是int类型,其中1为核查,2为检查 * 检查类型,数据库里的数据结构是int类型,其中0为核查,1为检查
* *
* @see com.tykj.dev.device.confirmcheck.common.CheckTypeConvert * @see com.tykj.dev.device.confirmcheck.common.CheckTypeConvert
*/ */
......
...@@ -3,6 +3,7 @@ package com.tykj.dev.device.confirmcheck.entity.vo; ...@@ -3,6 +3,7 @@ package com.tykj.dev.device.confirmcheck.entity.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -19,6 +20,7 @@ import java.util.List; ...@@ -19,6 +20,7 @@ import java.util.List;
@ApiModel("核查发起细节") @ApiModel("核查发起细节")
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder
public class CheckExamDetailVo { public class CheckExamDetailVo {
@ApiModelProperty(name = "核查组名称") @ApiModelProperty(name = "核查组名称")
......
package com.tykj.dev.device.confirmcheck.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDate;
import java.util.List;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/11/21
*/
@Data
@ApiModel("检查发起对象")
public class CheckExamStartVo {
@ApiModelProperty(name = "业务标题", example = "浙江省手动核查测试")
private String title;
@ApiModelProperty(name = "截止时间", example = "2021-01-12")
private LocalDate endTime ;
@ApiModelProperty(name = "发起单位的id号")
private Integer unitId;
@ApiModelProperty(name = "检查统计业务id,如果是直接创建则给0",example = "0")
private Integer examStatId;
@ApiModelProperty(name = "需要被检查的区域id")
private List<Integer> unitIds;
@ApiModelProperty(name = "备注")
private String remark;
}
...@@ -33,4 +33,5 @@ public class CheckExamVo { ...@@ -33,4 +33,5 @@ public class CheckExamVo {
@ApiModelProperty(name = "发起检查细节") @ApiModelProperty(name = "发起检查细节")
@JSONField(name = "detail") @JSONField(name = "detail")
private List<CheckExamDetailVo> detail; private List<CheckExamDetailVo> detail;
} }
package com.tykj.dev.device.confirmcheck.entity.vo;
import com.tykj.dev.device.user.subject.entity.Units;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/11/21
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CheckUnitsExistVo {
private Units units;
private boolean exist;
}
package com.tykj.dev.device.confirmcheck.entity.vo; package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -13,6 +14,7 @@ import lombok.NoArgsConstructor; ...@@ -13,6 +14,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Data @Data
@Builder
public class LinkCheckDetail { public class LinkCheckDetail {
/** /**
......
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
* LinkEscrowDetail
*
* @author Ozoz.L cnljj1995@gmail.com
* on 11/10/21
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class LinkEscrowDetail {
/**
* 代管业务ID
*/
private Integer id;
private String checkUnit;
private String checkSituation;
private String checkResult;
private int remark;
}
...@@ -52,7 +52,7 @@ public class LinkVo { ...@@ -52,7 +52,7 @@ public class LinkVo {
private List<LinkCheckDetail> lcDetail; private List<LinkCheckDetail> lcDetail;
/** /**
* 里面装的都是自查数据 * 里面装的都是自查数据
*/ */
private List<LinkExamDetail> leDetail; private List<LinkExamDetail> leDetail;
......
...@@ -26,7 +26,7 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetail, I ...@@ -26,7 +26,7 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetail, I
@Modifying @Modifying
@Query("update DeviceCheckDetail o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6,o.terminalInfo=?7 where o.id=?1") @Query("update DeviceCheckDetail o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6,o.terminalInfo=?7 where o.id=?1")
void updateCheckDetailWithT(Integer id, String checkDetail, String checkResult, int userAId, int userBId, Integer checkedCount,String terminalInfo); void updateCheckDetailWithT(Integer id, String checkDetail, String checkResult, int userAId, int userBId, Integer checkedCount, String terminalInfo);
/** /**
* 根据id更新checkDetail 用于专管员B检查 * 根据id更新checkDetail 用于专管员B检查
...@@ -52,4 +52,15 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetail, I ...@@ -52,4 +52,15 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetail, I
@Modifying @Modifying
@Query("update DeviceCheckDetail o set o.checkUserAId =?2,o.checkUserBId=?3 where o.id =?1") @Query("update DeviceCheckDetail o set o.checkUserAId =?2,o.checkUserBId=?3 where o.id =?1")
void updateCheckUser(int id, int checkUserAId, int checkUserBId); void updateCheckUser(int id, int checkUserAId, int checkUserBId);
/**
* 更新 checkUserAId 与 checkUserBId
*
* @param id detailId
* @param checkUserAId 核查组成员A
* @param checkUserBId 核查组成员B
*/
@Modifying
@Query("update DeviceCheckDetail o set o.checkUserAId =?2,o.checkUserBId=?3, o.checkCName = ?4 where o.id =?1")
void updateCheckUserAbc(int id, int checkUserAId, int checkUserBId, String checkCName);
} }
...@@ -3,6 +3,9 @@ package com.tykj.dev.device.confirmcheck.repository; ...@@ -3,6 +3,9 @@ package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
import java.util.Optional;
/** /**
* DeviceCheckStatRepo. * DeviceCheckStatRepo.
* *
...@@ -10,4 +13,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -10,4 +13,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @since 2020/8/16 at 5:26 下午 * @since 2020/8/16 at 5:26 下午
*/ */
public interface DeviceCheckStatDao extends JpaRepository<DeviceCheckStat, Integer> { public interface DeviceCheckStatDao extends JpaRepository<DeviceCheckStat, Integer> {
} }
package com.tykj.dev.device.confirmcheck.service;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckUnitsExistVo;
import com.tykj.dev.device.user.subject.entity.Units;
import java.util.List;
import java.util.Map;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/10/21
*/
public interface CheckUnitService {
/**
* 查询核查/检查的单位
* 包括省级、省本级、市
* @param isCheck true_过滤掉省(检查用),false_不过滤省(核查用)
* @return map
*/
Map<Integer, List<Units>> findCheckUnit(boolean isCheck);
List<Units> checkPossible(List<Integer> ids, boolean isCheck);
/**
* 根据给定的单位给出没有装备的单位
* @param ids 单位id
* @return 没有装备的单位id
*/
List<Integer> findUnExistDevice(List<Integer> ids);
List<Integer> findExistDevice(List<Integer> ids);
/**
* 获取所有代管戴单位
* @return list
*/
List<Units> findAllEscrow();
}
package com.tykj.dev.device.confirmcheck.service;
import com.google.common.collect.ImmutableMap;
import com.tykj.dev.device.user.subject.entity.Units;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/9/21
*/
@Service
public interface EscrowService {
/**
* 查询所有代管的单位
* @return units
*/
List<Units> findAllEscrowUnit(boolean filter);
/**
* 检查代管单位是否有装备
* @return map
*/
ImmutableMap checkPossible();
}
package com.tykj.dev.device.confirmcheck.service;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckExamVo;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/14/21
*/
public interface ExamCheckService {
/**
* 发起检查
* @param checkExamVo vo
*/
void startExam(CheckExamVo checkExamVo);
}
package com.tykj.dev.device.confirmcheck.service.impl;
import com.google.common.collect.ImmutableMap;
import com.tykj.dev.device.confirmcheck.service.CheckUnitService;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.AreaExhibitionDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Units;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/10/21
*/
@Slf4j
@Service
public class CheckUnitServiceImpl implements CheckUnitService {
@Autowired
private UnitsCache unitsCache;
@Autowired
private UnitsDao unitsRepo;
@Autowired
private AreaDao areaRepo;
@Autowired
private DeviceLibraryDao deviceRepo;
@Autowired
private AreaExhibitionDao AreaExRepo;
@Override
public Map<Integer, List<Units>> findCheckUnit(boolean filter) {
// 1 构建省级单位集合
List<Units> provinceUnits = new ArrayList<>(unitsRepo
.findAllByTypeInAndLevelIn(new ArrayList<>(2), new ArrayList<>(1))
.orElse(Collections.emptyList()));
// 过滤省局,逻辑为:如果不过滤,就加上省局
if (!filter) {
List<Units> pro = unitsRepo.
findAllByTypeAndLevel(1, 1);
provinceUnits.add(pro.get(0));
}
// 2 构建省直属单位集合
List<Units> esAUnits = unitsRepo.findAllByEscrow(1).orElse(Collections.emptyList());
// 3 构建市
List<Units> cityUnits = unitsRepo.findAllByLevel(2);
if (filter) {
cityUnits.forEach(
units -> units.setName(areaRepo.findNameById(units.getAreaId()))
);
}
return ImmutableMap.of(1, provinceUnits, 2, esAUnits, 3, cityUnits);
}
@Override
public List<Units> checkPossible(List<Integer> ids, boolean isCheck) {
if (isCheck) {
return unitsRepo.findAllById(findUnExistDevice(ids));
}
List<Integer> rs = new ArrayList<>(ids);
// 市本级id
List<Integer> city = unitsRepo.findAllByLevel(2).stream().map(Units::getUnitId).collect(toList());
// 市本级需要验证的id
List<Integer> contains = ids.stream().filter(city::contains).collect(toList());
for (Integer contain : contains) {
List<Integer> collect = unitsCache.findByIdSubordinateAndOneself(contain).stream().map(Units::getUnitId).collect(toList());
rs.addAll(collect);
}
// 去重
List<Integer> unitsIds = findUnExistDevice(rs);
return unitsRepo.findAllById(unitsIds.stream().distinct().collect(toList()));
}
@Override
public List<Integer> findUnExistDevice(List<Integer> ids) {
return ids.stream()
.filter(id -> deviceRepo
.findAllByOwnUnit(
unitsRepo.findById(id)
.orElse(Units.builder().name("未知").build()).getName())
.size() == 0)
.collect(Collectors.toList());
}
@Override
public List<Integer> findExistDevice(List<Integer> ids) {
return ids.stream()
.filter(id -> deviceRepo
.findAllByOwnUnit(
unitsRepo.findById(id)
.orElse(Units.builder().name("未知").build()).getName())
.size() != 0)
.collect(Collectors.toList()); }
@Override
public List<Units> findAllEscrow() {
return unitsRepo.findAllByEscrow(1).orElse(Collections.emptyList());
}
}
...@@ -336,7 +336,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine ...@@ -336,7 +336,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
Units unit = unitsRepo.findById(checkBillSelectVo.getUnitId()).get(); Units unit = unitsRepo.findById(checkBillSelectVo.getUnitId()).get();
if(unit.getLevel() == 2) { if(unit.getLevel() == 2) {
Specification<DeviceCheckDetail> pred = Specifications.<DeviceCheckDetail>and() Specification<DeviceCheckDetail> pred = Specifications.<DeviceCheckDetail>and()
.eq("checkUnit", unit.getName()) .eq("checkUnitId", checkBillSelectVo.getUnitId())
.build(); .build();
List<CheckDetailVo> detailVoList = detailRepo.findAll(pred).stream() List<CheckDetailVo> detailVoList = detailRepo.findAll(pred).stream()
.map(transUtil::CheckDetailDo2Vo) .map(transUtil::CheckDetailDo2Vo)
...@@ -351,7 +351,8 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine ...@@ -351,7 +351,8 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
checkStatTableVo.setShowType(1); checkStatTableVo.setShowType(1);
checkStatTableVo.setCreateTime(TimestampUtil.dateToLocalDateTime(checkDetailVo.getCheckTime())); checkStatTableVo.setCreateTime(TimestampUtil.dateToLocalDateTime(checkDetailVo.getCheckTime()));
//设置完成情况 //设置完成情况
List<TaskUserVo> taskUserVos = taskService.findByBillIdAndBusinessType(checkDetailVo.getId(), 8).stream().map(Task::parse2Bto).map(TaskBto::toVo).collect(toList()); List<TaskUserVo> taskUserVos = taskService.findByBillIdAndBusinessType(checkDetailVo.getId(), 8)
.stream().map(Task::parse2Bto).map(TaskBto::toVo).collect(toList());
if (taskUserVos.size() == 1) { if (taskUserVos.size() == 1) {
checkStatTableVo.setCompletion(taskUserVos.get(0).getStatus()); checkStatTableVo.setCompletion(taskUserVos.get(0).getStatus());
} }
...@@ -360,6 +361,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine ...@@ -360,6 +361,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
tableVos.addAll(cityDetailToStatList); tableVos.addAll(cityDetailToStatList);
} }
return PageUtil.getPerPage(checkBillSelectVo.getPage(),checkBillSelectVo.getSize(),tableVos,checkBillSelectVo.getPageable()); return PageUtil.getPerPage(checkBillSelectVo.getPage(),checkBillSelectVo.getSize(),tableVos,checkBillSelectVo.getPageable());
} }
......
package com.tykj.dev.device.confirmcheck.service.impl;
import com.google.common.collect.ImmutableMap;
import com.tykj.dev.device.confirmcheck.service.EscrowService;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Units;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/9/21
*/
@Service
public class EscrowServiceImpl implements EscrowService {
@Autowired
private UnitsDao unitsDao;
@Autowired
private DeviceLibraryDao deviceRepo;
@Override
public List<Units> findAllEscrowUnit(boolean filter) {
List<Units> units = unitsDao.findAll().stream().filter(Units::isEscrow).collect(Collectors.toList());
if (filter) {
units = units.stream()
.filter(unit -> deviceRepo.findAllByOwnUnit(unit.getName()).size() != 0)
.collect(toList());
}
return units;
}
@Override
public ImmutableMap checkPossible() {
List<Units> units = unitsDao.findAll().stream().filter(Units::isEscrow).collect(Collectors.toList());
List<String> unitsStr = units.stream()
.filter(unit -> deviceRepo.findAllByOwnUnit(unit.getName()).size() == 0)
.map(Units::getName).collect(toList());
boolean findEmpty = unitsStr.isEmpty();
StringBuilder alertString = new StringBuilder("[");
if (!findEmpty) {
for (String s : unitsStr) {
alertString.append(s);
}
}
return ImmutableMap.of("empty", findEmpty, "msg", alertString + "]代管单位没有装备数据,将不进行检查,是否继续!");
}
}
package com.tykj.dev.device.confirmcheck.service.impl;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckExamVo;
import com.tykj.dev.device.confirmcheck.service.ExamCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author Ozoz.L cnljj1995@gmail.com
* on 11/14/21
*/
@Slf4j
@Service
public class ExamCheckServiceImpl implements ExamCheckService {
@Override
public void startExam(CheckExamVo checkExamVo) {
// 只有省级和市本级可以发起检查
//
}
}
...@@ -214,20 +214,20 @@ public class ObjTransUtil { ...@@ -214,20 +214,20 @@ public class ObjTransUtil {
String userBName = checkUserB == null ? "" : checkUserB.getName(); String userBName = checkUserB == null ? "" : checkUserB.getName();
//解析JSON并赋值 //解析JSON并赋值
ObjectMapper objectMapper = new ObjectMapper(); // ObjectMapper objectMapper = new ObjectMapper();
CheckDeviceStatVo[] checkDeviceStatVos = new CheckDeviceStatVo[0]; // CheckDeviceStatVo[] checkDeviceStatVos = new CheckDeviceStatVo[0];
try { // try {
boolean isArray = objectMapper.readTree(statDo.getStatInfo()).isArray(); // boolean isArray = objectMapper.readTree(statDo.getStatInfo()).isArray();
if (isArray) { // if (isArray) {
checkDeviceStatVos = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo[].class); // checkDeviceStatVos = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo[].class);
} else { // } else {
CheckDeviceStatVo checkDeviceStatVo = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo.class); // CheckDeviceStatVo checkDeviceStatVo = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo.class);
checkDeviceStatVos = new CheckDeviceStatVo[]{checkDeviceStatVo}; // checkDeviceStatVos = new CheckDeviceStatVo[]{checkDeviceStatVo};
} // }
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
initialStat.setDeviceStatVoList(Arrays.asList(checkDeviceStatVos)); initialStat.setDeviceStatVoList(Collections.emptyList());
initialStat.setCheckUserAName(userAName); initialStat.setCheckUserAName(userAName);
initialStat.setCheckUserBName(userBName); initialStat.setCheckUserBName(userBName);
initialStat.setCheckType(statDo.getCheckType().getId()); initialStat.setCheckType(statDo.getCheckType().getId());
......
...@@ -14,6 +14,8 @@ import java.util.Optional; ...@@ -14,6 +14,8 @@ import java.util.Optional;
*/ */
public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationExecutor<Task> { public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationExecutor<Task> {
Optional<List<Task>> findAllByOwnUnitInAndParentTaskId(List<Integer> ownIds, Integer parentId);
/** /**
* @param billId 账单id * @param billId 账单id
* @param businessType 业务类型 * @param businessType 业务类型
......
...@@ -1236,8 +1236,8 @@ public class TaskServiceImpl implements TaskService { ...@@ -1236,8 +1236,8 @@ public class TaskServiceImpl implements TaskService {
} }
@Override @Override
public void moveAllSonNodeToEnd(Integer taaskId) { public void moveAllSonNodeToEnd(Integer taskId) {
List<Task> tasks = taskDao.findAllByParentTaskId(taaskId); List<Task> tasks = taskDao.findAllByParentTaskId(taskId);
if (tasks.size()>0){ if (tasks.size()>0){
tasks.forEach(task -> { tasks.forEach(task -> {
moveToEnd(task.parse2Bto()); moveToEnd(task.parse2Bto());
......
...@@ -4,6 +4,7 @@ import com.tykj.dev.device.user.subject.entity.Units; ...@@ -4,6 +4,7 @@ import com.tykj.dev.device.user.subject.entity.Units;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -11,6 +12,23 @@ import java.util.Optional; ...@@ -11,6 +12,23 @@ import java.util.Optional;
@Repository @Repository
public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificationExecutor<Units> { public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificationExecutor<Units> {
/**
* 查询是否代管的单位
* @param tag 1_代管,0_非代管
* @return units
*/
Optional<List<Units>> findAllByEscrow(Integer tag);
/**
* 根据Type和level查询单位
* @return units
*/
Optional<List<Units>> findAllByTypeInAndLevelIn(List<Integer> type, List<Integer> level);
List<Units> findAllByTypeAndLevel(Integer type, Integer level);
List<Units> findAllByLevel(Integer level); List<Units> findAllByLevel(Integer level);
List<Units> findAllByAreaId(Integer areaId); List<Units> findAllByAreaId(Integer areaId);
...@@ -45,6 +63,10 @@ public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificatio ...@@ -45,6 +63,10 @@ public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificatio
Units findByAreaIdAndLevel(Integer areaId, Integer level); Units findByAreaIdAndLevel(Integer areaId, Integer level);
default Units findByAreaIdEquals() {
return findByAreaIdEquals();
}
Units findByAreaIdEquals(Integer areaId); Units findByAreaIdEquals(Integer areaId);
List<Units> findAllByLevelIn(List<Integer> levels); List<Units> findAllByLevelIn(List<Integer> levels);
......
...@@ -7,6 +7,7 @@ import com.tykj.dev.misc.base.BeanHelper; ...@@ -7,6 +7,7 @@ import com.tykj.dev.misc.base.BeanHelper;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
...@@ -31,6 +32,7 @@ import java.util.UUID; ...@@ -31,6 +32,7 @@ import java.util.UUID;
@ApiModel(value = "单位对象", description = "单位详细信息") @ApiModel(value = "单位对象", description = "单位详细信息")
@Where(clause = "id_del = 0") @Where(clause = "id_del = 0")
@SQLDelete(sql = "update user set id_del = 1 where id = ?") @SQLDelete(sql = "update user set id_del = 1 where id = ?")
@Builder
public class Units { public class Units {
/** /**
* 单位id * 单位id
...@@ -70,6 +72,7 @@ public class Units { ...@@ -70,6 +72,7 @@ public class Units {
*/ */
@ApiModelProperty(value = "序列号", name = "code", example = "12321L") @ApiModelProperty(value = "序列号", name = "code", example = "12321L")
private String code; private String code;
/** /**
* 1.在系统单位 * 1.在系统单位
* 2.省直属单位 areaid 0 * 2.省直属单位 areaid 0
...@@ -142,6 +145,7 @@ public class Units { ...@@ -142,6 +145,7 @@ public class Units {
return mapper.map(this, UnitsTrainVo.class); return mapper.map(this, UnitsTrainVo.class);
} }
public LeftNavigation toLeftNavigation(){ public LeftNavigation toLeftNavigation(){
return new LeftNavigation(unitId,name,null, UUID.randomUUID().toString(),2,showOrder,null); return new LeftNavigation(unitId,name,null, UUID.randomUUID().toString(),2,showOrder,null);
} }
......
package com.tykj.dev.device.user.subject.service; package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.enums.AuExample; import com.tykj.dev.device.user.base.enums.AuExample;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit; import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import java.util.List; import java.util.List;
/** /**
* AuService. * AuService.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论