HtAnalogDataServiceImpl.java 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. package com.bizmatics.service.impl;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  6. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  7. import com.bizmatics.common.core.exception.BusinessException;
  8. import com.bizmatics.common.core.util.Arith;
  9. import com.bizmatics.common.core.util.BeanMapperUtils;
  10. import com.bizmatics.common.core.util.DateUtils;
  11. import com.bizmatics.common.core.util.FileUtils;
  12. import com.bizmatics.common.mvc.base.AbstractCrudService;
  13. import com.bizmatics.common.spring.util.GlobalUtils;
  14. import com.bizmatics.common.spring.util.JsonUtils;
  15. import com.bizmatics.model.*;
  16. import com.bizmatics.model.vo.*;
  17. import com.bizmatics.persistence.mapper.HtAnalogDataMapper;
  18. import com.bizmatics.service.*;
  19. import com.bizmatics.service.util.FieldEscapeUtils;
  20. import com.bizmatics.service.util.SecurityUtils;
  21. import com.bizmatics.service.vo.*;
  22. import com.fasterxml.jackson.core.type.TypeReference;
  23. import org.apache.poi.ss.usermodel.Workbook;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import java.io.File;
  27. import java.io.FileOutputStream;
  28. import java.io.IOException;
  29. import java.math.BigDecimal;
  30. import java.text.DateFormat;
  31. import java.text.DecimalFormat;
  32. import java.text.SimpleDateFormat;
  33. import java.util.*;
  34. import java.util.concurrent.atomic.AtomicReference;
  35. import java.util.stream.Collectors;
  36. import java.util.stream.Stream;
  37. import static com.bizmatics.service.impl.RtAnalogDataServiceImpl.getLastDayOfMonth;
  38. /**
  39. * @author yq
  40. * @date 2021/7/20 16:49
  41. */
  42. @Service
  43. public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMapper, HtAnalogData> implements HtAnalogDataService {
  44. @Autowired
  45. private HadSiteStaticService hadSiteStaticService;
  46. @Autowired
  47. private RtAnalogDataService rtAnalogDataService;
  48. @Autowired
  49. private DeviceService deviceService;
  50. @Autowired
  51. private SiteDynamicPropertiesService siteDynamicPropertiesService;
  52. @Autowired
  53. private DeviceAttributeService deviceAttributeService;
  54. @Override
  55. public HadCountVO selectCount() {
  56. HadCountVO hadCountVO = new HadCountVO();
  57. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  58. Date date = new Date();
  59. hadCountVO.setDayCount(hadSiteStaticService.getCount(userId, DateUtils.getDayStartTime(date), date, null));
  60. hadCountVO.setMonthCount(hadSiteStaticService.getCount(userId, DateUtils.getFirstDayOfMonth(date), date, null));
  61. hadCountVO.setYearCount(hadSiteStaticService.getCount(userId, DateUtils.getBeginDayOfYear(date), date, null));
  62. return hadCountVO;
  63. }
  64. @Override
  65. public List<CommonIcoVO> selectTrendByDate(Integer siteId) {
  66. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  67. Date date = new Date();
  68. Date sTime = DateUtils.getDayStartTime(date);
  69. Date eTime = DateUtils.getDayEndTime(date);
  70. Date ysTime = DateUtils.addDays(sTime, -1);
  71. Date yeTime = DateUtils.addDays(eTime, -1);
  72. List<CommonIcoVO> list = new ArrayList<>();
  73. if (null != siteId) {
  74. list.add(getTreedBySite("昨日", siteId, ysTime, yeTime));
  75. list.add(getTreedBySite("今日", siteId, sTime, eTime));
  76. } else {
  77. list.add(getTrendOne("昨日", userId, ysTime, yeTime));
  78. list.add(getTrendOne("今日", userId, sTime, eTime));
  79. }
  80. return list;
  81. }
  82. public CommonIcoVO getTrendOne(String name, Integer userId, Date startTime, Date endTime) {
  83. List<HadSiteStatic> list = hadSiteStaticService.list(null, startTime, endTime, userId);
  84. List<Object> objects = new ArrayList<>();
  85. objects.add(0.0);
  86. List<Object> dates = new ArrayList<>();
  87. dates.add("00:00:00");
  88. for (int i = 2; i < 24; i += 2) {
  89. //结束时间
  90. Date hours = DateUtils.setHours(startTime, i);
  91. startTime = hours;
  92. dates.add(DateUtils.getTime(hours));
  93. Double hourCount = 0.00;
  94. for (HadSiteStatic hadSiteStatic : list) {
  95. CommonIcoVO commonIcoVO = JsonUtils.fromJson(hadSiteStatic.getLoadIco(), CommonIcoVO.class);
  96. List<Double> dataList = (List<Double>) commonIcoVO.getList();
  97. hourCount += dataList.get(i / 2);
  98. }
  99. objects.add(Arith.div(hourCount, 1, 2));
  100. }
  101. return CommonIcoVO.builder().name(name).list(objects).listDate(dates).build();
  102. }
  103. CommonIcoVO getTreedBySite(String name, Integer siteId, Date startTime, Date endTime) {
  104. Date sTime = DateUtils.getDayStartTime(startTime);
  105. Date eTime = DateUtils.getDayEndTime(endTime);
  106. HadSiteStatic hadSiteStatic = hadSiteStaticService.oneBySite(siteId, sTime, eTime);
  107. CommonIcoVO commonIcoVO = null;
  108. if (null != hadSiteStatic) {
  109. commonIcoVO = JsonUtils.fromJson(hadSiteStatic.getLoadIco(), CommonIcoVO.class);
  110. commonIcoVO.setName(name);
  111. } else {
  112. List<Object> objects = new ArrayList<>();
  113. objects.add(0.0);
  114. List<Object> dates = new ArrayList<>();
  115. dates.add("00:00:00");
  116. for (int i = 2; i < 24; i += 2) {
  117. //结束时间
  118. Date hours = DateUtils.setHours(startTime, i);
  119. objects.add(0.0);
  120. startTime = hours;
  121. dates.add(DateUtils.getTime(hours));
  122. }
  123. commonIcoVO = CommonIcoVO.builder().name(name).list(objects).listDate(dates).build();
  124. }
  125. return commonIcoVO;
  126. }
  127. @Override
  128. public List<CommonIcoVO> selectTrendByMonth() {
  129. Date date = new Date();
  130. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  131. List<CommonIcoVO> list = new ArrayList<>();
  132. list.add(selectTreedMonthOne(DateUtils.getLastDayOfMonth(DateUtils.addMonths(date, -1)), userId, "上月趋势图"));
  133. list.add(selectTreedMonthOne(DateUtils.getLastDayOfMonth(date), userId, "当月趋势图"));
  134. return list;
  135. }
  136. public CommonIcoVO selectTreedMonthOne(Date date, Integer userId, String name) {
  137. List<Object> objects = new ArrayList<>();
  138. List<Object> dateList = new ArrayList<>();
  139. for (int i = 1; i <= Integer.parseInt(DateUtils.getDay(date)); i++) {
  140. Date setDays = DateUtils.setDays(date, i);
  141. Date dayStartTime = DateUtils.getDayStartTime(setDays);
  142. Date dayEndTime = DateUtils.getDayEndTime(setDays);
  143. objects.add(hadSiteStaticService.getCount(userId, dayStartTime, dayEndTime, null));
  144. dateList.add(DateUtils.getDay(setDays));
  145. }
  146. return CommonIcoVO.builder().name(name).list(objects).listDate(dateList).build();
  147. }
  148. @Override
  149. public HadCountVO getCountBySite(Integer siteId) {
  150. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  151. Date date = new Date();
  152. //当日开始时间
  153. Date firstDayOfDate = DateUtils.getDayStartTime(date);
  154. //当月开始时间
  155. Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(date);
  156. //当年开始时间
  157. Date firstDayOfYear = DateUtils.getBeginDayOfYear(date);
  158. HadCountVO hadCountVO = new HadCountVO();
  159. hadCountVO.setDayCount(hadSiteStaticService.getCount(userId, DateUtils.getDayStartTime(date), date, siteId));
  160. hadCountVO.setMonthCount(hadSiteStaticService.getCount(userId, DateUtils.getFirstDayOfMonth(date), date, siteId));
  161. hadCountVO.setYearCount(hadSiteStaticService.getCount(userId, DateUtils.getBeginDayOfYear(date), date, siteId));
  162. hadCountVO.setLastDayCount(hadSiteStaticService.getCount(userId, DateUtils.addDays(firstDayOfDate, -1), DateUtils.addDays(date, -1), siteId));
  163. hadCountVO.setLastMonthCount(hadSiteStaticService.getCount(userId, DateUtils.addMonths(firstDayOfMonth, -1), DateUtils.addMonths(date, -1), siteId));
  164. hadCountVO.setLastYearCount(hadSiteStaticService.getCount(userId, DateUtils.addYears(firstDayOfYear, -1), DateUtils.addYears(date, -1), siteId));
  165. hadCountVO.setDayRadio(Optional.ofNullable(hadCountVO.getDayCount())
  166. .filter(dayCount -> 0.00 != dayCount)
  167. .map(dayCount -> Arith.div(hadCountVO.getLastDayCount(), dayCount))
  168. .orElse(0.00));
  169. hadCountVO.setMonthRadio(Optional.ofNullable(hadCountVO.getMonthCount())
  170. .filter(dayCount -> 0.00 != dayCount)
  171. .map(dayCount -> Arith.div(hadCountVO.getLastMonthCount(), dayCount))
  172. .orElse(0.00));
  173. hadCountVO.setYearRadio(Optional.ofNullable(hadCountVO.getYearCount())
  174. .filter(dayCount -> 0.00 != dayCount)
  175. .map(dayCount -> Arith.div(hadCountVO.getLastYearCount(), dayCount))
  176. .orElse(0.00));
  177. return hadCountVO;
  178. }
  179. @Override
  180. public TimeShareVO getTimeShare(Integer siteId, Integer type) {
  181. AtomicReference<TimeShareVO> timeShareVO = new AtomicReference<>(new TimeShareVO());
  182. Date date = new Date();
  183. if (0 == type) {
  184. Date yeDay = DateUtils.addDays(date, -1);
  185. Date yeStartDay = DateUtils.getDayStartTime(yeDay);
  186. HadSiteStatic hadSiteStatic = hadSiteStaticService.oneBySite(siteId, yeStartDay, yeDay);
  187. Optional.ofNullable(hadSiteStatic).ifPresent(hads -> {
  188. timeShareVO.set(JsonUtils.fromJson(hads.getTimeShare(), TimeShareVO.class));
  189. });
  190. } else {
  191. List<HadSiteStatic> list = hadSiteStaticService.list(siteId, DateUtils.getFirstDayOfMonth(date), date);
  192. for (HadSiteStatic hadSiteStatic : list) {
  193. Optional.ofNullable(hadSiteStatic.getTimeShare())
  194. .ifPresent(has -> {
  195. TimeShareVO ts = JsonUtils.fromJson(has, TimeShareVO.class);
  196. timeShareVO.get().setFlat(Arith.add(timeShareVO.get().getFlat(), ts.getFlat()));
  197. timeShareVO.get().setPeak(Arith.add(timeShareVO.get().getPeak(), ts.getPeak()));
  198. timeShareVO.get().setNeed(Arith.add(timeShareVO.get().getNeed(), ts.getNeed()));
  199. timeShareVO.get().setGrain(Arith.add(timeShareVO.get().getGrain(), ts.getGrain()));
  200. });
  201. }
  202. }
  203. return timeShareVO.get();
  204. }
  205. @Override
  206. public List<CommonIcoVO> getDemandIco(Integer siteId) {
  207. Date date = new Date();
  208. List<Object> maxList = new ArrayList<>();
  209. List<Object> minList = new ArrayList<>();
  210. List<Object> avgList = new ArrayList<>();
  211. List<Object> dateList = new ArrayList<>();
  212. List<HadSiteStatic> hadSiteStatics = hadSiteStaticService.list(siteId, DateUtils.getFirstDayOfMonth(date), date);
  213. for (int i = 1; i <= Integer.parseInt(DateUtils.getDay(date)); i++) {
  214. Date setDays = DateUtils.setDays(date, i);
  215. Date dayStartTime = DateUtils.getDayStartTime(setDays);
  216. Date dayEndTime = DateUtils.getDayEndTime(setDays);
  217. maxList.add(hadSiteStatics.stream()
  218. .filter(hadSiteStatic -> DateUtils.isEffectiveDate(hadSiteStatic.getHadTime(), dayStartTime, dayEndTime)
  219. ).findFirst().map(HadSiteStatic::getMaxDemand).orElse(0.00));
  220. minList.add(hadSiteStatics.stream()
  221. .filter(hadSiteStatic -> DateUtils.isEffectiveDate(hadSiteStatic.getHadTime(), dayStartTime, dayEndTime)
  222. ).findFirst().map(HadSiteStatic::getMinDemand).orElse(0.00));
  223. avgList.add(hadSiteStatics.stream()
  224. .filter(hadSiteStatic -> DateUtils.isEffectiveDate(hadSiteStatic.getHadTime(), dayStartTime, dayEndTime)
  225. ).findFirst().map(HadSiteStatic::getAvgDemand).orElse(0.00));
  226. dateList.add(DateUtils.getDay(setDays));
  227. }
  228. List<CommonIcoVO> list = new ArrayList<>();
  229. list.add(CommonIcoVO.builder().name("最大值").list(maxList).listDate(dateList).build());
  230. list.add(CommonIcoVO.builder().name("最小值").list(minList).listDate(dateList).build());
  231. list.add(CommonIcoVO.builder().name("平均值").list(avgList).listDate(dateList).build());
  232. return list;
  233. }
  234. @Override
  235. public List<CommonIcoVO> getElectricIco(Integer siteId, Date date) {
  236. List<Object> iaList = new ArrayList<>();
  237. iaList.add(0.00);
  238. List<Object> ibList = new ArrayList<>();
  239. ibList.add(0.00);
  240. List<Object> icList = new ArrayList<>();
  241. icList.add(0.00);
  242. List<Object> uaList = new ArrayList<>();
  243. uaList.add(0.00);
  244. List<Object> ubList = new ArrayList<>();
  245. ubList.add(0.00);
  246. List<Object> ucList = new ArrayList<>();
  247. ucList.add(0.00);
  248. List<Object> dateList = new ArrayList<>();
  249. dateList.add("00:00:00");
  250. HadSiteStatic hadSiteStatic = hadSiteStaticService.oneBySite(siteId, date, date);
  251. List<HtAnalogData> htList = Optional.ofNullable(hadSiteStatic)
  252. .map(HadSiteStatic::getHisIco)
  253. .map(his -> JsonUtils.fromJson(hadSiteStatic.getHisIco(), new TypeReference<List<HtAnalogData>>() {
  254. }))
  255. .orElse(null);
  256. for (int i = 2; i < 24; i += 2) {
  257. Date hours = DateUtils.setHours(date, i);
  258. date = hours;
  259. Date finalDate = date;
  260. Optional<HtAnalogData> htAnalogData = Optional.ofNullable(htList).flatMap(hts -> hts.stream()
  261. .filter(hads -> DateUtils.isEffectiveDate(hads.getDataTime(), finalDate, hours))
  262. .findFirst());
  263. iaList.add(htAnalogData.map(HtAnalogData::getIa).orElse(0.00));
  264. ibList.add(htAnalogData.map(HtAnalogData::getIb).orElse(0.00));
  265. icList.add(htAnalogData.map(HtAnalogData::getIc).orElse(0.00));
  266. uaList.add(htAnalogData.map(HtAnalogData::getUa).orElse(0.00));
  267. ubList.add(htAnalogData.map(HtAnalogData::getUb).orElse(0.00));
  268. ucList.add(htAnalogData.map(HtAnalogData::getUc).orElse(0.00));
  269. dateList.add(htAnalogData.map(HtAnalogData::getDataTime).map(s -> DateUtils.getTime(hours)).orElse(DateUtils.getTime(hours)));
  270. }
  271. List<CommonIcoVO> list = new ArrayList<>();
  272. list.add(CommonIcoVO.builder().name("IA").list(iaList).listDate(dateList).build());
  273. list.add(CommonIcoVO.builder().name("IB").list(ibList).listDate(dateList).build());
  274. list.add(CommonIcoVO.builder().name("IC").list(icList).listDate(dateList).build());
  275. list.add(CommonIcoVO.builder().name("UA").list(uaList).listDate(dateList).build());
  276. list.add(CommonIcoVO.builder().name("UB").list(ubList).listDate(dateList).build());
  277. list.add(CommonIcoVO.builder().name("UC").list(ucList).listDate(dateList).build());
  278. return list;
  279. }
  280. @Override
  281. public List<RealScoreVO> rtRealScore(String deviceCode, Date startTime, Date endTime) {
  282. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  283. //查询设备
  284. LambdaQueryWrapper<Device> deviceQuery = Wrappers.lambdaQuery();
  285. deviceQuery.eq(Device::getDeviceCode, deviceCode);
  286. Device device = deviceService.getOne(deviceQuery);
  287. Optional.ofNullable(device).orElseThrow(() -> new BusinessException("设备不存在"));
  288. String table = "ht_analog_data";
  289. if (device.getDeviceType().equals("1")) {
  290. table = "ht_analog_data";
  291. } else if (device.getDeviceType().equals("4")) {
  292. table = "ht_analog_173_data";
  293. }
  294. List<HtAnalogData> list = baseMapper.getDemandAnalysisList(deviceCode, formatter.format(startTime), formatter.format(endTime), table);
  295. //查询sd
  296. LambdaQueryWrapper<SiteDynamicProperties> sdQuery = Wrappers.lambdaQuery();
  297. sdQuery.eq(SiteDynamicProperties::getSiteId, device.getSiteId());
  298. SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.getOne(sdQuery);
  299. Optional.ofNullable(siteDynamicProperties).orElseThrow(() -> new BusinessException("sd不存在"));
  300. LambdaQueryWrapper<DeviceAttribute> adQuery = Wrappers.lambdaQuery();
  301. adQuery.eq(DeviceAttribute::getSiteId, device.getSiteId());
  302. List<DeviceAttribute> deviceAttributes = deviceAttributeService.list(adQuery);
  303. if (CollectionUtils.isEmpty(deviceAttributes)) {
  304. throw new BusinessException("da不存在");
  305. }
  306. DeviceAttribute deviceAttribute = deviceAttributes.stream().min(Comparator.comparing(DeviceAttribute::getId)).get();
  307. List<RealScoreVO> realScoreVOS = new ArrayList<>();
  308. for (HtAnalogData htAnalogData : list) {
  309. RtAnalogData rtAnalogData = BeanMapperUtils.map(htAnalogData, RtAnalogData.class);
  310. realScoreVOS.add(rtAnalogDataService.fillRealScoreData(rtAnalogData, siteDynamicProperties, deviceAttribute));
  311. }
  312. return realScoreVOS;
  313. }
  314. // public List<RealScoreVO> rtRealScore(String deviceCode, Date startTime, Date endTime) {
  315. // LambdaQueryWrapper<HtAnalogData> queryWrapper = Wrappers.lambdaQuery();
  316. // queryWrapper.select(HtAnalogData::getIa, HtAnalogData::getIb, HtAnalogData::getIc,
  317. // HtAnalogData::getUa, HtAnalogData::getUb, HtAnalogData::getUc, HtAnalogData::getDataTime,
  318. // HtAnalogData::getCos)
  319. // .eq(HtAnalogData::getDeviceName, deviceCode)
  320. // .between(HtAnalogData::getDataTime, startTime, endTime);
  321. // List<HtAnalogData> list = this.list(queryWrapper);
  322. // //查询设备
  323. // LambdaQueryWrapper<Device> deviceQuery = Wrappers.lambdaQuery();
  324. // deviceQuery.eq(Device::getDeviceCode, deviceCode);
  325. // Device device = deviceService.getOne(deviceQuery);
  326. // Optional.ofNullable(device).orElseThrow(() -> new BusinessException("设备不存在"));
  327. // //查询sd
  328. // LambdaQueryWrapper<SiteDynamicProperties> sdQuery = Wrappers.lambdaQuery();
  329. // sdQuery.eq(SiteDynamicProperties::getSiteId, device.getSiteId());
  330. // SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.getOne(sdQuery);
  331. // Optional.ofNullable(siteDynamicProperties).orElseThrow(() -> new BusinessException("sd不存在"));
  332. // LambdaQueryWrapper<DeviceAttribute> adQuery = Wrappers.lambdaQuery();
  333. // adQuery.eq(DeviceAttribute::getSiteId, device.getSiteId());
  334. // List<DeviceAttribute> deviceAttributes = deviceAttributeService.list(adQuery);
  335. // if (CollectionUtils.isEmpty(deviceAttributes)) {
  336. // throw new BusinessException("da不存在");
  337. // }
  338. // DeviceAttribute deviceAttribute = deviceAttributes.stream().min(Comparator.comparing(DeviceAttribute::getId)).get();
  339. // List<RealScoreVO> realScoreVOS = new ArrayList<>();
  340. // for (HtAnalogData htAnalogData : list) {
  341. // RtAnalogData rtAnalogData = BeanMapperUtils.map(htAnalogData, RtAnalogData.class);
  342. // realScoreVOS.add(rtAnalogDataService.fillRealScoreData(rtAnalogData, siteDynamicProperties, deviceAttribute));
  343. // }
  344. // return realScoreVOS;
  345. // }
  346. @Override
  347. public List<CommonIcoVO> yearOnYearList(DataManagementOneVO dataManagementOneVO) {
  348. List<DataManagementVO> dataManagementVOList = new ArrayList<>();
  349. List<String> newListOne = new ArrayList<>();
  350. List<String> newListTwo = new ArrayList<>();
  351. List<String> newListThree = new ArrayList<>();
  352. List<DeviceAnalogVariableList> variableCodingList = new LinkedList<>();
  353. List<String> fieldDisplay = new ArrayList<>();
  354. Integer type = dataManagementOneVO.getType();
  355. Integer valueCalculation = dataManagementOneVO.getValueCalculation();
  356. newListOne.add("dataTime");
  357. for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  358. DataManagementVO dataManagementVO = new DataManagementVO();
  359. dataManagementVO.setDisplayField(dataManagementOneVO.getDisplayField().get(i).split("_")[0]);
  360. dataManagementVOList.add(dataManagementVO);
  361. newListOne.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  362. newListTwo.add(dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  363. fieldDisplay.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  364. newListThree.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  365. DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
  366. deviceAnalogVariableList.setVariableCoding(dataManagementOneVO.getDisplayField().get(i).split("_")[0] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  367. variableCodingList.add(deviceAnalogVariableList);
  368. }
  369. //通信设备编号
  370. Set set = new HashSet();
  371. List<DataManagementVO> newList = new ArrayList();
  372. set.addAll(dataManagementVOList);
  373. newList.addAll(set);
  374. //显示的字段名
  375. Set set1 = new HashSet();
  376. List<String> list = new ArrayList();
  377. set1.addAll(newListOne);
  378. list.addAll(set1);
  379. //监控ID
  380. Set set2 = new HashSet();
  381. List<String> monitor_list = new ArrayList();
  382. set2.addAll(newListTwo);
  383. monitor_list.addAll(set2);
  384. //查询字段
  385. Set set3 = new HashSet();
  386. List<String> fieldDisplayOne = new ArrayList();
  387. set3.addAll(fieldDisplay);
  388. fieldDisplayOne.addAll(set3);
  389. List<String> fieldDisplayOne183 = new ArrayList();
  390. List<String> fieldDisplayOne171 = new ArrayList();
  391. List<String> fieldDisplayOne173 = new ArrayList();
  392. List<Device> deviceList = baseMapper.getDeviceList(newList);
  393. for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  394. String device_code = dataManagementOneVO.getDisplayField().get(i).split("_")[0];
  395. String display_field = dataManagementOneVO.getDisplayField().get(i).split("_")[1];
  396. for (int j = 0; j < deviceList.size(); j++) {
  397. if (device_code.equals(deviceList.get(j).getDeviceCode())) {
  398. if (deviceList.get(j).getDeviceType().equals("1")) {
  399. fieldDisplayOne183.add(display_field);
  400. } else if (deviceList.get(j).getDeviceType().equals("3")) {
  401. fieldDisplayOne171.add(display_field);
  402. } else if (deviceList.get(j).getDeviceType().equals("4")) {
  403. fieldDisplayOne173.add(display_field);
  404. }
  405. }
  406. }
  407. }
  408. List<ContextualDataVo> yearOnYearList1 = new ArrayList<>();
  409. List<ContextualDataVo> yearOnYearList2 = new ArrayList<>();
  410. List<ContextualDataVo> yearOnYearList3 = new ArrayList<>();
  411. if (fieldDisplayOne183.size() > 0) {
  412. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne183);
  413. yearOnYearList1 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_data", 0,type);
  414. }
  415. if (fieldDisplayOne171.size() > 0) {
  416. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne171);
  417. yearOnYearList2 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_171_data", 0,type);
  418. }
  419. if (fieldDisplayOne173.size() > 0) {
  420. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne173);
  421. yearOnYearList3 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_173_data", 0,type);
  422. }
  423. List<ContextualDataVo> yearOnYearList4 = Stream.of(yearOnYearList1, yearOnYearList2).flatMap(Collection::stream).distinct().collect(Collectors.toList());
  424. List<ContextualDataVo> yearOnYearList = Stream.of(yearOnYearList3, yearOnYearList4).flatMap(Collection::stream).distinct().collect(Collectors.toList());
  425. FieldEscapeUtils.remove1(list);
  426. List<CommonIcoVO> reListOne = new ArrayList<>();
  427. if (yearOnYearList != null && !yearOnYearList.isEmpty()) {
  428. for (int i = 0; i < monitor_list.size(); i++) {
  429. for (int j = 0; j < list.size(); j++) {
  430. List<Object> data = new ArrayList<>();
  431. String name = null;
  432. List<Object> time = new ArrayList<>();
  433. for (int k = 0; k < yearOnYearList.size(); k++) {
  434. String variable_one = list.get(j) + "_" + monitor_list.get(i);
  435. String variable_two = list.get(j) + "_" + yearOnYearList.get(k).getDeviceAttributeId();
  436. System.out.println("variable_one:" + variable_one + "---variable_two:" + variable_two);
  437. if (variable_one.equals(variable_two)) {
  438. String variable_three = list.get(j) + "_" + yearOnYearList.get(k).getDeviceAttributeId();
  439. System.out.println("variable_one_a:" + newListThree + "---variable_two_b:" + variable_three + "---value:" + newListThree.contains(variable_three));
  440. if (newListThree.contains(variable_three)) {
  441. name = yearOnYearList.get(k).getMonitorDeviceName() + "/" + FieldEscapeUtils.fieldEscapeUtils(list.get(j));
  442. time.add(yearOnYearList.get(k).getDataTime());
  443. // System.out.println();
  444. data.add(FieldEscapeUtils.transformation1(yearOnYearList.get(k), list.get(j)));
  445. }
  446. }
  447. }
  448. if (data != null && !data.isEmpty()) {
  449. reListOne.add(CommonIcoVO.builder().name(name).list(data).listDate(time).build());
  450. }
  451. }
  452. }
  453. }
  454. return reListOne;
  455. }
  456. // public List<CommonIcoVO> yearOnYearList(DataManagementOneVO dataManagementOneVO) {
  457. // List<HtAnalogDataVo> yearOnYearList = null;
  458. // List<DataManagementVO> dataManagementVOList = new ArrayList<>();
  459. // List<String> newListOne = new ArrayList<>();
  460. // List<String> newListTwo = new ArrayList<>();
  461. // List<String> newListThree = new ArrayList<>();
  462. // List<DeviceAnalogVariableList> variableCodingList = new LinkedList<>();
  463. // List<String> fieldDisplay = new ArrayList<>();
  464. // newListOne.add("dataTime");
  465. // for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  466. // DataManagementVO dataManagementVO = new DataManagementVO();
  467. // dataManagementVO.setDisplayField(dataManagementOneVO.getDisplayField().get(i).split("_")[0]);
  468. // dataManagementVOList.add(dataManagementVO);
  469. // newListOne.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  470. // newListTwo.add(dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  471. // fieldDisplay.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  472. // newListThree.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  473. // DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
  474. // deviceAnalogVariableList.setVariableCoding(dataManagementOneVO.getDisplayField().get(i).split("_")[0] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  475. // variableCodingList.add(deviceAnalogVariableList);
  476. // }
  477. // Set set = new HashSet();
  478. // List<DataManagementVO> newList = new ArrayList();
  479. // set.addAll(dataManagementVOList);
  480. // newList.addAll(set);
  481. //
  482. // //通信设备编号
  483. // Set set1 = new HashSet();
  484. // List<String> list = new ArrayList();
  485. // set1.addAll(newListOne);
  486. // list.addAll(set1);
  487. //
  488. // //显示的字段名
  489. // Set set2 = new HashSet();
  490. // List<String> monitor_list = new ArrayList();
  491. // set2.addAll(newListTwo);
  492. // monitor_list.addAll(set2);
  493. //
  494. // //查询字段
  495. // Set set3 = new HashSet();
  496. // List<String> fieldDisplayOne = new ArrayList();
  497. // set3.addAll(fieldDisplay);
  498. // fieldDisplayOne.addAll(set3);
  499. //
  500. // if (dataManagementOneVO.getType() == 1) {
  501. // if (dataManagementOneVO.getValueCalculation() == 1) {
  502. // yearOnYearList = baseMapper.yearOnYearOne(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  503. // } else if (dataManagementOneVO.getValueCalculation() == 2) {
  504. // yearOnYearList = baseMapper.dayMaxDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  505. // } else if (dataManagementOneVO.getValueCalculation() == 3) {
  506. // yearOnYearList = baseMapper.dayMinDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  507. // } else if (dataManagementOneVO.getValueCalculation() == 4) {
  508. // yearOnYearList = baseMapper.daySumDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  509. // }
  510. // } else if (dataManagementOneVO.getType() == 2) {
  511. // if (dataManagementOneVO.getValueCalculation() == 1) {
  512. // yearOnYearList = baseMapper.yearOnYearTwo(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  513. // } else if (dataManagementOneVO.getValueCalculation() == 2) {
  514. // yearOnYearList = baseMapper.monthMaxDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  515. // } else if (dataManagementOneVO.getValueCalculation() == 3) {
  516. // yearOnYearList = baseMapper.monthMinDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  517. // } else if (dataManagementOneVO.getValueCalculation() == 4) {
  518. // yearOnYearList = baseMapper.monthSumDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  519. // }
  520. // } else {
  521. // yearOnYearList = baseMapper.yearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayOne);
  522. // }
  523. // FieldEscapeUtils.remove1(list);
  524. // List<CommonIcoVO> reListOne = new ArrayList<>();
  525. // if (yearOnYearList != null && !yearOnYearList.isEmpty()) {
  526. // for (int i = 0; i < monitor_list.size(); i++) {
  527. // for (int j = 0; j < list.size(); j++) {
  528. // List<Object> data = new ArrayList<>();
  529. // String name = null;
  530. // List<Object> time = new ArrayList<>();
  531. // for (int k = 0; k < yearOnYearList.size(); k++) {
  532. // String variable_one = list.get(j) + "_" + monitor_list.get(i);
  533. // String variable_two = list.get(j) + "_" + yearOnYearList.get(k).getDeviceAttributeId();
  534. // System.out.println("variable_one:" + variable_one + "---variable_two:" + variable_two);
  535. // if (variable_one.equals(variable_two)) {
  536. // String variable_three = list.get(j) + "_" + yearOnYearList.get(k).getDeviceAttributeId();
  537. // System.out.println("variable_one_a:" + newListThree + "---variable_two_b:" + variable_three + "---value:" + newListThree.contains(variable_three));
  538. // if (newListThree.contains(variable_three)) {
  539. // name = yearOnYearList.get(k).getMonitorDeviceName() + "/" + FieldEscapeUtils.fieldEscapeUtils(list.get(j));
  540. // time.add(yearOnYearList.get(k).getDataTime());
  541. //// System.out.println();
  542. // data.add(FieldEscapeUtils.transformation(yearOnYearList.get(k), list.get(j)));
  543. // }
  544. // }
  545. // }
  546. // if (data != null && !data.isEmpty()) {
  547. // reListOne.add(CommonIcoVO.builder().name(name).list(data).listDate(time).build());
  548. // }
  549. //
  550. // }
  551. // }
  552. // }
  553. // return reListOne;
  554. // }
  555. @Override
  556. public List<CommonIcoVO> ringRatioList(DataManagementOneVO dataManagementOneVO) {
  557. List<DataManagementVO> dataManagementVOList = new ArrayList<>();
  558. List<String> newListOne = new ArrayList<>();
  559. List<String> newListTwo = new ArrayList<>();
  560. List<String> newListThree = new ArrayList<>();
  561. List<String> fieldDisplay = new ArrayList<>();
  562. Integer type = dataManagementOneVO.getType();
  563. Integer valueCalculation = dataManagementOneVO.getValueCalculation();
  564. newListOne.add("dataTime");
  565. List<DeviceAnalogVariableList> variableCodingList = new LinkedList<>();
  566. for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  567. DataManagementVO dataManagementVO = new DataManagementVO();
  568. dataManagementVO.setDisplayField(dataManagementOneVO.getDisplayField().get(i).split("_")[0]);
  569. dataManagementVOList.add(dataManagementVO);
  570. newListOne.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  571. fieldDisplay.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  572. newListTwo.add(dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  573. newListThree.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  574. DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
  575. deviceAnalogVariableList.setVariableCoding(dataManagementOneVO.getDisplayField().get(i).split("_")[0] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  576. variableCodingList.add(deviceAnalogVariableList);
  577. }
  578. Set set = new HashSet();
  579. List<DataManagementVO> newList = new ArrayList();
  580. set.addAll(dataManagementVOList);
  581. newList.addAll(set);
  582. Set set1 = new HashSet();
  583. List<String> list = new ArrayList();
  584. set1.addAll(newListOne);
  585. list.addAll(set1);
  586. Set set2 = new HashSet();
  587. List<String> monitor_list = new ArrayList();
  588. set2.addAll(newListTwo);
  589. monitor_list.addAll(set2);
  590. Set set3 = new HashSet();
  591. List<String> fieldDisplayOne = new ArrayList();
  592. set3.addAll(fieldDisplay);
  593. fieldDisplayOne.addAll(set3);
  594. List<String> fieldDisplayOne183 = new ArrayList();
  595. List<String> fieldDisplayOne171 = new ArrayList();
  596. List<String> fieldDisplayOne173 = new ArrayList();
  597. List<Device> deviceList = baseMapper.getDeviceList(newList);
  598. for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  599. String device_code = dataManagementOneVO.getDisplayField().get(i).split("_")[0];
  600. String display_field = dataManagementOneVO.getDisplayField().get(i).split("_")[1];
  601. for (int j = 0; j < deviceList.size(); j++) {
  602. if (device_code.equals(deviceList.get(j).getDeviceCode())) {
  603. if (deviceList.get(j).getDeviceType().equals("1")) {
  604. fieldDisplayOne183.add(display_field);
  605. } else if (deviceList.get(j).getDeviceType().equals("3")) {
  606. fieldDisplayOne171.add(display_field);
  607. } else if (deviceList.get(j).getDeviceType().equals("4")) {
  608. fieldDisplayOne173.add(display_field);
  609. }
  610. }
  611. }
  612. }
  613. List<ContextualDataVo> yearOnYearList1 = new ArrayList<>();
  614. List<ContextualDataVo> yearOnYearList2 = new ArrayList<>();
  615. List<ContextualDataVo> yearOnYearList3 = new ArrayList<>();
  616. if (fieldDisplayOne183.size() > 0) {
  617. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne183);
  618. yearOnYearList1 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_data", 0,type);
  619. }
  620. if (fieldDisplayOne171.size() > 0) {
  621. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne171);
  622. yearOnYearList2 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_171_data", 0,type);
  623. }
  624. if (fieldDisplayOne173.size() > 0) {
  625. List<String> fieldDisplayList = FieldEscapeUtils.getSyllable(type, valueCalculation, fieldDisplayOne173);
  626. yearOnYearList3 = baseMapper.getYearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayList, "ht_analog_173_data", 0,type);
  627. }
  628. List<ContextualDataVo> yearOnYearList4 = Stream.of(yearOnYearList1, yearOnYearList2).flatMap(Collection::stream).distinct().collect(Collectors.toList());
  629. List<ContextualDataVo> currentPeriodRingRatioList = Stream.of(yearOnYearList3, yearOnYearList4).flatMap(Collection::stream).distinct().collect(Collectors.toList());
  630. FieldEscapeUtils.remove1(list);
  631. List<CommonIcoVO> reListOne = new ArrayList<>();
  632. if (currentPeriodRingRatioList != null && !currentPeriodRingRatioList.isEmpty()) {
  633. for (int i = 0; i < monitor_list.size(); i++) {
  634. for (int j = 0; j < list.size(); j++) {
  635. List<Object> data = new ArrayList<>();
  636. String name = null;
  637. List<Object> time = new ArrayList<>();
  638. for (int k = 0; k < currentPeriodRingRatioList.size(); k++) {
  639. String variable_one = list.get(j) + "_" + monitor_list.get(i);
  640. String variable_two = list.get(j) + "_" + currentPeriodRingRatioList.get(k).getDeviceAttributeId();
  641. System.out.println("variable_one:" + variable_one + "---variable_two:" + variable_two);
  642. if (variable_one.equals(variable_two)) {
  643. String variable_three = list.get(j) + "_" + currentPeriodRingRatioList.get(k).getDeviceAttributeId();
  644. System.out.println("variable_one_a:" + newListThree + "---variable_two_b:" + variable_three + "---value:" + newListThree.contains(variable_three));
  645. if (newListThree.contains(variable_three)) {
  646. name = currentPeriodRingRatioList.get(k).getMonitorDeviceName() + "/" + FieldEscapeUtils.fieldEscapeUtils(list.get(j));
  647. time.add(currentPeriodRingRatioList.get(k).getDataTime());
  648. // System.out.println();
  649. data.add(FieldEscapeUtils.transformation1(currentPeriodRingRatioList.get(k), list.get(j)));
  650. }
  651. }
  652. }
  653. if (data != null && !data.isEmpty()) {
  654. reListOne.add(CommonIcoVO.builder().name(name).list(data).listDate(time).build());
  655. }
  656. }
  657. }
  658. }
  659. return reListOne;
  660. }
  661. // public List<CommonIcoVO> ringRatioList(DataManagementOneVO dataManagementOneVO) {
  662. // List<HtAnalogDataVo> currentPeriodRingRatioList = null;
  663. //// List<HtAnalogDataVo> lastPeriodRingRatioList = null;
  664. // List<DataManagementVO> dataManagementVOList = new ArrayList<>();
  665. // List<String> newListOne = new ArrayList<>();
  666. // List<String> newListTwo = new ArrayList<>();
  667. // List<String> newListThree = new ArrayList<>();
  668. // List<String> fieldDisplay = new ArrayList<>();
  669. // newListOne.add("dataTime");
  670. // List<DeviceAnalogVariableList> variableCodingList = new LinkedList<>();
  671. // for (int i = 0; i < dataManagementOneVO.getDisplayField().size(); i++) {
  672. // DataManagementVO dataManagementVO = new DataManagementVO();
  673. // dataManagementVO.setDisplayField(dataManagementOneVO.getDisplayField().get(i).split("_")[0]);
  674. // dataManagementVOList.add(dataManagementVO);
  675. // newListOne.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  676. // fieldDisplay.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  677. // newListTwo.add(dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  678. // newListThree.add(dataManagementOneVO.getDisplayField().get(i).split("_")[1] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[2]);
  679. // DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
  680. // deviceAnalogVariableList.setVariableCoding(dataManagementOneVO.getDisplayField().get(i).split("_")[0] + "_" + dataManagementOneVO.getDisplayField().get(i).split("_")[1]);
  681. // variableCodingList.add(deviceAnalogVariableList);
  682. // }
  683. // Set set = new HashSet();
  684. // List<DataManagementVO> newList = new ArrayList();
  685. // set.addAll(dataManagementVOList);
  686. // newList.addAll(set);
  687. //
  688. // Set set1 = new HashSet();
  689. // List<String> list = new ArrayList();
  690. // set1.addAll(newListOne);
  691. // list.addAll(set1);
  692. //
  693. // Set set2 = new HashSet();
  694. // List<String> monitor_list = new ArrayList();
  695. // set2.addAll(newListTwo);
  696. // monitor_list.addAll(set2);
  697. //
  698. // Set set3 = new HashSet();
  699. // List<String> fieldDisplayOne = new ArrayList();
  700. // set3.addAll(fieldDisplay);
  701. // fieldDisplayOne.addAll(set3);
  702. //
  703. // //旧数据时间计算
  704. //// SimpleDateFormat sfOne = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  705. //// long startLong = DateUtils.toDate(DateUtils.toLocalDateTime(dataManagementOneVO.getStartTime(), "yyyy-MM-dd HH:mm:ss")).getTime();
  706. //// long endLong = DateUtils.toDate(DateUtils.toLocalDateTime(dataManagementOneVO.getEndTime(), "yyyy-MM-dd HH:mm:ss")).getTime();
  707. //// long interval = (endLong - startLong) / 13;
  708. //// String lastPeriodStartTime = sfOne.format(new Date(startLong - (interval * 14)));
  709. // if (dataManagementOneVO.getType() == 1) {
  710. // if (dataManagementOneVO.getValueCalculation() == 1) {
  711. // currentPeriodRingRatioList = baseMapper.yearOnYearOne(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  712. // } else if (dataManagementOneVO.getValueCalculation() == 2) {
  713. // currentPeriodRingRatioList = baseMapper.dayMaxDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  714. // } else if (dataManagementOneVO.getValueCalculation() == 3) {
  715. // currentPeriodRingRatioList = baseMapper.dayMinDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  716. // } else if (dataManagementOneVO.getValueCalculation() == 4) {
  717. // currentPeriodRingRatioList = baseMapper.daySumDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  718. // }
  719. // } else if (dataManagementOneVO.getType() == 2) {
  720. // if (dataManagementOneVO.getValueCalculation() == 1) {
  721. // currentPeriodRingRatioList = baseMapper.yearOnYearTwo(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  722. // } else if (dataManagementOneVO.getValueCalculation() == 2) {
  723. // currentPeriodRingRatioList = baseMapper.monthMaxDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  724. // } else if (dataManagementOneVO.getValueCalculation() == 3) {
  725. // currentPeriodRingRatioList = baseMapper.monthMinDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  726. // } else if (dataManagementOneVO.getValueCalculation() == 4) {
  727. // currentPeriodRingRatioList = baseMapper.monthSumDataList(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList);
  728. // }
  729. // } else {
  730. //// String[] a={"Epn3","Epp"};
  731. // currentPeriodRingRatioList = baseMapper.yearOnYearThree(newList, dataManagementOneVO.getStartTime(), dataManagementOneVO.getEndTime(), variableCodingList, fieldDisplayOne);
  732. // }
  733. //
  734. // FieldEscapeUtils.remove1(list);
  735. // List<CommonIcoVO> reListOne = new ArrayList<>();
  736. // if (currentPeriodRingRatioList != null && !currentPeriodRingRatioList.isEmpty()) {
  737. // for (int i = 0; i < monitor_list.size(); i++) {
  738. // for (int j = 0; j < list.size(); j++) {
  739. // List<Object> data = new ArrayList<>();
  740. // String name = null;
  741. // List<Object> time = new ArrayList<>();
  742. // for (int k = 0; k < currentPeriodRingRatioList.size(); k++) {
  743. // String variable_one = list.get(j) + "_" + monitor_list.get(i);
  744. // String variable_two = list.get(j) + "_" + currentPeriodRingRatioList.get(k).getDeviceAttributeId();
  745. // System.out.println("variable_one:" + variable_one + "---variable_two:" + variable_two);
  746. // if (variable_one.equals(variable_two)) {
  747. // String variable_three = list.get(j) + "_" + currentPeriodRingRatioList.get(k).getDeviceAttributeId();
  748. // System.out.println("variable_one_a:" + newListThree + "---variable_two_b:" + variable_three + "---value:" + newListThree.contains(variable_three));
  749. // if (newListThree.contains(variable_three)) {
  750. // name = currentPeriodRingRatioList.get(k).getMonitorDeviceName() + "/" + FieldEscapeUtils.fieldEscapeUtils(list.get(j));
  751. // time.add(currentPeriodRingRatioList.get(k).getDataTime());
  752. //// System.out.println();
  753. // data.add(FieldEscapeUtils.transformation(currentPeriodRingRatioList.get(k), list.get(j)));
  754. // }
  755. // }
  756. // }
  757. // if (data != null && !data.isEmpty()) {
  758. // reListOne.add(CommonIcoVO.builder().name(name).list(data).listDate(time).build());
  759. // }
  760. //
  761. // }
  762. // }
  763. // }
  764. // return reListOne;
  765. // }
  766. @Override
  767. public List<CommonIcoVO> monthlyReport(String deviceCode, int cycle, String startTime, String endTime) {
  768. List<Object> eppList = new ArrayList<>();
  769. List<Object> freezingTimesList = new ArrayList<>();
  770. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  771. queryWrapper.eq(Device::getDeviceCode, deviceCode);
  772. List<Device> deviceList = deviceService.list(queryWrapper);
  773. String table = "ht_analog_data";
  774. if (deviceList.size() > 0) {
  775. if (deviceList.get(0).getDeviceType().equals("1")) {
  776. table = "ht_analog_data";
  777. } else if (deviceList.get(0).getDeviceType().equals("4")) {
  778. table = "ht_analog_173_data";
  779. } else {
  780. throw new BusinessException("173用电设备无用电数据采集");
  781. }
  782. } else {
  783. throw new BusinessException("错误数据,设备不存在");
  784. }
  785. List<HtAnalogDataVo> maxMonthlyReport = baseMapper.getEnergyUseList(deviceCode, startTime, endTime, cycle, 1, table);
  786. List<HtAnalogDataVo> minMonthlyReport = baseMapper.getEnergyUseList(deviceCode, startTime, endTime, cycle, 2, table);
  787. if (maxMonthlyReport.size() > 0) {
  788. for (int i = 0; i < maxMonthlyReport.size(); i++) {
  789. BigDecimal b1 = new BigDecimal(maxMonthlyReport.get(i).getEpp().toString());
  790. BigDecimal b2 = new BigDecimal(minMonthlyReport.get(i).getEpp().toString());
  791. eppList.add(b1.subtract(b2).doubleValue());
  792. freezingTimesList.add(maxMonthlyReport.get(i).getFreezingTimes());
  793. }
  794. }
  795. List<CommonIcoVO> list = new ArrayList<>();
  796. list.add(CommonIcoVO.builder().name("电量").list(eppList).listDate(freezingTimesList).build());
  797. return list;
  798. }
  799. // public List<CommonIcoVO> monthlyReport(String deviceCode, int cycle, String startTime, String endTime) {
  800. // List<Object> eppList = new ArrayList<>();
  801. // List<Object> freezingTimesList = new ArrayList<>();
  802. // List<HtAnalogDataVo> maxMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 1);
  803. // List<HtAnalogDataVo> minMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 2);
  804. // if (maxMonthlyReport.size() > 0) {
  805. // for (int i = 0; i < maxMonthlyReport.size(); i++) {
  806. // BigDecimal b1 = new BigDecimal(maxMonthlyReport.get(i).getEpp().toString());
  807. // BigDecimal b2 = new BigDecimal(minMonthlyReport.get(i).getEpp().toString());
  808. // eppList.add(b1.subtract(b2).doubleValue());
  809. // freezingTimesList.add(maxMonthlyReport.get(i).getFreezingTimes());
  810. // }
  811. // }
  812. // List<CommonIcoVO> list = new ArrayList<>();
  813. // list.add(CommonIcoVO.builder().name("电量").list(eppList).listDate(freezingTimesList).build());
  814. // return list;
  815. // }
  816. @Override
  817. public List<CommonIcoVO> demandAnalysis(String deviceCode, String monthDate, int cycle) {
  818. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  819. SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
  820. String date = FieldEscapeUtils.getLastDayOfMonth(monthDate);
  821. String date1 = monthDate + "-01 00:00:00";
  822. String date2 = date + " 23:59:59";
  823. LambdaQueryWrapper<Device> queryWrapper1 = Wrappers.lambdaQuery();
  824. queryWrapper1.eq(Device::getDeviceCode, deviceCode);
  825. List<Device> deviceList = deviceService.list(queryWrapper1);
  826. String table = "ht_analog_data";
  827. if (deviceList.size() > 0) {
  828. if (deviceList.get(0).getDeviceType().equals("1")) {
  829. table = "ht_analog_data";
  830. } else if (deviceList.get(0).getDeviceType().equals("4")) {
  831. table = "ht_analog_173_data";
  832. } else {
  833. throw new BusinessException("173用电设备无用电数据采集");
  834. }
  835. } else {
  836. throw new BusinessException("错误数据,设备不存在");
  837. }
  838. List<HtAnalogData> list1 = baseMapper.getDemandAnalysisList(deviceCode, date1, date2, table);
  839. List<Object> demandList = new ArrayList<>();
  840. List<Object> freezingTimesList = new ArrayList<>();
  841. for (int i = 0; i < list1.size(); i++) {
  842. demandList.add(list1.get(i).getDemand());
  843. freezingTimesList.add(formatter1.format(list1.get(i).getFreezingTime()));
  844. }
  845. List<CommonIcoVO> list = new ArrayList<>();
  846. list.add(CommonIcoVO.builder().name("实时有功需量").list(demandList).listDate(freezingTimesList).build());
  847. return list;
  848. }
  849. // public List<CommonIcoVO> demandAnalysis(String deviceCode, String monthDate, int cycle) {
  850. // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  851. // SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
  852. // String date = FieldEscapeUtils.getLastDayOfMonth(monthDate);
  853. // String date1 = monthDate + "-01 00:00:00";
  854. // String date2 = date + " 23:59:59";
  855. // Date startTime;
  856. // Date endTime;
  857. // try {
  858. // startTime = formatter.parse(date1);
  859. // endTime = formatter.parse(date2);
  860. // } catch (Exception e) {
  861. // throw new BusinessException("时间错误");
  862. // }
  863. //
  864. // LambdaQueryWrapper<HtAnalogData> queryWrapper = Wrappers.lambdaQuery();
  865. // queryWrapper.select(HtAnalogData::getDemand, HtAnalogData::getFreezingTime)
  866. // .eq(HtAnalogData::getDeviceName, deviceCode)
  867. // .between(HtAnalogData::getFreezingTime, startTime, endTime)
  868. // .groupBy(HtAnalogData::getFreezingTime);
  869. // List<HtAnalogData> list1 = this.list(queryWrapper);
  870. // List<Object> demandList = new ArrayList<>();
  871. // List<Object> freezingTimesList = new ArrayList<>();
  872. // for (int i = 0; i < list1.size(); i++) {
  873. // demandList.add(list1.get(i).getDemand());
  874. // freezingTimesList.add(formatter1.format(list1.get(i).getFreezingTime()));
  875. // }
  876. //
  877. //
  878. //// List<Object> demandList = new ArrayList<>();
  879. //// List<Object> freezingTimesList = new ArrayList<>();
  880. //// List<HtAnalogDataVo> maxdemandAnalysis = baseMapper.demandAnalysisList(deviceCode, monthDate);
  881. //// for (int i = 0; i < maxdemandAnalysis.size(); i++){
  882. //// demandList.add(maxdemandAnalysis.get(i).getDemand());
  883. //// freezingTimesList.add(maxdemandAnalysis.get(i).getFreezingTimes());
  884. //// }
  885. // List<CommonIcoVO> list = new ArrayList<>();
  886. // list.add(CommonIcoVO.builder().name("实时有功需量").list(demandList).listDate(freezingTimesList).build());
  887. // return list;
  888. // }
  889. @Override
  890. public String monthlyReportExport(String deviceCode, String startTime, String endTime, int cycle) {
  891. DateFormat dFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
  892. Workbook workbook = null;
  893. File file = null;
  894. try {
  895. ExportParams params = new ExportParams(null, "用能月报");
  896. workbook = ExcelExportUtil.exportBigExcel(params, HtAnalogDataTwoExportVo.class,
  897. (o, i) -> {
  898. int startCurrent = (i - 1) * 10000;
  899. List<HtAnalogDataOneVo> listOne = this.monthlyReportlist(deviceCode, startTime, endTime, cycle, startCurrent);
  900. return new ArrayList<>(BeanMapperUtils.mapList(listOne, HtAnalogDataOneVo.class, HtAnalogDataTwoExportVo.class));
  901. }, null);
  902. if (null != workbook) {
  903. file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "用能月报", dFormat.format(System.currentTimeMillis()) + ""));
  904. FileUtils.createFile(file.getAbsolutePath());
  905. FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
  906. workbook.write(allListingFileOutputStream);
  907. } else {
  908. throw new BusinessException("表格数据为空");
  909. }
  910. } catch (Exception e) {
  911. log.error("导出文件失败", e);
  912. throw new BusinessException("导出文件失败");
  913. } finally {
  914. if (workbook != null) {
  915. try {
  916. workbook.close();
  917. } catch (IOException e) {
  918. log.error("===export spec=== 关闭workbook失败", e);
  919. }
  920. }
  921. }
  922. return file.getName();
  923. }
  924. @Override
  925. public List<HtAnalogDataOneVo> monthlyReportlist(String deviceCode, String startTime, String endTime, int cycle, Integer startCurrent) {
  926. List<HtAnalogDataOneVo> listOne = new ArrayList<>();
  927. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  928. queryWrapper.eq(Device::getDeviceCode, deviceCode);
  929. List<Device> deviceList = deviceService.list(queryWrapper);
  930. String table = "ht_analog_data";
  931. if (deviceList.size() > 0) {
  932. if (deviceList.get(0).getDeviceType().equals("1")) {
  933. table = "ht_analog_data";
  934. } else if (deviceList.get(0).getDeviceType().equals("4")) {
  935. table = "ht_analog_173_data";
  936. } else {
  937. throw new BusinessException("173用电设备无用电数据采集");
  938. }
  939. } else {
  940. throw new BusinessException("错误数据,设备不存在");
  941. }
  942. List<HtAnalogDataOneVo> maxMonthlyReport = baseMapper.getEnergyUseListOne(deviceCode, startTime, endTime, cycle, 1, 10000, startCurrent, table);
  943. List<HtAnalogDataOneVo> minMonthlyReport = baseMapper.getEnergyUseListOne(deviceCode, startTime, endTime, cycle, 2, 10000, startCurrent, table);
  944. if (maxMonthlyReport.size() > 0) {
  945. Double epp = 0.00;
  946. for (int j = 0; j < maxMonthlyReport.size() + 1; j++) {
  947. HtAnalogDataOneVo htAnalogDataOneVo = new HtAnalogDataOneVo();
  948. if (j == maxMonthlyReport.size()) {
  949. htAnalogDataOneVo.setEpp(epp);
  950. htAnalogDataOneVo.setFreezingTime("合计");
  951. } else {
  952. BigDecimal b1 = new BigDecimal(maxMonthlyReport.get(j).getEpp().toString());
  953. BigDecimal b2 = new BigDecimal(minMonthlyReport.get(j).getEpp().toString());
  954. epp += b1.subtract(b2).doubleValue();
  955. htAnalogDataOneVo.setEpp(b1.subtract(b2).doubleValue());
  956. htAnalogDataOneVo.setFreezingTime(maxMonthlyReport.get(j).getFreezingTime());
  957. }
  958. listOne.add(htAnalogDataOneVo);
  959. }
  960. }
  961. return listOne;
  962. }
  963. @Override
  964. public SingleLoopReportOneVo SingleLoopReportData(String deviceCode, Date time, int type) {
  965. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  966. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
  967. String startTime = null;
  968. String endtime = null;
  969. if (type == 1) {
  970. startTime = sdf.format(time) + " 00:00:00";
  971. endtime = sdf.format(time) + " 23:59:59";
  972. } else {
  973. startTime = sdf1.format(time) + "-01 00:00:00";
  974. String time1 = sdf1.format(time) + "-01";
  975. try {
  976. Date yq = getLastDayOfMonth(sdf.parse(time1));
  977. endtime = sdf.format(yq) + " 23:59:59";
  978. } catch (Exception e) {
  979. throw new BusinessException("时间错误");
  980. }
  981. }
  982. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  983. queryWrapper.eq(Device::getDeviceCode, deviceCode);
  984. List<Device> deviceList = deviceService.list(queryWrapper);
  985. String table = "ht_analog_data";
  986. if (deviceList.size() > 0) {
  987. if (deviceList.get(0).getDeviceType().equals("1")) {
  988. table = "ht_analog_data";
  989. } else if (deviceList.get(0).getDeviceType().equals("4")) {
  990. table = "ht_analog_173_data";
  991. }
  992. }
  993. List<SingleLoopReportVo> SingleLoopReportList = baseMapper.getSingleLoopReportData(deviceCode, startTime, endtime, table);
  994. if (CollectionUtils.isEmpty(SingleLoopReportList)) {
  995. SingleLoopReportOneVo singleLoopReportOneVo = new SingleLoopReportOneVo();
  996. return singleLoopReportOneVo;
  997. }
  998. List<HtAnalogData> RtAnalogDataList = baseMapper.getHtAnalogDataList(deviceCode, startTime, endtime, table);
  999. if (CollectionUtils.isEmpty(RtAnalogDataList)) {
  1000. throw new BusinessException("da不存在");
  1001. }
  1002. return analysisCalculation(SingleLoopReportList, RtAnalogDataList);
  1003. }
  1004. // public SingleLoopReportOneVo SingleLoopReportData(String deviceCode, Date time, int type) {
  1005. // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1006. // SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
  1007. // String startTime = null;
  1008. // String endtime = null;
  1009. // if (type == 1) {
  1010. // startTime = sdf.format(time) + " 00:00:00";
  1011. // endtime = sdf.format(time) + " 23:59:59";
  1012. // } else {
  1013. // startTime = sdf1.format(time) + "-01 00:00:00";
  1014. // String time1 = sdf1.format(time) + "-01";
  1015. // try {
  1016. // Date yq = getLastDayOfMonth(sdf.parse(time1));
  1017. // endtime = sdf.format(yq) + " 23:59:59";
  1018. // } catch (Exception e) {
  1019. // throw new BusinessException("时间错误");
  1020. // }
  1021. // }
  1022. // List<SingleLoopReportVo> SingleLoopReportList = baseMapper.SingleLoopReportData(deviceCode, startTime, endtime);
  1023. // if (CollectionUtils.isEmpty(SingleLoopReportList)) {
  1024. // SingleLoopReportOneVo singleLoopReportOneVo = null;
  1025. // return singleLoopReportOneVo;
  1026. //// throw new BusinessException("暂无数据");
  1027. // }
  1028. // LambdaQueryWrapper<HtAnalogData> adQuery = Wrappers.lambdaQuery();
  1029. // adQuery.eq(HtAnalogData::getDeviceName, deviceCode)
  1030. // .between(HtAnalogData::getDataTime, startTime, endtime);
  1031. // List<HtAnalogData> RtAnalogDataList = this.list(adQuery);
  1032. // if (CollectionUtils.isEmpty(RtAnalogDataList)) {
  1033. // throw new BusinessException("da不存在");
  1034. // }
  1035. //
  1036. //
  1037. // return analysisCalculation(SingleLoopReportList, RtAnalogDataList);
  1038. // }
  1039. public SingleLoopReportOneVo analysisCalculation(List<SingleLoopReportVo> SingleLoopReportList, List<HtAnalogData> RtAnalogDataList) {
  1040. DecimalFormat df = new DecimalFormat("######0.00");
  1041. List<Double> checkList = new ArrayList<>();
  1042. SingleLoopReportOneVo singleLoopReportOneVo = BeanMapperUtils.map(SingleLoopReportList.get(0), SingleLoopReportOneVo.class);
  1043. checkList.add(SingleLoopReportList.get(0).getAvgIa());
  1044. checkList.add(SingleLoopReportList.get(0).getAvgIb());
  1045. checkList.add(SingleLoopReportList.get(0).getAvgIc());
  1046. //电流不平衡(平均)
  1047. Double AvgElBalun = checkBalun(checkList) * 100;
  1048. singleLoopReportOneVo.setAvgElBalun(Double.valueOf(df.format(AvgElBalun)));
  1049. if (AvgElBalun < 15) {
  1050. singleLoopReportOneVo.setAvgElBalunStatus(true);
  1051. } else {
  1052. singleLoopReportOneVo.setAvgElBalunStatus(false);
  1053. }
  1054. checkList.clear();
  1055. checkList.add(SingleLoopReportList.get(0).getMaxIa());
  1056. checkList.add(SingleLoopReportList.get(0).getMaxIb());
  1057. checkList.add(SingleLoopReportList.get(0).getMaxIc());
  1058. //电流不平衡(最大)
  1059. Double MaxElBalun = checkBalun(checkList) * 100;
  1060. singleLoopReportOneVo.setMaxElBalun(Double.valueOf(df.format(MaxElBalun)));
  1061. if (MaxElBalun < 15) {
  1062. singleLoopReportOneVo.setMaxElBalunStatus(true);
  1063. } else {
  1064. singleLoopReportOneVo.setMaxElBalunStatus(false);
  1065. }
  1066. checkList.clear();
  1067. checkList.add(SingleLoopReportList.get(0).getMinIa());
  1068. checkList.add(SingleLoopReportList.get(0).getMinIb());
  1069. checkList.add(SingleLoopReportList.get(0).getMinIc());
  1070. //电流不平衡(最小)
  1071. Double MinElBalun = checkBalun(checkList) * 100;
  1072. singleLoopReportOneVo.setMinElBalun(Double.valueOf(df.format(MinElBalun)));
  1073. if (MinElBalun < 15) {
  1074. singleLoopReportOneVo.setMinElBalunStatus(true);
  1075. } else {
  1076. singleLoopReportOneVo.setMinElBalunStatus(false);
  1077. }
  1078. if (AvgElBalun < 15 && MaxElBalun < 15 && MinElBalun < 15) {
  1079. singleLoopReportOneVo.setElBalunStatus(true);
  1080. } else {
  1081. singleLoopReportOneVo.setElBalunStatus(false);
  1082. }
  1083. checkList.clear();
  1084. checkList.add(SingleLoopReportList.get(0).getAvgUa());
  1085. checkList.add(SingleLoopReportList.get(0).getAvgUb());
  1086. checkList.add(SingleLoopReportList.get(0).getAvgUc());
  1087. //电压不平衡(平均)
  1088. Double AvgVtBalun = checkBalun(checkList) * 100;
  1089. singleLoopReportOneVo.setAvgVtBalun(Double.valueOf(df.format(AvgVtBalun)));
  1090. if (AvgVtBalun < 15) {
  1091. singleLoopReportOneVo.setAvgVtBalunStatus(true);
  1092. } else {
  1093. singleLoopReportOneVo.setAvgVtBalunStatus(false);
  1094. }
  1095. checkList.clear();
  1096. checkList.add(SingleLoopReportList.get(0).getMaxUa());
  1097. checkList.add(SingleLoopReportList.get(0).getMaxUb());
  1098. checkList.add(SingleLoopReportList.get(0).getMaxUc());
  1099. //电压不平衡(最大)
  1100. Double MaxVtBalun = checkBalun(checkList) * 100;
  1101. singleLoopReportOneVo.setMaxVtBalun(Double.valueOf(df.format(MaxVtBalun)));
  1102. if (MaxVtBalun < 15) {
  1103. singleLoopReportOneVo.setMaxVtBalunStatus(true);
  1104. } else {
  1105. singleLoopReportOneVo.setMaxVtBalunStatus(false);
  1106. }
  1107. checkList.clear();
  1108. checkList.add(SingleLoopReportList.get(0).getMinUa());
  1109. checkList.add(SingleLoopReportList.get(0).getMinUb());
  1110. checkList.add(SingleLoopReportList.get(0).getMinUc());
  1111. //电压不平衡(最小)
  1112. Double MinVtBalun = checkBalun(checkList) * 100;
  1113. singleLoopReportOneVo.setMinVtBalun(Double.valueOf(df.format(MinVtBalun)));
  1114. if (MinVtBalun < 15) {
  1115. singleLoopReportOneVo.setMinVtBalunStatus(true);
  1116. } else {
  1117. singleLoopReportOneVo.setMinVtBalunStatus(false);
  1118. }
  1119. if (AvgVtBalun < 15 && MaxVtBalun < 15 && MinVtBalun < 15) {
  1120. singleLoopReportOneVo.setVtBalunStatus(true);
  1121. } else {
  1122. singleLoopReportOneVo.setVtBalunStatus(false);
  1123. }
  1124. double voltageLevel = Double.parseDouble(singleLoopReportOneVo.getVoltageLevel());
  1125. double voltageLevelWanting = voltageLevel / 100 * 7;
  1126. //A相电压合格率(平均)
  1127. checkList.clear();
  1128. checkList.add(SingleLoopReportList.get(0).getAvgUa());
  1129. checkList.add(voltageLevel);
  1130. Double AvgUaQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1131. singleLoopReportOneVo.setAvgUa(df.format(SingleLoopReportList.get(0).getAvgUa()) + "kV(" + AvgUaQR + "%)");
  1132. if (AvgUaQR < 7.00) {
  1133. singleLoopReportOneVo.setAvgUaStatus(true);
  1134. } else {
  1135. singleLoopReportOneVo.setAvgUaStatus(false);
  1136. }
  1137. //B相电压合格率(平均)
  1138. checkList.clear();
  1139. checkList.add(SingleLoopReportList.get(0).getAvgUb());
  1140. checkList.add(voltageLevel);
  1141. Double AvgUbQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1142. singleLoopReportOneVo.setAvgUb(df.format(SingleLoopReportList.get(0).getAvgUb()) + "kV(" + AvgUbQR + "%)");
  1143. if (AvgUbQR < 7.00) {
  1144. singleLoopReportOneVo.setAvgUbStatus(true);
  1145. } else {
  1146. singleLoopReportOneVo.setAvgUbStatus(false);
  1147. }
  1148. //C相电压合格率(平均)
  1149. checkList.clear();
  1150. checkList.add(SingleLoopReportList.get(0).getAvgUc());
  1151. checkList.add(voltageLevel);
  1152. Double AvgUcQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1153. singleLoopReportOneVo.setAvgUc(df.format(SingleLoopReportList.get(0).getAvgUc()) + "kV(" + AvgUcQR + "%)");
  1154. if (AvgUcQR < 7.00) {
  1155. singleLoopReportOneVo.setAvgUcStatus(true);
  1156. } else {
  1157. singleLoopReportOneVo.setAvgUcStatus(false);
  1158. }
  1159. //A相电压合格率(最大)
  1160. checkList.clear();
  1161. checkList.add(SingleLoopReportList.get(0).getMaxUa());
  1162. checkList.add(voltageLevel);
  1163. Double MaxUaQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1164. singleLoopReportOneVo.setMaxUa(df.format(SingleLoopReportList.get(0).getMaxUa()) + "kV(" + MaxUaQR + "%)");
  1165. if (MaxUaQR < 7.00) {
  1166. singleLoopReportOneVo.setMaxUaStatus(true);
  1167. } else {
  1168. singleLoopReportOneVo.setMaxUaStatus(false);
  1169. }
  1170. //B相电压合格率(最大)
  1171. checkList.clear();
  1172. checkList.add(SingleLoopReportList.get(0).getMaxUb());
  1173. checkList.add(voltageLevel);
  1174. Double MaxUbQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1175. singleLoopReportOneVo.setMaxUb(df.format(SingleLoopReportList.get(0).getMaxUb()) + "kV(" + MaxUbQR + "%)");
  1176. if (MaxUbQR < 7.00) {
  1177. singleLoopReportOneVo.setMaxUbStatus(true);
  1178. } else {
  1179. singleLoopReportOneVo.setMaxUbStatus(false);
  1180. }
  1181. //C相电压合格率(最大)
  1182. checkList.clear();
  1183. checkList.add(SingleLoopReportList.get(0).getMaxUc());
  1184. checkList.add(voltageLevel);
  1185. Double MaxUcQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1186. singleLoopReportOneVo.setMaxUc(df.format(SingleLoopReportList.get(0).getMaxUc()) + "kV(" + MaxUcQR + "%)");
  1187. if (MaxUcQR < 7.00) {
  1188. singleLoopReportOneVo.setMaxUcStatus(true);
  1189. } else {
  1190. singleLoopReportOneVo.setMaxUcStatus(false);
  1191. }
  1192. //A相电压合格率(最小)
  1193. checkList.clear();
  1194. checkList.add(SingleLoopReportList.get(0).getMinUa());
  1195. checkList.add(voltageLevel);
  1196. Double MinUaQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1197. singleLoopReportOneVo.setMinUa(df.format(SingleLoopReportList.get(0).getMinUa()) + "kV(" + MinUaQR + "%)");
  1198. if (MinUaQR < 7.00) {
  1199. singleLoopReportOneVo.setMinUaStatus(true);
  1200. } else {
  1201. singleLoopReportOneVo.setMinUaStatus(false);
  1202. }
  1203. //B相电压合格率(最小)
  1204. checkList.clear();
  1205. checkList.add(SingleLoopReportList.get(0).getMinUb());
  1206. checkList.add(voltageLevel);
  1207. Double MinUbQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1208. singleLoopReportOneVo.setMinUb(df.format(SingleLoopReportList.get(0).getMinUb()) + "kV(" + MinUbQR + "%)");
  1209. if (MinUbQR < 7.00) {
  1210. singleLoopReportOneVo.setMinUbStatus(true);
  1211. } else {
  1212. singleLoopReportOneVo.setMinUbStatus(false);
  1213. }
  1214. //C相电压合格率(最小)
  1215. checkList.clear();
  1216. checkList.add(SingleLoopReportList.get(0).getMinUc());
  1217. checkList.add(voltageLevel);
  1218. Double MinUcQR = Double.valueOf(df.format(VoltageQr(checkList, voltageLevel)));
  1219. singleLoopReportOneVo.setMinUc(df.format(SingleLoopReportList.get(0).getMinUc()) + "kV(" + MinUcQR + "%)");
  1220. if (MinUcQR < 7.00) {
  1221. singleLoopReportOneVo.setMinUcStatus(true);
  1222. } else {
  1223. singleLoopReportOneVo.setMinUcStatus(false);
  1224. }
  1225. if (AvgUaQR < 7.00 && MaxUaQR < 7.00 && MinUaQR < 7.00) {
  1226. singleLoopReportOneVo.setUaStatus(true);
  1227. } else {
  1228. singleLoopReportOneVo.setUaStatus(false);
  1229. }
  1230. if (AvgUbQR < 7.00 && MaxUbQR < 7.00 && MinUbQR < 7.00) {
  1231. singleLoopReportOneVo.setUbStatus(true);
  1232. } else {
  1233. singleLoopReportOneVo.setUbStatus(false);
  1234. }
  1235. if (AvgUcQR < 7.00 && MaxUcQR < 7.00 && MinUcQR < 7.00) {
  1236. singleLoopReportOneVo.setUcStatus(true);
  1237. } else {
  1238. singleLoopReportOneVo.setUcStatus(false);
  1239. }
  1240. //频率(平均)
  1241. Double cAvgF = 0.00;
  1242. if (SingleLoopReportList.get(0).getAvgF() >= 50) {
  1243. cAvgF = Double.valueOf(df.format(SingleLoopReportList.get(0).getAvgF() - 50.00));
  1244. } else {
  1245. cAvgF = Double.valueOf(df.format(50.00 - SingleLoopReportList.get(0).getAvgF()));
  1246. }
  1247. singleLoopReportOneVo.setAvgF(df.format(SingleLoopReportList.get(0).getAvgF()) + "Hz(" + cAvgF + "Hz)");
  1248. if (SingleLoopReportList.get(0).getAvgF() < 50.2 && SingleLoopReportList.get(0).getAvgF() > 49.8) {
  1249. singleLoopReportOneVo.setAvgFStatus(true);
  1250. } else {
  1251. singleLoopReportOneVo.setAvgFStatus(false);
  1252. }
  1253. //频率(最大)
  1254. Double cMaxF = 0.00;
  1255. if (SingleLoopReportList.get(0).getAvgF() >= 50) {
  1256. cMaxF = Double.valueOf(df.format(SingleLoopReportList.get(0).getMaxF() - 50.00));
  1257. } else {
  1258. cMaxF = Double.valueOf(df.format(50.00 - SingleLoopReportList.get(0).getMaxF()));
  1259. }
  1260. singleLoopReportOneVo.setMaxF(df.format(SingleLoopReportList.get(0).getMaxF()) + "Hz(" + cMaxF + "Hz)");
  1261. if (SingleLoopReportList.get(0).getMaxF() < 50.2 && SingleLoopReportList.get(0).getMaxF() > 49.8) {
  1262. singleLoopReportOneVo.setMaxFStatus(true);
  1263. } else {
  1264. singleLoopReportOneVo.setMaxFStatus(false);
  1265. }
  1266. //频率(最小)
  1267. Double cMinF = 0.00;
  1268. if (SingleLoopReportList.get(0).getAvgF() >= 50) {
  1269. cMinF = Double.valueOf(df.format(SingleLoopReportList.get(0).getMinF() - 50.00));
  1270. } else {
  1271. cMinF = Double.valueOf(df.format(50.00 - SingleLoopReportList.get(0).getMinF()));
  1272. }
  1273. singleLoopReportOneVo.setMinF(df.format(SingleLoopReportList.get(0).getMinF()) + "Hz(" + cMinF + "Hz)");
  1274. if (SingleLoopReportList.get(0).getMinF() < 50.2 && SingleLoopReportList.get(0).getMinF() > 49.8) {
  1275. singleLoopReportOneVo.setMinFStatus(true);
  1276. } else {
  1277. singleLoopReportOneVo.setMinFStatus(false);
  1278. }
  1279. if (singleLoopReportOneVo.getAvgFStatus() == true && singleLoopReportOneVo.getMaxFStatus() == true && singleLoopReportOneVo.getMaxFStatus() == true) {
  1280. singleLoopReportOneVo.setFStatus(true);
  1281. } else {
  1282. singleLoopReportOneVo.setFStatus(false);
  1283. }
  1284. if (SingleLoopReportList.get(0).getCos() > 0.85) {
  1285. singleLoopReportOneVo.setCosStatus(true);
  1286. } else {
  1287. singleLoopReportOneVo.setCosStatus(false);
  1288. }
  1289. int OverrunUa = 0;
  1290. int OverrunUb = 0;
  1291. int OverrunUc = 0;
  1292. int OverrunF = 0;
  1293. int OverrunElBalun = 0;
  1294. int OverrunVtBalun = 0;
  1295. if (RtAnalogDataList.size() > 0) {
  1296. for (int i = 0; i < RtAnalogDataList.size(); i++) {
  1297. checkList.clear();
  1298. checkList.add(RtAnalogDataList.get(i).getUa());
  1299. checkList.add(voltageLevel);
  1300. Double maxUa = checkList.stream().max(Double::compareTo).get();
  1301. Double minUa = checkList.stream().min(Double::compareTo).get();
  1302. Double wantingUa = Arith.sub(maxUa, minUa);
  1303. if (wantingUa < voltageLevelWanting) {
  1304. OverrunUa++;
  1305. }
  1306. checkList.clear();
  1307. checkList.add(RtAnalogDataList.get(i).getUb());
  1308. checkList.add(voltageLevel);
  1309. Double maxUb = checkList.stream().max(Double::compareTo).get();
  1310. Double minUb = checkList.stream().min(Double::compareTo).get();
  1311. Double wantingUb = Arith.sub(maxUb, minUb);
  1312. if (wantingUb < voltageLevelWanting) {
  1313. OverrunUb++;
  1314. }
  1315. checkList.clear();
  1316. checkList.add(RtAnalogDataList.get(i).getUc());
  1317. checkList.add(voltageLevel);
  1318. Double maxUc = checkList.stream().max(Double::compareTo).get();
  1319. Double minUc = checkList.stream().min(Double::compareTo).get();
  1320. Double wantingUc = Arith.sub(maxUc, minUc);
  1321. if (wantingUc < voltageLevelWanting) {
  1322. OverrunUc++;
  1323. }
  1324. if (RtAnalogDataList.get(i).getF() < 50.2 && RtAnalogDataList.get(i).getF() > 49.8) {
  1325. OverrunF++;
  1326. }
  1327. checkList.clear();
  1328. checkList.add(RtAnalogDataList.get(i).getIa());
  1329. checkList.add(RtAnalogDataList.get(i).getIb());
  1330. checkList.add(RtAnalogDataList.get(i).getIc());
  1331. //电流不平衡
  1332. Double ElBalun = checkBalun(checkList);
  1333. if (ElBalun < 0.15) {
  1334. OverrunElBalun++;
  1335. }
  1336. checkList.clear();
  1337. checkList.add(RtAnalogDataList.get(i).getUa());
  1338. checkList.add(RtAnalogDataList.get(i).getUb());
  1339. checkList.add(RtAnalogDataList.get(i).getUc());
  1340. //电压不平衡
  1341. Double VtBalunQ = checkBalun(checkList);
  1342. if (VtBalunQ < 0.15) {
  1343. OverrunVtBalun++;
  1344. }
  1345. }
  1346. }
  1347. singleLoopReportOneVo.setProportionUa(singleLoopReportOneVo.getMeasuringPoints() - OverrunUa + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1348. singleLoopReportOneVo.setProportionUb(singleLoopReportOneVo.getMeasuringPoints() - OverrunUb + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1349. singleLoopReportOneVo.setProportionUc(singleLoopReportOneVo.getMeasuringPoints() - OverrunUc + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1350. singleLoopReportOneVo.setProportionF(singleLoopReportOneVo.getMeasuringPoints() - OverrunF + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1351. singleLoopReportOneVo.setProportionElBalun(singleLoopReportOneVo.getMeasuringPoints() - OverrunElBalun + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1352. singleLoopReportOneVo.setProportionVtBalun(singleLoopReportOneVo.getMeasuringPoints() - OverrunVtBalun + "/" + singleLoopReportOneVo.getMeasuringPoints());
  1353. singleLoopReportOneVo.setQrUa(OverrunUa == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunUa) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()) * 100)));
  1354. singleLoopReportOneVo.setQrUb(OverrunUb == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunUb) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()) * 100)));
  1355. singleLoopReportOneVo.setQrUc(OverrunUc == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunUc) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()) * 100)));
  1356. singleLoopReportOneVo.setQrF(OverrunF == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunF) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()) * 100)));
  1357. singleLoopReportOneVo.setQrElBalun(OverrunElBalun == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunElBalun) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()))));
  1358. singleLoopReportOneVo.setQrVtBalun(OverrunVtBalun == 0 ? 00.00 : Double.valueOf(df.format(Double.valueOf(OverrunVtBalun) / Double.valueOf(singleLoopReportOneVo.getMeasuringPoints()))));
  1359. singleLoopReportOneVo.setVoltageLevelToplimit(voltageLevel + voltageLevelWanting);
  1360. singleLoopReportOneVo.setVoltageLevelLowerLimit(voltageLevel - voltageLevelWanting);
  1361. singleLoopReportOneVo.setMhz(50.00);
  1362. singleLoopReportOneVo.setFToplimit(50.2);
  1363. singleLoopReportOneVo.setFLowerLimit(49.8);
  1364. singleLoopReportOneVo.setAppraise(0.85);
  1365. singleLoopReportOneVo.setBalanceToplimit(15.00);
  1366. singleLoopReportOneVo.setBalanceLowerLimit(15.00);
  1367. return singleLoopReportOneVo;
  1368. }
  1369. public Double VoltageQr(List<Double> checkList, Double voltageLevel) {
  1370. Double max = checkList.stream().max(Double::compareTo).get();
  1371. Double min = checkList.stream().min(Double::compareTo).get();
  1372. Double wanting = Arith.sub(max, min);
  1373. Double QR = wanting / voltageLevel * 100;
  1374. return QR;
  1375. }
  1376. public Double checkBalun(List<Double> list) {
  1377. long count = list.stream().filter(code -> 0.00 == code).count();
  1378. if (3 == count) {
  1379. return 0.00;
  1380. }
  1381. Double max = list.stream().max(Double::compareTo).get();
  1382. Double min = list.stream().min(Double::compareTo).get();
  1383. return Arith.div(Arith.sub(max, min), max);
  1384. }
  1385. }