jihs 3 anos atrás
pai
commit
6282dc2868

+ 4 - 0
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/mapper/ActBusinessMapper.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.activiti.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.*;
 import org.jeecg.modules.activiti.entity.ActBusiness;
+import org.springframework.security.core.parameters.P;
 
 import java.util.List;
 import java.util.Map;
@@ -33,4 +34,7 @@ public interface ActBusinessMapper extends BaseMapper<ActBusiness> {
     @Select("SELECT ari.ID_ FROM ACT_RU_IDENTITYLINK ari\n" +
             "      WHERE TYPE_ = #{type} AND TASK_ID_ = #{taskId}")
     List<String> selectIRunIdentity(@Param("taskId")String taskId,@Param("type") String type);
+
+    @Select("select * from ${tableName} where ${pid} = #{tableId}")
+    List<Map<String, Object>> getChildList(@Param("tableId") String tableId, @Param("tableName") String tableName, @Param("pid") String pid);
 }

+ 117 - 34
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/service/Impl/ActBusinessServiceImpl.java

@@ -2,17 +2,27 @@ package org.jeecg.modules.activiti.service.Impl;
 
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jdk.nashorn.internal.scripts.JS;
+import org.activiti.engine.delegate.DelegateExecution;
 import org.apache.commons.lang.StringUtils;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.modules.activiti.entity.ActBusiness;
 import org.jeecg.modules.activiti.mapper.ActBusinessMapper;
 import org.jeecg.modules.activiti.service.IActBusinessService;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 流程业务扩展表
@@ -30,40 +40,50 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
      * <br>该方法相对通用,复杂业务单独定制,套路类似
      * @param tableId 业务表中的数据id
      * */
