浏览代码

月报修改

tudc 4 年之前
父节点
当前提交
986db90a51

+ 85 - 0
src/main/java/com/minpay/common/util/ExportExcelUtil.java

@@ -5,13 +5,17 @@ import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+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.HSSFFont;
@@ -20,6 +24,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
 import org.apache.poi.xssf.usermodel.XSSFColor;
@@ -30,6 +35,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.elasticsearch.common.Strings;
 
+
 public class ExportExcelUtil<T> {
 
 	// 2007 版本以上 最大支持1048576行
@@ -388,5 +394,84 @@ public class ExportExcelUtil<T> {
 			e.printStackTrace();
 		}
 	}
+	
+	
+	 public static <T> HSSFWorkbook export(HttpServletResponse response, String fileName, String[] excelHeader,
+			   Collection<T> dataList) throws Exception {
+			  // 设置请求
+			  response.setContentType("application/application/vnd.ms-excel");
+			  response.setHeader("Content-disposition",
+			    "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
+			  // 创建一个Workbook,对应一个Excel文件
+			  HSSFWorkbook wb = new HSSFWorkbook();
+			  // 设置标题样式
+			  HSSFCellStyle titleStyle = wb.createCellStyle();
+			  // 设置字体样式
+			  Font titleFont = wb.createFont();
+			  titleFont.setFontHeightInPoints((short) 12); // 字体高度
+			  titleFont.setFontName("黑体"); // 字体样式
+			  titleStyle.setFont(titleFont);
+			  // 在Workbook中添加一个sheet,对应Excel文件中的sheet
+			  HSSFSheet sheet = wb.createSheet(fileName);
+			  // 标题数组
+			  String[] titleArray = new String[excelHeader.length];
+			  // 字段名数组
+			  String[] fieldArray = new String[excelHeader.length];
+			  for (int i = 0; i < excelHeader.length; i++) {
+				  String[] tempArray = excelHeader[i].split("#");// 临时数组 分割#
+				  titleArray[i] = tempArray[0];
+				  fieldArray[i] = tempArray[1];
+			  }
+			  // 在sheet中添加标题行
+			  HSSFRow row = sheet.createRow((int) 0);// 行数从0开始
+			  HSSFCell sequenceCell = row.createCell(0);// cell列 从0开始 第一列添加序号
+			  sequenceCell.setCellValue("序号");
+			  sequenceCell.setCellStyle(titleStyle);
+			  sheet.autoSizeColumn(0);// 自动设置宽度
+			  // 为标题行赋值
+			  for (int i = 0; i < titleArray.length; i++) {
+				  HSSFCell titleCell = row.createCell(i + 1);// 0号位被序号占用,所以需+1
+				  titleCell.setCellValue(titleArray[i]);
+				  titleCell.setCellStyle(titleStyle);
+				  sheet.autoSizeColumn(i + 1);// 0号位被序号占用,所以需+1
+				  sheet.setColumnWidth(i+1,titleArray[i].getBytes().length*256+200);
+			  }
+			  // 数据样式 因为标题和数据样式不同 需要分开设置 不然会覆盖
+			  HSSFCellStyle dataStyle = wb.createCellStyle();
+			  // 设置数据字体
+			  Font dataFont = wb.createFont();
+			  dataFont.setFontHeightInPoints((short) 10); // 字体高度
+			  dataFont.setFontName("宋体"); // 字体
+			  dataStyle.setFont(dataFont);
+			  // 遍历集合数据,产生数据行
+			  Iterator<T> it = dataList.iterator();
+			  int index = 0;
+			  while (it.hasNext()) {
+				  index++;
+				  row = sheet.createRow(index);
+				  // 为序号赋值
+				  HSSFCell sequenceCellValue = row.createCell(0);// 序号值永远是第0列
+				  sequenceCellValue.setCellValue(index);
+				  sequenceCellValue.setCellStyle(dataStyle);
+//					  sheet.autoSizeColumn(0);
+				  T t = (T) it.next();
+				  Map<String, Object> map = (Map<String, Object> )t;
+				  HSSFCell dataCell = null;
+				  for (int i = 0; i < fieldArray.length; i++) {
+					  dataCell = row.createCell(i + 1);
+					  dataCell.setCellStyle(dataStyle);
+					  String fieldName = fieldArray[i];
+					  String value = CommonUtil.objToString(map.get(fieldName));
+					  if (CommonUtil.isEmpty(value)) {
+						  dataCell.setCellValue("");					// 为当前列赋值
+					  } else {
+						  dataCell.setCellValue(CommonUtil.objToString(value));// 为当前列赋值
+					  }
+					  
+				  }
+			  }
+			  sheet.setColumnWidth(fieldArray.length, 20 * 256);
+			  return wb;
+		 }
 
 }

