jihs 3 lat temu
rodzic
commit
40ed4c4d06

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

@@ -37,4 +37,6 @@ public interface ActBusinessMapper extends BaseMapper<ActBusiness> {
 
     @Select("select * from ${tableName} where ${pid} = #{tableId}")
     List<Map<String, Object>> getChildList(@Param("tableId") String tableId, @Param("tableName") String tableName, @Param("pid") String pid);
+    @Delete("${sql}")
+    void deletetBusiData(@Param("sql") String format);
 }

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

@@ -2,27 +2,20 @@ 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: 流程业务扩展表
@@ -47,7 +40,7 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             String tableName = request.getParameter("tableName");
             String filedNames = request.getParameter("filedNames");
             //子表
-            String tableNameB= request.getParameter("tableNameB");
+            String tableNameB= request.getParameter("table_name_b");
             String filedNamesB= request.getParameter("filedNamesB");
            String childstr= request.getParameter("childList");  //
 
@@ -67,9 +60,11 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
 
                 JSONArray jsonArray = JSONArray.parseArray(childstr);
                 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 = filedNamesB.split(",");
@@ -81,6 +76,11 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
                         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()));
                 }
             }
@@ -100,25 +100,30 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             if(StringUtils.isNotBlank(tableNameB)) {
                 JSONArray jsonArray = JSONArray.parseArray(childstr);
                 for(int i = 0; i < jsonArray.size(); i++) {
-                    StringBuilder setSql2 = new StringBuilder();
+                    //子表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 = filedNamesB.split(",");
                     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));
-                        }
+                    for (String filed : fileds2) {
+                        filedIdB.append(","+filed);
+                        filedIdVB.append(",'"+jobj.getString(filed)+"'");
                     }
-                    String substring2 = setSql.substring(0, setSql2.length() - 1);//去掉最后一个,号
-                    this.baseMapper.insertBusiData(String.format("update %s set %s where id = '%s'", tableNameB, substring2, tableBId));
+
+                    //排序
+                    filedIdB.append(",sort");
+                    filedIdVB.append(",'" + i + "'");
+                    //删除子表
+                    this.baseMapper.deletetBusiData(String.format("DELETE FROM %s WHERE %s = %s", tableNameB, tableName + "_id",  tableBId));
+
+
+                    this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", tableNameB, filedIdB.toString(), filedIdVB.toString()));
                 }
             }
 

+ 7 - 1
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActBusinessController.java

@@ -85,7 +85,13 @@ public class ActBusinessController {
         /*保存业务表单数据到数据库表*/
         String tableId = request.getParameter("tableId");
         String tableName = request.getParameter("tableName");
-        String tableNameb = request.getParameter("tableNameB");
+//        String tableNameb = request.getParameter("tableNameB");
+        Map<String, Object> map = actBusinessService.getApplyForm(tableId, tableName);
+        String tableNameb = null;
+        if(MapUtil.isNotEmpty(map)){
+            tableNameb  = (String) map.get("table_name_b");
+        }
+
         if (StrUtil.isBlank(tableName)){
             return Result.error("参数缺省!");
         }