123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- 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.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.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";
-
-
- /**
- * 台区停电穿透数据
- * @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<String, Object> param = new HashMap<String, Object>();
- 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<Map<String, String>> 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<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
- List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
- DwFileDetail00Example example = new DwFileDetail00Example();
- example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay).andEndTimeLessThanOrEqualTo(dayIntervalArray[1]);
- example.setOrderByClause("DFD0_ADDRESS_NUM");
- List<DwFileDetail00> 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<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
- param.put("yesterdayDetail", yesterdayList);
-
- List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
-
- List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
- DwFileDetail00Example example = new DwFileDetail00Example();
- example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay + timeIntervalArray[0]).andEndTimeLessThanOrEqualTo(dayIntervalArray[1] + timeIntervalArray[1]);
- example.setOrderByClause("DFD0_ADDRESS_NUM");
- List<DwFileDetail00> 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);
- // 2个月停电1次及以上台区且当日停电穿透
- } else if ("TQTD04".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<Map<String, String>> yesterdayList = db.getMybatisMapper(ReportServiceMapper.class).queryYesterdayDetail(param);
- param.put("yesterdayDetail", yesterdayList);
-
- // List<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
-
- List<String> addressNumList = CommonUtil.getIdFromList(yesterdayList, "addressNum");
- DwFileDetail00Example example = new DwFileDetail00Example();
- example.createCriteria().andAddressNumIn(addressNumList).andStartTimeGreaterThanOrEqualTo(beginDay + timeIntervalArray[0]).andEndTimeLessThanOrEqualTo(dayIntervalArray[1] + timeIntervalArray[1]);
- example.setOrderByClause("DFD0_ADDRESS_NUM");
- List<DwFileDetail00> 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 ("TQTD05".equals(chuantouType)) {
- List<Map<String, String>> 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);
- }
-
- return res;
- }
-
- /**
- * 台区停电附件导出
- * @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<String, Object> param = new HashMap<String, Object>();
- 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<Map<String, String>> mountCountList = db.getMybatisMapper(ReportServiceMapper.class).selectMountCount00(param);
-
- List<String> addressNumList = CommonUtil.getIdFromList(mountCountList, "addressNum");
- DwFileDetail00Example fileDetail00Example = new DwFileDetail00Example();
- fileDetail00Example.createCriteria().andAddressNumIn(addressNumList)
- .andStartTimeGreaterThanOrEqualTo(beginDay).andStartTimeLessThanOrEqualTo(rangeArray[1]);
- fileDetail00Example.setOrderByClause("DFD0_ADDRESS_NUM desc");
- List<DwFileDetail00> fileDetail00List = db.selectByExample(DwFileDetail00Mapper.class, fileDetail00Example);
- int i = 0;
- String addressNumFlag = null;
- List<Map<String, String>> excelList = new ArrayList<Map<String,String>>();
- for (int j = 0; j < fileDetail00List.size(); j ++) {
- DwFileDetail00 dwFileDetail00 = fileDetail00List.get(j);
- // 与上一条数据是否相同
- if (!dwFileDetail00.getAddressNum().equals(addressNumFlag) && addressNumFlag != null) {
- /*Map<String, String> excelMap = new HashMap<String, String>();
- excelMap.put("shichang", String.valueOf(i));
- excelList.add(excelMap);*/
- for (int k = 0; k < i; k ++) {
- Map<String, String> map = excelList.get(j - 1 - k);
- map.put("cishu", String.valueOf(i));
- }
- i = 0;
- }
- Map<String, String> excelMap = new HashMap<String, String>();
- 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 ++;
- }
-
- Map<String, String> excelMap = new HashMap<String, String>();
- excelMap.put("shichang", String.valueOf(i));
- excelList.add(excelMap);
-
- // 格式化时间
- 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();
- appparExample.createCriteria().andCodeEqualTo("tqtd_num");
- List<PubApppar> appparList = db.selectByExample(PubAppparMapper.class, appparExample);
- List<Map<String, String>> resList = new ArrayList<Map<String, String>>();
- Map<String, String> resMap = new HashMap<String, String>();
- resList.add(resMap);
- String hejiNum = "0";
- for (PubApppar pub : appparList) {
- resMap.put(pub.getValue(), pub.getShowmsg());
- hejiNum = CommonUtil.add(hejiNum, pub.getShowmsg());
- }
- resMap.put("合计", hejiNum);
- res.set(IMINBusinessConstant.F_PAGING_LAY, resList);
- 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();
- // 修改数据库数据
- db = Service.lookup(IMINDataBaseService.class);
- PubApppar apppar = new PubApppar();
- apppar.setCode("tqtd_num");
- apppar.setValue(field);
- apppar.setShowmsg(value);
- db.updateByPrimaryKeySelective(PubAppparMapper.class, apppar);
-
- // 更新值
- Service.lookup(IReportService.class).reflush();
-
- return res;
- }
- }
|