12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259 |
- 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.CollectionUtils;
- 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.model.vo.EvaluationReporVo;
- 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.RealScoreOneVO;
- 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.text.SimpleDateFormat;
- 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);
- }
- public String addUnitOne(String name) {
- if (name.endsWith("电压")) {
- return "V";
- } else if (name.endsWith("电流")) {
- return "A";
- } else if (name.endsWith("温度")) {
- return "℃";
- } else if (name.endsWith("频率")) {
- return "Hz";
- } else if (name.endsWith("有功功率") || name.endsWith("需量")) {
- return "KW";
- } else if (name.endsWith("无功功率")) {
- return "KVar";
- } else if (name.endsWith("不平衡度") || name.endsWith("电压畸变率")) {
- return "%";
- } else if (name.endsWith("次数")) {
- return "次";
- } else if (name.endsWith("电度") || name.endsWith("有功")) {
- return "KWh";
- } else if (name.endsWith("THD")) {
- return "%";
- }
- return "";
- }
- @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) + "" + addUnitOne(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 RealScoreVO realScore(String deviceCode) {
- LambdaQueryWrapper<RtAnalogData> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(RtAnalogData::getDeviceName, deviceCode);
- RtAnalogData rtAnalogData = getOne(queryWrapper);
- Optional.ofNullable(rtAnalogData).orElseThrow(() -> new BusinessException("设备实时信息不存在"));
- //查询设备
- LambdaQueryWrapper<Device> deviceQuery = Wrappers.lambdaQuery();
- deviceQuery.eq(Device::getDeviceCode, deviceCode);
- Device device = deviceService.getOne(deviceQuery);
- Optional.ofNullable(device).orElseThrow(() -> new BusinessException("设备不存在"));
- //查询sd
- LambdaQueryWrapper<SiteDynamicProperties> sdQuery = Wrappers.lambdaQuery();
- sdQuery.eq(SiteDynamicProperties::getSiteId, device.getSiteId());
- SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.getOne(sdQuery);
- Optional.ofNullable(siteDynamicProperties).orElseThrow(() -> new BusinessException("sd不存在"));
- LambdaQueryWrapper<DeviceAttribute> adQuery = Wrappers.lambdaQuery();
- adQuery.eq(DeviceAttribute::getSiteId, device.getSiteId());
- List<DeviceAttribute> deviceAttributes = deviceAttributeService.list(adQuery);
- if (CollectionUtils.isEmpty(deviceAttributes)) {
- throw new BusinessException("da不存在");
- }
- DeviceAttribute deviceAttribute = deviceAttributes.stream().min(Comparator.comparing(DeviceAttribute::getId)).get();
- return fillRealScoreData(rtAnalogData, siteDynamicProperties, deviceAttribute);
- }
- @Override
- public RealScoreOneVO realScoreOne(String deviceCode) {
- LambdaQueryWrapper<RtAnalogData> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(RtAnalogData::getDeviceName, deviceCode);
- RtAnalogData rtAnalogData = getOne(queryWrapper);
- Optional.ofNullable(rtAnalogData).orElseThrow(() -> new BusinessException("设备实时信息不存在"));
- //查询设备
- LambdaQueryWrapper<Device> deviceQuery = Wrappers.lambdaQuery();
- deviceQuery.eq(Device::getDeviceCode, deviceCode);
- Device device = deviceService.getOne(deviceQuery);
- Optional.ofNullable(device).orElseThrow(() -> new BusinessException("设备不存在"));
- //查询sd
- LambdaQueryWrapper<SiteDynamicProperties> sdQuery = Wrappers.lambdaQuery();
- sdQuery.eq(SiteDynamicProperties::getSiteId, device.getSiteId());
- SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.getOne(sdQuery);
- Optional.ofNullable(siteDynamicProperties).orElseThrow(() -> new BusinessException("sd不存在"));
- return fillRealScoreDataOne(rtAnalogData, siteDynamicProperties);
- }
- @Override
- public RealScoreOneVO fillRealScoreDataOne(RtAnalogData rtAnalogData, SiteDynamicProperties siteDynamicProperties) {
- List<Double> checkList = new ArrayList<>();
- RealScoreOneVO realScoreVo = BeanMapperUtils.map(rtAnalogData, RealScoreOneVO.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());
- //ABC三相电压占比
- Double max = checkList.stream().max(Double::compareTo).get();
- if (max == 0.00) {
- realScoreVo.setUaPercentage(0.00);
- realScoreVo.setUbPercentage(0.00);
- realScoreVo.setUcPercentage(0.00);
- } else {
- realScoreVo.setUaPercentage(Arith.div(realScoreVo.getUa(), (max / 100 * 20 + max) * 100));
- realScoreVo.setUbPercentage(Arith.div(realScoreVo.getUb(), (max / 100 * 20 + max) * 100));
- realScoreVo.setUcPercentage(Arith.div(realScoreVo.getUc(), (max / 100 * 20 + max) * 100));
- }
- //电压不平衡
- realScoreVo.setVtBalun(checkBalun(checkList));
- //当前频率
- realScoreVo.setF(realScoreVo.getF());
- //频率偏差
- if (realScoreVo.getF() == 0.00) {
- realScoreVo.setFdeviation(0.00);
- } else {
- checkList.clear();
- checkList.add(50.00);
- checkList.add(realScoreVo.getF());
- Double max1 = checkList.stream().max(Double::compareTo).get();
- Double min1 = checkList.stream().min(Double::compareTo).get();
- realScoreVo.setFdeviation(Arith.sub(max1, min1) / 50 * 100);
- }
- if (realScoreVo.getP() == 0.00) {
- realScoreVo.setPpercentage(0.00);
- } else {
- realScoreVo.setPpercentage(Arith.div(realScoreVo.getP(), realScoreVo.getP() / 100 * 20 + realScoreVo.getP()));
- }
- if (realScoreVo.getQ() == 0.00) {
- realScoreVo.setQpercentage(0.00);
- } else {
- realScoreVo.setQpercentage(Arith.div(realScoreVo.getQ(), realScoreVo.getQ() / 100 * 20 + realScoreVo.getQ()));
- }
- realScoreVo.setVoltageLevel(siteDynamicProperties.getVoltageLevel());
- return realScoreVo;
- }
- /**
- * 填充实时数据
- */
- @Override
- public RealScoreVO fillRealScoreData(RtAnalogData rtAnalogData, SiteDynamicProperties siteDynamicProperties, DeviceAttribute deviceAttribute) {
- List<Double> checkList = new ArrayList<>();
- Integer score = 0;
- RealScoreVO realScoreVo = BeanMapperUtils.map(rtAnalogData, RealScoreVO.class);
- if (null == realScoreVo.getCos()) {
- realScoreVo.setCos(0.00);
- }
- 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));
- //电压合格率
- double voltageLevel = Double.parseDouble(siteDynamicProperties.getVoltageLevel());
- realScoreVo.setUaQualified(Arith.sub(rtAnalogData.getUa(), voltageLevel));
- realScoreVo.setUbQualified(Arith.sub(rtAnalogData.getUb(), voltageLevel));
- realScoreVo.setUcQualified(Arith.sub(rtAnalogData.getUc(), voltageLevel));
- //电流负载率
- Double ratedCurrent = deviceAttribute.getRatedCurrent();
- realScoreVo.setIaLoad(Arith.div(realScoreVo.getIa(), ratedCurrent));
- realScoreVo.setIbLoad(Arith.div(realScoreVo.getIb(), ratedCurrent));
- realScoreVo.setIcLoad(Arith.div(realScoreVo.getIc(), ratedCurrent));
- //计算分数
- //电压分数
- realScoreVo.setUaQ(computeUScore(realScoreVo.getUaQualified(), voltageLevel));
- realScoreVo.setUbQ(computeUScore(realScoreVo.getUbQualified(), voltageLevel));
- realScoreVo.setUcQ(computeUScore(realScoreVo.getUcQualified(), voltageLevel));
- if (realScoreVo.getUaQ() && realScoreVo.getUbQ() && realScoreVo.getUcQ()) {
- realScoreVo.setUQ(true);
- score += 20;
- } else {
- realScoreVo.setUQ(false);
- }
- //电流分数
- realScoreVo.setIaLoadQ(realScoreVo.getIaLoad() <= 0.8);
- realScoreVo.setIbLoadQ(realScoreVo.getIbLoad() <= 0.8);
- realScoreVo.setIcLoadQ(realScoreVo.getIcLoad() <= 0.8);
- if (realScoreVo.getIaLoadQ() && realScoreVo.getIbLoadQ() && realScoreVo.getIcLoadQ()) {
- realScoreVo.setILoadQ(true);
- score += 20;
- } else {
- realScoreVo.setILoadQ(false);
- }
- //电压平衡分数
- realScoreVo.setElBalunQ(realScoreVo.getElBalun() <= 0.15);
- if (realScoreVo.getElBalunQ()) {
- score += 20;
- }
- //电流平衡分数
- realScoreVo.setVtBalunQ(realScoreVo.getVtBalun() <= 0.15);
- if (realScoreVo.getVtBalunQ()) {
- score += 20;
- }
- //功率
- realScoreVo.setCosQ(realScoreVo.getCos() <= 0.15);
- if (realScoreVo.getCosQ()) {
- score += 20;
- }
- realScoreVo.setScore(score);
- return realScoreVo;
- }
- /**
- * 计算电压分数
- *
- * @return
- */
- public Boolean computeUScore(Double qualified, Double voltageLevel) {
- double mul = Arith.mul(qualified, voltageLevel);
- if (mul <= 0.07 && mul >= -0.07) {
- return true;
- }
- return false;
- }
- /**
- * 计算电流/电压不平衡
- *
- * @param list
- * @return
- */
- public Double checkBalun(List<Double> list) {
- long count = list.stream().filter(code -> 0.00 == code).count();
- if (3 == count) {
- return 0.00;
- }
- 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();
- }
- public static Date getLastDayOfMonth(Date sDate1) {
- Calendar cDay1 = Calendar.getInstance();
- cDay1.setTime(sDate1);
- final int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH);
- Date lastDate = cDay1.getTime();
- lastDate.setDate(lastDay);
- return lastDate;
- }
- @Override
- public List<RealScoreVO> evaluationReport(int siteId, Date time, int type) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
- String startTime = null;
- String endtime = null;
- if (type == 1) {
- startTime = sdf.format(time) + " 00:00:00";
- endtime = sdf.format(time) + " 23:59:59";
- } else {
- startTime = sdf1.format(time) + "-01 00:00:00";
- String time1 = sdf1.format(time) + "-01";
- try {
- Date yq = getLastDayOfMonth(sdf.parse(time1));
- endtime = sdf.format(yq) + " 23:59:59";
- } catch (Exception e) {
- throw new BusinessException("时间错误");
- }
- }
- List<EvaluationReporVo> evaluationReporVo = baseMapper.evaluationReportList(siteId, startTime, endtime);
- return fillRealScoreDataTwo(evaluationReporVo);
- }
- @Override
- public List<RealScoreVO> fillRealScoreDataTwo(List<EvaluationReporVo> evaluationReporVo) {
- List<RealScoreVO> realScoreVoList = new ArrayList<>();
- if (evaluationReporVo.size() > 0) {
- for (int i = 0; i < evaluationReporVo.size(); i++) {
- List<Double> checkList = new ArrayList<>();
- Integer score = 0;
- RealScoreVO realScoreVo = BeanMapperUtils.map(evaluationReporVo.get(i), RealScoreVO.class);
- if (null == realScoreVo.getCos()) {
- realScoreVo.setCos(0.00);
- }
- checkList.clear();
- 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));
- //电压合格率
- double voltageLevel = Double.parseDouble(evaluationReporVo.get(i).getVoltageLevel());
- realScoreVo.setUaQualified(Arith.sub(evaluationReporVo.get(i).getUa(), voltageLevel));
- realScoreVo.setUbQualified(Arith.sub(evaluationReporVo.get(i).getUb(), voltageLevel));
- realScoreVo.setUcQualified(Arith.sub(evaluationReporVo.get(i).getUc(), voltageLevel));
- //电流负载率
- Double ratedCurrent = evaluationReporVo.get(i).getRatedCurrent();
- realScoreVo.setIaLoad(Arith.div(realScoreVo.getIa(), ratedCurrent));
- realScoreVo.setIbLoad(Arith.div(realScoreVo.getIb(), ratedCurrent));
- realScoreVo.setIcLoad(Arith.div(realScoreVo.getIc(), ratedCurrent));
- //计算分数
- //电压分数
- realScoreVo.setUaQ(computeUScore(realScoreVo.getUaQualified(), voltageLevel));
- realScoreVo.setUbQ(computeUScore(realScoreVo.getUbQualified(), voltageLevel));
- realScoreVo.setUcQ(computeUScore(realScoreVo.getUcQualified(), voltageLevel));
- if (realScoreVo.getUaQ() && realScoreVo.getUbQ() && realScoreVo.getUcQ()) {
- realScoreVo.setUQ(true);
- score += 20;
- } else {
- realScoreVo.setUQ(false);
- }
- //电流分数
- realScoreVo.setIaLoadQ(realScoreVo.getIaLoad() <= 0.8);
- realScoreVo.setIbLoadQ(realScoreVo.getIbLoad() <= 0.8);
- realScoreVo.setIcLoadQ(realScoreVo.getIcLoad() <= 0.8);
- if (realScoreVo.getIaLoadQ() && realScoreVo.getIbLoadQ() && realScoreVo.getIcLoadQ()) {
- realScoreVo.setILoadQ(true);
- score += 20;
- } else {
- realScoreVo.setILoadQ(false);
- }
- //电压平衡分数
- realScoreVo.setElBalunQ(realScoreVo.getElBalun() <= 0.15);
- if (realScoreVo.getElBalunQ()) {
- score += 20;
- }
- //电流平衡分数
- realScoreVo.setVtBalunQ(realScoreVo.getVtBalun() <= 0.15);
- if (realScoreVo.getVtBalunQ()) {
- score += 20;
- }
- //功率
- realScoreVo.setCosQ(realScoreVo.getCos() <= 0.15);
- if (realScoreVo.getCosQ()) {
- score += 20;
- }
- realScoreVo.setScore(score);
- realScoreVoList.add(realScoreVo);
- }
- }
- return realScoreVoList;
- }
- // @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();
- // }
- }
|