From 312720fadaf525f55d860401848705117ab8d40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Fri, 7 Mar 2025 23:02:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(flow-task):=20=E6=96=B0=E5=A2=9E=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8F=B7=E7=BB=84=E4=BB=B6=20=EF=BC=88=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E4=BA=8E=E5=90=8E=E7=AB=AF=E8=B5=8B=E5=80=BC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/flow/task/vo/FormItemVO.java | 3 + .../task/service/impl/ProcessServiceImpl.java | 323 ++++++++++-------- 2 files changed, 179 insertions(+), 147 deletions(-) diff --git a/pigx-flow/pigx-flow-task/pigx-flow-task-api/src/main/java/com/pig4cloud/pigx/flow/task/vo/FormItemVO.java b/pigx-flow/pigx-flow-task/pigx-flow-task-api/src/main/java/com/pig4cloud/pigx/flow/task/vo/FormItemVO.java index 49191072d..b9afca52f 100644 --- a/pigx-flow/pigx-flow-task/pigx-flow-task-api/src/main/java/com/pig4cloud/pigx/flow/task/vo/FormItemVO.java +++ b/pigx-flow/pigx-flow-task/pigx-flow-task-api/src/main/java/com/pig4cloud/pigx/flow/task/vo/FormItemVO.java @@ -2,12 +2,14 @@ package com.pig4cloud.pigx.flow.task.vo; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.FieldNameConstants; /** * 表单 */ @Data @NoArgsConstructor +@FieldNameConstants public class FormItemVO { private String id; @@ -30,6 +32,7 @@ public class FormItemVO { @Data @NoArgsConstructor + @FieldNameConstants public static class Props { private Object value; diff --git a/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/service/impl/ProcessServiceImpl.java b/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/service/impl/ProcessServiceImpl.java index 9138c6367..03740f222 100644 --- a/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/service/impl/ProcessServiceImpl.java +++ b/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/service/impl/ProcessServiceImpl.java @@ -4,6 +4,9 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -11,6 +14,7 @@ import com.pig4cloud.pigx.common.core.util.R; import com.pig4cloud.pigx.common.security.util.SecurityUtils; import com.pig4cloud.pigx.common.sequence.sequence.Sequence; import com.pig4cloud.pigx.flow.task.api.feign.RemoteFlowEngineService; +import com.pig4cloud.pigx.flow.task.constant.FormTypeEnum; import com.pig4cloud.pigx.flow.task.dto.Node; import com.pig4cloud.pigx.flow.task.dto.NodeUser; import com.pig4cloud.pigx.flow.task.entity.Process; @@ -19,6 +23,7 @@ import com.pig4cloud.pigx.flow.task.mapper.ProcessMapper; import com.pig4cloud.pigx.flow.task.service.IProcessService; import com.pig4cloud.pigx.flow.task.service.IProcessStarterService; import com.pig4cloud.pigx.flow.task.utils.NodeUtil; +import com.pig4cloud.pigx.flow.task.vo.FormItemVO; import com.pig4cloud.pigx.flow.task.vo.ProcessVO; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -27,6 +32,7 @@ import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** *

@@ -40,178 +46,201 @@ import java.util.Map; @RequiredArgsConstructor public class ProcessServiceImpl extends ServiceImpl implements IProcessService { - private final IProcessStarterService processStarterService; + private final IProcessStarterService processStarterService; - private final RemoteFlowEngineService flowEngineService; + private final RemoteFlowEngineService flowEngineService; - private final Sequence flowSequence; + private final ObjectMapper objectMapper; - private final ObjectMapper objectMapper; + private final Sequence flowSequence; - /** - * 获取详细数据 - * @param flowId - * @return - */ - @Override - public R getDetail(String flowId) { - // 获取流程详情 - ProcessVO processVO = this.getProcessVO(flowId); - return R.ok(processVO); - } - /** - * 根据流程ID获取流程详情 - * @param flowId 流程ID - * @return 流程详情 - */ - @SneakyThrows - private ProcessVO getProcessVO(String flowId) { + /** + * 获取详细数据 + * + * @param flowId + * @return + */ + @Override + public R getDetail(String flowId) { + // 获取流程详情 + ProcessVO processVO = this.getProcessVO(flowId); + return R.ok(processVO); + } - Process oaForms = getByFlowId(flowId); - String process = oaForms.getProcess(); - String formItems = oaForms.getFormItems(); - Node startNode = objectMapper.readValue(process, new TypeReference<>() { - }); + /** + * 根据流程ID获取流程详情 + * + * @param flowId 流程ID + * @return 流程详情 + */ + @SneakyThrows + private ProcessVO getProcessVO(String flowId) { - List selectUserNodeId = NodeUtil.selectUserNodeId(startNode); + Process oaForms = getByFlowId(flowId); + String process = oaForms.getProcess(); + String formItems = oaForms.getFormItems(); + Node startNode = objectMapper.readValue(process, new TypeReference<>() { + }); - ProcessVO processVO = BeanUtil.copyProperties(oaForms, ProcessVO.class); - processVO.setSelectUserNodeId(selectUserNodeId); - processVO.setFormItems(formItems); - processVO.setFormPerms(startNode.getFormPerms()); - return processVO; - } + List selectUserNodeId = NodeUtil.selectUserNodeId(startNode); - /** - * 根据流程ID获取流程 - * @param flowId 流程ID - * @return 流程 - */ - @Override - public Process getByFlowId(String flowId) { - return this.lambdaQuery().eq(Process::getFlowId, flowId).one(); - } + ProcessVO processVO = BeanUtil.copyProperties(oaForms, ProcessVO.class); + processVO.setSelectUserNodeId(selectUserNodeId); - /** - * 更新流程 - * @param process 流程 - */ - @Override - public void updateByFlowId(Process process) { - this.lambdaUpdate().eq(Process::getFlowId, process.getFlowId()).update(process); - } + JSONArray formItemJsonArray = JSONUtil.parseArray(formItems); + // 特殊字段复制 + for (Object object : formItemJsonArray) { + if (object instanceof JSONObject) { + JSONObject formVO = (JSONObject) object; + JSONObject props = formVO.getJSONObject(FormItemVO.Fields.props); + if (Objects.nonNull(props) && FormTypeEnum.SEQUENCE.getType().equals(props.getStr(FormItemVO.Fields.type))) { + String nextNo = flowSequence.nextNo(); + props.set(FormItemVO.Props.Fields.value, nextNo); + formVO.set(FormItemVO.Props.Fields.value, nextNo); + } + } + } - /** - * 隐藏流程 - * @param flowId 流程ID - */ - @Override - public void hide(String flowId) { - this.lambdaUpdate().set(Process::getHidden, true).eq(Process::getFlowId, flowId).update(new Process()); - } + processVO.setFormItems(formItemJsonArray.toStringPretty()); + processVO.setFormPerms(startNode.getFormPerms()); + return processVO; + } - /** - * 创建流程 - * @param process 流程 - * @return 操作结果 - */ - @SneakyThrows - @Override - public R create(Process process) { - Map map = new HashMap<>(); - map.put("process", process); - map.put("userId", SecurityUtils.getUser().getId()); - R r = flowEngineService.createFlow(map); - if (!r.isOk()) { - return R.failed(r.getMsg()); - } - String flowId = r.getData(); - NodeUser nodeUser = objectMapper.readValue(process.getAdminList(), new TypeReference>() { - }).get(0); + /** + * 根据流程ID获取流程 + * + * @param flowId 流程ID + * @return 流程 + */ + @Override + public Process getByFlowId(String flowId) { + return this.lambdaQuery().eq(Process::getFlowId, flowId).one(); + } - // 更新流程 - if (StrUtil.isNotBlank(process.getFlowId())) { + /** + * 更新流程 + * + * @param process 流程 + */ + @Override + public void updateByFlowId(Process process) { + this.lambdaUpdate().eq(Process::getFlowId, process.getFlowId()).update(process); + } - Process oldProcess = this.getByFlowId(process.getFlowId()); - this.hide(process.getFlowId()); - // 修改所有的管理员 - this.lambdaUpdate() - .set(Process::getAdminId, nodeUser.getId()) - .eq(Process::getUniqueId, oldProcess.getUniqueId()) - .update(new Process()); + /** + * 隐藏流程 + * + * @param flowId 流程ID + */ + @Override + public void hide(String flowId) { + this.lambdaUpdate().set(Process::getHidden, true).eq(Process::getFlowId, flowId).update(new Process()); + } - } + /** + * 创建流程 + * + * @param process 流程 + * @return 操作结果 + */ + @SneakyThrows + @Override + public R create(Process process) { + Map map = new HashMap<>(); + map.put("process", process); + map.put("userId", SecurityUtils.getUser().getId()); + R r = flowEngineService.createFlow(map); + if (!r.isOk()) { + return R.failed(r.getMsg()); + } + String flowId = r.getData(); + NodeUser nodeUser = objectMapper.readValue(process.getAdminList(), new TypeReference>() { + }).get(0); - Node startNode = objectMapper.readValue(process.getProcess(), Node.class); + // 更新流程 + if (StrUtil.isNotBlank(process.getFlowId())) { - List nodeUserList = startNode.getNodeUserList(); + Process oldProcess = this.getByFlowId(process.getFlowId()); + this.hide(process.getFlowId()); + // 修改所有的管理员 + this.lambdaUpdate() + .set(Process::getAdminId, nodeUser.getId()) + .eq(Process::getUniqueId, oldProcess.getUniqueId()) + .update(new Process()); - StringBuilder stringBuilder = new StringBuilder(); - if (CollUtil.isNotEmpty(nodeUserList)) { - int index = 0; + } - for (NodeUser user : nodeUserList) { - if (index > 0) { - stringBuilder.append(","); - } - stringBuilder.append(user.getName()); - index++; - if (index > 5) { - break; - } + Node startNode = objectMapper.readValue(process.getProcess(), Node.class); - } - } + List nodeUserList = startNode.getNodeUserList(); - Process p = new Process(); - p.setFlowId(flowId); - p.setName(process.getName()); - p.setLogo(process.getLogo()); - p.setSettings(process.getSettings()); - p.setGroupId(process.getGroupId()); - p.setFormItems(process.getFormItems()); - p.setProcess(process.getProcess()); - p.setRemark(process.getRemark()); - p.setSort(0); - p.setHidden("0"); - p.setStop("0"); - p.setAdminId(nodeUser.getId()); - p.setUniqueId(IdUtil.fastSimpleUUID()); - p.setAdminList(process.getAdminList()); - p.setRangeShow(stringBuilder.toString()); + StringBuilder stringBuilder = new StringBuilder(); + if (CollUtil.isNotEmpty(nodeUserList)) { + int index = 0; - this.save(p); + for (NodeUser user : nodeUserList) { + if (index > 0) { + stringBuilder.append(","); + } + stringBuilder.append(user.getName()); + index++; + if (index > 5) { + break; + } - // 保存范围 - for (NodeUser nodeUserDto : nodeUserList) { - ProcessStarter processStarter = new ProcessStarter(); + } + } - processStarter.setProcessId(p.getId()); - processStarter.setTypeId(nodeUserDto.getId()); - processStarter.setType(nodeUserDto.getType()); - processStarterService.save(processStarter); - } + Process p = new Process(); + p.setFlowId(flowId); + p.setName(process.getName()); + p.setLogo(process.getLogo()); + p.setSettings(process.getSettings()); + p.setGroupId(process.getGroupId()); + p.setFormItems(process.getFormItems()); + p.setProcess(process.getProcess()); + p.setRemark(process.getRemark()); + p.setSort(0); + p.setHidden("0"); + p.setStop("0"); + p.setAdminId(nodeUser.getId()); + p.setUniqueId(IdUtil.fastSimpleUUID()); + p.setAdminList(process.getAdminList()); + p.setRangeShow(stringBuilder.toString()); - return R.ok(); - } + this.save(p); - /** - * 编辑表单 - * @param flowId 流程ID - * @param type 类型 stop using delete - * @param groupId 分组ID - * @return 操作结果 - */ - @Override - public R update(String flowId, String type, Long groupId) { - Process process = new Process(); - process.setFlowId(flowId); - process.setStop("stop".equals(type) ? "1" : "0"); - process.setHidden("delete".equals(type) ? "1" : "0"); - process.setGroupId(groupId); - this.updateByFlowId(process); - return R.ok(); - } + // 保存范围 + for (NodeUser nodeUserDto : nodeUserList) { + ProcessStarter processStarter = new ProcessStarter(); + + processStarter.setProcessId(p.getId()); + processStarter.setTypeId(nodeUserDto.getId()); + processStarter.setType(nodeUserDto.getType()); + processStarterService.save(processStarter); + } + + return R.ok(); + } + + /** + * 编辑表单 + * + * @param flowId 流程ID + * @param type 类型 stop using delete + * @param groupId 分组ID + * @return 操作结果 + */ + @Override + public R update(String flowId, String type, Long groupId) { + Process process = new Process(); + process.setFlowId(flowId); + process.setStop("stop".equals(type) ? "1" : "0"); + process.setHidden("delete".equals(type) ? "1" : "0"); + process.setGroupId(groupId); + this.updateByFlowId(process); + return R.ok(); + } }