|
@@ -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);
|
|
|
+ }
|
|
|
}
|