-    public void saveApplyForm(String tableId, HttpServletRequest request) {
-        String tableName = request.getParameter("tableName");
-        String filedNames = request.getParameter("filedNames");
-        //子表
-        String tableNameB= request.getParameter("tableNameB");
-        String filedNamesB= request.getParameter("filedNamesB");
-
-        Map<String, Object> busiData = this.baseMapper.getBusiData(tableId, tableName);
-        String[] fileds = filedNames.split(",");
-        if (MapUtil.isEmpty(busiData)){ //没有,新增逻辑
-            StringBuilder filedsB = new StringBuilder("id");
-            StringBuilder filedsVB = new StringBuilder("'"+tableId+"'");
-            for (String filed : fileds) {
-                filedsB.append(","+filed);
-                filedsVB.append(",'"+request.getParameter(filed)+"'");
-            }
+    public void saveApplyForm(String tableId, HttpServletRequest request) throws IOException {
+//           String json = getRequestPostStr(request);
+//           JSONObject jsonObject = JSONObject.parseObject(json);
+
+            String tableName = request.getParameter("tableName");
+            String filedNames = request.getParameter("filedNames");
+            //子表
+            String tableNameB= request.getParameter("tableNameB");
+            String filedNamesB= request.getParameter("filedNamesB");
+           String childstr= request.getParameter("childList");  //
+
+            Map<String, Object> busiData = this.baseMapper.getBusiData(tableId, tableName);
+            String[] fileds = filedNames.split(",");
+            if (MapUtil.isEmpty(busiData)){ //没有,新增逻辑
+                StringBuilder filedsB = new StringBuilder("id");
+                StringBuilder filedsVB = new StringBuilder("'"+tableId+"'");
+                for (String filed : fileds) {
+                    filedsB.append(","+filed);
+                    filedsVB.append(",'"+request.getParameter(filed)+"'");
+                }
             this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)",tableName,filedsB.toString(),filedsVB.toString()));
 
-            //子表新增逻辑
-            if(StringUtils.isNotBlank(tableNameB)){
-                String tableBId = IdUtil.simpleUUID();
+            //子表是否存在
+            if(StringUtils.isNotBlank(tableNameB)) {
+
+                JSONArray jsonArray = JSONArray.parseArray(childstr);
+                for(int i =0; i< jsonArray.size(); i++) {
+                    String tableBId = IdUtil.simpleUUID();
                     StringBuilder filedIdB = new StringBuilder("id");
                     StringBuilder filedIdVB = new StringBuilder("'" + tableBId + "'");
                     filedIdB.append("," + tableName + "_id");
                     filedIdVB.append(",'" + tableId + "'");
                     String[] fileds2 = filedNamesB.split(",");
+                    JSONObject jobj = (JSONObject) jsonArray.get(i);
+
+
                     for(String filed : fileds2) {
                         filedIdB.append("," + filed);
-                        filedIdVB.append(",'" + request.getParameter(filed) + "'");
+                        filedIdVB.append(",'" + jobj.getString(filed) + "'");
                     }
 
                     this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", tableNameB, filedIdB.toString(), filedIdVB.toString()));
                 }
-
+            }
         }else { //有,修改
             StringBuilder setSql = new StringBuilder();
             for (String filed : fileds) {
@@ -77,23 +97,31 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             String substring = setSql.substring(0, setSql.length()-1);//去掉最后一个,号
             this.baseMapper.insertBusiData(String.format("update %s set %s where id = '%s'",tableName,substring,tableId));
             //子表修改逻辑
-            if(StringUtils.isNotBlank(tableNameB)){
-                StringBuilder setSql2 = new StringBuilder();
-                String tableBId = IdUtil.simpleUUID();
-                String[] fileds2 = filedNamesB.split(",");
-                for(String filed : fileds2) {
-                    String parameter2 = request.getParameter(filed);
-                    if (parameter2==null){
-                        setSql2.append(String.format("%s = null,",filed));
-                    }else {
-                        setSql2.append(String.format("%s = '%s',",filed, parameter2));
+            if(StringUtils.isNotBlank(tableNameB)) {
+                JSONArray jsonArray = JSONArray.parseArray(childstr);
+                for(int i = 0; i < jsonArray.size(); i++) {
+                    StringBuilder setSql2 = new StringBuilder();
+                    JSONObject jobj = (JSONObject) jsonArray.get(i);
+                    String tableBId = jobj.getString("id");
+                    if(StringUtils.isBlank(tableBId)){
+                        throw new JeecgBootException("子表id不能为空");
                     }
+
+                    String[] fileds2 = filedNamesB.split(",");
+
+                    for(String filed : fileds2) {
+                        String parameter2 = jobj.getString(filed);
+                        if(parameter2 == null) {
+                            setSql2.append(String.format("%s = null,", filed));
+                        } else {
+                            setSql2.append(String.format("%s = '%s',", filed, parameter2));
+                        }
+                    }
+                    String substring2 = setSql.substring(0, setSql2.length() - 1);//去掉最后一个,号
+                    this.baseMapper.insertBusiData(String.format("update %s set %s where id = '%s'", tableNameB, substring2, tableBId));
                 }
-                String substring2 = setSql.substring(0, setSql2.length()-1);//去掉最后一个,号
-                this.baseMapper.insertBusiData(String.format("update %s set %s where id = '%s'", tableNameB, substring2, tableBId));
             }
 
-
         }
 
     }
@@ -130,4 +158,59 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             System.out.println("end=========");
         }
     }
+
+    /**
+     * @desc 获取 post 请求内容
+     */
+    private String getRequestPostStr(HttpServletRequest request) throws IOException {
+        byte buffer[] = getRequestPostBytes(request);
+        String charEncoding = request.getCharacterEncoding();
+        if (charEncoding == null) {
+            charEncoding = "UTF-8";
+        }
+        return new String(buffer, charEncoding);
+    }
+
+    public static byte[] getRequestPostBytes(HttpServletRequest request)
+            throws IOException {
+        int contentLength = request.getContentLength();
+        if(contentLength<0){
+            return null;
+        }
+        byte buffer[] = new byte[contentLength];
+        for (int i = 0; i < contentLength;)
+        {
+            int readlen = request.getInputStream().read(buffer, i,
+                    contentLength - i);
+            if (readlen == -1) {
+                break;
+            }
+            i += readlen;
+        }
+        return buffer;
+    }
+
+
+    /***
+     * 获取 request 中 json 字符串的内容
+     *
+     * @param request
+     * @return : <code>byte[]</code>
+     * @throws IOException
+     */
+    private String getRequestJsonString(HttpServletRequest request)
+            throws IOException {
+        String submitMehtod = request.getMethod();
+        // GET
+        if (submitMehtod.equals("GET")) {
+            return new String(request.getQueryString().getBytes("iso-8859-1"),"utf-8").replaceAll("%22", "\"");
+            // POST
+        } else {
+            return getRequestPostStr(request);
+        }
+    }
+
+    public List<Map<String,Object>> getChildList(String tableId, String tableName, String pid) {
+        return this.baseMapper.getChildList(tableId, tableName, pid);
+    }
 }

+ 19 - 4
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActBusinessController.java

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.activiti.engine.RuntimeService;
 import org.activiti.engine.TaskService;
 import org.activiti.engine.task.Task;
+import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.api.ISysBaseAPI;
@@ -25,9 +26,11 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  *
@@ -52,7 +55,7 @@ public class ActBusinessController {
     ISysBaseAPI sysBaseAPI;
     /*添加申请草稿状态*/
     @RequestMapping(value = "/add", method = RequestMethod.POST)
-    public Result add(HttpServletRequest request){
+    public Result add(HttpServletRequest request) throws IOException {
         String procDefId = request.getParameter("procDefId");
         String procDeTitle = request.getParameter("procDeTitle");
         String tableName = request.getParameter("tableName");
@@ -82,15 +85,27 @@ public class ActBusinessController {
         /*保存业务表单数据到数据库表*/
         String tableId = request.getParameter("tableId");
         String tableName = request.getParameter("tableName");
+        String tableNameb = request.getParameter("tableNameB");
         if (StrUtil.isBlank(tableName)){
             return Result.error("参数缺省!");
         }
-        Map<String, Object> applyForm = actBusinessService.getApplyForm(tableId, tableName);
-        return Result.ok(applyForm);
+        Map<String, Object> applyForm = null;
+        List<Map<String, Object>> list = null;
+        if(StringUtils.isBlank(tableNameb)){
+            applyForm = actBusinessService.getApplyForm(tableId, tableName);
+            return Result.ok(applyForm);
+        } else {
+            applyForm = actBusinessService.getApplyForm(tableId, tableName);
+            list = actBusinessService.getChildList(tableId, tableNameb, tableName+"_id");
+            applyForm.put("childList", list);
+            return
+                    Result.ok(applyForm);
+
+        }
     }
     /*修改业务表单信息*/
     @RequestMapping(value = "/editForm", method = RequestMethod.POST)
-    public Result editForm(HttpServletRequest request){
+    public Result editForm(HttpServletRequest request) throws IOException {
         /*保存业务表单数据到数据库表*/
         String tableId = request.getParameter("id");
         actBusinessService.saveApplyForm(tableId,request);