多级标题嵌套数据纠正

main 29
hshansha 5 months ago
parent d463d7e592
commit 8ce8bc668f

@ -76,23 +76,23 @@ public class KhGatherController extends BaseController {
newChildren.put(oldchild); newChildren.put(oldchild);
} }
JSONObject zongfen = new JSONObject(); JSONObject zongfen = new JSONObject();
zongfen.put("name", pyhz_name +"_df"); zongfen.put("name", pyhz_name + "_df");
zongfen.put("label","总分"); zongfen.put("label", "总分");
newChildren.put(zongfen); newChildren.put(zongfen);
head.put("children", newChildren); head.put("children", newChildren);
header.put(head); header.put(head);
//获取并整合数据 //获取并整合数据
JSONArray tabledata = new JSONArray((JSONArray) nodes.get("alldatas")); JSONArray tabledata = new JSONArray((JSONArray) nodes.get("alldatas"));
JSONArray hz_df = new JSONArray((JSONArray) nodes.get("hz_df")); JSONArray hz_df = new JSONArray((JSONArray) nodes.get("title_df"));
for (Object zf : hz_df) { for (Object zf : hz_df) {
JSONObject chulizf = (JSONObject) zf; JSONObject chulizf = (JSONObject) zf;
BigDecimal yijidf = chulizf.getBigDecimal(pyhz_name + "_df"); BigDecimal yijidf = chulizf.getBigDecimal(pyhz_name + "_df");
JSONObject newDf = new JSONObject(); JSONObject newDf = new JSONObject();
newDf.put(pyhz_name + "_df", yijidf); newDf.put(pyhz_name + "_df", yijidf);
chulizf.put(pyhz_name,newDf); chulizf.put(pyhz_name, newDf);
chulizf.remove(pyhz_name+"_df"); chulizf.remove(pyhz_name + "_df");
zf=chulizf; zf = chulizf;
} }
tabledata.putAll(hz_df); tabledata.putAll(hz_df);
//根据被考核对象名分组数据到map中 得到表格内容的最终数据 //根据被考核对象名分组数据到map中 得到表格内容的最终数据
@ -139,7 +139,7 @@ public class KhGatherController extends BaseController {
if (jobj.has("zb")) { if (jobj.has("zb")) {
zb = jobj.getBigDecimal("zb"); zb = jobj.getBigDecimal("zb");
} }
//如果是标题-------------------------------------------------------------- //标题--------------------------------------------------------------
if (type.equals("0")) { if (type.equals("0")) {
JSONArray data2 = jobj.getJSONArray("data"); JSONArray data2 = jobj.getJSONArray("data");
//递归获取下一级数据 //递归获取下一级数据
@ -162,19 +162,20 @@ public class KhGatherController extends BaseController {
JSONArray alldatas1 = (JSONArray) childmap.get("alldatas"); JSONArray alldatas1 = (JSONArray) childmap.get("alldatas");
JSONArray title_df1 = (JSONArray) childmap.get("title_df"); JSONArray title_df1 = (JSONArray) childmap.get("title_df");
if(title_df1==null){//代表它下面还是标题,没有数据 多级标题的 btKhdx = (JSONObject) childmap.get("btKhdx");
if (title_df1 == null) {//代表它下面还是标题,没有数据 多级标题的
BigDecimal erjidf = BigDecimal.ZERO; BigDecimal erjidf = BigDecimal.ZERO;
JSONObject outsideTitle = new JSONObject(); JSONObject outsideTitle = new JSONObject();
JSONObject newDf = new JSONObject(); JSONObject newDf = new JSONObject();
newDf.put(erjiPyTitle+"_df", erjidf); newDf.put(erjiPyTitle + "_df", erjidf);
if (z_zb != null) { //如果传递过来的标题占比不为null if (z_zb != null) { //如果传递过来的标题占比不为null
BigDecimal erjizsfs = z_zb.multiply(erjidf); BigDecimal erjizsfs = z_zb.multiply(erjidf);
newDf.put(erjiPyTitle + "_zb", z_zb); newDf.put(erjiPyTitle + "_zb", z_zb);
newDf.put(erjiPyTitle + "_zsfs", erjizsfs); newDf.put(erjiPyTitle + "_zsfs", erjizsfs);
} }
outsideTitle.put(pyTitle,newDf); outsideTitle.put(pyTitle, newDf);
title_df1.put(outsideTitle); title_df1.put(outsideTitle);
}else { } else {
//循环处理后的标题得分 加上层级及 占比、折算分数 //循环处理后的标题得分 加上层级及 占比、折算分数
for (Object df : title_df1) { for (Object df : title_df1) {
JSONObject dfobj = (JSONObject) df; JSONObject dfobj = (JSONObject) df;
@ -183,34 +184,30 @@ public class KhGatherController extends BaseController {
newDf.put(erjiPyTitle + "_df", erjidf); newDf.put(erjiPyTitle + "_df", erjidf);
BigDecimal erjizsfs = BigDecimal.ZERO; BigDecimal erjizsfs = BigDecimal.ZERO;
if (zb != null) { //如果标题占比不为null if (zb != null) { //如果标题占比不为null
erjizsfs= zb.multiply(erjidf); erjizsfs = zb.multiply(erjidf);
newDf.put(erjiPyTitle + "_zb", zb); newDf.put(erjiPyTitle + "_zb", zb);
newDf.put(erjiPyTitle + "_zsfs", erjizsfs); newDf.put(erjiPyTitle + "_zsfs", erjizsfs);
} }
//存储最外层需要的得分数据 //标题递归来得分数据按格式 //{"khdx":"",pyTitle _df:defen}存储到title_df中
if(z_zb==null){ //只有最外层标题没有占比 JSONObject hzdf = new JSONObject();
JSONObject hzdf = new JSONObject(); hzdf.put("khdx", dfobj.get("khdx"));
hzdf.put("khdx",dfobj.get("khdx")); if (zb != null) {
if(zb != null){ hzdf.put(pyTitle + "_df", erjizsfs);
hzdf.put(pyTitle + "_df", erjizsfs); } else {
}else{ hzdf.put(pyTitle + "_df", erjidf);
hzdf.put(pyTitle + "_df", erjidf);
}
title_df.put(hzdf);
} }
title_df.put(hzdf);
dfobj.remove(erjiPyTitle + "_df");//删除原来的数据项 dfobj.remove(erjiPyTitle + "_df");//删除原来的数据项
dfobj.put(pyTitle, newDf);//删除原来的数据项 dfobj.put(pyTitle, newDf);//删除原来的数据项
df = dfobj; df = dfobj;//更改df结构添加外层主题嵌套 如:{"khdx":"",pyTitle:{erjiPyTitle_df:defen}}
} }
alldatas.putAll(title_df1); alldatas.putAll(title_df1);
} }
//循环改变内部层级关系 //循环改变内部层级关系
for (Object tabledatum : alldatas1) { for (Object tabledatum : alldatas1) {
JSONObject obj = (JSONObject) tabledatum; JSONObject obj = (JSONObject) tabledatum;
@ -234,9 +231,7 @@ public class KhGatherController extends BaseController {
if (khrw != null && khrw.size() > 0) { if (khrw != null && khrw.size() > 0) {
//----------组合表头数据--------- //----------组合表头数据---------
JSONArray tableHeader = new JSONArray(khrw.get(0).getTableHeader()); JSONArray tableHeader = new JSONArray(khrw.get(0).getTableHeader());
if(z_zb==null){ //最外层总站比为null btKhdx = tableHeader.getJSONObject(0);//下标0 单位/姓名
btKhdx = tableHeader.getJSONObject(0);//下标0 单位/姓名
}
JSONObject head1 = tableHeader.getJSONObject(1); //整体数据 JSONObject head1 = tableHeader.getJSONObject(1); //整体数据
JSONObject head2 = tableHeader.getJSONObject(2);//得分 JSONObject head2 = tableHeader.getJSONObject(2);//得分
btchildren.put(head1); btchildren.put(head1);
@ -266,17 +261,17 @@ public class KhGatherController extends BaseController {
erji.put(pinyinKhrw + "_zsfs", zsfs); erji.put(pinyinKhrw + "_zsfs", zsfs);
//获取上一级标题得分数组 //获取上一级标题得分数组
JSONObject khdx = new JSONObject(); JSONObject khdx = new JSONObject();
khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称 khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称
khdx.put(pyTitle + "_df", zsfs);//存储当前考核对象最后折算分数 khdx.put(pyTitle + "_df", zsfs);//存储当前考核对象最后折算分数
title_df.put(khdx); title_df.put(khdx); //{"khdx":"",pyTitle _df:defen}
} else { //当前考核任务无占比 上面只存储了得分 } else { //当前考核任务无占比 上面只存储了得分
//获取上一级标题得分数组 //获取上一级标题得分数组
JSONObject khdx = new JSONObject(); JSONObject khdx = new JSONObject();
khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称 khdx.put("khdx", obj.get("khdx"));//存储当前考核对象名称
khdx.put(pyTitle + "_df", obj.get(pinyinKhrw + "_df"));///存储当前考核对象最后得分 khdx.put(pyTitle + "_df", obj.get(pinyinKhrw + "_df"));///存储当前考核对象最后得分
title_df.put(khdx); title_df.put(khdx); //{"khdx":"",pyTitle _df:defen}
} }
obj.remove(pinyinKhrw);//删除原来的数据项 obj.remove(pinyinKhrw);//删除原来的数据项
obj.remove(pinyinKhrw + "_df");//删除原来的得分 obj.remove(pinyinKhrw + "_df");//删除原来的得分
@ -287,21 +282,14 @@ public class KhGatherController extends BaseController {
} }
} }
} }
title_df = new JSONArray(JsonDeepMerge.jsonGroupSum(title_df, "khdx", pyTitle + "_df")); title_df = new JSONArray(JsonDeepMerge.jsonGroupSum(title_df, "khdx", pyTitle + "_df"));
if(z_zb==null){
hz_df.putAll(title_df);
}
// title_df.putAll(title_df);
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("alldatas", alldatas);
result.put("title_df", title_df); result.put("title_df", title_df);
result.put("btKhdx", btKhdx); result.put("btKhdx", btKhdx);
result.put("hz_df", hz_df);
return result; return result;
} }

Loading…
Cancel
Save