RtAnalogDataServiceImpl.java 65 KB

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