提交 8c61dd24 authored 作者: Matrix's avatar Matrix

[核查模块] 修复了统计数据的撞他异常的问题

上级 029df4f2
......@@ -39,7 +39,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
......@@ -89,7 +88,7 @@ public class DeviceCheckController {
@GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息")
public ResponseEntity findAreaUnderId(@PathVariable Integer fatherId, HttpServletRequest request) {
public ResponseEntity findAreaUnderId(@PathVariable Integer fatherId) {
return ResponseEntity.ok(new ResultObj(areaRepo.findByFatherId(fatherId)));
}
......@@ -228,26 +227,28 @@ public class DeviceCheckController {
}
// 处理JSON INFO 数据
// 对于省统计来说,需要去掉所有的区地区的数据
// 对于省统计来说,需要把区的数据累加到市级中去
List<CheckDeviceStatVo> statVoListCopy1 = MapperUtils.mapAll(statVoList, CheckDeviceStatVo.class);
List<CheckDeviceStatVo> statVoListCopy2 = MapperUtils.mapAll(statVoList, CheckDeviceStatVo.class);
//分组 分出区数据 与 非市数据 , 市数据进行分组 - 按照model名分组 model - areaName - Object
//按照区数据与市数据进行分组 - 按照model名分组 model - areaName - Object
Map<Boolean, List<CheckDeviceStatVo>> regionMap = statVoListCopy1.stream()
.collect(partitioningBy(stat -> countyAreaNames.contains(stat.getAreaStatList().get(0).getAreaName())));
// 区数据
List<CheckDeviceStatVo> countyVo = regionMap.get(true);
Map<String, Map<String, List<CheckDeviceStatVo>>> modAreaMap = regionMap.get(false).stream()
.collect(groupingBy(CheckDeviceStatVo::getDeviceModel,
groupingBy(c -> c.getAreaStatList().get(0).getAreaName())));
//查找区域数据内的父级地区(即市),将数据count数据add进去(通过两次get)
//查找区域数据内的父级地区(即市),将数据count数据add进去(通过两次get),将areaList数据也加进去
for (CheckDeviceStatVo v : countyVo) {
String couName = v.getAreaStatList().get(0).getAreaName();
String fatherName = areaCache.findFatherByName(couName).getName();
String fatherAreaName = areaCache.findFatherByName(couName).getName();
modAreaMap.computeIfPresent(v.getDeviceModel(), (k1, v1) -> {
v1.computeIfPresent(fatherName, (k2, v2) -> {
v1.computeIfPresent(fatherAreaName, (k2, v2) -> {
log.warn("发现需要堆叠计算的装备,装备信息为: {}", v2);
v2.get(0).addDeviceCount(1);
v2.get(0).getAreaStatList().get(0).addSuppose(1);
v2.get(0).getAreaStatList().addAll(v.getAreaStatList());
return v2;
});
return v1;
......@@ -414,13 +415,12 @@ public class DeviceCheckController {
Integer userBId = detailDo.getCheckUserBId();
// 如果是4流程的,则需要指定核查组成员A接任务
detailRepo.updateCheckStatus(id, checkStatus);
if (userAId > 0 && userBId > 0) {
detailRepo.updateCheckStatus(id, checkStatus);
currentTask = taskService.moveToNext(currentTask, checkUserAId);
logService.addLog(new TaskLogBto(currentTask.getId(), "B岗审核成功,等待核查组确认"));
} else {
// 如果是2流程的,则直接结束该任务
detailRepo.updateCheckStatus(id, checkStatus);
taskService.moveToEnd(currentTask);
logService.addLog(new TaskLogBto(currentTask.getId(), "B岗审核成功"));
}
......@@ -471,12 +471,14 @@ public class DeviceCheckController {
// 获得当前城市的统计信息 以及 要汇总的地区信息 并累加保存
List<CheckDeviceStatVo> addVos = parseStatString2Vo(currentTask, level, currentDetail.getCheckDetail());
CheckStatVo resultVo = transUtil.checkStatDo2Vo(statRepo.findById(statId).get());
resultVo.setDeviceStatVoList(accumulateStat(addVos, resultVo.getDeviceStatVoList()));
resultVo = resultVo.addStatList(addVos);
statRepo.save(resultVo.toDo());
// 判断地区数据是否均汇总完毕
boolean over = taskService.TaskTreeIsOver(fatherTaskId);
log.info("[核查模块] D 汇总完毕,汇总的账单id为 {}, Task id为 {}", statId,fatherTaskId);
// 如果汇总完毕则将父级的统计任务推进
if (over) {
TaskBto fatherTask = taskService.get(fatherTaskId);
......@@ -519,8 +521,7 @@ public class DeviceCheckController {
TaskBto parentTask = taskService.get(parentTaskId);
CheckStatVo cityStat = transUtil.checkStatDo2Vo(statRepo.findById(statId).get());
CheckStatVo provinceStat = transUtil.checkStatDo2Vo(statRepo.findById(parentTask.getBillId()).get());
List<CheckDeviceStatVo> accStat = accumulateStat(cityStat.getDeviceStatVoList(), provinceStat.getDeviceStatVoList());
provinceStat.setDeviceStatVoList(accStat);
provinceStat.addStatList(cityStat.getDeviceStatVoList());
statRepo.save(provinceStat.toDo());
// 如果所有子地区统计任务都已经完结,则推进父地区统计任务进度
boolean allOver = taskService.TaskTreeIsOver(parentTaskId);
......@@ -546,49 +547,33 @@ public class DeviceCheckController {
return GlobalMap.getStatusEnumMap().get(currentStatusId - remainder);
}
private List<CheckDeviceStatVo> accumulateStat(List<CheckDeviceStatVo> originalVos, List<CheckDeviceStatVo> addVos) {
for (CheckDeviceStatVo originalVo : originalVos) {
for (CheckDeviceStatVo addVo : addVos) {
if (originalVo.getDeviceModel().equals(addVo.getDeviceModel())) {
addVo.add(originalVo);
}
}
}
return addVos;
}
public List<CheckDeviceStatVo> parseStatString2Vo(TaskBto task, int cityLevel, String statString) {
List<CheckDeviceStatVo> statVoList = new ArrayList<>();
//分为 id - status 的数组 其中status 0缺失 1无误 2新增 3不在库
String[] statArray = statString.split(",");
//将 id - status 转化为 model - count - status(只统计新增和无误的作为数量)
// 根据unitId 查到 areaId 根据 areaId 查询到 areaName
int areaId = unitsRepo.findAreaId(task.getOwnUnit());
String areaName = areaRepo.findNameById(areaId);
for (String s : statArray) {
String[] device = s.split("-");
int deviceId = Integer.parseInt(device[0]);
int deviceStatus = Integer.parseInt(device[1]);
int proofResult = Integer.parseInt(device[1]);
DeviceLibrary checkDevice = deviceRepo.findById(deviceId).get();
//查询出地区对应的统计账单与详情账单
// 如果是level为3的城市,那么可以通过taskId获得详情id
int statId = 0;
int detailId = 0;
if (cityLevel == 3) {
Integer resultDetailId = taskRepo.findBillIdByTaskId(task.getId());
detailId = resultDetailId == null ? 0 : resultDetailId;
}
// 查询出地区对应的统计账单与详情账单
// 查询出对应的detailId与statId(从fatherTask中获得)
int detailId = Optional.ofNullable(taskRepo.findBillIdByTaskId(task.getId())).orElse(0);
// 如果是level为2的城市,可以通过unitId以及fatherId获得统计
if (cityLevel == 2) {
Integer resultDetailId = taskRepo.findBillIdByTaskId(task.getId());
detailId = resultDetailId == null ? 0 : resultDetailId;
Integer resultStatId = taskRepo.findBillId(task.getParentTaskId(), CONFIRM_CHECK_STAT.id);
statId = resultStatId == null ? 0 : resultStatId;
}
int statId = Optional.ofNullable(taskRepo.findBillId(task.getParentTaskId(), CONFIRM_CHECK_STAT.id))
.orElse(0);
// 根据unitId 查到 areaId 根据 areaId 查询到 areaName
int areaId = unitsRepo.findAreaId(task.getOwnUnit());
String areaName = areaRepo.findNameById(areaId);
CheckAreaStatVo checkAreaStatVo;
if (deviceStatus == 1) {
// proofResult 9=(1,1) 1=(2,0) other=(2,1)
if (proofResult == 9) {
checkAreaStatVo = new CheckAreaStatVo(areaName, 1, 1, 1, 1, statId, detailId);
} else if (proofResult == 1) {
checkAreaStatVo = new CheckAreaStatVo(areaName, 1, 1, 2, 0, statId, detailId);
} else {
checkAreaStatVo = new CheckAreaStatVo(areaName, 1, 1, 2, 1, statId, detailId);
......
......@@ -59,14 +59,14 @@ public class DeviceCheckDetailEntity {
*/
@ApiModelProperty(value = "检查组成员1(省A岗)id")
@Column(name = "check_UserA_id")
@Column(name = "check_userA_id")
private Integer checkUserAId = 0;
/**
* 检查组成员2(省A岗)id
*/
@ApiModelProperty(value = "检查组成员2(省A岗)id")
@Column(name = "check_UserB_id")
@Column(name = "check_userB_id")
private Integer checkUserBId = 0;
/**
* 本级经办人id(A岗)
......
......@@ -62,10 +62,10 @@ public class DeviceCheckStat {
*/
private String statInfo;
@Column(name = "check_UserA_id")
@Column(name = "check_userA_id")
private Integer checkUserAId;
@Column(name = "check_UserB_id")
@Column(name = "check_userB_id")
private Integer checkUserBId;
private String remark;
......
......@@ -54,4 +54,16 @@ public class CheckAreaStatVo {
this.supposeCount += supposeCount;
return this;
}
public CheckAreaStatVo add(CheckAreaStatVo other) {
this.areaName = other.getAreaName();
this.areaStatId = other.getAreaStatId();
this.areaDetailId = other.getAreaDetailId();
this.actualCount = other.getActualCount() + other.getActualCount();
this.supposeCount = other.getSupposeCount() + other.getSupposeCount();
this.comProgress = other.getComProgress();
this.comSituation = other.getComSituation();
return this;
}
}
......@@ -8,6 +8,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import static java.util.stream.Collectors.toMap;
/**
* CheckDeviceStatVo.
......@@ -53,30 +57,27 @@ public class CheckDeviceStatVo {
}
deviceCount += other.getDeviceCount();
// 如果源地区为空,则直接覆盖掉
if (CollectionUtils.isEmpty(areaStatList)) {
areaStatList = other.getAreaStatList();
}
Map<String, CheckAreaStatVo> areaMap = areaStatList.stream()
.collect(toMap(CheckAreaStatVo::getAreaName, Function.identity()));
for (CheckAreaStatVo otherArea : other.getAreaStatList()) {
if (deviceModel.equals(other.getDeviceModel())) {
if (CollectionUtils.isEmpty(areaStatList)) {
areaStatList = other.getAreaStatList();
}
for (CheckAreaStatVo statVo : areaStatList) {
if (statVo.getAreaName().equals(otherArea.getAreaName())) {
statVo.setAreaName(otherArea.getAreaName());
statVo.setAreaStatId(otherArea.getAreaStatId());
statVo.setAreaDetailId(otherArea.getAreaDetailId());
statVo.setActualCount(statVo.getActualCount() + otherArea.getActualCount());
statVo.setSupposeCount(statVo.getSupposeCount() + otherArea.getSupposeCount());
statVo.setComProgress(otherArea.getComProgress());
statVo.setComSituation(otherArea.getComSituation());
}
}
}
//如果原来的没有则添加,否则累加
areaMap.putIfAbsent(otherArea.getAreaName(), otherArea);
areaMap.computeIfPresent(otherArea.getAreaName(), (k, v) -> v.add(otherArea));
}
areaStatList = (List<CheckAreaStatVo>) areaMap.values();
return this;
}
public CheckDeviceStatVo addDeviceCount(int count){
public CheckDeviceStatVo addDeviceCount(int count) {
this.deviceCount += count;
return this;
}
......
......@@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.util.CollectionUtils;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
......@@ -15,6 +16,9 @@ import javax.persistence.Id;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* DeviceCheckStatVo.
......@@ -79,6 +83,7 @@ public class CheckStatVo {
*/
private List<CheckDeviceStatVo> deviceStatVoList;
public CheckStatVo(String remark, Integer checkUserAId, Integer checkUserBId, Integer id, String title, String subtitle, Date startTime, Date endTime, List<CheckDeviceStatVo> deviceStatVoList) {
this.checkUserAId = checkUserAId;
this.checkUserBId = checkUserBId;
......@@ -96,6 +101,26 @@ public class CheckStatVo {
return new CheckStatVo("", 0, 0, 0, "无指定数据", "无指定数据", null, null, emptyList);
}
public CheckStatVo addStatList(List<CheckDeviceStatVo> otherList) {
if (CollectionUtils.isEmpty(deviceStatVoList)) {
deviceStatVoList = otherList;
return this;
}
Map<String, CheckDeviceStatVo> oriModelMap = deviceStatVoList.stream()
.collect(Collectors.toMap(CheckDeviceStatVo::getDeviceModel, Function.identity()));
//遍历要加入的LIST 如果在源数据map中寻找到了则累加,否则添加进去
for (CheckDeviceStatVo vo : otherList) {
oriModelMap.putIfAbsent(vo.getDeviceModel(), vo);
oriModelMap.computeIfPresent(vo.getDeviceModel(), (k, v) -> v.add(vo));
}
deviceStatVoList = (List<CheckDeviceStatVo>) oriModelMap.values();
return this;
}
/**
* Vo转Do
*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论