|
|
|
|
@ -2,14 +2,10 @@ package com.ruoyi.kaohe.controller;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
|
import com.ruoyi.common.utils.LogUtils;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
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;
|
|
|
|
|
@ -59,7 +55,7 @@ public class KhGatherController extends BaseController {
|
|
|
|
|
*/
|
|
|
|
|
//@PreAuthorize("@ss.hasPermi('kaohe:gather:list')")
|
|
|
|
|
@PostMapping("/generateSum")
|
|
|
|
|
public AjaxResult generateSum(@RequestBody String json) {
|
|
|
|
|
public AjaxResult generateSum(@RequestBody String json) throws JsonProcessingException {
|
|
|
|
|
// 将String转换为JSONObject
|
|
|
|
|
JSONObject jsonObject = new JSONObject(json);
|
|
|
|
|
String hz_name = jsonObject.getString("title");
|
|
|
|
|
@ -83,29 +79,35 @@ public class KhGatherController extends BaseController {
|
|
|
|
|
|
|
|
|
|
//获取并整合数据
|
|
|
|
|
JSONArray tabledata = new JSONArray((JSONArray) nodes.get("alldatas"));
|
|
|
|
|
JSONArray erjiTtitle_df = new JSONArray((JSONArray) nodes.get("title_df"));
|
|
|
|
|
tabledata.putAll(erjiTtitle_df);
|
|
|
|
|
//根据被考核对象名分组数据到map中 得到表格内容的最终数据
|
|
|
|
|
JSONArray endTableData = JsonDeepMerge.mergeByKey(tabledata, "khdx");
|
|
|
|
|
/* KhGather gather = new KhGather();
|
|
|
|
|
|
|
|
|
|
KhGather gather = new KhGather();
|
|
|
|
|
gather.setHzName(hz_name);
|
|
|
|
|
gather.setTableHeader(header.toString(2));
|
|
|
|
|
gather.setTableData(endTableData.toString(2));
|
|
|
|
|
khGatherService.insertKhGather(gather);*/
|
|
|
|
|
khGatherService.insertKhGather(gather);
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归解析json
|
|
|
|
|
*
|
|
|
|
|
* @param datas
|
|
|
|
|
* @param titleP
|
|
|
|
|
* @param z_zb
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Object> parseJson(JSONArray datas, String titleP,BigDecimal z_zb) {
|
|
|
|
|
private Map<String, Object> parseJson(JSONArray datas, String titleP, BigDecimal z_zb) throws JsonProcessingException {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
BigDecimal title_zsfs=BigDecimal.ZERO;
|
|
|
|
|
JSONArray endtTitle_df = new JSONArray();//存储标题占比时的得分
|
|
|
|
|
JSONArray title_df = new JSONArray();//处理标题占比时的得分
|
|
|
|
|
String pyTitle = PinYinUtil.getPinyinInitials(titleP);//父级表头
|
|
|
|
|
JSONObject btKhdx = new JSONObject();
|
|
|
|
|
JSONObject btTitle = new JSONObject();
|
|
|
|
|
JSONObject btKhdx = new JSONObject(true); //表头考核对象存储
|
|
|
|
|
JSONObject btTitle = new JSONObject(true);
|
|
|
|
|
btTitle.put("name", pyTitle);
|
|
|
|
|
btTitle.put("label", titleP);
|
|
|
|
|
JSONArray btchildren = new JSONArray();
|
|
|
|
|
@ -129,52 +131,65 @@ public class KhGatherController extends BaseController {
|
|
|
|
|
//递归获取下一级数据
|
|
|
|
|
Map<String, Object> childmap = parseJson(data2, title, zb);
|
|
|
|
|
JSONObject head = (JSONObject) childmap.get("head");
|
|
|
|
|
JSONObject defen = new JSONObject();
|
|
|
|
|
JSONObject defen = new JSONObject(true);
|
|
|
|
|
defen.put("name", erjiPyTitle + "_df");
|
|
|
|
|
defen.put("label", "得分");
|
|
|
|
|
JSONObject zb1 = new JSONObject();
|
|
|
|
|
JSONObject zb1 = new JSONObject(true);
|
|
|
|
|
zb1.put("name", erjiPyTitle + "_zb");
|
|
|
|
|
zb1.put("label", "占比");
|
|
|
|
|
JSONObject zsfs = new JSONObject();
|
|
|
|
|
JSONObject zsfs = new JSONObject(true);
|
|
|
|
|
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");
|
|
|
|
|
JSONArray title_df1 = (JSONArray) childmap.get("title_df");
|
|
|
|
|
/*if(title_df1==null){//代表它下面还是标题,没有数据 多级标题的
|
|
|
|
|
BigDecimal erjidf = BigDecimal.ZERO;
|
|
|
|
|
JSONObject outsideTitle = new JSONObject();
|
|
|
|
|
JSONObject newDf = new JSONObject();
|
|
|
|
|
newDf.put(erjiPyTitle+"_df", erjidf);
|
|
|
|
|
if (z_zb != null) { //如果传递过来的标题占比不为null
|
|
|
|
|
BigDecimal erjizsfs = z_zb.multiply(erjidf);
|
|
|
|
|
newDf.put(erjiPyTitle + "_zb", z_zb);
|
|
|
|
|
newDf.put(erjiPyTitle + "_zsfs", erjizsfs);
|
|
|
|
|
}
|
|
|
|
|
outsideTitle.put(pyTitle,newDf);
|
|
|
|
|
title_df.put(outsideTitle);
|
|
|
|
|
}else{*/
|
|
|
|
|
JSONArray title_df_cl = new JSONArray(JsonDeepMerge.jsonGroupSum(title_df1, "khdx", erjiPyTitle + "_df"));
|
|
|
|
|
//循环处理后的标题得分 加上层级及 占比、折算分数
|
|
|
|
|
for (Object df : title_df_cl) {
|
|
|
|
|
JSONObject dfobj = (JSONObject) df;
|
|
|
|
|
BigDecimal erjidf = dfobj.getBigDecimal(erjiPyTitle + "_df");
|
|
|
|
|
JSONObject newDf = new JSONObject();
|
|
|
|
|
newDf.put(erjiPyTitle + "_df", erjidf);
|
|
|
|
|
if (zb != null) { //如果传递过来的标题占比不为null
|
|
|
|
|
BigDecimal erjizsfs = zb.multiply(erjidf);
|
|
|
|
|
newDf.put(erjiPyTitle + "_zb", zb);
|
|
|
|
|
newDf.put(erjiPyTitle + "_zsfs", erjizsfs);
|
|
|
|
|
}
|
|
|
|
|
dfobj.remove(erjiPyTitle + "_df");//删除原来的数据项
|
|
|
|
|
dfobj.put(pyTitle, newDf);//删除原来的数据项
|
|
|
|
|
df = dfobj;
|
|
|
|
|
}
|
|
|
|
|
title_df=title_df_cl;
|
|
|
|
|
|
|
|
|
|
//循环改变内部层级关系
|
|
|
|
|
for (Object tabledatum : alldatas1) {
|
|
|
|
|
JSONObject obj = (JSONObject) tabledatum;
|
|
|
|
|
JSONObject yiji = new JSONObject();
|
|
|
|
|
JSONObject yiji = new JSONObject(true);
|
|
|
|
|
yiji.put(erjiPyTitle, obj.get(erjiPyTitle));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yiji.put(erjiPyTitle + "_df", title_zsfs);
|
|
|
|
|
if (z_zb != null) { //如果传递过来的标题占比不为null
|
|
|
|
|
BigDecimal erjizsfs = z_zb.multiply(title_zsfs);
|
|
|
|
|
yiji.put(erjiPyTitle + "_zb", z_zb);
|
|
|
|
|
yiji.put(erjiPyTitle + "_zsfs", erjizsfs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj.remove(erjiPyTitle);//删除原来的数据项
|
|
|
|
|
obj.put(pyTitle, yiji);
|
|
|
|
|
tabledatum = obj;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
alldatas.putAll(alldatas1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { //引用考核任务
|
|
|
|
|
Long pcId = jobj.getLong("id");
|
|
|
|
|
|
|
|
|
|
@ -193,27 +208,42 @@ public class KhGatherController extends BaseController {
|
|
|
|
|
btchildren.put(head1);
|
|
|
|
|
btchildren.put(head2);
|
|
|
|
|
if (zb != null) { //当考核任务不占比时
|
|
|
|
|
JSONObject head3 = new JSONObject(); //占比
|
|
|
|
|
JSONObject head3 = new JSONObject(true); //占比
|
|
|
|
|
head3.put("name", pykhrwName + "_zb");
|
|
|
|
|
head3.put("label", "占比");
|
|
|
|
|
JSONObject head4 = new JSONObject(); //折算分数
|
|
|
|
|
JSONObject head4 = new JSONObject(true); //折算分数
|
|
|
|
|
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();
|
|
|
|
|
JSONObject erji = new JSONObject(true);
|
|
|
|
|
erji.put(pinyinKhrw, obj.get(pinyinKhrw));
|
|
|
|
|
erji.put(pinyinKhrw + "_df", obj.get(pinyinKhrw + "_df"));
|
|
|
|
|
if (zb != null) {
|
|
|
|
|
if (zb != null) { //代表当前引用考核任务有占比
|
|
|
|
|
BigDecimal zsfs = zb.multiply((BigDecimal) obj.get(pinyinKhrw + "_df"));
|
|
|
|
|
erji.put(pinyinKhrw + "_zb", zb);
|
|
|
|
|
erji.put(pinyinKhrw + "_zsfs", zsfs);
|
|
|
|
|
if (z_zb != null) {//代表上一级标题有占比
|
|
|
|
|
JSONObject khdx = new JSONObject();
|
|
|
|
|
khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称
|
|
|
|
|
khdx.put(pyTitle + "_df", zsfs);//存储当前考核对象最后折算分数
|
|
|
|
|
title_df.put(khdx);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (z_zb != null) {//代表上一级标题有占比
|
|
|
|
|
title_df.put(obj.getJSONObject("khdx"));//
|
|
|
|
|
JSONObject khdx = new JSONObject();
|
|
|
|
|
khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称
|
|
|
|
|
khdx.put(pyTitle + "_df", obj.get(pinyinKhrw + "_df"));///存储当前考核对象最后折算分数
|
|
|
|
|
title_df.put(khdx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
obj.remove(pinyinKhrw);//删除原来的数据项
|
|
|
|
|
obj.remove(pinyinKhrw + "_df");//删除原来的得分
|
|
|
|
|
@ -224,11 +254,14 @@ public class KhGatherController extends BaseController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btTitle.put("children", btchildren);
|
|
|
|
|
result.put("head", btTitle);
|
|
|
|
|
result.put("data", bd);
|
|
|
|
|
result.put("alldatas", alldatas);
|
|
|
|
|
result.put("btKhdx", btKhdx);
|
|
|
|
|
result.put("title_df", title_df);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|