<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title> 学生单科成绩统计分析表</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />
<meta name="MobileOptimized" content="320">
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link rel="stylesheet" type="text/css" href="../../../assets/plugins/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="../../../assets/plugins/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../../assets/plugins/data-tables/dataTables.bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../../../assets/plugins/data-tables/css/fixedHeader.bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../../assets/css/report.css" />
<link rel="stylesheet" type="text/css" href="../../../assets/css/report_udr.css" />
</head>
<style>
body {
background: #fff !important;
padding: 5px;
overflow-x: hidden;
}
.search input{
width:50px;
}
.search2 input{
width:70px;
}
.red{
color:red;
}
.green{
color:green;
}
.table{
text-align: center;
}
.search{
margin-bottom: 20px;
}
.wrong{
position: absolute;
top:226px;
left:360px;
display: none;
}
.form-control{
width:120px;
display: inline-block;
}
th{
white-space: nowrap;
vertical-align: middle !important;
}
.btn{
margin-left: 20px;
}
</style>
<body>
<div class="rpt_header">
<h4 class="rpt_title"></h4>
<h4 class="rpt_title_ext"></h4>
</div>
<div class="page-container">
<div class="search">
<p class="range" style="text-align:center;font-size:18px;padding-top:10px;"></p>
请选择学科 :
<select class="select form-control">
<option selected value="1">语文</option>
<option value="2">数学</option>
<option value="3">英语</option>
<option value="4">物理</option>
<option value="5">化学</option>
<option value="6">历史</option>
<option value="7">地理</option>
<option value="8">政治</option>
<option value="9">生物</option>
</select>
请选择试卷类别 :
<select class="select1 form-control">
<option selected value="0">全卷</option>
<option value="1">A卷</option>
<option value="2">B卷</option>
</select>
<div class="wrong"><span style="padding:20px;color:#999;font-size:30px;">没有检索到数据.</span></div>
</div>
<div class="search2" style="margin-top: 10px;">
高线 : <input type="text" class="high form-control"/>
中线 : <input type="text" class="mid form-control"/>
<button type="button" class="btn btn-primary" style="margin-left: 30px">查询</button>
</div>
<div class="page-content" style="margin-left: 0px;">
<div class="rpt_chart" id="rptChart"></div>
<table class="table table-striped table-bordered table-hover rpt_table" align='center'>
</table>
</div>
</div>
<script type="text/javascript" src="../../../assets/lib/jquery-3.0.0.min.js"></script>
<script type="text/javascript" src="../../../assets/plugins/backbone/underscore.js"></script>
<script type="text/javascript" src="../../../assets/plugins/backbone/backbone.js"></script>
<script type="text/javascript" src="../../../assets/plugins/jquery.cookie.min.js"></script>
<script type="text/javascript" src="../../../assets/plugins/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="../../../assets/plugins/data-tables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../../assets/plugins/data-tables/dataTables.fixedHeader.min.js"></script>
<script type="text/javascript" src="../../../assets/plugins/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../assets/plugins/purl.js"></script>
<script type="text/javascript" src="../../../assets/plugins/pace/pace.min.js"></script>
<script type="text/javascript" src="../../../assets/plugins/echart/echarts-all.js"></script>
<script type="text/javascript" src="../../../assets/lib/zxt.js"></script>
<script type="text/javascript" src="../../../assets/scripts/app.js"></script>
<script type="text/javascript" src="../../../assets/scripts/app_udr.js"></script>
<script id="rpt_table" type="text/template">
<thead>
<tr>
<th rowspan="2">学校</th>
<th rowspan="2">参考人数</th>
<th rowspan="1" colspan="2" style="text-align:center">优秀(80%)</th>
<th rowspan="1" colspan="2" style="text-align:center">及格(60%)</th>
<th rowspan="1" colspan="2" style="text-align:center">学困(40%)</th>
<th rowspan="1" colspan="2" style="text-align:center">高线(<%=data[0].highScore%>)</th>
<th rowspan="1" colspan="2" style="text-align:center">中线(<%=data[0].midScore%>)</th>
</tr>
<tr>
<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[0].data, function(d){%>
<tr>
<%for(var i=0;i<d.length;i++){%>
<%if(i==0){%>
<th><%=d[i]%></th>
<%}else{%>
<% if(i > 1 && i % 2 == 1 && d[i] != ""){%>
<th style="text-align:right;"><%=(d[i]*100).toFixed(2) + '%'%></th>
<%}else{%>
<th style="text-align:right;"><%=d[i]%></th>
<%}%>
<%}%>
<%}%>
</tr>
<%})%>
</tbody>
</script>
<script>
jQuery(document).ready(function() {
var xkId = $('body', window.parent.document).attr('xkId');
if( xkId != undefined && xkId != null && xkId.length!=0){
$(".select").attr('disabled','true');
$(".select option[value='"+xkId+"']").attr('selected',true);
}
var exam = appUtils.getExamInfo();
var totalScore;
function getTotalScore(){
ZX.getDataByAjax(
"../../../rpt/single/rpt2008/tbl/"+exam.uid+"/"+exam.examId+"/"+$(".select").val(),
'json',
function(res){
$('.wrong').css('display','none');
$(".btn").removeAttr('disabled');
totalScore = res[0].paperScore;
$(".range").html('').html('自定义分数档 /分 (0 - '+totalScore+'): ');
},
function(){
//判断dom节点是否被datatable了
if ($.fn.DataTable.isDataTable($('.rpt_table'))) {
//构建datatable的dom对象进行销毁
$('.rpt_table').DataTable().destroy(true);
//销毁后 dom也会一并销毁,此处需要还原dom节点
$('.page-content').append('<table class="table table-striped table-bordered table-hover rpt_table" align="center"></table>');
}
$('.wrong').css('display','block');
$(".range").html('未查到该考试的分数信息');
$(".btn").attr('disabled',true);
$.zxtloading.close();
}
);
}
getTotalScore();
var url = "";
var xkId = $(".select").val();
$(".select").change(function(){
var high = $(".high").val().trim();
var mid = $(".mid").val().trim();
if (high == '' || mid == ''){
alert("不能有空值!");
}else{
if(isNaN(high)){
alert("高线请输入数字!");
}else if(isNaN(mid)){
alert("中线请输入数字!");
}
else if(parseFloat(high)<0 || parseFloat(high)>totalScore){
alert("高线超出分数范围!");
}else if(parseFloat(mid)<0 || parseFloat(mid)>totalScore){
alert("中线超出分数范围!");
}
else{
high = parseFloat(parseFloat($(".high").val().trim()).toFixed(2));
$(".high").val(high);
mid = parseFloat(parseFloat($(".mid").val().trim()).toFixed(2));
$(".mid").val(mid);
var xkId = $(".select").val();
var section = $(".select1").val();
url = "../../../rpt/single/rpt2039/tbl/"+exam.uid+"/"+exam.examId+"/"+xkId+"/"+high+"/"+mid+"/"+section;
RptController.renderRptTable();
getTotalScore();
}
}
});
$(".select1").change(function(){
var high = $(".high").val().trim();
var mid = $(".mid").val().trim();
if (high == '' || mid == ''){
alert("不能有空值!");
}else{
if(isNaN(high)){
alert("高线请输入数字!");
}else if(isNaN(mid)){
alert("中线请输入数字!");
}
else if(parseFloat(high)<0 || parseFloat(high)>totalScore){
alert("高线超出分数范围!");
}else if(parseFloat(mid)<0 || parseFloat(mid)>totalScore){
alert("中线超出分数范围!");
}
else{
high = parseFloat(parseFloat($(".high").val().trim()).toFixed(2));
$(".high").val(high);
mid = parseFloat(parseFloat($(".mid").val().trim()).toFixed(2));
$(".mid").val(mid);
var xkId = $(".select").val();
var section = $(".select1").val();
url = "../../../rpt/single/rpt2039/tbl/"+exam.uid+"/"+exam.examId+"/"+xkId+"/"+high+"/"+mid+"/"+section;
RptController.renderRptTable();
getTotalScore();
}
}
});
$(".btn").click(function(){
var high = $(".high").val().trim();
var mid = $(".mid").val().trim();
if (high == '' || mid == ''){
alert("不能有空值!");
}else{
if(isNaN(high)){
alert("高线请输入数字!");
}else if(isNaN(mid)){
alert("中线请输入数字!");
}
else if(parseFloat(high)<0 || parseFloat(high)>totalScore){
alert("高线超出分数范围!");
}else if(parseFloat(mid)<0 || parseFloat(mid)>totalScore){
alert("中线超出分数范围!");
}
else{
high = parseFloat(parseFloat($(".high").val().trim()).toFixed(2));
$(".high").val(high);
mid = parseFloat(parseFloat($(".mid").val().trim()).toFixed(2));
$(".mid").val(mid);
var xkId = $(".select").val();
var section = $(".select1").val();
url = "../../../rpt/single/rpt2039/tbl/"+exam.uid+"/"+exam.examId+"/"+xkId+"/"+high+"/"+mid+"/"+section;
RptController.renderRptTable();
getTotalScore();
}
}
});
var RptController = function() {
var renderRptTable = function() {
//获取数据
$('.wrong').css('display','none');
ZX.getDataByAjax(
url,
'json',
function(res){
if(res.length==1 && _.isEmpty(res[0]) || res==null || res==undefined || res.length==0){
//判断dom节点是否被datatable了
if ($.fn.DataTable.isDataTable($('.rpt_table'))) {
//构建datatable的dom对象进行销毁
$('.rpt_table').DataTable().destroy(true);
//销毁后 dom也会一并销毁,此处需要还原dom节点
$('.page-content').append('<table class="table table-striped table-bordered table-hover rpt_table" align="center"></table>');
}
$('.wrong').css('display','block');
$.zxtloading.close();
}else{
var data = {};
data["data"] = res;
var high = $(".high").val().trim();
var mid = $(".mid").val().trim();
var section = $(".select1").val();
//判断dom节点是否被datatable了
if ($.fn.DataTable.isDataTable($('.rpt_table'))) {
//构建datatable的dom对象进行销毁
$('.rpt_table').DataTable().destroy(true);
//销毁后 dom也会一并销毁,此处需要还原dom节点
$('.page-content').append('<table class="table table-striped table-bordered table-hover rpt_table" align="center"></table>');
}
var xkId = $(".select").val();
$('.rpt_table').zxtable({
//url: url,
data: data,
template: '#rpt_table',
exportURL: '../../../rpt/single/rpt2039/export/'+exam.uid+'/'+exam.examId+'/'+exam.examName+'/'+exam.yearIn+'/'+xkId+'/'+high+'/'+mid+'/'+section,
needDataTable: true,
renderTbody:false,
orderby: [[ 0, "asc" ]],
fixedHeader: true,
callBack: function(){
$.zxtloading.close();
}
});
}
},
function(){
//判断dom节点是否被datatable了
if ($.fn.DataTable.isDataTable($('.rpt_table'))) {
//构建datatable的dom对象进行销毁
$('.rpt_table').DataTable().destroy(true);
//销毁后 dom也会一并销毁,此处需要还原dom节点
$('.page-content').append('<table class="table table-striped table-bordered table-hover rpt_table" align="center"></table>');
}
$('.wrong').css('display','block');
$.zxtloading.close();
}
);
};
return {
renderRptTable: function() {
renderRptTable();
}
}
}();
var initView = function() {
return {
init: function() {
$.cookie.json = true;
//启动加载进度条
if( exam.uid == undefined){
alert("参数非法.");
$.zxtloading.close();
return false;
}
if( exam.examId == undefined){
alert("请先选择考试.");
$.zxtloading.close();
return false;
}
Pace.start();
}
}
}();
initView.init();
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
package cn.doofen.udr.controller.single;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.doofen.udr.UDRBaseConst;
import cn.doofen.udr.bo.single.ISingleBo;
import cn.doofen.udr.bo.single.impl.Rpt2039Bo;
import cn.doofen.udr.controller.SingleController;
import cn.doofen.udr.controller.UDRBaseParam;
import cn.doofen.udr.utils.Unit2Utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
*
* @Package cn.doofen.udr.controller.multi
* @ClassName: Rpt2039Controller
* @Description: 学生单科成绩统计分析表
* @author fyq
* @date 2018年05月04日
*
*/
@Controller
@RequestMapping("/rpt/single/rpt2039")
public class Rpt2039Controller extends SingleController {
private static ISingleBo bo = new Rpt2039Bo();
/**
*
* @Title: rpt2039_tble
* @Description: 获取报表列表数据
* @param uid
* @param examId
* @param yearIn
* @return 参数
* @return JSONObject
* @throws
*/
@RequestMapping(value = "/tbl/{orgId}/{examId}/{xkId}/{high}/{mid}/{section}", method = RequestMethod.GET)
@ResponseBody
public JSONObject rpt2035_tble(@PathVariable(value = "orgId") Long orgId,
@PathVariable(value = "examId") Long examId,
@PathVariable(value = "high") Double high,
@PathVariable(value = "mid") Double mid,
@PathVariable(value = "section") Integer section,
@PathVariable(value = "xkId") Integer xkId) {
try {
UDRBaseParam param = new UDRBaseParam();
param.setExamId(examId);
param.setOrgId(orgId);
param.setXkId(xkId);
param.setHigh(high);
param.setMid(mid);
param.setSection(section);
JSONArray rjarr = loadTblData(param);
return getSuccessResult(rjarr);
} catch (Exception e) {
return getErrorResult("");
}
}
/**
*
* @Title: exportExcel
* @Description: 导出excel
* @param request
* @param response
* @param uid
* @param examName
* @param examId
* @param yearIn
* 参数
* @return void
* @throws
*/
@RequestMapping(value = "/export/{orgId}/{examId}/{examName}/{yearIn}/{xkId}/{high}/{mid}/{section}", method = RequestMethod.GET)
@ResponseBody
public void exportExcel(HttpServletRequest request,
HttpServletResponse response,
@PathVariable(value = "orgId") Long orgId,
@PathVariable(value = "examName") String examName,
@PathVariable(value = "examId") Long examId,
@PathVariable(value = "yearIn") Integer yearIn,
@PathVariable(value = "high") Double high,
@PathVariable(value = "mid") Double mid,
@PathVariable(value = "section") Integer section,
@PathVariable(value = "xkId") Integer xkId) {
try {
// 注意协议头有字节数限制,所以fileName不能超长
Unit2Utils u2u = new Unit2Utils();
String xkName = u2u.excelXKChange(xkId);
String secName = "";
if(section == 0){
secName = "全卷";
}else if (section == 1){
secName = "A卷";
}else if (section == 2){
secName = "B卷";
}
String fileName = getExcelName(request, UDRBaseConst.RPT_2035_NAME+"_"+xkName+"("+secName+")"+"_"+examName);
response.reset();
response.setContentType("application/vnd.ms-excel"); // 改成输出excel文件
response.setHeader("Content-disposition", "attachment; filename="
+ fileName);
UDRBaseParam param = new UDRBaseParam();
param.setExamId(examId);
param.setOrgId(orgId);
param.setYearIn(yearIn);
param.setXkId(xkId);
param.setExamName(examName);
param.setXkName(xkName);
param.setHigh(high);
param.setMid(mid);
param.setSection(section);
exportExcel(request, response, param);
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
/**
*
* @Title: loadTblData
* @Description: 获取页面table数据
* @param param
* 参数
* @return 参数
* @return JSONObject
* @throws
*/
protected JSONArray loadTblData(UDRBaseParam param) throws Exception {
if (param.getOrgId() != null && param.getExamId() != null
&& param.getXkId() != null) {
return bo.loadTblData(param);
}
return null;
}
/**
*
* @Title: loadChartData
* @Description: 获取页面chart的数据
* @param param
* @return 参数
* @return JSONObject
* @throws
*/
protected JSONArray loadChartData(UDRBaseParam param) throws Exception {
if (param.getOrgId() != null && param.getExamId() != null
&& param.getXkId() != null) {
return bo.loadChartData(param);
}
return null;
}
/**
*
* @Title: exportExcel
* @Description: 导出Excel
* @param param
* @return 参数
* @return void
* @throws
*/
protected void exportExcel(HttpServletRequest request,
HttpServletResponse response, UDRBaseParam param) throws Exception {
if (param.getOrgId() != null && param.getExamId() != null
&& param.getExamName() != null && param.getYearIn() != null
&& param.getXkId() != null && param.getXkName()!=null) {
bo.exportExcel(request, response, param);
}
}
}
package cn.doofen.udr.bo.single.impl;
import java.io.OutputStream;
import java.util.ArrayList;
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 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;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zxt.framework.export.RptExcelDomain;
import com.zxt.framework.utils.PropertiesConfigUtils;
/**
*
* @Package cn.doofen.udr.bo.multi.impl
* @ClassName: Rpt2035Bo
* @Description: rpt2035的业务接口 学校分类的单学科总体分析
* @author Zed
* @date 2016年11月29日
*
*/
public class Rpt2039Bo extends SingleBoImpl implements ISingleBo {
private static final String DSI_EXT_RPT_TBL_2039 = PropertiesConfigUtils
.getString("dsi.ext.rpt.tbl.2039");
private static final String logo = PropertiesConfigUtils
.getString("logo");
/**
*
* @Title: loadTblData
* @Description: 获取页面table数据
* @param param
* 参数
* @return 参数
* @return JSONArray
* @throws
*/
public JSONArray loadTblData(UDRBaseParam param) throws Exception {
JSONObject uparam = new JSONObject();
uparam.put("xkId", param.getXkId());
uparam.put("orgId", param.getOrgId());
uparam.put("examId", param.getExamId());
uparam.put("high", param.getHigh());
uparam.put("mid", param.getMid());
uparam.put("section", param.getSection());
JSONArray resJarr = null;
if (UDRBaseConfig.SYS_DEBUG) {
Unit2Utils u2u = new Unit2Utils();
resJarr = u2u.getTestJSONArray("TestJSONArray1035.txt");
} else {
String url = getHttpDSIRestUri4Report(DSI_EXT_RPT_TBL_2039);
JSONObject rjo = httpRestGet(url, uparam.toString(), null);
if (rjo != null && !rjo.isEmpty()
&& rjo.getBooleanValue("success") == true) {
JSONObject job = rjo.getJSONObject("data");
resJarr = new JSONArray();
resJarr.add(job);
} 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 resJarr;
}
/**
*
* @Title: loadChartData
* @Description: 获取页面chart的数据
* @param param
* @return 参数
* @return JSONOArray
* @throws
*/
public JSONArray loadChartData(UDRBaseParam param) throws Exception {
return null;
}
/**
*
* @Title: exportExcel
* @Description: 导出Excel
* @param param
* @return 参数
* @return void
* @throws
*/
public void exportExcel(HttpServletRequest request,
HttpServletResponse response, UDRBaseParam param) throws Exception {
//输出表格的头部名称
Unit2Utils unit2=new Unit2Utils();
String xkName=unit2.excelXKChange(param.getXkId());
int sec = param.getSection();
String secName = null;
if(sec == 0){
secName = "全卷";
}else if (sec == 1){
secName = "A卷";
}else if (sec == 2){
secName = "B卷";
}
String title = UDRBaseConst.RPT_2039_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+"("+secName+")");
//所有数据的JSONArray
JSONArray ja = new JSONArray();
ja.add( jo);
rptDo.setSheetData( ja);
List<RptExcelDomain> sheets = new ArrayList<RptExcelDomain>();
sheets.add( rptDo);
setSheets( sheets);
//写入数据
writeExcel(os,true);
} catch (Exception e) {
throw new Exception("Export Excel failed, beacause"
+ e.getMessage());
} finally {
os.close();
}
}
/**
* 重载excel创建
*
*/
protected void writeExcelSheetSelf( RptExcelDomain rptDomain){
// 创建Excel的工作sheet,对应到一个excel文档的tab
HSSFSheet sheet = wb.createSheet( rptDomain.getSheetName());
// 设置excel每列宽度
sheet.setColumnWidth(0, 6000);
sheet.setColumnWidth(1, 2500);
// 创建Excel的sheet的一行
HSSFRow row =null;
String[] titleDefault = {"学校", "参考人数"};
String[] headers = {"人数", "比例"};
/*---------------------------------------
* 创建sheet的数据
*--------------------------------------*/
JSONArray datas = rptDomain.getSheetData();
Object[] titles = datas.getJSONObject(0).getJSONArray( "head").toArray();
Integer xkMerg = (titles.length-titleDefault.length)*headers.length;
JSONArray rowDatas = datas.getJSONObject(0).getJSONArray( "data");
//装第一行的表头数据
JSONArray ja=new JSONArray();
ja.add("学校");
ja.add("参考人数");
for(int i=titleDefault.length;i<titles.length;i++){
String schName=datas.getJSONObject(0).getJSONArray( "head").getJSONObject(i).getString("itemName");
ja.add(schName);
}
titles=ja.toArray();
//拿出副标题和主标题
String str=rptDomain.getSheetTitle();
String [] strs=new String[2];
strs=str.split(",");
String head1=strs[0];
String head2=strs[1];
// 创建Excel的sheet的一行
row = sheet.createRow(0);
row.setHeight((short) rptDomain.getSheetTitleHeight());// 设定行的高度
// 创建一个Excel的单元格
HSSFCell cell_title = row.createCell(0);
// 合并单元格(startRow,endRow,startColumn,endColumn)
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, xkMerg+titleDefault.length-1));
// 给Excel的单元格设置样式和赋值
cell_title.setCellStyle( this.getStyleTitle());
cell_title.setCellValue( head1);
//副标题
row = sheet.createRow(1);
// 创建一个Excel的单元格
HSSFCell cell_title1 = row.createCell(0);
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, xkMerg+titleDefault.length-1));
//给单元格设置样式和赋值
cell_title1.setCellType(HSSFCellStyle.ALIGN_LEFT);
cell_title1.setCellValue(head2);
//构建表头
//第一行
HSSFCellStyle headerStyle = this.getStyleHeader();
row = sheet.createRow(2);
HSSFCell cell_header = null;
for( int i = 0; i <titleDefault.length; i++ ){
cell_header = row.createCell( i );
sheet.addMergedRegion(new CellRangeAddress( 2, 3, i,i));
cell_header.setCellStyle( headerStyle);
cell_header.setCellValue( titleDefault[i]);
}
int startHcl = titleDefault.length;
for( int i = 2; i < titles.length; i++){
cell_header = row.createCell( startHcl );
sheet.addMergedRegion(new CellRangeAddress( 2, 2, startHcl, startHcl+headers.length-1 ));
cell_header.setCellStyle( headerStyle);
cell_header.setCellValue((String)titles[i]);
startHcl = startHcl + headers.length;
}
//第二行
row = sheet.createRow(3);
int startCol = titleDefault.length;
for( int i = 2; i < titles.length; i++){
for( int j = 0; j < headers.length; j++){
cell_header = row.createCell( startCol );
cell_header.setCellStyle( headerStyle);
cell_header.setCellValue( (String)headers[j]);
startCol = startCol + 1;
}
}
int startRow = 3;
//构建独立表的数据
for( int d =0; d <rowDatas.size(); d++ ){
startRow = startRow + 1;
row = sheet.createRow( startRow );
JSONArray _cellDatas = rowDatas.getJSONArray(d);
HSSFCell cell_Data = null;
for(int j = 0; j < _cellDatas.size(); j++){
cell_Data = row.createCell(j);
if(j > 1 && j % 2 == 1 && !_cellDatas.getString(j).equals("")){
cell_Data.setCellValue(String.format("%.2f",_cellDatas.getDouble(j)*100)+"%");
}else{
cell_Data.setCellValue(_cellDatas.getString(j));
}
}
}
}
}
package cn.doofen.dsi.core.bo.org.impl.or;
import cn.doofen.dsi.core.bo.BOException;
import cn.doofen.dsi.core.bo.DsiBOImpl;
import cn.doofen.dsi.core.bo.check.BaseCheck;
import cn.doofen.dsi.core.bo.org.ior.IOrgRpt0028;
import cn.doofen.dsi.core.ctrl.pub.data.DataErrorCode;
import cn.doofen.dsi.core.eao.BxoEAO;
import cn.doofen.dsi.core.eao.BxoEAOImpl;
import cn.doofen.dsi.core.eao.CicadaEAO;
import cn.doofen.dsi.core.eao.CicadaEAOImpl;
import cn.doofen.dsi.core.eao.OrgEAO;
import cn.doofen.dsi.core.eao.OrgEAOImpl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doofen.dict.core.bbo.dto.BBOOrg;
import com.doofen.dict.core.beo.dto.BEOExam;
/**
*
* @Package cn.doofen.dsi.core.bo.org.impl.or
* @ClassName: OrgRpt0028Impl
* @Description: 获取报表单科/全科学校分类分析
* @author fyq
* @date 2018年05月03日
*
*/
public class OrgRpt0028Impl extends DsiBOImpl implements IOrgRpt0028 {
@Override
/**
*
* @Title: get
* @Description: 获取报表 学校分类单科/全科分析
* @param orgId
* @param examId
* @param xkId
* @return {"width":11,head:[],data:[[],..]}
* @throws Exception 参数
* @return JSONObject
* @throws
*/
public JSONObject get(Long orgId, Double high, Double mid, Long examId, Integer xkId, Integer section) throws Exception {
BaseCheck checkH = new BaseCheck();
// 获取基础数据
BBOOrg org = checkH.checkOrg(orgId);
BEOExam exam = checkH.checkExamOrg(examId, orgId);
if (xkId == 0) {
} else {
checkH.checkExamPaper(examId, xkId);
}
// 获取index
String index = getOrgIndex(exam.getExamDate());
// 获取数据
return getData(index, org, exam, xkId, high, mid,section);
}
/**
*
* @Title: getData
* @Description: 获取具体数据
* @param index
* @param orgId
* @param exam
* @param xkId
* @return {"width":11,"head":[],"data":[..],..}
* @throws Exception
* 参数
* @return JSONObject
* @throws
*/
private JSONObject getData(String index, BBOOrg org, BEOExam exam, Integer xkId, Double high, Double mid, Integer section) throws Exception {
JSONObject jo = new JSONObject();
OrgEAO eao = new OrgEAOImpl(index);
Long examId = exam.getExamId();
Long orgId = org.getOrgId();
JSONObject Data = new JSONObject();
if (xkId.intValue() == 0) {
Data = eao.getStatOrgScoreMix(orgId, examId);
} else {
Data = eao.getStatOrgScore(orgId, examId, xkId);
}
if ((Data == null) || (Data.isEmpty())) {
throw new BOException(DataErrorCode.ECODE_DATA_LACK, "考试(" + examId + ")" + "机构分析数据没有找到");
}
JSONArray examSches = Data.getJSONArray("examSches");
JSONObject schInfo = getSchIds(examSches);
JSONArray datas = pre_data(schInfo, xkId, exam, examId, eao, orgId, high, mid, section);
JSONArray head = new JSONArray();
head.add("学校");
head.add("参考人数");
JSONObject headContent = new JSONObject();
headContent.put("itemName", "优秀");
headContent.put("subNum", 2);
JSONArray subHead = new JSONArray();
subHead.add("人数");
subHead.add("比例");
headContent.put("subHead", subHead);
head.add(headContent);
headContent = new JSONObject();
headContent.put("itemName", "及格");
headContent.put("subNum", 2);
subHead = new JSONArray();
subHead.add("人数");
subHead.add("比例");
headContent.put("subHead", subHead);
head.add(headContent);
headContent = new JSONObject();
headContent.put("itemName", "学困");
headContent.put("subNum", 2);
subHead = new JSONArray();
subHead.add("人数");
subHead.add("比例");
headContent.put("subHead", subHead);
head.add(headContent);
headContent = new JSONObject();
headContent.put("itemName", "高线("+high+")");
headContent.put("subNum", 2);
subHead = new JSONArray();
subHead.add("人数");
subHead.add("比例");
headContent.put("subHead", subHead);
head.add(headContent);
headContent = new JSONObject();
headContent.put("itemName", "中线("+mid+")");
headContent.put("subNum", 2);
subHead = new JSONArray();
subHead.add("人数");
subHead.add("比例");
headContent.put("subHead", subHead);
head.add(headContent);
jo.put("head", head);
jo.put("data", datas);
jo.put("highScore", high);
jo.put("midScore", mid);
return jo;
}
/**
*
* @Title: getSchIds
* @Description:获取参加考试的学校id
* @param examSches
* @return 参数
* @return {schIds:[],shName:[]}
* @throws
*/
private JSONObject getSchIds(JSONArray examSches) {
JSONObject jo = new JSONObject();
Long[] schIds = new Long[examSches.size()];
String[] schNames = new String[examSches.size()];
for (int i = 0; i < examSches.size(); i++) {
JSONObject sch = examSches.getJSONObject(i);
schIds[i] = sch.getLong("schId");
schNames[i] = sch.getString("schName");
}
jo.put("schIds", schIds);
jo.put("schNames", schNames);
return jo;
}
/**
* @throws Exception
*
* @Title: pre_data
* @Description: 拿每一个学校的数据
* @param schInfo
* @return 参数
* @return JSONArray
* @throws
*/
private JSONArray pre_data(JSONObject schInfo, Integer xkId, BEOExam exam, Long examId, OrgEAO eao, Long orgId, Double high, Double mid, Integer section) throws Exception {
// TODO Auto-generated method stub
JSONObject schData = new JSONObject();
JSONArray datas = new JSONArray();
if (xkId == 0) {
schData = eao.getExtStatSchScoreMix(orgId, examId);
} else {
schData = eao.getExtStatSchScore(orgId, examId, xkId);
}
Long[] schIds = schInfo.getObject("schIds", Long[].class);
JSONObject OrgBase = new JSONObject();
JSONArray CicadaEAO = new JSONArray();
Long highNum = null;
Long midNum = null;
Long passNum = null;
if (xkId == 0) {
OrgBase = eao.getStatSchScoreMix(orgId, examId);
for (int i = 0; i < schIds.length; i++) {
JSONArray tmp = new JSONArray();
JSONObject data = schData.getJSONObject(schIds[i].toString());
if (data == null || data.isEmpty()) {
continue;
}
String schName = data.getString("schName");
JSONObject schBase = OrgBase.getJSONObject(schIds[i].toString());
int schStuNum = schBase.getInteger("schStuNum");
double totalScore = data.getDoubleValue("paperScore");
double pass = totalScore*0.6;
int schEStuNum = schBase.getIntValue("schEStuNum");
double schEStuPer = schBase.getDoubleValue("schEStuPer");
int schDStuNum = schBase.getIntValue("schDStuNum");
double schDStuPer = schBase.getDoubleValue("schDStuPer");
highNum = eao.getExtStatStuMixHighNum(orgId, examId, schIds[i], high);
double highPer = (double)highNum/schStuNum;
midNum = eao.getExtStatStuMixMidNum(orgId, examId, schIds[i], mid);
double midPer = (double)midNum/schStuNum;
passNum = eao.getExtStatStuPassNum(orgId, examId, schIds[i], pass);
double passPer = (double)passNum/schStuNum;
tmp.add(schName);
tmp.add(schStuNum);
tmp.add(schEStuNum);
tmp.add(schEStuPer);
tmp.add(passNum);
tmp.add(passPer);
tmp.add(schDStuNum);
tmp.add(schDStuPer);
tmp.add(highNum);
tmp.add(highPer);
tmp.add(midNum);
tmp.add(midPer);
datas.add(tmp);
}
} else {
OrgBase = eao.getStatSchScore(orgId, examId, xkId);
for (int i = 0; i < schIds.length; i++) {
JSONArray tmp = new JSONArray();
JSONObject data = schData.getJSONObject(schIds[i].toString());
if (data == null || data.isEmpty()) {
continue;
}
BxoEAO beao = new BxoEAOImpl();
String schName = data.getString("schName");
JSONObject schBase = OrgBase.getJSONObject(schIds[i].toString());
int schStuNum = schBase.getInteger("schStuNum");
if(section == 0){
int schEStuNum = schBase.getIntValue("schEStuNum");
double schEStuPer = schBase.getDoubleValue("schEStuPer");
int schPassNum = schBase.getIntValue("schPassNum");
double schPassPer = schBase.getDoubleValue("schPassPer");
int schDStuNum = schBase.getIntValue("schDStuNum");
double schDStuPer = schBase.getDoubleValue("schDStuPer");
highNum = eao.getExtStatStuHighNum(orgId, examId, schIds[i], high, xkId);
double highPer = (double)highNum/schStuNum;
midNum = eao.getExtStatStuMidNum(orgId, examId, schIds[i], mid, xkId);
double midPer = (double)midNum/schStuNum;
tmp.add(schName);
tmp.add(schStuNum);
tmp.add(schEStuNum);
tmp.add(schEStuPer);
tmp.add(schPassNum);
tmp.add(schPassPer);
tmp.add(schDStuNum);
tmp.add(schDStuPer);
tmp.add(highNum);
tmp.add(highPer);
tmp.add(midNum);
tmp.add(midPer);
datas.add(tmp);
} else if(section == 1){
long paperId = data.getLongValue("paperId");
JSONArray secArr = beao.getSectionScore(paperId);
JSONObject secObj = secArr.getJSONObject(0);
JSONArray ABscores = secObj.getJSONArray("sectionPaperScores");
JSONObject Ascores = ABscores.getJSONObject(0);
double Ascore = Ascores.getDoubleValue("disScore");
double Escore = Ascore*0.8;
double Pscore = Ascore*0.6;
double Dscore = Ascore*0.4;
int Enum = 0;
int Pnum = 0;
int Dnum = 0;
String index = getCicadaIndex(exam.getExamDate(), schIds[i]);
CicadaEAO ceao = new CicadaEAOImpl(index);
CicadaEAO = ceao.getStatStuScoreNum(examId, xkId);
for(int j = 0; j < CicadaEAO.size(); j++){
JSONObject stuscores = CicadaEAO.getJSONObject(j);
JSONArray abscores = stuscores.getJSONArray("stuSections");
if(abscores != null ){
JSONObject ascores = abscores.getJSONObject(0);
double ascore = ascores.getDoubleValue("disStuScore");
if (ascore >= Escore ){
++Enum;
}
if (ascore >= Pscore){
++Pnum;
}
if (ascore < Dscore){
++Dnum;
}
}
}
double schEStuPer = (double)Enum/schStuNum;
double schPassPer = (double)Pnum/schStuNum;;
double schDStuPer = (double)Dnum/schStuNum;;
tmp.add(schName);
tmp.add(schStuNum);
tmp.add(Enum);
tmp.add(schEStuPer);
tmp.add(Pnum);
tmp.add(schPassPer);
tmp.add(Dnum);
tmp.add(schDStuPer);
tmp.add("");
tmp.add("");
tmp.add("");
tmp.add("");
datas.add(tmp);
}else if(section == 2){
long paperId = data.getLongValue("paperId");
JSONArray secArr = beao.getSectionScore(paperId);
JSONObject secObj = secArr.getJSONObject(0);
JSONArray ABscores = secObj.getJSONArray("sectionPaperScores");
JSONObject Bscores = ABscores.getJSONObject(1);
double Bscore = Bscores.getDoubleValue("disScore");
double Escore = Bscore*0.8;
double Pscore = Bscore*0.6;
double Dscore = Bscore*0.4;
int Enum = 0;
int Pnum = 0;
int Dnum = 0;
String index = getCicadaIndex(exam.getExamDate(), schIds[i]);
CicadaEAO ceao = new CicadaEAOImpl(index);
CicadaEAO = ceao.getStatStuScoreNum(examId, xkId);
for(int j = 0; j < CicadaEAO.size(); j++){
JSONObject stuscores = CicadaEAO.getJSONObject(j);
JSONArray abscores = stuscores.getJSONArray("stuSections");
if(abscores != null ){
JSONObject bscores = abscores.getJSONObject(1);
double bscore = bscores.getDoubleValue("disStuScore");
if (bscore >= Escore ){
++Enum;
}
if (bscore >= Pscore){
++Pnum;
}
if (bscore < Dscore){
++Dnum;
}
}
}
double schEStuPer = (double)Enum/schStuNum;
double schPassPer = (double)Pnum/schStuNum;;
double schDStuPer = (double)Dnum/schStuNum;;
tmp.add(schName);
tmp.add(schStuNum);
tmp.add(Enum);
tmp.add(schEStuPer);
tmp.add(Pnum);
tmp.add(schPassPer);
tmp.add(Dnum);
tmp.add(schDStuPer);
tmp.add("");
tmp.add("");
tmp.add("");
tmp.add("");
datas.add(tmp);
}
}
}
return datas;
}
}