ReportManageAction.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. package com.minpay.reportManage.action;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.net.URLEncoder;
  6. import java.text.ParseException;
  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. import java.util.List;
  12. import java.util.Map;
  13. import javax.servlet.http.HttpServletResponse;
  14. import org.apache.commons.fileupload.FileItem;
  15. import org.apache.poi.hssf.usermodel.HSSFCell;
  16. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  17. import org.apache.poi.hssf.usermodel.HSSFPalette;
  18. import org.apache.poi.hssf.usermodel.HSSFRow;
  19. import org.apache.poi.hssf.usermodel.HSSFSheet;
  20. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  21. import org.apache.poi.hssf.util.HSSFColor;
  22. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  23. import org.apache.poi.ss.usermodel.CellStyle;
  24. import org.apache.poi.ss.usermodel.FillPatternType;
  25. import org.apache.poi.ss.usermodel.Font;
  26. import org.apache.poi.ss.usermodel.IndexedColors;
  27. import com.minpay.common.bean.User;
  28. import com.minpay.common.constant.Constant;
  29. import com.minpay.common.format.IFormatService;
  30. import com.minpay.common.service.IDianwangService;
  31. import com.minpay.common.service.IReportService;
  32. import com.minpay.common.util.CommonUtil;
  33. import com.minpay.common.util.DateUtil;
  34. import com.minpay.common.util.FilesUtil;
  35. import com.minpay.db.table.mapper.DwBranchReportTypeMapper;
  36. import com.minpay.db.table.mapper.DwDdyFxbDetailMapper;
  37. import com.minpay.db.table.mapper.DwDdyFxbMapper;
  38. import com.minpay.db.table.mapper.DwReportDataMapper;
  39. import com.minpay.db.table.mapper.DwReportInfMapper;
  40. import com.minpay.db.table.model.DwBranchReportType;
  41. import com.minpay.db.table.model.DwDdyFxb;
  42. import com.minpay.db.table.model.DwDdyFxbDetail;
  43. import com.minpay.db.table.model.DwDdyFxbDetailExample;
  44. import com.minpay.db.table.model.DwDdyFxbExample;
  45. import com.minpay.db.table.model.DwReportData;
  46. import com.minpay.db.table.model.DwReportInf;
  47. import com.minpay.db.table.own.mapper.ReportManageMapper;
  48. import com.minpay.db.table.own.mapper.SequenceMapper;
  49. import com.minpay.dianwang.util.ReportExcelUtil;
  50. import com.startup.minpay.frame.business.IMINAction;
  51. import com.startup.minpay.frame.business.MINHttpServletRequestContext;
  52. import com.startup.minpay.frame.business.res.MINActionResult;
  53. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  54. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  55. import com.startup.minpay.frame.exception.MINBusinessException;
  56. import com.startup.minpay.frame.jdbc.MINRowBounds;
  57. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  58. import com.startup.minpay.frame.service.base.Service;
  59. import com.startup.minpay.frame.session.MINSession;
  60. import com.startup.minpay.frame.target.MINAction;
  61. import com.startup.minpay.frame.target.MINComponent;
  62. import com.startup.minpay.frame.target.MINParam;
  63. import net.sf.json.JSONArray;
  64. @MINComponent
  65. public class ReportManageAction implements IMINAction {
  66. private IMINDataBaseService db;
  67. /** 报表查询 */
  68. public final static String REPORT_INF_QUERY = "reportInfQuery";
  69. /** 生成报表的数据查询 */
  70. public final static String FILE_INF_REPORT_QUERY = "fileInfReportQuery";
  71. /** 根据不同的报表类型查询对应时间范围类的所需数据 */
  72. public final static String REPORT_NEED_DATA_DETAIL = "reportNeedDataDetail";
  73. /** 生成报表 */
  74. public final static String FILE_INF_REPORT_SUBMIT = "fileInfReportSubmit";
  75. /** 报告数据详情 */
  76. public final static String REPORT_INF_DETAIL = "reportInfDetail";
  77. /** 报告下载 */
  78. public final static String REPORT_DOWN_LOAD = "reportDownLoad";
  79. /** 报告删除 */
  80. public final static String REPORT_INF_DELETE = "reportInfDelete";
  81. /** 报告修改 */
  82. public final static String REPORT_INF_UPDATE = "reportInfUpdate";
  83. /** 低电压分析表提交 */
  84. public final static String DDY_REPORT_INF_SUBMIT = "ddyReportInfSubmit";
  85. /** 低电压分析表详情 */
  86. public final static String DDY_REPORT_INF_DETAIL = "ddyReportInfDetail";
  87. /** 低电压分析表编辑 */
  88. public final static String DDY_REPORT_INF_UPDATE = "ddyReportInfUpdate";
  89. /** 低电压分析表下载*/
  90. public final static String DDY_REPORT_INF_DOWNLOAD = "ddyReportInfDownload";
  91. /** 低电压分析表上传*/
  92. public final static String DDY_REPORT_INF_UPLOAD = "ddyReportInfUpload";
  93. /**
  94. * 报表查询
  95. * @param page
  96. * @param limit
  97. * @param date
  98. * @param fileName
  99. * @return
  100. * @throws MINBusinessException
  101. * @throws InvocationTargetException
  102. * @throws IllegalArgumentException
  103. * @throws IllegalAccessException
  104. * @throws SecurityException
  105. * @throws NoSuchMethodException
  106. * @throws InstantiationException
  107. */
  108. @MINAction(value = REPORT_INF_QUERY)
  109. public MINActionResult reportInfQuery(
  110. @MINParam(key = "page", defaultValue = "1") int page,
  111. @MINParam(key = "limit", defaultValue = "10") int limit,
  112. @MINParam(key = "date") String date,
  113. @MINParam(key = "fileName") String fileName,
  114. @MINParam(key = "timeType") String timeType,
  115. @MINParam(key = "reportType") String reportType,
  116. MINSession session
  117. ) throws MINBusinessException {
  118. MINActionResult res = new MINActionResult();
  119. db = Service.lookup(IMINDataBaseService.class);
  120. //分页
  121. MINRowBounds rows = new MINRowBounds(page, limit);
  122. rows.setSeparateSql(true);
  123. Map<String, Object> param = new HashMap<String, Object>();
  124. param.put("date", date);
  125. param.put("fileName", fileName);
  126. param.put("timeType", timeType);
  127. param.put("reportType", reportType);
  128. User user = session.getUser();
  129. String roleId = user.getRoleId();
  130. // 非系统管理员
  131. if (!Constant.ROLE_ID.equals(roleId)) {
  132. param.put("branchId", user.getBranchid());
  133. }
  134. List<Map<String, String>> list = db.getMybatisMapper(ReportManageMapper.class).selectReportInf(param, rows);
  135. list = Service.lookup(IFormatService.class).formatDate(list, "uploadDate");
  136. // 设置返回值
  137. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  138. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  139. return res;
  140. }
  141. /**
  142. * 报告明细信息组装
  143. * @param chooseFileListStr
  144. * @param session
  145. * @return
  146. * @throws MINBusinessException
  147. */
  148. @MINAction(value = FILE_INF_REPORT_QUERY)
  149. public MINActionResult fileInfReportQuery(
  150. @MINParam(key = "chooseFileListStr") String chooseFileListStr,
  151. @MINParam(key = "page", defaultValue = "1") int page,
  152. @MINParam(key = "limit", defaultValue = "200") int limit,
  153. MINSession session
  154. ) throws MINBusinessException {
  155. MINActionResult res = new MINActionResult();
  156. MINRowBounds rows = new MINRowBounds(page, limit);
  157. rows.setSeparateSql(true);
  158. JSONArray chooseFileList = JSONArray.fromObject(chooseFileListStr);
  159. List<Map<String, Object>> fileTypeList = new ArrayList<Map<String, Object>>();
  160. // 处理选中数据 将同一文件类型的数据放在一起,方便分表查询数据
  161. for (Object object : chooseFileList) {
  162. Map<String, String> chooseFile = (Map<String, String>)object;
  163. boolean flag = false;
  164. for (Map<String, Object> fileType : fileTypeList) {
  165. if (chooseFile.get("type").equals(fileType.get("type"))) {
  166. List<String> fileIdList = (List<String>)fileType.get("fileIdList");
  167. fileIdList.add(chooseFile.get("id"));
  168. }
  169. flag = true;
  170. }
  171. if (!flag) {
  172. Map<String, Object> fileType = new HashMap<String, Object>();
  173. List<String> fileIdList = new ArrayList<String>();
  174. fileIdList.add(chooseFile.get("id"));
  175. fileType.put("type", chooseFile.get("type"));
  176. fileType.put("fileIdList", fileIdList);
  177. fileTypeList.add(fileType);
  178. }
  179. }
  180. // 查询对应明细信息
  181. for (Map<String, Object> fileType : fileTypeList) {
  182. String type = fileType.get("type").toString();
  183. List<String> fileIdList = (List<String>)fileType.get("fileIdList");
  184. Map<String, String> param = new HashMap<String, String>();
  185. param.put("fileType", type);
  186. param.put("fileIdListStr", JSONArray.fromObject(fileIdList).toString());
  187. List fileInfDetailList = Service.lookup(IDianwangService.class).queryFileInfDetail(param, rows);
  188. fileType.put("fileInfDetailList", fileInfDetailList);
  189. }
  190. // 设置返回值
  191. res.set(IMINBusinessConstant.F_PAGING_LAY, fileTypeList);
  192. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  193. return res;
  194. }
  195. /**
  196. * 报表信息组装
  197. * @param monthChoose 月范围
  198. * @param range 日期范围
  199. * @param timeRange 时分秒范围
  200. * @param reportInf 报表信息
  201. * @param monthNum 台区停电 monthNum个月内停电countNum次
  202. * @param countNum 台区停电 monthNum个月内停电countNum次
  203. * @param firstFileId 终端投托运报表选择的第一个原始数据文件
  204. * @param secondFileId 终端投托运报表选择的对比原始数据文件
  205. * @param FADateRange FA动作日期区间
  206. * @param yearChoose FA动作年份
  207. * @param DdyDateRange 低电压动日期区间
  208. * @param ddyFxbId 低电压分析表id
  209. * @return
  210. * @throws MINBusinessException
  211. * @throws ParseException
  212. * @throws InvocationTargetException
  213. * @throws IllegalArgumentException
  214. * @throws IllegalAccessException
  215. * @throws SecurityException
  216. * @throws NoSuchMethodException
  217. * @throws IOException
  218. * @throws InvalidFormatException
  219. */
  220. @MINAction(value = REPORT_NEED_DATA_DETAIL)
  221. public MINActionResult reportNeedDataDetail(
  222. MINHttpServletRequestContext request,
  223. @MINParam(key = "monthChoose") String monthChoose,
  224. @MINParam(key = "range") String range,
  225. @MINParam(key = "timeRange") String timeRange,
  226. @MINParam(key = "reportInf") String reportInf,
  227. @MINParam(key = "monthNum") String monthNum,
  228. @MINParam(key = "countNum") String countNum,
  229. @MINParam(key = "firstFileId") String firstFileId,
  230. @MINParam(key = "secondFileId") String secondFileId,
  231. @MINParam(key = "FADateRange") String FADateRange,
  232. @MINParam(key = "yearChoose") String yearChoose,
  233. @MINParam(key = "DdyDateRange") String DdyDateRange,
  234. @MINParam(key = "ddyFxbId") String ddyFxbId
  235. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InvalidFormatException, IOException {
  236. MINActionResult res = new MINActionResult();
  237. // 报表类型id
  238. String reportTypeId = reportInf.split("_")[0];
  239. Map<String, Object> param = new HashMap<String, Object>();
  240. param.put("monthChoose", monthChoose);
  241. param.put("range", range);
  242. param.put("timeRange", timeRange);
  243. param.put("reportTypeId", reportTypeId);
  244. param.put("monthNum", monthNum);
  245. param.put("countNum", countNum);
  246. param.put("firstFileId", firstFileId);
  247. param.put("secondFileId", secondFileId);
  248. param.put("FADateRange", FADateRange);
  249. param.put("yearChoose", yearChoose);
  250. param.put("DdyDateRange", DdyDateRange);
  251. param.put("ddyFxbId", ddyFxbId);
  252. param.put("request", request);
  253. Map<String, Object> resMap = Service.lookup(IReportService.class).reportNeedDetail(param);
  254. res.set(IMINBusinessConstant.F_PAGING_LAY, resMap);
  255. return res;
  256. }
  257. /**
  258. *
  259. * @param reportData
  260. * @param reportInf
  261. * @param fileName
  262. * @param monthNum 台区停电参数 台区停电【month个月内停电count次及以上台区】的month
  263. * @param countNum 台区停电参数 台区停电【month个月内停电count次及以上台区】的count
  264. * @param range 台区停电参数
  265. * @param timeRange 台区停电参数
  266. * @param firstFileId 终端投退运参数
  267. * @param secondFileId 终端投退运参数
  268. * @param session
  269. * @return
  270. * @throws MINBusinessException
  271. */
  272. @MINAction(value = FILE_INF_REPORT_SUBMIT, transaction = IMINTransactionEnum.CMT)
  273. public MINActionResult fileInfReportSubmit(
  274. @MINParam(key = "reportData") String reportData,
  275. @MINParam(key = "reportInf") String reportInf,
  276. @MINParam(key = "fileName") String fileName,
  277. @MINParam(key = "monthNum") String monthNum,
  278. @MINParam(key = "countNum") String countNum,
  279. @MINParam(key = "range") String range,
  280. @MINParam(key = "timeRange") String timeRange,
  281. @MINParam(key = "firstFileId") String firstFileId,
  282. @MINParam(key = "secondFileId") String secondFileId,
  283. @MINParam(key = "ddyFxbId") String ddyFxbId,
  284. @MINParam(key = "yearChoose") String yearChoose,
  285. @MINParam(key = "monthChoose") String monthChoose,
  286. MINSession session
  287. ) throws MINBusinessException {
  288. db = Service.lookup(IMINDataBaseService.class);
  289. MINActionResult res = new MINActionResult();
  290. String reportId = db.getMybatisMapper(SequenceMapper.class).getSequence("REPORT_INF_NO");
  291. String reportType = reportInf.split("_")[1];
  292. String reportTypeId = reportInf.split("_")[0];
  293. // 生成报表数据表
  294. DwReportData reportDataInf = new DwReportData();
  295. reportDataInf.setId(reportId);
  296. reportDataInf.setData(reportData);
  297. reportDataInf.setType(reportType);
  298. db.insertSelective(DwReportDataMapper.class, reportDataInf);
  299. User user = session.getUser();
  300. // 生成报告表
  301. DwReportInf report = new DwReportInf();
  302. report.setId(reportId);
  303. report.setUploadDate(DateUtil.getCurrentDateString());
  304. report.setFileName(fileName);
  305. report.setCreatUser(user.getId());
  306. report.setBranch(user.getBranchid());
  307. report.setType(reportTypeId);
  308. report.setZdttyCompareId(firstFileId + "-" + secondFileId);
  309. report.setTqtdMonth(monthNum); // 台区停电【month个月内停电count次及以上台区】的month
  310. report.setTqtdCount(countNum); // 台区停电【month个月内停电count次及以上台区】的count
  311. report.setDdyFxbId(ddyFxbId);
  312. report.setDayInterval(range.replaceAll(" ", "")); // 日期时间段
  313. report.setTimeInterval(timeRange.replaceAll(" ", "")); // 时分秒时间段
  314. report.setYearInterval(yearChoose.replaceAll(" ", ""));
  315. report.setMonthInterval(monthChoose.replaceAll(" ", ""));
  316. db.insertSelective(DwReportInfMapper.class, report);
  317. return res;
  318. }
  319. /**
  320. * 报告详情
  321. * @param reportId
  322. * @param session
  323. * @return
  324. * @throws MINBusinessException
  325. */
  326. @MINAction(value = REPORT_INF_DETAIL)
  327. public MINActionResult reportInfDetail(
  328. @MINParam(key = "reportId") String reportId,
  329. MINSession session
  330. ) throws MINBusinessException {
  331. db = Service.lookup(IMINDataBaseService.class);
  332. MINActionResult res = new MINActionResult();
  333. DwReportData reportDataInf = db.selectByPrimaryKey(DwReportDataMapper.class, reportId);
  334. res.set(IMINBusinessConstant.F_PAGING_LAY, reportDataInf);
  335. return res;
  336. }
  337. /**
  338. * 报表下载
  339. * @param reportId
  340. * @param response
  341. * @return
  342. * @throws MINBusinessException
  343. */
  344. @MINAction(value = REPORT_DOWN_LOAD)
  345. public HttpServletResponse reportDownLoad(
  346. @MINParam(key = "reportId") String reportId,
  347. HttpServletResponse response
  348. ) throws MINBusinessException {
  349. db = Service.lookup(IMINDataBaseService.class);
  350. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  351. DwBranchReportType branchReportType = db.selectByPrimaryKey(DwBranchReportTypeMapper.class, reportInf.getType());
  352. DwReportData reportDataInf = db.selectByPrimaryKey(DwReportDataMapper.class, reportId);
  353. // excel类型
  354. if ("00".equals(branchReportType.getType())) {
  355. //导出Excel
  356. OutputStream out=null;
  357. try {
  358. out = response.getOutputStream();
  359. HSSFWorkbook wb = ReportExcelUtil.export(response, reportInf.getFileName(), reportDataInf.getData());
  360. if(wb != null){
  361. wb.write(out);
  362. }
  363. out.flush();
  364. out.close();
  365. } catch (Exception e) {
  366. e.printStackTrace();
  367. }
  368. }
  369. return response;
  370. }
  371. /**
  372. * 报告删除
  373. * @param reportId
  374. * @param session
  375. * @return
  376. * @throws MINBusinessException
  377. */
  378. @MINAction(value = REPORT_INF_DELETE)
  379. public MINActionResult reportInfDelete(
  380. @MINParam(key = "reportId") String reportId,
  381. MINSession session
  382. ) throws MINBusinessException {
  383. db = Service.lookup(IMINDataBaseService.class);
  384. MINActionResult res = new MINActionResult();
  385. DwReportInf reportInf = new DwReportInf();
  386. reportInf.setId(reportId);
  387. reportInf.setState(Constant.REPORT_STATE_1);
  388. db.updateByPrimaryKeySelective(DwReportInfMapper.class, reportInf);
  389. return res;
  390. }
  391. /**
  392. * 修改
  393. * @param reportId
  394. * @param excelList
  395. * @param reportName
  396. * @param session
  397. * @return
  398. * @throws MINBusinessException
  399. */
  400. @MINAction(value = REPORT_INF_UPDATE)
  401. public MINActionResult reportInfUpdate(
  402. @MINParam(key = "reportId") String reportId,
  403. @MINParam(key = "excelList") String excelList,
  404. @MINParam(key = "reportName") String reportName,
  405. MINSession session
  406. ) throws MINBusinessException {
  407. db = Service.lookup(IMINDataBaseService.class);
  408. MINActionResult res = new MINActionResult();
  409. DwReportInf reportInf = new DwReportInf();
  410. reportInf.setId(reportId);
  411. reportInf.setFileName(reportName);
  412. db.updateByPrimaryKeySelective(DwReportInfMapper.class, reportInf);
  413. DwReportData reportData = new DwReportData();
  414. reportData.setId(reportId);
  415. reportData.setData(excelList);
  416. db.updateByPrimaryKeySelective(DwReportDataMapper.class, reportData);
  417. return res;
  418. }
  419. /**
  420. * 低电压分析表提交
  421. * @param reportId
  422. * @param excelList
  423. * @param reportName
  424. * @param session
  425. * @return
  426. * @throws MINBusinessException
  427. * @throws ParseException
  428. * @throws InvocationTargetException
  429. * @throws IllegalArgumentException
  430. * @throws IllegalAccessException
  431. * @throws SecurityException
  432. * @throws NoSuchMethodException
  433. */
  434. @MINAction(value = DDY_REPORT_INF_SUBMIT, transaction = IMINTransactionEnum.CMT)
  435. public MINActionResult ddyReportInfSubmit(
  436. @MINParam(key = "range") String range,
  437. @MINParam(key = "fileName") String fileName,
  438. @MINParam(key = "reportInf") String reportInf,
  439. MINSession session
  440. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  441. db = Service.lookup(IMINDataBaseService.class);
  442. MINActionResult res = new MINActionResult();
  443. String reportType = reportInf.split("_")[0];
  444. User user = session.getUser();
  445. String reportId = db.getMybatisMapper(SequenceMapper.class).getSequence("REPORT_INF_NO");
  446. // 生成报告表
  447. DwReportInf report = new DwReportInf();
  448. report.setId(reportId);
  449. report.setUploadDate(DateUtil.getCurrentDateString());
  450. report.setFileName(fileName);
  451. report.setCreatUser(user.getId());
  452. report.setBranch(user.getBranchid());
  453. report.setType(reportType);
  454. report.setDayInterval(range.replaceAll(" ", "")); // 日期时间段
  455. db.insertSelective(DwReportInfMapper.class, report);
  456. int page = 1;
  457. int limit = 1000;
  458. // 循环生成分析表数据
  459. while (true) {
  460. Map<String, Object> resMap = Service.lookup(IReportService.class).reportTypeDDYZLFXB(report.getDayInterval(), reportType, page, limit);
  461. // 需处理总条数
  462. Integer count = (Integer)resMap.get("count");
  463. List<List<String>> resList = (List<List<String>>)resMap.get("resList");
  464. for (int i = 2; i < resList.size(); i ++) {
  465. List<String> childList = (List<String>)resList.get(i);
  466. String id = db.getMybatisMapper(SequenceMapper.class).getSequence("DW_DDY_FXB_NO");
  467. DwDdyFxb ddyFxb = new DwDdyFxb();
  468. ddyFxb.setId(id);
  469. ddyFxb.setXh(childList.get(0));
  470. ddyFxb.setXgsmc(childList.get(1));
  471. ddyFxb.setYhgldwmc(childList.get(2));
  472. ddyFxb.setXlmc(childList.get(3));
  473. ddyFxb.setTqid(childList.get(4));
  474. ddyFxb.setByqmc(childList.get(5));
  475. ddyFxb.setYhbh(childList.get(6));
  476. ddyFxb.setDdysj(Integer.parseInt(childList.get(7)));
  477. ddyFxb.setLjts(Integer.parseInt(childList.get(8)));
  478. ddyFxb.setDdyzymc(childList.get(9));
  479. ddyFxb.setJtyy(childList.get(10));
  480. ddyFxb.setZlcs(childList.get(11));
  481. ddyFxb.setSfzl(childList.get(12));
  482. ddyFxb.setZlwcsj(childList.get(13));
  483. ddyFxb.setSfxc(childList.get(14));
  484. ddyFxb.setZrxz(childList.get(15));
  485. ddyFxb.setQnljts(Integer.parseInt(childList.get(16)));
  486. ddyFxb.setReportId(reportId);
  487. db.insertSelective(DwDdyFxbMapper.class, ddyFxb);
  488. String beginDate = report.getDayInterval().split("-")[0];
  489. String endDate = report.getDayInterval().split("-")[1];
  490. int index = 17;
  491. while (CommonUtil.compare(endDate, beginDate) != -1) {
  492. if (CommonUtil.isEmpty(childList.get(index))) {
  493. // 天数减1
  494. endDate = DateUtil.dateAddDay(endDate, -1);
  495. index++;
  496. continue;
  497. }
  498. DwDdyFxbDetail ddyFxbDetail = new DwDdyFxbDetail();
  499. String detailId = db.getMybatisMapper(SequenceMapper.class).getSequence("DW_DDY_FXB_DETAIL_NO");
  500. ddyFxbDetail.setId(detailId);
  501. ddyFxbDetail.setDate(endDate);
  502. ddyFxbDetail.setFxbId(id);
  503. ddyFxbDetail.setSc(childList.get(index));
  504. index++;
  505. db.insertSelective(DwDdyFxbDetailMapper.class, ddyFxbDetail);
  506. // 天数减1
  507. endDate = DateUtil.dateAddDay(endDate, -1);
  508. }
  509. }
  510. if (count <= page * limit) {
  511. break;
  512. }
  513. page ++;
  514. }
  515. return res;
  516. }
  517. /**
  518. * 低电压报告详情
  519. * @param reportId
  520. * @param session
  521. * @return
  522. * @throws MINBusinessException
  523. * @throws ParseException
  524. * @throws InvocationTargetException
  525. * @throws IllegalArgumentException
  526. * @throws IllegalAccessException
  527. * @throws SecurityException
  528. * @throws NoSuchMethodException
  529. */
  530. @MINAction(value = DDY_REPORT_INF_DETAIL)
  531. public MINActionResult ddyReportInfDetail(
  532. @MINParam(key = "reportId") String reportId,
  533. @MINParam(key = "page") int page,
  534. @MINParam(key = "limit") int limit,
  535. MINSession session
  536. ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  537. db = Service.lookup(IMINDataBaseService.class);
  538. MINActionResult res = new MINActionResult();
  539. List<Map<String, String>> resList = new ArrayList<Map<String, String>>();
  540. MINRowBounds rows = new MINRowBounds(page, limit);
  541. rows.setSeparateSql(true);
  542. DwDdyFxbExample ddyFxbExample = new DwDdyFxbExample();
  543. ddyFxbExample.createCriteria().andReportIdEqualTo(reportId);
  544. ddyFxbExample.setOrderByClause("DDF_ID");
  545. List<DwDdyFxb> ddyFxbList = db.selectByExample(DwDdyFxbMapper.class, ddyFxbExample, rows);
  546. List<String> fxbIdList = CommonUtil.getIdFromList(ddyFxbList, "id");
  547. DwDdyFxbDetailExample ddyFxbDetailExample = new DwDdyFxbDetailExample();
  548. ddyFxbDetailExample.createCriteria().andFxbIdIn(fxbIdList);
  549. ddyFxbDetailExample.setOrderByClause("DDFD_FXB_ID");
  550. List<DwDdyFxbDetail> detailList = db.selectByExample(DwDdyFxbDetailMapper.class, ddyFxbDetailExample);
  551. for (DwDdyFxb ddyFxb : ddyFxbList) {
  552. Map<String, String> child = new HashMap<String, String>();
  553. child.put("id", ddyFxb.getId());
  554. child.put("xh", ddyFxb.getXh());
  555. child.put("xgsmc", ddyFxb.getXgsmc());
  556. child.put("yhgldwmc", ddyFxb.getYhgldwmc());
  557. child.put("xlmc", ddyFxb.getXlmc());
  558. child.put("tqid", ddyFxb.getTqid());
  559. child.put("byqmc", ddyFxb.getByqmc());
  560. child.put("yhbh", ddyFxb.getYhbh());
  561. child.put("ddysj", String.valueOf(ddyFxb.getDdysj()));
  562. child.put("ljts", String.valueOf(ddyFxb.getLjts()));
  563. child.put("ddyzymc", ddyFxb.getDdyzymc());
  564. child.put("jtyy", ddyFxb.getJtyy());
  565. child.put("zlcs", ddyFxb.getZlcs());
  566. child.put("sfzl", ddyFxb.getSfzl());
  567. child.put("zlwcsj", ddyFxb.getZlwcsj());
  568. child.put("sfxc", ddyFxb.getSfxc());
  569. for (int i = 0; i < detailList.size(); i++) {
  570. // 分析表id一致
  571. if (ddyFxb.getId().equals(detailList.get(i).getFxbId())) {
  572. String sjrq = detailList.get(i).getDate();
  573. child.put(sjrq, detailList.get(i).getSc());
  574. detailList.remove(i);
  575. i --;
  576. } else {
  577. break;
  578. }
  579. }
  580. resList.add(child);
  581. }
  582. res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
  583. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  584. return res;
  585. }
  586. /**
  587. * 低电压编辑
  588. * @param id
  589. * @param ddyzymc
  590. * @param jtyy
  591. * @param zlcs
  592. * @param sfzl
  593. * @param zlwcsj
  594. * @param sfxc
  595. * @param session
  596. * @return
  597. * @throws MINBusinessException
  598. * @throws ParseException
  599. */
  600. @MINAction(value = DDY_REPORT_INF_UPDATE, transaction = IMINTransactionEnum.CMT)
  601. public MINActionResult ddyReportInfUpdate(
  602. @MINParam(key = "id") String id,
  603. @MINParam(key = "ddyzymc") String ddyzymc,
  604. @MINParam(key = "jtyy") String jtyy,
  605. @MINParam(key = "zlcs") String zlcs,
  606. @MINParam(key = "sfzl") String sfzl,
  607. @MINParam(key = "zlwcsj") String zlwcsj,
  608. @MINParam(key = "sfxc") String sfxc,
  609. MINSession session
  610. ) throws MINBusinessException, ParseException {
  611. db = Service.lookup(IMINDataBaseService.class);
  612. MINActionResult res = new MINActionResult();
  613. DwDdyFxb ddyFxb = new DwDdyFxb();
  614. ddyFxb.setId(id);
  615. if (!CommonUtil.isEmpty(ddyzymc)) {
  616. ddyFxb.setDdyzymc(ddyzymc);
  617. }
  618. if (!CommonUtil.isEmpty(jtyy)) {
  619. ddyFxb.setJtyy(jtyy);
  620. }
  621. if (!CommonUtil.isEmpty(zlcs)) {
  622. ddyFxb.setZlcs(zlcs);
  623. }
  624. if (!CommonUtil.isEmpty(sfzl)) {
  625. ddyFxb.setSfzl(sfzl);
  626. }
  627. if (!CommonUtil.isEmpty(zlwcsj)) {
  628. ddyFxb.setZlwcsj(zlwcsj);
  629. }
  630. if (!CommonUtil.isEmpty(sfxc)) {
  631. ddyFxb.setSfxc(sfxc);
  632. }
  633. db.updateByPrimaryKeySelective(DwDdyFxbMapper.class, ddyFxb);
  634. return res;
  635. }
  636. @MINAction(value = DDY_REPORT_INF_DOWNLOAD)
  637. public HttpServletResponse ddyReportInfDownload(
  638. @MINParam(key = "reportId") String reportId,
  639. HttpServletResponse response
  640. ) throws Exception {
  641. db = Service.lookup(IMINDataBaseService.class);
  642. DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId);
  643. int page = 1;
  644. int limit = 1000;
  645. int count = 0;
  646. List<Map<String, String>> resList = new ArrayList<Map<String, String>>();
  647. while (true) {
  648. MINRowBounds rows = new MINRowBounds(page, limit);
  649. rows.setSeparateSql(true);
  650. DwDdyFxbExample ddyFxbExample = new DwDdyFxbExample();
  651. ddyFxbExample.createCriteria().andReportIdEqualTo(reportId);
  652. ddyFxbExample.setOrderByClause("DDF_ID");
  653. List<DwDdyFxb> ddyFxbList = db.selectByExample(DwDdyFxbMapper.class, ddyFxbExample, rows);
  654. count = rows.getCount();
  655. List<String> fxbIdList = CommonUtil.getIdFromList(ddyFxbList, "id");
  656. DwDdyFxbDetailExample ddyFxbDetailExample = new DwDdyFxbDetailExample();
  657. ddyFxbDetailExample.createCriteria().andFxbIdIn(fxbIdList);
  658. ddyFxbDetailExample.setOrderByClause("DDFD_FXB_ID");
  659. List<DwDdyFxbDetail> detailList = db.selectByExample(DwDdyFxbDetailMapper.class, ddyFxbDetailExample);
  660. for (DwDdyFxb ddyFxb : ddyFxbList) {
  661. Map<String, String> child = new HashMap<String, String>();
  662. child.put("id", ddyFxb.getId());
  663. child.put("xh", ddyFxb.getXh());
  664. child.put("xgsmc", ddyFxb.getXgsmc());
  665. child.put("yhgldwmc", ddyFxb.getYhgldwmc());
  666. child.put("xlmc", ddyFxb.getXlmc());
  667. child.put("tqid", ddyFxb.getTqid());
  668. child.put("byqmc", ddyFxb.getByqmc());
  669. child.put("yhbh", ddyFxb.getYhbh());
  670. child.put("ddysj", String.valueOf(ddyFxb.getDdysj()));
  671. child.put("ljts", String.valueOf(ddyFxb.getLjts()));
  672. child.put("ddyzymc", ddyFxb.getDdyzymc());
  673. child.put("jtyy", ddyFxb.getJtyy());
  674. child.put("zlcs", ddyFxb.getZlcs());
  675. child.put("sfzl", ddyFxb.getSfzl());
  676. child.put("zlwcsj", ddyFxb.getZlwcsj());
  677. child.put("sfxc", ddyFxb.getSfxc());
  678. for (int i = 0; i < detailList.size(); i++) {
  679. // 分析表id一致
  680. if (ddyFxb.getId().equals(detailList.get(i).getFxbId())) {
  681. String sjrq = detailList.get(i).getDate();
  682. child.put(sjrq, detailList.get(i).getSc());
  683. detailList.remove(i);
  684. i --;
  685. } else {
  686. break;
  687. }
  688. }
  689. resList.add(child);
  690. }
  691. if (limit*page >= count) {
  692. break;
  693. }
  694. page ++;
  695. }
  696. //导出Excel
  697. OutputStream out=null;
  698. try {
  699. String beginTime = reportInf.getDayInterval().split("-")[0];
  700. String endTime = reportInf.getDayInterval().split("-")[1];
  701. int dayNum = DateUtil.diffDate(beginTime, endTime);
  702. String[] excelHeader = new String[dayNum + 16];
  703. excelHeader[0] = "系统编号#id";
  704. excelHeader[1] = "县公司名称#xgsmc";
  705. excelHeader[2] = "用户管理单位名称#yhgldwmc";
  706. excelHeader[3] = "线路名称#xlmc";
  707. excelHeader[4] = "台区ID#tqid";
  708. excelHeader[5] = "变压器名称#byqmc";
  709. excelHeader[6] = "用户编号#yhbh";
  710. excelHeader[7] = "低电压时长#ddysj";
  711. excelHeader[8] = "累计天数#ljts";
  712. excelHeader[9] = "低电压主要原因#ddyzymc";
  713. excelHeader[10] = "具体原因#jtyy";
  714. excelHeader[11] = "治理措施#zlcs";
  715. excelHeader[12] = "是否治理#sfzl";
  716. excelHeader[13] = "治理完成时间#zlwcsj";
  717. excelHeader[14] = "是否消除#sfxc";
  718. int index = 15;
  719. while (CommonUtil.compare(endTime, beginTime) != -1) {
  720. excelHeader[index] = endTime + "#" + endTime;
  721. index ++;
  722. endTime = DateUtil.dateAddDay(endTime, -1);
  723. }
  724. out = response.getOutputStream();
  725. HSSFWorkbook wb = export(response, reportInf.getFileName(), excelHeader, resList);
  726. if(wb != null){
  727. wb.write(out);
  728. }
  729. out.flush();
  730. out.close();
  731. } catch (Exception e) {
  732. e.printStackTrace();
  733. }
  734. return response;
  735. }
  736. @MINAction(value = DDY_REPORT_INF_UPLOAD)
  737. public MINActionResult ddyReportInfUpload(
  738. MINHttpServletRequestContext request,
  739. @MINParam(key = "id") String id,
  740. MINSession session
  741. ) throws MINBusinessException, InvalidFormatException, IOException {
  742. MINActionResult res = new MINActionResult();
  743. db = Service.lookup(IMINDataBaseService.class);
  744. // 获取文件
  745. FileItem fileItem = request.getFile("file");
  746. String fileName = fileItem.getName();
  747. if (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls")) {
  748. throw new MINBusinessException("文件格式错误!");
  749. }
  750. // 获取表格信息
  751. String[] titleKey = new String[]{"NO","ID","XGSMC","YHGLDWMC", "XLMC","TQID","BYQMC","YHBH","DDYSJ","LJTS","DDYZYMC","JTYY","ZLCS","SFZL","ZLWCSJ","SFXC"};
  752. List<Map<String,String>> list = FilesUtil.readExecleasy(fileItem, titleKey, 1);
  753. for (int i = 0; i < list.size(); i ++) {
  754. Map<String, String> map = list.get(i);
  755. DwDdyFxb ddyFxb = new DwDdyFxb();
  756. ddyFxb.setId(map.get("ID"));
  757. ddyFxb.setDdyzymc(map.get("DDYZYMC"));
  758. ddyFxb.setJtyy(map.get("JTYY"));
  759. ddyFxb.setZlcs(map.get("ZLCS"));
  760. ddyFxb.setSfzl(map.get("SFZL"));
  761. ddyFxb.setZlwcsj(map.get("ZLWCSJ"));
  762. ddyFxb.setSfxc(map.get("SFXC"));
  763. db.updateByPrimaryKeySelective(DwDdyFxbMapper.class, ddyFxb);
  764. }
  765. return res;
  766. }
  767. public static <T> HSSFWorkbook export(HttpServletResponse response, String fileName, String[] excelHeader,
  768. Collection<T> dataList) throws Exception {
  769. // 设置请求
  770. response.setContentType("application/application/vnd.ms-excel");
  771. response.setHeader("Content-disposition",
  772. "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "UTF-8"));
  773. // 创建一个Workbook,对应一个Excel文件
  774. HSSFWorkbook wb = new HSSFWorkbook();
  775. // 设置标题样式
  776. HSSFCellStyle titleStyle = wb.createCellStyle();
  777. // 设置字体样式
  778. Font titleFont = wb.createFont();
  779. titleFont.setFontHeightInPoints((short) 12); // 字体高度
  780. titleFont.setFontName("黑体"); // 字体样式
  781. titleStyle.setFont(titleFont);
  782. titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
  783. // 在Workbook中添加一个sheet,对应Excel文件中的sheet
  784. HSSFSheet sheet = wb.createSheet(fileName);
  785. // 标题数组
  786. String[] titleArray = new String[excelHeader.length];
  787. // 字段名数组
  788. String[] fieldArray = new String[excelHeader.length];
  789. for (int i = 0; i < excelHeader.length; i++) {
  790. String[] tempArray = excelHeader[i].split("#");// 临时数组 分割#
  791. titleArray[i] = tempArray[0];
  792. fieldArray[i] = tempArray[1];
  793. }
  794. // 在sheet中添加标题行
  795. HSSFRow row = sheet.createRow((int) 0);// 行数从0开始
  796. HSSFCell sequenceCell = row.createCell(0);// cell列 从0开始 第一列添加序号
  797. sequenceCell.setCellValue("序号");
  798. sequenceCell.setCellStyle(titleStyle);
  799. sheet.autoSizeColumn(0);// 自动设置宽度
  800. // 为标题行赋值
  801. for (int i = 0; i < titleArray.length; i++) {
  802. HSSFCell titleCell = row.createCell(i + 1);// 0号位被序号占用,所以需+1
  803. titleCell.setCellValue(titleArray[i]);
  804. titleCell.setCellStyle(titleStyle);
  805. sheet.autoSizeColumn(i + 1);// 0号位被序号占用,所以需+1
  806. sheet.setColumnWidth(i+1,titleArray[i].getBytes().length*256+500);
  807. }
  808. // 数据样式 因为标题和数据样式不同 需要分开设置 不然会覆盖
  809. HSSFCellStyle dataStyle = wb.createCellStyle();
  810. // 设置数据字体
  811. Font dataFont = wb.createFont();
  812. dataFont.setFontHeightInPoints((short) 10); // 字体高度
  813. dataFont.setFontName("宋体"); // 字体
  814. dataStyle.setFont(dataFont);
  815. dataStyle.setAlignment(CellStyle.ALIGN_CENTER);
  816. // 自定义颜色
  817. HSSFPalette palette = wb.getCustomPalette();
  818. palette.setColorAtIndex((short)9, (byte) (0xff & 240), (byte) (0xff & 165), (byte) (0xff & 172));
  819. palette.setColorAtIndex((short)10, (byte) (0xff & 255), (byte) (0xff & 192), (byte) (0xff & 0));
  820. HSSFCellStyle dataStyle2 = wb.createCellStyle();
  821. dataStyle2.setFont(dataFont);
  822. dataStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND);
  823. dataStyle2.setFillForegroundColor((short)9);
  824. dataStyle2.setAlignment(CellStyle.ALIGN_CENTER);
  825. HSSFCellStyle dataStyle3 = wb.createCellStyle();
  826. dataStyle3.setFont(dataFont);
  827. dataStyle3.setFillPattern(CellStyle.SOLID_FOREGROUND);
  828. dataStyle3.setFillForegroundColor((short)10);
  829. dataStyle3.setAlignment(CellStyle.ALIGN_CENTER);
  830. // 遍历集合数据,产生数据行
  831. Iterator<T> it = dataList.iterator();
  832. int index = 0;
  833. while (it.hasNext()) {
  834. index++;
  835. row = sheet.createRow(index);
  836. // 为序号赋值
  837. HSSFCell sequenceCellValue = row.createCell(0);// 序号值永远是第0列
  838. sequenceCellValue.setCellValue(index);
  839. sequenceCellValue.setCellStyle(dataStyle);
  840. // sheet.autoSizeColumn(0);
  841. T t = (T) it.next();
  842. Map<String, Object> map = (Map<String, Object> )t;
  843. HSSFCell dataCell = null;
  844. for (int i = 0; i < fieldArray.length; i++) {
  845. dataCell = row.createCell(i + 1);
  846. String fieldName = fieldArray[i];
  847. String value = CommonUtil.objToString(map.get(fieldName));
  848. // 每日时长列
  849. if (i >= 15) {
  850. if (CommonUtil.isEmpty(value)) {
  851. dataCell.setCellValue("");
  852. dataCell.setCellStyle(dataStyle);
  853. } else {
  854. dataCell.setCellValue(value);// 为当前列赋值
  855. dataCell.setCellStyle(dataStyle2);
  856. }
  857. //用户编号列
  858. } else if (i == 6) {
  859. // 低电压时长
  860. String sj = String.valueOf(map.get(fieldArray[i + 1]));
  861. if (CommonUtil.compare(sj, "48") != -1) {
  862. dataCell.setCellValue(value);// 为当前列赋值
  863. dataCell.setCellStyle(dataStyle3);
  864. } else {
  865. dataCell.setCellValue(value);// 为当前列赋值
  866. dataCell.setCellStyle(dataStyle);
  867. }
  868. } else {
  869. dataCell.setCellStyle(dataStyle);
  870. if (CommonUtil.isEmpty(value)) {
  871. dataCell.setCellValue(""); // 为当前列赋值
  872. } else {
  873. dataCell.setCellValue(CommonUtil.objToString(value));// 为当前列赋值
  874. }
  875. }
  876. }
  877. }
  878. sheet.setColumnWidth(fieldArray.length, 20 * 256);
  879. return wb;
  880. }
  881. }