package com.product.server.report.service; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.product.core.dao.BaseDao; import com.product.core.dao.support.Dao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.core.service.support.AbstractBaseService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.core.transfer.Transactional; import com.product.server.report.controller.TestDao; import com.product.server.report.service.idel.EChartsReportConfigService; @Service public class EChartsReportConfigServiceimple extends AbstractBaseService implements EChartsReportConfigService { @Autowired public BaseDao baseDao; public BaseDao getBaseDao() { return baseDao; } public void setBaseDao(BaseDao baseDao) { this.baseDao = baseDao; } @Override @Transactional public JSONObject getSqlTableInfo(String sql) throws BaseException{ DataTableEntity dataTableEntity = TestDao.getColumnNames(sql); JSONArray jsonArray = new JSONArray(); for (int i = 0; i < dataTableEntity.getRows(); i++) { JSONObject fObject = new JSONObject(); fObject.put("field_name",dataTableEntity.getFieldSetEntity(i).getString("field_name")); fObject.put("field_type",dataTableEntity.getFieldSetEntity(i).getString("field_type")); jsonArray.add(fObject); } JSONObject object = new JSONObject(); object.put("sqlfield", jsonArray); return object; } @Override public JSONObject getNameTableInfo(String name) throws BaseException { //获取表信息 FieldSetEntity fSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "table_name=?",new String[] {name}, false); String tableuuid = fSetEntity.getString("uuid"); //获取字段信息 DataTableEntity dTableEntity = baseDao.listTable("product_sys_datamodel_field", "table_uuid = ?",new String[] {tableuuid}); //查询是否有子表 DataTableEntity subTableEntity = baseDao.listTable("product_sys_datamodel_field", "field_relation_table = ?",new String[] {fSetEntity.getString("uuid")}); JSONObject jsonObject = new JSONObject(); if (subTableEntity.getRows() > 0) { JSONArray subJsonArray = new JSONArray(); for (int i = 0; i < subTableEntity.getRows(); i++) { JSONObject subJsonObject = new JSONObject(); //子表uuid String table_uuid = subTableEntity.getFieldSetEntity(i).getString("table_uuid"); //子表表名 FieldSetEntity sub_table = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "uuid = ?",new String[] {table_uuid}, false); //存放子表信息 subJsonObject.put("sub_table_uuid", sub_table.getString("uuid")); subJsonObject.put("sub_table_name", sub_table.getString("table_name")); subJsonObject.put("sub_table_description", sub_table.getString("table_description")); //子表字段信息 DataTableEntity subDataEntity = baseDao.listTable("product_sys_datamodel_field", "table_uuid = ?",new String[] {table_uuid}); //创建数组存字段名 JSONArray jsonArray = new JSONArray(); //存放子表字段 for (int j = 0; j < subDataEntity.getRows(); j++) { FieldSetEntity subFieldEntity = subDataEntity.getFieldSetEntity(j); String sub_field_uuid = subFieldEntity.getString("uuid"); String sub_field_name = subFieldEntity.getString("field_name"); String sub_field_description = subFieldEntity.getString("field_description"); String sub_field_type = subFieldEntity.getString("field_type"); JSONObject sub_field_json = new JSONObject(); sub_field_json.put("sub_field_uuid", sub_field_uuid); sub_field_json.put("sub_field_name", sub_field_name); sub_field_json.put("sub_field_description", sub_field_description); sub_field_json.put("sub_field_type", sub_field_type); jsonArray.add(sub_field_json); } //子表字段信息json subJsonObject.put("sub_table_field", jsonArray); subJsonArray.add(subJsonObject); } jsonObject.put("subTable", subJsonArray); } jsonObject.put("table_name", fSetEntity.getString("table_name"));//表名 jsonObject.put("table_description", fSetEntity.getString("table_description"));//描述 //创建数组存字段名 JSONArray jsonArray = new JSONArray(); for (int i = 0; i < dTableEntity.getRows(); i++) { FieldSetEntity fEntity = dTableEntity.getFieldSetEntity(i); JSONObject object = new JSONObject(); object.put("field_name", fEntity.getString("field_name")); object.put("field_uuid", fEntity.getString("uuid")); object.put("field_description", fEntity.getString("field_description")); object.put("field_type", fEntity.getString("field_type")); jsonArray.add(object); } jsonObject.put("table_field", jsonArray); jsonObject.put("table_uuid",tableuuid); System.out.println(jsonObject.toString()); return jsonObject; } @Override @Transactional public boolean addTableInfo(JSONObject reportInfo) throws BaseException { FieldSetEntity fieldSetEntity = new FieldSetEntity(); fieldSetEntity.setTableName("product_sys_reoprt_config"); System.out.print(reportInfo); String report_head_title_left = (String)reportInfo.get("report_head_title_left");//头部报表标题—左 String report_head_title_center = (String)reportInfo.get("report_head_title_center");//头部报表标题—中 String report_head_title_right = (String)reportInfo.get("report_head_title_right");//头部报表标题-右 String report_tail_title_left = (String)reportInfo.get("report_tail_title_left");//尾部报表标题—左 String report_tail_title_center = (String)reportInfo.get("report_tail_title_center");//尾部报表标题—中 String report_tail_title_right = (String)reportInfo.get("report_tail_title_right");//尾部报表标题-右 String report_name = (String)reportInfo.get("report_name");//报表名称 String report_type = (String)reportInfo.get("report_type");//报表类型 String report_table_name = (String)reportInfo.get("report_table_name"); //数据表名称 String report_data_filter = (String)reportInfo.get("report_data_filter");//查询条件 String report_data_sql = (String)reportInfo.get("report_data_sql");//报表数据源,直接写sql(不能有排序) String fix_header = (String)reportInfo.get("fix_header");//是否固定表头 String last_total = (String)reportInfo.get("last_total");//是否最后总计 String is_page = (String)reportInfo.get("is_page");//是否分页 String page_size = (String)reportInfo.get("page_size");//每页条数 String title_back_css = (String)reportInfo.get("title_back_css");//标题样式* String body_back_css = (String)reportInfo.get("body_back_css");//表格主体样式* String total_row_css = (String)reportInfo.get("total_row_css");//汇总行样式 String orderby = (String)reportInfo.get("orderby");//排序* String report_data_width = (String)reportInfo.get("report_data_width");//报表长度 JSONArray map = (JSONArray)((JSONObject)reportInfo.get("map")).get("elements");//选中字段map JSONArray headerMap = (JSONArray)((JSONObject)reportInfo.get("headerMap")).get("elements");//表头map String report_uuid = (String)reportInfo.get("report_uuid");//报表uuid System.out.println(map); System.out.println(headerMap); fieldSetEntity.setValue("report_head_title_left", report_head_title_left); fieldSetEntity.setValue("report_head_title_center", report_head_title_center); fieldSetEntity.setValue("report_head_title_right", report_head_title_right); fieldSetEntity.setValue("report_tail_title_left",report_tail_title_left); fieldSetEntity.setValue("report_tail_title_center",report_tail_title_center); fieldSetEntity.setValue("report_tail_title_right",report_tail_title_right); fieldSetEntity.setValue("report_name", report_name); fieldSetEntity.setValue("report_type", report_type); fieldSetEntity.setValue("report_table_name", report_table_name); fieldSetEntity.setValue("report_data_filter", report_data_filter); fieldSetEntity.setValue("report_data_sql", report_data_sql); fieldSetEntity.setValue("fix_header", fix_header);//是否固定表头 fieldSetEntity.setValue("last_total", last_total);//是否最后总计 fieldSetEntity.setValue("is_page", is_page);//是否分页 fieldSetEntity.setValue("page_size", page_size);//分页字段 fieldSetEntity.setValue("title_back_css", title_back_css);//标题样式 fieldSetEntity.setValue("body_back_css", body_back_css);//表格主体样式 fieldSetEntity.setValue("total_row_css", total_row_css);//会总行样式 fieldSetEntity.setValue("orderby", orderby);//排序 fieldSetEntity.setValue("report_data_width",report_data_width); if(report_uuid.isEmpty()){ report_uuid = baseDao.add(fieldSetEntity); }else { fieldSetEntity.setValue("uuid",report_uuid); baseDao.update(fieldSetEntity); } baseDao.delete("product_sys_report_header_properties", "report_uuid=?",new String[] {report_uuid}); baseDao.delete("product_sys_report_field_properties","report_uuid = ?",new String[] {report_uuid}); //表头配置表 //PRODUCT_SYS_reoprt_config_header JSONObject header = (JSONObject)headerMap.get(0); JSONArray headerArray = (JSONArray)header.get("value"); //DataTableEntity dataTableEntity = new DataTableEntity(); if(headerArray != null){ for(int i=0;i