RtAnalogDataServiceImpl.java 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. package com.bizmatics.service.impl;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.bizmatics.common.core.exception.BusinessException;
  9. import com.bizmatics.common.core.util.*;
  10. import com.bizmatics.common.mvc.base.AbstractCrudService;
  11. import com.bizmatics.common.spring.util.GlobalUtils;
  12. import com.bizmatics.model.*;
  13. import com.bizmatics.persistence.mapper.RtAnalogDataMapper;
  14. import com.bizmatics.service.DeviceAttributeService;
  15. import com.bizmatics.service.DeviceService;
  16. import com.bizmatics.service.RtAnalogDataService;
  17. import com.bizmatics.service.SiteDynamicPropertiesService;
  18. import com.bizmatics.service.util.SecurityUtils;
  19. import com.bizmatics.service.vo.RadCountVO;
  20. import com.bizmatics.service.vo.RealScoreVO;
  21. import org.apache.commons.lang3.ArrayUtils;
  22. import org.apache.poi.ss.usermodel.Workbook;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25. import java.io.File;
  26. import java.io.FileNotFoundException;
  27. import java.io.FileOutputStream;
  28. import java.io.IOException;
  29. import java.util.*;
  30. import java.util.concurrent.atomic.AtomicReference;
  31. /**
  32. * <p>
  33. * 服务实现类
  34. * </p>
  35. *
  36. * @author ya
  37. * @since 2021-07-07
  38. */
  39. @Service
  40. public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMapper, RtAnalogData> implements RtAnalogDataService {
  41. @Autowired
  42. private DeviceService deviceService;
  43. @Autowired
  44. private SiteDynamicPropertiesService siteDynamicPropertiesService;
  45. @Autowired
  46. private DeviceAttributeService deviceAttributeService;
  47. @Override
  48. public RadCountVO selectCount() {
  49. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  50. AtomicReference<Integer> heavyLoad = new AtomicReference<>(0);
  51. AtomicReference<Integer> easyLoad = new AtomicReference<>(0);
  52. AtomicReference<Integer> norMalLoad = new AtomicReference<>(0);
  53. AtomicReference<Integer> count = new AtomicReference<>(0);
  54. List<Device> deviceList = deviceService.list(userId, null, null, null, null, null);
  55. List<RtAnalogData> list = baseMapper.list(userId);
  56. for (Device device : deviceList) {
  57. list.stream()
  58. .filter(rtAnalogData -> device.getDeviceCode().equals(rtAnalogData.getDeviceName())).findAny()
  59. .ifPresent(rtAnalogData -> {
  60. String installedCapacity = device.getInstalledCapacity();
  61. double installedCapacityDouble = 0.00;
  62. if (StringUtils.isNotBlank(installedCapacity)) {
  63. installedCapacityDouble = Double.parseDouble(installedCapacity);
  64. if (installedCapacityDouble > 0) {
  65. installedCapacityDouble = Arith.div(rtAnalogData.getP(), installedCapacityDouble);
  66. }
  67. }
  68. if (installedCapacityDouble < 0.4) {
  69. easyLoad.getAndSet(easyLoad.get() + 1);
  70. } else if (installedCapacityDouble >= 0.4 && installedCapacityDouble <= 0.8) {
  71. norMalLoad.getAndSet(norMalLoad.get() + 1);
  72. } else {
  73. heavyLoad.getAndSet(heavyLoad.get() + 1);
  74. }
  75. count.getAndSet(count.get() + 1);
  76. });
  77. }
  78. RadCountVO radCountVO = new RadCountVO();
  79. radCountVO.setHeavyLoad(subRadio(heavyLoad.get(), count.get()));
  80. radCountVO.setEasyLoad(subRadio(easyLoad.get(), count.get()));
  81. radCountVO.setNorMalLoad(Arith.sub(1, Arith.add(radCountVO.getEasyLoad(), radCountVO.getHeavyLoad())));
  82. return radCountVO;
  83. }
  84. public Double subRadio(Integer typeCount, Integer count) {
  85. return Optional.of(count).filter(total -> total != 0).map(sub -> Arith.div(typeCount, sub)).orElse(0.00);
  86. }
  87. @Override
  88. public List<Map<String, Object>> getOne(Integer siteId) {
  89. List<Map<String, Object>> list = new ArrayList<>();
  90. Map<String, Object> radMap = baseMapper.getOneMap(siteId);
  91. Optional.ofNullable(radMap).ifPresent(rad -> {
  92. for (String name : rad.keySet()) {
  93. Map<String, Object> map = new HashMap<>();
  94. map.put("name", name);
  95. map.put("value", rad.get(name));
  96. list.add(map);
  97. }
  98. });
  99. return list;
  100. }
  101. @Override
  102. public Double getEpLoad(Integer siteId) {
  103. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  104. return baseMapper.selectTotalLoad(userId, siteId);
  105. }
  106. @Override
  107. public RealScoreVO realScore(String deviceCode) {
  108. LambdaQueryWrapper<RtAnalogData> queryWrapper = Wrappers.lambdaQuery();
  109. queryWrapper.eq(RtAnalogData::getDeviceName,deviceCode);
  110. RtAnalogData rtAnalogData = getOne(queryWrapper);
  111. Optional.ofNullable(rtAnalogData).orElseThrow(() -> new BusinessException("设备实时信息不存在"));
  112. //查询设备
  113. LambdaQueryWrapper<Device> deviceQuery = Wrappers.lambdaQuery();
  114. deviceQuery.eq(Device::getDeviceCode,deviceCode);
  115. Device device = deviceService.getOne(deviceQuery);
  116. Optional.ofNullable(device).orElseThrow(() -> new BusinessException("设备不存在"));
  117. //查询sd
  118. LambdaQueryWrapper<SiteDynamicProperties> sdQuery = Wrappers.lambdaQuery();
  119. sdQuery.eq(SiteDynamicProperties::getSiteId,device.getSiteId());
  120. SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.getOne(sdQuery);
  121. Optional.ofNullable(siteDynamicProperties).orElseThrow(() -> new BusinessException("sd不存在"));
  122. LambdaQueryWrapper<DeviceAttribute> adQuery = Wrappers.lambdaQuery();
  123. adQuery.eq(DeviceAttribute::getSiteId,device.getSiteId());
  124. List<DeviceAttribute> deviceAttributes = deviceAttributeService.list(adQuery);
  125. if (CollectionUtils.isEmpty(deviceAttributes)){
  126. throw new BusinessException("da不存在");
  127. }
  128. DeviceAttribute deviceAttribute = deviceAttributes.stream().min(Comparator.comparing(DeviceAttribute::getId)).get();
  129. return fillRealScoreData(rtAnalogData,siteDynamicProperties,deviceAttribute);
  130. }
  131. /**
  132. * 填充实时数据
  133. */
  134. @Override
  135. public RealScoreVO fillRealScoreData(RtAnalogData rtAnalogData, SiteDynamicProperties siteDynamicProperties,DeviceAttribute deviceAttribute){
  136. List<Double> checkList = new ArrayList<>();
  137. Integer score = 0;
  138. RealScoreVO realScoreVo = BeanMapperUtils.map(rtAnalogData, RealScoreVO.class);
  139. if (null == realScoreVo.getCos()){
  140. realScoreVo.setCos(0.00);
  141. }
  142. checkList.add(realScoreVo.getIa());
  143. checkList.add(realScoreVo.getIb());
  144. checkList.add(realScoreVo.getIc());
  145. //电流不平衡
  146. realScoreVo.setElBalun(checkBalun(checkList));
  147. checkList.clear();
  148. checkList.add(realScoreVo.getUa());
  149. checkList.add(realScoreVo.getUb());
  150. checkList.add(realScoreVo.getUc());
  151. //电压不平衡
  152. realScoreVo.setVtBalun(checkBalun(checkList));
  153. //电压合格率
  154. double voltageLevel = Double.parseDouble(siteDynamicProperties.getVoltageLevel());
  155. realScoreVo.setUaQualified(Arith.sub(rtAnalogData.getUa(), voltageLevel));
  156. realScoreVo.setUbQualified(Arith.sub(rtAnalogData.getUb(),voltageLevel));
  157. realScoreVo.setUcQualified(Arith.sub(rtAnalogData.getUc(), voltageLevel));
  158. //电流负载率
  159. Double ratedCurrent = deviceAttribute.getRatedCurrent();
  160. realScoreVo.setIaLoad(Arith.div(realScoreVo.getIa(),ratedCurrent));
  161. realScoreVo.setIbLoad(Arith.div(realScoreVo.getIb(),ratedCurrent));
  162. realScoreVo.setIcLoad(Arith.div(realScoreVo.getIc(),ratedCurrent));
  163. //计算分数
  164. //电压分数
  165. realScoreVo.setUaQ(computeUScore(realScoreVo.getUaQualified(), voltageLevel));
  166. realScoreVo.setUbQ(computeUScore(realScoreVo.getUbQualified(), voltageLevel));
  167. realScoreVo.setUcQ(computeUScore(realScoreVo.getUcQualified(), voltageLevel));
  168. if (realScoreVo.getUaQ() && realScoreVo.getUbQ() && realScoreVo.getUcQ()) {
  169. realScoreVo.setUQ(true);
  170. score+=20;
  171. }else {
  172. realScoreVo.setUQ(false);
  173. }
  174. //电流分数
  175. realScoreVo.setIaLoadQ(realScoreVo.getIaLoad() <= 0.8);
  176. realScoreVo.setIbLoadQ(realScoreVo.getIbLoad() <= 0.8);
  177. realScoreVo.setIcLoadQ(realScoreVo.getIcLoad() <= 0.8);
  178. if (realScoreVo.getIaLoadQ() && realScoreVo.getIbLoadQ() && realScoreVo.getIcLoadQ()){
  179. realScoreVo.setILoadQ(true);
  180. score+=20;
  181. }else {
  182. realScoreVo.setILoadQ(false);
  183. }
  184. //电压平衡分数
  185. realScoreVo.setElBalunQ(realScoreVo.getElBalun() <= 0.15);
  186. if (realScoreVo.getElBalunQ()){
  187. score+=20;
  188. }
  189. //电流平衡分数
  190. realScoreVo.setVtBalunQ(realScoreVo.getVtBalun() <= 0.15);
  191. if (realScoreVo.getVtBalunQ()){
  192. score+=20;
  193. }
  194. //功率
  195. realScoreVo.setCosQ(realScoreVo.getCos() <= 0.15);
  196. if (realScoreVo.getCosQ()){
  197. score+=20;
  198. }
  199. realScoreVo.setScore(score);
  200. return realScoreVo;
  201. }
  202. /**
  203. * 计算电压分数
  204. * @return
  205. */
  206. public Boolean computeUScore(Double qualified,Double voltageLevel){
  207. double mul = Arith.mul(qualified, voltageLevel);
  208. if (mul <= 0.07 && mul >= -0.07){
  209. return true;
  210. }
  211. return false;
  212. }
  213. /**
  214. * 计算电流/电压不平衡
  215. * @param list
  216. * @return
  217. */
  218. public Double checkBalun(List<Double> list){
  219. long count = list.stream().filter(code -> 0.00 == code).count();
  220. if (3 == count){
  221. return 0.00;
  222. }
  223. Double max = list.stream().max(Double::compareTo).get();
  224. Double min = list.stream().min(Double::compareTo).get();
  225. return Arith.div(Arith.sub(max,min),max);
  226. }
  227. /**
  228. * 添加数据单位
  229. *
  230. * @return
  231. */
  232. public String addUnit(String name, String value) {
  233. if (name.endsWith("电压")) {
  234. return value + "V";
  235. } else if (name.endsWith("电流")) {
  236. return value + "A";
  237. } else if (name.endsWith("温度")) {
  238. return value + "C";
  239. } else if (name.endsWith("频率")) {
  240. return value + "Hz";
  241. } else if (name.endsWith("有功功率") || name.endsWith("需量")) {
  242. return value + "KW";
  243. } else if (name.endsWith("无功功率")) {
  244. return value + "KVar";
  245. } else if (name.endsWith("不平衡度") || name.endsWith("电压畸变率")) {
  246. return value + "%";
  247. } else if (name.endsWith("次数")) {
  248. return value + "次";
  249. } else if (name.endsWith("电度") || name.endsWith("有功")) {
  250. return value + "KWh";
  251. }
  252. return value;
  253. }
  254. @Override
  255. public List<Map<String, Object>> getDataReport(Integer siteId, Date startTime, Date endTime, String queryType) {
  256. List<Map<String, Object>> list = new ArrayList<>();
  257. List<HtAnalogData> rtAnalogDataList = null;
  258. long diff = endTime.getTime() - startTime.getTime();
  259. long days = diff / (1000 * 60 * 60);
  260. if (days <= 24) {
  261. rtAnalogDataList = baseMapper.getDataReportMap(siteId, startTime, endTime);
  262. } else if (days < 360 && days > 24) {
  263. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  264. rtAnalogDataList = baseMapper.getDataReportMMap(device_list, startTime, endTime);
  265. } else if (days >= 360) {
  266. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  267. rtAnalogDataList = baseMapper.getDataReportDMap(device_list, startTime, endTime);
  268. }
  269. String[] result = queryType.split(",");
  270. if (rtAnalogDataList.size() > 0) {
  271. rtAnalogDataList.forEach(rtAnalogData -> {
  272. Map<String, Object> map = new HashMap<>();
  273. if (ArrayUtils.contains(result, "I")) {
  274. map.put("Ia", rtAnalogData.getIa());
  275. map.put("Ib", rtAnalogData.getIb());
  276. map.put("Ic", rtAnalogData.getIc());
  277. if (ArrayUtils.contains(result, "P")) {
  278. map.put("P", rtAnalogData.getP());
  279. map.put("Q", rtAnalogData.getQ());
  280. map.put("Pa", rtAnalogData.getPa());
  281. map.put("Pb", rtAnalogData.getPb());
  282. map.put("Pc", rtAnalogData.getPc());
  283. map.put("Qa", rtAnalogData.getQa());
  284. map.put("Qb", rtAnalogData.getQb());
  285. map.put("Qc", rtAnalogData.getQc());
  286. map.put("Demand", rtAnalogData.getDemand());
  287. if (ArrayUtils.contains(result, "KWh")) {
  288. map.put("Epn", rtAnalogData.getEpn());
  289. map.put("Epp", rtAnalogData.getEpp());
  290. map.put("Eqn", rtAnalogData.getEqn());
  291. map.put("Eqp", rtAnalogData.getEqp());
  292. if (ArrayUtils.contains(result, "V")) {
  293. map.put("Ua", rtAnalogData.getUa());
  294. map.put("Ub", rtAnalogData.getUb());
  295. map.put("Uc", rtAnalogData.getUc());
  296. map.put("Uab", rtAnalogData.getUab());
  297. map.put("Ubc", rtAnalogData.getUbc());
  298. map.put("Uca", rtAnalogData.getUca());
  299. map.put("Ul", rtAnalogData.getUl());
  300. if (ArrayUtils.contains(result, "C")) {
  301. map.put("T1", rtAnalogData.getT1());
  302. map.put("T2", rtAnalogData.getT2());
  303. map.put("T3", rtAnalogData.getT3());
  304. map.put("T4", rtAnalogData.getT4());
  305. map.put("DeviceTemp", rtAnalogData.getDeviceTemp());
  306. if (ArrayUtils.contains(result, "HZ")) {
  307. map.put("F", rtAnalogData.getF());
  308. if (ArrayUtils.contains(result, "PS")) {
  309. map.put("COSa", rtAnalogData.getCOSa());
  310. map.put("COSb", rtAnalogData.getCOSb());
  311. map.put("COSc", rtAnalogData.getCOSc());
  312. map.put("COS", rtAnalogData.getCos());
  313. if (ArrayUtils.contains(result, "RMS")) {
  314. map.put("IHa", rtAnalogData.getIHa());
  315. map.put("IHb", rtAnalogData.getIHb());
  316. map.put("IHc", rtAnalogData.getIHc());
  317. if (ArrayUtils.contains(result, "DDB")) {
  318. map.put("SignalIntensity", rtAnalogData.getSignalIntensity());
  319. if (ArrayUtils.contains(result, "VT")) {
  320. map.put("Upt", rtAnalogData.getUpt());
  321. map.put("Udt", rtAnalogData.getUdt());
  322. map.put("Ust", rtAnalogData.getUst());
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. if (days <= 24) {
  334. map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), "MM-dd HH:mm"));
  335. } else if (days < 360 && days > 24) {
  336. map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), "MM-dd HH:mm"));
  337. } else if (days >= 360) {
  338. map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(), DateUtils.PARSE_PATTERNS[8]));
  339. }
  340. list.add(map);
  341. });
  342. }
  343. return list;
  344. }
  345. @Override
  346. public List<Map<String, Object>> getHistoricalCurve(Integer siteId, Date startTime, Date endTime, String queryType) {
  347. List<Map<String, Object>> list = new ArrayList<>();
  348. List<Map<String, Object>> listdataTime = new ArrayList<>();
  349. List<Map<String, Object>> list1 = new ArrayList<>();
  350. List<Map<String, Object>> list2 = new ArrayList<>();
  351. List<Map<String, Object>> list3 = new ArrayList<>();
  352. List<Map<String, Object>> list4 = new ArrayList<>();
  353. List<Map<String, Object>> list5 = new ArrayList<>();
  354. List<Map<String, Object>> list6 = new ArrayList<>();
  355. List<Map<String, Object>> list7 = new ArrayList<>();
  356. List<Map<String, Object>> list8 = new ArrayList<>();
  357. List<Map<String, Object>> list9 = new ArrayList<>();
  358. List<HtAnalogData> rtAnalogDataList = null;
  359. long diff = endTime.getTime() - startTime.getTime();
  360. long days = diff / (1000 * 60 * 60);
  361. if (days <= 24) {
  362. rtAnalogDataList = baseMapper.getDataReportMap(siteId, startTime, endTime);
  363. } else if (days < 360 && days > 24) {
  364. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  365. rtAnalogDataList = baseMapper.getDataReportMMap(device_list, startTime, endTime);
  366. } else if (days >= 360) {
  367. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  368. rtAnalogDataList = baseMapper.getDataReportDMap(device_list, startTime, endTime);
  369. }
  370. String[] result = queryType.split(",");
  371. if (rtAnalogDataList.size() > 0) {
  372. Map<String, Object> mapIe1 = new HashMap<>();
  373. Map<String, Object> mapIe2 = new HashMap<>();
  374. Map<String, Object> mapIe3 = new HashMap<>();
  375. Map<String, Object> mapIe4 = new HashMap<>();
  376. Map<String, Object> mapIe5 = new HashMap<>();
  377. Map<String, Object> mapIe6 = new HashMap<>();
  378. Map<String, Object> mapIe7 = new HashMap<>();
  379. Map<String, Object> mapIe8 = new HashMap<>();
  380. Map<String, Object> mapIe9 = new HashMap<>();
  381. for (int i = 0; i < rtAnalogDataList.size(); i++) {
  382. Map<String, Object> map = new HashMap<>();
  383. Map<String, Object> map1 = new HashMap<>();
  384. Map<String, Object> map2 = new HashMap<>();
  385. Map<String, Object> map3 = new HashMap<>();
  386. Map<String, Object> map4 = new HashMap<>();
  387. Map<String, Object> map5 = new HashMap<>();
  388. Map<String, Object> map6 = new HashMap<>();
  389. Map<String, Object> map7 = new HashMap<>();
  390. Map<String, Object> map8 = new HashMap<>();
  391. Map<String, Object> map9 = new HashMap<>();
  392. HtAnalogData rtAnalogData = (HtAnalogData) rtAnalogDataList.get(i);
  393. // if (days<=24){
  394. // map.put("dataTime",DateUtils.format(rtAnalogData.getDataTime(),"MM-dd HH:mm"));
  395. // }else if (days<360&&days>24){
  396. // map.put("dataTime", DateUtils.format(rtAnalogData.getDataTime(),"MM-dd HH:mm"));
  397. // }else if (days>=360){
  398. // map.put("dataTime",DateUtils.format(rtAnalogData.getDataTime(),DateUtils.PARSE_PATTERNS[8]));
  399. // }
  400. map.put("dataTime", rtAnalogData.getDataTime());
  401. if (ArrayUtils.contains(result, "I")) {
  402. map1.put("Ia", rtAnalogData.getIa());
  403. map2.put("Ib", rtAnalogData.getIb());
  404. map3.put("Ic", rtAnalogData.getIc());
  405. } else if (ArrayUtils.contains(result, "P")) {
  406. map1.put("P", rtAnalogData.getP());
  407. map2.put("Q", rtAnalogData.getQ());
  408. map3.put("Pa", rtAnalogData.getPa());
  409. map4.put("Pb", rtAnalogData.getPb());
  410. map5.put("Pc", rtAnalogData.getPc());
  411. map6.put("Qa", rtAnalogData.getQa());
  412. map7.put("Qb", rtAnalogData.getQb());
  413. map8.put("Qc", rtAnalogData.getQc());
  414. map9.put("Demand", rtAnalogData.getDemand());
  415. } else if (ArrayUtils.contains(result, "KWh")) {
  416. map1.put("Epn", rtAnalogData.getEpn());
  417. map2.put("Epp", rtAnalogData.getEpp());
  418. map3.put("Eqn", rtAnalogData.getEqn());
  419. map4.put("Eqp", rtAnalogData.getEqp());
  420. } else if (ArrayUtils.contains(result, "V")) {
  421. map1.put("Ua", rtAnalogData.getUa());
  422. map2.put("Ub", rtAnalogData.getUb());
  423. map3.put("Uc", rtAnalogData.getUc());
  424. map4.put("Uab", rtAnalogData.getUab());
  425. map5.put("Ubc", rtAnalogData.getUbc());
  426. map6.put("Uca", rtAnalogData.getUca());
  427. map7.put("Ul", rtAnalogData.getUl());
  428. } else if (ArrayUtils.contains(result, "C")) {
  429. map1.put("T1", rtAnalogData.getT1());
  430. map2.put("T2", rtAnalogData.getT2());
  431. map3.put("T3", rtAnalogData.getT3());
  432. map4.put("T4", rtAnalogData.getT4());
  433. map5.put("DeviceTemp", rtAnalogData.getDeviceTemp());
  434. } else if (ArrayUtils.contains(result, "HZ")) {
  435. map1.put("F", rtAnalogData.getF());
  436. } else if (ArrayUtils.contains(result, "PS")) {
  437. map1.put("COSa", rtAnalogData.getCOSa());
  438. map2.put("COSb", rtAnalogData.getCOSb());
  439. map3.put("COSc", rtAnalogData.getCOSc());
  440. map4.put("COS", rtAnalogData.getCos());
  441. } else if (ArrayUtils.contains(result, "RMS")) {
  442. map1.put("IHa", rtAnalogData.getIHa());
  443. map2.put("IHb", rtAnalogData.getIHb());
  444. map3.put("IHc", rtAnalogData.getIHc());
  445. } else if (ArrayUtils.contains(result, "DDB")) {
  446. map1.put("SignalIntensity", rtAnalogData.getSignalIntensity());
  447. } else if (ArrayUtils.contains(result, "VT")) {
  448. map1.put("Upt", rtAnalogData.getUpt());
  449. map2.put("Udt", rtAnalogData.getUdt());
  450. map3.put("Ust", rtAnalogData.getUst());
  451. }
  452. listdataTime.add(map);
  453. list1.add(map1);
  454. list2.add(map2);
  455. list3.add(map3);
  456. list4.add(map4);
  457. list5.add(map5);
  458. list6.add(map6);
  459. list7.add(map7);
  460. list8.add(map8);
  461. list9.add(map9);
  462. }
  463. Object arre1[][] = new Object[listdataTime.size()][2];
  464. Object arre2[][] = new Object[listdataTime.size()][2];
  465. Object arre3[][] = new Object[listdataTime.size()][2];
  466. Object arre4[][] = new Object[listdataTime.size()][2];
  467. Object arre5[][] = new Object[listdataTime.size()][2];
  468. Object arre6[][] = new Object[listdataTime.size()][2];
  469. Object arre7[][] = new Object[listdataTime.size()][2];
  470. Object arre8[][] = new Object[listdataTime.size()][2];
  471. Object arre9[][] = new Object[listdataTime.size()][2];
  472. if (ArrayUtils.contains(result, "I")) {
  473. for (int i = 0; i < listdataTime.size(); i++) {
  474. arre1[i][0] = listdataTime.get(i).get("dataTime");
  475. arre1[i][1] = list1.get(i).get("Ia");
  476. arre2[i][0] = listdataTime.get(i).get("dataTime");
  477. arre2[i][1] = list2.get(i).get("Ib");
  478. arre3[i][0] = listdataTime.get(i).get("dataTime");
  479. arre3[i][1] = list3.get(i).get("Ic");
  480. }
  481. mapIe1.put("name", "A相电流");
  482. mapIe1.put("arr", arre1);
  483. mapIe2.put("name", "B相电流");
  484. mapIe2.put("arr", arre2);
  485. mapIe3.put("name", "C相电流");
  486. mapIe3.put("arr", arre3);
  487. list.add(mapIe1);
  488. list.add(mapIe2);
  489. list.add(mapIe3);
  490. } else if (ArrayUtils.contains(result, "P")) {
  491. for (int i = 0; i < listdataTime.size(); i++) {
  492. arre1[i][0] = listdataTime.get(i).get("dataTime");
  493. arre1[i][1] = list1.get(i).get("P");
  494. arre2[i][0] = listdataTime.get(i).get("dataTime");
  495. arre2[i][1] = list2.get(i).get("Q");
  496. arre3[i][0] = listdataTime.get(i).get("dataTime");
  497. arre3[i][1] = list3.get(i).get("Pa");
  498. arre4[i][0] = listdataTime.get(i).get("dataTime");
  499. arre4[i][1] = list4.get(i).get("Pb");
  500. arre5[i][0] = listdataTime.get(i).get("dataTime");
  501. arre5[i][1] = list5.get(i).get("Pc");
  502. arre6[i][0] = listdataTime.get(i).get("dataTime");
  503. arre6[i][1] = list6.get(i).get("Qa");
  504. arre7[i][0] = listdataTime.get(i).get("dataTime");
  505. arre7[i][1] = list7.get(i).get("Qb");
  506. arre8[i][0] = listdataTime.get(i).get("dataTime");
  507. arre8[i][1] = list8.get(i).get("Qc");
  508. arre9[i][0] = listdataTime.get(i).get("dataTime");
  509. arre9[i][1] = list9.get(i).get("Demand");
  510. }
  511. mapIe1.put("name", "总有功功率");
  512. mapIe1.put("arr", arre1);
  513. mapIe2.put("name", "总无功功率");
  514. mapIe2.put("arr", arre2);
  515. mapIe3.put("name", "A相有功功率");
  516. mapIe3.put("arr", arre3);
  517. mapIe4.put("name", "B相有功功率");
  518. mapIe4.put("arr", arre4);
  519. mapIe5.put("name", "C相有功功率");
  520. mapIe5.put("arr", arre5);
  521. mapIe6.put("name", "A相无功功率");
  522. mapIe6.put("arr", arre6);
  523. mapIe7.put("name", "B相无功功率");
  524. mapIe7.put("arr", arre7);
  525. mapIe8.put("name", "C相无功功率");
  526. mapIe8.put("arr", arre8);
  527. mapIe9.put("name", "实时需量");
  528. mapIe9.put("arr", arre9);
  529. list.add(mapIe1);
  530. list.add(mapIe2);
  531. list.add(mapIe3);
  532. list.add(mapIe4);
  533. list.add(mapIe5);
  534. list.add(mapIe6);
  535. list.add(mapIe7);
  536. list.add(mapIe8);
  537. list.add(mapIe9);
  538. } else if (ArrayUtils.contains(result, "KWh")) {
  539. for (int i = 0; i < listdataTime.size(); i++) {
  540. arre1[i][0] = listdataTime.get(i).get("dataTime");
  541. arre1[i][1] = list1.get(i).get("Epn");
  542. arre2[i][0] = listdataTime.get(i).get("dataTime");
  543. arre2[i][1] = list2.get(i).get("Epp");
  544. arre3[i][0] = listdataTime.get(i).get("dataTime");
  545. arre3[i][1] = list3.get(i).get("Eqn");
  546. arre4[i][0] = listdataTime.get(i).get("dataTime");
  547. arre4[i][1] = list4.get(i).get("Eqp");
  548. }
  549. mapIe1.put("name", "负有功电度");
  550. mapIe1.put("arr", arre1);
  551. mapIe2.put("name", "正有功电度");
  552. mapIe2.put("arr", arre2);
  553. mapIe3.put("name", "负无功电度");
  554. mapIe3.put("arr", arre3);
  555. mapIe4.put("name", "正无功电度");
  556. mapIe4.put("arr", arre4);
  557. list.add(mapIe1);
  558. list.add(mapIe2);
  559. list.add(mapIe3);
  560. list.add(mapIe4);
  561. } else if (ArrayUtils.contains(result, "V")) {
  562. for (int i = 0; i < listdataTime.size(); i++) {
  563. arre1[i][0] = listdataTime.get(i).get("dataTime");
  564. arre1[i][1] = list1.get(i).get("Ua");
  565. arre2[i][0] = listdataTime.get(i).get("dataTime");
  566. arre2[i][1] = list2.get(i).get("Ub");
  567. arre3[i][0] = listdataTime.get(i).get("dataTime");
  568. arre3[i][1] = list3.get(i).get("Uc");
  569. arre4[i][0] = listdataTime.get(i).get("dataTime");
  570. arre4[i][1] = list4.get(i).get("Uab");
  571. arre5[i][0] = listdataTime.get(i).get("dataTime");
  572. arre5[i][1] = list5.get(i).get("Ubc");
  573. arre6[i][0] = listdataTime.get(i).get("dataTime");
  574. arre6[i][1] = list6.get(i).get("Uca");
  575. arre7[i][0] = listdataTime.get(i).get("dataTime");
  576. arre7[i][1] = list7.get(i).get("Ul");
  577. }
  578. mapIe1.put("name", "A相电压");
  579. mapIe1.put("arr", arre1);
  580. mapIe2.put("name", "B相电压");
  581. mapIe2.put("arr", arre2);
  582. mapIe3.put("name", "C相电压");
  583. mapIe3.put("arr", arre3);
  584. mapIe4.put("name", "AB线电压");
  585. mapIe4.put("arr", arre4);
  586. mapIe5.put("name", "BC线电压");
  587. mapIe5.put("arr", arre5);
  588. mapIe6.put("name", "CA线电压");
  589. mapIe6.put("arr", arre6);
  590. mapIe7.put("name", "回路电压");
  591. mapIe7.put("arr", arre7);
  592. list.add(mapIe1);
  593. list.add(mapIe2);
  594. list.add(mapIe3);
  595. list.add(mapIe4);
  596. list.add(mapIe5);
  597. list.add(mapIe6);
  598. list.add(mapIe7);
  599. } else if (ArrayUtils.contains(result, "C")) {
  600. for (int i = 0; i < listdataTime.size(); i++) {
  601. arre1[i][0] = listdataTime.get(i).get("dataTime");
  602. arre1[i][1] = list1.get(i).get("T1");
  603. arre2[i][0] = listdataTime.get(i).get("dataTime");
  604. arre2[i][1] = list2.get(i).get("T2");
  605. arre3[i][0] = listdataTime.get(i).get("dataTime");
  606. arre3[i][1] = list3.get(i).get("T3");
  607. arre4[i][0] = listdataTime.get(i).get("dataTime");
  608. arre4[i][1] = list4.get(i).get("T4");
  609. arre5[i][0] = listdataTime.get(i).get("dataTime");
  610. arre5[i][1] = list5.get(i).get("DeviceTemp");
  611. }
  612. mapIe1.put("name", "外接温度1");
  613. mapIe1.put("arr", arre1);
  614. mapIe2.put("name", "外接温度1");
  615. mapIe2.put("arr", arre2);
  616. mapIe3.put("name", "外接温度1");
  617. mapIe3.put("arr", arre3);
  618. mapIe4.put("name", "外接温度1");
  619. mapIe4.put("arr", arre4);
  620. mapIe5.put("name", "环境温度");
  621. mapIe5.put("arr", arre5);
  622. list.add(mapIe1);
  623. list.add(mapIe2);
  624. list.add(mapIe3);
  625. list.add(mapIe4);
  626. list.add(mapIe5);
  627. } else if (ArrayUtils.contains(result, "HZ")) {
  628. for (int i = 0; i < listdataTime.size(); i++) {
  629. arre1[i][0] = listdataTime.get(i).get("dataTime");
  630. arre1[i][1] = list1.get(i).get("F");
  631. }
  632. mapIe1.put("name", "频率");
  633. mapIe1.put("arr", arre1);
  634. list.add(mapIe1);
  635. } else if (ArrayUtils.contains(result, "PS")) {
  636. for (int i = 0; i < listdataTime.size(); i++) {
  637. arre1[i][0] = listdataTime.get(i).get("dataTime");
  638. arre1[i][1] = list1.get(i).get("COSa");
  639. arre2[i][0] = listdataTime.get(i).get("dataTime");
  640. arre2[i][1] = list2.get(i).get("COSb");
  641. arre3[i][0] = listdataTime.get(i).get("dataTime");
  642. arre3[i][1] = list3.get(i).get("COSc");
  643. arre4[i][0] = listdataTime.get(i).get("dataTime");
  644. arre4[i][1] = list4.get(i).get("COS");
  645. }
  646. mapIe1.put("name", "A相功率因数");
  647. mapIe1.put("arr", arre1);
  648. mapIe2.put("name", "B相功率因数");
  649. mapIe2.put("arr", arre2);
  650. mapIe3.put("name", "C相功率因数");
  651. mapIe3.put("arr", arre3);
  652. mapIe4.put("name", "功率因数");
  653. mapIe4.put("arr", arre4);
  654. list.add(mapIe1);
  655. list.add(mapIe2);
  656. list.add(mapIe3);
  657. list.add(mapIe4);
  658. } else if (ArrayUtils.contains(result, "RMS")) {
  659. for (int i = 0; i < listdataTime.size(); i++) {
  660. arre1[i][0] = listdataTime.get(i).get("dataTime");
  661. arre1[i][1] = list1.get(i).get("IHa");
  662. arre2[i][0] = listdataTime.get(i).get("dataTime");
  663. arre2[i][1] = list2.get(i).get("IHb");
  664. arre3[i][0] = listdataTime.get(i).get("dataTime");
  665. arre3[i][1] = list3.get(i).get("IHc");
  666. }
  667. mapIe1.put("name", "Ia总谐波电流");
  668. mapIe1.put("arr", arre1);
  669. mapIe2.put("name", "Ib总谐波电流");
  670. mapIe2.put("arr", arre2);
  671. mapIe3.put("name", "Ic总谐波电流");
  672. mapIe3.put("arr", arre3);
  673. list.add(mapIe1);
  674. list.add(mapIe2);
  675. list.add(mapIe3);
  676. } else if (ArrayUtils.contains(result, "DDB")) {
  677. for (int i = 0; i < listdataTime.size(); i++) {
  678. arre1[i][0] = listdataTime.get(i).get("dataTime");
  679. arre1[i][1] = list1.get(i).get("SignalIntensity");
  680. }
  681. mapIe1.put("name", "设备信号强度");
  682. mapIe1.put("arr", arre1);
  683. list.add(mapIe1);
  684. } else if (ArrayUtils.contains(result, "VT")) {
  685. for (int i = 0; i < listdataTime.size(); i++) {
  686. arre1[i][0] = listdataTime.get(i).get("dataTime");
  687. arre1[i][1] = list1.get(i).get("Upt");
  688. arre2[i][0] = listdataTime.get(i).get("dataTime");
  689. arre2[i][1] = list2.get(i).get("Udt");
  690. arre3[i][0] = listdataTime.get(i).get("dataTime");
  691. arre3[i][1] = list3.get(i).get("Ust");
  692. }
  693. mapIe1.put("name", "电压暂升次数");
  694. mapIe1.put("arr", arre1);
  695. mapIe2.put("name", "电压暂降次数");
  696. mapIe2.put("arr", arre2);
  697. mapIe3.put("name", "电压中断次数");
  698. mapIe3.put("arr", arre3);
  699. list.add(mapIe1);
  700. list.add(mapIe2);
  701. list.add(mapIe3);
  702. }
  703. }
  704. return list;
  705. }
  706. @Override
  707. public String DataReportExport(Integer siteId, Date startTime, Date endTime, String queryType) {
  708. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  709. Workbook workbook = null;
  710. File file = null;
  711. long diff = endTime.getTime() - startTime.getTime();
  712. long days = diff / (1000 * 60 * 60);
  713. ExportParams params = new ExportParams("数据报表", "数据报表");
  714. List<HtAnalogData> page1 = null;
  715. if (days <= 24) {
  716. page1 = baseMapper.getDataReportMap(siteId, startTime, endTime);
  717. } else if (days < 360 && days > 24) {
  718. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  719. page1 = baseMapper.getDataReportMMap(device_list, startTime, endTime);
  720. } else if (days >= 360) {
  721. List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  722. page1 = baseMapper.getDataReportDMap(device_list, startTime, endTime);
  723. }
  724. String[] result = queryType.split(",");
  725. try {
  726. List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
  727. ExcelExportEntity colEntity = new ExcelExportEntity("序号", "xh");
  728. colEntity.setNeedMerge(true);
  729. colList.add(colEntity);
  730. colEntity = new ExcelExportEntity("时间", "dataTime");
  731. colEntity.setNeedMerge(true);
  732. colList.add(colEntity);
  733. if (ArrayUtils.contains(result, "I")) {
  734. colEntity = new ExcelExportEntity("A相电流", "Ia");
  735. colEntity.setNeedMerge(true);
  736. colList.add(colEntity);
  737. colEntity = new ExcelExportEntity("B相电流", "Ib");
  738. colEntity.setNeedMerge(true);
  739. colList.add(colEntity);
  740. colEntity = new ExcelExportEntity("C相电流", "Ic");
  741. colEntity.setNeedMerge(true);
  742. colList.add(colEntity);
  743. if (ArrayUtils.contains(result, "P")) {
  744. colEntity = new ExcelExportEntity("总有功功率", "P");
  745. colEntity.setNeedMerge(true);
  746. colList.add(colEntity);
  747. colEntity = new ExcelExportEntity("总无功功率", "Q");
  748. colEntity.setNeedMerge(true);
  749. colList.add(colEntity);
  750. colEntity = new ExcelExportEntity("A相有功功率", "Pa");
  751. colEntity.setNeedMerge(true);
  752. colList.add(colEntity);
  753. colEntity = new ExcelExportEntity("B相有功功率", "Pb");
  754. colEntity.setNeedMerge(true);
  755. colList.add(colEntity);
  756. colEntity = new ExcelExportEntity("C相有功功率", "Pc");
  757. colEntity.setNeedMerge(true);
  758. colList.add(colEntity);
  759. colEntity = new ExcelExportEntity("A相无功功率", "Qa");
  760. colEntity.setNeedMerge(true);
  761. colList.add(colEntity);
  762. colEntity = new ExcelExportEntity("B相无功功率", "Qb");
  763. colEntity.setNeedMerge(true);
  764. colList.add(colEntity);
  765. colEntity = new ExcelExportEntity("C相无功功率", "Qc");
  766. colEntity.setNeedMerge(true);
  767. colList.add(colEntity);
  768. colEntity = new ExcelExportEntity("实时需量", "Demand");
  769. colEntity.setNeedMerge(true);
  770. colList.add(colEntity);
  771. if (ArrayUtils.contains(result, "KWh")) {
  772. colEntity = new ExcelExportEntity("负有功电度", "Epn");
  773. colEntity.setNeedMerge(true);
  774. colList.add(colEntity);
  775. colEntity = new ExcelExportEntity("正有功电度", "Epp");
  776. colEntity.setNeedMerge(true);
  777. colList.add(colEntity);
  778. colEntity = new ExcelExportEntity("负无功电度", "Eqn");
  779. colEntity.setNeedMerge(true);
  780. colList.add(colEntity);
  781. colEntity = new ExcelExportEntity("正无功电度", "Eqp");
  782. colEntity.setNeedMerge(true);
  783. colList.add(colEntity);
  784. if (ArrayUtils.contains(result, "V")) {
  785. colEntity = new ExcelExportEntity("A相电压", "Ua");
  786. colEntity.setNeedMerge(true);
  787. colList.add(colEntity);
  788. colEntity = new ExcelExportEntity("B相电压", "Ub");
  789. colEntity.setNeedMerge(true);
  790. colList.add(colEntity);
  791. colEntity = new ExcelExportEntity("C相电压", "Ub");
  792. colEntity.setNeedMerge(true);
  793. colList.add(colEntity);
  794. colEntity = new ExcelExportEntity("AB线电压", "Uab");
  795. colEntity.setNeedMerge(true);
  796. colList.add(colEntity);
  797. colEntity = new ExcelExportEntity("BC线电压", "Ubc");
  798. colEntity.setNeedMerge(true);
  799. colList.add(colEntity);
  800. colEntity = new ExcelExportEntity("CA线电压", "Uca");
  801. colEntity.setNeedMerge(true);
  802. colList.add(colEntity);
  803. colEntity = new ExcelExportEntity("回路电压", "Ul");
  804. colEntity.setNeedMerge(true);
  805. colList.add(colEntity);
  806. if (ArrayUtils.contains(result, "C")) {
  807. colEntity = new ExcelExportEntity("外接温度1", "T1");
  808. colEntity.setNeedMerge(true);
  809. colList.add(colEntity);
  810. colEntity = new ExcelExportEntity("外接温度2", "T2");
  811. colEntity.setNeedMerge(true);
  812. colList.add(colEntity);
  813. colEntity = new ExcelExportEntity("外接温度3", "T3");
  814. colEntity.setNeedMerge(true);
  815. colList.add(colEntity);
  816. colEntity = new ExcelExportEntity("外接温度4", "T4");
  817. colEntity.setNeedMerge(true);
  818. colList.add(colEntity);
  819. colEntity = new ExcelExportEntity("环境温度", "DeviceTemp");
  820. colEntity.setNeedMerge(true);
  821. colList.add(colEntity);
  822. if (ArrayUtils.contains(result, "HZ")) {
  823. colEntity = new ExcelExportEntity("频率", "F");
  824. colEntity.setNeedMerge(true);
  825. colList.add(colEntity);
  826. // map.put("F",rtAnalogData.getF());
  827. if (ArrayUtils.contains(result, "PS")) {
  828. colEntity = new ExcelExportEntity("A相功率因数", "COSa");
  829. colEntity.setNeedMerge(true);
  830. colList.add(colEntity);
  831. colEntity = new ExcelExportEntity("B相功率因数", "COSb");
  832. colEntity.setNeedMerge(true);
  833. colList.add(colEntity);
  834. colEntity = new ExcelExportEntity("C相功率因数", "COSc");
  835. colEntity.setNeedMerge(true);
  836. colList.add(colEntity);
  837. colEntity = new ExcelExportEntity("功率因数", "COS");
  838. colEntity.setNeedMerge(true);
  839. colList.add(colEntity);
  840. if (ArrayUtils.contains(result, "RMS")) {
  841. colEntity = new ExcelExportEntity("Ia总谐波电流", "IHa");
  842. colEntity.setNeedMerge(true);
  843. colList.add(colEntity);
  844. colEntity = new ExcelExportEntity("Ib总谐波电流", "IHb");
  845. colEntity.setNeedMerge(true);
  846. colList.add(colEntity);
  847. colEntity = new ExcelExportEntity("Ic总谐波电流", "IHc");
  848. colEntity.setNeedMerge(true);
  849. colList.add(colEntity);
  850. if (ArrayUtils.contains(result, "DDB")) {
  851. colEntity = new ExcelExportEntity("设备信号强度", "SignalIntensity");
  852. colEntity.setNeedMerge(true);
  853. colList.add(colEntity);
  854. if (ArrayUtils.contains(result, "VT")) {
  855. colEntity = new ExcelExportEntity("电压暂升次数", "Upt");
  856. colEntity.setNeedMerge(true);
  857. colList.add(colEntity);
  858. colEntity = new ExcelExportEntity("电压暂降次数", "Udt");
  859. colEntity.setNeedMerge(true);
  860. colList.add(colEntity);
  861. colEntity = new ExcelExportEntity("电压中断次数", "Ust");
  862. colEntity.setNeedMerge(true);
  863. colList.add(colEntity);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. }
  870. }
  871. }
  872. }
  873. }
  874. List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  875. for (int i = 0; i < page1.size(); i++) {
  876. Map<String, Object> valMap = new HashMap<String, Object>();
  877. valMap.put("xh", i + 1);
  878. if (days <= 24) {
  879. valMap.put("dataTime", DateUtils.format(page1.get(i).getDataTime(), "MM-dd HH:mm"));
  880. } else if (days < 360 && days > 24) {
  881. valMap.put("dataTime", DateUtils.format(page1.get(i).getDataTime(), "MM-dd HH:mm"));
  882. } else if (days >= 360) {
  883. valMap.put("dataTime", DateUtils.format(page1.get(i).getDataTime(), DateUtils.PARSE_PATTERNS[8]));
  884. }
  885. if (ArrayUtils.contains(result, "I")) {
  886. valMap.put("Ia", page1.get(i).getIa());
  887. valMap.put("Ib", page1.get(i).getIb());
  888. valMap.put("Ic", page1.get(i).getIc());
  889. if (ArrayUtils.contains(result, "P")) {
  890. valMap.put("P", page1.get(i).getP());
  891. valMap.put("Q", page1.get(i).getQ());
  892. valMap.put("Pa", page1.get(i).getPa());
  893. valMap.put("Pb", page1.get(i).getPb());
  894. valMap.put("Pc", page1.get(i).getPc());
  895. valMap.put("Qa", page1.get(i).getQa());
  896. valMap.put("Qb", page1.get(i).getQb());
  897. valMap.put("Qc", page1.get(i).getQc());
  898. valMap.put("Demand", page1.get(i).getDemand());
  899. if (ArrayUtils.contains(result, "KWh")) {
  900. valMap.put("Epn", page1.get(i).getEpn());
  901. valMap.put("Epp", page1.get(i).getEpp());
  902. valMap.put("Eqn", page1.get(i).getEqn());
  903. valMap.put("Eqp", page1.get(i).getEqp());
  904. if (ArrayUtils.contains(result, "V")) {
  905. valMap.put("Ua", page1.get(i).getUa());
  906. valMap.put("Ub", page1.get(i).getUb());
  907. valMap.put("Uc", page1.get(i).getUc());
  908. valMap.put("Uab", page1.get(i).getUab());
  909. valMap.put("Ubc", page1.get(i).getUbc());
  910. valMap.put("Uca", page1.get(i).getUca());
  911. valMap.put("Ul", page1.get(i).getUl());
  912. if (ArrayUtils.contains(result, "C")) {
  913. valMap.put("T1", page1.get(i).getT1());
  914. valMap.put("T2", page1.get(i).getT2());
  915. valMap.put("T3", page1.get(i).getT3());
  916. valMap.put("T4", page1.get(i).getT4());
  917. valMap.put("DeviceTemp", page1.get(i).getDeviceTemp());
  918. if (ArrayUtils.contains(result, "HZ")) {
  919. valMap.put("F", page1.get(i).getF());
  920. if (ArrayUtils.contains(result, "PS")) {
  921. valMap.put("COSa", page1.get(i).getCOSa());
  922. valMap.put("COSb", page1.get(i).getCOSb());
  923. valMap.put("COSc", page1.get(i).getCOSc());
  924. valMap.put("COS", page1.get(i).getCos());
  925. if (ArrayUtils.contains(result, "RMS")) {
  926. valMap.put("IHa", page1.get(i).getIHa());
  927. valMap.put("IHb", page1.get(i).getIHb());
  928. valMap.put("IHc", page1.get(i).getIHc());
  929. if (ArrayUtils.contains(result, "DDB")) {
  930. valMap.put("SignalIntensity", page1.get(i).getSignalIntensity());
  931. if (ArrayUtils.contains(result, "VT")) {
  932. valMap.put("Upt", page1.get(i).getUpt());
  933. valMap.put("Udt", page1.get(i).getUdt());
  934. valMap.put("Ust", page1.get(i).getUst());
  935. }
  936. }
  937. }
  938. }
  939. }
  940. }
  941. }
  942. }
  943. }
  944. }
  945. list.add(valMap);
  946. }
  947. workbook = ExcelExportUtil.exportExcel(params, colList, list);
  948. if (null != workbook) {
  949. file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "数据报表", System.currentTimeMillis() + ""));
  950. FileUtils.createFile(file.getAbsolutePath());
  951. FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
  952. workbook.write(allListingFileOutputStream);
  953. } else {
  954. throw new BusinessException("表格数据为空");
  955. }
  956. } catch (FileNotFoundException e) {
  957. log.error("导出文件失败", e);
  958. throw new BusinessException("导出文件失败");
  959. } catch (IOException e) {
  960. e.printStackTrace();
  961. }
  962. return file.getName();
  963. }
  964. // @Override
  965. // public String DataReportExport(Integer siteId,Date startTime, Date endTime,String queryType){
  966. // Integer userId = UserUtil.getUserId();
  967. // Workbook workbook = null;
  968. // File file = null;
  969. // long diff = endTime.getTime() - startTime.getTime();
  970. // long days = diff / (1000 * 60 * 60);
  971. // try {
  972. // ExportParams params = new ExportParams(null, "数据报表");
  973. // workbook = ExcelExportUtil.exportBigExcel(params, HtAnalogDataExportVO.class,
  974. // (o, i) -> {
  975. // Page<HtAnalogData> page = new Page<>(i, 30);
  976. // if (days<=24){
  977. // page = baseMapper.getDataReportMap1(page,siteId, startTime, endTime);
  978. // }else if (days<360&&days>24){
  979. // List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  980. // page = baseMapper.getDataReportMMap1(page,device_list,startTime, endTime);
  981. // }else if (days>=360){
  982. // List<Device> device_list = baseMapper.getDeviceListMap(siteId);
  983. // page = baseMapper.getDataReportDMap1(page,device_list,startTime, endTime);
  984. // }
  985. //
  986. // return new ArrayList<>(BeanMapperUtils.mapList(page.getRecords(), HtAnalogData.class, HtAnalogDataExportVO.class));
  987. // },null);
  988. // if (null != workbook) {
  989. // file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "数据报表", System.currentTimeMillis() + ""));
  990. // FileUtils.createFile(file.getAbsolutePath());
  991. // FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
  992. // workbook.write(allListingFileOutputStream);
  993. // } else {
  994. // throw new BusinessException("表格数据为空");
  995. // }
  996. // } catch (Exception e) {
  997. // log.error("导出文件失败", e);
  998. // throw new BusinessException("导出文件失败");
  999. // } finally {
  1000. // if (workbook != null) {
  1001. // try {
  1002. // workbook.close();
  1003. // } catch (IOException e) {
  1004. // log.error("===export spec=== 关闭workbook失败", e);
  1005. // }
  1006. // }
  1007. // }
  1008. // return file.getName();
  1009. // }
  1010. }