java数据处理与展现


java数据处理与展现_第1张图片

样板


源数据

ja: [{
	"orgStuNum": 1372,
	"yearIn": 15,
	"kpStuAvg": 0.08,
	"examDate": 1453219200000,
	"kpLostPer": 0.0844,
	"paperName": "育才_15_07_期末_英语_20160120",
	"kpId": 1130021,
	"kpName": "物主代词",
	"schStuNum": 616,
	"kpQids": [{
		"realId": "43_0",
		"realTopicName": "单项选择",
		"qid_qcId": "43_0"
	}],
	"termId": 1,
	"orgId": 280951,
	"xkName": "英语",
	"_id": "2001472115909607_280951_280010_3_1130021",
	"kpAcq": 564.0,
	"schId": 280010,
	"kpLostStuPer": 0.0844,
	"examId": 2001472115909607,
	"kpLost": 52.0,
	"orgAlias": "成都七中育才 ",
	"examName": "七中育才_期末考试_20160120",
	"examGradeName": "七年级",
	"schName": "成都七中育才学校本部",
	"paperId": 1111111280011026,
	"paperEScore": 0.0,
	"kpLostStuNum": 52,
	"xkId": 3,
	"orgName": "成都七中育才 ",
	"kpPaperScore": 616.0,
	"paperScore": 150.0,
	"examGradeId": 7,
	"kpLostStuAvg": 1.0,
	"examSort": 3,
	"schAlias": "育才本部",
	"examType": 5
},


第一次处理

 public JSONObject getStatOrgKp(Long orgId, Long examId, Integer xkId) throws Exception {
        // 确定type
        String type = OrgConst.STAT_ORG_KP;
        // fields
        String fields = "*";
        // condition
        String condition = "orgId=" + orgId + " and examId=" + examId + " and xkId= " + xkId;
        // filter
        QryDomainFilter filter = new QryDomainFilter();
        filter.setIndex(index);
        filter.setTypes(type);
        filter.setSelect(fields);
        filter.setCondition(condition);
        // query
        JSONArray ja = new JSONArray();
        try {
            ja = statCustom.getStat(filter);
        } catch (Exception e) {
            throw e;
        }

        if (ja == null || ja.isEmpty()) {
            return new JSONObject();
        }

        // jo{kpId:{},...}
        JSONObject jo = new JSONObject();
        for (int i = 0; i < ja.size(); i++) {
            JSONObject _jo = ja.getJSONObject(i);
            String kpId = _jo.getString("kpId");
            jo.put(kpId, _jo);
        }
        return jo;

    }


public JSONObject getStatSchKp(Long orgId, Long examId, Integer xkId) throws Exception {
        // 确定type
        String type = OrgConst.STAT_SCH_KP;
        // fields
        String fields = "*";
        // condition
        String condition = "orgId=" + orgId + " and examId=" + examId + " and xkId= " + xkId;
        // filter
        QryDomainFilter filter = new QryDomainFilter();
        filter.setIndex(index);
        filter.setTypes(type);
        filter.setSelect(fields);
        filter.setCondition(condition);
        // query
        JSONArray ja = new JSONArray();
        try {
            ja = statCustom.getStat(filter);
        } catch (Exception e) {
            throw e;
        }

        if (ja == null || ja.isEmpty()) {
            return new JSONObject();
        }
        
        System.out.println("ja: "+ja.toJSONString());

        // jo{"schId":{kpId:{}},...}
        JSONObject jo = new JSONObject();
        for (int i = 0; i < ja.size(); i++) {
            JSONObject _jo = ja.getJSONObject(i);
            String schIdKey = _jo.getString("schId");
            String kpId = _jo.getString("kpId");
            if (!jo.containsKey(schIdKey))
                jo.put(schIdKey, new JSONObject());
            jo.getJSONObject(schIdKey).put(kpId, _jo);

        }
        return jo;
    }


第一次处理结果

orgKpData: {
	"1153069": {
		"orgStuNum": 1347,
		"yearIn": 14,
		"kpStuAvg": 1.31,
		"examDate": 1496160000000,
		"paperName": "七中育才_14_09_月考_化学_20170531",
		"kpLostPer": 0.3287,
		"kpId": 1153069,
		"kpName": "水的组成",
		"kpQids": [{
			"realId": "19_0",
			"realTopicName": "填空题",
			"qid_qcId": "19_0"
		}],
		"termId": 2,
		"orgId": 280951,
		"xkName": "化学",
		"_id": "2001496195562171_280951_5_1153069",
		"kpAcq": 3617.0,
		"kpLostStuPer": 0.8612,
		"examId": 2001496195562171,
		"kpLost": 1771.0,
		"orgAlias": "成都七中育才 ",
		"examName": "七中育才_月考_20170531",
		"examGradeName": "九年级",
		"paperId": 1001496195562175,
		"paperEScore": 0.0,
		"kpLostStuNum": 1160,
		"xkId": 5,
		"orgName": "成都七中育才 ",
		"kpPaperScore": 5388.0,
		"paperScore": 100.0,
		"examGradeId": 9,
		"kpLostStuAvg": 1.53,
		"examSort": 3,
		"examType": 2
	},


schKpData: {
	"280010": {
		"1153069": {
			"orgStuNum": 1347,
			"yearIn": 14,
			"kpStuAvg": 1.04,
			"examDate": 1496160000000,
			"kpLostPer": 0.2607,
			"paperName": "七中育才_14_09_月考_化学_20170531",
			"kpId": 1153069,
			"kpName": "水的组成",
			"schStuNum": 617,
			"kpQids": [{
				"realId": "19_0",
				"realTopicName": "填空题",
				"qid_qcId": "19_0"
			}],
			"termId": 2,
			"orgId": 280951,
			"xkName": "化学",
			"_id": "2001496195562171_280951_280010_5_1153069",
			"kpAcq": 1824.66,
			"schId": 280010,
			"kpLostStuPer": 0.812,
			"examId": 2001496195562171,
			"kpLost": 643.34,
			"orgAlias": "成都七中育才 ",
			"examName": "七中育才_月考_20170531",
			"examGradeName": "九年级",
			"schName": "成都七中育才学校水井坊",
			"paperId": 1001496195562175,
			"paperEScore": 0.0,
			"kpLostStuNum": 501,
			"xkId": 5,
			"orgName": "成都七中育才 ",
			"kpPaperScore": 2468.0,
			"paperScore": 100.0,
			"examGradeId": 9,
			"kpLostStuAvg": 1.28,
			"examSort": 3,
			"schAlias": "七中育才水井坊",
			"examType": 2
		},


核心实现方法

private JSONObject getData(String index, BBOOrg org, BEOExam exam, Integer xkId) throws Exception {
        OrgEAO eao = new OrgEAOImpl(index);

        JSONObject orgKpData = eao.getStatOrgKp(org.getOrgId(), exam.getExamId(), xkId);
        if ((orgKpData == null) || (orgKpData.isEmpty())) {
            return new JSONObject();
        }
        JSONObject schKpData = eao.getStatSchKp(org.getOrgId(), exam.getExamId(), xkId);
        
        JSONObject schs = getSchool(schKpData);
         
        Long[] kpIds = getKpIds(orgKpData);
        
        JSONObject kpTrees = getKpTrees(kpIds);
        
        if (kpIds[0] == -xkId){
        	
        	JSONObject jo = new JSONObject();
        	
        	kpTrees.put(kpIds[0].toString(), jo);
        	jo.put("kpId", kpIds[0]);
        	jo.put("kpName", "未配置知识点");
        	jo.put("childs", new JSONObject());
        }
        

        JSONArray kpIdsJa = Long2Ja(kpIds);
        double paperScore = 0.0D;
        for (String key : orgKpData.keySet()) {
            paperScore = orgKpData.getJSONObject(key).getDoubleValue("paperScore");
        }
        JSONArray data = prepare_data(schs, orgKpData, schKpData, kpTrees, kpIdsJa);
        JSONObject jo = new JSONObject();
        jo.put("paperScore", Double.valueOf(paperScore));
        jo.put("data", data);
        return jo;
    }

第二次处理

 protected Long[] getKpIds(JSONObject orgKpData) {
        Long[] kpIds = new Long[orgKpData.size()];
        int i = 0;
        for (String kpId : orgKpData.keySet()) {
            kpIds[(i++)] = Long.valueOf(Long.parseLong(kpId));
        }
        Arrays.sort(kpIds);
        return kpIds;
    }

结果

kpIds: [-5, 1105303, 1105316, 1105318, 1153026, 1153044, 1153045, 1153069, 1153070, 1153082, 1153100, 1153118, 1153129, 1153139, 1153147, 1153153, 1153171, 1153172, 1153183, 1153187, 1153196]


第三次处理

    private JSONObject getKpTrees(Long[] kpIds) throws Exception {
    	
        BxoEAO bxo = new BxoEAOImpl();
        JSONObject bsoKps = bxo.getBSOKp(kpIds);
        JSONObject kpLevels = getKpLevels(bsoKps, bxo);
        
        
        return kpLevels;
    }


结果

bsoKps: {
	"1153147": {
		"kpCode": 53147,
		"kpId": 1153147,
		"kpName": "化合价的求法",
		"kpPid": 1105315,
		"kpSetId": 11,
		"position": 4,
		"xkId": 5
	},
	"1153172": {
		"kpCode": 53172,
		"kpId": 1153172,
		"kpName": "燃烧、缓慢氧化和爆炸",
		"kpPid": 1105319,
		"kpSetId": 11,
		"position": 3,
		"xkId": 5
	},
	"1153069": {
		"kpCode": 53069,
		"kpId": 1153069,
		"kpName": "水的组成",
		"kpPid": 1105307,
		"kpSetId": 11,
		"position": 1,
		"xkId": 5
	},
	"1153171": {
		"kpCode": 53171,
		"kpId": 1153171,
		"kpName": "灭火的原理和方法",
		"kpPid": 1105319,
		"kpSetId": 11,
		"position": 2,
		"xkId": 5
	},


第四次处理

private JSONObject getKpLevels(JSONObject bsoKps, BxoEAO bxo) throws Exception {
    	
        JSONObject tree = new JSONObject();
        for (String kpId : bsoKps.keySet()) {
        	//kpId =    1113088;
            BSOKP bsoKp = (BSOKP) bsoKps.getObject(kpId, BSOKP.class);
         // bsoKp = "1113088":{"kpCode":13088,"kpId":1113088,"kpName":"说明文重点词句段的分析与理解",
                    //"kpPid":1101314,"kpSetId":11,"position":8,"xkId":1},
            String kpCode = bsoKp.getKpCode().toString();
            
            
            // kpCode = 13088
            String kpName = bsoKp.getKpName();
            if (kpCode.length() == 5) {
                JSONObject kp3Obj = new JSONObject();
                kp3Obj.put("kpId", Long.valueOf(Long.parseLong(kpId)));
                kp3Obj.put("kpName", kpName);
         //  kp3Obj = {"kpId":1113088,"kpName":说明文重点词句段的分析与理解}
                Long kpId2 = bsoKp.getKpPid();
             //kpId2 = 1101314
                BSOKP kpLevel2 = bxo.getBSOKp(kpId2);
                // kpLevel2 = {"position":2,"kpCode":1314,"_id":"1101314","kpId":1101314,
                             //"kpSetId":11,"xkId":1,"kpName":"说明文阅读","kpPid":1100133}]
                String kpName2 = kpLevel2.getKpName();   

                
                
              // kpName2 = 说明文阅读
                Long kpId1 = kpLevel2.getKpPid();
                //kpId1 = 1100133
                BSOKP kpLevel1 = bxo.getBSOKp(kpId1);
                //kpLevel1 =  {"position":3,"kpCode":133,"_id":"1100133","kpId":1100133,"kpSetId":11,
                             //"xkId":1,"kpName":"现代文阅读理解及鉴赏","kpPid":0}]
                String kpName1 = kpLevel1.getKpName();
                //判断tree里是否包含kpId1
                if (!tree.containsKey(kpId1.toString())) {
                    tree.put(kpId1.toString(), new JSONObject());
                    tree.getJSONObject(kpId1.toString()).put("kpId", kpId1);
                    tree.getJSONObject(kpId1.toString()).put("kpName", kpName1);
                    tree.getJSONObject(kpId1.toString()).put("childs", new JSONObject());
                }
                //判断第二层对象的孩子对象是否包含kpId2
                if (!tree.getJSONObject(kpId1.toString()).getJSONObject("childs").containsKey(kpId2.toString())) {
                    tree.getJSONObject(kpId1.toString()).getJSONObject("childs").put(kpId2.toString(), new JSONObject());

                    tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId2.toString()).put("kpId", kpId2);
                    tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId2.toString()).put("kpName", kpName2);
                    tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId2.toString()).put("childs", new JSONArray());
                }
                //向第二层的孩子添加第三层数据
                tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId2.toString()).getJSONArray("childs").add(kp3Obj);
            } else if (kpCode.length() == 4) {
            	
                BSOKP kpLevel2 = bxo.getBSOKp(Long.valueOf(Long.parseLong(kpId)));
                Long kpId1 = kpLevel2.getKpPid();
                String kpName1 = kpLevel2.getKpName();
                if (!tree.containsKey(kpId1.toString()))
                {
                  tree.put(kpId1.toString(), new JSONObject());
                  tree.getJSONObject(kpId1.toString()).put("childs", new JSONObject());
                  
                  tree.getJSONObject(kpId1.toString()).put("kpName", kpName1);
                  tree.getJSONObject(kpId1.toString()).put("kpId", kpId1);
                }
                if (!tree.getJSONObject(kpId1.toString()).getJSONObject("childs").containsKey(kpId))
                {
                  tree.getJSONObject(kpId1.toString()).getJSONObject("childs").put(kpId.toString(), new JSONObject());
                  
                  tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId.toString()).put("childs", new JSONArray());
                  tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId.toString()).put("kpId", kpId);
                  tree.getJSONObject(kpId1.toString()).getJSONObject("childs").getJSONObject(kpId.toString()).put("kpName", kpName);
                }

            } else if (!tree.containsKey(kpId)) {
                tree.put(kpId.toString(), new JSONObject());
                tree.getJSONObject(kpId.toString()).put("childs", new JSONObject());

                tree.getJSONObject(kpId.toString()).put("kpName", kpName);
                tree.getJSONObject(kpId.toString()).put("kpId", kpId);
            }
        }
        return tree;
    }


