123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965 |
- 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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.bizmatics.common.core.exception.BusinessException;
- import com.bizmatics.common.core.util.*;
- import com.bizmatics.common.mvc.base.AbstractCrudService;
- import com.bizmatics.common.spring.util.GlobalUtils;
- import com.bizmatics.model.*;
- import com.bizmatics.persistence.mapper.RtAnalogDataMapper;
- import com.bizmatics.service.DeviceAttributeService;
- import com.bizmatics.service.DeviceService;
- import com.bizmatics.service.RtAnalogDataService;
- import com.bizmatics.service.SiteDynamicPropertiesService;
- import com.bizmatics.service.util.SecurityUtils;
- import com.bizmatics.service.vo.RadCountVO;
- import com.bizmatics.service.vo.RealScoreVO;
- import org.apache.commons.lang3.ArrayUtils;
- 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.*;
- import java.util.concurrent.atomic.AtomicReference;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author ya
- * @since 2021-07-07
- */
- @Service
- public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMapper, RtAnalogData> implements RtAnalogDataService {
- @Autowired
- private DeviceService deviceService;
- @Autowired
- private SiteDynamicPropertiesService siteDynamicPropertiesService;
- @Autowired
- private DeviceAttributeService deviceAttributeService;
- @Override
- public RadCountVO selectCount() {
- Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
- AtomicReference<Integer> heavyLoad = new AtomicReference<>(0);
- AtomicReference<Integer> easyLoad = new AtomicReference<>(0);
- AtomicReference<Integer> norMalLoad = new AtomicReference<>(0);
- AtomicReference<Integer> count = new AtomicReference<>(0);
- List<Device> deviceList = deviceService.list(userId, null, null, null, null, null);
- List<RtAnalogData> list = baseMapper.list(userId);
- for (Device device : deviceList) {
- list.stream()
- .filter(rtAnalogData -> device.getDeviceCode().equals(rtAnalogData.getDeviceName())).findAny()
- .ifPresent(rtAnalogData -> {
- String installedCapacity = device.getInstalledCapacity();
- double installedCapacityDouble = 0.00;
- if (StringUtils.isNotBlank(installedCapacity)) {
- installedCapacityDouble = Double.parseDouble(installedCapacity);
- if (installedCapacityDouble > 0) {
- installedCapacityDouble = Arith.div(rtAnalogData.getP(), installedCapacityDouble);
- }
- }
- if (installedCapacityDouble < 0.4) {
- easyLoad.getAndSet(easyLoad.get() + 1);
- } else if (installedCapacityDouble >= 0.4 && installedCapacityDouble <= 0.8) {
- norMalLoad.getAndSet(norMalLoad.get() + 1);
- } else {
- heavyLoad.getAndSet(heavyLoad.get() + 1);
- }
- count.getAndSet(count.get() + 1);
- });
- }
- RadCountVO radCountVO = new RadCountVO();
- radCountVO.setHeavyLoad(subRadio(heavyLoad.get(), count.get()));
- radCountVO.setEasyLoad(subRadio(easyLoad.get(), count.get()));
- radCountVO.setNorMalLoad(Arith.sub(1, Arith.add(radCountVO.getEasyLoad(), radCountVO.getHeavyLoad())));
- return radCountVO;
- }
- public Double subRadio(Integer typeCount, Integer count) {
- return Optional.of(count).filter(total -> total != 0).map(sub -> Arith.div(typeCount, sub)).orElse(0.00);
- }
- @Override
- public List<Map<String, Object>> getOne(Integer siteId) {
- List<Map<String, Object>> list = new ArrayList<>();
- Map<String, Object> radMap = baseMapper.getOneMap(siteId);
- Optional.ofNullable(radMap).ifPresent(rad -> {
- for (String name : rad.keySet()) {
- Map<String, Object> map = new HashMap<>();
- map.put("name", name);
- map.put("value", rad.get(name));
- list.add(map);
- }
- });
- return list;
- }
- @Override
- public Double getEpLoad(Integer siteId) {
- Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
- return baseMapper.selectTotalLoad(userId, siteId);
- }
- @Override
- public List<String> realScore(String deviceName) {
- LambdaQueryWrapper<RtAnalogData> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(RtAnalogData::getDeviceName,deviceName);
- RtAnalogData rtAnalogData = getOne(queryWrapper);
- return null;
- }
- /**
- * 填充实时数据
- */
- public void fillRealScoreData(RtAnalogData rtAnalogData, SiteDynamicProperties siteDynamicProperties,DeviceAttribute deviceAttribute){
- List<Double> checkList = new ArrayList<>();
- RealScoreVO realScoreVo = BeanMapperUtils.map(rtAnalogData, RealScoreVO.class);
- checkList.add(realScoreVo.getIa());
- checkList.add(realScoreVo.getIb());
- checkList.add(realScoreVo.getIc());
- //电流不平衡
- realScoreVo.setElBalun(checkBalun(checkList));
- checkList.clear();
- checkList.add(realScoreVo.getUa());
- checkList.add(realScoreVo.getUb());
- checkList.add(realScoreVo.getUc());
- //电压不平衡
- realScoreVo.setVtBalun(checkBalun(checkList));
- //电压合格率
- realScoreVo.setUaQualified(Arith.sub(rtAnalogData.getUa(), Double.parseDouble(siteDynamicProperties.getVoltageLevel())));
- realScoreVo.setUbQualified(Arith.sub(rtAnalogData.getUb(), Double.parseDouble(siteDynamicProperties.getVoltageLevel())));
- realScoreVo.setUcQualified(Arith.sub(rtAnalogData.getUc(), Double.parseDouble(siteDynamicProperties.getVoltageLevel())));
- //电流负载率
- realScoreVo.setIaLoad(Arith.div(realScoreVo.getIa(),deviceAttribute.getRatedCurrent()));
- realScoreVo.setIbLoad(Arith.div(realScoreVo.getIb(),deviceAttribute.getRatedCurrent()));
- realScoreVo.setIcLoad(Arith.div(realScoreVo.getIc(),deviceAttribute.getRatedCurrent()));
- //金
- }
- /**
- * 计算电流/电压不平衡
- * @param list
- * @return
- */
- public Double checkBalun(List<Double> list){
- Double max = list.stream().max(Double::compareTo).get();
- Double min = list.stream().min(Double::compareTo).get();
- return Arith.div(Arith.sub(max,min),max);
- }
- /**
- * 添加数据单位
- *
- * @return
- */
- public String addUnit(String name, String value) {
- if (name.endsWith("电压")) {
- return value + "V";
- } else if (name.endsWith("电流")) {
- return value + "A";
- } else if (name.endsWith("温度")) {
- return value + "C";
- } else if (name.endsWith("频率")) {
- return value + "Hz";
- } else if (name.endsWith("有功功率") || name.endsWith("需量")) {
- return value + "KW";
- } else if (name.endsWith("无功功率")) {
- return value + "KVar";
- } else if (name.endsWith("不平衡度") || name.endsWith("电压畸变率")) {
- return value + "%";
- } else if (name.endsWith("次数")) {
- return value + "次";
- } else if (name.endsWith("电度") || name.endsWith("有功")) {
- return value + "KWh";
- }
- return value;
- }
- @Override
- public List<Map<String, Object>> getDataReport(Integer siteId, Date startTime, Date endTime, String queryType) {
- List<Map<String, Object>> list = new ArrayList<>();
- List<HtAnalogData> rtAnalogDataList = null;
- long diff = endTime.getTime() - startTime.getTime();
- long days = diff / (1000 * 60 * 60);
- if (days <= 24) {
- rtAnalogDataList = baseMapper.getDataReportMap(siteId, startTime, endTime);
- } else if (days < 360 && days > 24) {
- List<Device> device_list = baseMapper.getDeviceListMap(siteId);
- rtAnalogDataList = baseMapper.getDataReportMMap(device_list, startTime, endTime);
- } else if (days >= 360) {
- List<Device> device_list = baseMapper.getDeviceListMap(siteId);
- rtAnalogDataList = baseMapper.getDataReportDMap(device_list, startTime, endTime);
- }
- String[] result = queryType.split(",");
- if (rtAnalogDataList.size() > 0) {
- rtAnalogDataList.forEach(rtAnalogData -> {
- Map<String, Object> map = new HashMap<>();
- if (ArrayUtils.contains(result, "I")) {
- map.put("Ia", rtAnalogData.getIa());
- map.put("Ib", rtAnalogData.getIb());
- map.put("Ic", rtAnalogData.getIc());
- if (ArrayUtils.contains(result, "P")) {
- map.put("P", rtAnalogData.getP());
- map.put("Q", rtAnalogData.getQ());
- map.put("Pa", rtAnalogData.getPa());
- map.put("Pb", rtAnalogData.getPb());
- map.put("Pc", rtAnalogData.getPc());
- map.put("Qa", rtAnalogData.getQa());
- map.put("Qb", rtAnalogData.getQb());
- map.put("Qc", rtAnalogData.getQc());
- map.put("Demand", rtAnalogData.getDemand());
- if (ArrayUtils.contains(result, "KWh")) {
- map.put("Epn", rtAnalogData.getEpn());
- map.put("Epp", rtAnalogData.getEpp());
- map.put("Eqn", rtAnalogData.getEqn());
- map.put("Eqp", rtAnalogData.getEqp());
- if (ArrayUtils.contains(result, "V")) {
- map.put("Ua", rtAnalogData.getUa());
- map.put("Ub", rtAnalogData.getUb());
- map.put("Uc", rtAnalogData.getUc());
- map.put("Uab", rtAnalogData.getUab());
- map.put("Ubc", rtAnalogData.getUbc());
- map.put("Uca", rtAnalogData.getUca());
- map.put("Ul", rtAnalogData.getUl());
- if (ArrayUtils.contains(result, "C")) {
- map.put("T1", rtAnalogData.getT1());
- map.put("T2", rtAnalogData.getT2());
- map.put("T3", rtAnalogData.getT3());
- map.put("T4", rtAnalogData.getT4());
- map.put("DeviceTemp", rtAnalogData.getDeviceTemp());
- if (ArrayUtils.contains(result, "HZ")) {
- map.put("F", rtAnalogData.getF());
- if (ArrayUtils.contains(result, "PS")) {
- map.put("COSa", rtAnalogData.getCOSa());
- map.put("COSb", rtAnalogData.getCOSb());
- map.put("COSc", rtAnalogData.getCOSc());
- map.put("COS", rtAnalogData.getCos());
- if (ArrayUtils.contains(result, "RMS")) {
- map.put("IHa", rtAnalogData.getIHa());
- map.put("IHb", rtAnalogData.getIHb());
- map.put("IHc", rtAnalogData.getIHc());
- if (ArrayUtils.contains(result, "DDB")) {
- map.put("SignalIntensity", rtAnalogData.getSignalIntensity());
- if (ArrayUtils.contains(result, "VT")) {
- map.put("Upt", rtAnalogData.getUpt());
- map.put("Udt", rtAnalogData.getUdt());
- map.put("Ust", rtAnalogData.getUst());
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (days <= 24) {
- map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), "MM-dd HH:mm"));
- } else if (days < 360 && days > 24) {
- map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), "MM-dd HH:mm"));
- } else if (days >= 360) {
- map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), DateUtils.PARSE_PATTERNS[8]));
- }
- list.add(map);
- });
- }
- return list;
- }
- @Override
- public List<Map<String, Object>> getHistoricalCurve(Integer siteId, Date startTime, Date endTime, String queryType) {
- List<Map<String, Object>> list = new ArrayList<>();
- List<Map<String, Object>> listdataTime = new ArrayList<>();
- List<Map<String, Object>> list1 = new ArrayList<>();
- List<Map<String, Object>> list2 = new ArrayList<>();
- List<Map<String, Object>> list3 = new ArrayList<>();
- List<Map<String, Object>> list4 = new ArrayList<>();
- List<Map<String, Object>> list5 = new ArrayList<>();
- List<Map<String, Object>> list6 = new ArrayList<>();
- List<Map<String, Object>> list7 = new ArrayList<>();
- List<Map<String, Object>> list8 = new ArrayList<>();
- List<Map<String, Object>> list9 = new ArrayList<>();
- List<HtAnalogData> rtAnalogDataList = null;
- long diff = endTime.getTime() - startTime.getTime();
- long days = diff / (1000 * 60 * 60);
- if (days <= 24) {
- rtAnalogDataList = baseMapper.getDataReportMap(siteId, startTime, endTime);
- } else if (days < 360 && days > 24) {
- List<Device> device_list = baseMapper.getDeviceListMap(siteId);
- rtAnalogDataList = baseMapper.getDataReportMMap(device_list, startTime, endTime);
- } else if (days >= 360) {
- List<Device> device_list = baseMapper.getDeviceListMap(siteId);
- rtAnalogDataList = baseMapper.getDataReportDMap(device_list, startTime, endTime);
- }
- String[] result = queryType.split(",");
- if (rtAnalogDataList.size() > 0) {
- Map<String, Object> mapIe1 = new HashMap<>();
- Map<String, Object> mapIe2 = new HashMap<>();
- Map<String, Object> mapIe3 = new HashMap<>();
- Map<String, Object> mapIe4 = new HashMap<>();
- Map<String, Object> mapIe5 = new HashMap<>();
- Map<String, Object> mapIe6 = new HashMap<>();
- Map<String, Object> mapIe7 = new HashMap<>();
- Map<String, Object> mapIe8 = new HashMap<>();
- Map<String, Object> mapIe9 = new HashMap<>();
- for (int i = 0; i < rtAnalogDataList.size(); i++) {
- Map<String, Object> map = new HashMap<>();
- Map<String, Object> map1 = new HashMap<>();
- Map<String, Object> map2 = new HashMap<>();
- Map<String, Object> map3 = new HashMap<>();
- Map<String, Object> map4 = new HashMap<>();
- Map<String, Object> map5 = new HashMap<>();
- Map<String, Object> map6 = new HashMap<>();
- Map<String, Object> map7 = new HashMap<>();
- Map<String, Object> map8 = new HashMap<>();
- Map<String, Object> map9 = new HashMap<>();
- HtAnalogData rtAnalogData = (HtAnalogData) rtAnalogDataList.get(i);
- // if (days<=24){
- // map.put("dataTime",DateUtils.format(rtAnalogData.getDataTime(),"MM-dd HH:mm"));
- // }else if (days<360&&days>24){
- // map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(),"MM-dd HH:mm"));
- // }else if (days>=360){
- // map.put("dataTime",DateUtils.format(rtAnalogData.getDataTime(),DateUtils.PARSE_PATTERNS[8]));
- // }
- map.put("dataTime", rtAnalogData.getDataTime());
- if (ArrayUtils.contains(result, "I")) {
- map1.put("Ia", rtAnalogData.getIa());
- map2.put("Ib", rtAnalogData.getIb());
- map3.put("Ic", rtAnalogData.getIc());
- } else if (ArrayUtils.contains(result, "P")) {
- map1.put("P", rtAnalogData.getP());
- map2.put("Q", rtAnalogData.getQ());
- map3.put("Pa", rtAnalogData.getPa());
- map4.put("Pb", rtAnalogData.getPb());
- map5.put("Pc", rtAnalogData.getPc());
- map6.put("Qa", rtAnalogData.getQa());
- map7.put("Qb", rtAnalogData.getQb());
- map8.put("Qc", rtAnalogData.getQc());
- map9.put("Demand", rtAnalogData.getDemand());
- } else if (ArrayUtils.contains(result, "KWh")) {
- map1.put("Epn", rtAnalogData.getEpn());
- map2.put("Epp", rtAnalogData.getEpp());
- map3.put("Eqn", rtAnalogData.getEqn());
- map4.put("Eqp", rtAnalogData.getEqp());
- } else if (ArrayUtils.contains(result, "V")) {
- map1.put("Ua", rtAnalogData.getUa());
- map2.put("Ub", rtAnalogData.getUb());
- map3.put("Uc", rtAnalogData.getUc());
- map4.put("Uab", rtAnalogData.getUab());
- map5.put("Ubc", rtAnalogData.getUbc());
- map6.put("Uca", rtAnalogData.getUca());
- map7.put("Ul", rtAnalogData.getUl());
- } else if (ArrayUtils.contains(result, "C")) {
- map1.put("T1", rtAnalogData.getT1());
- map2.put("T2", rtAnalogData.getT2());
- map3.put("T3", rtAnalogData.getT3());
- map4.put("T4", rtAnalogData.getT4());
- map5.put("DeviceTemp", rtAnalogData.getDeviceTemp());
- } else if (ArrayUtils.contains(result, "HZ")) {
- map1.put("F", rtAnalogData.getF());
- } else if (ArrayUtils.contains(result, "PS")) {
- map1.put("COSa", rtAnalogData.getCOSa());
- map2.put("COSb", rtAnalogData.getCOSb());
- map3.put("COSc", rtAnalogData.getCOSc());
- map4.put("COS", rtAnalogData.getCos());
- } else if (ArrayUtils.contains(result, "RMS")) {
- map1.put("IHa", rtAnalogData.getIHa());
- map2.put("IHb", rtAnalogData.getIHb());
- map3.put("IHc", rtAnalogData.getIHc());
- } else if (ArrayUtils.contains(result, "DDB")) {
- map1.put("SignalIntensity", rtAnalogData.getSignalIntensity());
- } else if (ArrayUtils.contains(result, "VT")) {
- map1.put("Upt", rtAnalogData.getUpt());
- map2.put("Udt", rtAnalogData.getUdt());
- map3.put("Ust", rtAnalogData.getUst());
- }
- listdataTime.add(map);
- list1.add(map1);
- list2.add(map2);
- list3.add(map3);
- list4.add(map4);
- list5.add(map5);
- list6.add(map6);
- list7.add(map7);
- list8.add(map8);
- list9.add(map9);
- }
- Object arre1[][] = new Object[listdataTime.size()][2];
- Object arre2[][] = new Object[listdataTime.size()][2];
- Object arre3[][] = new Object[listdataTime.size()][2];
- Object arre4[][] = new Object[listdataTime.size()][2];
- Object arre5[][] = new Object[listdataTime.size()][2];
- Object arre6[][] = new Object[listdataTime.size()][2];
- Object arre7[][] = new Object[listdataTime.size()][2];
- Object arre8[][] = new Object[listdataTime.size()][2];
- Object arre9[][] = new Object[listdataTime.size()][2];
- if (ArrayUtils.contains(result, "I")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("Ia");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("Ib");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("Ic");
- }
- mapIe1.put("name", "A相电流");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "B相电流");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "C相电流");
- mapIe3.put("arr", arre3);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- } else if (ArrayUtils.contains(result, "P")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("P");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("Q");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("Pa");
- arre4[i][0] = listdataTime.get(i).get("dataTime");
- arre4[i][1] = list4.get(i).get("Pb");
- arre5[i][0] = listdataTime.get(i).get("dataTime");
- arre5[i][1] = list5.get(i).get("Pc");
- arre6[i][0] = listdataTime.get(i).get("dataTime");
- arre6[i][1] = list6.get(i).get("Qa");
- arre7[i][0] = listdataTime.get(i).get("dataTime");
- arre7[i][1] = list7.get(i).get("Qb");
- arre8[i][0] = listdataTime.get(i).get("dataTime");
- arre8[i][1] = list8.get(i).get("Qc");
- arre9[i][0] = listdataTime.get(i).get("dataTime");
- arre9[i][1] = list9.get(i).get("Demand");
- }
- mapIe1.put("name", "总有功功率");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "总无功功率");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "A相有功功率");
- mapIe3.put("arr", arre3);
- mapIe4.put("name", "B相有功功率");
- mapIe4.put("arr", arre4);
- mapIe5.put("name", "C相有功功率");
- mapIe5.put("arr", arre5);
- mapIe6.put("name", "A相无功功率");
- mapIe6.put("arr", arre6);
- mapIe7.put("name", "B相无功功率");
- mapIe7.put("arr", arre7);
- mapIe8.put("name", "C相无功功率");
- mapIe8.put("arr", arre8);
- mapIe9.put("name", "实时需量");
- mapIe9.put("arr", arre9);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- list.add(mapIe4);
- list.add(mapIe5);
- list.add(mapIe6);
- list.add(mapIe7);
- list.add(mapIe8);
- list.add(mapIe9);
- } else if (ArrayUtils.contains(result, "KWh")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("Epn");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("Epp");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("Eqn");
- arre4[i][0] = listdataTime.get(i).get("dataTime");
- arre4[i][1] = list4.get(i).get("Eqp");
- }
- mapIe1.put("name", "负有功电度");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "正有功电度");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "负无功电度");
- mapIe3.put("arr", arre3);
- mapIe4.put("name", "正无功电度");
- mapIe4.put("arr", arre4);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- list.add(mapIe4);
- } else if (ArrayUtils.contains(result, "V")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("Ua");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("Ub");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("Uc");
- arre4[i][0] = listdataTime.get(i).get("dataTime");
- arre4[i][1] = list4.get(i).get("Uab");
- arre5[i][0] = listdataTime.get(i).get("dataTime");
- arre5[i][1] = list5.get(i).get("Ubc");
- arre6[i][0] = listdataTime.get(i).get("dataTime");
- arre6[i][1] = list6.get(i).get("Uca");
- arre7[i][0] = listdataTime.get(i).get("dataTime");
- arre7[i][1] = list7.get(i).get("Ul");
- }
- mapIe1.put("name", "A相电压");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "B相电压");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "C相电压");
- mapIe3.put("arr", arre3);
- mapIe4.put("name", "AB线电压");
- mapIe4.put("arr", arre4);
- mapIe5.put("name", "BC线电压");
- mapIe5.put("arr", arre5);
- mapIe6.put("name", "CA线电压");
- mapIe6.put("arr", arre6);
- mapIe7.put("name", "回路电压");
- mapIe7.put("arr", arre7);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- list.add(mapIe4);
- list.add(mapIe5);
- list.add(mapIe6);
- list.add(mapIe7);
- } else if (ArrayUtils.contains(result, "C")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("T1");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("T2");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("T3");
- arre4[i][0] = listdataTime.get(i).get("dataTime");
- arre4[i][1] = list4.get(i).get("T4");
- arre5[i][0] = listdataTime.get(i).get("dataTime");
- arre5[i][1] = list5.get(i).get("DeviceTemp");
- }
- mapIe1.put("name", "外接温度1");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "外接温度1");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "外接温度1");
- mapIe3.put("arr", arre3);
- mapIe4.put("name", "外接温度1");
- mapIe4.put("arr", arre4);
- mapIe5.put("name", "环境温度");
- mapIe5.put("arr", arre5);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- list.add(mapIe4);
- list.add(mapIe5);
- } else if (ArrayUtils.contains(result, "HZ")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("F");
- }
- mapIe1.put("name", "频率");
- mapIe1.put("arr", arre1);
- list.add(mapIe1);
- } else if (ArrayUtils.contains(result, "PS")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("COSa");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("COSb");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("COSc");
- arre4[i][0] = listdataTime.get(i).get("dataTime");
- arre4[i][1] = list4.get(i).get("COS");
- }
- mapIe1.put("name", "A相功率因数");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "B相功率因数");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "C相功率因数");
- mapIe3.put("arr", arre3);
- mapIe4.put("name", "功率因数");
- mapIe4.put("arr", arre4);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- list.add(mapIe4);
- } else if (ArrayUtils.contains(result, "RMS")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("IHa");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("IHb");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("IHc");
- }
- mapIe1.put("name", "Ia总谐波电流");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "Ib总谐波电流");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "Ic总谐波电流");
- mapIe3.put("arr", arre3);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- } else if (ArrayUtils.contains(result, "DDB")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("SignalIntensity");
- }
- mapIe1.put("name", "设备信号强度");
- mapIe1.put("arr", arre1);
- list.add(mapIe1);
- } else if (ArrayUtils.contains(result, "VT")) {
- for (int i = 0; i < listdataTime.size(); i++) {
- arre1[i][0] = listdataTime.get(i).get("dataTime");
- arre1[i][1] = list1.get(i).get("Upt");
- arre2[i][0] = listdataTime.get(i).get("dataTime");
- arre2[i][1] = list2.get(i).get("Udt");
- arre3[i][0] = listdataTime.get(i).get("dataTime");
- arre3[i][1] = list3.get(i).get("Ust");
- }
- mapIe1.put("name", "电压暂升次数");
- mapIe1.put("arr", arre1);
- mapIe2.put("name", "电压暂降次数");
- mapIe2.put("arr", arre2);
- mapIe3.put("name", "电压中断次数");
- mapIe3.put("arr", arre3);
- list.add(mapIe1);
- list.add(mapIe2);
- list.add(mapIe3);
- }
- }
- return list;
- }
- @Override
- public String DataReportExport(Integer siteId, Date startTime, Date endTime, String queryType) {
- Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
- 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 {
- 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);
- if (null != workbook) {
- file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "数据报表", System.currentTimeMillis() + ""));
- FileUtils.createFile(file.getAbsolutePath());
- FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
- workbook.write(allListingFileOutputStream);
- } else {
- throw new BusinessException("表格数据为空");
- }
- } catch (FileNotFoundException e) {
- log.error("导出文件失败", e);
- throw new BusinessException("导出文件失败");
- } catch (IOException e) {
- e.printStackTrace();
- }
- return file.getName();
- }
- // @Override
- // public String DataReportExport(Integer siteId,Date startTime, Date endTime,String queryType){
- // Integer userId = UserUtil.getUserId();
- // Workbook workbook = null;
- // File file = null;
- // long diff = endTime.getTime() - startTime.getTime();
- // long days = diff / (1000 * 60 * 60);
- // 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);
- // }
- //
- // 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());
- // FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
- // workbook.write(allListingFileOutputStream);
- // } else {
- // throw new BusinessException("表格数据为空");
- // }
- // } catch (Exception e) {
- // log.error("导出文件失败", e);
- // throw new BusinessException("导出文件失败");
- // } finally {
- // if (workbook != null) {
- // try {
- // workbook.close();
- // } catch (IOException e) {
- // log.error("===export spec=== 关闭workbook失败", e);
- // }
- // }
- // }
- // return file.getName();
- // }
- }
|