XlgzzReportAction.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. package com.minpay.reportManage.action;
  2. import com.minpay.common.bean.User;
  3. import com.minpay.common.constant.Constant;
  4. import com.minpay.common.format.IFormatService;
  5. import com.minpay.common.service.IReportService;
  6. import com.minpay.common.util.DateUtil;
  7. import com.minpay.common.util.ExportUtils;
  8. import com.minpay.db.table.mapper.DwReportInfMapper;
  9. import com.minpay.db.table.model.DwReportInf;
  10. import com.minpay.db.table.own.mapper.IReportBatchMapper;
  11. import com.minpay.db.table.own.mapper.ReportManageMapper;
  12. import com.minpay.db.table.own.mapper.SequenceMapper;
  13. import com.startup.minpay.frame.business.IMINAction;
  14. import com.startup.minpay.frame.business.res.MINActionResult;
  15. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  16. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  17. import com.startup.minpay.frame.exception.MINBusinessException;
  18. import com.startup.minpay.frame.jdbc.MINRowBounds;
  19. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  20. import com.startup.minpay.frame.service.base.Service;
  21. import com.startup.minpay.frame.session.MINSession;
  22. import com.startup.minpay.frame.target.MINAction;
  23. import com.startup.minpay.frame.target.MINComponent;
  24. import com.startup.minpay.frame.target.MINParam;
  25. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  26. import org.apache.poi.xssf.usermodel.*;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.io.IOException;
  29. import java.io.OutputStream;
  30. import java.lang.reflect.InvocationTargetException;
  31. import java.net.URLEncoder;
  32. import java.text.ParseException;
  33. import java.util.*;
  34. @MINComponent
  35. public class XlgzzReportAction implements IMINAction {
  36. private IMINDataBaseService db;
  37. /** 报表查询 */
  38. public final static String REPORT_INF_QUERY = "reportInfQuery";
  39. /** 根据不同的报表类型查询对应时间范围类的所需数据 */
  40. public final static String REPORT_NEED_DATA_DETAIL = "reportNeedDataDetail";
  41. public final static String REPORT_NEED_DATA_DETAIL2 = "reportNeedDataDetail2";
  42. /** 生成报表 */
  43. public final static String FILE_INF_REPORT_SUBMIT = "fileInfReportSubmit";
  44. /** 报告下载 */
  45. public final static String REPORT_DOWN_LOAD = "reportDownLoad";
  46. /** 报告修改 */
  47. public final static String REPORT_INF_UPDATE = "reportInfUpdate";
  48. @MINAction(value = REPORT_INF_QUERY)
  49. public MINActionResult reportInfQuery(
  50. @MINParam(key = "page", defaultValue = "1") int page,
  51. @MINParam(key = "limit", defaultValue = "10") int limit,
  52. @MINParam(key = "date") String date,
  53. @MINParam(key = "fileName") String fileName,
  54. @MINParam(key = "timeType") String timeType,
  55. @MINParam(key = "reportType") String reportType,
  56. MINSession session
  57. ) throws MINBusinessException {
  58. MINActionResult res = new MINActionResult();
  59. db = Service.lookup(IMINDataBaseService.class);
  60. //分页
  61. MINRowBounds rows = new MINRowBounds(page, limit);
  62. rows.setSeparateSql(true);
  63. Map<String, Object> param = new HashMap<String, Object>();
  64. param.put("date", date);
  65. param.put("fileName", fileName);
  66. param.put("timeType", timeType);
  67. param.put("reportType", reportType);
  68. User user = session.getUser();
  69. String roleId = user.getRoleId();
  70. // 非系统管理员
  71. if (!Constant.ROLE_ID.equals(roleId)) {
  72. param.put("branchId", user.getBranchid());
  73. }
  74. List<Map<String, String>> list = db.getMybatisMapper(ReportManageMapper.class).selectReportInf(param, rows);
  75. list = Service.lookup(IFormatService.class).formatDate(list, "uploadDate");
  76. // 设置返回值
  77. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  78. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  79. return res;
  80. }
  81. @MINAction(value = FILE_INF_REPORT_SUBMIT, transaction = IMINTransactionEnum.CMT)
  82. public MINActionResult fileInfReportSubmit(
  83. @MINParam(key = "reportData") String reportData,
  84. @MINParam(key = "reportInf") String reportInf,
  85. @MINParam(key = "fileName") String fileName,
  86. @MINParam(key = "monthNum") String monthNum,
  87. @MINParam(key = "countNum") String countNum,
  88. @MINParam(key = "range") String range,
  89. @MINParam(key = "timeRange") String timeRange,
  90. @MINParam(key = "firstFileId") String firstFileId,
  91. @MINParam(key = "secondFileId") String secondFileId,
  92. @MINParam(key = "ddyFxbId") String ddyFxbId,
  93. @MINParam(key = "yearChoose") String yearChoose,
  94. @MINParam(key = "monthChoose") String monthChoose,
  95. MINSession session
  96. ) throws MINBusinessException {
  97. db = Service.lookup(IMINDataBaseService.class);
  98. MINActionResult res = new MINActionResult();
  99. String reportId = db.getMybatisMapper(SequenceMapper.class).getSequence("REPORT_INF_NO");
  100. String reportType = reportInf.split("_")[1];
  101. String reportTypeId = reportInf.split("_")[0];
  102. // 不生成报表数据表,实时计算
  103. // DwReportData reportDataInf = new DwReportData();
  104. // reportDataInf.setId(reportId);//
  105. // reportDataInf.setData(reportData);
  106. // reportDataInf.setType(reportType);
  107. // db.insertSelective(DwReportDataMapper.class, reportDataInf);
  108. User user = session.getUser();
  109. // 生成报告表
  110. DwReportInf report = new DwReportInf();
  111. report.setId(reportId);//报表ID
  112. report.setUploadDate(DateUtil.getCurrentDateString());//更新时间
  113. report.setFileName(fileName);//文件名
  114. report.setCreatUser(user.getId());//当前登录用户ID
  115. report.setBranch(user.getBranchid());//所属结构(班组)
  116. report.setType(reportTypeId);//dw_branch_report_type.DBRT_ID
  117. report.setZdttyCompareId(firstFileId + "-" + secondFileId);
  118. report.setTqtdMonth(monthNum); // 台区停电【month个月内停电count次及以上台区】的month
  119. report.setTqtdCount(countNum); // 台区停电【month个月内停电count次及以上台区】的count
  120. report.setDdyFxbId(ddyFxbId);
  121. report.setDayInterval(range.replaceAll(" ", "")); // 日期时间段
  122. report.setTimeInterval(timeRange.replaceAll(" ", "")); // 时分秒时间段
  123. report.setYearInterval(yearChoose.replaceAll(" ", ""));
  124. report.setMonthInterval(monthChoose.replaceAll(" ", ""));
  125. db.insertSelective(DwReportInfMapper.class, report);
  126. return res;
  127. }
  128. @MINAction(value = REPORT_NEED_DATA_DETAIL)
  129. public MINActionResult reportNeedDataDetail(
  130. @MINParam(key = "monthChoose") String monthChoose,
  131. @MINParam(key = "range") String range,
  132. @MINParam(key = "timeRange") String timeRange,
  133. @MINParam(key = "reportInf") String reportInf,
  134. @MINParam(key = "monthNum") String monthNum,
  135. @MINParam(key = "countNum") String countNum,
  136. @MINParam(key = "firstFileId") String firstFileId,
  137. @MINParam(key = "secondFileId") String secondFileId,
  138. @MINParam(key = "FADateRange") String FADateRange,
  139. @MINParam(key = "yearChoose") String yearChoose,
  140. @MINParam(key = "DdyDateRange") String DdyDateRange,
  141. @MINParam(key = "ddyFxbId") String ddyFxbId
  142. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InvalidFormatException, IOException {
  143. MINActionResult res = new MINActionResult();
  144. // 报表类型id
  145. String reportTypeId = reportInf.split("_")[0];
  146. Map<String, Object> param = new HashMap<String, Object>();
  147. param.put("monthChoose", monthChoose);
  148. param.put("range", range);
  149. param.put("timeRange", timeRange);
  150. param.put("reportTypeId", reportTypeId);
  151. param.put("monthNum", monthNum);
  152. param.put("countNum", countNum);
  153. param.put("firstFileId", firstFileId);
  154. param.put("secondFileId", secondFileId);
  155. param.put("FADateRange", FADateRange);
  156. param.put("yearChoose", yearChoose);
  157. param.put("DdyDateRange", DdyDateRange);
  158. param.put("ddyFxbId", ddyFxbId);
  159. Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
  160. res.set(IMINBusinessConstant.F_PAGING_LAY, resMap);
  161. return res;
  162. }
  163. @MINAction(value = REPORT_NEED_DATA_DETAIL2)
  164. public MINActionResult reportNeedDataDetail2(
  165. @MINParam(key = "reportId") String reportId,
  166. @MINParam(key = "reportType") String reportType
  167. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InvalidFormatException, IOException {
  168. MINActionResult res = new MINActionResult();
  169. db = Service.lookup(IMINDataBaseService.class);
  170. // 报表类型id
  171. Map<String, Object> param = new HashMap<String, Object>();
  172. param.put("reportId", reportId);
  173. param.put("reportTypeId",reportType);
  174. if("XLGZZRB".equals(reportType)){
  175. param.put("timeType","00");
  176. }else{
  177. param.put("timeType","01");
  178. }
  179. String fileName = "";
  180. List<Map<String,String>> list = db.getMybatisMapper(IReportBatchMapper.class).selectReportInfo(param);
  181. if(list != null && !list.isEmpty()){
  182. param.put("range",list.get(0).get("DAYINTERVAL")) ;
  183. param.put("timeRange",list.get(0).get("TIMEINTERVAL"));
  184. fileName = list.get(0).get("FILENAME");
  185. }else{
  186. param.put("range","19000101-19000101") ;
  187. param.put("timeRange","000000-235959");
  188. }
  189. Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
  190. resMap.put("fileName",fileName);
  191. res.set(IMINBusinessConstant.F_PAGING_LAY, resMap);
  192. return res;
  193. }
  194. @MINAction(value = REPORT_DOWN_LOAD)
  195. public MINActionResult reportDownLoad(
  196. @MINParam(key = "reportId") String reportId,
  197. @MINParam(key = "timeType") String timeType,
  198. @MINParam(key = "reportType") String reportType,
  199. HttpServletResponse response
  200. ) throws Exception {
  201. MINActionResult res = new MINActionResult();
  202. db = Service.lookup(IMINDataBaseService.class);
  203. // 报表类型id
  204. Map<String, Object> param = new HashMap<String, Object>();
  205. param.put("reportId", reportId);
  206. param.put("reportTypeId",reportType);
  207. param.put("timeType",timeType);
  208. List<Map<String,String>> list = db.getMybatisMapper(IReportBatchMapper.class).selectReportInfo(param);
  209. String fileName = "";
  210. if(list != null && !list.isEmpty()){
  211. param.put("range",list.get(0).get("DAYINTERVAL")) ;
  212. param.put("timeRange",list.get(0).get("TIMEINTERVAL"));
  213. fileName = list.get(0).get("FILENAME");
  214. }else{
  215. param.put("range","19000101-19000101") ;
  216. param.put("timeRange","000000-235959");
  217. }
  218. if("".equals(fileName)){
  219. fileName = "线路重过载日报";
  220. }
  221. Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
  222. //导出Excel
  223. OutputStream out = null;
  224. out = response.getOutputStream();
  225. XSSFWorkbook wb = export(response, fileName, resMap);
  226. try {
  227. if(wb != null){
  228. wb.write(out);
  229. }
  230. }catch (Exception e){
  231. e.printStackTrace();
  232. }finally {
  233. if(wb != null){
  234. }
  235. if(out != null){
  236. out.flush();
  237. out.close();
  238. }
  239. }
  240. return res;
  241. }
  242. public <T> XSSFWorkbook export(HttpServletResponse response, String fileName, Map<String, Object> map) throws Exception {
  243. // 设置请求
  244. response.setContentType("application/application/vnd.ms-excel");
  245. response.setHeader("Content-disposition",
  246. "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "UTF-8"));
  247. // 创建一个Workbook,对应一个Excel文件
  248. XSSFWorkbook wb = new XSSFWorkbook();
  249. //******************************************线路重载明细******************************************//
  250. // 标题数组
  251. String[] titleArray = new String[]{"单位","供电所","线路名称","重载时长(h)","平均负载率(%)"};
  252. // 字段名数组
  253. String[] fieldArray = new String[]{"DFD17_XGSMC","DFD17_BZMC","DFD17_XLMC","sum","avg"};
  254. Map<String,Object> temp = (Map<String, Object>) map.get("resList");
  255. List<String> tempList = (List<String>) temp.get("descStr");
  256. StringBuffer descxl = new StringBuffer();
  257. descxl
  258. .append(" ")
  259. .append(tempList.get(0))
  260. .append("\r\n")
  261. .append(" ")
  262. .append(tempList.get(1))
  263. .append("\n")
  264. .append(" ")
  265. .append("注:线路负载率持续1小时在70%-100%为重载,持续1小时在100%以上为过载。");
  266. List<Map<String,String>> dataList = (List<Map<String, String>>) temp.get("result");
  267. int index = 0;
  268. ExportUtils.XlzgzCreateSheet(wb,index,"线路重载明细",titleArray,fieldArray,descxl.toString(),dataList,new HashMap<String,String>());
  269. //******************************************线路过载明细******************************************//
  270. titleArray[3] = "过载时长(h)";
  271. List<Map<String,String>> dataList2 = (List<Map<String, String>>) temp.get("result2");
  272. ExportUtils.XlzgzCreateSheet(wb,index,"线路过载明细",titleArray,fieldArray,"",dataList2,new HashMap<String,String>());
  273. //******************************************公变过载明细******************************************//
  274. String[] titleArray2 = new String[]{"单位","供电所","公变名称","重载时长(h)","平均负载率(%)","原因","解决措施"};
  275. String[] fieldArray2 = new String[]{"DFD13_UNIT","DFD13_BZMC","DFD13_GBMC","DFD13_ZZSC","avg","DFD13_JTYY","DFD13_JTJJCS"};
  276. List<String> tempList2 = (List<String>) temp.get("descStr2");
  277. StringBuffer descxl2 = new StringBuffer();
  278. descxl2
  279. .append(" ")
  280. .append(tempList2.get(0))
  281. .append("\r\n")
  282. .append(" ")
  283. .append(tempList2.get(1))
  284. .append("\r\n")
  285. .append(" ")
  286. .append("注:配变负载率连续2小时在80%-100%之间为重载,连续2小时在100%以上为过载。");
  287. List<Map<String,String>> dataList4 = (List<Map<String, String>>) temp.get("result4");
  288. ExportUtils.XlzgzCreateSheet(wb,index,"公变重载明细",titleArray2,fieldArray2,descxl2.toString(),dataList4,new HashMap<String,String>());
  289. //******************************************公变重载明细******************************************//
  290. titleArray2[3] = "过载时长(h)";
  291. fieldArray2[3] = "DFD13_GZSC";
  292. List<Map<String,String>> dataList3 = (List<Map<String, String>>) temp.get("result3");
  293. index = ExportUtils.XlzgzCreateSheet(wb,index,"公变过载明细",titleArray2,fieldArray2,"",dataList3,new HashMap<String,String>());
  294. // //******************************************抢修类工单明细******************************************//
  295. // String[] titleArray3 = new String[]{"单位","客户总量(户)","平均到达现场时间(分)","工单处理平均时长(分)","到达现场超时数",
  296. // "工单时长超70分钟数","故障类型#客户内部故障","故障类型#低压故障","故障类型#非电力故障","故障类型#电能质量等故障","疑似虚假回单","工单总数","万户报修率"};
  297. // String[] fieldArray3 = new String[]{"DFD11_GDDW","KHZS","DDXCSJ","GDCLSJ","DDXCCSS","GDCSZS","GZLS-A","GZLS-B","GZLS-C","GZLS-D","YSXJHD","GDZS","WH","","","",""};
  298. // List<Map<String,String>> dataList5 = (List<Map<String, String>>) temp.get("result5");
  299. // String tempList3 = String.valueOf(temp.get("descStr3"));
  300. // ExportUtils.XlzgzCreateSheet(wb,index,"抢修类工单报表明细",titleArray3,fieldArray3,tempList3,dataList5,new HashMap<String,String>());
  301. return wb;
  302. }
  303. }