+ 130 - 1
src/main/java/com/minpay/reportManage/action/TQTDReportAction.java

@@ -1,13 +1,25 @@
 package com.minpay.reportManage.action;
 
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
 import com.minpay.common.format.IFormatService;
+import com.minpay.common.util.CommonUtil;
 import com.minpay.common.util.DateUtil;
+import com.minpay.common.util.ExportExcelUtil;
+import com.minpay.db.table.mapper.DwFileDetail00Mapper;
 import com.minpay.db.table.mapper.DwReportInfMapper;
+import com.minpay.db.table.model.DwFileDetail00;
+import com.minpay.db.table.model.DwFileDetail00Example;
 import com.minpay.db.table.model.DwReportInf;
 import com.minpay.db.table.own.mapper.ReportServiceMapper;
 import com.startup.minpay.frame.business.IMINAction;
@@ -26,9 +38,12 @@ import com.startup.minpay.frame.target.MINParam;
 public class TQTDReportAction implements IMINAction {
 
     private IMINDataBaseService db;
-    /** 台区停电穿透数据 */
+    /** 台区停电日报穿透数据 */
     public final static String REPORT_INF_CHUANTOU = "reportInfChuantou";
     
+    /** 台区停电月报附件 */
+    public final static String REPORT_INF_FUJIAN = "reportInfFujian";
+    
     
     /**
      * 台区停电穿透数据
@@ -120,4 +135,118 @@ public class TQTDReportAction implements IMINAction {
 		
 		return res;
     }
+    
+    /**
+     * 台区停电附件导出
+     * @param reportId
+     * @param response
+     * @param session
+     * @return
+     * @throws MINBusinessException
+     * @throws ParseException
+     * @throws NoSuchMethodException
+     * @throws SecurityException
+     * @throws IllegalAccessException
+     * @throws IllegalArgumentException
+     * @throws InvocationTargetException
+     */
+    @MINAction(value = REPORT_INF_FUJIAN)
+    public HttpServletResponse reportInfFujian(
+    		@MINParam(key = "reportId") String reportId,
+    		HttpServletResponse response,
+    		MINSession session
+    		) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+    	db = Service.lookup(IMINDataBaseService.class);
+    	//分页
+    	MINRowBounds rows = new MINRowBounds();
+    	rows.setSeparateSql(true);
+    	DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
+    	// 日期区间
+    	String dayInterval = reportInf.getDayInterval();
+    	// 时分秒区间
+    	String timeInterval = reportInf.getTimeInterval();
+    	// 获取时分秒
+    	String beginTime = null;
+		String endTime = null;
+		String[] rangeArray = dayInterval.split("-");
+		if (CommonUtil.isEmpty(timeInterval)) {
+			beginTime = rangeArray[0] + "000000";
+			endTime = rangeArray[1] + "235959";
+		} else {
+			String[] timeRangeArray = timeInterval.split("-");
+			beginTime = rangeArray[0] + timeRangeArray[0];
+			endTime = rangeArray[1] + timeRangeArray[1];
+		}
+		
+		Map<String, Object> param = new HashMap<String, Object>();
+		param.put("beginTime", beginTime);
+		param.put("endTime", endTime);
+		
+		String beginDay = DateUtil.dateAddMonth(rangeArray[1], Integer.parseInt("-2"));
+		param.put("beginDay", beginDay);
+		param.put("endDay", rangeArray[1]);
+		param.put("countNum", "3");
+		List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
+		
+		List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
+		DwFileDetail00Example fileDetail00Example = new DwFileDetail00Example();
+		fileDetail00Example.createCriteria().andAddressNumIn(addressNumList)
+										.andStartTimeGreaterThanOrEqualTo(beginDay).andStartTimeLessThanOrEqualTo(rangeArray[1]);
+		fileDetail00Example.setOrderByClause("DFD0_ADDRESS_NUM desc");
+		List<DwFileDetail00> fileDetail00List = db.selectByExample(DwFileDetail00Mapper.class, fileDetail00Example);
+		int i = 0;
+		String addressNumFlag = null;
+		List<Map<String, String>> excelList = new ArrayList<Map<String,String>>();
+		for (DwFileDetail00 dwFileDetail00 : fileDetail00List) {
+			// 与上一条数据是否相同
+			if (!dwFileDetail00.getAddressNum().equals(addressNumFlag) && addressNumFlag != null) {
+				Map<String, String> excelMap = new HashMap<String, String>();
+				excelMap.put("shichang", String.valueOf(i));
+				excelList.add(excelMap);
+				i = 0;
+			}
+			Map<String, String> excelMap = new HashMap<String, String>();
+			excelMap.put("addressNum", dwFileDetail00.getAddressNum());
+			excelMap.put("addressName", dwFileDetail00.getAddressName());
+			excelMap.put("date", dwFileDetail00.getDate());
+			excelMap.put("area", dwFileDetail00.getArea());
+			excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName());
+			excelMap.put("terminalName", dwFileDetail00.getTerminalName());
+			excelMap.put("terminalNum", dwFileDetail00.getTerminalNum());
+			excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress());
+			excelMap.put("startTime", dwFileDetail00.getStartTime());
+			excelMap.put("endTime", dwFileDetail00.getEndTime());
+			// 时差分钟
+			Long dateDiff = DateUtil.dateDiff(dwFileDetail00.getStartTime(), dwFileDetail00.getEndTime());
+			// 转换成小时
+			String shichang = CommonUtil.divide(String.valueOf(dateDiff), "60", 2);
+			excelMap.put("shichang", shichang);
+			excelList.add(excelMap);
+			addressNumFlag = dwFileDetail00.getAddressNum();
+			i ++;
+		}
+		
+		Map<String, String> excelMap = new HashMap<String, String>();
+		excelMap.put("shichang", String.valueOf(i));
+		excelList.add(excelMap);
+		
+		// 格式化时间
+		excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
+		
+		OutputStream out=null;
+		try {
+			String[] excelHeader = {"台区名称#addressName","数据日期#date","台区编号#addressNum","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#shichang"};
+			out = response.getOutputStream();
+			HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
+			if(wb != null){
+				wb.write(out);
+			}
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
+    	return response;
+    }
 }

