|
@@ -6,7 +6,7 @@ import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.fastjson2.TypeReference;
|
|
import com.alibaba.fastjson2.TypeReference;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.flowable.common.constant.ProcessConstants;
|
|
import com.ruoyi.flowable.common.constant.ProcessConstants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
|
@@ -24,10 +24,12 @@ import com.ruoyi.flowable.factory.FlowServiceFactory;
|
|
|
import com.ruoyi.flowable.flow.CustomProcessDiagramGenerator;
|
|
import com.ruoyi.flowable.flow.CustomProcessDiagramGenerator;
|
|
|
import com.ruoyi.flowable.flow.FindNextNodeUtil;
|
|
import com.ruoyi.flowable.flow.FindNextNodeUtil;
|
|
|
import com.ruoyi.flowable.flow.FlowableUtils;
|
|
import com.ruoyi.flowable.flow.FlowableUtils;
|
|
|
|
|
+import com.ruoyi.flowable.flow.VFormUtils;
|
|
|
import com.ruoyi.flowable.service.IFlowTaskService;
|
|
import com.ruoyi.flowable.service.IFlowTaskService;
|
|
|
import com.ruoyi.flowable.service.ISysDeployFormService;
|
|
import com.ruoyi.flowable.service.ISysDeployFormService;
|
|
|
import com.ruoyi.flowable.service.ISysFormService;
|
|
import com.ruoyi.flowable.service.ISysFormService;
|
|
|
import com.ruoyi.system.domain.SysForm;
|
|
import com.ruoyi.system.domain.SysForm;
|
|
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -81,6 +83,8 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
@Resource
|
|
@Resource
|
|
|
private ISysUserService sysUserService;
|
|
private ISysUserService sysUserService;
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
|
|
+ @Resource
|
|
|
private ISysRoleService sysRoleService;
|
|
private ISysRoleService sysRoleService;
|
|
|
@Resource
|
|
@Resource
|
|
|
private ISysDeployFormService sysInstanceFormService;
|
|
private ISysDeployFormService sysInstanceFormService;
|
|
@@ -424,6 +428,7 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void claim(FlowTaskVo flowTaskVo) {
|
|
public void claim(FlowTaskVo flowTaskVo) {
|
|
|
|
|
+ flowTaskVo.setUserId(SecurityUtils.getUserId().toString());
|
|
|
taskService.claim(flowTaskVo.getTaskId(), flowTaskVo.getUserId());
|
|
taskService.claim(flowTaskVo.getTaskId(), flowTaskVo.getUserId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -552,6 +557,9 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
if (StringUtils.isNotBlank(taskList.get(0).getAssignee())) {
|
|
if (StringUtils.isNotBlank(taskList.get(0).getAssignee())) {
|
|
|
// 当前任务节点办理人信息
|
|
// 当前任务节点办理人信息
|
|
|
SysUser sysUser = sysUserService.selectUserById(Long.parseLong(taskList.get(0).getAssignee()));
|
|
SysUser sysUser = sysUserService.selectUserById(Long.parseLong(taskList.get(0).getAssignee()));
|
|
|
|
|
+ if(sysUser==null){
|
|
|
|
|
+ sysUser=sysUserService.selectUserByUserName(taskList.get(0).getAssignee());
|
|
|
|
|
+ }
|
|
|
if (Objects.nonNull(sysUser)) {
|
|
if (Objects.nonNull(sysUser)) {
|
|
|
flowTask.setAssigneeId(sysUser.getUserId());
|
|
flowTask.setAssigneeId(sysUser.getUserId());
|
|
|
flowTask.setAssigneeName(sysUser.getNickName());
|
|
flowTask.setAssigneeName(sysUser.getNickName());
|
|
@@ -690,13 +698,17 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public AjaxResult todoList(FlowQueryVo queryVo) {
|
|
public AjaxResult todoList(FlowQueryVo queryVo) {
|
|
|
|
|
+ System.out.print(sysUserService+"------------------------------");
|
|
|
Page<FlowTaskDto> page = new Page<>();
|
|
Page<FlowTaskDto> page = new Page<>();
|
|
|
// 只查看自己的数据
|
|
// 只查看自己的数据
|
|
|
SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
|
|
|
+ // 1. 获取用户所属的组/部门列表
|
|
|
|
|
+ List<String> groupIds = getCurrentUserGroups(sysUser.getUserId());
|
|
|
TaskQuery taskQuery = taskService.createTaskQuery()
|
|
TaskQuery taskQuery = taskService.createTaskQuery()
|
|
|
.active()
|
|
.active()
|
|
|
.includeProcessVariables()
|
|
.includeProcessVariables()
|
|
|
- .taskCandidateGroupIn(sysUser.getRoles().stream().map(role -> role.getRoleId().toString()).collect(Collectors.toList()))
|
|
|
|
|
|
|
+ //.taskCandidateGroupIn(sysUser.getRoles().stream().map(role -> role.getRoleId().toString()).collect(Collectors.toList()))
|
|
|
|
|
+ .taskCandidateGroupIn(groupIds)
|
|
|
.taskCandidateOrAssigned(sysUser.getUserId().toString())
|
|
.taskCandidateOrAssigned(sysUser.getUserId().toString())
|
|
|
.orderByTaskCreateTime().desc();
|
|
.orderByTaskCreateTime().desc();
|
|
|
|
|
|
|
@@ -716,6 +728,9 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
flowTask.setProcDefId(task.getProcessDefinitionId());
|
|
flowTask.setProcDefId(task.getProcessDefinitionId());
|
|
|
flowTask.setExecutionId(task.getExecutionId());
|
|
flowTask.setExecutionId(task.getExecutionId());
|
|
|
flowTask.setTaskName(task.getName());
|
|
flowTask.setTaskName(task.getName());
|
|
|
|
|
+ if(StringUtils.isNotBlank(task.getAssignee())){
|
|
|
|
|
+ flowTask.setAssigneeId(Long.parseLong(task.getAssignee()));
|
|
|
|
|
+ }
|
|
|
// 流程定义信息
|
|
// 流程定义信息
|
|
|
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
|
|
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
|
|
|
.processDefinitionId(task.getProcessDefinitionId())
|
|
.processDefinitionId(task.getProcessDefinitionId())
|
|
@@ -858,8 +873,17 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
stringBuilder.append(sysUser.getNickName()).append(",");
|
|
stringBuilder.append(sysUser.getNickName()).append(",");
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isNotBlank(identityLink.getGroupId())) {
|
|
if (StringUtils.isNotBlank(identityLink.getGroupId())) {
|
|
|
|
|
+ // 先尝试作为部门查询
|
|
|
|
|
+ SysDept dept = sysDeptService.selectDeptById(Long.parseLong(identityLink.getGroupId()));
|
|
|
|
|
+ if (dept != null) {
|
|
|
|
|
+ stringBuilder.append(dept.getDeptName()).append(",");
|
|
|
|
|
+ continue; // 找到部门后不再查找角色
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果不是部门,尝试作为角色查询
|
|
|
SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
|
|
SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
|
|
|
- stringBuilder.append(sysRole.getRoleName()).append(",");
|
|
|
|
|
|
|
+ if(sysRole!=null) {
|
|
|
|
|
+ stringBuilder.append(sysRole.getRoleName()).append(",");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1170,7 +1194,7 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public AjaxResult flowTaskForm(String taskId) throws Exception {
|
|
public AjaxResult flowTaskForm(String taskId) throws Exception {
|
|
|
- JSONObject result = new JSONObject();
|
|
|
|
|
|
|
+ /*JSONObject result = new JSONObject();
|
|
|
result.put("formKeyExist", false);
|
|
result.put("formKeyExist", false);
|
|
|
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
|
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
|
|
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
|
|
@@ -1212,7 +1236,59 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
} else {
|
|
} else {
|
|
|
result.put("formData", parameters.get("variables"));
|
|
result.put("formData", parameters.get("variables"));
|
|
|
return AjaxResult.success("", result);
|
|
return AjaxResult.success("", result);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
|
|
|
+ // 流程变量
|
|
|
|
|
+ Map<String, Object> parameters = new HashMap<>();
|
|
|
|
|
+ HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().finished().taskId(taskId).singleResult();
|
|
|
|
|
+ if (Objects.nonNull(historicTaskInstance)) {
|
|
|
|
|
+ parameters = historicTaskInstance.getProcessVariables();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parameters = taskService.getVariables(taskId);
|
|
|
}
|
|
}
|
|
|
|
|
+ /*JSONObject oldVariables = JSONObject.parseObject(JSON.toJSONString(parameters.get("formJson")));
|
|
|
|
|
+ List<JSONObject> oldFields = JSON.parseObject(JSON.toJSONString(oldVariables.get("widgetList")), new TypeReference<List<JSONObject>>() {
|
|
|
|
|
+ });
|
|
|
|
|
+ // 设置已填写的表单为禁用状态
|
|
|
|
|
+ for (JSONObject oldField : oldFields) {
|
|
|
|
|
+ JSONObject options = oldField.getJSONObject("options");
|
|
|
|
|
+ options.put("disabled", true);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ // 获取原始对象引用(关键修改点)
|
|
|
|
|
+ JSONObject oldVariables = JSONObject.parseObject(JSON.toJSONString(parameters.get("formJson")));
|
|
|
|
|
+ JSONArray oldFields = oldVariables.getJSONArray("widgetList");
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 调用工具类方法处理
|
|
|
|
|
+ VFormUtils.disableGridColFields(oldFields);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 记录日志或进行其他处理
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException("处理表单组件失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 暂时只处理用户任务上的表单
|
|
|
|
|
+ if (StringUtils.isNotBlank(task.getFormKey())) {
|
|
|
|
|
+ SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey()));
|
|
|
|
|
+ JSONObject data = JSONObject.parseObject(sysForm.getFormContent());
|
|
|
|
|
+ List<JSONObject> newFields = JSON.parseObject(JSON.toJSONString(data.get("widgetList")), new TypeReference<List<JSONObject>>() {
|
|
|
|
|
+ });
|
|
|
|
|
+ // 表单回显时 加入子表单信息到流程变量中
|
|
|
|
|
+ for (JSONObject newField : newFields) {
|
|
|
|
|
+ String key = newField.getString("id");
|
|
|
|
|
+ // 处理图片上传组件回显问题
|
|
|
|
|
+ if ("picture-upload".equals(newField.getString("type"))) {
|
|
|
|
|
+ parameters.put(key, new ArrayList<>());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parameters.put(key, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ oldFields.addAll(newFields);
|
|
|
|
|
+ }
|
|
|
|
|
+ oldVariables.put("widgetList", oldFields);
|
|
|
|
|
+ parameters.put("formJson", oldVariables);
|
|
|
|
|
+ return AjaxResult.success(parameters);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1260,4 +1336,48 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
|
|
|
return 0 + "秒";
|
|
return 0 + "秒";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 辅助方法:判断是否是 input/select 类型
|
|
|
|
|
+ private boolean isInputOrSelect(String fieldType) {
|
|
|
|
|
+ return "input".equals(fieldType) || "select".equals(fieldType);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 辅助方法:判断是否是栅格嵌套的 input(递归检查子字段)
|
|
|
|
|
+ private boolean isNestedInputInGrid(JSONObject field) {
|
|
|
|
|
+ String fieldType = field.containsKey("type") ? field.getString("type") : "";
|
|
|
|
|
+ // 如果是栅格类型,递归检查子字段
|
|
|
|
|
+ if (fieldType.contains("grid")) {
|
|
|
|
|
+ JSONArray cols = field.getJSONArray("cols");
|
|
|
|
|
+ if (cols != null) {
|
|
|
|
|
+ for (int i = 0; i < cols.size(); i++) {
|
|
|
|
|
+ JSONObject subField = cols.getJSONObject(i);
|
|
|
|
|
+ String subFieldType = subField.containsKey("type") ? subField.getString("type") : "";
|
|
|
|
|
+ if (subField != null) {
|
|
|
|
|
+ // 递归检查子字段是否是 input/select
|
|
|
|
|
+ if (isInputOrSelect(subFieldType)
|
|
|
|
|
+ || isNestedInputInGrid(subField)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前用户所属的组/部门列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<String> getCurrentUserGroups(Long userId) {
|
|
|
|
|
+ // 实现获取用户所属组逻辑,例如:
|
|
|
|
|
+ // 1. 从部门获取
|
|
|
|
|
+ SysUser user = sysUserService.selectUserById(userId);
|
|
|
|
|
+ List<String> groups = new ArrayList<>();
|
|
|
|
|
+ groups.add(user.getDeptId().toString());
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 从角色获取
|
|
|
|
|
+ List<SysRole> roles = sysRoleService.selectRolesByUserId(userId);
|
|
|
|
|
+ roles.forEach(role -> groups.add(role.getRoleId().toString()));
|
|
|
|
|
+
|
|
|
|
|
+ return groups;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|