提交 eafc9aae authored 作者: Matrix's avatar Matrix

[核查模块] 去除一些不必要的代码

上级 2409a64f
......@@ -32,7 +32,6 @@ import com.tykj.dev.misc.utils.MapperUtils;
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.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
......@@ -50,7 +49,7 @@ import static java.util.stream.Collectors.*;
/**
* @author dengdiyi
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
@SuppressWarnings({"OptionalGetWithoutIsPresent"})
@RestController
@RequestMapping(value = "/check/confirm")
@AutoDocument
......@@ -59,28 +58,31 @@ import static java.util.stream.Collectors.*;
@Slf4j
public class DeviceCheckController {
@Autowired
private DeviceCheckStatRepo statRepo;
@Autowired
private DeviceCheckBillDao billRepo;
@Autowired
private AreaDao areaRepo;
@Autowired
private UnitsDao unitsRepo;
@Autowired
private DeviceLibraryDao deviceRepo;
@Autowired
private DeviceCheckDetailDao detailRepo;
@Autowired
private ObjTransUtil transUtil;
@Autowired
private TaskDao taskRepo;
@Autowired
private TaskService taskService;
@Autowired
private AuthenticationUtils AuthenticationUtils;
@Autowired
private AreaCache areaCache;
private final DeviceCheckStatRepo statRepo;
private final DeviceCheckBillDao billRepo;
private final AreaDao areaRepo;
private final UnitsDao unitsRepo;
private final DeviceLibraryDao deviceRepo;
private final DeviceCheckDetailDao detailRepo;
private final ObjTransUtil transUtil;
private final TaskDao taskRepo;
private final TaskService taskService;
private final AuthenticationUtils AuthenticationUtils;
private final AreaCache areaCache;
public DeviceCheckController(DeviceCheckBillDao billRepo, DeviceCheckStatRepo statRepo, AreaDao areaRepo, UnitsDao unitsRepo, DeviceLibraryDao deviceRepo, DeviceCheckDetailDao detailRepo, ObjTransUtil transUtil, TaskDao taskRepo, TaskService taskService, AuthenticationUtils AuthenticationUtils, AreaCache areaCache) {
this.billRepo = billRepo;
this.statRepo = statRepo;
this.areaRepo = areaRepo;
this.unitsRepo = unitsRepo;
this.deviceRepo = deviceRepo;
this.detailRepo = detailRepo;
this.transUtil = transUtil;
this.taskRepo = taskRepo;
this.taskService = taskService;
this.AuthenticationUtils = AuthenticationUtils;
this.areaCache = areaCache;
}
@GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息")
......@@ -111,7 +113,7 @@ public class DeviceCheckController {
@PostMapping("/auto")
public ResponseEntity<ResultObj<Map<String, List<Integer>>>> startAutoCheck() {
// 构建返回数据对象
Map<String, List<Integer>> resultIds = new HashMap<>();
Map<String, List<Integer>> resultIds = new HashMap<>(8);
resultIds.put("statId", new ArrayList<>());
resultIds.put("detailId", new ArrayList<>());
resultIds.put("taskId", new ArrayList<>());
......@@ -260,7 +262,6 @@ public class DeviceCheckController {
if (csd.getRemark().split("\\|").length <= 1) {
continue;
}
String unitName = csd.getRemark().split("\\|")[1];
Integer cityId = Integer.valueOf(csd.getRemark().split("\\|")[2]);
String cityName = areaCache.findById(cityId).getName();
List<String> childNames = areaRepo.findByFatherId(cityId).stream().map(Area::getName).collect(toList());
......@@ -394,9 +395,6 @@ public class DeviceCheckController {
statRepo.save(cityVo.toDo());
log.info("[核查模块 检测到是自动核查任务,将省级统计 id = {} 认为开启]", provStat.getId());
}
TaskBto fatherStatTask = taskService.get(fatherId);
return ResponseEntity.ok(new ResultObj<>("专管员A操作成功"));
}
......@@ -434,12 +432,11 @@ public class DeviceCheckController {
// 如果是4流程的,则需要指定核查组成员A接任务
detailRepo.updateCheckStatus(id, checkStatus);
if (userAId > 0 && userBId > 0) {
currentTask = taskService.moveToNext(currentTask, checkUserAId);
taskService.moveToNext(currentTask, checkUserAId);
} else {
// 如果是2流程的,则直接结束该任务
taskService.moveToEnd(currentTask);
summaryDetail(currentTask, currentDetail);
}
} else {
//不通过则回到第一阶段
......@@ -460,7 +457,8 @@ public class DeviceCheckController {
DeviceCheckDetail currentDetail = detailRepo.findById(id).get();
if (pass) {
// 如果当前是第3步(利用余数来判断),则需要指定核查组B的人来接受任务
if (currentTask.getBillStatus() % 10 == 2) {
boolean stepC = currentTask.getBillStatus() % 10 == 2;
if (stepC) {
log.info("[核查模块] C 检查组成员A正在进行核查操作,核查详情账单id为 : {}", id);
if (!currentTask.getBillStatus().equals(CHECK_DETAIL_2.id)) {
return ResponseEntity.status(400).body(new ResultObj<>(String.format("当前任务的状态异常!当前任务状态为 %s , 任务状态应该为 %s", GlobalMap.getStatusEnumMap().get(currentTask.getBillStatus()), CHECK_DETAIL_2.name)));
......@@ -469,7 +467,8 @@ public class DeviceCheckController {
log.info("[核查模块] C 操作完毕");
}
if (currentTask.getBillStatus() % 10 == 3) {
boolean stepD = currentTask.getBillStatus() % 10 == 3;
if (stepD) {
if (!currentTask.getBillStatus().equals(CHECK_DETAIL_3.id)) {
return ResponseEntity.status(400).body(new ResultObj<>(String.format("当前任务的状态异常!当前任务状态为 %s , 任务状态应该为 %s", GlobalMap.getStatusEnumMap().get(currentTask.getBillStatus()), CHECK_DETAIL_3.name)));
}
......@@ -479,7 +478,6 @@ public class DeviceCheckController {
summaryDetail(currentTask, currentDetail);
log.info("[核查模块] D 操作完毕");
}
} else {
// 如果没通过则返回第1步
StatusEnum firstStatus = getFirstStatus(currentTask.getBillStatus());
......@@ -489,35 +487,6 @@ public class DeviceCheckController {
return ResponseEntity.ok(new ResultObj<>("操作成功"));
}
private void summaryDetail(TaskBto currentTask, DeviceCheckDetail currentDetail) {
log.info("[核查模块] 正在进行数据汇总");
// 任务结束后需要将当前城市的统计信息汇总上去()
Units units = unitsRepo.findById(currentTask.getOwnUnit()).get();
int level = units.getLevel();
// 先找到汇总地区的账单id 查询当前detail task 的 父级TASK
Integer fatherTaskId = currentTask.getParentTaskId();
int statId = taskRepo.findBillId(fatherTaskId, CONFIRM_CHECK_STAT.id);
// 获得当前城市的统计信息 以及 要汇总的地区信息 并累加保存
List<CheckDeviceStatVo> addVos = parseStatString2Vo(currentTask, level, currentDetail.getCheckDetail());
CheckStatVo resultVo = transUtil.checkStatDo2Vo(statRepo.findById(statId).get());
resultVo = resultVo.cleanReduce(addVos);
statRepo.save(resultVo.toDo());
// 判断地区数据是否均汇总完毕
boolean over = taskService.TaskTreeIsOver(fatherTaskId);
// 如果汇总完毕则将父级的统计任务推进
if (over) {
TaskBto fatherTask = taskService.get(fatherTaskId);
//如果上一个id是-1 则证明是所有人的跟踪统计,即自动核查,那么下一步推进到所有人的待办
Integer lastUserId = fatherTask.getLastUserId() == -1 ? 0 : fatherTask.getLastUserId();
taskService.moveToNext(fatherTask, lastUserId);
}
log.info("[核查模块] 数据汇总完毕");
}
/**
* @param statId 统计账单主键id
*/
......@@ -547,8 +516,8 @@ public class DeviceCheckController {
// 如果所有子地区统计任务都已经完结,则推进父地区统计任务进度
boolean allOver = taskService.TaskTreeIsOver(parentTaskId);
if (allOver) {
log.info("[核查任务] 所有市的核查统计任务已经完毕,推进省级的核查统计任务");
TaskBto statTask = taskService.moveToNext(parentTask, 0);
TaskBto provTask = taskService.moveToNext(parentTask, 0);
log.info("[核查任务] 所有市的核查统计任务已经完毕,推进省级 id = {}的核查统计任务", provTask.getId());
}
}
......@@ -556,6 +525,36 @@ public class DeviceCheckController {
return ResponseEntity.ok(new ResultObj<>("统计数据确认完毕"));
}
/**
* 任务结束后需要将当前城市的统计信息汇总上
*
* @param currentTask 当前任务
* @param currentDetail 需要汇总的详情核查数据对象
*/
private void summaryDetail(TaskBto currentTask, DeviceCheckDetail currentDetail) {
log.info("[核查模块] 正在进行数据汇总");
// 先找到汇总地区的账单id 查询当前detail task 的 父级TASK
Integer fatherTaskId = currentTask.getParentTaskId();
int statId = taskRepo.findBillId(fatherTaskId, CONFIRM_CHECK_STAT.id);
// 获得当前城市的统计信息 以及 要汇总的地区信息 并累加保存
List<CheckDeviceStatVo> addVos = parseStatString2Vo(currentTask, currentDetail.getCheckDetail());
CheckStatVo resultVo = transUtil.checkStatDo2Vo(statRepo.findById(statId).get());
resultVo = resultVo.cleanReduce(addVos);
statRepo.save(resultVo.toDo());
// 判断地区数据是否均汇总完毕
boolean over = taskService.TaskTreeIsOver(fatherTaskId);
// 如果汇总完毕则将父级的统计任务推进
if (over) {
TaskBto fatherTask = taskService.get(fatherTaskId);
//如果上一个id是-1 则证明是所有人的跟踪统计,即自动核查,那么下一步推进到所有人的待办
Integer lastUserId = fatherTask.getLastUserId() == -1 ? 0 : fatherTask.getLastUserId();
taskService.moveToNext(fatherTask, lastUserId);
}
log.info("[核查模块] 数据汇总完毕");
}
/**
* 获取指定任务的第一步的任务状态
......@@ -567,7 +566,7 @@ public class DeviceCheckController {
return GlobalMap.getStatusEnumMap().get(currentStatusId - remainder);
}
public List<CheckDeviceStatVo> parseStatString2Vo(TaskBto task, int cityLevel, String statString) {
public List<CheckDeviceStatVo> parseStatString2Vo(TaskBto task, String statString) {
List<CheckDeviceStatVo> statVoList = new ArrayList<>();
//分为 id - status 的数组 其中status 0缺失 1无误 2新增 3不在库
String[] statArray = statString.split(",");
......@@ -633,10 +632,6 @@ public class DeviceCheckController {
.collect(toMap(CheckDeviceStatVo::getDeviceModel, Function.identity(), CheckDeviceStatVo::reduce))
.values();
//构造最终数据
LocalDate startTime = LocalDate.now();
LocalDate endTime = startTime.plusMonths(1);
return new DeviceCheckStat(title,
startUnitName + "待核查装备统计单",
JacksonUtil.toJSon(new ArrayList<>(statVos)),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论