Browse Source

工作流+自定义表单

姚斌 1 year ago
parent
commit
3266dd41c3

+ 109 - 0
itdmServer/module-ACTIVITI/src/main/java/org/jeecg/common/utils/BeanUtils.java

@@ -0,0 +1,109 @@
+package org.jeecg.common.utils;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Bean 工具类
+ *
+ */
+public class BeanUtils extends org.springframework.beans.BeanUtils
+{
+    /** Bean方法名中属性名开始的下标 */
+    private static final int BEAN_METHOD_PROP_INDEX = 3;
+
+    /** * 匹配getter方法的正则表达式 */
+    private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)");
+
+    /** * 匹配setter方法的正则表达式 */
+    private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)");
+
+    /**
+     * Bean属性复制工具方法。
+     *
+     * @param dest 目标对象
+     * @param src 源对象
+     */
+    public static void copyBeanProp(Object dest, Object src)
+    {
+        try
+        {
+            copyProperties(src, dest);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取对象的setter方法。
+     *
+     * @param obj 对象
+     * @return 对象的setter方法列表
+     */
+    public static List<Method> getSetterMethods(Object obj)
+    {
+        // setter方法列表
+        List<Method> setterMethods = new ArrayList<Method>();
+
+        // 获取所有方法
+        Method[] methods = obj.getClass().getMethods();
+
+        // 查找setter方法
+
+        for (Method method : methods)
+        {
+            Matcher m = SET_PATTERN.matcher(method.getName());
+            if (m.matches() && (method.getParameterTypes().length == 1))
+            {
+                setterMethods.add(method);
+            }
+        }
+        // 返回setter方法列表
+        return setterMethods;
+    }
+
+    /**
+     * 获取对象的getter方法。
+     *
+     * @param obj 对象
+     * @return 对象的getter方法列表
+     */
+
+    public static List<Method> getGetterMethods(Object obj)
+    {
+        // getter方法列表
+        List<Method> getterMethods = new ArrayList<Method>();
+        // 获取所有方法
+        Method[] methods = obj.getClass().getMethods();
+        // 查找getter方法
+        for (Method method : methods)
+        {
+            Matcher m = GET_PATTERN.matcher(method.getName());
+            if (m.matches() && (method.getParameterTypes().length == 0))
+            {
+                getterMethods.add(method);
+            }
+        }
+        // 返回getter方法列表
+        return getterMethods;
+    }
+
+    /**
+     * 检查Bean方法名中的属性名是否相等。<br>
+     * 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。
+     *
+     * @param m1 方法名1
+     * @param m2 方法名2
+     * @return 属性名一样返回true,否则返回false
+     */
+
+    public static boolean isMethodPropEquals(String m1, String m2)
+    {
+        return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
+    }
+}

+ 10 - 2
itdmServer/module-ACTIVITI/src/main/java/org/jeecg/modules/activiti/controller/ServiceController.java

@@ -30,9 +30,11 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.utils.ActivitiTracingChart;
 import org.jeecg.common.utils.AjaxResult;
+import org.jeecg.common.utils.BeanUtils;
 import org.jeecg.modules.activiti.model.entity.EntityUtil;
 import org.jeecg.modules.activiti.model.entity.FlowInfo;
 import org.jeecg.modules.activiti.model.entity.TaskInfo;
+import org.jeecg.modules.activiti.model.entity.VariableInfo;
 import org.jeecg.modules.customform.entity.CustomForm;
 import org.jeecg.modules.customform.service.ICustomFormService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -298,13 +300,19 @@ public class ServiceController {
         List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery()
                 .processInstanceId(executionId)
                 .variableName("formData").list();
-
+        List<VariableInfo> infos = new ArrayList<>();
+        variableInstances.forEach(v->{
+            VariableInfo info = new VariableInfo();
+            BeanUtils.copyBeanProp(info, v);
+            info.setValue(v.getValue().toString());
+            infos.add(info);
+        });
         Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
         // 根据任务id获取任务id的formKey,也就是获取任务节点的自定义表单值
         //formService.getTaskFormData(taskId).getFormKey();
         CustomForm customForm = customFormService.getById(task.getFormKey());
         Map<String ,Object> map = new HashMap<>();
-        map.put("fromData1",variableInstances);
+        map.put("fromData1",infos);
         map.put("fromData2",customForm.getFormcontent());
         return Result.OK("查询成功",map);
     }

+ 58 - 0
itdmServer/module-ACTIVITI/src/main/java/org/jeecg/modules/activiti/model/entity/VariableInfo.java

@@ -0,0 +1,58 @@
+package org.jeecg.modules.activiti.model.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+public class VariableInfo {
+
+    String variableName;
+
+    String variableTypeName;
+
+    String value;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    Date createTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    Date lastUpdatedTime;
+
+    public String getVariableName() {
+        return variableName;
+    }
+
+    public void setVariableName(String variableName) {
+        this.variableName = variableName;
+    }
+
+    public String getVariableTypeName() {
+        return variableTypeName;
+    }
+
+    public void setVariableTypeName(String variableTypeName) {
+        this.variableTypeName = variableTypeName;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getLastUpdatedTime() {
+        return lastUpdatedTime;
+    }
+
+    public void setLastUpdatedTime(Date lastUpdatedTime) {
+        this.lastUpdatedTime = lastUpdatedTime;
+    }
+}