+ 39 - 2
src/main/webapp/admin/tqtd/reportManageDetailTqtd.html

@@ -10,6 +10,10 @@
 	<div class="shadow-content" style="margin:1.5rem; text-align: center;">
 		<p id = "reportTitle" style="margin:15px; font-size : 20px"></p>
     	<table id="reportTable" class="layui-table"></table>
+    	<div id = "reportDiv" style = "margin : 20px; text-align : left;"></div>
+    	<div id = "reportFujian" style = "margin : 20px; text-align : right;">
+    		<a style = "color : red;" onclick = "downLoadFujian()">附件下载</a>
+    	</div>
 	</div>
     <script>
 	var pageId = getQueryString("pageId");
@@ -23,6 +27,8 @@
 	
 	// excel
 	if ("00" == type) {
+		$("#reportDiv").hide();
+		$("#reportFujian").hide();
 		$("#reportTitle").html(fileName);
 		$.request({
 			action : 'ReportManageAction/reportInfDetail',
@@ -40,7 +46,35 @@
 	  	});
 	// word
 	} else {
-		
+		$("#reportTable").hide();
+		$("#reportTitle").html(fileName);
+		$.request({
+			action : 'ReportManageAction/reportInfDetail',
+			data : {
+				reportId : reportId
+			},
+			success : function(data) {
+				var reportDataJsonStr = data.data.data;
+				var reportDataJson = eval('(' + reportDataJsonStr + ')');
+				var reportDesc = "<p>(1)台区停电总体情况${month}月份,台区累计停电${benyueCount}台次,同比${tongbi},环比${huanbi},涉及${shejiNum}个台区,${shejiDesc}</p>"
+					+ "<p>(2)台区停电时长情况${totalCount}个台区累计停电时间${benyueTime}小时,平均停电时长${pingjunHour}小时,同比${tongbiPingjunHour},环比${huanbiPingjunHour}。台区平均停电时间为${areaPingjunDesc}从同比情况看,${tbAreaPingjunDesc}</p>"
+					+ "<p>台区停电时长在${fenduanDesc}停电时长最长的为${zuichangTaiQu},停电${zuichangTaiQuTime}小时,其次是${qiciTaiQu},停电时长${qiciTaiQuTime}小时。</p>"
+					+ "<p>(3)台区重复停电情况两个月内停电2次及以上的台变${totalCountTwice}个,其中${totalCountTwiceDesc}${totalCountTwice}个重复停电台变中,${countMapTwiceDesc}两个月内停电3次及以上的台变${totalCountthiple}个。</p>";
+				
+				for(var key in reportDataJson){
+					var replaceStr = "${" + key + "}";
+					if (key == "totalCountTwice") {
+						reportDesc = reportDesc.replace(/\${totalCountTwice}/g, reportDataJson[key]);
+					} else {
+						reportDesc = reportDesc.replace(replaceStr, reportDataJson[key]);
+					}
+				}
+				$("#reportDiv").html(reportDesc);
+			},
+			error : function(data2) {
+				$.ErrorAlert(data2.MINErrorMessage);
+			}
+	  	});
 	}
 	
 	function reportTable(excelList, typeId, isEdit) {
@@ -95,7 +129,10 @@
 		openMainTabPage(openPageId, "详情", "tqtd/reportManageDetailChuantou.html?pageId="+openPageId+"&reportId="+reportId+"&chuantouType=TQTD04", '', pageId, null);
 	}
 	
