jihs 3 yıl önce
ebeveyn
işleme
b00690778b

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

@@ -6,6 +6,7 @@ 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 com.google.common.collect.Lists;
 import org.activiti.engine.delegate.DelegateExecution;
 import org.apache.commons.lang.StringUtils;
 import org.jeecg.modules.activiti.entity.ActBusiness;
@@ -14,6 +15,7 @@ import org.jeecg.modules.activiti.service.IActBusinessService;
 import org.springframework.stereotype.Service;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -42,7 +44,13 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             //子表
             String tableNameB= request.getParameter("table_name_b");
             String filedNamesB= request.getParameter("filedNamesB");
-           String childstr= request.getParameter("childList");  //
+            String childstr= request.getParameter("childList");
+
+            String tableNameChildren = request.getParameter("table_name_children"); //其他子表集合
+            List<String> tableNameChildrenList = Lists.newArrayList();
+            if(StringUtils.isNotBlank(tableNameChildren)){
+                tableNameChildrenList = Arrays.asList(tableNameChildren.split(","));
+            }
 
             Map<String, Object> busiData = this.baseMapper.getBusiData(tableId, tableName);
             String[] fileds = filedNames.split(",");
@@ -64,7 +72,7 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             if(StringUtils.isNotBlank(tableNameB)) {
 
                 JSONArray jsonArray = JSONArray.parseArray(childstr);
-                for(int i =0; i< jsonArray.size(); i++) {
+                for(int i = 0; i < jsonArray.size(); i++) {
                     //子表id
                     String tableBId = IdUtil.simpleUUID();
                     StringBuilder filedIdB = new StringBuilder("id");
@@ -75,19 +83,53 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
                     String[] fileds2 = filedNamesB.split(",");
                     JSONObject jobj = (JSONObject) jsonArray.get(i);
 
-
                     for(String filed : fileds2) {
-                            filedIdB.append(",`" + filed+"`");
-                            filedIdVB.append(",'" + jobj.getString(filed) + "'");
+                        filedIdB.append(",`" + filed + "`");
+                        filedIdVB.append(",'" + jobj.getString(filed) + "'");
                     }
 
                     //排序
                     filedIdB.append(",sort");
                     filedIdVB.append(",'" + i + "'");
 
-                     //新增子表
+                    //新增子表
                     this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", tableNameB, filedIdB.toString(), filedIdVB.toString()));
                 }
+
+            }
+            if(StringUtils.isNotBlank(tableNameChildren)){
+                //新增其他子表数据
+                for(int j = 1; j<= tableNameChildrenList.size(); j++){
+                    String childFiledNames= request.getParameter("childFiledNames" + j);   //其他子表字段
+                    String childList= request.getParameter("childList"+j);     //其他子表List数据
+                    JSONArray childrenArray = JSONArray.parseArray(childList);
+                    for(int i =0; i< childrenArray.size(); i++){
+                    //子表id
+                    String tableBId = IdUtil.simpleUUID();
+                    StringBuilder filedIdB = new StringBuilder("id");  //字段
+                    StringBuilder filedIdVB = new StringBuilder("'" + tableBId + "'"); //字段值
+
+                    //主表id
+                    filedIdB.append("," + tableName + "_id");
+                    filedIdVB.append(",'" + tableId + "'");
+                    String[] fileds2 = childFiledNames.split(",");
+                    JSONObject jobj = (JSONObject) childrenArray.get(i);
+
+
+                    for(String filed : fileds2) {
+                        filedIdB.append(",`" + filed+"`");
+                        filedIdVB.append(",'" + jobj.getString(filed) + "'");
+                    }
+
+                    //排序
+                    filedIdB.append(",sort");
+                    filedIdVB.append(",'" + i + "'");
+
+                    //新增子表
+                    String childTableName = tableNameChildrenList.get(j - 1);
+                    this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", childTableName, filedIdB.toString(), filedIdVB.toString()));
+                    }
+                }
             }
         }else { //有,修改
             StringBuilder setSql = new StringBuilder();
@@ -129,9 +171,41 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
                     this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", tableNameB, filedIdB.toString(), filedIdVB.toString()));
                 }
             }
