提交 44e3e709 authored 作者: Matrix's avatar Matrix

[核查模块] 增加了核查时对省本直,省直属,以及市的发起自查的功能

上级 2f07bee9
...@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -30,10 +31,11 @@ public class UnitAreaBean { ...@@ -30,10 +31,11 @@ public class UnitAreaBean {
@Bean(name = "unMap") @Bean(name = "unMap")
public Map<String, AreaUnit> unitNameMap() { public Map<String, AreaUnit> unitNameMap() {
return unitsDao.findAll().stream() return unitsDao.findAll().stream()
.filter(units -> units.getType() == 1) // .filter(units -> units.getType() == 1)
.map(unit -> { .map(unit -> {
int areaId = unitsDao.findAreaIdByName(unit.getName()); int areaId = unitsDao.findAreaIdByName(unit.getName());
Area area = areaDao.findById(areaId).get(); Area area = areaDao.findById(areaId)
.orElse(new Area(0, "无地区归属", 9999, "9999", 0, ""));
return new AreaUnit(area, unit); return new AreaUnit(area, unit);
}).collect(Collectors.toMap(AreaUnit::getUnitName, Function.identity())); }).collect(Collectors.toMap(AreaUnit::getUnitName, Function.identity()));
......
...@@ -2,6 +2,7 @@ package com.tykj.dev.device.confirmcheck.controller; ...@@ -2,6 +2,7 @@ package com.tykj.dev.device.confirmcheck.controller;
import com.github.wenhao.jpa.Specifications; import com.github.wenhao.jpa.Specifications;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.tykj.dev.config.GlobalMap; import com.tykj.dev.config.GlobalMap;
import com.tykj.dev.config.swagger.AutoDocument; import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.confirmcheck.common.CheckType; import com.tykj.dev.device.confirmcheck.common.CheckType;
...@@ -52,6 +53,7 @@ import java.time.LocalDateTime; ...@@ -52,6 +53,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static com.tykj.dev.misc.base.BusinessEnum.CONFIRM_CHECK_DETAIL; 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.BusinessEnum.CONFIRM_CHECK_STAT;
...@@ -105,6 +107,16 @@ public class DeviceCheckController { ...@@ -105,6 +107,16 @@ public class DeviceCheckController {
return ResponseEntity.ok(new ResultObj<>(areaRepo.findByFatherId(fatherId))); return ResponseEntity.ok(new ResultObj<>(areaRepo.findByFatherId(fatherId)));
} }
/**
* @return level = 0 ,1 ,2 的单位
*/
@GetMapping("/unit")
@ApiOperation(value = "查询默认的可以被核查单位的清单(省本直,省直属,市局)")
public ResponseEntity findDefaultUnits() {
return ResponseEntity.ok(new ResultObj<>(unitsRepo.findAllByLevelIn(Lists.newArrayList(0, 1, 2))));
}
@ApiOperation(value = "根据id查询核查统计数据", notes = "可以通过这个接口查询核查统计数据") @ApiOperation(value = "根据id查询核查统计数据", notes = "可以通过这个接口查询核查统计数据")
@GetMapping("/stat/{id}") @GetMapping("/stat/{id}")
public CheckStatVo findStatById(@PathVariable Integer id) { public CheckStatVo findStatById(@PathVariable Integer id) {
...@@ -191,17 +203,19 @@ public class DeviceCheckController { ...@@ -191,17 +203,19 @@ public class DeviceCheckController {
return new ResultObj<>(resultIds, "自动核查任务发起成功"); return new ResultObj<>(resultIds, "自动核查任务发起成功");
} }
@ApiOperation(value = "发起核查", notes = "对指定单位发起核查任务")
@ApiOperation(value = "发起核查", notes = "对指定地区发起核查任务")
@PostMapping("/startCheck") @PostMapping("/startCheck")
public ResponseEntity startCheck(@RequestBody CheckCheckVo ccVO) { public ResponseEntity startCheck(@RequestBody CheckCheckVo ccVO) {
//构建省的统计账单 // 构建省的统计账单
Integer startUnitId = ccVO.getUnitId(); Integer startUnitId = ccVO.getUnitId();
Units startUnit = unitsRepo.findById(startUnitId).get(); Units startUnit = unitsRepo.findById(startUnitId).get();
List<Units> checkedUnits = unitsRepo.findByAreaIdIn(ccVO.getAreaRange()); List<Units> checkedUnits = unitsRepo.findAllById(ccVO.getUnitRange());
// 1.发起自己的自查 (市,tpy2=2,省 level = 0,1,2)
// 2.发起自己的检查(只是市级别的 level=2)
List<String> checkedUnitNames = checkedUnits.stream().map(Units::getName).collect(toList()); List<String> checkedUnitNames = checkedUnits.stream().map(Units::getName).collect(toList());
log.info("[核查模块]发起核查,发起单位为{},被查单位为{}", startUnit.getName(), checkedUnitNames); log.info("[核查模块]发起核查,发起单位为{},被查单位为{}", startUnit.getName(), checkedUnitNames);
// 构建省的统计账单,所有的checkedUnits都要被包含到统计中去
DeviceCheckStat provinceCheckStat = initStatData(ccVO.getTitle(), ccVO.getRemark(), 0, 0, startUnit.getName(), checkedUnits, ccVO.getEndTime().atStartOfDay()); DeviceCheckStat provinceCheckStat = initStatData(ccVO.getTitle(), ccVO.getRemark(), 0, 0, startUnit.getName(), checkedUnits, ccVO.getEndTime().atStartOfDay());
Integer statId = statRepo.save(provinceCheckStat).getId(); Integer statId = statRepo.save(provinceCheckStat).getId();
List<CheckDeviceStatVo> deviceStatVos = Arrays.stream( List<CheckDeviceStatVo> deviceStatVos = Arrays.stream(
...@@ -217,8 +231,52 @@ public class DeviceCheckController { ...@@ -217,8 +231,52 @@ public class DeviceCheckController {
provStatTask.setCustomInfo("check"); provStatTask.setCustomInfo("check");
provStatTask = taskService.start(provStatTask); provStatTask = taskService.start(provStatTask);
//构建市的检查任务 // 构建自查任务(levl = 0,1,2)
for (Units unit : checkedUnits) { List<Units> selfCheckUnits = checkedUnits.stream()
.filter(units -> Arrays.asList(0, 1, 2).contains(units.getLevel()))
.collect(toList());
// 获取所有在库装备与不在库装备
Map<String, List<DeviceLibrary>> devInLib = deviceRepo.findAll().stream()
.filter(device -> device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
Map<String, List<DeviceLibrary>> devNotInLib = deviceRepo.findAll().stream()
.filter(device -> !device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
User loginUser = authenticationUtils.getAuthentication().getCurrentUserInfo();
for (Units unit : selfCheckUnits) {
//核查组成员名称用当前登录用户
String names = loginUser.getName();
// 3-1 构建被查单位的 自查账单
DeviceCheckDetail unitDetailDoc = DeviceCheckDetail.EmptyWithChecker(names + "|" + "默认备注", "默认标题", 0, 0, 0, 0, unit.getName(), devInLib.getOrDefault(unit.getName(), new ArrayList<>()), devNotInLib.getOrDefault(unit.getName(), new ArrayList<>()));
DeviceCheckDetail detail = detailRepo.save(unitDetailDoc);
// 将id放入统计中去 model -> areaName -> detailId
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 构建被查单位的 自查任务 (根据被查单位的级别来区分是县级状态是市级状态) 这里的父级任务应该是省统计
TaskBto checkedTask = new TaskBto(CHECK_EXAM_DETAIL_0.id, "自核查任务", provStatTask.getId(), addNode(provStatTask.getNodeIdDetail(), provStatTask.getId()), CONFIRM_CHECK_DETAIL.id, detail.getId(), unit.getUnitId(), 0);
checkedTask.setCustomInfo("manual");
taskService.start(checkedTask);
}
//构建市的检查任务(level=2)
List<Units> examCheckUnits = checkedUnits.stream()
.filter(units -> Arrays.asList( 2).contains(units.getLevel()))
.collect(toList());
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());
......
...@@ -29,8 +29,8 @@ public class CheckCheckVo { ...@@ -29,8 +29,8 @@ public class CheckCheckVo {
@ApiModelProperty(name = "发起单位id") @ApiModelProperty(name = "发起单位id")
private Integer unitId; private Integer unitId;
@ApiModelProperty(name = "被核查的区域id集合") @ApiModelProperty(name = "被核查的单位id集合")
private List<Integer> areaRange; private List<Integer> unitRange;
@ApiModelProperty(name = "备注") @ApiModelProperty(name = "备注")
private String remark; private String remark;
......
...@@ -14,5 +14,6 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -14,5 +14,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
public class BaseTest { public class
BaseTest {
} }
...@@ -78,7 +78,7 @@ public class AuServiceImpl implements AuService { ...@@ -78,7 +78,7 @@ public class AuServiceImpl implements AuService {
.eq(Objects.nonNull(value), example.getFieldName(), value) .eq(Objects.nonNull(value), example.getFieldName(), value)
.build(); .build();
Units units = unitsRepo.findOne(pred).get(); Units units = unitsRepo.findOne(pred).get();
Area area = areaRepo.findById(units.getAreaId()).get(); Area area = areaRepo.findById(units.getAreaId()).orElse(new Area(0, "无地区归属", 9999, "9999", 0, ""));
return new AreaUnit(area, units); return new AreaUnit(area, units);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论