提交 992e22e5 authored 作者: Matrix's avatar Matrix

增加了自动核查

上级 5b7aa28e
...@@ -19,12 +19,14 @@ import com.tykj.dev.device.task.subject.bto.TaskLogBto; ...@@ -19,12 +19,14 @@ import com.tykj.dev.device.task.subject.bto.TaskLogBto;
import com.tykj.dev.device.task.subject.domin.Task; import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.user.subject.dao.AreaDao; 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.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units; import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.User; import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.util.AuthenticationUtils; import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.misc.base.GlobalMap; import com.tykj.dev.misc.base.GlobalMap;
import com.tykj.dev.misc.base.ResultObj; import com.tykj.dev.misc.base.ResultObj;
import com.tykj.dev.misc.base.StatusEnum; import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.utils.JacksonUtil;
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 lombok.extern.slf4j.Slf4j;
...@@ -34,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -34,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -83,7 +86,7 @@ public class DeviceCheckController { ...@@ -83,7 +86,7 @@ public class DeviceCheckController {
@GetMapping("/area/{fatherId}") @GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息") @ApiOperation(value = "查询指定区域下的所有区域信息")
public ResponseEntity findAreaUnderId(@PathVariable Integer fatherId) { public ResponseEntity findAreaUnderId(@PathVariable Integer fatherId, HttpServletRequest request) {
return ResponseEntity.ok(new ResultObj(areaRepo.findByFatherId(fatherId))); return ResponseEntity.ok(new ResultObj(areaRepo.findByFatherId(fatherId)));
} }
...@@ -107,18 +110,131 @@ public class DeviceCheckController { ...@@ -107,18 +110,131 @@ public class DeviceCheckController {
} }
@ApiOperation(value = "发起自动核查", notes = "发起自动核查") @ApiOperation(value = "发起自动核查", notes = "发起自动核查")
@PostMapping("/check/auto")
public ResponseEntity startAutoCheck() { public ResponseEntity startAutoCheck() {
// 发起省级的统计 - 获得所有的市级单位 // 发起省级的统计 - 获得所有的市级单位
List<Units> cityUnits = unitsRepo.findAllByLevel(2); List<Units> cityUnits = unitsRepo.findAllByLevel(2);
Units provUnit = unitsRepo.findById(1).get(); Units provUnit = unitsRepo.findById(1).get();
String baseTitle = LocalDate.now().getYear() + "年" + (LocalDate.now().getMonthValue() + 1) + "月"; String baseTitle = LocalDate.now().getYear() + "年" + (LocalDate.now().getMonthValue() + 1) + "月";
initStatData("自动核查", // 构建省的统计账单
DeviceCheckStat provinceStat = initStatData("自动核查",
0, 0,
0, 0,
baseTitle + "浙江省自动核查", baseTitle + "浙江省自动核查",
provUnit.getName(), provUnit.getName(),
cityUnits); cityUnits);
return ResponseEntity.ok("nothing"); List<DeviceLibrary> deviceList = deviceRepo.findAll();
Map<String, List<DeviceLibrary>> devInLib = deviceList.stream()
.filter(device -> device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
Map<String, List<DeviceLibrary>> devNotInLib = deviceList.stream()
.filter(device -> !device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
// 构建省统Task
TaskBto provStatTask = new Task(CHECK_STAT_0.id, "省自动核查", 0, ".0.", CONFIRM_CHECK_STAT.id, provinceStat.getId(), provUnit.getUnitId())
.parse2Bto();
taskService.start(provStatTask);
List<CheckDeviceStatVo> statVoList = new ArrayList<>();
List<DeviceCheckStat> cityStatList = new ArrayList<>();
List<String> countyNames = new ArrayList<>();
// 构建所有市的统计账单(先不考虑JSON-INFO)
for (Units city : cityUnits) {
List<Integer> areaIds = areaRepo.findAllByFatherId(city.getAreaId()).stream().map(Area::getId).collect(toList());
List<Units> countyUnits = unitsRepo.findByAreaIdIn(areaIds);
// 构建市统账单
DeviceCheckStat cityStatDo = initStatData("自动核查",
0,
0,
baseTitle + city.getName() + "自动核查统计",
provUnit.getName(),
countyUnits);
DeviceCheckStat cityStat = statRepo.save(cityStatDo);
cityStatList.add(cityStat);
// 构建市统task 获得id
TaskBto cityStatTask = new Task(CHECK_STAT_0.id, city.getName() + "自动核查统计", provStatTask.getId(), addNode(provStatTask.getNodeIdDetail(), provinceStat.getId()), CONFIRM_CHECK_STAT.id, cityStat.getId(), city.getUnitId())
.parse2Bto();
taskService.start(cityStatTask);
// 构建市自查账单
DeviceCheckDetailEntity cityDetailDo = DeviceCheckDetailEntity.EmptyWithChecker(
"系统发起的自查|" + city.getName() + "|" + city.getAreaId(),
baseTitle + city.getName() + "核查任务",
0, 0, 0, 0,
provUnit.getName(),
devInLib.getOrDefault(city.getName(), new ArrayList<>()),
devNotInLib.getOrDefault(city.getName(), new ArrayList<>()));
DeviceCheckDetailEntity cityDetail = detailRepo.save(cityDetailDo);
List<CheckDeviceStatVo> cityStatVoList = deviceList.stream()
.filter(d -> d.getOwnUnit().equals(city.getName()))
.map(d -> transUtil.device2InitStatVo(d, city.getName(), cityStat.getId(), cityDetail.getId()))
.collect(toList());
statVoList.addAll(cityStatVoList);
// 构建市自查TASK
TaskBto cityDetailTask = new Task(CHECK_DETAIL_0.id, city.getName() + "自动核查自查", cityStatTask.getId(), addNode(cityStatTask.getNodeIdDetail(), cityStatTask.getId()), CONFIRM_CHECK_DETAIL.id, cityDetail.getId(), city.getUnitId())
.parse2Bto();
taskService.start(cityDetailTask);
// 构建县任务
for (Units county : countyUnits) {
countyNames.add(county.getName());
//构建县自查账单
DeviceCheckDetailEntity countyDetailDo = DeviceCheckDetailEntity.EmptyWithChecker(
"系统发起的自查|" + county.getName() + "|" + county.getAreaId(),
baseTitle + county.getName() + "核查任务",
0, 0, 0, 0,
provUnit.getName(),
devInLib.getOrDefault(city.getName(), new ArrayList<>()),
devNotInLib.getOrDefault(city.getName(), new ArrayList<>()));
DeviceCheckDetailEntity countyDetail = detailRepo.save(countyDetailDo);
List<CheckDeviceStatVo> countyStatVoList = deviceList.stream()
.filter(d -> d.getOwnUnit().equals(city.getName()))
.map(d -> transUtil.device2InitStatVo(d, city.getName(), cityStat.getId(), countyDetail.getId()))
.collect(toList());
statVoList.addAll(countyStatVoList);
//构建县自查TASK
TaskBto countyDetailTask = new Task(CHECK_DETAIL_0.id, county.getName() + "自动核查自查", cityStatTask.getId(), addNode(cityStatTask.getNodeIdDetail(), cityStatTask.getId()), CONFIRM_CHECK_DETAIL.id, countyDetail.getId(), county.getUnitId())
.parse2Bto();
taskService.start(countyDetailTask);
}
// 处理JSON INFO 数据
// 对于省统计来说,需要去掉所有的区地区的数据
CheckDeviceStatVo provStatVo = statVoList.stream()
.filter(stat -> !countyNames.contains(stat.getAreaStatList().get(0).getAreaName()))
.reduce(CheckDeviceStatVo::add)
.get();
provinceStat.setStatInfo(JacksonUtil.toJSon(provStatVo));
statRepo.save(provinceStat);
// 对于市统计来说,只需要自己本市以及其下地区的数据
for (DeviceCheckStat csd : cityStatList) {
List<String> cityNames = new ArrayList<>();
if (csd.getRemark().split("\\|").length <= 1) {
continue;
}
String areaName = csd.getRemark().split("\\|")[1];
Integer cityId = Integer.valueOf(csd.getRemark().split("\\|")[2]);
List<String> childNames = areaRepo.findByFatherId(cityId).stream().map(Area::getName).collect(toList());
cityNames.add(areaName);
cityNames.addAll(childNames);
CheckDeviceStatVo cityStatVo = statVoList.stream()
.filter(stat -> cityNames.contains(stat.getAreaStatList().get(0).getAreaName()))
.reduce(CheckDeviceStatVo::add)
.get();
csd.setStatInfo(JacksonUtil.toJSon(cityStatVo));
}
statRepo.saveAll(cityStatList);
}
return ResponseEntity.ok("自动发起任务成功");
} }
/** /**
......
...@@ -229,8 +229,8 @@ public class DeviceCheckDetailEntity { ...@@ -229,8 +229,8 @@ public class DeviceCheckDetailEntity {
/** /**
* @param checkUnit 要核查的单位 * @param checkUnit 要核查的单位
* @param goodDevices 所属与所在均在本单位的装备集合 * @param devInLib 所属与所在均在本单位的装备集合
* @param badDevices 所属在,但所在不在本单位的装备集合 * @param devNotInLib 所属在,但所在不在本单位的装备集合
* @return 初始化的账单(还没有被人修改过的) * @return 初始化的账单(还没有被人修改过的)
*/ */
public static DeviceCheckDetailEntity EmptyWithChecker( public static DeviceCheckDetailEntity EmptyWithChecker(
...@@ -241,19 +241,19 @@ public class DeviceCheckDetailEntity { ...@@ -241,19 +241,19 @@ public class DeviceCheckDetailEntity {
Integer userAId, Integer userAId,
Integer userBId, Integer userBId,
String checkUnit, String checkUnit,
List<DeviceLibrary> goodDevices, List<DeviceLibrary> devInLib,
List<DeviceLibrary> badDevices) { List<DeviceLibrary> devNotInLib) {
//构造checkDetail 分当前在库与不在库的 赋予不同状态 //构造checkDetail 分当前在库与不在库的 赋予不同状态
String goodCheckDetail = ""; String goodCheckDetail = "";
if (!CollectionUtils.isEmpty(goodDevices)) { if (!CollectionUtils.isEmpty(devInLib)) {
goodCheckDetail = goodDevices.stream() goodCheckDetail = devInLib.stream()
.map(device -> device.getId() + "-9") .map(device -> device.getId() + "-9")
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
} }
String badCheckDetail = ""; String badCheckDetail = "";
if (!CollectionUtils.isEmpty(badDevices)) { if (!CollectionUtils.isEmpty(devNotInLib)) {
badCheckDetail = badDevices.stream() badCheckDetail = devNotInLib.stream()
.map(device -> device.getId() + "-3") .map(device -> device.getId() + "-3")
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
} }
...@@ -271,7 +271,7 @@ public class DeviceCheckDetailEntity { ...@@ -271,7 +271,7 @@ public class DeviceCheckDetailEntity {
userBId, userBId,
TimestampUtil.getNowDate(), TimestampUtil.getNowDate(),
checkUnit, checkUnit,
goodDevices.size(), devInLib.size(),
0, 0,
"", "",
checkDetail, checkDetail,
......
...@@ -5,6 +5,7 @@ import lombok.Builder; ...@@ -5,6 +5,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
...@@ -45,15 +46,19 @@ public class CheckDeviceStatVo { ...@@ -45,15 +46,19 @@ public class CheckDeviceStatVo {
/** /**
* other的model一定要与本deviceModel相同 * other的model一定要与本deviceModel相同
*/ */
public void add(CheckDeviceStatVo other) { public CheckDeviceStatVo add(CheckDeviceStatVo other) {
if (!deviceModel.equals(other.getDeviceModel())) { if (!deviceModel.equals(other.getDeviceModel())) {
log.warn("[核查] 合并统计的数据发现装备不统一的情况"); log.warn("[核查] 合并统计的数据发现装备不统一的情况");
return; return this;
} }
deviceCount += other.getDeviceCount(); deviceCount += other.getDeviceCount();
for (CheckAreaStatVo otherArea : other.getAreaStatList()) { for (CheckAreaStatVo otherArea : other.getAreaStatList()) {
if (deviceModel.equals(other.getDeviceModel())) { if (deviceModel.equals(other.getDeviceModel())) {
if (CollectionUtils.isEmpty(areaStatList)) {
areaStatList = other.getAreaStatList();
}
for (CheckAreaStatVo statVo : areaStatList) { for (CheckAreaStatVo statVo : areaStatList) {
if (statVo.getAreaName().equals(otherArea.getAreaName())) { if (statVo.getAreaName().equals(otherArea.getAreaName())) {
statVo.setAreaName(otherArea.getAreaName()); statVo.setAreaName(otherArea.getAreaName());
...@@ -67,6 +72,8 @@ public class CheckDeviceStatVo { ...@@ -67,6 +72,8 @@ public class CheckDeviceStatVo {
} }
} }
} }
return this;
} }
} }
package com.tykj.dev.device.confirmcheck.utils; package com.tykj.dev.device.confirmcheck.utils;
import com.google.common.collect.Lists;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
...@@ -46,6 +47,26 @@ public class ObjTransUtil { ...@@ -46,6 +47,26 @@ public class ObjTransUtil {
@Autowired @Autowired
private UnitsDao unitRepo; private UnitsDao unitRepo;
/**
* 装备转化为初始化的装备统计类
*
* @param device
* @return
*/
public CheckDeviceStatVo device2InitStatVo(DeviceLibrary device) {
String ownUnit = device.getOwnUnit();
int areaId = unitRepo.findAreaIdByName(ownUnit);
String areaName = areaRepo.findNameById(areaId);
List<CheckAreaStatVo> areaStatList = Lists.newArrayList(new CheckAreaStatVo(areaName, 0, 1, 0, 0, 0, 0));
return new CheckDeviceStatVo(device.getModel(), device.getName(), 1, areaStatList);
}
public CheckDeviceStatVo device2InitStatVo(DeviceLibrary device, String areaName, Integer statId, Integer detailId) {
List<CheckAreaStatVo> areaStatList = Lists.newArrayList(new CheckAreaStatVo(areaName, 0, 1, 0, 0, statId, detailId));
return new CheckDeviceStatVo(device.getModel(), device.getName(), 1, areaStatList);
}
/** /**
* Do类转化为Vo类 * Do类转化为Vo类
*/ */
......
...@@ -16,9 +16,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -16,9 +16,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableTransactionManagement @EnableTransactionManagement
public class UnionApplication extends SpringBootServletInitializer { public class UnionApplication extends SpringBootServletInitializer {
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder){ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(UnionApplication.class); return applicationBuilder.sources(UnionApplication.class);
} }
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(UnionApplication.class, args); SpringApplication.run(UnionApplication.class, args);
} }
......
...@@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
@WithMockUser(username = "shena", password = "qwer1234", authorities = "省A专管员") @WithMockUser(username = "shena", password = "qwer1234", authorities = "省A专管员")
@ActiveProfiles("dev") @ActiveProfiles("test")
class DeviceCheckControllerTest extends BaseTest { class DeviceCheckControllerTest extends BaseTest {
@Autowired @Autowired
...@@ -55,6 +55,19 @@ class DeviceCheckControllerTest extends BaseTest { ...@@ -55,6 +55,19 @@ class DeviceCheckControllerTest extends BaseTest {
@Autowired @Autowired
private ObjTransUtil transUtil; private ObjTransUtil transUtil;
@Test
void startAutoCheck() throws Exception {
// 测试
RequestBuilder request;
request = post("/check/confirm/check/auto")
.header("Origin", "*");
mockMvc.perform(request)
.andExpect(status().isOk())
.andDo(mvcResult1 -> System.out.println("[测试结果] 自动发起核查任务测试通过"));
}
@Test @Test
void startManualCheck() throws Exception { void startManualCheck() throws Exception {
......
...@@ -25,5 +25,4 @@ public interface AreaDao extends JpaRepository<Area, Integer>, JpaSpecificationE ...@@ -25,5 +25,4 @@ public interface AreaDao extends JpaRepository<Area, Integer>, JpaSpecificationE
@Query("select o.name from Area o where o.id=?1") @Query("select o.name from Area o where o.id=?1")
String findNameById(int id); String findNameById(int id);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论