TQTDReportAction.java 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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.DwFileDetail98Mapper;
  18. import com.minpay.db.table.mapper.DwFileDetail99Mapper;
  19. import com.minpay.db.table.mapper.DwReportInfMapper;
  20. import com.minpay.db.table.mapper.PubAppparMapper;
  21. import com.minpay.db.table.model.DwFileDetail00;
  22. import com.minpay.db.table.model.DwFileDetail00Example;
  23. import com.minpay.db.table.model.DwFileDetail98;
  24. import com.minpay.db.table.model.DwFileDetail98Example;
  25. import com.minpay.db.table.model.DwFileDetail99;
  26. import com.minpay.db.table.model.DwFileDetail99Example;
  27. import com.minpay.db.table.model.DwReportInf;
  28. import com.minpay.db.table.model.PubApppar;
  29. import com.minpay.db.table.model.PubAppparExample;
  30. import com.minpay.db.table.own.mapper.ReportServiceMapper;
  31. import com.startup.minpay.frame.business.IMINAction;
  32. import com.startup.minpay.frame.business.res.MINActionResult;
  33. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  34. import com.startup.minpay.frame.exception.MINBusinessException;
  35. import com.startup.minpay.frame.jdbc.MINRowBounds;
  36. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  37. import com.startup.minpay.frame.service.base.Service;
  38. import com.startup.minpay.frame.session.MINSession;
  39. import com.startup.minpay.frame.target.MINAction;
  40. import com.startup.minpay.frame.target.MINComponent;
  41. import com.startup.minpay.frame.target.MINParam;
  42. @MINComponent
  43. public class TQTDReportAction implements IMINAction {
  44. private IMINDataBaseService db;
  45. /** 台区停电日报穿透数据 */
  46. public final static String REPORT_INF_CHUANTOU = "reportInfChuantou";
  47. /** 台区停电月报附件 */
  48. public final static String REPORT_INF_FUJIAN = "reportInfFujian";
  49. /** 台区数量管理 */
  50. public final static String AREA_NUM_MANAGE = "areaNumManage";
  51. /** 台区数量编辑 */
  52. public final static String AREA_NUM_UPDATE = "areaNumUpdate";
  53. /**穿透导出详情*/
  54. public final static String REPORT_INF_FUJIAN_CHUANTOU = "reportInfFujianChuantou";
  55. /**红黄蓝督办预警下载*/
  56. public final static String DOWN_RB_HHL = "downRbHhl";
  57. /** 台区停电周报报穿透数据 */
  58. public final static String REPORT_INF_ZB_CHUANTOU = "reportInfZbChuantou";
  59. /** 台区停电周报报穿透数据下载 */
  60. public final static String REPORT_INF_ZB_CHUANTOU_DOWN = "reportInfZbChuantouDown";
  61. /**
  62. * 台区停电穿透数据
  63. * @param reportId 报表id
  64. * @param chuantouType 穿透类型
  65. * @param session
  66. * @return
  67. * @throws MINBusinessException
  68. * @throws ParseException
  69. * @throws InvocationTargetException
  70. * @throws IllegalArgumentException
  71. * @throws IllegalAccessException
  72. * @throws SecurityException
  73. * @throws NoSuchMethodException
  74. */
  75. @MINAction(value = REPORT_INF_CHUANTOU)
  76. public MINActionResult reportInfChuantou(
  77. @MINParam(key = "reportId") String reportId,
  78. @MINParam(key = "chuantouType") String chuantouType,
  79. MINSession session
  80. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  81. MINActionResult res = new MINActionResult();
  82. db = Service.lookup(IMINDataBaseService.class);
  83. //分页
  84. MINRowBounds rows = new MINRowBounds();
  85. rows.setSeparateSql(true);
  86. // 查询报表具体信息
  87. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  88. // 报表时间范围
  89. Map<String, Object> param = new HashMap<String, Object>();
  90. String dayInterval = reportInf.getDayInterval();
  91. String timeInterval = reportInf.getTimeInterval();
  92. String[] dayIntervalArray = dayInterval.split("-");
  93. String[] timeIntervalArray = timeInterval.split("-");
  94. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  95. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  96. param.put("beginTime", beginTime);
  97. param.put("endTime", endTime);
  98. // 台区次数穿透数据
  99. if ("TQTD01".equals(chuantouType)) {
  100. List<Map<String, String>> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  101. fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date");
  102. fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime");
  103. res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00);
  104. // month个月停电count次及以上台区穿透
  105. } else if ("TQTD02".equals(chuantouType)) {
  106. String monthNum = reportInf.getTqtdMonth();
  107. String countNum = reportInf.getTqtdCount();
  108. // monthNum个月内停电 countNum次以上的台区
  109. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  110. param.put("beginDay", beginDay);
  111. param.put("endDay", dayIntervalArray[1]);
  112. param.put("countNum", countNum);
  113. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  114. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  115. if (addressNumList.size() == 0) {
  116. return res;
  117. }
  118. DwFileDetail00Example example = new DwFileDetail00Example();
  119. example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
  120. example.setOrderByClause("DFD0_ADDRESS_NUM");
  121. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  122. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  123. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  124. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  125. // month个月停电count次及以上台区且当日停电穿透
  126. } else if ("TQTD03".equals(chuantouType)) {
  127. String monthNum = reportInf.getTqtdMonth();
  128. String countNum = reportInf.getTqtdCount();
  129. // monthNum个月内停电 countNum次以上的台区
  130. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  131. param.put("beginDay", beginDay + timeIntervalArray[0]);
  132. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  133. param.put("countNum", countNum);
  134. // 查询当日停电的数据
  135. param.put("yesterday", dayIntervalArray[1]);
  136. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  137. param.put("yesterdayDetail", yesterdayList);
  138. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  139. if (mountCountList.size() == 0) {
  140. return res;
  141. }
  142. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  143. param.put("addressNumList", addressNumList);
  144. List<Map<String, String>> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  145. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  146. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  147. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  148. // 2个月停电2次台区且当日停电穿透
  149. } else if ("TQTD04".equals(chuantouType)) {
  150. String monthNum = "2";
  151. String countNum = "2";
  152. // monthNum个月内停电 countNum次以上的台区
  153. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  154. param.put("beginDay", beginDay + timeIntervalArray[0]);
  155. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  156. param.put("countNum", countNum);
  157. // 查询当日停电的数据
  158. param.put("yesterday", dayIntervalArray[1]);
  159. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  160. param.put("yesterdayDetail", yesterdayList);
  161. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param);
  162. if (mountCountList.size() == 0) {
  163. return res;
  164. }
  165. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  166. param.put("addressNumList", addressNumList);
  167. List<Map<String, String>> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  168. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  169. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  170. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  171. // 台区停电时户数
  172. } else if ("TQTD05".equals(chuantouType)) {
  173. List<Map<String, String>> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  174. fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date");
  175. fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime");
  176. res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00);
  177. // 2个月停电1次台区且当日停电穿透
  178. }else if ("TQTD06".equals(chuantouType)) {
  179. String monthNum = "2";
  180. String countNum = "1";
  181. // monthNum个月内停电 countNum次以上的台区
  182. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  183. param.put("beginDay", beginDay + timeIntervalArray[0]);
  184. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  185. param.put("countNum", countNum);
  186. // 查询当日停电的数据
  187. param.put("yesterday", dayIntervalArray[1]);
  188. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  189. if (yesterdayList.size() == 0) {
  190. return res;
  191. }
  192. param.put("yesterdayDetail", yesterdayList);
  193. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param);
  194. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  195. param.put("addressNumList", addressNumList);
  196. List<Map<String, String>> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  197. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  198. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  199. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  200. }
  201. return res;
  202. }
  203. @MINAction(value = REPORT_INF_FUJIAN_CHUANTOU)
  204. public HttpServletResponse reportInfFujianChuantou(
  205. @MINParam(key = "reportId") String reportId,
  206. @MINParam(key = "chuantouType") String chuantouType,
  207. HttpServletResponse response,
  208. MINSession session
  209. )throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  210. //分页
  211. MINRowBounds rows = new MINRowBounds();
  212. rows.setSeparateSql(true);
  213. // 查询报表具体信息
  214. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  215. // 报表时间范围
  216. Map<String, Object> param = new HashMap<String, Object>();
  217. String dayInterval = reportInf.getDayInterval();
  218. String timeInterval = reportInf.getTimeInterval();
  219. String[] dayIntervalArray = dayInterval.split("-");
  220. String[] timeIntervalArray = timeInterval.split("-");
  221. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  222. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  223. param.put("beginTime", beginTime);
  224. param.put("endTime", endTime);
  225. List<Map<String, String>> excelList = null;
  226. // 台区次数穿透数据
  227. if ("TQTD01".equals(chuantouType)) {
  228. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  229. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  230. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  231. // month个月停电count次及以上台区穿透
  232. } else if ("TQTD02".equals(chuantouType)) {
  233. String monthNum = reportInf.getTqtdMonth();
  234. String countNum = reportInf.getTqtdCount();
  235. // monthNum个月内停电 countNum次以上的台区
  236. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  237. param.put("beginDay", beginDay);
  238. param.put("endDay", dayIntervalArray[1]);
  239. param.put("countNum", countNum);
  240. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  241. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  242. if (addressNumList.size() == 0) {
  243. excelList = new ArrayList<>();
  244. } else {
  245. excelList = new ArrayList<>();
  246. DwFileDetail00Example example = new DwFileDetail00Example();
  247. example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
  248. example.setOrderByClause("DFD0_ADDRESS_NUM");
  249. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  250. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  251. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  252. for (DwFileDetail00 dwFileDetail00:selectByExample) {
  253. Map<String, String> excelMap = new HashMap<String, String>();
  254. excelMap.put("addressNum", dwFileDetail00.getAddressNum());
  255. excelMap.put("addressName", dwFileDetail00.getAddressName());
  256. excelMap.put("date", dwFileDetail00.getDate());
  257. excelMap.put("area", dwFileDetail00.getArea());
  258. excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName());
  259. excelMap.put("terminalName", dwFileDetail00.getTerminalName());
  260. excelMap.put("terminalNum", dwFileDetail00.getTerminalNum());
  261. excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress());
  262. excelMap.put("startTime", dwFileDetail00.getStartTime());
  263. excelMap.put("endTime", dwFileDetail00.getEndTime());
  264. excelList.add(excelMap);
  265. }
  266. }
  267. // month个月停电count次及以上台区且当日停电穿透
  268. } else if ("TQTD03".equals(chuantouType)) {
  269. String monthNum = reportInf.getTqtdMonth();
  270. String countNum = reportInf.getTqtdCount();
  271. // monthNum个月内停电 countNum次以上的台区
  272. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  273. param.put("beginDay", beginDay + timeIntervalArray[0]);
  274. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  275. param.put("countNum", countNum);
  276. // 查询当日停电的数据
  277. param.put("yesterday", dayIntervalArray[1]);
  278. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  279. param.put("yesterdayDetail", yesterdayList);
  280. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  281. if (mountCountList.size() == 0) {
  282. excelList = new ArrayList<>();
  283. } else {
  284. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  285. param.put("addressNumList", addressNumList);
  286. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  287. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  288. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  289. }
  290. // 2个月停电2次台区且当日停电穿透
  291. } else if ("TQTD04".equals(chuantouType)) {
  292. String monthNum = "2";
  293. String countNum = "2";
  294. // monthNum个月内停电 countNum次以上的台区
  295. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  296. param.put("beginDay", beginDay + timeIntervalArray[0]);
  297. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  298. param.put("countNum", countNum);
  299. // 查询当日停电的数据
  300. param.put("yesterday", dayIntervalArray[1]);
  301. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  302. param.put("yesterdayDetail", yesterdayList);
  303. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param);
  304. if (mountCountList.size() == 0) {
  305. excelList = new ArrayList<>();
  306. } else {
  307. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  308. param.put("addressNumList", addressNumList);
  309. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  310. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  311. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  312. }
  313. // 台区停电时户数
  314. } else if ("TQTD05".equals(chuantouType)) {
  315. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  316. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  317. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  318. for (Map<String, String> m : excelList) {
  319. m.put("hour", CommonUtil.divide(m.get("time"), "60", 2));
  320. }
  321. // 2个月停电1次台区且当日停电穿透
  322. }else if ("TQTD06".equals(chuantouType)) {
  323. String monthNum = "2";
  324. String countNum = "1";
  325. // monthNum个月内停电 countNum次以上的台区
  326. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  327. param.put("beginDay", beginDay + timeIntervalArray[0]);
  328. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  329. param.put("countNum", countNum);
  330. // 查询当日停电的数据
  331. param.put("yesterday", dayIntervalArray[1]);
  332. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  333. if (yesterdayList.size() == 0) {
  334. excelList = new ArrayList<>();
  335. } else {
  336. param.put("yesterdayDetail", yesterdayList);
  337. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param);
  338. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  339. param.put("addressNumList", addressNumList);
  340. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  341. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  342. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  343. }
  344. }
  345. OutputStream out=null;
  346. try {
  347. out = response.getOutputStream();
  348. HSSFWorkbook wb = null;
  349. if ("TQTD01".equals(chuantouType)) {
  350. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  351. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  352. } else if ("TQTD02".equals(chuantouType)) {
  353. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  354. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  355. } else if ("TQTD03".equals(chuantouType)) {
  356. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","停电时间#startTime","来电时间#endTime"};
  357. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  358. } else if ("TQTD04".equals(chuantouType)) {
  359. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  360. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  361. } else if ("TQTD05".equals(chuantouType)) {
  362. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#hour"};
  363. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  364. } else if ("TQTD06".equals(chuantouType)) {
  365. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  366. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  367. }
  368. if(wb != null){
  369. wb.write(out);
  370. }
  371. out.flush();
  372. out.close();
  373. } catch (Exception e) {
  374. e.printStackTrace();
  375. }
  376. return response;
  377. }
  378. /**
  379. * 台区停电附件导出
  380. * @param reportId
  381. * @param response
  382. * @param session
  383. * @return
  384. * @throws MINBusinessException
  385. * @throws ParseException
  386. * @throws NoSuchMethodException
  387. * @throws SecurityException
  388. * @throws IllegalAccessException
  389. * @throws IllegalArgumentException
  390. * @throws InvocationTargetException
  391. */
  392. @MINAction(value = REPORT_INF_FUJIAN)
  393. public HttpServletResponse reportInfFujian(
  394. @MINParam(key = "reportId") String reportId,
  395. HttpServletResponse response,
  396. MINSession session
  397. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  398. db = Service.lookup(IMINDataBaseService.class);
  399. //分页
  400. MINRowBounds rows = new MINRowBounds();
  401. rows.setSeparateSql(true);
  402. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  403. // 日期区间
  404. String dayInterval = reportInf.getDayInterval();
  405. // 时分秒区间
  406. String timeInterval = reportInf.getTimeInterval();
  407. // 获取时分秒
  408. String beginTime = null;
  409. String endTime = null;
  410. String[] rangeArray = dayInterval.split("-");
  411. if (CommonUtil.isEmpty(timeInterval)) {
  412. beginTime = rangeArray[0] + "000000";
  413. endTime = rangeArray[1] + "235959";
  414. } else {
  415. String[] timeRangeArray = timeInterval.split("-");
  416. beginTime = rangeArray[0] + timeRangeArray[0];
  417. endTime = rangeArray[1] + timeRangeArray[1];
  418. }
  419. Map<String, Object> param = new HashMap<String, Object>();
  420. param.put("beginTime", beginTime);
  421. param.put("endTime", endTime);
  422. String beginDay = DateUtil.dateAddMonth(rangeArray[1], Integer.parseInt("-2"));
  423. param.put("beginDay", beginDay);
  424. param.put("endDay", rangeArray[1]);
  425. param.put("countNum", "3");
  426. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  427. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  428. if(addressNumList == null || addressNumList.isEmpty()){
  429. addressNumList.add("XXXXXXXX");
  430. }
  431. DwFileDetail00Example fileDetail00Example = new DwFileDetail00Example();
  432. fileDetail00Example.createCriteria().andAddressNumIn(addressNumList)
  433. .andStartTimeGreaterThanOrEqualTo(beginDay).andStartTimeLessThanOrEqualTo(rangeArray[1]);
  434. fileDetail00Example.setOrderByClause("DFD0_ADDRESS_NUM desc");
  435. List<DwFileDetail00> fileDetail00List = db.selectByExample(DwFileDetail00Mapper.class, fileDetail00Example);
  436. int i = 0;
  437. String addressNumFlag = null;
  438. List<Map<String, String>> excelList = new ArrayList<Map<String,String>>();
  439. for (int j = 0; j < fileDetail00List.size(); j ++) {
  440. DwFileDetail00 dwFileDetail00 = fileDetail00List.get(j);
  441. // 与上一条数据是否相同
  442. if (!dwFileDetail00.getAddressNum().equals(addressNumFlag) && addressNumFlag != null) {
  443. for (int k = 0; k < i; k ++) {
  444. Map<String, String> map = excelList.get(j - 1 - k);
  445. map.put("cishu", String.valueOf(i));
  446. }
  447. i = 0;
  448. }
  449. Map<String, String> excelMap = new HashMap<String, String>();
  450. excelMap.put("addressNum", dwFileDetail00.getAddressNum());
  451. excelMap.put("addressName", dwFileDetail00.getAddressName());
  452. excelMap.put("date", dwFileDetail00.getDate());
  453. excelMap.put("area", dwFileDetail00.getArea());
  454. excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName());
  455. excelMap.put("terminalName", dwFileDetail00.getTerminalName());
  456. excelMap.put("terminalNum", dwFileDetail00.getTerminalNum());
  457. excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress());
  458. excelMap.put("startTime", dwFileDetail00.getStartTime());
  459. excelMap.put("endTime", dwFileDetail00.getEndTime());
  460. // 时差分钟
  461. Long dateDiff = DateUtil.dateDiff(dwFileDetail00.getStartTime(), dwFileDetail00.getEndTime());
  462. // 转换成小时
  463. String shichang = CommonUtil.divide(String.valueOf(dateDiff), "60", 2);
  464. excelMap.put("shichang", shichang);
  465. excelList.add(excelMap);
  466. addressNumFlag = dwFileDetail00.getAddressNum();
  467. i ++;
  468. if (j == fileDetail00List.size() - 1) {
  469. for (int k = 0; k < i; k ++) {
  470. Map<String, String> map = excelList.get(j - k);
  471. map.put("cishu", String.valueOf(i));
  472. }
  473. }
  474. }
  475. // 格式化时间
  476. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  477. OutputStream out = null;
  478. try {
  479. String[] excelHeader = {"台区名称#addressName","数据日期#date","台区编号#addressNum","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#shichang","停电次数#cishu"};
  480. out = response.getOutputStream();
  481. HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  482. if(wb != null){
  483. wb.write(out);
  484. }
  485. out.flush();
  486. out.close();
  487. } catch (Exception e) {
  488. e.printStackTrace();
  489. }
  490. return response;
  491. }
  492. /**
  493. * 台区数量管理
  494. * @param session
  495. * @return
  496. * @throws MINBusinessException
  497. */
  498. @MINAction(value = AREA_NUM_MANAGE)
  499. public MINActionResult areaNumManage(
  500. MINSession session
  501. ) throws MINBusinessException {
  502. MINActionResult res = new MINActionResult();
  503. db = Service.lookup(IMINDataBaseService.class);
  504. PubAppparExample appparExample = new PubAppparExample();
  505. String systemCode = Service.lookup(IReportService.class).getSystemCode();
  506. appparExample.createCriteria().andCodeEqualTo("tqtd_num_" + systemCode);
  507. List<PubApppar> appparList = db.selectByExample(PubAppparMapper.class, appparExample);
  508. List<Map<String, String>> resList = new ArrayList<Map<String, String>>();
  509. Map<String, String> resMap = new HashMap<String, String>();
  510. resList.add(resMap);
  511. String hejiNum = "0";
  512. List<Map<String, Object>> col = new ArrayList<Map<String, Object>>();
  513. for (PubApppar pub : appparList) {
  514. resMap.put(pub.getValue(), pub.getShowmsg());
  515. hejiNum = CommonUtil.add(hejiNum, pub.getShowmsg());
  516. Map<String, Object> colMap = new HashMap<String, Object>();
  517. colMap.put("field", pub.getValue());
  518. colMap.put("title", pub.getValue());
  519. colMap.put("edit", "text");
  520. col.add(colMap);
  521. }
  522. Map<String, Object> colHejiMap = new HashMap<String, Object>();
  523. colHejiMap.put("field", "合计");
  524. colHejiMap.put("title", "合计");
  525. col.add(colHejiMap);
  526. resMap.put("合计", hejiNum);
  527. res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
  528. res.set("col", col);
  529. return res;
  530. }
  531. @MINAction(value = AREA_NUM_UPDATE)
  532. public MINActionResult areaNumUpdate(
  533. @MINParam(key = "field") String field,
  534. @MINParam(key = "value") String value,
  535. MINSession session
  536. ) throws MINBusinessException {
  537. MINActionResult res = new MINActionResult();
  538. String systemCode = Service.lookup(IReportService.class).getSystemCode();
  539. // 修改数据库数据
  540. db = Service.lookup(IMINDataBaseService.class);
  541. PubApppar apppar = new PubApppar();
  542. apppar.setCode("tqtd_num_"+systemCode);
  543. apppar.setValue(field);
  544. apppar.setShowmsg(value);
  545. db.updateByPrimaryKeySelective(PubAppparMapper.class, apppar);
  546. // 更新值
  547. Service.lookup(IReportService.class).reflush();
  548. return res;
  549. }
  550. @MINAction(value = DOWN_RB_HHL)
  551. public MINActionResult downRbHhl(
  552. @MINParam(key = "reportId") String reportId,
  553. HttpServletResponse response,
  554. MINSession session
  555. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  556. db = Service.lookup(IMINDataBaseService.class);
  557. MINActionResult res = new MINActionResult();
  558. // 查询报表具体信息
  559. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  560. // 报表时间范围
  561. Map<String, Object> param = new HashMap<String, Object>();
  562. String dayInterval = reportInf.getDayInterval();
  563. String timeInterval = reportInf.getTimeInterval();
  564. String[] dayIntervalArray = dayInterval.split("-");
  565. String[] timeIntervalArray = timeInterval.split("-");
  566. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  567. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  568. param.put("beginTime", beginTime);
  569. param.put("endTime", endTime);
  570. List<Map<String, String>> excelList = null;
  571. String monthNum = reportInf.getTqtdMonth();
  572. String countNum = "1";
  573. // monthNum个月内停电 countNum次以上的台区
  574. String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum));
  575. param.put("beginDay", beginDay + timeIntervalArray[0]);
  576. param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]);
  577. param.put("countNum", countNum);
  578. // 查询当日停电的数据
  579. param.put("yesterday", dayIntervalArray[1]);
  580. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  581. param.put("yesterdayDetail", yesterdayList);
  582. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  583. if (mountCountList.size() == 0) {
  584. excelList = new ArrayList<>();
  585. } else {
  586. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  587. param.put("addressNumList", addressNumList);
  588. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  589. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  590. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  591. }
  592. List<String> addressNameList = CommonUtil.getIdFromList(excelList, "addressName");
  593. // 线路台账(供服)
  594. DwFileDetail98Example dwFileDetail98Example = new DwFileDetail98Example();
  595. dwFileDetail98Example.createCriteria().andGbmcIn(addressNameList);
  596. List<DwFileDetail98> gfList = db.getMybatisMapper(DwFileDetail98Mapper.class).selectByExample(dwFileDetail98Example);
  597. // 匹配供服台账的线路数据
  598. for (Map<String, String> e : excelList) {
  599. for (DwFileDetail98 d : gfList) {
  600. if (d.getGbmc().equals(e.get("addressName"))) {
  601. e.put("ssxl", d.getSskx());
  602. break;
  603. }
  604. }
  605. }
  606. DwFileDetail99Example dwFileDetail99Example = new DwFileDetail99Example();
  607. dwFileDetail99Example.createCriteria().andTqIn(addressNameList);
  608. List<DwFileDetail99> yxList = db.getMybatisMapper(DwFileDetail99Mapper.class).selectByExample(dwFileDetail99Example);
  609. // 匹配营销台账的线路数据
  610. for (Map<String, String> e : excelList) {
  611. for (DwFileDetail99 d : yxList) {
  612. if (CommonUtil.isEmpty(e.get("ssxl")) && d.getTq().equals(e.get("addressName"))) {
  613. e.put("ssxl", d.getTq());
  614. break;
  615. }
  616. }
  617. }
  618. OutputStream out=null;
  619. try {
  620. out = response.getOutputStream();
  621. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","所属线路#ssxl"};
  622. HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  623. if(wb != null){
  624. wb.write(out);
  625. }
  626. out.flush();
  627. out.close();
  628. } catch (Exception e) {
  629. e.printStackTrace();
  630. }
  631. return res;
  632. }
  633. @MINAction(value = REPORT_INF_ZB_CHUANTOU)
  634. public MINActionResult reportInfZbChuantou(
  635. @MINParam(key = "reportId") String reportId,
  636. @MINParam(key = "chuantouType") String chuantouType,
  637. MINSession session
  638. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  639. MINActionResult res = new MINActionResult();
  640. db = Service.lookup(IMINDataBaseService.class);
  641. //分页
  642. MINRowBounds rows = new MINRowBounds();
  643. rows.setSeparateSql(true);
  644. // 查询报表具体信息
  645. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  646. // 报表时间范围
  647. Map<String, Object> param = new HashMap<String, Object>();
  648. String dayInterval = reportInf.getDayInterval();
  649. String timeInterval = reportInf.getTimeInterval();
  650. String[] dayIntervalArray = dayInterval.split("-");
  651. String[] timeIntervalArray = timeInterval.split("-");
  652. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  653. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  654. param.put("beginTime", beginTime);
  655. param.put("endTime", endTime);
  656. // 停电台区数
  657. if ("TQTD00".equals(chuantouType)) {
  658. param.put("beginDay", beginTime);
  659. param.put("endDay", endTime);
  660. List<Map<String, String>> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  661. res.set(IMINBusinessConstant.F_PAGING_LAY, tqCountList);
  662. // 本周累计停电台次
  663. }else if ("TQTD01".equals(chuantouType)) {
  664. DwFileDetail00Example example = new DwFileDetail00Example();
  665. example.createCriteria().andStartTimeGreaterThanOrEqualTo(beginTime).andEndTimeLessThanOrEqualTo(endTime);
  666. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  667. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  668. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  669. res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample);
  670. // 本周重复停电台区数
  671. } else if ("TQTD02".equals(chuantouType)) {
  672. param.put("beginDay", beginTime);
  673. param.put("endDay", endTime);
  674. param.put("countNum", "2");
  675. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  676. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  677. if (addressNumList.size() == 0) {
  678. return res;
  679. }
  680. param.put("addressNumList", addressNumList);
  681. List<Map<String, String>> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  682. res.set(IMINBusinessConstant.F_PAGING_LAY, tqCountList);
  683. // 本周督办频繁停电台次
  684. } else if ("TQTD03".equals(chuantouType)) {
  685. List<Map<String, String>> resList = new ArrayList<>();
  686. String begin = dayIntervalArray[0];
  687. String end = dayIntervalArray[1];
  688. while (CommonUtil.compare(begin, end) != 1) {
  689. param.put("yesterday", begin);
  690. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  691. if (yesterdayList.size() == 0) {
  692. begin = DateUtil.dateAddDay(begin, 1);
  693. continue;
  694. }
  695. param.put("yesterdayDetail", yesterdayList);
  696. param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  697. param.put("endDay", begin + endTime.substring(8, 14));
  698. param.put("countNum", 3);
  699. List<Map<String, String>> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  700. List<String> addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum");
  701. if (addressNumList.size() != 0) {
  702. param.put("beginTime", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  703. param.put("endTime", begin + endTime.substring(8, 14));
  704. param.put("addressNumList", addressNumList);
  705. List<Map<String, String>> selectReportType00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  706. for (Map<String, String> map : selectReportType00) {
  707. map.put("queryDate", begin);
  708. }
  709. resList.addAll(selectReportType00);
  710. }
  711. // 天数 + 1
  712. begin = DateUtil.dateAddDay(begin, 1);
  713. }
  714. resList = Service.lookup(IFormatService.class).formatDate(resList, "date", "queryDate");
  715. resList = Service.lookup(IFormatService.class).formatDateTime(resList, "startTime", "endTime");
  716. res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
  717. // 本周督办频繁停电台区数
  718. } else if ("TQTD04".equals(chuantouType)) {
  719. List<Map<String, String>> resList = new ArrayList<>();
  720. String begin = dayIntervalArray[0];
  721. String end = dayIntervalArray[1];
  722. while (CommonUtil.compare(begin, end) != 1) {
  723. param.put("yesterday", begin);
  724. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  725. if (yesterdayList.size() == 0) {
  726. begin = DateUtil.dateAddDay(begin, 1);
  727. continue;
  728. }
  729. param.put("yesterdayDetail", yesterdayList);
  730. param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  731. param.put("endDay", begin + endTime.substring(8, 14));
  732. param.put("countNum", 3);
  733. List<Map<String, String>> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  734. List<String> addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum");
  735. if (addressNumList.size() != 0) {
  736. param.put("addressNumList", addressNumList);
  737. List<Map<String, String>> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  738. for (Map<String, String> t : tqCountList) {
  739. t.put("date", begin);
  740. }
  741. resList.addAll(tqCountList);
  742. }
  743. // 天数 + 1
  744. begin = DateUtil.dateAddDay(begin, 1);
  745. }
  746. resList = Service.lookup(IFormatService.class).formatDate(resList, "date");
  747. res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
  748. }
  749. return res;
  750. }
  751. @MINAction(value = REPORT_INF_ZB_CHUANTOU_DOWN)
  752. public MINActionResult reportInfZbChuantouDown(
  753. @MINParam(key = "reportId") String reportId,
  754. @MINParam(key = "chuantouType") String chuantouType,
  755. HttpServletResponse response,
  756. MINSession session
  757. )throws MINBusinessException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ParseException{
  758. MINActionResult res = new MINActionResult();
  759. db = Service.lookup(IMINDataBaseService.class);
  760. //分页
  761. MINRowBounds rows = new MINRowBounds();
  762. rows.setSeparateSql(true);
  763. // 查询报表具体信息
  764. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  765. // 报表时间范围
  766. Map<String, Object> param = new HashMap<String, Object>();
  767. String dayInterval = reportInf.getDayInterval();
  768. String timeInterval = reportInf.getTimeInterval();
  769. String[] dayIntervalArray = dayInterval.split("-");
  770. String[] timeIntervalArray = timeInterval.split("-");
  771. String beginTime = dayIntervalArray[0] + timeIntervalArray[0];
  772. String endTime = dayIntervalArray[1] + timeIntervalArray[1];
  773. param.put("beginTime", beginTime);
  774. param.put("endTime", endTime);
  775. List<Map<String, String>> excelList = new ArrayList<>();
  776. // 停电台区数
  777. if ("TQTD00".equals(chuantouType)) {
  778. param.put("beginDay", beginTime);
  779. param.put("endDay", endTime);
  780. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  781. // 本周累计停电台次
  782. }else if ("TQTD01".equals(chuantouType)) {
  783. DwFileDetail00Example example = new DwFileDetail00Example();
  784. example.createCriteria().andStartTimeGreaterThanOrEqualTo(beginTime).andEndTimeLessThanOrEqualTo(endTime);
  785. List<DwFileDetail00> selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example);
  786. selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date");
  787. selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime");
  788. for (DwFileDetail00 dwFileDetail00:selectByExample) {
  789. Map<String, String> excelMap = new HashMap<String, String>();
  790. excelMap.put("addressNum", dwFileDetail00.getAddressNum());
  791. excelMap.put("addressName", dwFileDetail00.getAddressName());
  792. excelMap.put("date", dwFileDetail00.getDate());
  793. excelMap.put("area", dwFileDetail00.getArea());
  794. excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName());
  795. excelMap.put("terminalName", dwFileDetail00.getTerminalName());
  796. excelMap.put("terminalNum", dwFileDetail00.getTerminalNum());
  797. excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress());
  798. excelMap.put("startTime", dwFileDetail00.getStartTime());
  799. excelMap.put("endTime", dwFileDetail00.getEndTime());
  800. excelList.add(excelMap);
  801. }
  802. // 本周重复停电台区数
  803. } else if ("TQTD02".equals(chuantouType)) {
  804. param.put("beginDay", beginTime);
  805. param.put("endDay", endTime);
  806. param.put("countNum", "2");
  807. List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  808. List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
  809. if (addressNumList.size() == 0) {
  810. return res;
  811. }
  812. param.put("addressNumList", addressNumList);
  813. excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  814. // 本周督办频繁停电台次
  815. } else if ("TQTD03".equals(chuantouType)) {
  816. String begin = dayIntervalArray[0];
  817. String end = dayIntervalArray[1];
  818. while (CommonUtil.compare(begin, end) != 1) {
  819. param.put("yesterday", begin);
  820. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  821. if (yesterdayList.size() == 0) {
  822. begin = DateUtil.dateAddDay(begin, 1);
  823. continue;
  824. }
  825. param.put("yesterdayDetail", yesterdayList);
  826. param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  827. param.put("endDay", begin + endTime.substring(8, 14));
  828. param.put("countNum", 3);
  829. List<Map<String, String>> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  830. List<String> addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum");
  831. if (addressNumList.size() != 0) {
  832. param.put("beginTime", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  833. param.put("endTime", begin + endTime.substring(8, 14));
  834. param.put("addressNumList", addressNumList);
  835. List<Map<String, String>> selectReportType00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param);
  836. for (Map<String, String> map : selectReportType00) {
  837. map.put("queryDate", begin);
  838. }
  839. excelList.addAll(selectReportType00);
  840. }
  841. // 天数 + 1
  842. begin = DateUtil.dateAddDay(begin, 1);
  843. }
  844. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date", "queryDate");
  845. excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime");
  846. // 本周督办频繁停电台区数
  847. } else if ("TQTD04".equals(chuantouType)) {
  848. String begin = dayIntervalArray[0];
  849. String end = dayIntervalArray[1];
  850. while (CommonUtil.compare(begin, end) != 1) {
  851. param.put("yesterday", begin);
  852. List<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
  853. if (yesterdayList.size() == 0) {
  854. begin = DateUtil.dateAddDay(begin, 1);
  855. continue;
  856. }
  857. param.put("yesterdayDetail", yesterdayList);
  858. param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14));
  859. param.put("endDay", begin + endTime.substring(8, 14));
  860. param.put("countNum", 3);
  861. List<Map<String, String>> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
  862. List<String> addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum");
  863. if (addressNumList.size() != 0) {
  864. param.put("addressNumList", addressNumList);
  865. List<Map<String, String>> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param);
  866. for (Map<String, String> t : tqCountList) {
  867. t.put("date", begin);
  868. }
  869. excelList.addAll(tqCountList);
  870. }
  871. // 天数 + 1
  872. begin = DateUtil.dateAddDay(begin, 1);
  873. }
  874. excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date");
  875. }
  876. OutputStream out=null;
  877. try {
  878. out = response.getOutputStream();
  879. HSSFWorkbook wb = null;
  880. if ("TQTD00".equals(chuantouType)) {
  881. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num"};
  882. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  883. } else if ("TQTD01".equals(chuantouType)) {
  884. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  885. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  886. } else if ("TQTD02".equals(chuantouType)) {
  887. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num"};
  888. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  889. } else if ("TQTD03".equals(chuantouType)) {
  890. String[] excelHeader = {"日报日期#queryDate","台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"};
  891. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  892. } else if ("TQTD04".equals(chuantouType)) {
  893. String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","日报日期#date"};
  894. wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList);
  895. }
  896. if(wb != null){
  897. wb.write(out);
  898. }
  899. out.flush();
  900. out.close();
  901. } catch (Exception e) {
  902. e.printStackTrace();
  903. }
  904. return res;
  905. }
  906. }