jihs 3 роки тому
батько
коміт
5a7acc4ebe

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

@@ -1,9 +1,10 @@
 package org.jeecg.modules.activiti.service.Impl;
 
 import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.IdUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.commons.lang.StringUtils;
 import org.jeecg.modules.activiti.entity.ActBusiness;
 import org.jeecg.modules.activiti.mapper.ActBusinessMapper;
 import org.jeecg.modules.activiti.service.IActBusinessService;
@@ -32,6 +33,10 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
     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)){ //没有,新增逻辑
@@ -42,6 +47,23 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
                 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();
+                    StringBuilder filedIdB = new StringBuilder("id");
+                    StringBuilder filedIdVB = new StringBuilder("'" + tableBId + "'");
+                    filedIdB.append("," + tableName + "_id");
+                    filedIdVB.append(",'" + tableId + "'");
+                    String[] fileds2 = filedNamesB.split(",");
+                    for(String filed : fileds2) {
+                        filedIdB.append("," + filed);
+                        filedIdVB.append(",'" + request.getParameter(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) {
@@ -54,6 +76,24 @@ 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));
+                    }
+                }
+                String substring2 = setSql.substring(0, setSql2.length()-1);//去掉最后一个,号
+                this.baseMapper.insertBusiData(String.format("update %s set %s where id = '%s'", tableNameB, substring2, tableBId));
+            }
+
+
         }
 
     }