package com.minpay.reportManage.action; import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.minpay.common.format.IFormatService; import com.minpay.common.service.IReportService; import com.minpay.common.util.CommonUtil; import com.minpay.common.util.DateUtil; import com.minpay.common.util.ExportExcelUtil; import com.minpay.db.table.mapper.DwFileDetail00Mapper; import com.minpay.db.table.mapper.DwFileDetail98Mapper; import com.minpay.db.table.mapper.DwFileDetail99Mapper; import com.minpay.db.table.mapper.DwReportInfMapper; import com.minpay.db.table.mapper.PubAppparMapper; import com.minpay.db.table.model.DwFileDetail00; import com.minpay.db.table.model.DwFileDetail00Example; import com.minpay.db.table.model.DwFileDetail98; import com.minpay.db.table.model.DwFileDetail98Example; import com.minpay.db.table.model.DwFileDetail99; import com.minpay.db.table.model.DwFileDetail99Example; import com.minpay.db.table.model.DwReportInf; import com.minpay.db.table.model.PubApppar; import com.minpay.db.table.model.PubAppparExample; import com.minpay.db.table.own.mapper.ReportServiceMapper; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; @MINComponent public class TQTDReportAction implements IMINAction { private IMINDataBaseService db; /** 台区停电日报穿透数据 */ public final static String REPORT_INF_CHUANTOU = "reportInfChuantou"; /** 台区停电月报附件 */ public final static String REPORT_INF_FUJIAN = "reportInfFujian"; /** 台区数量管理 */ public final static String AREA_NUM_MANAGE = "areaNumManage"; /** 台区数量编辑 */ public final static String AREA_NUM_UPDATE = "areaNumUpdate"; /**穿透导出详情*/ public final static String REPORT_INF_FUJIAN_CHUANTOU = "reportInfFujianChuantou"; /**红黄蓝督办预警下载*/ public final static String DOWN_RB_HHL = "downRbHhl"; /** 台区停电周报报穿透数据 */ public final static String REPORT_INF_ZB_CHUANTOU = "reportInfZbChuantou"; /** 台区停电周报报穿透数据下载 */ public final static String REPORT_INF_ZB_CHUANTOU_DOWN = "reportInfZbChuantouDown"; /** * 台区停电穿透数据 * @param reportId 报表id * @param chuantouType 穿透类型 * @param session * @return * @throws MINBusinessException * @throws ParseException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException * @throws SecurityException * @throws NoSuchMethodException */ @MINAction(value = REPORT_INF_CHUANTOU) public MINActionResult reportInfChuantou( @MINParam(key = "reportId") String reportId, @MINParam(key = "chuantouType") String chuantouType, MINSession session ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { MINActionResult res = new MINActionResult(); db = Service.lookup(IMINDataBaseService.class); //分页 MINRowBounds rows = new MINRowBounds(); rows.setSeparateSql(true); // 查询报表具体信息 DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 报表时间范围 Map param = new HashMap(); String dayInterval = reportInf.getDayInterval(); String timeInterval = reportInf.getTimeInterval(); String[] dayIntervalArray = dayInterval.split("-"); String[] timeIntervalArray = timeInterval.split("-"); String beginTime = dayIntervalArray[0] + timeIntervalArray[0]; String endTime = dayIntervalArray[1] + timeIntervalArray[1]; param.put("beginTime", beginTime); param.put("endTime", endTime); // 台区次数穿透数据 if ("TQTD01".equals(chuantouType)) { List> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date"); fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00); // month个月停电count次及以上台区穿透 } else if ("TQTD02".equals(chuantouType)) { String monthNum = reportInf.getTqtdMonth(); String countNum = reportInf.getTqtdCount(); // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay); param.put("endDay", dayIntervalArray[1]); param.put("countNum", countNum); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); if (addressNumList.size() == 0) { return res; } DwFileDetail00Example example = new DwFileDetail00Example(); example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]); example.setOrderByClause("DFD0_ADDRESS_NUM"); List selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample); // month个月停电count次及以上台区且当日停电穿透 } else if ("TQTD03".equals(chuantouType)) { String monthNum = reportInf.getTqtdMonth(); String countNum = reportInf.getTqtdCount(); // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); if (mountCountList.size() == 0) { return res; } List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); List> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample); // 2个月停电2次台区且当日停电穿透 } else if ("TQTD04".equals(chuantouType)) { String monthNum = "2"; String countNum = "2"; // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param); if (mountCountList.size() == 0) { return res; } List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); List> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample); // 台区停电时户数 } else if ("TQTD05".equals(chuantouType)) { List> fileList00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); fileList00 = Service.lookup(IFormatService.class).formatDate(fileList00, "date"); fileList00 = Service.lookup(IFormatService.class).formatDateTime(fileList00, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, fileList00); // 2个月停电1次台区且当日停电穿透 }else if ("TQTD06".equals(chuantouType)) { String monthNum = "2"; String countNum = "1"; // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { return res; } param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); List> selectByExample = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample); } return res; } @MINAction(value = REPORT_INF_FUJIAN_CHUANTOU) public HttpServletResponse reportInfFujianChuantou( @MINParam(key = "reportId") String reportId, @MINParam(key = "chuantouType") String chuantouType, HttpServletResponse response, MINSession session )throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { //分页 MINRowBounds rows = new MINRowBounds(); rows.setSeparateSql(true); // 查询报表具体信息 DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 报表时间范围 Map param = new HashMap(); String dayInterval = reportInf.getDayInterval(); String timeInterval = reportInf.getTimeInterval(); String[] dayIntervalArray = dayInterval.split("-"); String[] timeIntervalArray = timeInterval.split("-"); String beginTime = dayIntervalArray[0] + timeIntervalArray[0]; String endTime = dayIntervalArray[1] + timeIntervalArray[1]; param.put("beginTime", beginTime); param.put("endTime", endTime); List> excelList = null; // 台区次数穿透数据 if ("TQTD01".equals(chuantouType)) { excelList = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); // month个月停电count次及以上台区穿透 } else if ("TQTD02".equals(chuantouType)) { String monthNum = reportInf.getTqtdMonth(); String countNum = reportInf.getTqtdCount(); // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay); param.put("endDay", dayIntervalArray[1]); param.put("countNum", countNum); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); if (addressNumList.size() == 0) { excelList = new ArrayList<>(); } else { excelList = new ArrayList<>(); DwFileDetail00Example example = new DwFileDetail00Example(); example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]); example.setOrderByClause("DFD0_ADDRESS_NUM"); List selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); for (DwFileDetail00 dwFileDetail00:selectByExample) { Map excelMap = new HashMap(); excelMap.put("addressNum", dwFileDetail00.getAddressNum()); excelMap.put("addressName", dwFileDetail00.getAddressName()); excelMap.put("date", dwFileDetail00.getDate()); excelMap.put("area", dwFileDetail00.getArea()); excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName()); excelMap.put("terminalName", dwFileDetail00.getTerminalName()); excelMap.put("terminalNum", dwFileDetail00.getTerminalNum()); excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress()); excelMap.put("startTime", dwFileDetail00.getStartTime()); excelMap.put("endTime", dwFileDetail00.getEndTime()); excelList.add(excelMap); } } // month个月停电count次及以上台区且当日停电穿透 } else if ("TQTD03".equals(chuantouType)) { String monthNum = reportInf.getTqtdMonth(); String countNum = reportInf.getTqtdCount(); // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); if (mountCountList.size() == 0) { excelList = new ArrayList<>(); } else { List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); } // 2个月停电2次台区且当日停电穿透 } else if ("TQTD04".equals(chuantouType)) { String monthNum = "2"; String countNum = "2"; // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param); if (mountCountList.size() == 0) { excelList = new ArrayList<>(); } else { List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); } // 台区停电时户数 } else if ("TQTD05".equals(chuantouType)) { excelList = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); for (Map m : excelList) { m.put("hour", CommonUtil.divide(m.get("time"), "60", 2)); } // 2个月停电1次台区且当日停电穿透 }else if ("TQTD06".equals(chuantouType)) { String monthNum = "2"; String countNum = "1"; // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { excelList = new ArrayList<>(); } else { param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount01(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); } } OutputStream out=null; try { out = response.getOutputStream(); HSSFWorkbook wb = null; if ("TQTD01".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD02".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD03".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD04".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD05".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#hour"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD06".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } if(wb != null){ wb.write(out); } out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return response; } /** * 台区停电附件导出 * @param reportId * @param response * @param session * @return * @throws MINBusinessException * @throws ParseException * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException */ @MINAction(value = REPORT_INF_FUJIAN) public HttpServletResponse reportInfFujian( @MINParam(key = "reportId") String reportId, HttpServletResponse response, MINSession session ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { db = Service.lookup(IMINDataBaseService.class); //分页 MINRowBounds rows = new MINRowBounds(); rows.setSeparateSql(true); DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 日期区间 String dayInterval = reportInf.getDayInterval(); // 时分秒区间 String timeInterval = reportInf.getTimeInterval(); // 获取时分秒 String beginTime = null; String endTime = null; String[] rangeArray = dayInterval.split("-"); if (CommonUtil.isEmpty(timeInterval)) { beginTime = rangeArray[0] + "000000"; endTime = rangeArray[1] + "235959"; } else { String[] timeRangeArray = timeInterval.split("-"); beginTime = rangeArray[0] + timeRangeArray[0]; endTime = rangeArray[1] + timeRangeArray[1]; } Map param = new HashMap(); param.put("beginTime", beginTime); param.put("endTime", endTime); String beginDay = DateUtil.dateAddMonth(rangeArray[1], Integer.parseInt("-2")); param.put("beginDay", beginDay); param.put("endDay", rangeArray[1]); param.put("countNum", "3"); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); if(addressNumList == null || addressNumList.isEmpty()){ addressNumList.add("XXXXXXXX"); } DwFileDetail00Example fileDetail00Example = new DwFileDetail00Example(); fileDetail00Example.createCriteria().andAddressNumIn(addressNumList) .andStartTimeGreaterThanOrEqualTo(beginDay).andStartTimeLessThanOrEqualTo(rangeArray[1]); fileDetail00Example.setOrderByClause("DFD0_ADDRESS_NUM desc"); List fileDetail00List = db.selectByExample(DwFileDetail00Mapper.class, fileDetail00Example); int i = 0; String addressNumFlag = null; List> excelList = new ArrayList>(); for (int j = 0; j < fileDetail00List.size(); j ++) { DwFileDetail00 dwFileDetail00 = fileDetail00List.get(j); // 与上一条数据是否相同 if (!dwFileDetail00.getAddressNum().equals(addressNumFlag) && addressNumFlag != null) { for (int k = 0; k < i; k ++) { Map map = excelList.get(j - 1 - k); map.put("cishu", String.valueOf(i)); } i = 0; } Map excelMap = new HashMap(); excelMap.put("addressNum", dwFileDetail00.getAddressNum()); excelMap.put("addressName", dwFileDetail00.getAddressName()); excelMap.put("date", dwFileDetail00.getDate()); excelMap.put("area", dwFileDetail00.getArea()); excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName()); excelMap.put("terminalName", dwFileDetail00.getTerminalName()); excelMap.put("terminalNum", dwFileDetail00.getTerminalNum()); excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress()); excelMap.put("startTime", dwFileDetail00.getStartTime()); excelMap.put("endTime", dwFileDetail00.getEndTime()); // 时差分钟 Long dateDiff = DateUtil.dateDiff(dwFileDetail00.getStartTime(), dwFileDetail00.getEndTime()); // 转换成小时 String shichang = CommonUtil.divide(String.valueOf(dateDiff), "60", 2); excelMap.put("shichang", shichang); excelList.add(excelMap); addressNumFlag = dwFileDetail00.getAddressNum(); i ++; if (j == fileDetail00List.size() - 1) { for (int k = 0; k < i; k ++) { Map map = excelList.get(j - k); map.put("cishu", String.valueOf(i)); } } } // 格式化时间 excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); OutputStream out = null; try { String[] excelHeader = {"台区名称#addressName","数据日期#date","台区编号#addressNum","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime","时长#shichang","停电次数#cishu"}; out = response.getOutputStream(); HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); if(wb != null){ wb.write(out); } out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return response; } /** * 台区数量管理 * @param session * @return * @throws MINBusinessException */ @MINAction(value = AREA_NUM_MANAGE) public MINActionResult areaNumManage( MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); db = Service.lookup(IMINDataBaseService.class); PubAppparExample appparExample = new PubAppparExample(); String systemCode = Service.lookup(IReportService.class).getSystemCode(); appparExample.createCriteria().andCodeEqualTo("tqtd_num_" + systemCode); List appparList = db.selectByExample(PubAppparMapper.class, appparExample); List> resList = new ArrayList>(); Map resMap = new HashMap(); resList.add(resMap); String hejiNum = "0"; List> col = new ArrayList>(); for (PubApppar pub : appparList) { resMap.put(pub.getValue(), pub.getShowmsg()); hejiNum = CommonUtil.add(hejiNum, pub.getShowmsg()); Map colMap = new HashMap(); colMap.put("field", pub.getValue()); colMap.put("title", pub.getValue()); colMap.put("edit", "text"); col.add(colMap); } Map colHejiMap = new HashMap(); colHejiMap.put("field", "合计"); colHejiMap.put("title", "合计"); col.add(colHejiMap); resMap.put("合计", hejiNum); res.set(IMINBusinessConstant.F_PAGING_LAY, resList); res.set("col", col); return res; } @MINAction(value = AREA_NUM_UPDATE) public MINActionResult areaNumUpdate( @MINParam(key = "field") String field, @MINParam(key = "value") String value, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); String systemCode = Service.lookup(IReportService.class).getSystemCode(); // 修改数据库数据 db = Service.lookup(IMINDataBaseService.class); PubApppar apppar = new PubApppar(); apppar.setCode("tqtd_num_"+systemCode); apppar.setValue(field); apppar.setShowmsg(value); db.updateByPrimaryKeySelective(PubAppparMapper.class, apppar); // 更新值 Service.lookup(IReportService.class).reflush(); return res; } @MINAction(value = DOWN_RB_HHL) public MINActionResult downRbHhl( @MINParam(key = "reportId") String reportId, HttpServletResponse response, MINSession session ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { db = Service.lookup(IMINDataBaseService.class); MINActionResult res = new MINActionResult(); // 查询报表具体信息 DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 报表时间范围 Map param = new HashMap(); String dayInterval = reportInf.getDayInterval(); String timeInterval = reportInf.getTimeInterval(); String[] dayIntervalArray = dayInterval.split("-"); String[] timeIntervalArray = timeInterval.split("-"); String beginTime = dayIntervalArray[0] + timeIntervalArray[0]; String endTime = dayIntervalArray[1] + timeIntervalArray[1]; param.put("beginTime", beginTime); param.put("endTime", endTime); List> excelList = null; String monthNum = reportInf.getTqtdMonth(); String countNum = "1"; // monthNum个月内停电 countNum次以上的台区 String beginDay = DateUtil.dateAddMonth(dayIntervalArray[1], Integer.parseInt("-" + monthNum)); param.put("beginDay", beginDay + timeIntervalArray[0]); param.put("endDay", dayIntervalArray[1] + timeIntervalArray[1]); param.put("countNum", countNum); // 查询当日停电的数据 param.put("yesterday", dayIntervalArray[1]); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); param.put("yesterdayDetail", yesterdayList); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); if (mountCountList.size() == 0) { excelList = new ArrayList<>(); } else { List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); param.put("addressNumList", addressNumList); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); } List addressNameList = CommonUtil.getIdFromList(excelList, "addressName"); // 线路台账(供服) DwFileDetail98Example dwFileDetail98Example = new DwFileDetail98Example(); dwFileDetail98Example.createCriteria().andGbmcIn(addressNameList); List gfList = db.getMybatisMapper(DwFileDetail98Mapper.class).selectByExample(dwFileDetail98Example); // 匹配供服台账的线路数据 for (Map e : excelList) { for (DwFileDetail98 d : gfList) { if (d.getGbmc().equals(e.get("addressName"))) { e.put("ssxl", d.getSskx()); break; } } } DwFileDetail99Example dwFileDetail99Example = new DwFileDetail99Example(); dwFileDetail99Example.createCriteria().andTqIn(addressNameList); List yxList = db.getMybatisMapper(DwFileDetail99Mapper.class).selectByExample(dwFileDetail99Example); // 匹配营销台账的线路数据 for (Map e : excelList) { for (DwFileDetail99 d : yxList) { if (CommonUtil.isEmpty(e.get("ssxl")) && d.getTq().equals(e.get("addressName"))) { e.put("ssxl", d.getTq()); break; } } } OutputStream out=null; try { out = response.getOutputStream(); String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","所属线路#ssxl"}; HSSFWorkbook wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); if(wb != null){ wb.write(out); } out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return res; } @MINAction(value = REPORT_INF_ZB_CHUANTOU) public MINActionResult reportInfZbChuantou( @MINParam(key = "reportId") String reportId, @MINParam(key = "chuantouType") String chuantouType, MINSession session ) throws MINBusinessException, ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { MINActionResult res = new MINActionResult(); db = Service.lookup(IMINDataBaseService.class); //分页 MINRowBounds rows = new MINRowBounds(); rows.setSeparateSql(true); // 查询报表具体信息 DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 报表时间范围 Map param = new HashMap(); String dayInterval = reportInf.getDayInterval(); String timeInterval = reportInf.getTimeInterval(); String[] dayIntervalArray = dayInterval.split("-"); String[] timeIntervalArray = timeInterval.split("-"); String beginTime = dayIntervalArray[0] + timeIntervalArray[0]; String endTime = dayIntervalArray[1] + timeIntervalArray[1]; param.put("beginTime", beginTime); param.put("endTime", endTime); // 停电台区数 if ("TQTD00".equals(chuantouType)) { param.put("beginDay", beginTime); param.put("endDay", endTime); List> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); res.set(IMINBusinessConstant.F_PAGING_LAY, tqCountList); // 本周累计停电台次 }else if ("TQTD01".equals(chuantouType)) { DwFileDetail00Example example = new DwFileDetail00Example(); example.createCriteria().andStartTimeGreaterThanOrEqualTo(beginTime).andEndTimeLessThanOrEqualTo(endTime); List selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, selectByExample); // 本周重复停电台区数 } else if ("TQTD02".equals(chuantouType)) { param.put("beginDay", beginTime); param.put("endDay", endTime); param.put("countNum", "2"); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); if (addressNumList.size() == 0) { return res; } param.put("addressNumList", addressNumList); List> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); res.set(IMINBusinessConstant.F_PAGING_LAY, tqCountList); // 本周督办频繁停电台次 } else if ("TQTD03".equals(chuantouType)) { List> resList = new ArrayList<>(); String begin = dayIntervalArray[0]; String end = dayIntervalArray[1]; while (CommonUtil.compare(begin, end) != 1) { param.put("yesterday", begin); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { begin = DateUtil.dateAddDay(begin, 1); continue; } param.put("yesterdayDetail", yesterdayList); param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endDay", begin + endTime.substring(8, 14)); param.put("countNum", 3); List> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum"); if (addressNumList.size() != 0) { param.put("beginTime", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endTime", begin + endTime.substring(8, 14)); param.put("addressNumList", addressNumList); List> selectReportType00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); for (Map map : selectReportType00) { map.put("queryDate", begin); } resList.addAll(selectReportType00); } // 天数 + 1 begin = DateUtil.dateAddDay(begin, 1); } resList = Service.lookup(IFormatService.class).formatDate(resList, "date", "queryDate"); resList = Service.lookup(IFormatService.class).formatDateTime(resList, "startTime", "endTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, resList); // 本周督办频繁停电台区数 } else if ("TQTD04".equals(chuantouType)) { List> resList = new ArrayList<>(); String begin = dayIntervalArray[0]; String end = dayIntervalArray[1]; while (CommonUtil.compare(begin, end) != 1) { param.put("yesterday", begin); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { begin = DateUtil.dateAddDay(begin, 1); continue; } param.put("yesterdayDetail", yesterdayList); param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endDay", begin + endTime.substring(8, 14)); param.put("countNum", 3); List> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum"); if (addressNumList.size() != 0) { param.put("addressNumList", addressNumList); List> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); for (Map t : tqCountList) { t.put("date", begin); } resList.addAll(tqCountList); } // 天数 + 1 begin = DateUtil.dateAddDay(begin, 1); } resList = Service.lookup(IFormatService.class).formatDate(resList, "date"); res.set(IMINBusinessConstant.F_PAGING_LAY, resList); } return res; } @MINAction(value = REPORT_INF_ZB_CHUANTOU_DOWN) public MINActionResult reportInfZbChuantouDown( @MINParam(key = "reportId") String reportId, @MINParam(key = "chuantouType") String chuantouType, HttpServletResponse response, MINSession session )throws MINBusinessException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ParseException{ MINActionResult res = new MINActionResult(); db = Service.lookup(IMINDataBaseService.class); //分页 MINRowBounds rows = new MINRowBounds(); rows.setSeparateSql(true); // 查询报表具体信息 DwReportInf reportInf = db.selectByPrimaryKey(DwReportInfMapper.class, reportId); // 报表时间范围 Map param = new HashMap(); String dayInterval = reportInf.getDayInterval(); String timeInterval = reportInf.getTimeInterval(); String[] dayIntervalArray = dayInterval.split("-"); String[] timeIntervalArray = timeInterval.split("-"); String beginTime = dayIntervalArray[0] + timeIntervalArray[0]; String endTime = dayIntervalArray[1] + timeIntervalArray[1]; param.put("beginTime", beginTime); param.put("endTime", endTime); List> excelList = new ArrayList<>(); // 停电台区数 if ("TQTD00".equals(chuantouType)) { param.put("beginDay", beginTime); param.put("endDay", endTime); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); // 本周累计停电台次 }else if ("TQTD01".equals(chuantouType)) { DwFileDetail00Example example = new DwFileDetail00Example(); example.createCriteria().andStartTimeGreaterThanOrEqualTo(beginTime).andEndTimeLessThanOrEqualTo(endTime); List selectByExample = db.selectByExample(DwFileDetail00Mapper.class, example); selectByExample = Service.lookup(IFormatService.class).formatDate(selectByExample, "date"); selectByExample = Service.lookup(IFormatService.class).formatDateTime(selectByExample, "startTime", "endTime"); for (DwFileDetail00 dwFileDetail00:selectByExample) { Map excelMap = new HashMap(); excelMap.put("addressNum", dwFileDetail00.getAddressNum()); excelMap.put("addressName", dwFileDetail00.getAddressName()); excelMap.put("date", dwFileDetail00.getDate()); excelMap.put("area", dwFileDetail00.getArea()); excelMap.put("comonpanyName", dwFileDetail00.getComonpanyName()); excelMap.put("terminalName", dwFileDetail00.getTerminalName()); excelMap.put("terminalNum", dwFileDetail00.getTerminalNum()); excelMap.put("terminalAddress", dwFileDetail00.getTerminalAddress()); excelMap.put("startTime", dwFileDetail00.getStartTime()); excelMap.put("endTime", dwFileDetail00.getEndTime()); excelList.add(excelMap); } // 本周重复停电台区数 } else if ("TQTD02".equals(chuantouType)) { param.put("beginDay", beginTime); param.put("endDay", endTime); param.put("countNum", "2"); List> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum"); if (addressNumList.size() == 0) { return res; } param.put("addressNumList", addressNumList); excelList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); // 本周督办频繁停电台次 } else if ("TQTD03".equals(chuantouType)) { String begin = dayIntervalArray[0]; String end = dayIntervalArray[1]; while (CommonUtil.compare(begin, end) != 1) { param.put("yesterday", begin); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { begin = DateUtil.dateAddDay(begin, 1); continue; } param.put("yesterdayDetail", yesterdayList); param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endDay", begin + endTime.substring(8, 14)); param.put("countNum", 3); List> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum"); if (addressNumList.size() != 0) { param.put("beginTime", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endTime", begin + endTime.substring(8, 14)); param.put("addressNumList", addressNumList); List> selectReportType00 = db.getMybatisMapper(ReportServiceMapper.class).selectReportType00(param); for (Map map : selectReportType00) { map.put("queryDate", begin); } excelList.addAll(selectReportType00); } // 天数 + 1 begin = DateUtil.dateAddDay(begin, 1); } excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date", "queryDate"); excelList = Service.lookup(IFormatService.class).formatDateTime(excelList, "startTime", "endTime"); // 本周督办频繁停电台区数 } else if ("TQTD04".equals(chuantouType)) { String begin = dayIntervalArray[0]; String end = dayIntervalArray[1]; while (CommonUtil.compare(begin, end) != 1) { param.put("yesterday", begin); List> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param); if (yesterdayList.size() == 0) { begin = DateUtil.dateAddDay(begin, 1); continue; } param.put("yesterdayDetail", yesterdayList); param.put("beginDay", DateUtil.dateAddDay(DateUtil.dateAddMonth(begin, -2), 1) + beginTime.substring(8, 14)); param.put("endDay", begin + endTime.substring(8, 14)); param.put("countNum", 3); List> sanciData = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param); List addressNumList = CommonUtil.getIdFromList(sanciData, "addressNum"); if (addressNumList.size() != 0) { param.put("addressNumList", addressNumList); List> tqCountList = db.getMybatisMapper(ReportServiceMapper.class).selectTqtdRbDetail(param); for (Map t : tqCountList) { t.put("date", begin); } excelList.addAll(tqCountList); } // 天数 + 1 begin = DateUtil.dateAddDay(begin, 1); } excelList = Service.lookup(IFormatService.class).formatDate(excelList, "date"); } OutputStream out=null; try { out = response.getOutputStream(); HSSFWorkbook wb = null; if ("TQTD00".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD01".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD02".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD03".equals(chuantouType)) { String[] excelHeader = {"日报日期#queryDate","台区编号#addressNum","台区名称#addressName","数据日期#date","单位#area","单位名称#comonpanyName","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电时间#startTime","来电时间#endTime"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } else if ("TQTD04".equals(chuantouType)) { String[] excelHeader = {"台区编号#addressNum","台区名称#addressName","单位#area","终端名称#terminalName","终端编号#terminalNum","终端地址码#terminalAddress","停电次数#num","日报日期#date"}; wb = ExportExcelUtil.export(response, reportInf.getFileName(), excelHeader, excelList); } if(wb != null){ wb.write(out); } out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return res; } }