数据源改造

数据源改造前

jarr: [{
	"schId": 112100,
	"idType": 1,
	"yearIn": 17,
	"_id": "1_112100_17",
	"kpSets": [{
		"kpSetId": 16,
		"xkId": 1
	}, {
		"kpSetId": 11,
		"xkId": 2
	}, {
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": 11,
		"xkId": 4
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": 11,
		"xkId": 6
	}, {
		"kpSetId": 16,
		"xkId": 7
	}, {
		"kpSetId": 11,
		"xkId": 8
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}, {
	"schId": 112100,
	"idType": 1,
	"yearIn": 16,
	"_id": "1_112100_16",
	"kpSets": [{
		"kpSetId": 11,
		"xkId": 1
	}, {
		"kpSetId": 11,
		"xkId": 2
	}, {
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": 11,
		"xkId": 4
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}, {
	"schId": 112100,
	"idType": 1,
	"yearIn": 15,
	"_id": "1_112100_15",
	"kpSets": [{
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": 11,
		"xkId": 6
	}, {
		"kpSetId": 11,
		"xkId": 7
	}, {
		"kpSetId": 11,
		"xkId": 8
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}]

数据源改造后

newJarr: [{
	"schId": 112100,
	"yearIn": 17,
	"kpSets": [{
		"kpSetId": 16,
		"xkId": 1
	}, {
		"kpSetId": 11,
		"xkId": 2
	}, {
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": 11,
		"xkId": 4
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": 11,
		"xkId": 6
	}, {
		"kpSetId": 16,
		"xkId": 7
	}, {
		"kpSetId": 11,
		"xkId": 8
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}, {
	"schId": 112100,
	"yearIn": 16,
	"kpSets": [{
		"kpSetId": 11,
		"xkId": 1
	}, {
		"kpSetId": 11,
		"xkId": 2
	}, {
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": 11,
		"xkId": 4
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": "",
		"xkId": 6
	}, {
		"kpSetId": "",
		"xkId": 7
	}, {
		"kpSetId": "",
		"xkId": 8
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}, {
	"schId": 112100,
	"yearIn": 15,
	"kpSets": [{
		"kpSetId": "",
		"xkId": 1
	}, {
		"kpSetId": "",
		"xkId": 2
	}, {
		"kpSetId": 11,
		"xkId": 3
	}, {
		"kpSetId": "",
		"xkId": 4
	}, {
		"kpSetId": 11,
		"xkId": 5
	}, {
		"kpSetId": 11,
		"xkId": 6
	}, {
		"kpSetId": 11,
		"xkId": 7
	}, {
		"kpSetId": 11,
		"xkId": 8
	}, {
		"kpSetId": 11,
		"xkId": 9
	}]
}]

处理逻辑

@Controller
@RequestMapping("sch")
public class SchKpAbSetController extends VOController{

	
	
	/**
	 * 
	    * @Title: getSchKpSets
	    * @Description: 获取指定学校知识点体系信息
	    * @param schId
	    * @param request
	    * @return    参数
	    * @return JSONObject
	    * @throws
	 */
	@RequestMapping(value="/kpSet/list/{schId}",method=RequestMethod.GET)
	@ResponseBody
	public JSONObject getSchKpSet( 
					@PathVariable(value="schId") Long schId,
					HttpServletRequest  request ){

		try{
			JSONArray newJarr = gerNewKpJarr(schId);
			return getSuccessResult( newJarr );
		}catch(Exception e){
			return getErrorResult("系统异常,请稍后重试.");
		}
	}
	
	
	
	public JSONArray gerNewKpJarr(Long schId) throws Exception{
		
		JSONArray jarr = new JSONArray();
		QryDomainFilter filter = new QryDomainFilter();
		StatCustom statCustom = new StatCustomImpl();
		filter.setIndex( IndexBox.INDEX_BASE_BUSINESS_OBJECT );
		filter.setTypes( BBOConst.BBO_SCH_KP_SET );
		filter.setSelect("*");
		filter.setCondition( "schId="+ schId );
		//filter.setOrderBy("yearIn");
		jarr= statCustom.getStat(filter);
		JSONArray newJarr = new JSONArray();
		for(int i = 0; i < jarr.size(); i++){
			JSONObject yearInObj = new JSONObject();
			JSONObject obj1 = new JSONObject();
			obj1 = jarr.getJSONObject(i);
			yearInObj.put("schId", obj1.getIntValue("schId"));
			yearInObj.put("yearIn", obj1.getIntValue("yearIn"));
			JSONArray jarr1 = new JSONArray();
			jarr1 = obj1.getJSONArray("kpSets");
			JSONArray jarr2 = new JSONArray();
			for(int j = 1; j < 10; j++ ){
				JSONObject obj2 = new JSONObject();
				for(int k = 0; k < jarr1.size(); k++){
					obj2 = new JSONObject();
					obj2 = jarr1.getJSONObject(k);
					if(obj2.getIntValue("xkId") == j){
						break;
					}	
				}
				if(obj2.getIntValue("xkId") == j){
					jarr2.add(obj2);
				}else{
					obj2 = new JSONObject();
					obj2.put("kpSetId", "");
					obj2.put("xkId", j);
					jarr2.add(obj2);
				}
				
			}
			yearInObj.put("kpSets", jarr2);
			newJarr.add(yearInObj);
		}
		return newJarr;
	}

页面展示代码

    <table class="table table-bordered table-hover kpSet_list sd_tbl">
    </table>


<script id="kpSet_list_trail" type="text/template">
    <thead>
        <tr>
            <th>学校编号</th>
            <th>学级</th>
            <th>语文</th>
            <th>数学</th>
			<th>英语</th>
            <th>物理</th>
            <th>化学</th>
            <th>历史</th>
            <th>地理</th>
            <th>政治</th>
            <th>生物</th>
        </tr>
    </thead>
    <tbody>
        <%_.each(data, function(d){%>
            <tr>
                <td><%=d.schId%></td>
                <td><%=d.yearIn%></td>
              	<%_.each(d.kpSets, function(kp){%>
					<td><%=kp.kpSetId%></td>
				<%})%>
            </tr>     
        <%})%>
    </tbody>
</script>
<!--班级选择项 -->

<script>

    var  schId = $.url().param('sid');
    //控制real类型教师信息的展现
    var InitData = function(){

        function loadTchs(tchGid){
            if( schId == null){
                $('.kpSet_list').html('<tr><td>没有检索到数据.</td></tr>');
                return false;
            } 
            //获取数据
            var url = "../sch/kpSet/list/"+schId;
            var temp = '#kpSet_list_trail';
            $('.kpSet_list').zxtable({
                url: url,
                template: temp,
                needDataTable: true,
                orderby: [  [1, 'desc'] ],
                fixedHeader: false,   
            });

         
        }
        return {
            init: function(){
                loadTchs();   
            },
            loadTchs: function(tchGid){
                loadTchs( tchGid);
            }
        }
    }();

  
    InitData.init();


</script>

页面效果



猜你喜欢

转载自blog.csdn.net/qq_24192465/article/details/79928637