mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 14:09:00 +08:00
feat(flow-task): 新增序列号组件 (依赖于后端赋值)
This commit is contained in:
1 parent
af90a5c906
commit
312720fada
2 files changed
+179
-147
No files matched your search
+3
@@ -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;
|
||||
|
||||
+176
-147
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -40,178 +46,201 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class ProcessServiceImpl extends ServiceImpl<ProcessMapper, Process> 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<ProcessVO> 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<ProcessVO> 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<String> 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<String> 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<String, Object> map = new HashMap<>();
|
||||
map.put("process", process);
|
||||
map.put("userId", SecurityUtils.getUser().getId());
|
||||
R<String> r = flowEngineService.createFlow(map);
|
||||
if (!r.isOk()) {
|
||||
return R.failed(r.getMsg());
|
||||
}
|
||||
String flowId = r.getData();
|
||||
NodeUser nodeUser = objectMapper.readValue(process.getAdminList(), new TypeReference<List<NodeUser>>() {
|
||||
}).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<String, Object> map = new HashMap<>();
|
||||
map.put("process", process);
|
||||
map.put("userId", SecurityUtils.getUser().getId());
|
||||
R<String> r = flowEngineService.createFlow(map);
|
||||
if (!r.isOk()) {
|
||||
return R.failed(r.getMsg());
|
||||
}
|
||||
String flowId = r.getData();
|
||||
NodeUser nodeUser = objectMapper.readValue(process.getAdminList(), new TypeReference<List<NodeUser>>() {
|
||||
}).get(0);
|
||||
|
||||
Node startNode = objectMapper.readValue(process.getProcess(), Node.class);
|
||||
// 更新流程
|
||||
if (StrUtil.isNotBlank(process.getFlowId())) {
|
||||
|
||||
List<NodeUser> 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<NodeUser> 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user