结果

tree: {
	"1100131": {
		"kpId": 1100131,
		"childs": {
			"1101303": {
				"kpId": 1101303,
				"childs": [{
					"kpId": 1113020,
					"kpName": "熟语(歇后语,谚语等)及其使用"
				}, {
					"kpId": 1113019,
					"kpName": "成语及其使用"
				}],
				"kpName": "词语"
			},
			"1101304": {
				"kpId": 1101304,
				"childs": [{
					"kpId": 1113040,
					"kpName": "表意不明病句"
				}, {
					"kpId": 1113221,
					"kpName": "病句辨析及修改"
				}, {
					"kpId": 1113222,
					"kpName": "选用、仿用、变换句式"
				}],
				"kpName": "句子"
			},
			"1101301": {
				"kpId": 1101301,
				"childs": [{
					"kpId": 1113008,
					"kpName": "常用字"
				}, {
					"kpId": 1113005,
					"kpName": "习惯性误读字"
				}, {
					"kpId": 1113001,
					"kpName": "常见字"
				}],
				"kpName": "拼音与汉字"
			}
		},
		"kpName": "基础积累及运用"
	},

第五次处理

  private JSONArray Long2Ja(Long[] kpIds) {
        JSONArray ja = new JSONArray();
        for (int i = 0; i < kpIds.length; i++) {
            ja.add(kpIds[i]);
        }
        return ja;
    }

结果

kpIdsJa: [-5,1105303,1105316,1105318,1153026,1153044,1153045,1153069,1153070,1153082,1153100,1153118,1153129,1153139,1153147,1153153,1153171,1153172,1153183,1153187,1153196]


第六次处理

private JSONArray prepare_data(JSONObject schs, JSONObject orgKpData, JSONObject schKpData, JSONObject kpTrees, JSONArray kpIds) throws Exception {
    	

        JSONArray datas = new JSONArray();
        JSONArray schIds = schs.getJSONArray("schIds");

        
        
        Long[] kps1 = getKpIds(kpTrees);
        for (int i = 0; i < kps1.length; i++) {
            JSONObject data = new JSONObject();

            String kpId1 = kps1[i].toString();
            JSONObject kpInfos = kpTrees.getJSONObject(kpId1);
            String kpName = kpInfos.getString("kpName");

            data.put("kpName", kpName);
            data.put("kpId", kps1[i]);
            data.put("levels", "1");
            if (kpIds.contains(kps1[i])) {
                addData(orgKpData, schIds, schKpData, schs, kpId1, data);
            }
            JSONArray data2s = new JSONArray();

            Long[] kps2 = getKpIds(kpInfos.getJSONObject("childs"));
            for (int j = 0; j < kps2.length; j++) {
                JSONObject data2 = new JSONObject();
                String kpId2 = kps2[j].toString();
                JSONObject kp2Info = kpInfos.getJSONObject("childs").getJSONObject(kpId2);
                String kp2Name = kp2Info.getString("kpName");
                data2.put("kpId", kps2[j]);
                data2.put("kpName", kp2Name);
                data2.put("levels", "2");
                if (kpIds.contains(kps2[j])) {
                    addData(orgKpData, schIds, schKpData, schs, kpId2, data2);
                }
                JSONArray data3s = new JSONArray();
                JSONArray kp3Infos = kp2Info.getJSONArray("childs");
                for (int k = 0; k < kp3Infos.size(); k++) {
                    JSONObject data3 = new JSONObject();
                    Long kpId3 = kp3Infos.getJSONObject(k).getLong("kpId");
                    String kp3Name = kp3Infos.getJSONObject(k).getString("kpName");
                    data3.put("kpId", kpId3);
                    data3.put("kpName", kp3Name);
                    data3.put("levels", "3");

                    addData(orgKpData, schIds, schKpData, schs, kpId3.toString(), data3);
                    data3s.add(data3);
                }
                data2.put("childs", data3s);
                data2s.add(data2);
            }
            data.put("childs", data2s);
            datas.add(data);
        }
        return datas;
    }
 private void addData(JSONObject orgKpData, JSONArray schIds, JSONObject schKpData, JSONObject schs, String kpId, JSONObject data) throws Exception {
        JSONObject _orgKpData = orgKpData.getJSONObject(kpId);

        double kpScorePer = calKpScorePer(_orgKpData);

        double orgGetScorePer = 1.0D - _orgKpData.getDouble("kpLostPer").doubleValue();
        orgGetScorePer = Utils.mydouble(orgGetScorePer, BOConst.NUM_FOUR);

        data.put("kpScorePer", Double.valueOf(kpScorePer));
        data.put("orgGetScorePer", Double.valueOf(orgGetScorePer));

        JSONArray schInfos = new JSONArray();
        for (int j = 0; j < schIds.size(); j++) {
            JSONObject schInfo = new JSONObject();
            String schId = schIds.getString(j);
            JSONObject _schKpData = schKpData.getJSONObject(schId);
            JSONObject _schKpData1 = _schKpData.getJSONObject(kpId);
          
 
            String schName = schs.getString(schId);
            double schGetScorePer = 1.0D - _schKpData1.getDouble("kpLostPer").doubleValue();
            schGetScorePer = Utils.mydouble(schGetScorePer, BOConst.NUM_FOUR);
            schInfo.put("schId", Long.valueOf(Long.parseLong(schId)));
            schInfo.put("schGetScorePer", Double.valueOf(schGetScorePer));
            schInfo.put("schName", schName);
            schInfos.add(schInfo);
        }
        data.put("schDatas", schInfos);
    }
 /**
     * 
     * @Title: calKpScorePer
     * @Description: 计算知识点的分数占比
     * @param _orgKpData
     * @return double
     * @throws Exception
     *             参数
     * @return double
     * @throws
     */
    private double calKpScorePer(JSONObject _orgKpData) throws Exception {
        // 机构学生总数
        int orgStuNum = _orgKpData.getIntValue("orgStuNum");
        // 机构知识点总分
        double kpPaperScore = _orgKpData.getDouble("kpPaperScore");
        // 试卷卷面分数
        double paperScore = _orgKpData.getDouble("paperScore");

        double kpScorePer = kpPaperScore / (orgStuNum * paperScore);
        // 保留四位小数
        kpScorePer = Utils.mydouble(kpScorePer, BOConst.NUM_FOUR);
        return kpScorePer;

    }



结果

data1: {"levels":"1","kpId":1100535,"kpName":"化学与社会发展"}

data2: [{
	"orgGetScorePer": 1.0,
	"levels": "1",
	"kpId": -5,
	"childs": [],
	"kpName": "未配置知识点",
	"kpScorePer": 0.1,
	"schDatas": [{
		"schId": 280010,
		"schGetScorePer": 1.0,
		"schName": "七中育才水井坊"
	}, {
		"schId": 280011,
		"schGetScorePer": 1.0,
		"schName": "七中育才汇源"
	}, {
		"schId": 280015,
		"schGetScorePer": 1.0,
		"schName": "七中育才银杏"
	}]
}, {
	"levels": "1",
	"kpId": 1100531,
	"childs": [{
		"orgGetScorePer": 0.8566,
		"levels": "2",
		"kpId": 1105303,
		"childs": [{
			"orgGetScorePer": 0.8324,
			"levels": "3",
			"kpId": 1153026,
			"kpName": "S/Fe/C/P等物质在氧气中的燃烧",
			"kpScorePer": 0.05,
			"schDatas": [{
				"schId": 280010,
				"schGetScorePer": 0.8802,
				"schName": "七中育才水井坊"
			}, {
				"schId": 280011,
				"schGetScorePer": 0.9136,
				"schName": "七中育才汇源"
			}, {
				"schId": 280015,
				"schGetScorePer": 0.6579,
				"schName": "七中育才银杏"
			}]
		}],
		"kpName": "常见实验",
		"kpScorePer": 0.12,
		"schDatas": [{
			"schId": 280010,
			"schGetScorePer": 0.9253,
			"schName": "七中育才水井坊"
		}, {
			"schId": 280011,
			"schGetScorePer": 0.8699,
			"schName": "七中育才汇源"
		}, {
			"schId": 280015,
			"schGetScorePer": 0.7197,
			"schName": "七中育才银杏"
		}]
	}, {
		"levels": "2",
		"kpId": 1105327,
		"childs": [{
			"orgGetScorePer": 0.7746,
			"levels": "3",
			"kpId": 1153044,
			"kpName": "设计实验方案、观察实验现象、填写实验报告",
			"kpScorePer": 0.085,
			"schDatas": [{
				"schId": 280010,
				"schGetScorePer": 0.8347,
				"schName": "七中育才水井坊"
			}, {
				"schId": 280011,
				"schGetScorePer": 0.8204,
				"schName": "七中育才汇源"
			}, {
				"schId": 280015,
				"schGetScorePer": 0.6172,
				"schName": "七中育才银杏"
			}]
		}, {
			"orgGetScorePer": 0.7625,
			"levels": "3",
			"kpId": 1153045,
			"kpName": "化学实验方案的设计与评价",
			"kpScorePer": 0.115,
			"schDatas": [{
				"schId": 280010,
				"schGetScorePer": 0.8339,
				"schName": "七中育才水井坊"
			}, {
				"schId": 280011,
				"schGetScorePer": 0.7801,
				"schName": "七中育才汇源"
			}, {
				"schId": 280015,
				"schGetScorePer": 0.6163,
				"schName": "七中育才银杏"
			}]
		}],
		"kpName": "科学探究能力"
	}],
	"kpName": "科学探究"
}, 


最终返回到前台数据

jo: {
	"paperScore": 100.0,
	"data": [{
		"orgGetScorePer": 1.0,
		"levels": "1",
		"kpId": -5,
		"childs": [],
		"kpName": "未配置知识点",
		"kpScorePer": 0.1,
		"schDatas": [{
			"schId": 280010,
			"schGetScorePer": 1.0,
			"schName": "七中育才水井坊"
		}, {
			"schId": 280011,
			"schGetScorePer": 1.0,
			"schName": "七中育才汇源"
		}, {
			"schId": 280015,
			"schGetScorePer": 1.0,
			"schName": "七中育才银杏"
		}]
	}, {
		"levels": "1",
		"kpId": 1100531,
		"childs": [{
			"orgGetScorePer": 0.8566,
			"levels": "2",
			"kpId": 1105303,
			"childs": [{
				"orgGetScorePer": 0.8324,
				"levels": "3",
				"kpId": 1153026,
				"kpName": "S/Fe/C/P等物质在氧气中的燃烧",
				"kpScorePer": 0.05,
				"schDatas": [{
					"schId": 280010,
					"schGetScorePer": 0.8802,
					"schName": "七中育才水井坊"
				}, {
					"schId": 280011,
					"schGetScorePer": 0.9136,
					"schName": "七中育才汇源"
				}, {
					"schId": 280015,
					"schGetScorePer": 0.6579,
					"schName": "七中育才银杏"
				}]
			}],
			"kpName": "常见实验",
			"kpScorePer": 0.12,
			"schDatas": [{
				"schId": 280010,
				"schGetScorePer": 0.9253,
				"schName": "七中育才水井坊"
			}, {
				"schId": 280011,
				"schGetScorePer": 0.8699,
				"schName": "七中育才汇源"
			}, {
				"schId": 280015,
				"schGetScorePer": 0.7197,
				"schName": "七中育才银杏"
			}]
		}, {
			"levels": "2",
			"kpId": 1105327,
			"childs": [{
				"orgGetScorePer": 0.7746,
				"levels": "3",
				"kpId": 1153044,
				"kpName": "设计实验方案、观察实验现象、填写实验报告",
				"kpScorePer": 0.085,
				"schDatas": [{
					"schId": 280010,
					"schGetScorePer": 0.8347,
					"schName": "七中育才水井坊"
				}, {
					"schId": 280011,
					"schGetScorePer": 0.8204,
					"schName": "七中育才汇源"
				}, {
					"schId": 280015,
					"schGetScorePer": 0.6172,
					"schName": "七中育才银杏"
				}]
			}, {
				"orgGetScorePer": 0.7625,
				"levels": "3",
				"kpId": 1153045,
				"kpName": "化学实验方案的设计与评价",
				"kpScorePer": 0.115,
				"schDatas": [{
					"schId": 280010,
					"schGetScorePer": 0.8339,
					"schName": "七中育才水井坊"
				}, {
					"schId": 280011,
					"schGetScorePer": 0.7801,
					"schName": "七中育才汇源"
				}, {
					"schId": 280015,
					"schGetScorePer": 0.6163,
					"schName": "七中育才银杏"
				}]
			}],
			"kpName": "科学探究能力"
		}],
		"kpName": "科学探究"
	},


前台对以上数据处理并展示

 var renderRptTable = function() { 

                    $('.xk_change').change(function(){
                        xkId=$('.xk_change').find('option:selected').val();
                        var url='../../../rpt/single/rpt2027/tbl/'+exam.uid+'/'+exam.examId+'/'+xkId;
                        table_change(url);
                    });
                    table_change('../../../rpt/single/rpt2027/tbl/'+exam.uid+'/'+exam.examId+'/'+$('.xk_change').find('option:selected').val());
                    //获取数据
                    function table_change(url){

                        ZX.getDataByAjax(
                        url,
                        'json',
                        function(data){
                            if(data == null || data.length == 0 || _.isEmpty(data[0]) || data[0].data.length == 0){
                                $('.kp1_kp2_sel').addClass('hidden');
                                $('.rpt_table tbody').html('没有检索到数据.');
                                //判断dom节点是否被datatable了
                                if ($.fn.DataTable.isDataTable($('.rpt_table'))) { 
                                    //构建datatable的dom对象进行销毁
                                    $('.rpt_table').DataTable().destroy(true); 
                                    //销毁后 dom也会一并销毁,此处需要还原dom节点
                                    $('.page-content').append('
'); } $.zxtloading.close(); }else{ $('.kp1_kp2_sel').removeClass('hidden'); // var data = {}; var kp_all_table = []; _.each(data[0].data,function(item,index){ if(item.schDatas != null && item.schDatas!= undefined){ var kp1 ={}; kp1['name1'] = item.kpName; kp1['schDatas'] = item.schDatas; kp1['orgGetScorePer'] = item.orgGetScorePer; kp1['kpScorePer'] = item.kpScorePer; kp_all_table.push(kp1); }; if(item.childs!=null && item.childs!=undefined ){ _.each(item.childs,function(one){ if(one.schDatas != null && one.schDatas!= undefined){ var kp2 ={}; kp2['name1'] = item.kpName; kp2['name2'] = one.kpName; kp2['schDatas'] = one.schDatas; kp2['orgGetScorePer'] = one.orgGetScorePer; kp2['kpScorePer'] = one.kpScorePer; kp_all_table.push(kp2); }; if(one.childs!=null && one.childs!=undefined ){ _.each(one.childs,function(io){ if(io.schDatas != null && io.schDatas!= undefined){ var kp3 ={}; kp3['name1'] = item.kpName; kp3['name2'] = one.kpName; kp3['name3'] = io.kpName; kp3['schDatas'] = io.schDatas; kp3['orgGetScorePer'] = io.orgGetScorePer; kp3['kpScorePer'] = io.kpScorePer; kp_all_table.push(kp3); }; }) } }); } }); var heads = ["一级知识点","二级知识点","三级知识点","分数占比","区得分率"]; _.each(kp_all_table[0].schDatas,function(item){ heads.push(item.schName) });


处理结果

java数据处理与展现_第2张图片


数据导出

java数据处理与展现_第3张图片


核心代码

package cn.doofen.udr.bo.single.impl;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.util.CellRangeAddress;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zxt.framework.export.RptExcelDomain;
import com.zxt.framework.utils.PropertiesConfigUtils;

import cn.doofen.udr.UDRBaseConfig;
import cn.doofen.udr.UDRBaseConst;
import cn.doofen.udr.bo.single.ISingleBo;
import cn.doofen.udr.controller.UDRBaseParam;
import cn.doofen.udr.utils.Unit2Utils;
/**
 * 
    * @Package cn.doofen.udr.bo.single.impl
    * @ClassName: Rpt2027Bo
    * @Description: rpt2027的业务接口  单学科知识点得分率
    * @author Leesin
    * @date 2016年11月29日
    *
 */
public class Rpt2027Bo extends SingleBoImpl implements ISingleBo{
    private static final String DSI_EXT_RPT_TBL_2027 = PropertiesConfigUtils.getString("dsi.ext.rpt.tbl.2027");
	
	private static final String DSI_EXT_RPT_CHART_2027 = PropertiesConfigUtils.getString("dsi.ext.rpt.chart.2027");
	
	/**
	 * 
	    * @Title: loadViewData
	    * @Description: 获取页面table数据
	    * @param param 参数
	    * @return    参数
	    * @return JSONObject
	    * @throws
	 */
	public JSONArray loadTblData(UDRBaseParam param) throws Exception {
		JSONObject uparam = new JSONObject();
		uparam.put("orgId", param.getOrgId());
		uparam.put("examId", param.getExamId());
		uparam.put("xkId", param.getXkId());
		//uparam.put("stuId", stuId);
		JSONArray ja=new JSONArray();
		JSONObject jo=null;
		if( UDRBaseConfig.SYS_DEBUG ){
			Unit2Utils u2u = new Unit2Utils();
			jo=u2u.getTestJSONObject("rpt27data.txt");
			ja.add(jo);
			
		}else{
			String url	= getHttpDSIRestUri4Report( DSI_EXT_RPT_TBL_2027);
			JSONObject rjo =  httpRestGet( url, uparam.toString(), null );
			
			if( rjo != null && !rjo.isEmpty() && rjo.getBooleanValue("success") == true){
				jo= rjo.getJSONObject("data");
				ja.add(jo);
			}else{
				if( rjo != null && !rjo.isEmpty() ){
					throw new Exception("Load chart data failed, beacause : " +rjo.getString("error"));
				}else{
					throw new Exception("Load chart data failed, beacause dsi response is null.");
				}
			}
		}
		return ja;
	}

	/**
	 * 
	    * @Title: loadChartData
	    * @Description: 获取页面chart的数据
	    * @param param
	    * @return    参数
	    * @return JSONObject
	    * @throws
	 */
	public  JSONArray loadChartData( UDRBaseParam param) throws Exception {
		
		JSONObject uparam = new JSONObject();
		uparam.put("orgId", param.getOrgId());
		uparam.put("examId", param.getExamId());
		uparam.put("xkId", param.getXkId());
		//uparam.put("stuId", stuId);
		JSONArray ja=new JSONArray();
		JSONObject jo=null;
		if( UDRBaseConfig.SYS_DEBUG ){
			Unit2Utils u2u = new Unit2Utils();
			 jo=u2u.getTestJSONObject("rpt27data.txt");
			ja.add(jo);
			
		}else{
			String url	= getHttpDSIRestUri4Report( DSI_EXT_RPT_CHART_2027 );
			JSONObject rjo =  httpRestGet( url, uparam.toString(), null );
			if( rjo != null && !rjo.isEmpty() && rjo.getBooleanValue("success") == true){
				jo= rjo.getJSONObject("data");
				ja.add(jo);
			}else{
				if( rjo != null && !rjo.isEmpty() ){
					throw new Exception("Load chart data failed, beacause : " +rjo.getString("error"));
				}else{
					throw new Exception("Load chart data failed, beacause dsi response is null.");
				}
			}
		}
		return ja;
	}

	/**
	 * 
	    * @Title: loadChartData
	    * @Description: 导出Excel
	    * @param param
	    * @return    参数
	    * @return JSONObject
	    * @throws
	 */
	public  void exportExcel( 
					HttpServletRequest request,
					HttpServletResponse response,
					UDRBaseParam param)  throws Exception{
		//输出表格的头部名称
		Unit2Utils unit2=new Unit2Utils();
		String xkName=unit2.excelXKChange(param.getXkId());
		String title = UDRBaseConst.RPT_2027_NAME ;
		String logo=PropertiesConfigUtils.getString("logo")+SHEET_TITLE;
		OutputStream os = null;
		try{
		os = response.getOutputStream();
		//获取数据
		JSONObject jo =loadTblData(param).getJSONObject(0);
		RptExcelDomain rptDo = new RptExcelDomain();
		rptDo.setSheetName( logo+title);
		rptDo.setSheetTitle( logo+title +","+xkName);
		//所有数据的JSONArray
		JSONArray ja = new JSONArray();
		ja.add( jo);
		rptDo.setSheetData( ja);
		List sheets = new ArrayList();
		sheets.add( rptDo);
		setSheets( sheets);
		//写入数据
		writeExcel(os,true);
		}
		catch( Exception e){
			e.printStackTrace();
		}finally{
			if (os != null ) os.close();
		}	
	}
	
	
	/**
	 * 重载excel创建
	 *
	 */
	  protected void writeExcelSheetSelf(RptExcelDomain rptDomain)
	  {
	    HSSFSheet sheet = wb.createSheet(rptDomain.getSheetName());

	    sheet.setColumnWidth(0, 5400);

	    HSSFRow row = null;

	    JSONArray datas = rptDomain.getSheetData();
	    JSONArray before = datas.getJSONObject(0).getJSONArray("data");

	    JSONArray newdata = new JSONArray();
	    for (int i = 0; i < before.size(); i++) {
	      JSONObject it = before.getJSONObject(i);
	      if (it.getJSONArray("schDatas") != null) {
	        JSONObject one = new JSONObject();
	        if(it.getString("kpName") != null){
	        	 one.put("kpName1", it.getString("kpName"));
           }else{
           		one.put("kpNam1", "");
           }
	        one.put("kpName2", "");
	        one.put("kpName3", "");
	        one.put("kpScorePer", it.getDouble("kpScorePer"));
	        one.put("orgGetScorePer", it.getDouble("orgGetScorePer"));
	        one.put("schDatas", it.getJSONArray("schDatas"));
	        newdata.add(one);
	      } 
	      
	      //else {
	    	if(it.getJSONArray("childs") != null){
	    		
	    		JSONArray childs = it.getJSONArray("childs");
		        for (int j = 0; j < childs.size(); j++) {
		          JSONObject it2 = childs.getJSONObject(j);
		          if (it2.getJSONArray("schDatas") != null) {
		            JSONObject one2 = new JSONObject();
		            one2.put("kpName1", it.getString("kpName"));
		            if(it2.getString("kpName") != null){
		            	 one2.put("kpName2", it2.getString("kpName"));
	                }else{
	                	one2.put("kpNam2", "");
	                }
		            one2.put("kpName3", "");
		            one2.put("kpScorePer", it2.getDouble("kpScorePer"));
		            one2.put("orgGetScorePer", it2.getDouble("orgGetScorePer"));
		            one2.put("schDatas", it2.getJSONArray("schDatas"));
		            newdata.add(one2);
		          }
		          //else {
		          
		          if(it2.getJSONArray("childs") != null){
		        	  
		        	  JSONArray childs2 = it2.getJSONArray("childs");
			            for (int k = 0; k < childs2.size(); k++) {
			              JSONObject it3 = childs2.getJSONObject(k);
			              if (it3.getJSONArray("schDatas") != null) {
			                JSONObject one3 = new JSONObject();
			                one3.put("kpName1", it.getString("kpName"));
			                one3.put("kpName2", it2.getString("kpName"));
			                if(it3.getString("kpName") != null){
			                	one3.put("kpName3", it3.getString("kpName"));
			                }else{
			                	one3.put("kpName3", "");
			                }
			                one3.put("kpScorePer", it3.getDouble("kpScorePer"));
			                one3.put("orgGetScorePer", it3.getDouble("orgGetScorePer"));
			                one3.put("schDatas", it3.getJSONArray("schDatas"));
			                newdata.add(one3);
			              }
			            }
		        	  
		          }
		          
		            
		         // }

		        }

		      }
	    		
	    	}  
	        

	   // }

	    JSONObject oneKP = newdata.getJSONObject(0);
	    JSONArray oneSchData = oneKP.getJSONArray("schDatas");
	    String[] schs = new String[oneSchData.size() + 5];
	    schs[0] = "一级知识点";
	    schs[1] = "二级知识点";
	    schs[2] = "三级知识点";
	    schs[3] = "分数占比";
	    schs[4] = "区得分率";
	    for (int i = 0; i < oneSchData.size(); i++)
	    {
	      schs[(i + 5)] = oneSchData.getJSONObject(i).getString("schName");
	    }

	    String str = rptDomain.getSheetTitle();
	    String[] strs = new String[2];
	    strs = str.split(",");
	    String head1 = strs[0];
	    String head2 = strs[1];

	    Integer xkMerg = Integer.valueOf(schs.length);

	    row = sheet.createRow(0);
	    row.setHeight((short)rptDomain.getSheetTitleHeight());

	    HSSFCell cell_title = row.createCell(0);

	    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, xkMerg.intValue() - 1));

	    cell_title.setCellStyle(getStyleTitle());
	    cell_title.setCellValue(head1);

	    row = sheet.createRow(1);

	    HSSFCell cell_title1 = row.createCell(0);
	    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, xkMerg.intValue() - 1));

	    cell_title1.setCellType(1);

	    cell_title1.setCellValue(head2);

	    HSSFCellStyle headerStyle = getStyleHeader();
	    row = sheet.createRow(2);
	    HSSFCell cell_header = null;
	    for (int i = 0; i < schs.length; i++) {
	      cell_header = row.createCell(i);
	      cell_header.setCellStyle(headerStyle);
	      cell_header.setCellType(1);
	      cell_header.setCellValue(schs[i]);
	    }

	    int startRow = 2;
	    for (int d = 0; d < newdata.size(); d++) {
	      startRow += 1;
	      row = sheet.createRow(startRow);
	      JSONObject _cellDatas = newdata.getJSONObject(d);
	      int offset = 0;
	      HSSFCell cell_Data = null;

	      for (int j = 0; j < _cellDatas.size(); j++)
	      {
	        cell_Data = row.createCell(j + offset);
	        if (j == 0) {
	          cell_Data.setCellValue(_cellDatas.getString("kpName1"));
	        }else if(j == 1){
	        	cell_Data.setCellValue(_cellDatas.getString("kpName2"));
	        }else if(j == 2){
	        	cell_Data.setCellValue(_cellDatas.getString("kpName3"));
	        } 
	        else if (j == 3) {
	          cell_Data.setCellValue(String.format("%.2f", new Object[] { Double.valueOf(_cellDatas.getDouble("kpScorePer").doubleValue() * 100.0D) }) + "%");
	        } else if (j == 4) {
	          cell_Data.setCellValue(String.format("%.2f", new Object[] { Double.valueOf(_cellDatas.getDouble("orgGetScorePer").doubleValue() * 100.0D) }) + "%");
	        } else {
	          JSONArray sch_data = _cellDatas.getJSONArray("schDatas");
	          for (int i = 0; i < sch_data.size(); i++)
	          {
	            cell_Data = row.createCell(j + i);
	            cell_Data.setCellValue(String.format("%.2f", new Object[] { Double.valueOf(sch_data.getJSONObject(i).getDouble("schGetScorePer").doubleValue() * 100.0D) }) + "%");
	            cell_Data.setCellStyle(getStyleCellBold());
	          }
	        }
	        cell_Data.setCellStyle(getStyleCellBold());
	      }
	    }
	  }

}

你可能感兴趣的:(web前端,java,java后台)