+                if(StringUtils.isNotBlank(tableNameChildren)){
+                    //修改其他子表逻辑
+                    for(int j = 1; j<= tableNameChildrenList.size(); j++){
+                        String childFiledNames= request.getParameter("childFiledNames" + j);   //其他子表字段
+                        String childList= request.getParameter("childList"+j);     //其他子表List数据
+                        String childTableName = tableNameChildrenList.get(j - 1); //其他子表名
+                        JSONArray jsonArray = JSONArray.parseArray(childList);
 
-        }
+                        //删除子表
+                        this.baseMapper.deletetBusiData(String.format("DELETE FROM %s WHERE %s = %s", childTableName, tableName + "_id",  "'" + tableId + "'"));
+                        for(int i = 0; i < jsonArray.size(); i++) {
+                            //子表id
+                            String tableBId = IdUtil.simpleUUID();
+                            StringBuilder filedIdB = new StringBuilder("id");
+                            StringBuilder filedIdVB = new StringBuilder("'" + tableBId + "'");
+                            //主表id
+                            filedIdB.append("," + tableName + "_id");
+                            filedIdVB.append(",'" + tableId + "'");
+                            String[] fileds2 = childFiledNames.split(",");
+                            JSONObject jobj = (JSONObject) jsonArray.get(i);
+
+
+                            for (String filed : fileds2) {
+                                filedIdB.append(",`"+filed+"`");
+                                filedIdVB.append(",'"+jobj.getString(filed)+"'");
+                            }
 
+                            //排序
+                            filedIdB.append(",sort");
+                            filedIdVB.append(",'" + i + "'");
+                            this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", childTableName, filedIdB.toString(), filedIdVB.toString()));
+                        }
+                    }
+                }
+        }
     }
 
     public Map<String, Object> getApplyForm(String tableId, String tableName) {

+ 25 - 3
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActBusinessController.java

@@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.activiti.engine.RuntimeService;
@@ -86,11 +87,12 @@ public class ActBusinessController {
         /*保存业务表单数据到数据库表*/
         String tableId = request.getParameter("tableId");
         String tableName = request.getParameter("tableName");
-//        String tableNameb = request.getParameter("tableNameB");
         Map<String, Object> map = actBusinessService.getApplyForm(tableId, tableName);
         String tableNameb = null;
+        String tableNameChildren = null;
         if(MapUtil.isNotEmpty(map)){
             tableNameb  = (String) map.get("table_name_b");
+            tableNameChildren = (String)map.get("table_name_children");
         }
 
         if (StrUtil.isBlank(tableName)){
@@ -100,14 +102,34 @@ public class ActBusinessController {
         List<Map<String, Object>> list = null;
         if(StringUtils.isBlank(tableNameb)){
             applyForm = actBusinessService.getApplyForm(tableId, tableName);
+            //其他子表
+
+            if(StringUtils.isNotBlank(tableNameChildren)){
+                String[] tableNamesChidArr = tableNameChildren.split(",");
+                for(int i = 0; i < tableNamesChidArr.length; i++){
+                    list = actBusinessService.getChildList(tableId, tableNamesChidArr[i], tableName+"_id");
+                    int j = i+1;
+                    applyForm.put("childList"+ j, list);
+                }
+
+            }
             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);
+            //其他子表
+            if(StringUtils.isNotBlank(tableNameChildren)){
+                String[] tableNamesChidArr = tableNameChildren.split(",");
+                for(int i = 0; i < tableNamesChidArr.length; i++){
+                    list = actBusinessService.getChildList(tableId, tableNamesChidArr[i], tableName+"_id");
+                    int j = i+1;
+                    applyForm.put("childList"+ j, list);
+                }
+
+            }
 
+            return Result.ok(applyForm);
         }
     }
     /*修改业务表单信息*/