Browse Source

设备监测模块报表导出 更新

jichaobo 4 years ago
parent
commit
ee7b4d7acf

+ 241 - 32
fiveep-service/src/main/java/com/bizmatics/service/impl/RtAnalogDataServiceImpl.java

@@ -2,6 +2,7 @@ package com.bizmatics.service.impl;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
 import cn.afterturn.easypoi.excel.export.template.ExcelExportOfTemplateUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -22,11 +23,13 @@ import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.RadCountVO;
 import com.bizmatics.service.vo.HtAnalogDataExportVO;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.ibatis.annotations.Param;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.*;
@@ -592,36 +595,248 @@ public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMap
 
     @Override
     public String DataReportExport(Integer siteId,Date startTime, Date endTime,String queryType){
-
-
-
-
-
-
-
-
         Integer userId = SessionLocal.getUserId();
         Workbook workbook = null;
         File file = null;
         long diff = endTime.getTime() - startTime.getTime();
         long days = diff / (1000 * 60 * 60);
+        ExportParams params = new ExportParams("数据报表", "数据报表");
+        List<HtAnalogData> page1 = null;
+        if (days<=24){
+            page1 = baseMapper.getDataReportMap(siteId, startTime, endTime);
+        }else if (days<360&&days>24){
+            List<Device> device_list = baseMapper.getDeviceListMap(siteId);
+            page1 = baseMapper.getDataReportMMap(device_list,startTime, endTime);
+        }else if (days>=360){
+            List<Device> device_list = baseMapper.getDeviceListMap(siteId);
+            page1 = baseMapper.getDataReportDMap(device_list,startTime, endTime);
+        }
+        String[] result = queryType.split(",");
         try {
-            ExportParams params = new ExportParams(null, "数据报表");
-            workbook = ExcelExportUtil.exportBigExcel(params, HtAnalogDataExportVO.class,
-                    (o, i) -> {
-                        Page<HtAnalogData> page = new Page<>(i, 30);
-                        if (days<=24){
-                            page = baseMapper.getDataReportMap1(page,siteId, startTime, endTime);
-                        }else if (days<360&&days>24){
-                            List<Device> device_list = baseMapper.getDeviceListMap(siteId);
-                            page = baseMapper.getDataReportMMap1(page,device_list,startTime, endTime);
-                        }else if (days>=360){
-                            List<Device> device_list = baseMapper.getDeviceListMap(siteId);
-                            page = baseMapper.getDataReportDMap1(page,device_list,startTime, endTime);
+            List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
+            ExcelExportEntity colEntity = new ExcelExportEntity("序号", "xh");
+            colEntity.setNeedMerge(true);
+            colList.add(colEntity);
+            colEntity = new ExcelExportEntity("时间", "dataTime");
+            colEntity.setNeedMerge(true);
+            colList.add(colEntity);
+            if (ArrayUtils.contains(result,"I")){
+                colEntity = new ExcelExportEntity("A相电流", "Ia");
+                colEntity.setNeedMerge(true);
+                colList.add(colEntity);
+                colEntity = new ExcelExportEntity("B相电流", "Ib");
+                colEntity.setNeedMerge(true);
+                colList.add(colEntity);
+                colEntity = new ExcelExportEntity("C相电流", "Ic");
+                colEntity.setNeedMerge(true);
+                colList.add(colEntity);
+                if (ArrayUtils.contains(result,"P")){
+                    colEntity = new ExcelExportEntity("总有功功率", "P");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("总无功功率", "Q");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("A相有功功率", "Pa");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("B相有功功率", "Pb");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("C相有功功率", "Pc");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("A相无功功率", "Qa");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("B相无功功率", "Qb");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("C相无功功率", "Qc");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    colEntity = new ExcelExportEntity("实时需量", "Demand");
+                    colEntity.setNeedMerge(true);
+                    colList.add(colEntity);
+                    if (ArrayUtils.contains(result,"KWh")){
+                        colEntity = new ExcelExportEntity("负有功电度", "Epn");
+                        colEntity.setNeedMerge(true);
+                        colList.add(colEntity);
+                        colEntity = new ExcelExportEntity("正有功电度", "Epp");
+                        colEntity.setNeedMerge(true);
+                        colList.add(colEntity);
+                        colEntity = new ExcelExportEntity("负无功电度", "Eqn");
+                        colEntity.setNeedMerge(true);
+                        colList.add(colEntity);
+                        colEntity = new ExcelExportEntity("正无功电度", "Eqp");
+                        colEntity.setNeedMerge(true);
+                        colList.add(colEntity);
+                        if (ArrayUtils.contains(result,"V")){
+                            colEntity = new ExcelExportEntity("A相电压", "Ua");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("B相电压", "Ub");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("C相电压", "Ub");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("AB线电压", "Uab");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("BC线电压", "Ubc");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("CA线电压", "Uca");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            colEntity = new ExcelExportEntity("回路电压", "Ul");
+                            colEntity.setNeedMerge(true);
+                            colList.add(colEntity);
+                            if (ArrayUtils.contains(result,"C")){
+                                colEntity = new ExcelExportEntity("外接温度1", "T1");
+                                colEntity.setNeedMerge(true);
+                                colList.add(colEntity);
+                                colEntity = new ExcelExportEntity("外接温度2", "T2");
+                                colEntity.setNeedMerge(true);
+                                colList.add(colEntity);
+                                colEntity = new ExcelExportEntity("外接温度3", "T3");
+                                colEntity.setNeedMerge(true);
+                                colList.add(colEntity);
+                                colEntity = new ExcelExportEntity("外接温度4", "T4");
+                                colEntity.setNeedMerge(true);
+                                colList.add(colEntity);
+                                colEntity = new ExcelExportEntity("环境温度", "DeviceTemp");
+                                colEntity.setNeedMerge(true);
+                                colList.add(colEntity);
+                                if (ArrayUtils.contains(result,"HZ")){
+                                    colEntity = new ExcelExportEntity("频率", "F");
+                                    colEntity.setNeedMerge(true);
+                                    colList.add(colEntity);
+//                                    map.put("F",rtAnalogData.getF());
+                                    if (ArrayUtils.contains(result,"PS")){
+                                        colEntity = new ExcelExportEntity("A相功率因数", "COSa");
+                                        colEntity.setNeedMerge(true);
+                                        colList.add(colEntity);
+                                        colEntity = new ExcelExportEntity("B相功率因数", "COSb");
+                                        colEntity.setNeedMerge(true);
+                                        colList.add(colEntity);
+                                        colEntity = new ExcelExportEntity("C相功率因数", "COSc");
+                                        colEntity.setNeedMerge(true);
+                                        colList.add(colEntity);
+                                        colEntity = new ExcelExportEntity("功率因数", "COS");
+                                        colEntity.setNeedMerge(true);
+                                        colList.add(colEntity);
+                                        if (ArrayUtils.contains(result,"RMS")){
+                                            colEntity = new ExcelExportEntity("Ia总谐波电流", "IHa");
+                                            colEntity.setNeedMerge(true);
+                                            colList.add(colEntity);
+                                            colEntity = new ExcelExportEntity("Ib总谐波电流", "IHb");
+                                            colEntity.setNeedMerge(true);
+                                            colList.add(colEntity);
+                                            colEntity = new ExcelExportEntity("Ic总谐波电流", "IHc");
+                                            colEntity.setNeedMerge(true);
+                                            colList.add(colEntity);
+                                            if (ArrayUtils.contains(result,"DDB")){
+                                                colEntity = new ExcelExportEntity("设备信号强度", "SignalIntensity");
+                                                colEntity.setNeedMerge(true);
+                                                colList.add(colEntity);
+                                                if (ArrayUtils.contains(result,"VT")){
+                                                    colEntity = new ExcelExportEntity("电压暂升次数", "Upt");
+                                                    colEntity.setNeedMerge(true);
+                                                    colList.add(colEntity);
+                                                    colEntity = new ExcelExportEntity("电压暂降次数", "Udt");
+                                                    colEntity.setNeedMerge(true);
+                                                    colList.add(colEntity);
+                                                    colEntity = new ExcelExportEntity("电压中断次数", "Ust");
+                                                    colEntity.setNeedMerge(true);
+                                                    colList.add(colEntity);
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
                         }
+                    }
+                }
+            }
+            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+            for (int i = 0; i < page1.size(); i++) {
+                Map<String, Object> valMap = new HashMap<String, Object>();
+                valMap.put("xh",i+1);
+                if (days<=24){
+                    valMap.put("dataTime",DateUtils.format(page1.get(i).getDataTime(),"MM-dd HH:mm"));
+                }else if (days<360&&days>24){
+                    valMap.put("dataTime", DateUtils.format(page1.get(i).getDataTime(),"MM-dd HH:mm"));
+                }else if (days>=360){
+                    valMap.put("dataTime",DateUtils.format(page1.get(i).getDataTime(),DateUtils.PARSE_PATTERNS[8]));
+                }
+                if (ArrayUtils.contains(result,"I")){
+                    valMap.put("Ia",page1.get(i).getIa());
+                    valMap.put("Ib",page1.get(i).getIb());
+                    valMap.put("Ic",page1.get(i).getIc());
+                    if (ArrayUtils.contains(result,"P")){
+                        valMap.put("P",page1.get(i).getP());
+                        valMap.put("Q",page1.get(i).getQ());
+                        valMap.put("Pa",page1.get(i).getPa());
+                        valMap.put("Pb",page1.get(i).getPb());
+                        valMap.put("Pc",page1.get(i).getPc());
+                        valMap.put("Qa",page1.get(i).getQa());
+                        valMap.put("Qb",page1.get(i).getQb());
+                        valMap.put("Qc",page1.get(i).getQc());
+                        valMap.put("Demand",page1.get(i).getDemand());
+                        if (ArrayUtils.contains(result,"KWh")){
+                            valMap.put("Epn",page1.get(i).getEpn());
+                            valMap.put("Epp",page1.get(i).getEpp());
+                            valMap.put("Eqn",page1.get(i).getEqn());
+                            valMap.put("Eqp",page1.get(i).getEqp());
+                            if (ArrayUtils.contains(result,"V")){
+                                valMap.put("Ua",page1.get(i).getUa());
+                                valMap.put("Ub",page1.get(i).getUb());
+                                valMap.put("Uc",page1.get(i).getUc());
+                                valMap.put("Uab",page1.get(i).getUab());
+                                valMap.put("Ubc",page1.get(i).getUbc());
+                                valMap.put("Uca",page1.get(i).getUca());
+                                valMap.put("Ul",page1.get(i).getUl());
+                                if (ArrayUtils.contains(result,"C")){
+                                    valMap.put("T1",page1.get(i).getT1());
+                                    valMap.put("T2",page1.get(i).getT2());
+                                    valMap.put("T3",page1.get(i).getT3());
+                                    valMap.put("T4",page1.get(i).getT4());
+                                    valMap.put("DeviceTemp",page1.get(i).getDeviceTemp());
+                                    if (ArrayUtils.contains(result,"HZ")){
+                                        valMap.put("F",page1.get(i).getF());
+                                        if (ArrayUtils.contains(result,"PS")){
+                                            valMap.put("COSa",page1.get(i).getCOSa());
+                                            valMap.put("COSb",page1.get(i).getCOSb());
+                                            valMap.put("COSc",page1.get(i).getCOSc());
+                                            valMap.put("COS",page1.get(i).getCos());
+                                            if (ArrayUtils.contains(result,"RMS")){
+                                                valMap.put("IHa",page1.get(i).getIHa());
+                                                valMap.put("IHb",page1.get(i).getIHb());
+                                                valMap.put("IHc",page1.get(i).getIHc());
+                                                if (ArrayUtils.contains(result,"DDB")){
+                                                    valMap.put("SignalIntensity",page1.get(i).getSignalIntensity());
+                                                    if (ArrayUtils.contains(result,"VT")){
+                                                        valMap.put("Upt",page1.get(i).getUpt());
+                                                        valMap.put("Udt",page1.get(i).getUdt());
+                                                        valMap.put("Ust",page1.get(i).getUst());
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                list.add(valMap);
+            }
+
+            workbook = ExcelExportUtil.exportExcel(params, colList, list);
 
-                        return new ArrayList<>(BeanMapperUtils.mapList(page.getRecords(), HtAnalogData.class, HtAnalogDataExportVO.class));
-                    },null);
             if (null != workbook) {
                 file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "数据报表", System.currentTimeMillis() + ""));
                 FileUtils.createFile(file.getAbsolutePath());
@@ -630,17 +845,11 @@ public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMap
             } else {
                 throw new BusinessException("表格数据为空");
             }
-        } catch (Exception e) {
-            log.error("导出文件失败", e);
+        } catch (FileNotFoundException e) {
+             log.error("导出文件失败", e);
             throw new BusinessException("导出文件失败");
-        } finally {
-            if (workbook != null) {
-                try {
-                    workbook.close();
-                } catch (IOException e) {
-                    log.error("===export spec=== 关闭workbook失败", e);
-                }
-            }
+        } catch (IOException e) {
+            e.printStackTrace();
         }
         return file.getName();
     }