|
|
|
@ -2,16 +2,21 @@ package com.ruoyi.kaohe.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.ruoyi.common.utils.LogUtils;
|
|
|
|
import com.ruoyi.kaohe.domain.KhKhrwResult;
|
|
|
|
import com.ruoyi.kaohe.domain.KhKhrwResult;
|
|
|
|
|
|
|
|
import com.ruoyi.kaohe.domain.KhVoteEmp;
|
|
|
|
import com.ruoyi.kaohe.domain.KhgatherParam;
|
|
|
|
import com.ruoyi.kaohe.domain.KhgatherParam;
|
|
|
|
import com.ruoyi.kaohe.service.IKhKhrwResultService;
|
|
|
|
import com.ruoyi.kaohe.service.IKhKhrwResultService;
|
|
|
|
import com.ruoyi.kaohe.service.IKhVoteEmpService;
|
|
|
|
import com.ruoyi.kaohe.service.IKhVoteEmpService;
|
|
|
|
import com.ruoyi.kaohe.service.IKhVoteService;
|
|
|
|
import com.ruoyi.kaohe.service.IKhVoteService;
|
|
|
|
|
|
|
|
import com.ruoyi.kaohe.util.JsonDeepMerge;
|
|
|
|
import com.ruoyi.kaohe.util.PinYinUtil;
|
|
|
|
import com.ruoyi.kaohe.util.PinYinUtil;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
@ -56,139 +61,180 @@ public class KhGatherController extends BaseController {
|
|
|
|
@PostMapping("/generateSum")
|
|
|
|
@PostMapping("/generateSum")
|
|
|
|
public AjaxResult generateSum(@RequestBody String json) {
|
|
|
|
public AjaxResult generateSum(@RequestBody String json) {
|
|
|
|
// 将String转换为JSONObject
|
|
|
|
// 将String转换为JSONObject
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
|
JSONObject jsonObject = new JSONObject(json);
|
|
|
|
String hz_name = jsonObject.getString("title");
|
|
|
|
String hz_name = jsonObject.getString("title");
|
|
|
|
JSONArray datas = jsonObject.getJSONArray("data");
|
|
|
|
JSONArray datas = jsonObject.getJSONArray("data");
|
|
|
|
//拼接表头数据
|
|
|
|
//拼接表头数据
|
|
|
|
JSONArray header = new JSONArray();//存放表头及表格关联数据
|
|
|
|
JSONArray header = new JSONArray();//存放表头的最终数据
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
//循环主标题下的每一个子节点
|
|
|
|
//循环主标题下的每一个子节点
|
|
|
|
Map<String, Object> nodes = parseJson(datas, hz_name);
|
|
|
|
Map<String, Object> nodes = parseJson(datas, hz_name,null);
|
|
|
|
|
|
|
|
//获取并拼接表头
|
|
|
|
JSONObject btKhdx = (JSONObject) nodes.get("btKhdx");
|
|
|
|
JSONObject btKhdx = (JSONObject) nodes.get("btKhdx");
|
|
|
|
JSONObject head = (JSONObject) nodes.get("head");
|
|
|
|
JSONObject head = (JSONObject) nodes.get("head");
|
|
|
|
JSONArray oldchildren = head.getJSONArray("children");
|
|
|
|
JSONArray oldchildren = head.getJSONArray("children");
|
|
|
|
JSONArray newChildren = new JSONArray();
|
|
|
|
JSONArray newChildren = new JSONArray();
|
|
|
|
newChildren.add(btKhdx);
|
|
|
|
newChildren.put(btKhdx);
|
|
|
|
for (Object oldchild : oldchildren) {
|
|
|
|
for (Object oldchild : oldchildren) {
|
|
|
|
newChildren.add(oldchild);
|
|
|
|
newChildren.put(oldchild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
head.put("children", newChildren);
|
|
|
|
head.put("children", newChildren);
|
|
|
|
header.add(head);
|
|
|
|
header.put(head);
|
|
|
|
return AjaxResult.success(header);
|
|
|
|
|
|
|
|
|
|
|
|
//获取并整合数据
|
|
|
|
|
|
|
|
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<String, Object> parseJson(JSONArray datas, String titleP) {
|
|
|
|
* 递归解析json
|
|
|
|
|
|
|
|
* @param datas
|
|
|
|
|
|
|
|
* @param titleP
|
|
|
|
|
|
|
|
* @param z_zb
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Map<String, Object> parseJson(JSONArray datas, String titleP,BigDecimal z_zb) {
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
//父级表头
|
|
|
|
BigDecimal title_zsfs=BigDecimal.ZERO;
|
|
|
|
|
|
|
|
String pyTitle = PinYinUtil.getPinyinInitials(titleP);//父级表头
|
|
|
|
JSONObject btKhdx = new JSONObject();
|
|
|
|
JSONObject btKhdx = new JSONObject();
|
|
|
|
JSONObject btTitle = new JSONObject();
|
|
|
|
JSONObject btTitle = new JSONObject();
|
|
|
|
btTitle.put("name", PinYinUtil.getPinyinInitials(titleP));
|
|
|
|
btTitle.put("name", pyTitle);
|
|
|
|
btTitle.put("label", titleP);
|
|
|
|
btTitle.put("label", titleP);
|
|
|
|
JSONArray btchildren = new JSONArray();
|
|
|
|
JSONArray btchildren = new JSONArray();
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
JSONArray bd = new JSONArray();//表数据拼接
|
|
|
|
JSONArray bd = new JSONArray();//表数据拼接
|
|
|
|
List<Object> alldatas = new ArrayList<>();
|
|
|
|
JSONArray alldatas = new JSONArray();//表格数据拼接
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < datas.size(); i++) {
|
|
|
|
//循环考核任务或标题
|
|
|
|
|
|
|
|
for (int i = 0; i < datas.length(); i++) {
|
|
|
|
JSONObject jobj = (JSONObject) datas.get(i);
|
|
|
|
JSONObject jobj = (JSONObject) datas.get(i);
|
|
|
|
String type = jobj.getString("type");
|
|
|
|
String type = jobj.getString("type");
|
|
|
|
String title = jobj.getString("title");
|
|
|
|
String title = jobj.getString("title");
|
|
|
|
|
|
|
|
String erjiPyTitle = PinYinUtil.getPinyinInitials(title);
|
|
|
|
|
|
|
|
BigDecimal zb = null;
|
|
|
|
|
|
|
|
if (jobj.has("zb")) {
|
|
|
|
|
|
|
|
zb = jobj.getBigDecimal("zb");
|
|
|
|
|
|
|
|
}
|
|
|
|
//如果有子集就遍历
|
|
|
|
//如果有子集就遍历
|
|
|
|
if (type.equals("0")) {
|
|
|
|
if (type.equals("0")) {
|
|
|
|
JSONArray data2 = jobj.getJSONArray("data");
|
|
|
|
JSONArray data2 = jobj.getJSONArray("data");
|
|
|
|
BigDecimal zb = jobj.getBigDecimal("zb");
|
|
|
|
//递归获取下一级数据
|
|
|
|
Map<String, Object> childmap = parseJson(data2,title);
|
|
|
|
Map<String, Object> childmap = parseJson(data2, title,zb);
|
|
|
|
JSONObject head = (JSONObject) childmap.get("head");
|
|
|
|
JSONObject head = (JSONObject) childmap.get("head");
|
|
|
|
btchildren.add(head);
|
|
|
|
JSONObject defen = new JSONObject();
|
|
|
|
|
|
|
|
defen.put("name", erjiPyTitle + "_df");
|
|
|
|
|
|
|
|
defen.put("label", "得分");
|
|
|
|
|
|
|
|
JSONObject zb1 = new JSONObject();
|
|
|
|
|
|
|
|
zb1.put("name", erjiPyTitle + "_zb");
|
|
|
|
|
|
|
|
zb1.put("label", "占比");
|
|
|
|
|
|
|
|
JSONObject zsfs = new JSONObject();
|
|
|
|
|
|
|
|
zsfs.put("name", erjiPyTitle + "_zsfs");
|
|
|
|
|
|
|
|
zsfs.put("label", "折算分数");
|
|
|
|
|
|
|
|
btchildren.put(head);
|
|
|
|
|
|
|
|
btchildren.put(defen);
|
|
|
|
|
|
|
|
btchildren.put(zb1);
|
|
|
|
|
|
|
|
btchildren.put(zsfs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray alldatas1 = (JSONArray) childmap.get("alldatas");
|
|
|
|
|
|
|
|
//循环改变内部层级关系
|
|
|
|
|
|
|
|
for (Object tabledatum : alldatas1) {
|
|
|
|
|
|
|
|
JSONObject obj = (JSONObject) tabledatum;
|
|
|
|
|
|
|
|
JSONObject yiji = new JSONObject();
|
|
|
|
|
|
|
|
yiji.put(erjiPyTitle, obj.get(erjiPyTitle));
|
|
|
|
|
|
|
|
|
|
|
|
} else if (type.equals("1")) { //引用占比考核任务
|
|
|
|
|
|
|
|
Long pcId = jobj.getLong("id");
|
|
|
|
|
|
|
|
BigDecimal zb = jobj.getBigDecimal("zb");
|
|
|
|
|
|
|
|
KhKhrwResult khrwResult = new KhKhrwResult();
|
|
|
|
yiji.put(erjiPyTitle + "_df", title_zsfs);
|
|
|
|
khrwResult.setPcId(pcId);
|
|
|
|
if (z_zb != null) { //如果传递过来的标题占比不为null
|
|
|
|
//获取考核任务结果
|
|
|
|
BigDecimal erjizsfs = z_zb.multiply(title_zsfs);
|
|
|
|
List<KhKhrwResult> khrw = khKhrwResultService.selectKhKhrwResultList(khrwResult);
|
|
|
|
yiji.put(erjiPyTitle + "_zb", z_zb);
|
|
|
|
if(khrw!=null&&khrw.size()>0){
|
|
|
|
yiji.put(erjiPyTitle + "_zsfs", erjizsfs);
|
|
|
|
JSONArray tableHeader = JSONArray.parse(khrw.get(0).getTableHeader());
|
|
|
|
|
|
|
|
JSONObject head1 = new JSONObject();
|
|
|
|
|
|
|
|
JSONObject head2 = new JSONObject();
|
|
|
|
|
|
|
|
btKhdx=tableHeader.getJSONObject(0);//下标0 单位/姓名
|
|
|
|
|
|
|
|
head1=tableHeader.getJSONObject(1); //整体数据
|
|
|
|
|
|
|
|
head2=tableHeader.getJSONObject(2);//得分
|
|
|
|
|
|
|
|
btchildren.add(head1);
|
|
|
|
|
|
|
|
btchildren.add(head2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
JSONArray tabledata = JSONArray.parse(khrw.get(0).getTableData());
|
|
|
|
|
|
|
|
alldatas.addAll(tabledata);
|
|
|
|
|
|
|
|
} else { //引用不占比考核任务
|
|
|
|
obj.remove(erjiPyTitle);//删除原来的数据项
|
|
|
|
|
|
|
|
obj.put(pyTitle, yiji);
|
|
|
|
|
|
|
|
tabledatum = obj;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
alldatas.putAll(alldatas1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { //引用考核任务
|
|
|
|
Long pcId = jobj.getLong("id");
|
|
|
|
Long pcId = jobj.getLong("id");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String khrwName = jobj.getString("title");
|
|
|
|
|
|
|
|
String pykhrwName = PinYinUtil.getPinyinInitials(khrwName);
|
|
|
|
KhKhrwResult khrwResult = new KhKhrwResult();
|
|
|
|
KhKhrwResult khrwResult = new KhKhrwResult();
|
|
|
|
khrwResult.setPcId(pcId);
|
|
|
|
khrwResult.setPcId(pcId);
|
|
|
|
|
|
|
|
//获取考核任务结果
|
|
|
|
List<KhKhrwResult> khrw = khKhrwResultService.selectKhKhrwResultList(khrwResult);
|
|
|
|
List<KhKhrwResult> khrw = khKhrwResultService.selectKhKhrwResultList(khrwResult);
|
|
|
|
if (khrw != null && khrw.size() > 0) {
|
|
|
|
if (khrw != null && khrw.size() > 0) {
|
|
|
|
JSONArray tableHeader = JSONArray.parse(khrw.get(0).getTableHeader());
|
|
|
|
//----------组合表头数据---------
|
|
|
|
JSONObject head1 = new JSONObject();
|
|
|
|
JSONArray tableHeader = new JSONArray(khrw.get(0).getTableHeader());
|
|
|
|
JSONObject head2 = new JSONObject();
|
|
|
|
|
|
|
|
btKhdx = tableHeader.getJSONObject(0);//下标0 单位/姓名
|
|
|
|
btKhdx = tableHeader.getJSONObject(0);//下标0 单位/姓名
|
|
|
|
head1=tableHeader.getJSONObject(1); //整体数据
|
|
|
|
JSONObject head1 = tableHeader.getJSONObject(1); //整体数据
|
|
|
|
head2=tableHeader.getJSONObject(2);//得分
|
|
|
|
JSONObject head2 = tableHeader.getJSONObject(2);//得分
|
|
|
|
btchildren.add(head1);
|
|
|
|
btchildren.put(head1);
|
|
|
|
btchildren.add(head2);
|
|
|
|
btchildren.put(head2);
|
|
|
|
|
|
|
|
if (zb != null) { //当考核任务不占比时
|
|
|
|
|
|
|
|
JSONObject head3 = new JSONObject(); //占比
|
|
|
|
|
|
|
|
head3.put("name", pykhrwName + "_zb");
|
|
|
|
|
|
|
|
head3.put("label", "占比");
|
|
|
|
|
|
|
|
JSONObject head4 = new JSONObject(); //折算分数
|
|
|
|
|
|
|
|
head4.put("name", pykhrwName + "_zsfs");
|
|
|
|
|
|
|
|
head4.put("label", "折算分数");
|
|
|
|
|
|
|
|
btchildren.put(head3);
|
|
|
|
|
|
|
|
btchildren.put(head4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------组合表格数据------------------------------------------------
|
|
|
|
|
|
|
|
JSONArray tabledata = new JSONArray(khrw.get(0).getTableData());
|
|
|
|
|
|
|
|
String pinyinKhrw = PinYinUtil.getPinyinInitials(khrwName);
|
|
|
|
|
|
|
|
for (Object tabledatum : tabledata) {
|
|
|
|
|
|
|
|
JSONObject obj = (JSONObject) tabledatum;
|
|
|
|
|
|
|
|
JSONObject erji = new JSONObject();
|
|
|
|
|
|
|
|
erji.put(pinyinKhrw, obj.get(pinyinKhrw));
|
|
|
|
|
|
|
|
erji.put(pinyinKhrw + "_df", obj.get(pinyinKhrw + "_df"));
|
|
|
|
|
|
|
|
if (zb != null) {
|
|
|
|
|
|
|
|
BigDecimal zsfs = zb.multiply((BigDecimal) obj.get(pinyinKhrw + "_df"));
|
|
|
|
|
|
|
|
erji.put(pinyinKhrw + "_zb", zb);
|
|
|
|
|
|
|
|
erji.put(pinyinKhrw + "_zsfs", zsfs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.remove(pinyinKhrw);//删除原来的数据项
|
|
|
|
|
|
|
|
obj.remove(pinyinKhrw + "_df");//删除原来的得分
|
|
|
|
|
|
|
|
obj.put(pyTitle, erji);
|
|
|
|
|
|
|
|
tabledatum = obj;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
alldatas.putAll(tabledata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
JSONArray tabledata = JSONArray.parse(khrw.get(0).getTableData());
|
|
|
|
|
|
|
|
alldatas.addAll(tabledata);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
btTitle.put("children", btchildren);
|
|
|
|
btTitle.put("children", btchildren);
|
|
|
|
result.put("head", btTitle);
|
|
|
|
result.put("head", btTitle);
|
|
|
|
result.put("data", bd);
|
|
|
|
result.put("data", bd);
|
|
|
|
|
|
|
|
result.put("alldatas", alldatas);
|
|
|
|
result.put("btKhdx", btKhdx);
|
|
|
|
result.put("btKhdx", btKhdx);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*{
|
|
|
|
/*
|
|
|
|
"title": "教学单位领导班子考核总分",
|
|
|
|
{"title":"教学单位领导班子考核总分","data":[{"zb":0.9,"type":"0","title":"二级单位目标管理与绩效考核成绩","data":[{"type":"1","title":"党建与行政目标任务","id":1,"zb":0.1},{"type":"1","title":"事业发展","id":6,"zb":0.9}]},{"type":"1","title":"民主测评","id":2,"zb":0.3},{"type":"2","title":"创新","id":7}]}
|
|
|
|
"data": [
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": "0",
|
|
|
|
|
|
|
|
"title": "二级单位目标管理与绩效考核成绩",
|
|
|
|
|
|
|
|
"data": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": 1,
|
|
|
|
|
|
|
|
"title": "党建与行政目标任务",
|
|
|
|
|
|
|
|
"id": 1,
|
|
|
|
|
|
|
|
"zb": 0.1
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": "1",
|
|
|
|
|
|
|
|
"title": "事业发展",
|
|
|
|
|
|
|
|
"id": 4,
|
|
|
|
|
|
|
|
"zb": 0.9
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": "1",
|
|
|
|
|
|
|
|
"title": "民主测评",
|
|
|
|
|
|
|
|
"id": 2,
|
|
|
|
|
|
|
|
"zb": 0.3
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": "1",
|
|
|
|
|
|
|
|
"title": "创新",
|
|
|
|
|
|
|
|
"id": 5
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询生成汇总列表
|
|
|
|
* 查询生成汇总列表
|
|
|
|
|