package com.product.server.report.service;
|
|
|
import org.apache.log4j.Logger;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.entity.Report;
|
import com.product.core.exception.BaseException;
|
import com.product.server.report.service.idel.ListReportConfigService;
|
|
@Service
|
public class ListReportConfigServiceImple implements ListReportConfigService {
|
|
@Autowired
|
public BaseDao baseDao;
|
public BaseDao getBaseDao() {
|
return baseDao;
|
}
|
public void setBaseDao(BaseDao baseDao) {
|
this.baseDao = baseDao;
|
}
|
public ListReportServer reportServerNew;
|
|
public ListReportServer getReportServerNew() {
|
return reportServerNew;
|
}
|
public void setReportServerNew(ListReportServer reportServerNew) {
|
this.reportServerNew = reportServerNew;
|
}
|
public static Logger logger=Logger.getLogger(ListReportConfigServiceImple.class);
|
//根据表名获取报表
|
public String createReportInfo(String tableUuid) throws BaseException{
|
//获取配置报表
|
FieldSetEntity felset = baseDao.getFieldSetEntity("product_sys_reoprt_config", tableUuid, false);
|
DataTableEntity data = null;
|
if(felset.getString("report_table_name") != null && !felset.getString("report_table_name").isEmpty()){
|
data = baseDao.listTable(felset.getString("report_table_name"));
|
}else if(felset.getString("report_data_sql") != null){
|
data = baseDao.listTable(felset.getString("report_data_sql"), new String[]{});
|
}
|
DataTableEntity fieldData = baseDao.listTable("product_sys_report_field_properties", "report_uuid = '"+tableUuid+"'", "order_number");
|
Report rc=new Report();
|
if(fieldData.getRows() > 0){
|
int row = fieldData.getRows();
|
String[] showField = new String[row];//字段名
|
int[][] showColspan = new int[1][row];//跨列
|
String[][] showTitle = new String[1][row];//字段描述
|
int[][] showRowspan = new int[1][row];//跨行
|
boolean[] showTotalField = new boolean[row];//是否总计
|
int[] showColWidth = new int[row];//列宽
|
String[] showFormat = new String[row];//字段格式
|
boolean[] showGroupField = new boolean[row];//是否分组
|
String[] url = new String[row];//穿透地址
|
for(int i=0;i<fieldData.getRows();++i){
|
FieldSetEntity set = fieldData.getFieldSetEntity(i);
|
showField[i] = set.getString("table_field_name");//字段名
|
System.out.println(set.getString("table_field_description"));
|
showTitle[0][i] = set.getString("table_field_description");//字段中文名
|
showColspan[0][i] = 1;
|
showRowspan[0][i] = 1;
|
System.out.println(set.getString("end_total_type"));
|
if(set.getString("end_total_type").equals("false")){//是否最后总计
|
showTotalField[i] = false;
|
}else{
|
showTotalField[i] = true;
|
}
|
showColWidth[i] = set.getInteger("show_width");//宽度比例
|
System.out.println("数据格式:"+set.getString("data_format"));
|
if(set.getString("data_format") == null || set.getString("data_format").isEmpty() || set.getString("data_format").equals("null")){
|
showFormat[i] = null;
|
}else{
|
showFormat[i] = set.getString("data_format");
|
}
|
if(set.getString("is_group_field").equals("1")){
|
showGroupField[i] = true;//是否分组
|
}else{
|
showGroupField[i] = false;//是否分组
|
}
|
}
|
//是否固定表头
|
if(felset.getString("fix_header").equals("1")){
|
rc.setFixHeader(true);
|
}else{
|
rc.setFixHeader(false);
|
}
|
//是否最后总计
|
if(felset.getString("last_total").equals("1")){
|
rc.setTotal(true);
|
}else{
|
rc.setTotal(false);
|
}
|
//是否分页
|
// if(felset.getString("is_page").equals("1")){
|
// rc.setPage(true);
|
// rc.setPageSize(felset.getInteger("page_size"));
|
// }else{
|
// rc.setPage(false);
|
// }
|
DataTableEntity headerData = baseDao.listTable("product_sys_report_header_properties", "report_uuid = '"+tableUuid+"'");
|
if(headerData.getRows() > 0){
|
int headerY = headerData.getRows() / fieldData.getRows();//二维数组y
|
int[][] headerColspan = new int[headerY][fieldData.getRows()];//跨列
|
String[][] headerTitle = new String[headerY][fieldData.getRows()];//字段描述
|
int[][] headerRowspan = new int[headerY][fieldData.getRows()];//跨行
|
int y = 0;
|
for(int j=0;j<headerData.getRows();++j){
|
FieldSetEntity header = headerData.getFieldSetEntity(j);
|
int x = Integer.parseInt(header.getString("header_index").split("-")[0]);
|
//列发生改变
|
if(y != Integer.parseInt(header.getString("header_index").split("-")[1])){
|
y = Integer.parseInt(header.getString("header_index").split("-")[1]);
|
|
}
|
headerTitle[y][x] = header.getString("header_name");
|
headerColspan[y][x] = Integer.parseInt(header.getString("header_colspan"));
|
headerRowspan[y][x] = Integer.parseInt(header.getString("header_rowspan"));
|
}
|
showTitle = headerTitle;
|
showColspan = headerColspan;
|
showRowspan = headerRowspan;
|
}
|
url[3] = "~bottom_x2~,asdasd,asdasd,sadasd,aasdsad";
|
rc.setUrl(url);
|
rc.setTitle(showTitle);//字段中文描述
|
rc.setColspan(showColspan);//跨列
|
rc.setRowspan(showRowspan);//跨行
|
rc.setField(showField);//表头字段
|
rc.setTotalField(showTotalField);//是否总计
|
if(!(felset.getString("report_data_width") == null || felset.getString("report_data_width").isEmpty())){
|
rc.setWidth(felset.getInteger("report_data_width"));//表报宽度
|
}
|
rc.setColWidth(showColWidth);//列宽比例
|
rc.setFormat(showFormat);//字段格式
|
rc.setGroupField(showGroupField);//是否分组
|
}
|
|
System.out.println(data.getRows());
|
// rc.setCurrentPage(1);//当前页
|
// rc.setTotalCount(data.getRows() / felset.getInteger("page_size"));//总页数
|
// rc.setTotalRow(data.getRows());//总条数
|
rc.setDt(data);
|
System.out.println(rc.getDt().getRows());
|
System.out.println(rc.getGroupField());
|
System.out.println(reportServerNew);
|
ListReportServer reportServerNew = new ListReportServer();
|
reportServerNew.setReport(rc);
|
String error=reportServerNew.toCheckReport();//参数检测
|
if(error==null){
|
return reportServerNew.toCreateGroupReport();
|
} else{
|
return "错误:"+error;
|
}
|
}
|
public JSONObject getReportName(String table_uuid) throws BaseException{
|
FieldSetEntity fSetEntity = baseDao.getFieldSetEntity("product_sys_reoprt_config", table_uuid, false);
|
JSONObject object = new JSONObject();
|
//加载表名
|
object.put("report_name", fSetEntity.getString("report_name"));
|
//加载页眉页脚
|
object.put("report_head_title_left",fSetEntity.getString("report_head_title_left"));//头部报表标题—左
|
object.put("report_head_title_center",fSetEntity.getString("report_head_title_center"));//头部报表标题—中
|
object.put("report_head_title_right",fSetEntity.getString("report_head_title_right"));//头部报表标题—右
|
object.put("report_tail_title_left",fSetEntity.getString("report_tail_title_left"));//尾部报表标题—左
|
object.put("report_tail_title_center",fSetEntity.getString("report_tail_title_center"));//尾部报表标题—中
|
object.put("report_tail_title_right",fSetEntity.getString("report_tail_title_right"));//尾部报表标题—右
|
return object;
|
}
|
}
|