diff --git a/ruoyi-kaohe/pom.xml b/ruoyi-kaohe/pom.xml
index 04677b2..f024544 100644
--- a/ruoyi-kaohe/pom.xml
+++ b/ruoyi-kaohe/pom.xml
@@ -27,6 +27,11 @@
pinyin4j
2.5.0
+
+ org.json
+ json
+ 20210307
+
\ No newline at end of file
diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java
index 16b7440..a998500 100644
--- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java
+++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java
@@ -2,16 +2,21 @@ package com.ruoyi.kaohe.controller;
import java.math.BigDecimal;
import java.util.*;
+import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.utils.LogUtils;
import com.ruoyi.kaohe.domain.KhKhrwResult;
+import com.ruoyi.kaohe.domain.KhVoteEmp;
import com.ruoyi.kaohe.domain.KhgatherParam;
import com.ruoyi.kaohe.service.IKhKhrwResultService;
import com.ruoyi.kaohe.service.IKhVoteEmpService;
import com.ruoyi.kaohe.service.IKhVoteService;
+import com.ruoyi.kaohe.util.JsonDeepMerge;
import com.ruoyi.kaohe.util.PinYinUtil;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -56,139 +61,180 @@ public class KhGatherController extends BaseController {
@PostMapping("/generateSum")
public AjaxResult generateSum(@RequestBody String json) {
// 将String转换为JSONObject
- JSONObject jsonObject = JSONObject.parseObject(json);
+ JSONObject jsonObject = new JSONObject(json);
String hz_name = jsonObject.getString("title");
JSONArray datas = jsonObject.getJSONArray("data");
//拼接表头数据
- JSONArray header = new JSONArray();//存放表头及表格关联数据
+ JSONArray header = new JSONArray();//存放表头的最终数据
//----------------------------------------------------------------------------------------------
//循环主标题下的每一个子节点
- Map nodes = parseJson(datas, hz_name);
- JSONObject btKhdx = (JSONObject)nodes.get("btKhdx");
+ Map nodes = parseJson(datas, hz_name,null);
+ //获取并拼接表头
+ JSONObject btKhdx = (JSONObject) nodes.get("btKhdx");
JSONObject head = (JSONObject) nodes.get("head");
JSONArray oldchildren = head.getJSONArray("children");
JSONArray newChildren = new JSONArray();
- newChildren.add(btKhdx);
+ newChildren.put(btKhdx);
for (Object oldchild : oldchildren) {
- newChildren.add(oldchild);
+ newChildren.put(oldchild);
}
- head.put("children",newChildren);
- header.add(head);
- return AjaxResult.success(header);
+ head.put("children", newChildren);
+ header.put(head);
+
+ //获取并整合数据
+ JSONArray tabledata = new JSONArray((JSONArray) nodes.get("alldatas"));
+ //根据被考核对象名分组数据到map中 得到表格内容的最终数据
+ JSONArray endTableData = JsonDeepMerge.mergeByKey(tabledata, "khdx");
+/* KhGather gather = new KhGather();
+ gather.setHzName(hz_name);
+ gather.setTableHeader(header.toString(2));
+ gather.setTableData(endTableData.toString(2));
+ khGatherService.insertKhGather(gather);*/
+ return AjaxResult.success();
}
- //递归解析json
- private Map parseJson(JSONArray datas, String titleP) {
+ /**
+ * 递归解析json
+ * @param datas
+ * @param titleP
+ * @param z_zb
+ * @return
+ */
+ private Map parseJson(JSONArray datas, String titleP,BigDecimal z_zb) {
Map result = new HashMap<>();
- //父级表头
+ BigDecimal title_zsfs=BigDecimal.ZERO;
+ String pyTitle = PinYinUtil.getPinyinInitials(titleP);//父级表头
JSONObject btKhdx = new JSONObject();
JSONObject btTitle = new JSONObject();
- btTitle.put("name", PinYinUtil.getPinyinInitials(titleP));
+ btTitle.put("name", pyTitle);
btTitle.put("label", titleP);
JSONArray btchildren = new JSONArray();
//---------------------------------------------------------------------
JSONArray bd = new JSONArray();//表数据拼接
- List