提交 723c7806 authored 作者: Matrix's avatar Matrix

fix(核查模块): 增加了终止任务功能

上级 62b1a8c5
package com.tykj.dev.device.confirmcheck.common;
import com.tykj.dev.device.confirmcheck.entity.vo.LinkVo;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* CcDataCache. 核查模块自用缓存
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/23 at 5:32 下午
*/
@Data
public class CcDataCache {
public static Map<Integer, LinkVo> linkVoCache = new HashMap<>();
}
package com.tykj.dev.device.confirmcheck.common;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import java.util.HashMap;
/**
* CcInitRunner.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/23 at 5:30 下午
*/
@Order(99)
public class CcInitRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
//初始化Map 从DB里面拿数据
CcDataCache.linkVoCache = new HashMap<>(32);
}
}
package com.tykj.dev.device.confirmcheck.controller;
import com.alibaba.fastjson.JSON;
import com.github.wenhao.jpa.Specifications;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.sun.tools.corba.se.idl.StringGen;
import com.tykj.dev.config.GlobalMap;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.confirmcheck.common.CcNodeType;
......@@ -10,10 +12,12 @@ import com.tykj.dev.device.confirmcheck.common.CheckChart;
import com.tykj.dev.device.confirmcheck.common.CheckType;
import com.tykj.dev.device.confirmcheck.common.TaskPeriod;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckLink;
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.ConfirmCheckService;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
......@@ -87,6 +91,11 @@ public class DeviceCheckController {
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
......@@ -121,8 +130,6 @@ public class DeviceCheckController {
private MyWebSocket myWebSocket;
@Autowired
private SelfCheckController selfCheckController;
private int specialDetailId = 0;
private List<String> specialUnits = new ArrayList<>();
@Autowired
private MessageService messageService;
@Autowired
......@@ -370,42 +377,63 @@ public class DeviceCheckController {
return devLib;
}
/**
* 该接口负责处理以下跳转情况
* 1 - 统计跳转
* 1-1 省核查页面 - 市的检查以及省直属的自查任务
* 2 - 详情跳转
*
* @param type 7 统计 8 详情
* @param type 7 统计
* @param billId 业务id
* @return
*/
@ApiOperation(value = "统一跳转接口", notes = "可以通过这个接口进行跳转")
@GetMapping("/link")
public ResponseEntity unionLink(@RequestParam Integer type, @RequestParam Integer billId) {
public ResponseEntity<LinkVo> unionLink(@RequestParam Integer type, @RequestParam Integer billId) {
if (type != CONFIRM_CHECK_STAT.id) {
throw new ApiException("link跳转接口提供的type应当为7,你提供的是 " + type);
}
LinkVo linkVo = new LinkVo();
// 默认的shutDown状态为false
linkVo.setShutDown(false);
//type = 7 统计
if (type.equals(CONFIRM_CHECK_STAT.id)) {
DeviceCheckStat ct = statRepo.findById(billId).get();
CheckStatVo ctVo = transUtil.checkStatDo2Vo(ct);
linkVo.setTitle(ctVo.getTitle());
LocalDateTime endTime = ctVo.getEndTime();
endTime = LocalDateTime.of(ctVo.getEndTime().toLocalDate(), LocalTime.MAX);
// LocalDateTime endTime = ctVo.getEndTime().plusDays(1);
//新增修改时间
LocalDateTime updateTime = ctVo.getUpdateTime();
// linkVo.setEndTime(ctVo.getEndTime().toLocalDate());
linkVo.setEndTime(LocalDateTime.of(ctVo.getEndTime().toLocalDate(), LocalTime.MAX).toLocalDate());
List<LinkCheckDetail> lcdList = new ArrayList<>();
List<LinkExamDetail> ledList = new ArrayList<>();
// if else 结果 1.核查页面(市检查and省直属单位自查) 2.检查页面 (均为单位自查)
// check type = 0 核查页面 看见的是市检查与省直属自查
DeviceCheckStat ct = statRepo.findById(billId).get();
CheckStatVo ctVo = transUtil.checkStatDo2Vo(ct);
linkVo.setTitle(ctVo.getTitle());
LocalDateTime endTime = ctVo.getEndTime();
endTime = LocalDateTime.of(ctVo.getEndTime().toLocalDate(), LocalTime.MAX);
//新增修改时间
LocalDateTime updateTime = ctVo.getUpdateTime();
linkVo.setEndTime(LocalDateTime.of(ctVo.getEndTime().toLocalDate(), LocalTime.MAX).toLocalDate());
List<LinkCheckDetail> lcdList = new ArrayList<>();
List<LinkExamDetail> ledList = new ArrayList<>();
//是否要走缓存,如果该任务taskId = 20000,则调用上次保存的结果(取另外一张表),否则即时计算并保存结果
// 获取核查/检查的任务节点
Task rootTask = taskRepo.findAllByBillIdAndBusinessType(billId, type).stream()
.filter(task -> Objects.nonNull(task.getCustomInfo()) && ("exam".equals(task.getCustomInfo()) || "check".equals(task.getCustomInfo())))
.findFirst()
.orElseThrow(() -> new ApiException("[核查模块]没有找到对应billId的统计任务,您给的billId = " + billId));
// key = stat id ,value = LinkVo
if (rootTask.getBillStatus().equals(REVOKEALLOTTASK.id)) {
// 拿之前保存的缓存
linkVo = linkRepo.findByStatId(billId)
.orElseThrow(() -> new ApiException(String.format("没有找到stat id = %d 的统计缓存,请检查数据", billId)))
.toVo()
.getLinkVo();
linkVo.setShutDown(true);
}
else {
// 正常处理,即时计算
// checkType = 0 核查,checkType = 1 检查
if (ctVo.getCheckType() == 0) {
linkVo.setType(1);
// 根据tpye和billId找到父级节点 - 默认了最顶级的省核查节点应当为一个
Task rootTask = taskRepo.findAllByBillIdAndBusinessType(billId, type).get(0);
// 先检出所有类型为7或者8的Task集合 方便后续操作
Specification<Task> pred = Specifications.<Task>and()
......@@ -529,11 +557,7 @@ public class DeviceCheckController {
} else {
linkVo.setType(3);
}
//看到的都是自查 根据tpye和billId找到父级节点 这里的根节点只能是检查节点
Task rootTask = taskRepo.findAllByBillIdAndBusinessType(billId, type).stream()
.filter(task -> Objects.nonNull(task.getCustomInfo()) && task.getCustomInfo().contains("exam"))
.findFirst()
.orElseThrow(() -> new ApiException("[核查模块]没有找到对应billId的检查任务,您给的billId = " + billId));
// 找到所有的子节点
List<Task> childTask = taskRepo.findAllByParentTaskId(rootTask.getId());
......@@ -576,11 +600,11 @@ public class DeviceCheckController {
}
}
// type = 8 跳转
if (type.equals(CONFIRM_CHECK_DETAIL.id)) {
linkVo.setType(4);
linkVo.setDetailId(billId);
}
//将此次使用的linkVo更新
DeviceCheckLink updateLink = linkRepo.findByStatId(billId) .orElse(new DeviceCheckLink());
updateLink.setLinkText(JSON.toJSONStringWithDateFormat(linkVo,"yyyy-MM-dd"));
updateLink.setStatId(billId);
linkRepo.save(updateLink);
return ResponseEntity.ok(linkVo);
......@@ -972,7 +996,7 @@ public class DeviceCheckController {
TaskBto provStatTask = new Task(CHECK_STAT_1.id, getUnitDateString(startUnit, ccVO.getTitle()), 0, ".0.", CONFIRM_CHECK_STAT.id, statId, startUnitId)
.parse2Bto();
provStatTask.getInvolveUserIdList().add(authenticationUtils.getAuthentication().getCurrentUserInfo().getUserId());
provStatTask.getInvolveUserIdList().add(-1);
provStatTask.getInvolveUserIdList().add(0);
provStatTask.setCurrentPoint(1);
provStatTask.setCustomInfo("check");
provStatTask = taskService.start(provStatTask);
......@@ -1557,13 +1581,20 @@ public class DeviceCheckController {
@ApiOperation(value = "终结stat任务,多指核查任务")
@PutMapping("/stat/shutdown/{statId}")
public ResponseEntity shutDown(@PathVariable Integer statId) {
//
log.info("[核查模块] 终止任务 - 正在终止statId = {} 的统计任务",statId);
Task checkTask = taskRepo.findByBillIdAndBusinessType(statId, CONFIRM_CHECK_STAT.id).get();
// 将该stat任务置为20000,即终止
unionLink(7, statId);
taskService.moveToSpecial(checkTask.parse2Bto(), REVOKEALLOTTASK);
// 检验所有还没有end的节点
// 1级节点分为两类 自查类节点&统计数据确认节点 以及 检查类节点
List<Task> l1Childs = taskRepo.findAllByParentTaskId(checkTask.getId());
for (Task c1 : l1Childs) {
if (predNodeType(c1).equals(CcNodeType.EXAM)) {
// c1里的检查节点也shutDown掉 并保存掉
unionLink(7, c1.getBillId());//save
taskService.moveToSpecial(c1.parse2Bto(), REVOKEALLOTTASK);
List<Task> c2Childs = taskRepo.findAllByParentTaskId(c1.getId());
c2Childs.forEach(c2 -> shutDownNode(c2));
} else {
......@@ -1574,6 +1605,35 @@ public class DeviceCheckController {
return ResponseEntity.ok(String.format("任务节点task id = %d 的任务已经成功关闭", checkTask.getId()));
}
/**
* 关闭某个节点,该节点下必须没有子节点树了
* <p>1.将该任务进度推进至9999</>
* <p>2.手动补充终结日志</>
* <p>3.将终结信息添加阅知列表里面</>
*
* @param node
*/
private void shutDownNode(Task node) {
log.info("[核查模块] 终止任务-正在关闭 task id = {} 的任务节点");
// 如果是核查类捡点,抛出异常
if (node.getCustomInfo().equals("check") || node.getCustomInfo().equals("exam")) {
throw new ApiException("关闭节点里不处理核查/核查节点...,你提供的任务节点id = " + node.getId());
}
// 其余节点,执行关闭策略
// 1.将该任务进度推进至9999
TaskBto nodeBto = node.parse2Bto();
taskService.moveToEnd(nodeBto);
// 2.手动补充终结日志
String adminUser = authenticationUtils.getAuthentication().getCurrentUserInfo().getName();
String shutDownMsg = String.format("专管员[%s]终止了该任务", adminUser);
TaskLogBto taskLog = new TaskLogBto(node.getId(), shutDownMsg);
taskLogService.addLog(taskLog);
// 3.添加阅知信息
MessageBto msgBto = new MessageBto(node.getId(), node.getBusinessType(), shutDownMsg, nodeBto.getInvolveUserIdList());
messageService.add(msgBto);
log.info("[核查模块] 终止任务-task id = {} 成功关闭");
}
/**
* 将detail里的detailString里的检查数字该为指定数值
*
......@@ -1776,35 +1836,6 @@ public class DeviceCheckController {
statRepo.save(statVo.toDo());
}
/**
* 关闭某个节点,该节点下必须没有子节点树了
* <p>1.将该任务进度推进至9999</>
* <p>2.手动补充终结日志</>
* <p>3.将终结信息添加阅知列表里面</>
*
* @param node
*/
private void shutDownNode(Task node) {
log.info("[核查模块] 终止任务-正在关闭 task id = {} 的任务节点");
// 如果是核查类捡点,抛出异常
if (node.getCustomInfo().equals("check") || node.getCustomInfo().equals("exam")) {
throw new ApiException("关闭节点里不处理核查/核查节点...,你提供的任务节点id = " + node.getId());
}
// 其余节点,执行关闭策略
// 1.将该任务进度推进至9999
TaskBto nodeBto = node.parse2Bto();
taskService.moveToEnd(nodeBto);
// 2.手动补充终结日志
String adminUser = authenticationUtils.getAuthentication().getCurrentUserInfo().getName();
String shutDownMsg = String.format("专管员[%s]终止了该任务", adminUser);
TaskLogBto taskLog = new TaskLogBto(node.getId(), shutDownMsg);
taskLogService.addLog(taskLog);
// 3.添加阅知信息
MessageBto msgBto = new MessageBto(node.getId(), node.getBusinessType(), shutDownMsg, nodeBto.getInvolveUserIdList());
messageService.add(msgBto);
log.info("[核查模块] 终止任务-task id = {} 成功关闭");
}
/**
* 用来判断该节点类型
*
......@@ -1939,23 +1970,7 @@ public class DeviceCheckController {
taskService.moveToEnd(d.parse2Bto());
}
}
if (hasParent) {
//市统计的办结 -> 开启对应市 数据确认任务for 省s
Units units = unitsRepo.findById(currentTask.getOwnUnit()).get();
String areaName = auService.findOne(AuExample.UnitId, currentTask.getOwnUnit()).getName();
Integer provId = areaRepo.findAreasByType(1).stream()
.min(Comparator.comparing(Area::getId))
.get()
.getId();
String provTitle = taskRepo.findById(parentTaskId).get().getTitle();
TaskBto cityDoneTask = new TaskBto(CONFIRM_STAT_0.id, provTitle + "统计数据确认任务", parentTaskId, ".", CONFIRM_CHECK_STAT.id, statId, provId, 0);
cityDoneTask.getInvolveUserIdList().add(0);
cityDoneTask.setCurrentPoint(cityDoneTask.getCurrentPoint() + 1);
cityDoneTask.setCustomInfo("");
cityDoneTask = taskService.start(cityDoneTask);
log.info("[核查模块] 统计确认待办任务生成成功, id为 : {}", cityDoneTask.getId());
}
// 停止创建省办结任务
log.info("[核查模块] 统计数据确认操作成功");
return ResponseEntity.ok(new ResultObj<>("统计数据确认完毕"));
......
package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.device.confirmcheck.entity.vo.DeviceCheckLinkVo;
import com.tykj.dev.device.confirmcheck.entity.vo.LinkVo;
import com.tykj.dev.device.confirmcheck.utils.MapperHelper;
import com.tykj.dev.misc.base.BaseEntity;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.modelmapper.ModelMapper;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;
/**
* DeviceCheckLink.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/23 at 5:40 下午
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@SQLDelete(sql = "update device_check_link set delete_tag = 1 where id = ?")
@ApiModel("核查检查列表的缓存表")
@NoArgsConstructor
@Table(name = "device_check_link")
public class DeviceCheckLink extends BaseEntity {
private Integer statId;
@Column(name = "link_text", columnDefinition = "TEXT")
private String linkText;
public DeviceCheckLinkVo toVo() {
ModelMapper mapper = MapperHelper.getMapper();
DeviceCheckLinkVo dcLinkVo = mapper.map(this, DeviceCheckLinkVo.class);
LinkVo linkVo = JacksonUtil.readValue(linkText, LinkVo.class);
dcLinkVo.setLinkVo(linkVo);
return dcLinkVo;
}
public DeviceCheckLink(Integer statId , String linkText) {
this.statId = statId;
this.linkText = linkText;
}
public DeviceCheckLink(Integer id, Integer createUserId, Integer updateUserId, LocalDateTime createTime, LocalDateTime updateTime, Integer deleteTag, Integer statId, String linkText) {
super(id, createUserId, updateUserId, createTime, updateTime, deleteTag);
this.statId = statId;
this.linkText = linkText;
}
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import com.alibaba.fastjson.JSON;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckLink;
import com.tykj.dev.device.confirmcheck.utils.MapperHelper;
import com.tykj.dev.misc.base.BaseVo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import java.time.LocalDateTime;
/**
* DeviceCheckLinkVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/24 at 10:58 上午
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class DeviceCheckLinkVo extends BaseVo {
private Integer statId;
private LinkVo linkVo;
public DeviceCheckLinkVo(Integer statId, LinkVo linkVo) {
this.statId = statId;
this.linkVo = linkVo;
}
public DeviceCheckLinkVo(Integer id, Integer createUserId, Integer updateUserId, LocalDateTime createTime, LocalDateTime updateTime, Integer deleteTag, Integer statId, LinkVo linkVo) {
super(id, createUserId, updateUserId, createTime, updateTime, deleteTag);
this.statId = statId;
this.linkVo = linkVo;
}
public DeviceCheckLink toDo() {
ModelMapper mapper = MapperHelper.getMapper();
DeviceCheckLink dcLink = mapper.map(this, DeviceCheckLink.class);
String linkText = JSON.toJSONStringWithDateFormat(this.linkVo, "yyyy-MM-dd HH:mm:ss");
dcLink.setLinkText(linkText);
return dcLink;
}
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.List;
......@@ -25,11 +31,19 @@ public class LinkVo {
*/
private int type;
/**
* 是否终结 true = 已终结 ,false = 未终结
*/
private boolean isShutDown;
/**
* 核查/检查总标题
*/
private String title;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate endTime;
/**
......@@ -48,4 +62,13 @@ public class LinkVo {
this.type = type;
this.endTime = endTime;
}
// public LinkVo(int type, String title, String endTime, List<LinkCheckDetail> lcDetail, List<LinkExamDetail> leDetail, int detailId) {
// this.type = type;
// this.title = title;
// this.endTime = LocalDate.parse(endTime);
// this.lcDetail = lcDetail;
// this.leDetail = leDetail;
// this.detailId = detailId;
// }
}
package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckLink;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* DeviceCheckLinkDao.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/24 at 11:05 上午
*/
@Repository
public interface DeviceCheckLinkDao extends JpaRepository<DeviceCheckLink, Integer>, JpaSpecificationExecutor<DeviceCheckLink> {
Optional<DeviceCheckLink> findByStatId(Integer statId);
}
......@@ -42,6 +42,8 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.tykj.dev.misc.base.StatusEnum.END;
import static com.tykj.dev.misc.base.StatusEnum.REVOKEALLOTTASK;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
......@@ -164,7 +166,7 @@ public class ObjTransUtil {
long total = childTask.size();
long done = childTask.stream()
.filter(task -> task.getBillStatus().equals(9999))
.filter(task -> task.getBillStatus().equals(END.id)||task.getBillStatus().equals(REVOKEALLOTTASK.id))
.count();
//如果是检查统计的话那么还要看一下他的父节点是不是已经完成了
......
......@@ -9,6 +9,7 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.time.LocalDateTime;
......@@ -52,12 +53,14 @@ public class BaseEntity {
* 创建时间
*/
@CreatedDate
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/**
* 更新时间
*/
@LastModifiedDate
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
/**
......
package com.tykj.dev.misc.base;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;
/**
* BaseVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2021/9/24 at 11:02 上午
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseVo {
/**
* 主键id
*/
private Integer id;
/**
* 创建用户id
*/
private Integer createUserId;
/**
* 更新用户id
*/
private Integer updateUserId;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
private Integer deleteTag = 0;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论