-
+	function downLoadFujian() {
+		var data = {reportId : reportId};
+		exportExcel("../../TQTDReportAction/reportInfFujian",data);
+	}
     </script>
 </body>
 

+ 3 - 1
src/main/webapp/admin/tqtd/reportManageTqtd.html

@@ -40,7 +40,9 @@
 	</div>
 	<script type="text/html" id="barDemo">
 		<a class="layui-btn layui-btn-xs" lay-event="detail">详情查看</a>
-		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
+		{{#  if(timeType != '02'){ }}
+			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
+		{{#  } }}
      	<a class="layui-btn layui-btn-xs" lay-event="downLoad">下载</a>
 		<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
    	</script>

+ 25 - 1
src/main/webapp/js/min.js

@@ -1158,9 +1158,33 @@ function format45(num,n){
     return f;
 }
 
+// URL参数重新编码,解决get方式汉字乱码问题
 function chineseUrlEncode(str) {
 	return encodeURI(encodeURI(str))
 }
+//URL参数解码,解决get方式汉字乱码问题
 function chineseUrlDecodeURI(str) {
 	return decodeURI(decodeURI(str))
-}
+}
+
+//组装下载
+function exportExcel(action,data){
+	var tempForm = document.createElement("form");     
+    tempForm.id="tempForm1";     
+    tempForm.method="post";     
+    tempForm.action=action;     
+    tempForm.target = '下载';     
+	for(var k in data){ 
+		var hideInput = document.createElement("input");     
+	   hideInput.type="hidden";     
+	   hideInput.name= k;  
+	   hideInput.value= data[k];   
+	   tempForm.appendChild(hideInput);  
+	}    
+    tempForm.addEventListener("onsubmit",function(){ 
+    	self.open(action,name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
+    });   
+    document.body.appendChild(tempForm);     
+    tempForm.submit();   
+    document.body.removeChild(tempForm);
+}