TQTDReportAction.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. package com.minpay.reportManage.action;
  2. import java.io.OutputStream;
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.text.ParseException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import javax.servlet.http.HttpServletResponse;
  10. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  11. import com.minpay.common.format.IFormatService;
  12. import com.minpay.common.service.IReportService;
  13. import com.minpay.common.util.CommonUtil;
  14. import com.minpay.common.util.DateUtil;
  15. import com.minpay.common.util.ExportExcelUtil;
  16. import com.minpay.db.table.mapper.DwFileDetail00Mapper;
  17. import com.minpay.db.table.mapper.DwReportInfMapper;
  18. import com.minpay.db.table.mapper.PubAppparMapper;
  19. import com.minpay.db.table.model.DwFileDetail00;
  20. import com.minpay.db.table.model.DwFileDetail00Example;
  21. import com.minpay.db.table.model.DwReportInf;
  22. import com.minpay.db.table.model.PubApppar;
  23. import com.minpay.db.table.model.PubAppparExample;
  24. import com.minpay.db.table.own.mapper.ReportServiceMapper;
  25. import com.startup.minpay.frame.business.IMINAction;
  26. import com.startup.minpay.frame.business.res.MINActionResult;
  27. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  28. import com.startup.minpay.frame.exception.MINBusinessException;
  29. import com.startup.minpay.frame.jdbc.MINRowBounds;
  30. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  31. import com.startup.minpay.frame.service.base.Service;
  32. import com.startup.minpay.frame.session.MINSession;
  33. import com.startup.minpay.frame.target.MINAction;
  34. import com.startup.minpay.frame.target.MINComponent;
  35. import com.startup.minpay.frame.target.MINParam;
  36. @MINComponent
  37. public class TQTDReportAction implements IMINAction {
  38. private IMINDataBaseService db;
  39. /** 台区停电日报穿透数据 */
  40. public final static String REPORT_INF_CHUANTOU = "reportInfChuantou";
  41. /** 台区停电月报附件 */
  42. public final static String REPORT_INF_FUJIAN = "reportInfFujian";
  43. /** 台区数量管理 */
  44. public final static String AREA_NUM_MANAGE = "areaNumManage";
  45. /** 台区数量编辑 */
  46. public final static String AREA_NUM_UPDATE = "areaNumUpdate";
  47. /**
  48. * 台区停电穿透数据
  49. * @param reportId 报表id
  50. * @param chuantouType 穿透类型
  51. * @param session
  52. * @return
  53. * @throws MINBusinessException
  54. * @throws ParseException
  55. * @throws InvocationTargetException
  56. * @throws IllegalArgumentException
  57. * @throws IllegalAccessException
  58. * @throws SecurityException
  59. * @throws NoSuchMethodException
  60. */
  61. @MINAction(value = REPORT_INF_CHUANTOU)
  62. public MINActionResult reportInfChuantou(
  63. @MINParam(key = "reportId") String reportId,
  64. @MINParam(key = "chuantouType") String chuantouType,
  65. MINSession session
  66. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  67. MINActionResult res = new MINActionResult();
  68. db = Service.lookup(IMINDataBaseService.class);
  69. //分页
  70. MINRowBounds rows = new MINRowBounds();
  71. rows.setSeparateSql(true);
  72. // 查询报表具体信息
  73. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  74. // 报表时间范围
  75. Map<String, Object> param = new HashMap<String, Object>();
  76. String dayInterval = reportInf.getDayInterval();
  77. String timeInterval = reportInf.getTimeInterval();
  78. String[] dayIntervalArray = dayInterval.split("-");
  79. String[] timeIntervalArray = timeInterval.split("-");
  80. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  81. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  82. param.put("beginTime", beginTime);
  83. param.put("endTime", endTime);
  84. // 台区次数穿透数据
  85. if ("TQTD01".equals(chuantouType)) {
  86. List<Map<String, String>> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  87. fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date");
  88. fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime");
  89. res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00);
  90. // month个月停电count次及以上台区穿透
  91. } else if ("TQTD02".equals(chuantouType)) {
  92. String monthNum = reportInf.getTqtdMonth();
  93. String countNum = reportInf.getTqtdCount();
  94. // monthNum个月内停电 countNum次以上的台区
  95. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  96. param.put("beginDay", beginDay);
  97. param.put("endDay", dayIntervalArray[1]);
  98. param.put("countNum", countNum);
  99. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  100. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  101. DwFileDetail00Example example = new DwFileDetail00Example();
  102. example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
  103. example.setOrderByClause("DFD0_ADDRESS_NUM");
  104. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  105. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  106. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  107. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  108. // month个月停电count次及以上台区且昨日停电穿透
  109. } else if ("TQTD03".equals(chuantouType)) {
  110. String monthNum = reportInf.getTqtdMonth();
  111. String countNum = reportInf.getTqtdCount();
  112. // monthNum个月内停电 countNum次以上的台区
  113. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  114. param.put("beginDay", beginDay);
  115. param.put("endDay", dayIntervalArray[1]);
  116. param.put("countNum", countNum);
  117. // 查询昨日停电的数据
  118. param.put("yesterday", DateUtil.dateAddDay(dayIntervalArray[1], -1));
  119. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  120. param.put("yesterdayDetail", yesterdayList);
  121. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  122. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  123. DwFileDetail00Example example = new DwFileDetail00Example();
  124. example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
  125. example.setOrderByClause("DFD0_ADDRESS_NUM");
  126. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  127. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  128. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  129. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  130. // 2个月停电1次及以上台区且昨日停电穿透
  131. } else if ("TQTD04".equals(chuantouType)) {
  132. String monthNum = "2";
  133. String countNum = "1";
  134. // monthNum个月内停电 countNum次以上的台区
  135. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  136. param.put("beginDay", beginDay);
  137. param.put("endDay", dayIntervalArray[1]);
  138. param.put("countNum", countNum);
  139. // 查询昨日停电的数据
  140. param.put("yesterday", DateUtil.dateAddDay(dayIntervalArray[1], -1));
  141. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  142. param.put("yesterdayDetail", yesterdayList);
  143. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  144. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  145. DwFileDetail00Example example = new DwFileDetail00Example();
  146. example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
  147. example.setOrderByClause("DFD0_ADDRESS_NUM");
  148. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  149. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  150. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  151. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  152. // 台区停电时户数
  153. } else if ("TQTD05".equals(chuantouType)) {
  154. List<Map<String, String>> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  155. fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date");
  156. fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime");
  157. res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00);
  158. }
  159. return res;
  160. }
  161. /**
  162. * 台区停电附件导出
  163. * @param reportId
  164. * @param response
  165. * @param session
  166. * @return
  167. * @throws MINBusinessException
  168. * @throws ParseException
  169. * @throws NoSuchMethodException
  170. * @throws SecurityException
  171. * @throws IllegalAccessException
  172. * @throws IllegalArgumentException
  173. * @throws InvocationTargetException
  174. */
  175. @MINAction(value = REPORT_INF_FUJIAN)
  176. public HttpServletResponse reportInfFujian(
  177. @MINParam(key = "reportId") String reportId,
  178. HttpServletResponse response,
  179. MINSession session
  180. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  181. db = Service.lookup(IMINDataBaseService.class);
  182. //分页
  183. MINRowBounds rows = new MINRowBounds();
  184. rows.setSeparateSql(true);
  185. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  186. // 日期区间
  187. String dayInterval = reportInf.getDayInterval();
  188. // 时分秒区间
  189. String timeInterval = reportInf.getTimeInterval();
  190. // 获取时分秒
  191. String beginTime = null;
  192. String endTime = null;
  193. String[] rangeArray = dayInterval.split("-");
  194. if (CommonUtil.isEmpty(timeInterval)) {
  195. beginTime = rangeArray[0] + "000000";
  196. endTime = rangeArray[1] + "235959";
  197. } else {
  198. String[] timeRangeArray = timeInterval.split("-");
  199. beginTime = rangeArray[0] + timeRangeArray[0];
  200. endTime = rangeArray[1] + timeRangeArray[1];
  201. }
  202. Map<String, Object> param = new HashMap<String, Object>();
  203. param.put("beginTime", beginTime);
  204. param.put("endTime", endTime);
  205. String beginDay = DateUtil.dateAddMonth(rangeArray[1], Integer.parseInt("-2"));
  206. param.put("beginDay", beginDay);
  207. param.put("endDay", rangeArray[1]);
  208. param.put("countNum", "3");
  209. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  210. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  211. DwFileDetail00Example fileDetail00Example = new DwFileDetail00Example();
  212. fileDetail00Example.createCriteria().andAddressNumIn(addressNumList)
  213. .andStartTimeGreaterThanOrEqualTo(beginDay).andStartTimeLessThanOrEqualTo(rangeArray[1]);
  214. fileDetail00Example.setOrderByClause("DFD0_ADDRESS_NUM desc");
  215. List<DwFileDetail00> fileDetail00List = db.selectByExample(DwFileDetail00Mapper.class, fileDetail00Example);
  216. int i = 0;
  217. String addressNumFlag = null;
  218. List<Map<String, String>> excelList = new ArrayList<Map<String,String>>();
  219. for (int j = 0; j < fileDetail00List.size(); j ++) {
  220. DwFileDetail00 dwFileDetail00 = fileDetail00List.get(j);
  221. // 与上一条数据是否相同
  222. if (!dwFileDetail00.getAddressNum().equals(addressNumFlag) && addressNumFlag != null) {
  223. /*Map<String, String> excelMap = new HashMap<String, String>();
  224. excelMap.put("shichang", String.valueOf(i));
  225. excelList.add(excelMap);*/
  226. for (int k = 0; k < i; k ++) {
  227. Map<String, String> map = excelList.get(j - 1 - k);
  228. map.put("cishu", String.valueOf(i));
  229. }
  230. i = 0;
  231. }
  232. Map<String, String> excelMap = new HashMap<String, String>();
  233. excelMap.put("addressNum", dwFileDetail00.getAddressNum());
  234. excelMap.put("addressName", dwFileDetail00.getAddressName());
  235. excelMap.put("date", dwFileDetail00.getDate());
  236. excelMap.put("area", dwFileDetail00.getArea());
  237. excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName());
  238. excelMap.put("terminalName", dwFileDetail00.getTerminalName());
  239. excelMap.put("terminalNum", dwFileDetail00.getTerminalNum());
  240. excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress());
  241. excelMap.put("startTime", dwFileDetail00.getStartTime());
  242. excelMap.put("endTime", dwFileDetail00.getEndTime());
  243. // 时差分钟
  244. Long dateDiff = DateUtil.dateDiff(dwFileDetail00.getStartTime(), dwFileDetail00.getEndTime());
  245. // 转换成小时
  246. String shichang = CommonUtil.divide(String.valueOf(dateDiff), "60", 2);
  247. excelMap.put("shichang", shichang);
  248. excelList.add(excelMap);
  249. addressNumFlag = dwFileDetail00.getAddressNum();
  250. i ++;
  251. }
  252. Map<String, String> excelMap = new HashMap<String, String>();
  253. excelMap.put("shichang", String.valueOf(i));
  254. excelList.add(excelMap);
  255. // 格式化时间
  256. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  257. OutputStream out=null;
  258. try {
  259. String[] excelHeader = {"台区名称#addressName","数据日期#date","台区编号#addressNum","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#shichang","停电次数#cishu"};
  260. out = response.getOutputStream();
  261. HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  262. if(wb != null){
  263. wb.write(out);
  264. }
  265. out.flush();
  266. out.close();
  267. } catch (Exception e) {
  268. e.printStackTrace();
  269. }
  270. return response;
  271. }
  272. /**
  273. * 台区数量管理
  274. * @param session
  275. * @return
  276. * @throws MINBusinessException
  277. */
  278. @MINAction(value = AREA_NUM_MANAGE)
  279. public MINActionResult areaNumManage(
  280. MINSession session
  281. ) throws MINBusinessException {
  282. MINActionResult res = new MINActionResult();
  283. db = Service.lookup(IMINDataBaseService.class);
  284. PubAppparExample appparExample = new PubAppparExample();
  285. appparExample.createCriteria().andCodeEqualTo("tqtd_num");
  286. List<PubApppar> appparList = db.selectByExample(PubAppparMapper.class, appparExample);
  287. List<Map<String, String>> resList = new ArrayList<Map<String, String>>();
  288. Map<String, String> resMap = new HashMap<String, String>();
  289. resList.add(resMap);
  290. String hejiNum = "0";
  291. for (PubApppar pub : appparList) {
  292. resMap.put(pub.getValue(), pub.getShowmsg());
  293. hejiNum = CommonUtil.add(hejiNum, pub.getShowmsg());
  294. }
  295. resMap.put("合计", hejiNum);
  296. res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
  297. return res;
  298. }
  299. @MINAction(value = AREA_NUM_UPDATE)
  300. public MINActionResult areaNumUpdate(
  301. @MINParam(key = "field") String field,
  302. @MINParam(key = "value") String value,
  303. MINSession session
  304. ) throws MINBusinessException {
  305. MINActionResult res = new MINActionResult();
  306. // 修改数据库数据
  307. db = Service.lookup(IMINDataBaseService.class);
  308. PubApppar apppar = new PubApppar();
  309. apppar.setCode("tqtd_num");
  310. apppar.setValue(field);
  311. apppar.setShowmsg(value);
  312. db.updateByPrimaryKeySelective(PubAppparMapper.class, apppar);
  313. // 更新值
  314. Service.lookup(IReportService.class).reflush();
  315. return res;
  316. }
  317. }