初始代码
This commit is contained in:
27
yunzhupaas-flowable/yunzhupaas-flowable-controller/pom.xml
Normal file
27
yunzhupaas-flowable/yunzhupaas-flowable-controller/pom.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-flowable</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-flowable-controller</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-flowable-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-exception</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.CommentEntity;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.flowable.entity.TemplateNodeEntity;
|
||||
import com.yunzhupaas.flowable.enums.NodeEnum;
|
||||
import com.yunzhupaas.flowable.model.comment.CommentCrForm;
|
||||
import com.yunzhupaas.flowable.model.comment.CommentListVO;
|
||||
import com.yunzhupaas.flowable.model.comment.CommentPagination;
|
||||
import com.yunzhupaas.flowable.model.templatenode.nodejson.NodeModel;
|
||||
import com.yunzhupaas.flowable.service.CommentService;
|
||||
import com.yunzhupaas.flowable.service.TaskService;
|
||||
import com.yunzhupaas.flowable.service.TemplateNodeService;
|
||||
import com.yunzhupaas.flowable.util.ServiceUtil;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UploaderUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 流程评论
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
*/
|
||||
@Tag(name = "流程评论", description = "Comment")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/comment")
|
||||
public class CommentController extends SuperController<CommentService, CommentEntity> {
|
||||
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
@Autowired
|
||||
private TemplateNodeService templateNodeService;
|
||||
|
||||
/**
|
||||
* 获取流程评论列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取流程评论列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<CommentListVO>> list(CommentPagination pagination) {
|
||||
List<CommentEntity> list = commentService.getlist(pagination);
|
||||
List<String> replyId = list.stream().filter(t -> StringUtil.isNotEmpty(t.getReplyId())).map(CommentEntity::getReplyId).collect(Collectors.toList());
|
||||
List<CommentEntity> replyList = commentService.getlist(replyId);
|
||||
List<CommentListVO> listVO = JsonUtil.getJsonToList(list, CommentListVO.class);
|
||||
List<String> userId = list.stream().map(t -> t.getCreatorUserId()).collect(Collectors.toList());
|
||||
userId.addAll(replyList.stream().map(CommentEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
List<UserEntity> userName = serviceUtil.getUserName(userId);
|
||||
for (CommentListVO commentModel : listVO) {
|
||||
UserEntity userEntity = userName.stream().filter(t -> t.getId().equals(commentModel.getCreatorUserId())).findFirst().orElse(null);
|
||||
if (commentModel.getCreatorUserId().equals(userInfo.getUserId()) && !"1".equals(String.valueOf(commentModel.getDeleteShow()))) {
|
||||
commentModel.setIsDel(1); //1-删除按钮显示
|
||||
} else if ("1".equals(String.valueOf(commentModel.getDeleteShow()))) {
|
||||
commentModel.setIsDel(2); //1-删除按钮显示
|
||||
commentModel.setText("该评论已被删除");
|
||||
} else {
|
||||
commentModel.setIsDel(0);
|
||||
}
|
||||
commentModel.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
|
||||
commentModel.setCreatorUserHeadIcon(userEntity != null ? UploaderUtil.uploaderImg(userEntity.getHeadIcon()) : commentModel.getCreatorUserHeadIcon());
|
||||
List<CommentEntity> collect = replyList.stream().filter(t -> t.getId().equals(commentModel.getReplyId())).collect(Collectors.toList());
|
||||
StringJoiner name = new StringJoiner(",");
|
||||
StringJoiner text = new StringJoiner(",");
|
||||
for (CommentEntity replyEntity : collect) {
|
||||
if (null != replyEntity) {
|
||||
UserEntity user = userName.stream().filter(t -> t.getId().equals(replyEntity.getCreatorUserId())).findFirst().orElse(null);
|
||||
if (user != null) {
|
||||
name.add(user.getRealName() + "/" + user.getAccount());
|
||||
}
|
||||
String resText = ("1".equals(String.valueOf(replyEntity.getDeleteShow())) || "1".equals(String.valueOf(replyEntity.getDeleteMark()))) ? "该评论已被删除" : replyEntity.getText();
|
||||
text.add(resText);
|
||||
}
|
||||
}
|
||||
commentModel.setReplyText(text.toString());
|
||||
commentModel.setReplyUser(name.toString());
|
||||
CommentEntity entity = list.stream().filter(e -> ObjectUtil.equals(e.getId(), commentModel.getId())).findFirst().orElse(null);
|
||||
if (null != entity) {
|
||||
commentModel.setFile(entity.getFiles());
|
||||
}
|
||||
}
|
||||
PaginationVO vo = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建流程评论
|
||||
*
|
||||
* @param commentForm 流程评论模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建流程评论")
|
||||
@PostMapping
|
||||
@Parameters({
|
||||
@Parameter(name = "commentForm", description = "流程评论模型", required = true),
|
||||
})
|
||||
public ActionResult create(@RequestBody @Valid CommentCrForm commentForm) throws WorkFlowException {
|
||||
CommentEntity entity = JsonUtil.getJsonToBean(commentForm, CommentEntity.class);
|
||||
entity.setFiles(commentForm.getFile());
|
||||
commentService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流程评论
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除流程评论")
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
CommentEntity entity = commentService.getInfo(id);
|
||||
if (entity.getCreatorUserId().equals(UserProvider.getUser().getUserId())) {
|
||||
boolean delComment = false;
|
||||
TaskEntity task = taskService.getInfoSubmit(entity.getTaskId(), TaskEntity::getId, TaskEntity::getFlowId);
|
||||
if (task != null) {
|
||||
TemplateNodeEntity nodeEntity = templateNodeService.getList(task.getFlowId()).stream().filter(e -> StringUtil.equals(NodeEnum.global.getType(), e.getNodeType())).findFirst().orElse(null);
|
||||
if (nodeEntity != null) {
|
||||
NodeModel nodeModel = JsonUtil.getJsonToBean(nodeEntity.getNodeJson(), NodeModel.class);
|
||||
delComment = nodeModel.getHasCommentDeletedTips();
|
||||
}
|
||||
}
|
||||
commentService.delete(entity, delComment);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.DelegateEntity;
|
||||
import com.yunzhupaas.flowable.entity.DelegateInfoEntity;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateUserVo;
|
||||
import com.yunzhupaas.flowable.model.delegate.*;
|
||||
import com.yunzhupaas.flowable.model.template.TemplatePageLisVO;
|
||||
import com.yunzhupaas.flowable.model.template.TemplatePagination;
|
||||
import com.yunzhupaas.flowable.service.DelegateInfoService;
|
||||
import com.yunzhupaas.flowable.service.DelegateService;
|
||||
import com.yunzhupaas.flowable.util.ServiceUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的描述
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/5/13 17:27
|
||||
*/
|
||||
@Tag(name = "流程委托", description = "DelegateController")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/delegate")
|
||||
public class DelegateController extends SuperController<DelegateService, DelegateEntity> {
|
||||
@Autowired
|
||||
private DelegateService delegateService;
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
@Autowired
|
||||
private DelegateInfoService delegateInfoService;
|
||||
|
||||
/**
|
||||
* 获取流程委托列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "获取流程委托列表")
|
||||
@GetMapping
|
||||
public ActionResult list(DelegatePagination pagination) {
|
||||
List<DelegateListVO> voList;
|
||||
if (ObjectUtil.equals(pagination.getType(), 2) || ObjectUtil.equals(pagination.getType(), 4)) {
|
||||
voList = delegateInfoService.getList(pagination);
|
||||
} else {
|
||||
voList = delegateService.getList(pagination);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 委托信息列表
|
||||
*
|
||||
* @param delegateId 委托主键
|
||||
*/
|
||||
@Operation(summary = "委托信息列表")
|
||||
@GetMapping("/Info/{delegateId}")
|
||||
public ActionResult getDelegateInfo(@PathVariable("delegateId") String delegateId) {
|
||||
List<DelegateInfoEntity> list = delegateInfoService.getList(delegateId);
|
||||
return ActionResult.success(JsonUtil.getJsonToList(list, DelegateListVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程委托信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "获取流程委托信息")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult info(@PathVariable("id") String id) throws WorkFlowException {
|
||||
DelegateEntity entity = delegateService.getInfo(id);
|
||||
if (null == entity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
DelegateInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, DelegateInfoVO.class);
|
||||
List<DelegateInfoEntity> infoList = delegateInfoService.getList(entity.getId());
|
||||
if (CollectionUtil.isNotEmpty(infoList)) {
|
||||
List<String> toUserNameList = infoList.stream().map(DelegateInfoEntity::getToUserName)
|
||||
.collect(Collectors.toList());
|
||||
vo.setToUserName(String.join(",", toUserNameList));
|
||||
List<String> toUserIdList = infoList.stream().map(DelegateInfoEntity::getToUserId)
|
||||
.collect(Collectors.toList());
|
||||
vo.setToUserId(toUserIdList);
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建流程委托
|
||||
*
|
||||
* @param fo 参数
|
||||
*/
|
||||
@Operation(summary = "新建流程委托")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DelegateCrForm fo) {
|
||||
// 超管和管理员不能新增委托/代理(即:只有普通用户身份才能新建委托/代理,提示:“管理员不能新建委托/代理”)
|
||||
if (!serviceUtil.isCommonUser(UserProvider.getLoginUserId())) {
|
||||
return ActionResult.fail(MsgCode.WF130.get());
|
||||
}
|
||||
if (StringUtil.isBlank(fo.getUserId())) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
fo.setUserId(userInfo.getUserId());
|
||||
fo.setUserName(userInfo.getUserName() + "/" + userInfo.getUserAccount());
|
||||
}
|
||||
boolean isDelegate = ObjectUtil.equals(fo.getType(), "0");
|
||||
if (fo.getToUserId().contains(fo.getUserId())) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF017.get() : MsgCode.WF137.get());
|
||||
}
|
||||
// 受托人/代理人不能选择admin和本人
|
||||
List<String> toUserList = fo.getToUserId();
|
||||
String admin = serviceUtil.getAdmin();
|
||||
for (String toUser : toUserList) {
|
||||
if (ObjectUtil.equals(toUser, admin)) {
|
||||
return ActionResult.fail(MsgCode.WF131.get());
|
||||
}
|
||||
}
|
||||
if (this.alreadyDelegate(fo, null)) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF018.get() : MsgCode.WF144.get());
|
||||
}
|
||||
DelegateCrForm reverse = new DelegateCrForm();
|
||||
BeanUtils.copyProperties(fo, reverse);
|
||||
reverse.setUserIdList(fo.getToUserId());
|
||||
reverse.setToUserId(ImmutableList.of(fo.getUserId()));
|
||||
if (this.alreadyDelegate(reverse, null)) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF019.get() : MsgCode.WF145.get());
|
||||
}
|
||||
delegateService.create(fo);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新流程委托
|
||||
*
|
||||
* @param id 主键
|
||||
* @param fo 参数
|
||||
*/
|
||||
@Operation(summary = "更新流程委托")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DelegateUpForm fo)
|
||||
throws WorkFlowException {
|
||||
DelegateEntity entity = delegateService.getInfo(id);
|
||||
if (null == entity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
fo.setUserId(entity.getUserId());
|
||||
boolean isDelegate = ObjectUtil.equals(fo.getType(), "0");
|
||||
if (fo.getToUserId().contains(fo.getUserId())) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF017.get() : MsgCode.WF137.get());
|
||||
}
|
||||
if (this.alreadyDelegate(fo, id)) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF018.get() : MsgCode.WF144.get());
|
||||
}
|
||||
// 判断是否有人接受
|
||||
List<DelegateInfoEntity> infoList = delegateInfoService.getList(id);
|
||||
if (CollectionUtil.isNotEmpty(infoList)) {
|
||||
DelegateInfoEntity delegateInfoEntity = infoList.stream().filter(e -> ObjectUtil.equals(e.getStatus(), 1))
|
||||
.findFirst().orElse(null);
|
||||
if (null != delegateInfoEntity) {
|
||||
return ActionResult.fail(MsgCode.WF132.get());
|
||||
}
|
||||
}
|
||||
DelegateCrForm reverse = new DelegateCrForm();
|
||||
BeanUtils.copyProperties(fo, reverse);
|
||||
reverse.setUserIdList(fo.getToUserId());
|
||||
reverse.setToUserId(ImmutableList.of(fo.getUserId()));
|
||||
if (this.alreadyDelegate(reverse, id)) {
|
||||
return ActionResult.fail(isDelegate ? MsgCode.WF019.get() : MsgCode.WF145.get());
|
||||
}
|
||||
if (delegateService.update(entity, fo)) {
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
// 判断是否已有委托
|
||||
private boolean alreadyDelegate(DelegateCrForm form, String id) {
|
||||
List<DelegateEntity> delegateEntities = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(form.getUserIdList())) {
|
||||
for (String userId : form.getUserIdList()) {
|
||||
form.setUserId(userId);
|
||||
List<DelegateEntity> list = delegateService.selectSameParamAboutDelaget(form);
|
||||
delegateEntities.addAll(list);
|
||||
}
|
||||
} else {
|
||||
delegateEntities = delegateService.selectSameParamAboutDelaget(form);
|
||||
}
|
||||
for (DelegateEntity delegate : delegateEntities) {
|
||||
if (delegate.getId().equals(id)) {
|
||||
continue;
|
||||
}
|
||||
// 时间交叉
|
||||
if ((form.getStartTime() <= delegate.getStartTime().getTime()
|
||||
&& form.getEndTime() >= delegate.getStartTime().getTime()) ||
|
||||
(form.getStartTime() >= delegate.getStartTime().getTime()
|
||||
&& form.getStartTime() <= delegate.getEndTime().getTime())) {
|
||||
if (StringUtil.isEmpty(form.getFlowId())) {
|
||||
return true;
|
||||
} else {
|
||||
if (StringUtil.isEmpty(delegate.getFlowId())) {
|
||||
return true;
|
||||
} else {
|
||||
List<String> split = Arrays.asList(delegate.getFlowId().split(","));
|
||||
List<String> split1 = Arrays.asList(form.getFlowId().split(","));
|
||||
for (String srt : split) {
|
||||
if (split1.contains(srt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束委托
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "结束委托")
|
||||
@PutMapping("/Stop/{id}")
|
||||
public ActionResult stop(@PathVariable("id") String id) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.SECOND, -1);
|
||||
Date date = calendar.getTime();
|
||||
DelegateEntity entity = delegateService.getInfo(id);
|
||||
if (null != entity) {
|
||||
entity.setStartTime(date);
|
||||
entity.setEndTime(date);
|
||||
delegateService.updateStop(id, entity);
|
||||
return ActionResult.success(MsgCode.SU008.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流程委托
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "删除流程委托")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
DelegateEntity entity = delegateService.getInfo(id);
|
||||
if (null != entity) {
|
||||
delegateService.delete(entity);
|
||||
delegateInfoService.delete(entity.getId());
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 被委托发起
|
||||
* 根据被委托人查询可发起的流程列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "被委托发起")
|
||||
@GetMapping("/GetFlow")
|
||||
public ActionResult getFlow(TemplatePagination pagination) {
|
||||
List<TemplatePageLisVO> flows = delegateService.getFlow(pagination);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
List<TemplatePageLisVO> voList = JsonUtil.getJsonToList(flows, TemplatePageLisVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取委托人
|
||||
* 根据被委托人查询可发起的流程列表
|
||||
*/
|
||||
@Operation(summary = "获取委托人")
|
||||
@GetMapping("/UserList")
|
||||
public ActionResult getUserListByFlowId(@RequestParam("templateId") String templateId) throws WorkFlowException {
|
||||
ListVO<CandidateUserVo> userList = delegateService.getUserList(templateId);
|
||||
return ActionResult.success(userList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认
|
||||
*
|
||||
* @param id 委托信息主键
|
||||
* @param type 类型,1.接受 2.拒绝
|
||||
*/
|
||||
@Operation(summary = "确认")
|
||||
@PostMapping("/Notarize/{id}")
|
||||
public ActionResult accept(@PathVariable("id") String id, @RequestParam("type") Integer type)
|
||||
throws WorkFlowException {
|
||||
DelegateInfoEntity delegateInfo = delegateInfoService.getById(id == null ? "" : id);
|
||||
if (null == delegateInfo) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
delegateInfo.setStatus(type);
|
||||
delegateService.notarize(delegateInfo);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.OperatorEntity;
|
||||
import com.yunzhupaas.flowable.entity.RecordEntity;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.flowable.enums.OperatorStateEnum;
|
||||
import com.yunzhupaas.flowable.enums.TaskStatusEnum;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateCheckFo;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateCheckVo;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateUserFo;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateUserVo;
|
||||
import com.yunzhupaas.flowable.model.operator.FlowBatchModel;
|
||||
import com.yunzhupaas.flowable.model.operator.OperatorVo;
|
||||
import com.yunzhupaas.flowable.model.operator.ReducePagination;
|
||||
import com.yunzhupaas.flowable.model.operator.ReduceUserModel;
|
||||
import com.yunzhupaas.flowable.model.task.AuditModel;
|
||||
import com.yunzhupaas.flowable.model.task.FlowModel;
|
||||
import com.yunzhupaas.flowable.model.task.TaskPagination;
|
||||
import com.yunzhupaas.flowable.model.templatenode.BackNodeModel;
|
||||
import com.yunzhupaas.flowable.model.util.FlowNature;
|
||||
import com.yunzhupaas.flowable.service.CirculateService;
|
||||
import com.yunzhupaas.flowable.service.OperatorService;
|
||||
import com.yunzhupaas.flowable.service.RecordService;
|
||||
import com.yunzhupaas.flowable.service.TaskService;
|
||||
import com.yunzhupaas.flowable.util.*;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的描述
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/4/25 14:48
|
||||
*/
|
||||
@Tag(name = "经办", description = "OperatorController")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/operator")
|
||||
@RequiredArgsConstructor
|
||||
public class OperatorController extends SuperController<OperatorService, OperatorEntity> {
|
||||
private final OperatorService operatorService;
|
||||
private final TaskService taskService;
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
@Autowired
|
||||
private RecordService recordService;
|
||||
@Autowired
|
||||
private CirculateService circulateService;
|
||||
@Autowired
|
||||
private OperatorUtil operatorUtil;
|
||||
@Autowired
|
||||
private TaskUtil taskUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private RedisLock redisLock;
|
||||
|
||||
/**
|
||||
* 判断候选人
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param fo 参数类
|
||||
*/
|
||||
@Operation(summary = "判断候选人")
|
||||
@PostMapping("/CandidateNode/{id}")
|
||||
public ActionResult candidates(@PathVariable("id") String id, @RequestBody CandidateCheckFo fo)
|
||||
throws WorkFlowException {
|
||||
return ActionResult.success(taskService.checkCandidates(id, fo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取候选人
|
||||
*
|
||||
* @param fo 参数类
|
||||
*/
|
||||
@Operation(summary = "获取候选人")
|
||||
@PostMapping("/CandidateUser/{id}")
|
||||
public ActionResult candidateUser(@PathVariable("id") String id, @RequestBody CandidateUserFo fo)
|
||||
throws WorkFlowException {
|
||||
List<CandidateUserVo> candidates = taskService.getCandidateUser(id, fo);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(fo, PaginationVO.class);
|
||||
return ActionResult.page(candidates, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param category 列表标识
|
||||
* @param pagination 参数
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping("/List/{category}")
|
||||
public ActionResult list(@PathVariable("category") String category, TaskPagination pagination) {
|
||||
List<OperatorVo> list = new ArrayList<>();
|
||||
pagination.setCategory(category);
|
||||
pagination.setDelegateType(true);
|
||||
switch (category) {
|
||||
case "0": // 待签
|
||||
case "1": // 待办
|
||||
case "2": // 在办
|
||||
case "5": // 批量在办
|
||||
list = operatorService.getList(pagination);
|
||||
break;
|
||||
case "3": // 已办
|
||||
list = recordService.getList(pagination);
|
||||
break;
|
||||
case "4": // 抄送
|
||||
list = circulateService.getList(pagination);
|
||||
}
|
||||
List<OperatorVo> vos = new ArrayList<>();
|
||||
List<UserEntity> userList = serviceUtil
|
||||
.getUserName(list.stream().map(OperatorVo::getCreatorUserId).collect(Collectors.toList()));
|
||||
for (OperatorVo operatorVo : list) {
|
||||
OperatorVo vo = JsonUtil.getJsonToBean(operatorVo, OperatorVo.class);
|
||||
UserEntity userEntity = userList.stream().filter(t -> t.getId().equals(vo.getCreatorUserId())).findFirst()
|
||||
.orElse(null);
|
||||
vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
|
||||
if (ObjectUtil.equals(operatorVo.getIsProcessing(), 1)
|
||||
&& ObjectUtil.equals(operatorVo.getStatus(), OperatorStateEnum.Transfer.getCode())) {
|
||||
vo.setStatus(OperatorStateEnum.TransferProcessing.getCode());
|
||||
}
|
||||
vos.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(vos, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签收或退签
|
||||
*
|
||||
* @param flowModel 参数类,ids 主键集合、type 0 签收 1 退签
|
||||
*/
|
||||
@Operation(summary = "签收或退签")
|
||||
@PostMapping("/Sign")
|
||||
public ActionResult<String> sign(@RequestBody FlowModel flowModel) throws WorkFlowException {
|
||||
operatorService.sign(flowModel);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始办理
|
||||
*
|
||||
* @param flowModel 参数类,ids 主键集合
|
||||
*/
|
||||
@Operation(summary = "开始办理")
|
||||
@PostMapping("/Transact")
|
||||
public ActionResult<String> startHandle(@RequestBody FlowModel flowModel) throws WorkFlowException {
|
||||
operatorService.startHandle(flowModel);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存草稿
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "保存草稿")
|
||||
@PostMapping("/SaveAudit/{id}")
|
||||
public ActionResult<String> saveAudit(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
operatorService.saveAudit(id, flowModel);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意拒绝
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "同意拒绝")
|
||||
@PostMapping("/Audit/{id}")
|
||||
public ActionResult audit(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws Exception {
|
||||
OperatorEntity operator = operatorUtil.checkOperator(id);
|
||||
TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
|
||||
if (null == taskEntity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
boolean lock = redisLock.lock(taskEntity.getId() + operator.getNodeId(), operator.getId(), 5, TimeUnit.SECONDS);
|
||||
if (!lock) {
|
||||
throw new WorkFlowException("当前节点正在审批中,请稍后再试");
|
||||
}
|
||||
Integer handleStatus = flowModel.getHandleStatus();
|
||||
try {
|
||||
operatorService.auditWithCheck(id, flowModel);
|
||||
List<OperatorEntity> list = flowModel.getList();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
TimeUtil.timeModel(list, flowModel, redisUtil);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
operatorUtil.compensate(taskEntity);
|
||||
throw e;
|
||||
} finally {
|
||||
redisLock.unlock(taskEntity.getId() + operator.getNodeId(), operator.getId());
|
||||
}
|
||||
operatorUtil.handleEvent();
|
||||
taskEntity = flowModel.getTaskEntity();
|
||||
if (taskEntity.getRejectDataId() == null) {
|
||||
operatorUtil.autoAudit(flowModel);
|
||||
operatorUtil.handleEvent();
|
||||
}
|
||||
TaskEntity task = taskService.getById(taskEntity.getId());
|
||||
taskEntity = task == null ? taskEntity : task;
|
||||
AuditModel model = taskUtil.getAuditModel(taskEntity.getId(), flowModel, operator);
|
||||
String msg = Objects.equals(handleStatus, FlowNature.RejectCompletion) ? MsgCode.WF065.get()
|
||||
: MsgCode.WF066.get();
|
||||
if (ObjectUtil.equals(operator.getIsProcessing(), 1)) {
|
||||
msg = MsgCode.WF148.get();
|
||||
}
|
||||
return ActionResult.success(msg, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加签
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "加签")
|
||||
@PostMapping("/AddSign/{id}")
|
||||
public ActionResult<String> freeApprover(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws Exception {
|
||||
operatorService.addSign(id, flowModel);
|
||||
operatorUtil.autoAudit(flowModel);
|
||||
operatorUtil.handleEvent();
|
||||
return ActionResult.success(MsgCode.WF004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加签的人
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param pagination 参数
|
||||
*/
|
||||
@Operation(summary = "获取加签的人")
|
||||
@PostMapping("/AddSignUserIdList/{id}")
|
||||
public ActionResult getAddSignUserIdList(@PathVariable("id") String id, @RequestBody ReducePagination pagination)
|
||||
throws WorkFlowException {
|
||||
List<ReduceUserModel> reduceList = operatorService.getReduceList(id, pagination);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(reduceList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减签
|
||||
*
|
||||
* @param flowModel 参数
|
||||
* @param id 记录主键
|
||||
*/
|
||||
@Operation(summary = "减签")
|
||||
@PostMapping("/ReduceApprover/{id}")
|
||||
public ActionResult<String> reduceApprover(@RequestBody FlowModel flowModel, @PathVariable("id") String id)
|
||||
throws WorkFlowException {
|
||||
operatorService.reduce(id, flowModel);
|
||||
return ActionResult.success(MsgCode.WF069.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退回的节点
|
||||
*
|
||||
* @param id 经办主键
|
||||
*/
|
||||
@Operation(summary = "获取退回的节点")
|
||||
@GetMapping("/SendBackNodeList/{id}")
|
||||
public ActionResult getFallbacks(@PathVariable("id") String id) throws WorkFlowException {
|
||||
ListVO<BackNodeModel> vo = new ListVO<>();
|
||||
vo.setList(operatorService.getFallbacks(id));
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退回
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "退回")
|
||||
@PostMapping("/SendBack/{id}")
|
||||
public ActionResult<String> reject(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws Exception {
|
||||
OperatorEntity operator = operatorUtil.checkOperator(id);
|
||||
TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
|
||||
if (null == taskEntity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
try {
|
||||
operatorService.back(id, flowModel);
|
||||
} catch (Exception e) {
|
||||
operatorUtil.compensate(taskEntity);
|
||||
throw e;
|
||||
}
|
||||
operatorUtil.event(flowModel, 9);
|
||||
return ActionResult.success(MsgCode.WF002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回
|
||||
*
|
||||
* @param id 记录主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "撤回")
|
||||
@PostMapping("/Recall/{taskRecordId}")
|
||||
public ActionResult<String> recall(@PathVariable("taskRecordId") String id, @RequestBody FlowModel flowModel)
|
||||
throws Exception {
|
||||
RecordEntity record = recordService.getInfo(id);
|
||||
if (null == record) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
if (record.getStatus().equals(FlowNature.Invalid)) {
|
||||
throw new WorkFlowException(MsgCode.WF005.get());
|
||||
}
|
||||
OperatorEntity operator = operatorService.getInfo(record.getOperatorId());
|
||||
if (null == operator) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
|
||||
if (null == taskEntity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
flowModel.setRecordEntity(record);
|
||||
flowModel.setOperatorEntity(operator);
|
||||
try {
|
||||
operatorService.recall(id, flowModel);
|
||||
} catch (Exception e) {
|
||||
operatorUtil.compensate(taskEntity);
|
||||
throw e;
|
||||
}
|
||||
operatorUtil.event(flowModel, 6);
|
||||
return ActionResult.success(MsgCode.WF008.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转审
|
||||
*
|
||||
* @param id 经办主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "转审")
|
||||
@PostMapping("/Transfer/{id}")
|
||||
public ActionResult<String> transfer(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws Exception {
|
||||
operatorService.transfer(id, flowModel);
|
||||
operatorUtil.autoAudit(flowModel);
|
||||
operatorUtil.handleEvent();
|
||||
OperatorEntity operator = operatorService.getById(id);
|
||||
return ActionResult
|
||||
.success(ObjectUtil.equals(operator.getIsProcessing(), 1) ? MsgCode.WF003.get() : MsgCode.WF152.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 协办
|
||||
*
|
||||
* @param id 主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "协办")
|
||||
@PostMapping("/Assist/{id}")
|
||||
public ActionResult<String> assist(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
operatorService.assist(id, flowModel);
|
||||
return ActionResult.success(MsgCode.WF067.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 协办保存
|
||||
*
|
||||
* @param id 主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "协办保存")
|
||||
@PostMapping("/AssistSave/{id}")
|
||||
public ActionResult<String> assistSave(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
operatorService.assistSave(id, flowModel);
|
||||
return ActionResult.success(MsgCode.WF068.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批流程分类列表
|
||||
*/
|
||||
@Operation(summary = "批量审批流程分类列表")
|
||||
@GetMapping("/BatchFlowSelector")
|
||||
public ActionResult<List<FlowBatchModel>> batchFlowSelector() {
|
||||
List<FlowBatchModel> list = operatorService.batchFlowSelector();
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批流程版本列表
|
||||
*
|
||||
* @param templateId 流程定义主键
|
||||
*/
|
||||
@Operation(summary = "批量审批流程版本列表")
|
||||
@GetMapping("/BatchVersionSelector/{templateId}")
|
||||
public ActionResult<List<FlowBatchModel>> batchVersionSelector(@PathVariable("templateId") String templateId) {
|
||||
List<FlowBatchModel> list = operatorService.batchVersionSelector(templateId);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批节点列表
|
||||
*
|
||||
* @param flowId 定义版本主键
|
||||
*/
|
||||
@Operation(summary = "批量审批节点列表")
|
||||
@GetMapping("/BatchNodeSelector/{flowId}")
|
||||
public ActionResult<List<FlowBatchModel>> batchNodeSelector(@PathVariable("flowId") String flowId) {
|
||||
List<FlowBatchModel> list = operatorService.batchNodeSelector(flowId);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批节点属性
|
||||
*
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "批量审批节点属性")
|
||||
@GetMapping("/BatchNode")
|
||||
public ActionResult batchNode(FlowModel flowModel) throws WorkFlowException {
|
||||
Map<String, Object> nodeMap = operatorService.batchNode(flowModel);
|
||||
return ActionResult.success(nodeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取候选人
|
||||
*
|
||||
* @param flowId 版本主键
|
||||
* @param operatorId 经办主键
|
||||
* @param batchType 类型,0.同意 1.拒绝
|
||||
*/
|
||||
@Operation(summary = "批量获取候选人")
|
||||
@GetMapping("/BatchCandidate")
|
||||
public ActionResult batchCandidate(String flowId, String operatorId, Integer batchType) throws WorkFlowException {
|
||||
CandidateCheckVo vo = operatorService.batchCandidates(flowId, operatorId, batchType);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批
|
||||
*
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "批量审批")
|
||||
@PostMapping("/BatchOperation")
|
||||
public ActionResult batchOperation(@RequestBody FlowModel flowModel) throws Exception {
|
||||
try {
|
||||
operatorService.batch(flowModel);
|
||||
} catch (Exception e) {
|
||||
List<TaskEntity> taskList = flowModel.getTaskList();
|
||||
if (CollectionUtil.isNotEmpty(taskList)) {
|
||||
for (TaskEntity taskEntity : taskList) {
|
||||
operatorUtil.compensate(taskEntity);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return ActionResult.success(MsgCode.WF011.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息跳转工作流
|
||||
*
|
||||
* @param id 经办或抄送主键
|
||||
*/
|
||||
@Operation(summary = "消息跳转工作流")
|
||||
@GetMapping("/{id}/Info")
|
||||
public ActionResult checkInfo(@PathVariable("id") String id,
|
||||
@RequestParam(value = "opType", required = false) String opType) throws WorkFlowException {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
List<String> list = ImmutableList.of(FlowNature.LaunchDetail, FlowNature.LaunchCreate);
|
||||
if (list.contains(opType)) {
|
||||
String type = FlowNature.LaunchDetail;
|
||||
TaskEntity task = taskService.getById(id);
|
||||
if (null != task) {
|
||||
taskUtil.checkTemplateHide(task.getTemplateId());
|
||||
if (ObjectUtil.equals(task.getStatus(), TaskStatusEnum.TO_BE_SUBMIT.getCode())) {
|
||||
type = FlowNature.LaunchCreate;
|
||||
}
|
||||
}
|
||||
map.put("opType", type);
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
String type = taskService.checkInfo(id);
|
||||
map.put("opType", type);
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进度节点记录列表
|
||||
*
|
||||
* @param taskId 任务主键
|
||||
* @param nodeId 节点id
|
||||
*/
|
||||
@Operation(summary = "进度节点记录列表")
|
||||
@GetMapping("/RecordList")
|
||||
public ActionResult getRecordList(@RequestParam("taskId") String taskId, @RequestParam("nodeId") String nodeId) {
|
||||
return ActionResult.success(recordService.getList(taskId, nodeId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.OperatorEntity;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.flowable.entity.TriggerTaskEntity;
|
||||
import com.yunzhupaas.flowable.enums.TaskStatusEnum;
|
||||
import com.yunzhupaas.flowable.model.task.*;
|
||||
import com.yunzhupaas.flowable.model.template.BeforeInfoVo;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerInfoModel;
|
||||
import com.yunzhupaas.flowable.service.TaskService;
|
||||
import com.yunzhupaas.flowable.service.TriggerTaskService;
|
||||
import com.yunzhupaas.flowable.util.OperatorUtil;
|
||||
import com.yunzhupaas.flowable.util.ServiceUtil;
|
||||
import com.yunzhupaas.flowable.util.TaskUtil;
|
||||
import com.yunzhupaas.flowable.util.TimeUtil;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.model.user.UserIdListVo;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 流程任务
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/4/17 15:13
|
||||
*/
|
||||
@Tag(name = "流程任务", description = "TaskController")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/task")
|
||||
@RequiredArgsConstructor
|
||||
public class TaskController extends SuperController<TaskService, TaskEntity> {
|
||||
private final TaskService taskService;
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
@Autowired
|
||||
private TaskUtil taskUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private OperatorUtil operatorUtil;
|
||||
@Autowired
|
||||
private TriggerTaskService triggerTaskService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id 任务id
|
||||
* @param fo 参数类
|
||||
*/
|
||||
@Operation(summary = "详情")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult getInfo(@PathVariable("id") String id, FlowModel fo) throws WorkFlowException {
|
||||
if (ObjectUtil.equals(fo.getType(), 2)) {
|
||||
TriggerInfoModel triggerInfo = triggerTaskService.getInfo(id);
|
||||
return ActionResult.success(triggerInfo);
|
||||
}
|
||||
return ActionResult.success(taskService.getInfo(id, fo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂存或提交
|
||||
*
|
||||
* @param fo 参数类
|
||||
*/
|
||||
@Operation(summary = "暂存或提交")
|
||||
@PostMapping
|
||||
public ActionResult saveOrSubmit(@RequestBody FlowModel fo) throws Exception {
|
||||
taskService.batchSaveOrSubmit(fo);
|
||||
if (ObjectUtil.equals(TaskStatusEnum.RUNNING.getCode(), fo.getStatus())) {
|
||||
operatorUtil.event(fo, 1);
|
||||
}
|
||||
TaskEntity taskEntity = fo.getTaskEntity();
|
||||
if (taskEntity.getRejectDataId() == null) {
|
||||
operatorUtil.autoAudit(fo);
|
||||
operatorUtil.handleEvent();
|
||||
}
|
||||
List<OperatorEntity> list = fo.getList();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
TimeUtil.timeModel(list, fo, redisUtil);
|
||||
}
|
||||
String msg = TaskStatusEnum.TO_BE_SUBMIT.getCode().equals(fo.getStatus()) ? MsgCode.SU002.get()
|
||||
: MsgCode.SU006.get();
|
||||
TaskEntity task = taskService.getById(taskEntity.getId());
|
||||
taskEntity = task == null ? taskEntity : task;
|
||||
AuditModel model = taskUtil.getAuditModel(taskEntity.getId(), fo, null);
|
||||
return ActionResult.success(msg, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂存或提交,已暂存的再次暂存或提交
|
||||
*
|
||||
* @param id 任务主键
|
||||
* @param fo 参数
|
||||
*/
|
||||
@Operation(summary = "暂存或提交(我发起的)")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult saveOrSubmit(@PathVariable("id") String id, @RequestBody FlowModel fo) throws Exception {
|
||||
Map<String, Object> data = fo.getFormData();
|
||||
String flowTaskID = Objects.nonNull(data.get(FlowFormConstant.FLOWTASKID))
|
||||
? data.get(FlowFormConstant.FLOWTASKID).toString()
|
||||
: id;
|
||||
fo.setId(flowTaskID);
|
||||
TaskEntity taskEntity = taskService.getById(flowTaskID);
|
||||
if (taskEntity != null) {
|
||||
taskUtil.isSuspend(taskEntity);
|
||||
taskUtil.isCancel(taskEntity);
|
||||
}
|
||||
taskService.batchSaveOrSubmit(fo);
|
||||
if (ObjectUtil.equals(TaskStatusEnum.RUNNING.getCode(), fo.getStatus())) {
|
||||
operatorUtil.event(fo, 1);
|
||||
}
|
||||
taskEntity = fo.getTaskEntity();
|
||||
if (taskEntity.getRejectDataId() == null) {
|
||||
operatorUtil.autoAudit(fo);
|
||||
operatorUtil.handleEvent();
|
||||
}
|
||||
List<OperatorEntity> list = fo.getList();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
TimeUtil.timeModel(list, fo, redisUtil);
|
||||
}
|
||||
TaskEntity task = taskService.getById(taskEntity.getId());
|
||||
taskEntity = task == null ? taskEntity : task;
|
||||
String msg = TaskStatusEnum.TO_BE_SUBMIT.getCode().equals(fo.getStatus()) ? MsgCode.SU002.get()
|
||||
: MsgCode.SU006.get();
|
||||
AuditModel model = taskUtil.getAuditModel(taskEntity.getId(), fo, null);
|
||||
return ActionResult.success(msg, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) throws Exception {
|
||||
List<TaskEntity> list = taskService.delete(id);
|
||||
taskUtil.deleteFormData(list);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 我发起的 列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "我发起的")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<TaskVo>> list(TaskPagination pagination) {
|
||||
List<TaskEntity> list = taskService.getList(pagination);
|
||||
List<TaskVo> voList = new ArrayList<>();
|
||||
List<UserEntity> userList = serviceUtil
|
||||
.getUserName(list.stream().map(TaskEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
for (TaskEntity entity : list) {
|
||||
TaskVo vo = JsonUtil.getJsonToBean(entity, TaskVo.class);
|
||||
UserEntity userEntity = userList.stream().filter(t -> t.getId().equals(entity.getCreatorUserId()))
|
||||
.findFirst().orElse(null);
|
||||
vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
|
||||
vo.setFlowUrgent(entity.getUrgent());
|
||||
if (StringUtil.isNotBlank(entity.getDelegateUserId())) {
|
||||
vo.setDelegateUser(entity.getDelegateUserId());
|
||||
}
|
||||
voList.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起撤回
|
||||
*
|
||||
* @param id 任务主键
|
||||
*/
|
||||
@Operation(summary = "发起撤回")
|
||||
@PutMapping("/Recall/{id}")
|
||||
public ActionResult<String> recall(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.recall(id, flowModel);
|
||||
operatorUtil.event(flowModel, 3);
|
||||
return ActionResult.success(MsgCode.WF008.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 催办
|
||||
*
|
||||
* @param id 任务主键
|
||||
*/
|
||||
@Operation(summary = "催办")
|
||||
@PostMapping("/Press/{id}")
|
||||
public ActionResult<String> press(@PathVariable("id") String id) throws WorkFlowException {
|
||||
if (taskService.press(id)) {
|
||||
return ActionResult.success(MsgCode.WF022.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.WF023.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销
|
||||
*
|
||||
* @param id 任务主键
|
||||
*/
|
||||
@Operation(summary = "撤销")
|
||||
@PutMapping("/Revoke/{id}")
|
||||
public ActionResult<String> revoke(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws Exception {
|
||||
taskService.revoke(id, flowModel);
|
||||
return ActionResult.success(MsgCode.SU006.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程所关联的用户信息
|
||||
*
|
||||
* @param id 任务主键
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "获取流程所关联的用户信息")
|
||||
@GetMapping("/TaskUserList/{id}")
|
||||
public ActionResult getTaskUserList(@PathVariable("id") String id, TaskPagination pagination) {
|
||||
TaskUserListModel model = taskService.getTaskUserList(id);
|
||||
List<String> allUserIdList = model.getAllUserIdList();
|
||||
List<UserIdListVo> userList = serviceUtil.getUserList(allUserIdList, pagination, null);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(userList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子流程详情
|
||||
*
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "子流程详情")
|
||||
@GetMapping("/SubFlowInfo")
|
||||
public ActionResult subFlowInfo(FlowModel flowModel) throws WorkFlowException {
|
||||
List<BeforeInfoVo> list = taskService.subFlowInfo(flowModel);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看发起表单
|
||||
*
|
||||
* @param taskId 任务主键
|
||||
*/
|
||||
@Operation(summary = "查看发起表单")
|
||||
@GetMapping("/ViewStartForm/{taskId}")
|
||||
public ActionResult getStartForm(@PathVariable("taskId") String taskId) throws WorkFlowException {
|
||||
ViewFormModel model = taskService.getStartForm(taskId);
|
||||
return ActionResult.success(model);
|
||||
}
|
||||
|
||||
@GetMapping("/test")
|
||||
public Map test() {
|
||||
return ImmutableMap.of("handleId",
|
||||
"03d159a3-0f88-424c-a24f-02f63855fe4f,9624fa22-ac3a-4184-af0b-b2c720df9d60,3977de33-668c-4585-b09b-239aacfb4ebe");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.*;
|
||||
import com.yunzhupaas.flowable.enums.NodeEnum;
|
||||
import com.yunzhupaas.flowable.enums.OperatorStateEnum;
|
||||
import com.yunzhupaas.flowable.model.operator.OperatorVo;
|
||||
import com.yunzhupaas.flowable.model.task.FileModel;
|
||||
import com.yunzhupaas.flowable.model.task.FlowModel;
|
||||
import com.yunzhupaas.flowable.model.task.TaskPagination;
|
||||
import com.yunzhupaas.flowable.model.templatenode.nodejson.FileConfig;
|
||||
import com.yunzhupaas.flowable.model.templatenode.nodejson.NodeModel;
|
||||
import com.yunzhupaas.flowable.service.*;
|
||||
import com.yunzhupaas.flowable.util.OperatorUtil;
|
||||
import com.yunzhupaas.flowable.util.RecordUtil;
|
||||
import com.yunzhupaas.flowable.util.TaskUtil;
|
||||
import com.yunzhupaas.util.DateUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.workflow.service.TaskApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的描述
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/5/28 14:32
|
||||
*/
|
||||
@Component
|
||||
public class TaskForFileController implements TaskApi {
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
@Autowired
|
||||
private OperatorService operatorService;
|
||||
@Autowired
|
||||
private RecordService recordService;
|
||||
@Autowired
|
||||
private CirculateService circulateService;
|
||||
@Autowired
|
||||
private DelegateService delegateService;
|
||||
@Autowired
|
||||
private TemplateNodeService templateNodeService;
|
||||
@Autowired
|
||||
private RecordUtil recordUtil;
|
||||
@Autowired
|
||||
private OperatorUtil operatorUtil;
|
||||
@Autowired
|
||||
private TaskUtil taskUtil;
|
||||
|
||||
// 获取归档信息
|
||||
@Override
|
||||
public FileModel getFileModel(String taskId) throws WorkFlowException {
|
||||
TaskEntity taskEntity = taskService.getInfo(taskId);
|
||||
if (null == taskEntity) {
|
||||
throw new WorkFlowException(MsgCode.FA001.get());
|
||||
}
|
||||
FileModel model = new FileModel();
|
||||
|
||||
List<TemplateNodeEntity> nodeEntityList = templateNodeService.getList(taskEntity.getFlowId());
|
||||
TemplateNodeEntity globalEntity = nodeEntityList.stream()
|
||||
.filter(e -> StringUtil.equals(NodeEnum.global.getType(), e.getNodeType())).findFirst()
|
||||
.orElse(new TemplateNodeEntity());
|
||||
NodeModel global = JsonUtil.getJsonToBean(globalEntity.getNodeJson(), NodeModel.class);
|
||||
if (null != global) {
|
||||
FileConfig fileConfig = global.getFileConfig();
|
||||
// 归档路径
|
||||
model.setParentId(fileConfig.getParentId());
|
||||
|
||||
String userId = taskEntity.getCreatorUserId();
|
||||
if (fileConfig.getPermissionType().equals(1)) {
|
||||
// 创建人
|
||||
model.setUserId(userId);
|
||||
// 分享人
|
||||
List<String> list = operatorUtil.getListOfFile(taskId);
|
||||
model.setUserList(list.stream().filter(e -> !e.equals(userId)).collect(Collectors.toList()));
|
||||
} else if (fileConfig.getPermissionType().equals(3)) {
|
||||
// 最后节点审批人
|
||||
List<String> list = operatorUtil.getListOfLast(taskId);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
model.setUserId(list.get(0));
|
||||
list.remove(0);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
model.setUserList(list);
|
||||
}
|
||||
} else {
|
||||
model.setUserId(userId);
|
||||
}
|
||||
} else {
|
||||
// 创建人
|
||||
model.setUserId(userId);
|
||||
}
|
||||
}
|
||||
|
||||
// 文件名称
|
||||
String filename = taskEntity.getFullName();
|
||||
String datetime;
|
||||
if (null != taskEntity.getEndTime()) {
|
||||
datetime = DateUtil.dateToString(taskEntity.getEndTime(), "yyyyMMddHHmmss");
|
||||
} else {
|
||||
datetime = DateUtil.dateToString(new Date(), "yyyyMMddHHmmss");
|
||||
}
|
||||
filename += "-" + datetime;
|
||||
model.setFilename(filename + ".pdf");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskEntity getInfoSubmit(String id, SFunction<TaskEntity, ?>... columns) {
|
||||
return taskService.getInfoSubmit(id, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskEntity> getInfosSubmit(String[] ids, SFunction<TaskEntity, ?>... columns) {
|
||||
return taskService.getInfosSubmit(ids, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(TaskEntity taskEntity) throws Exception {
|
||||
taskService.delete(taskEntity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrSubmit(FlowModel flowModel) throws Exception {
|
||||
taskService.batchSaveOrSubmit(flowModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RecordEntity> getRecordList(String taskId) {
|
||||
return recordUtil.getList(taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIsFile(String taskId) {
|
||||
try {
|
||||
taskService.updateIsFile(taskId);
|
||||
} catch (WorkFlowException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperatorVo> getWaitList(TaskPagination pagination) {
|
||||
return operatorService.getList(pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperatorVo> getTrialList(TaskPagination pagination) {
|
||||
return recordService.getList(pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperatorVo> getCirculateList(TaskPagination pagination) {
|
||||
return circulateService.getList(pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DelegateEntity> getDelegateList() {
|
||||
return delegateService.getList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkSign() {
|
||||
QueryWrapper<OperatorEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(OperatorEntity::getCompletion, 0)
|
||||
.ne(OperatorEntity::getStatus, OperatorStateEnum.Futility.getCode())
|
||||
.isNull(OperatorEntity::getSignTime);
|
||||
long count = operatorService.count(queryWrapper);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkTodo() {
|
||||
QueryWrapper<OperatorEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(OperatorEntity::getCompletion, 0)
|
||||
.ne(OperatorEntity::getStatus, OperatorStateEnum.Futility.getCode())
|
||||
.isNotNull(OperatorEntity::getSignTime).isNull(OperatorEntity::getStartHandleTime);
|
||||
long count = operatorService.count(queryWrapper);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult launchFlow(FlowModel flowModel) {
|
||||
try {
|
||||
return taskUtil.launchFlow(flowModel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,617 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.TemplateEntity;
|
||||
import com.yunzhupaas.flowable.entity.TemplateJsonEntity;
|
||||
import com.yunzhupaas.flowable.model.candidates.CandidateUserVo;
|
||||
import com.yunzhupaas.flowable.model.template.*;
|
||||
import com.yunzhupaas.flowable.model.templatejson.FlowListModel;
|
||||
import com.yunzhupaas.flowable.model.templatejson.TemplateJsonInfoVO;
|
||||
import com.yunzhupaas.flowable.model.templatejson.TemplateJsonSelectVO;
|
||||
import com.yunzhupaas.flowable.model.templatenode.TemplateNodeCrFrom;
|
||||
import com.yunzhupaas.flowable.model.templatenode.TemplateNodeUpFrom;
|
||||
import com.yunzhupaas.flowable.service.CommonService;
|
||||
import com.yunzhupaas.flowable.service.OperatorService;
|
||||
import com.yunzhupaas.flowable.service.TemplateJsonService;
|
||||
import com.yunzhupaas.flowable.service.TemplateService;
|
||||
import com.yunzhupaas.flowable.util.ServiceUtil;
|
||||
import com.yunzhupaas.model.FlowWorkListVO;
|
||||
import com.yunzhupaas.permission.entity.OrganizeEntity;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.entity.UserRelationEntity;
|
||||
import com.yunzhupaas.permission.model.user.WorkHandoverModel;
|
||||
import com.yunzhupaas.util.FileUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.UploaderUtil;
|
||||
import com.yunzhupaas.workflow.service.TemplateApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "流程模板", description = "flowTemplate")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/template")
|
||||
public class TemplateController extends SuperController<TemplateService, TemplateEntity> implements TemplateApi {
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
@Autowired
|
||||
private TemplateJsonService templateJsonService;
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
@Autowired
|
||||
private CommonService commonService;
|
||||
@Autowired
|
||||
private OperatorService operatorService;
|
||||
|
||||
/**
|
||||
* 流程列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<TemplatePageLisVO>> list(TemplatePagination pagination) {
|
||||
List<TemplateEntity> list = templateService.getList(pagination);
|
||||
List<DictionaryDataEntity> dictionList = serviceUtil.getDictionName(list.stream().map(TemplateEntity::getCategory).collect(Collectors.toList()));
|
||||
List<UserEntity> userList = serviceUtil.getUserName(list.stream().map(TemplateEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
List<TemplatePageLisVO> listVO = new ArrayList<>();
|
||||
for (TemplateEntity entity : list) {
|
||||
TemplatePageLisVO vo = JsonUtil.getJsonToBean(entity, TemplatePageLisVO.class);
|
||||
DictionaryDataEntity dataEntity = dictionList.stream().filter(t -> t.getId().equals(entity.getCategory())).findFirst().orElse(null);
|
||||
vo.setCategory(dataEntity != null ? dataEntity.getFullName() : "");
|
||||
UserEntity userEntity = userList.stream().filter(t -> t.getId().equals(entity.getCreatorUserId())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
|
||||
listVO.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程列表")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<PageListVO<TemplatePageModel>> selector(TemplatePagination pagination) {
|
||||
List<TemplatePageVo> list = templateService.getSelector(pagination);
|
||||
List<TemplatePageModel> voList = JsonUtil.getJsonToList(list, TemplatePageModel.class);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 常用流程树
|
||||
*/
|
||||
@Operation(summary = "常用流程树")
|
||||
@GetMapping("/CommonFlowTree")
|
||||
public ActionResult getTreeCommon() {
|
||||
ListVO<TemplateTreeListVo> vo = new ListVO<>();
|
||||
vo.setList(templateService.getTreeCommon());
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 树形列表
|
||||
*/
|
||||
@Operation(summary = "树形列表")
|
||||
@GetMapping("/TreeList")
|
||||
public ActionResult<ListVO<TemplateTreeListVo>> treeList(@RequestParam(value = "formType", required = false) Integer formType) {
|
||||
ListVO<TemplateTreeListVo> vo = new ListVO<>();
|
||||
vo.setList(templateService.treeList(formType));
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限树形集合
|
||||
*/
|
||||
@Operation(summary = "权限树形列表")
|
||||
@GetMapping("/Power/TreeList")
|
||||
public ActionResult<List<TemplateTreeListVo>> treeListPower() {
|
||||
return ActionResult.success(templateService.treeListWithPower());
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程基础信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程基础信息")
|
||||
@GetMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<TemplateInfoVO> info(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateEntity entity = templateService.getInfo(id);
|
||||
TemplateInfoVO vo = JsonUtil.getJsonToBean(entity, TemplateInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程版本列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程版本列表")
|
||||
@GetMapping("/Version/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<List<TemplateJsonSelectVO>> version(@PathVariable("id") String id) throws WorkFlowException {
|
||||
List<TemplateJsonEntity> list = templateJsonService.getList(id);
|
||||
List<TemplateJsonSelectVO> listVO = new ArrayList<>();
|
||||
for (TemplateJsonEntity jsonEntity : list) {
|
||||
TemplateJsonSelectVO vo = JsonUtil.getJsonToBean(jsonEntity, TemplateJsonSelectVO.class);
|
||||
vo.setFlowVersion(jsonEntity.getVersion());
|
||||
vo.setFullName("流程版本V" + jsonEntity.getVersion());
|
||||
listVO.add(vo);
|
||||
}
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程模板信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程模板信息")
|
||||
@GetMapping("/Info/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<TemplateJsonInfoVO> templateJsonInfo(@PathVariable("id") String id) throws WorkFlowException {
|
||||
return ActionResult.success(templateJsonService.getInfoVo(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建流程
|
||||
*
|
||||
* @param form 流程模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建流程")
|
||||
@PostMapping
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "流程模型", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult create(@RequestBody @Valid TemplateNodeCrFrom form) throws WorkFlowException {
|
||||
TemplateEntity entity = JsonUtil.getJsonToBean(form, TemplateEntity.class);
|
||||
String flowConfig = form.getFlowConfig();
|
||||
FlowConfigModel config = JsonUtil.getJsonToBean(flowConfig, FlowConfigModel.class);
|
||||
config = config == null ? new FlowConfigModel() : config;
|
||||
entity.setVisibleType(config.getVisibleType());
|
||||
templateService.create(entity, form.getFlowXml(), form.getFlowNodes());
|
||||
return ActionResult.success(MsgCode.SU001.get(), entity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新流程
|
||||
*
|
||||
* @param id 主键
|
||||
* @param form 流程模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新流程")
|
||||
@PutMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "form", description = "流程模型", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid TemplateNodeUpFrom form) throws WorkFlowException {
|
||||
TemplateEntity entity = JsonUtil.getJsonToBean(form, TemplateEntity.class);
|
||||
String flowConfig = form.getFlowConfig();
|
||||
FlowConfigModel config = JsonUtil.getJsonToBean(flowConfig, FlowConfigModel.class);
|
||||
config = config == null ? new FlowConfigModel() : config;
|
||||
entity.setVisibleType(config.getVisibleType());
|
||||
templateService.update(id, entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新流程类型
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "更新流程类型")
|
||||
@PutMapping("/{id}/UpdateType")
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult updateType(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateEntity entity = templateService.getInfo(id);
|
||||
entity.setType(0);
|
||||
templateService.updateById(entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流程引擎
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除流程引擎")
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult delete(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateEntity entity = templateService.getInfo(id);
|
||||
templateService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流程版本
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除流程版本")
|
||||
@DeleteMapping("/Info/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult deleteInfo(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateJsonEntity entity = templateJsonService.getInfo(id);
|
||||
List<TemplateJsonEntity> list = templateJsonService.getList(entity.getTemplateId());
|
||||
if (list.size() == 1) {
|
||||
return ActionResult.fail(MsgCode.WF071.get());
|
||||
}
|
||||
if (Objects.equals(entity.getState(), 1)) {
|
||||
return ActionResult.fail(MsgCode.WF072.get());
|
||||
}
|
||||
if (Objects.equals(entity.getState(), 2)) {
|
||||
return ActionResult.fail(MsgCode.WF073.get());
|
||||
}
|
||||
templateJsonService.delete(ImmutableList.of(id));
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 上架下架
|
||||
*
|
||||
* @param id 主键
|
||||
* @param fo 参数
|
||||
*/
|
||||
@Operation(summary = "上架下架")
|
||||
@PutMapping("/{id}/UpDownShelf")
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult updateStatus(@PathVariable("id") String id, @RequestBody UpDownModel fo) throws WorkFlowException {
|
||||
TemplateEntity entity = templateService.getInfo(id);
|
||||
if (ObjectUtil.equals(fo.getIsUp(), 0)) {
|
||||
entity.setStatus(1);
|
||||
} else {
|
||||
entity.setStatus(ObjectUtil.equals(fo.getIsHidden(), 0) ? 2 : 3);
|
||||
}
|
||||
templateService.updateById(entity);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制流程引擎
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制流程引擎")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult copy(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateEntity entity = templateService.getInfo(id);
|
||||
templateService.copy(entity);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制流程版本
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制流程版本")
|
||||
@PostMapping("/Info/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult copyVersion(@PathVariable("id") String id) throws WorkFlowException {
|
||||
String templateJsonId = RandomUtil.uuId();
|
||||
TemplateJsonEntity entity = templateJsonService.getInfo(id);
|
||||
templateJsonService.copy(entity, templateJsonId);
|
||||
return ActionResult.success(MsgCode.SU007.get(), templateJsonId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程保存或发布
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "流程保存或发布")
|
||||
@PostMapping("/Save")
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult save(@RequestBody @Valid TemplateNodeUpFrom form) throws WorkFlowException {
|
||||
templateJsonService.save(form);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<DownloadVO> export(@PathVariable("id") String id) throws WorkFlowException {
|
||||
TemplateExportModel model = templateService.export(id);
|
||||
DownloadVO downloadVO = serviceUtil.exportData(model);
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @param file 文件
|
||||
* @param type 类型
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@SaCheckPermission(value = {"workFlow.flowEngine"})
|
||||
public ActionResult<String> importData(@RequestPart("file") MultipartFile file, @RequestParam("type") String type) throws WorkFlowException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(file, ModuleTypeEnum.FLOW_FLOWENGINE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//获取文件内容
|
||||
String fileContent = FileUtil.getFileContent(file);
|
||||
TemplateExportModel model = JsonUtil.getJsonToBean(fileContent, TemplateExportModel.class);
|
||||
if (ObjectUtil.isEmpty(model.getTemplate())) {
|
||||
return ActionResult.fail(MsgCode.IMP004.get());
|
||||
}
|
||||
templateService.importData(model, type);
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 委托可选全部流程
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "委托可选全部流程")
|
||||
@GetMapping("/GetFlowAll")
|
||||
public ActionResult getFlowAll(TemplatePagination pagination) {
|
||||
List<TemplateEntity> list = templateService.getListAll(pagination, true);
|
||||
List<TemplatePageLisVO> voList = JsonUtil.getJsonToList(list, TemplatePageLisVO.class);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 委托流程选择展示
|
||||
*
|
||||
* @param ids 版本主键集合
|
||||
*/
|
||||
@Operation(summary = "委托流程选择展示")
|
||||
@PostMapping("/GetFlowList")
|
||||
public ActionResult getFlowList(@RequestBody List<String> ids) {
|
||||
List<TemplateEntity> list = templateService.getList(ids);
|
||||
List<FlowListModel> voList = new ArrayList<>();
|
||||
for (TemplateEntity templateEntity : list) {
|
||||
FlowListModel model = new FlowListModel();
|
||||
model.setId(templateEntity.getId());
|
||||
model.setFullName(templateEntity.getFullName());
|
||||
model.setEnCode(templateEntity.getEnCode());
|
||||
voList.add(model);
|
||||
}
|
||||
return ActionResult.success(voList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子流程表单信息
|
||||
*
|
||||
* @param id 版本主键
|
||||
*/
|
||||
@Operation(summary = "子流程表单信息")
|
||||
@GetMapping("/{id}/FormInfo")
|
||||
public ActionResult formInfo(@PathVariable("id") String id) throws WorkFlowException {
|
||||
VisualdevEntity formInfo = templateJsonService.getFormInfo(id);
|
||||
return ActionResult.success(formInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表单主键获取流程
|
||||
*
|
||||
* @param formId 表单主键
|
||||
*/
|
||||
@Operation(summary = "根据表单主键获取流程")
|
||||
@GetMapping("/{formId}/FlowList")
|
||||
public ActionResult getByFormId(@PathVariable("formId") String formId, Boolean start) {
|
||||
FlowByFormModel model = templateService.getFlowByFormId(formId, start);
|
||||
return ActionResult.success(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子流程可发起人员
|
||||
*
|
||||
* @param id 版本主键
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "子流程可发起人员")
|
||||
@GetMapping("/{id}/SubFlowUserList")
|
||||
public ActionResult getSubFlowUserList(@PathVariable("id") String id, TemplatePagination pagination) throws WorkFlowException {
|
||||
List<UserEntity> list = templateService.getSubFlowUserList(id, pagination);
|
||||
List<CandidateUserVo> voList = new ArrayList<>();
|
||||
List<String> userIdList = list.stream().map(UserEntity::getId).collect(Collectors.toList());
|
||||
Map<String, List<UserRelationEntity>> userMap = serviceUtil.getListByUserIdAll(userIdList).stream()
|
||||
.filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.groupingBy(UserRelationEntity::getUserId));
|
||||
for (UserEntity user : list) {
|
||||
CandidateUserVo vo = JsonUtil.getJsonToBean(user, CandidateUserVo.class);
|
||||
vo.setFullName(user.getRealName() + "/" + user.getAccount());
|
||||
vo.setHeadIcon(UploaderUtil.uploaderImg(user.getHeadIcon()));
|
||||
List<UserRelationEntity> listByUserId = userMap.get(user.getId()) != null ? userMap.get(user.getId()) : new ArrayList<>();
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (UserRelationEntity relation : listByUserId) {
|
||||
List<OrganizeEntity> organizeId = serviceUtil.getOrganizeId(relation.getObjectId());
|
||||
if (!organizeId.isEmpty()) {
|
||||
String organizeName = organizeId.stream().map(OrganizeEntity::getFullName).collect(Collectors.joining("/"));
|
||||
joiner.add(organizeName);
|
||||
}
|
||||
}
|
||||
vo.setOrganize(joiner.toString());
|
||||
voList.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 常用流程
|
||||
*
|
||||
* @param id 版本主键
|
||||
*/
|
||||
@Operation(summary = "常用流程")
|
||||
@PostMapping("/SetCommonFlow/{id}")
|
||||
public ActionResult SetCommonFlow(@PathVariable("id") String id) {
|
||||
int flag = commonService.setCommonFLow(id);
|
||||
if (flag == 2) {
|
||||
return ActionResult.success(MsgCode.SU021.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU016.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板主键获取表单
|
||||
*
|
||||
* @param templateId 流程模板主键
|
||||
*/
|
||||
@Operation(summary = "根据模板主键获取表单")
|
||||
@GetMapping("/StartForm/{templateId}")
|
||||
public ActionResult getFormByTemplateId(@PathVariable("templateId") String templateId) throws WorkFlowException {
|
||||
return ActionResult.success(templateService.getFormByTemplateId(templateId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板主键获取表单主键和流程版本主键
|
||||
*
|
||||
* @param templateId 流程模板主键
|
||||
*/
|
||||
@Operation(summary = "根据模板主键获取表单主键和流程版本主键")
|
||||
@GetMapping("/StartFormId/{templateId}")
|
||||
public ActionResult getFormIdAndFlowIdByTemplateId(@PathVariable("templateId") String templateId) throws WorkFlowException {
|
||||
return ActionResult.success(templateService.getFormIdAndFlowId(templateId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowByFormModel getFlowByFormId(String formId, Boolean start) {
|
||||
return templateService.getFlowByFormId(formId, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormByFlowId(String templateId) {
|
||||
String formId = "";
|
||||
try {
|
||||
VisualdevEntity entity = templateService.getFormByTemplateId(templateId);
|
||||
if (null == entity) {
|
||||
throw new WorkFlowException(MsgCode.VS412.get());
|
||||
}
|
||||
formId = entity.getId();
|
||||
} catch (Exception e) {
|
||||
log.error("流程获取表单失败: {}", e.getMessage());
|
||||
}
|
||||
return formId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFlowIdsByTemplateId(String templateId) {
|
||||
List<TemplateJsonEntity> list = templateJsonService.getList(templateId);
|
||||
return list.stream().map(TemplateJsonEntity::getId).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateJsonEntity> getFlowIdsByTemplate(String templateId) {
|
||||
return templateJsonService.getList(templateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateEntity> getListByFlowIds(List<String> flowId) {
|
||||
return templateService.getList(flowId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateTreeListVo> treeListWithPower() {
|
||||
return templateService.treeListWithPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowWorkListVO flowWork(String fromId) {
|
||||
return operatorService.flowWork(fromId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean flowWork(WorkHandoverModel workHandoverModel) {
|
||||
return operatorService.flowWork(workHandoverModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFormList() {
|
||||
return templateService.getFormList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateByVersionId(String flowId) {
|
||||
String templateId = "";
|
||||
TemplateJsonEntity byId = templateJsonService.getById(flowId);
|
||||
if (byId != null) {
|
||||
templateId = byId.getTemplateId();
|
||||
}
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getFlowFormMap() {
|
||||
return templateService.getFlowFormMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.flowable.entity.TemplateJsonEntity;
|
||||
import com.yunzhupaas.flowable.entity.TemplateNodeEntity;
|
||||
import com.yunzhupaas.flowable.enums.NodeEnum;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerDataFo;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerDataModel;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerModel;
|
||||
import com.yunzhupaas.flowable.service.TemplateJsonService;
|
||||
import com.yunzhupaas.flowable.service.TemplateNodeService;
|
||||
import com.yunzhupaas.flowable.util.TriggerUtil;
|
||||
import com.yunzhupaas.workflow.service.TriggerApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的描述
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/9/11 10:39
|
||||
*/
|
||||
@Tag(name = "流程触发", description = "trigger")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/trigger")
|
||||
@Slf4j
|
||||
public class TriggerController implements TriggerApi {
|
||||
@Autowired
|
||||
private TriggerUtil triggerUtil;
|
||||
@Autowired
|
||||
private TemplateNodeService templateNodeService;
|
||||
@Autowired
|
||||
private TemplateJsonService templateJsonService;
|
||||
|
||||
/**
|
||||
* 任务流程触发
|
||||
*
|
||||
* @param model 参数
|
||||
*/
|
||||
@PostMapping("/Execute")
|
||||
public ActionResult execute(@RequestBody TriggerModel model) throws Exception {
|
||||
for (TriggerDataModel dataModel : model.getDataList()) {
|
||||
try {
|
||||
triggerUtil.handleTrigger(dataModel, model.getUserInfo());
|
||||
} catch (Exception e) {
|
||||
log.error("触发异常", e);
|
||||
// triggerUtil.createErrorRecord();
|
||||
}
|
||||
}
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时触发
|
||||
*
|
||||
* @param triggerModel 参数
|
||||
*/
|
||||
@PostMapping("/TimeExecute")
|
||||
public ActionResult timeExecute(@RequestBody TriggerModel triggerModel) {
|
||||
try {
|
||||
triggerUtil.handleTimeTrigger(triggerModel);
|
||||
} catch (Exception e) {
|
||||
log.error("定时触发异常", e);
|
||||
// triggerUtil.createErrorRecord();
|
||||
}
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知触发
|
||||
*
|
||||
* @param triggerModel 参数
|
||||
*/
|
||||
@PostMapping("/MsgExecute")
|
||||
public ActionResult msgExecute(@RequestBody TriggerModel triggerModel) {
|
||||
String msgId = triggerModel.getId();
|
||||
UserInfo userInfo = triggerModel.getUserInfo();
|
||||
|
||||
QueryWrapper<TemplateNodeEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(TemplateNodeEntity::getNodeType, NodeEnum.noticeTrigger.getType())
|
||||
.eq(TemplateNodeEntity::getFormId, msgId);
|
||||
List<TemplateNodeEntity> triggerNodeList = templateNodeService.list(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(triggerNodeList)) {
|
||||
List<String> flowIds = triggerNodeList.stream().map(TemplateNodeEntity::getFlowId).distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
QueryWrapper<TemplateJsonEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(TemplateJsonEntity::getState, 1).in(TemplateJsonEntity::getId, flowIds);
|
||||
List<TemplateJsonEntity> jsonEntityList = templateJsonService.list(wrapper);
|
||||
|
||||
for (TemplateNodeEntity triggerNode : triggerNodeList) {
|
||||
String flowId = triggerNode.getFlowId();
|
||||
TemplateJsonEntity jsonEntity = jsonEntityList.stream()
|
||||
.filter(e -> ObjectUtil.equals(e.getId(), flowId)).findFirst().orElse(null);
|
||||
if (null == jsonEntity) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
triggerUtil.msgTrigger(triggerNode, userInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("通知触发异常", e);
|
||||
// triggerUtil.createErrorRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TriggerDataModel> getTriggerDataModel(TriggerDataFo fo) {
|
||||
return triggerUtil.getTriggerDataModel(fo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.flowable.entity.TemplateEntity;
|
||||
import com.yunzhupaas.flowable.entity.TemplateJsonEntity;
|
||||
import com.yunzhupaas.flowable.entity.TriggerTaskEntity;
|
||||
import com.yunzhupaas.flowable.model.monitor.MonitorModel;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerInfoListModel;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerPagination;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerTaskModel;
|
||||
import com.yunzhupaas.flowable.service.TemplateJsonService;
|
||||
import com.yunzhupaas.flowable.service.TemplateService;
|
||||
import com.yunzhupaas.flowable.service.TriggerTaskService;
|
||||
import com.yunzhupaas.flowable.util.TriggerUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 任务流程
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/9/21 9:57
|
||||
*/
|
||||
@Tag(name = "任务流程实例", description = "triggerTask")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/trigger/task")
|
||||
@Slf4j
|
||||
public class TriggerTaskController {
|
||||
@Autowired
|
||||
private TriggerTaskService triggerTaskService;
|
||||
@Autowired
|
||||
private TriggerUtil triggerUtil;
|
||||
@Autowired
|
||||
private TemplateJsonService templateJsonService;
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
/**
|
||||
* 获取任务下的触发记录
|
||||
*
|
||||
* @param taskId 任务主键
|
||||
*/
|
||||
@Operation(summary = "获取任务下的触发记录")
|
||||
@GetMapping("/List")
|
||||
public ActionResult list(@RequestParam("taskId") String taskId, @RequestParam("nodeCode") String nodeCode) {
|
||||
List<TriggerInfoListModel> list = triggerTaskService.getListByTaskId(taskId, nodeCode);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务流程列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "任务流程列表")
|
||||
@GetMapping
|
||||
public ActionResult list(TriggerPagination pagination) {
|
||||
List<TriggerTaskEntity> list = triggerTaskService.getList(pagination);
|
||||
|
||||
List<String> flowIds = list.stream().map(TriggerTaskEntity::getFlowId).collect(Collectors.toList());
|
||||
List<TemplateJsonEntity> versionList = new ArrayList<>();
|
||||
List<TemplateEntity> templateList = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(flowIds)) {
|
||||
versionList = templateJsonService.listByIds(flowIds);
|
||||
List<String> templateIds = versionList.stream().map(TemplateJsonEntity::getTemplateId)
|
||||
.collect(Collectors.toList());
|
||||
templateList = templateService.listByIds(templateIds);
|
||||
}
|
||||
List<TriggerTaskModel> voList = JsonUtil.getJsonToList(list, TriggerTaskModel.class);
|
||||
for (TriggerTaskModel model : voList) {
|
||||
model.setIsRetry(ObjectUtil.equals(model.getParentId(), "0") ? 0 : 1);
|
||||
TemplateJsonEntity version = versionList.stream()
|
||||
.filter(e -> ObjectUtil.equals(model.getFlowId(), e.getId())).findFirst().orElse(null);
|
||||
if (null != version) {
|
||||
TemplateEntity template = templateList.stream()
|
||||
.filter(e -> ObjectUtil.equals(version.getTemplateId(), e.getId())).findFirst().orElse(null);
|
||||
if (null != template) {
|
||||
model.setTemplateStatus(template.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "重试")
|
||||
@PostMapping("/Retry/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult retry(@PathVariable("id") String id) throws Exception {
|
||||
try {
|
||||
triggerTaskService.retry(id);
|
||||
} catch (Exception e) {
|
||||
// triggerUtil.createErrorRecord();
|
||||
throw e;
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param model 参数
|
||||
*/
|
||||
@Operation(summary = "批量删除")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult delete(@RequestBody MonitorModel model) {
|
||||
triggerTaskService.batchDelete(model.getIds());
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.TemplateJsonEntity;
|
||||
import com.yunzhupaas.flowable.model.trigger.TriggerWebHookInfoVo;
|
||||
import com.yunzhupaas.flowable.service.TemplateJsonService;
|
||||
import com.yunzhupaas.flowable.util.TriggerUtil;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 类的描述
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/9/21 15:39
|
||||
*/
|
||||
@Tag(name = "webhook触发", description = "WebHook")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/Hooks")
|
||||
public class TriggerWebHookController {
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
@Autowired
|
||||
private TriggerUtil triggerUtil;
|
||||
@Autowired
|
||||
private TemplateJsonService templateJsonService;
|
||||
|
||||
private static final String WEBHOOK_RED_KEY = "webhook_trigger";
|
||||
private static final long DEFAULT_CACHE_TIME = 60 * 5;
|
||||
|
||||
@Operation(summary = "数据接收接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "tenantId", description = "租户id", required = false)
|
||||
})
|
||||
@PostMapping("/{id}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult webhookTrigger(@PathVariable("id") String id,
|
||||
@RequestParam(value = "tenantId", required = false) String tenantId,
|
||||
@RequestBody Map<String, Object> body) throws Exception {
|
||||
String idReal = new String(Base64.decodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
// 判断是不是从外面直接请求
|
||||
if (StringUtil.isNotEmpty(tenantId)) {
|
||||
// 切换成租户库
|
||||
try {
|
||||
TenantDataSourceUtil.switchTenant(tenantId);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.LOG105.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
triggerUtil.handleWebhookTrigger(idReal, tenantId, body);
|
||||
} catch (Exception e) {
|
||||
// triggerUtil.createErrorRecord();
|
||||
throw e;
|
||||
}
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取webhookUrl")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/getUrl")
|
||||
public ActionResult getWebhookUrl(@RequestParam("id") String id) {
|
||||
String enCodeBase64 = new String(Base64.encodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
String randomStr = UUID.randomUUID().toString().substring(0, 5);
|
||||
TriggerWebHookInfoVo vo = new TriggerWebHookInfoVo();
|
||||
vo.setEnCodeStr(enCodeBase64);
|
||||
vo.setRandomStr(randomStr);
|
||||
vo.setWebhookUrl("/api/workflow/Hooks/" + enCodeBase64);
|
||||
vo.setRequestUrl("/api/workflow/Hooks/" + enCodeBase64 + "/params/" + randomStr);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "通过get接口获取参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/params/{randomStr}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult getWebhookParams(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr) throws WorkFlowException {
|
||||
insertRedis(id, randomStr, new HashMap<>());
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "通过post接口获取参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@PostMapping("/{id}/params/{randomStr}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult postWebhookParams(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr,
|
||||
@RequestBody Map<String, Object> obj) throws WorkFlowException {
|
||||
insertRedis(id, randomStr, new HashMap<>(obj));
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 助手id查询信息,写入缓存
|
||||
*
|
||||
* @param id
|
||||
* @param randomStr
|
||||
* @param resultMap
|
||||
* @throws WorkFlowException
|
||||
*/
|
||||
private void insertRedis(String id, String randomStr, Map<String, Object> resultMap) throws WorkFlowException {
|
||||
String idReal = new String(Base64.decodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
String key1 = WEBHOOK_RED_KEY + "_" + idReal + "_" + randomStr;
|
||||
if (!redisUtil.exists(key1)) {
|
||||
throw new WorkFlowException(MsgCode.VS016.get());
|
||||
}
|
||||
String tenantId = redisUtil.getString(key1).toString();
|
||||
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
// 判断是不是从外面直接请求
|
||||
if (StringUtil.isNotEmpty(tenantId)) {
|
||||
// 切换成租户库
|
||||
try {
|
||||
TenantDataSourceUtil.switchTenant(tenantId);
|
||||
} catch (Exception e) {
|
||||
throw new WorkFlowException(MsgCode.LOG105.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
TemplateJsonEntity jsonEntity = templateJsonService.getById(idReal == null ? "" : idReal);
|
||||
if (!ObjectUtil.equals(jsonEntity.getState(), 1)) {
|
||||
throw new WorkFlowException("版本未启用");
|
||||
}
|
||||
Map<String, Object> parameterMap = new HashMap<>(ServletUtil.getRequest().getParameterMap());
|
||||
for (String key : parameterMap.keySet()) {
|
||||
String[] parameterValues = ServletUtil.getRequest().getParameterValues(key);
|
||||
if (parameterValues.length == 1) {
|
||||
parameterMap.put(key, parameterValues[0]);
|
||||
} else {
|
||||
parameterMap.put(key, parameterValues);
|
||||
}
|
||||
}
|
||||
resultMap.putAll(parameterMap);
|
||||
if (resultMap.keySet().size() > 0) {
|
||||
redisUtil.insert(WEBHOOK_RED_KEY + "_" + randomStr, resultMap, DEFAULT_CACHE_TIME);
|
||||
redisUtil.remove(key1);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "请求参数添加触发接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/start/{randomStr}")
|
||||
public ActionResult start(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr) {
|
||||
redisUtil.remove(WEBHOOK_RED_KEY + "_" + randomStr);
|
||||
redisUtil.insert(WEBHOOK_RED_KEY + "_" + id + "_" + randomStr, UserProvider.getUser().getTenantId(),
|
||||
DEFAULT_CACHE_TIME);
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取缓存的接口参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/getParams/{randomStr}")
|
||||
public ActionResult getRedisParams(@PathVariable("randomStr") String randomStr) {
|
||||
Map<String, Object> mapRedis = new HashMap<>();
|
||||
String key = WEBHOOK_RED_KEY + "_" + randomStr;
|
||||
if (redisUtil.exists(key)) {
|
||||
mapRedis = redisUtil.getMap(key);
|
||||
}
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (String redisKey : mapRedis.keySet()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", redisKey);
|
||||
map.put("fullName", mapRedis.get(redisKey));
|
||||
list.add(map);
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.yunzhupaas.flowable.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.flowable.model.monitor.MonitorModel;
|
||||
import com.yunzhupaas.flowable.model.monitor.MonitorVo;
|
||||
import com.yunzhupaas.flowable.model.task.FlowModel;
|
||||
import com.yunzhupaas.flowable.model.task.TaskPagination;
|
||||
import com.yunzhupaas.flowable.service.TaskService;
|
||||
import com.yunzhupaas.flowable.util.ServiceUtil;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 流程监控
|
||||
*
|
||||
* @author YUNZHUPAASYUNZHUPAAS开发组
|
||||
* @version 5.0.x
|
||||
* @since 2024/5/15 10:15
|
||||
*/
|
||||
@Tag(name = "流程监控", description = "Monitor")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow/monitor")
|
||||
@RequiredArgsConstructor
|
||||
public class WorkflowMonitorController {
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
@Autowired
|
||||
private ServiceUtil serviceUtil;
|
||||
|
||||
/**
|
||||
* 监控列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
*/
|
||||
@Operation(summary = "流程监控列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<MonitorVo>> list(TaskPagination pagination) {
|
||||
List<TaskEntity> list = taskService.getMonitorList(pagination);
|
||||
List<UserEntity> userList = serviceUtil
|
||||
.getUserName(list.stream().map(TaskEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
List<MonitorVo> voList = new LinkedList<>();
|
||||
for (TaskEntity taskEntity : list) {
|
||||
MonitorVo vo = JsonUtil.getJsonToBean(taskEntity, MonitorVo.class);
|
||||
UserEntity user = userList.stream().filter(t -> t.getId().equals(taskEntity.getCreatorUserId())).findFirst()
|
||||
.orElse(null);
|
||||
vo.setCreatorUser(user != null ? user.getRealName() + "/" + user.getAccount() : "");
|
||||
vo.setFlowUrgent(taskEntity.getUrgent());
|
||||
if (ObjectUtil.equals(taskEntity.getIsFile(), 0)) {
|
||||
vo.setIsFile("否");
|
||||
} else if (ObjectUtil.equals(taskEntity.getIsFile(), 1)) {
|
||||
vo.setIsFile("是");
|
||||
} else {
|
||||
vo.setIsFile("");
|
||||
}
|
||||
voList.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除流程监控
|
||||
*
|
||||
* @param model 参数
|
||||
*/
|
||||
@Operation(summary = "批量删除流程监控")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult delete(@RequestBody MonitorModel model) throws Exception {
|
||||
taskService.deleteBatch(model.getIds());
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在异步子流程
|
||||
*
|
||||
* @param id 任务主键
|
||||
*/
|
||||
@Operation(summary = "判断是否存在异步子流程")
|
||||
@GetMapping("/AnySubFlow/{id}")
|
||||
public ActionResult pause(@PathVariable("id") String id) {
|
||||
return ActionResult.success(taskService.checkAsync(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停
|
||||
*
|
||||
* @param id 主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "暂停")
|
||||
@PostMapping("/Pause/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult<String> pause(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.pause(id, flowModel, true);
|
||||
return ActionResult.success(MsgCode.WF074.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
*
|
||||
* @param id 主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "恢复")
|
||||
@PostMapping("/Reboot/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult<String> reboot(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.pause(id, flowModel, false);
|
||||
return ActionResult.success(MsgCode.WF016.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 终止
|
||||
*
|
||||
* @param id 任务主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "终止")
|
||||
@PostMapping("/Cancel/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult<String> cancel(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.cancel(id, flowModel, true);
|
||||
return ActionResult.success(MsgCode.SU009.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复活
|
||||
*
|
||||
* @param id 任务主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "复活")
|
||||
@PostMapping("/Activate/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult<String> activate(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.cancel(id, flowModel, false);
|
||||
return ActionResult.success(MsgCode.WF013.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 指派
|
||||
*
|
||||
* @param id 主键
|
||||
* @param flowModel 参数
|
||||
*/
|
||||
@Operation(summary = "指派")
|
||||
@PostMapping("/Assign/{id}")
|
||||
@SaCheckPermission(value = { "workFlow.flowMonitor" })
|
||||
public ActionResult<String> assign(@PathVariable("id") String id, @RequestBody FlowModel flowModel)
|
||||
throws WorkFlowException {
|
||||
taskService.assign(id, flowModel);
|
||||
return ActionResult.success(MsgCode.WF010.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user