|
|
@@ -5,6 +5,8 @@ import com.minpay.common.constant.Constant;
|
|
|
import com.minpay.common.format.IFormatService;
|
|
|
import com.minpay.common.service.IReportService;
|
|
|
import com.minpay.common.util.DateUtil;
|
|
|
+import com.minpay.common.util.ExportUtils;
|
|
|
+import com.minpay.common.util.StringUtil;
|
|
|
import com.minpay.db.table.mapper.DwReportDataMapper;
|
|
|
import com.minpay.db.table.mapper.DwReportInfMapper;
|
|
|
import com.minpay.db.table.model.DwReportData;
|
|
|
@@ -12,6 +14,7 @@ import com.minpay.db.table.model.DwReportInf;
|
|
|
import com.minpay.db.table.own.mapper.IReportBatchMapper;
|
|
|
import com.minpay.db.table.own.mapper.ReportManageMapper;
|
|
|
import com.minpay.db.table.own.mapper.SequenceMapper;
|
|
|
+import com.mongodb.util.StringBuilderPool;
|
|
|
import com.startup.minpay.frame.business.IMINAction;
|
|
|
import com.startup.minpay.frame.business.res.MINActionResult;
|
|
|
import com.startup.minpay.frame.constant.IMINBusinessConstant;
|
|
|
@@ -24,14 +27,21 @@ import com.startup.minpay.frame.session.MINSession;
|
|
|
import com.startup.minpay.frame.target.MINAction;
|
|
|
import com.startup.minpay.frame.target.MINComponent;
|
|
|
import com.startup.minpay.frame.target.MINParam;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@MINComponent
|
|
|
public class XlgzzReportAction implements IMINAction {
|
|
|
@@ -40,31 +50,17 @@ public class XlgzzReportAction implements IMINAction {
|
|
|
public final static String REPORT_INF_QUERY = "reportInfQuery";
|
|
|
|
|
|
|
|
|
- /** 生成报表的数据查询 */
|
|
|
- public final static String FILE_INF_REPORT_QUERY = "fileInfReportQuery";
|
|
|
-
|
|
|
-
|
|
|
/** 根据不同的报表类型查询对应时间范围类的所需数据 */
|
|
|
public final static String REPORT_NEED_DATA_DETAIL = "reportNeedDataDetail";
|
|
|
- public final static String REPORT_NEED_DATA_DETAIL2 = "reportNeedDataDetail2";
|
|
|
|
|
|
+ public final static String REPORT_NEED_DATA_DETAIL2 = "reportNeedDataDetail2";
|
|
|
|
|
|
/** 生成报表 */
|
|
|
public final static String FILE_INF_REPORT_SUBMIT = "fileInfReportSubmit";
|
|
|
|
|
|
-
|
|
|
- /** 报告数据详情 */
|
|
|
- public final static String REPORT_INF_DETAIL = "reportInfDetail";
|
|
|
-
|
|
|
-
|
|
|
/** 报告下载 */
|
|
|
public final static String REPORT_DOWN_LOAD = "reportDownLoad";
|
|
|
|
|
|
-
|
|
|
- /** 报告删除 */
|
|
|
- public final static String REPORT_INF_DELETE = "reportInfDelete";
|
|
|
-
|
|
|
-
|
|
|
/** 报告修改 */
|
|
|
public final static String REPORT_INF_UPDATE = "reportInfUpdate";
|
|
|
@MINAction(value = REPORT_INF_QUERY)
|
|
|
@@ -206,16 +202,152 @@ public class XlgzzReportAction implements IMINAction {
|
|
|
Map<String, Object> param = new HashMap<String, Object>();
|
|
|
param.put("reportId", reportId);
|
|
|
param.put("reportTypeId","XLGZZRB");
|
|
|
-
|
|
|
+ String fileName = "";
|
|
|
List<Map<String,String>> list = db.getMybatisMapper(IReportBatchMapper.class).selectReportInfo(param);
|
|
|
- String range = "";
|
|
|
- String timeRange = "";
|
|
|
if(list != null && !list.isEmpty()){
|
|
|
param.put("range",list.get(0).get("DAYINTERVAL")) ;
|
|
|
param.put("timeRange",list.get(0).get("TIMEINTERVAL"));
|
|
|
+ fileName = list.get(0).get("FILENAME");
|
|
|
+ }else{
|
|
|
+ param.put("range","19000101-19000101") ;
|
|
|
+ param.put("timeRange","000000-235959");
|
|
|
}
|
|
|
Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
|
|
|
+ resMap.put("fileName",fileName);
|
|
|
res.set(IMINBusinessConstant.F_PAGING_LAY, resMap);
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ @MINAction(value = REPORT_DOWN_LOAD)
|
|
|
+ public MINActionResult reportDownLoad(
|
|
|
+ @MINParam(key = "reportId") String reportId,
|
|
|
+ HttpServletResponse response
|
|
|
+ ) throws Exception {
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ db = Service.lookup(IMINDataBaseService.class);
|
|
|
+ // 报表类型id
|
|
|
+ Map<String, Object> param = new HashMap<String, Object>();
|
|
|
+ param.put("reportId", reportId);
|
|
|
+ param.put("reportTypeId","XLGZZRB");
|
|
|
+ List<Map<String,String>> list = db.getMybatisMapper(IReportBatchMapper.class).selectReportInfo(param);
|
|
|
+ String fileName = "";
|
|
|
+ if(list != null && !list.isEmpty()){
|
|
|
+ param.put("range",list.get(0).get("DAYINTERVAL")) ;
|
|
|
+ param.put("timeRange",list.get(0).get("TIMEINTERVAL"));
|
|
|
+ fileName = list.get(0).get("FILENAME");
|
|
|
+ }else{
|
|
|
+ param.put("range","19000101-19000101") ;
|
|
|
+ param.put("timeRange","000000-235959");
|
|
|
+ }
|
|
|
+ if("".equals(fileName)){
|
|
|
+ fileName = "线路重过载日报";
|
|
|
+ }
|
|
|
+ Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
|
|
|
+ //导出Excel
|
|
|
+ OutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ XSSFWorkbook wb = export(response, fileName, resMap);
|
|
|
+ if(wb != null){
|
|
|
+ wb.write(out);
|
|
|
+ }
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ public <T> XSSFWorkbook export(HttpServletResponse response, String fileName, Map<String, Object> map) throws Exception {
|
|
|
+ // 设置请求
|
|
|
+ response.setContentType("application/application/vnd.ms-excel");
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
+ "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "UTF-8"));
|
|
|
+ // 创建一个Workbook,对应一个Excel文件
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
+ //******************************************线路重载明细******************************************//
|
|
|
+ // 标题数组
|
|
|
+ String[] titleArray = new String[]{"单位","供电所","线路名称","重载时长(h)","平均负载率(%)"};
|
|
|
+ // 字段名数组
|
|
|
+ String[] fieldArray = new String[]{"DFD10_XGSMC","DFD10_BZMC","DFD10_XLMC","sum","avg"};
|
|
|
+ Map<String,Object> temp = (Map<String, Object>) map.get("resList");
|
|
|
+ List<String> tempList = (List<String>) temp.get("descStr");
|
|
|
+ StringBuffer descxl = new StringBuffer();
|
|
|
+ descxl.append(tempList.get(0))
|
|
|
+ .append("/r/n")
|
|
|
+ .append(tempList.get(1));
|
|
|
+ List<Map<String,String>> dataList = (List<Map<String, String>>) temp.get("result");
|
|
|
+ int index = 0;
|
|
|
+ index = this.XlzgzCreateSheet(wb,index,"线路重载明细",titleArray,fieldArray,descxl.toString(),dataList,new HashMap<String,String>());
|
|
|
+
|
|
|
+ //******************************************线路过载明细******************************************//
|
|
|
+ titleArray[3] = "过载时长(h)";
|
|
|
+ List<Map<String,String>> dataList2 = (List<Map<String, String>>) temp.get("result2");
|
|
|
+ index = this.XlzgzCreateSheet(wb,index,"线路过载明细",titleArray,fieldArray,"",dataList2,new HashMap<String,String>());
|
|
|
+
|
|
|
+ //******************************************公变重载明细******************************************//
|
|
|
+ String[] titleArray2 = new String[]{"单位","供电所","公变名称","重载时长(h)","平均负载率(%)","原因","解决措施"};
|
|
|
+ String[] fieldArray2 = new String[]{"DFD9_UNIT","DFD9_BZMC","DFD9_GBMC","DFD9_ZZSC","avg","DFD9_JTYY","DFD9_JTJJCS"};
|
|
|
+ List<String> tempList2 = (List<String>) temp.get("descStr2");
|
|
|
+ StringBuffer descxl2 = new StringBuffer();
|
|
|
+ descxl2.append(tempList2.get(0))
|
|
|
+ .append("/r/n")
|
|
|
+ .append(tempList2.get(1));
|
|
|
+ List<Map<String,String>> dataList3 = (List<Map<String, String>>) temp.get("result3");
|
|
|
+ index = this.XlzgzCreateSheet(wb,index,"公变重载明细",titleArray2,fieldArray2,descxl2.toString(),dataList3,new HashMap<String,String>());
|
|
|
+
|
|
|
+ //******************************************公变过载明细******************************************//
|
|
|
+ titleArray2[3] = "过载时长(h)";
|
|
|
+ List<Map<String,String>> dataList4 = (List<Map<String, String>>) temp.get("result4");
|
|
|
+ index = this.XlzgzCreateSheet(wb,index,"公变过载明细",titleArray2,fieldArray2,"",dataList4,new HashMap<String,String>());
|
|
|
+
|
|
|
+ //******************************************抢修类工单明细******************************************//
|
|
|
+ String[] titleArray3 = new String[]{"客户总量(户)","平均到达现场时间(分)","工单处理平均时长(分)","到达现场超时数",
|
|
|
+ "工单时长超70分钟数","客户内部故障","低压故障","非电力故障","电能质量等故障"};
|
|
|
+ String[] fieldArray3 = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
|
|
|
+ index = this.XlzgzCreateSheet(wb,index,"抢修类工单报表明细",titleArray3,fieldArray3,"",new ArrayList<>(),new HashMap<String,String>());
|
|
|
+ return wb;
|
|
|
+ }
|
|
|
+ private static int XlzgzCreateSheet(XSSFWorkbook wb,int sheetIndex, String sheetName,String[] titleArray,String[] fieldArray,String descStr,List<Map<String,String>> list,Map<String,String> map){
|
|
|
+ XSSFSheet sheet = wb.createSheet(sheetName);
|
|
|
+ int rowIndex = 0;
|
|
|
+ String title = StringUtil.ObjectToString(map.get("title"));
|
|
|
+ if(!"".equals(title)){
|
|
|
+ XSSFRow row0 = sheet.createRow((int) rowIndex);// 行数从0开始
|
|
|
+ row0.setHeightInPoints(30);//设置行的高度
|
|
|
+ XSSFCell celldesc = row0.createCell(0);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0,0,0,titleArray.length));//合并单元格
|
|
|
+ celldesc.setCellValue(StringUtil.ObjectToString(title));
|
|
|
+ celldesc.setCellStyle(ExportUtils.getDescCellStyle(wb));
|
|
|
+ rowIndex ++;
|
|
|
+ }
|
|
|
+ if(!"".equals(descStr)){
|
|
|
+ //添加描述行
|
|
|
+ XSSFRow row0 = sheet.createRow((int) rowIndex);// 行数从0开始
|
|
|
+ row0.setHeightInPoints(30);//设置行的高度
|
|
|
+ XSSFCell celldesc = row0.createCell(0);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0,0,0,titleArray.length));//合并单元格
|
|
|
+ celldesc.setCellValue(StringUtil.ObjectToString(descStr));
|
|
|
+ celldesc.setCellStyle(ExportUtils.getDescCellStyle(wb));
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+ if(titleArray.length > 0){
|
|
|
+ // 添加标题行
|
|
|
+ XSSFRow row1 = sheet.createRow((int) rowIndex);
|
|
|
+ for (int i = 0; i < titleArray.length; i++) {
|
|
|
+ XSSFCell titleCell = row1.createCell(i );// 0号位被序号占用,所以需+1
|
|
|
+ titleCell.setCellValue(titleArray[i]);
|
|
|
+ titleCell.setCellStyle(ExportUtils.getTitleCellStyle(wb));
|
|
|
+ sheet.setColumnWidth(i, 30 * 256);
|
|
|
+ }
|
|
|
+ rowIndex ++;
|
|
|
+ }
|
|
|
+ //数据列
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ //创建行
|
|
|
+ XSSFRow rowr = sheet.createRow((int) rowIndex + i);
|
|
|
+ for (int j = 0; j < fieldArray.length; j++) {
|
|
|
+ XSSFCell cell = rowr.createCell(j);
|
|
|
+ cell.setCellValue(StringUtil.ObjectToString(list.get(i).get(fieldArray[j])));
|
|
|
+ cell.setCellStyle(ExportUtils.getTextCellStyle(wb));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|