From d9a9d8a2dad1d1e57b184bf8f972a03d654d883a Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 22 七月 2022 15:07:01 +0800
Subject: [PATCH] 优化
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java | 269 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 230 insertions(+), 39 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
index 02bb51e..5986ccf 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -34,6 +34,7 @@
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
+import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LightMapper;
import com.sandu.ximon.dao.mapper.LightTaskMapper;
import lombok.AllArgsConstructor;
@@ -72,7 +73,7 @@
Boolean hasKey = redisService.hasKey(LightKey.REPORT_MAC.key(deviceName));
if (!hasKey) {
int count = count(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, deviceName));
- log.info("redis鏌ヤ笉鍒拌矾鐏暟鎹畕}={}", count, deviceName);
+ log.info("redis鏌ヤ笉鍒拌矾鐏暟鎹� 鏁伴噺:{}={}", count, deviceName);
// 褰撳墠璺伅琛ㄦ病鏈夊綍鍏ヨ澶囧悧
if (count == 0) {
Light light = new Light();
@@ -80,15 +81,15 @@
light.setLightPercent(heartBeatDataPackage.getLightPercent());
light.setLight2Percent(heartBeatDataPackage.getLight2Percent());
save(light);
+ log.info("鏂板璺伅");
}
redisService.set(LightKey.REPORT_MAC.key(deviceName), 1, LightKey.REPORT_MAC.expireSeconds());
- log.info("鏂板璺伅");
} else {
Light light = new Light();
light.setLightPercent(heartBeatDataPackage.getLightPercent());
light.setLight2Percent(heartBeatDataPackage.getLight2Percent());
- update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, deviceName));
- log.info("鏇存柊璺伅浜害");
+ boolean update = update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, deviceName));
+ log.info("鏇存柊璺伅浜害 {}", update);
}
}
@@ -97,10 +98,43 @@
*
* @return 杩斿洖缁勫悎鏁版嵁dto
*/
- public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
+ public List<LightBo> listLight(int pageNo, int pageSize, String keyword, Integer order, Integer seq) {
Long clientId = SecurityUtils.getClientId();
- // PageHelper.startPage(pageNo, pageSize);
+ //鎺掑簭瀛楁
+ String orderByResult = "light_id";
+ //姝e簭銆佸�掑彊
+ String orderBySeq = OrderByEnums.ASC.getCode();
+ if (order != null) {
+ switch (order) {
+ case 1:
+ orderByResult = OrderByEnums.LIGHT_POLE_NAME.getCode();
+ break;
+ case 2:
+ orderByResult = OrderByEnums.LIGHT_UPDATE_TIME.getCode();
+ break;
+ case 3:
+ orderByResult = OrderByEnums.LIGHT_CREATE_TIME.getCode();
+ break;
+ default:
+ }
+ }
+ if (seq != null) {
+ switch (seq) {
+ case 1:
+ orderBySeq = OrderByEnums.ASC.getCode();
+ break;
+ case 2:
+ orderBySeq = OrderByEnums.DESC.getCode();
+ break;
+ default:
+ break;
+ }
+ }
+ //鎺掑簭鏂瑰紡
+ String orderBy = orderByResult + " " + orderBySeq;
+
+ PageHelper.startPage(pageNo, pageSize, orderBy);
List<LightBo> listLight = baseMapper.listLight(clientId, keyword);
@@ -109,19 +143,19 @@
//鎷嗗垎list
List<List<String>> split = CollectionUtil.split(deviceCodeList, 100);
- List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses=null;
+ List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = null;
for (List<String> splist : split) {
- deviceStatuses=MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist);
+ deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist);
if (deviceStatuses != null) {
for (LightBo lightBo : listLight) {
for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) {
if (lightBo.getDeviceCode() != null && lightBo.getDeviceCode().equals(deviceStatus.getDeviceName())) {
- if("ONLINE".equals(deviceStatus.getStatus()) ){
+ if ("ONLINE".equals(deviceStatus.getStatus())) {
lightBo.setOnlineStatus(0);
- }else if("OFFLINE".equals(deviceStatus.getStatus())){
+ } else if ("OFFLINE".equals(deviceStatus.getStatus())) {
lightBo.setOnlineStatus(1);
- }else {
+ } else {
lightBo.setOnlineStatus(2);
}
@@ -230,7 +264,9 @@
map.put("deviceCode", param.getDeviceCode());
WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame
= MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class);
+ //瀛樺偍鎺у埗甯ф寚浠�
StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "鍗曠伅甯�-浜害鎺у埗", a5Frame, frame);
+
if (frame == null) {
map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
resultList.add(map);
@@ -334,7 +370,7 @@
currentWeekValue = 7;
}
map = new LinkedHashMap();
- map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ map.put("time", localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
map.put("value", getlist(currentWeekValue));
temp.add(map);
}
@@ -406,7 +442,7 @@
currentWeekValue = 7;
}
map = new LinkedHashMap();
- map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ map.put("time", localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
map.put("value", getlistEnergy(currentWeekValue));
temp.add(map);
}
@@ -486,9 +522,6 @@
public BigDecimal getlistEnergy(Integer week) {
- Long clientId = SecurityUtils.getClientId();
-// List<LightBo> listLight = baseMapper.listLight(clientId, null);
-// List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
//鑾峰彇鍒版鍦ㄦ墽琛岀殑浠诲姟鍒楄〃
List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask();
@@ -598,6 +631,61 @@
*/
}
+ /**
+ * 鍗曚釜浠诲姟涓�澶╃殑鑺傝兘鐜�
+ *
+ * @return
+ */
+ public BigDecimal jisuan(LightTaskDto Task) {
+ final BigDecimal[] bigDecimalResult = {new BigDecimal(0.00)};
+ /**
+ * 鑺傝兘鐜囪绠楀紑濮�
+ */
+ //鑾峰彇鏄ㄥぉ鐨勬槦鏈熸暟
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime yesterday = now.minusDays(1);
+ int week = yesterday.getDayOfWeek().getValue();
+
+ //鍒ゆ柇Task.getWeekList()鏄惁鍖呭惈鏄ㄥぉ鐨勬槦鏈熸暟 涓嶅寘鍚洿鎺ヨ繑鍥�0 涓嶈繘琛岃绠�
+ if (Task.getWeekList() != null && !Task.getWeekList().isEmpty()) {
+ if (!Task.getWeekList().contains(week)) {
+ return new BigDecimal(1);
+ }
+ } else {
+ return new BigDecimal(1);
+ }
+
+
+ ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder());
+ ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder());
+ //瀛樻斁鑺傝兘鐜�
+ //鑾峰彇鍒板崟鐏换鍔$殑鑺傝兘鐜�
+ if (Task.getControlOrder() != null && !Task.getControlOrder().isEmpty()) {//鏈夋帶绛夋寚浠� 鎷嗗垎璁$畻
+ List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder());
+
+ for (int i = 0; i < controlLightCommandVOS.size(); i++) {
+ BigDecimal bigDecimal = calculateEnergySaving(startTime, controlLightCommandVOS.get(i));
+ bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal);
+ if (controlLightCommandVOS.size() == (i + 1)) {
+ BigDecimal bigDecimal1 = calculateEnergySaving(controlLightCommandVOS.get(i), endTime);
+ bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal1);
+ break;
+ }
+ startTime = controlLightCommandVOS.get(i);
+// saving.add(bigDecimal);
+ }
+ } else {//鏃犳帶鐏寚浠� 鐩存帴璁$畻
+ BigDecimal bigDecimal = calculateEnergySaving(startTime, endTime);
+// saving.add(bigDecimal);
+ bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal);
+ }
+ return bigDecimalResult[0];
+
+ /**
+ * 鑺傝兘鐜囪绠楃粨鏉�
+ */
+ }
+
/**
* 涓�澶╃殑鑳借��
@@ -623,20 +711,22 @@
for (int i = 0; i < controlLightCommandVOS.size(); i++) {
//寰楀埌鏃堕暱*浜害
BigDecimal bigEnergy1 = calculateEnergyConsumption(startTime, controlLightCommandVOS.get(i));
-// //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
- BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
- bigEnergy[0] = bigEnergy[0].add(totalEnergy);
-// BigDecimal totalEnergy4 = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
-// bigEnergy[0] = bigEnergy[0].add(totalEnergy4);
+ //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+ if (bigEnergy1.compareTo(new BigDecimal(0)) != 0) {
+ //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
+ BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+ }
if (controlLightCommandVOS.size() == (i + 1)) {
BigDecimal bigEnergy2 = calculateEnergyConsumption(controlLightCommandVOS.get(i), endTime);
System.out.println(bigEnergy2 + "鏃堕暱*浜害===========================");
//璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
- BigDecimal totalEnergy3 = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos);
-// saving.add(bigDecimal1);
- bigEnergy[0] = bigEnergy[0].add(totalEnergy3);
+ if (bigEnergy2.compareTo(new BigDecimal(0)) != 0) {
+ BigDecimal totalEnergy3 = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy3);
+ }
break;
}
startTime = controlLightCommandVOS.get(i);
@@ -646,9 +736,14 @@
//璁$畻鑳借��(閮ㄥ垎 鏃堕暱*浜害)
BigDecimal Energy = calculateEnergyConsumption(startTime, endTime);
//璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
- BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos);
+ //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+ if (Energy.compareTo(new BigDecimal(0)) != 0) {
+ BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+ }
+
// saving.add(bigDecimal);
- bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+
}
});
return bigEnergy[0];
@@ -657,6 +752,87 @@
* 璁$畻鑳借�楃粨鏉�
*/
}
+
+
+ /**
+ * 涓�澶╃殑鑳借��
+ *
+ * @param
+ * @return
+ */
+ public BigDecimal jisuanEnergy(LightTaskDto Task) {
+ //瀛樻斁鑳借��
+ final BigDecimal[] bigEnergy = {new BigDecimal(0.00)};
+
+ //鑾峰彇鏄ㄥぉ鐨勬槦鏈熸暟
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime yesterday = now.minusDays(1);
+ int week = yesterday.getDayOfWeek().getValue();
+
+ //鍒ゆ柇Task.getWeekList()鏄惁鍖呭惈鏄ㄥぉ鐨勬槦鏈熸暟 涓嶅寘鍚洿鎺ヨ繑鍥�0 涓嶈繘琛岃绠�
+ if (Task.getWeekList() != null && !Task.getWeekList().isEmpty()) {
+ if (!Task.getWeekList().contains(week)) {
+ return BigDecimal.ZERO;
+ }
+ } else {
+ return BigDecimal.ZERO;
+ }
+
+ /**
+ * 鑺傝兘鐜囪绠楀紑濮�
+ */
+ List<PoleTaskLightPowerBo> poleTaskLightPowerBos = SpringContextHolder.getBean(LightTaskMapper.class).listLightTaskByTaskId(Task.getTaskId());
+ ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder());
+ ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder());
+ //鑾峰彇鍒板崟鐏换鍔$殑鑺傝兘鐜�
+ if (!Task.getControlOrder().isEmpty()) {//鏈夋帶绛夋寚浠� 鎷嗗垎璁$畻
+ List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder());
+
+
+ for (int i = 0; i < controlLightCommandVOS.size(); i++) {
+ //寰楀埌鏃堕暱*浜害
+ BigDecimal bigEnergy1 = calculateEnergyConsumption(startTime, controlLightCommandVOS.get(i));
+ //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+ if (bigEnergy1.compareTo(new BigDecimal(0)) != 0) {
+ //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
+ BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+ }
+ if (controlLightCommandVOS.size() == (i + 1)) {
+ BigDecimal bigEnergy2 = calculateEnergyConsumption(controlLightCommandVOS.get(i), endTime);
+
+ System.out.println(bigEnergy2 + "鏃堕暱*浜害===========================");
+
+ //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
+ if (bigEnergy2.compareTo(new BigDecimal(0)) != 0) {
+ BigDecimal totalEnergy3 = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy3);
+ }
+ break;
+ }
+ startTime = controlLightCommandVOS.get(i);
+ //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
+ }
+ } else {//鏃犳帶鐏寚浠� 鐩存帴璁$畻
+ //璁$畻鑳借��(閮ㄥ垎 鏃堕暱*浜害)
+ BigDecimal Energy = calculateEnergyConsumption(startTime, endTime);
+ //璁$畻鑳借��(鎬� 鏃堕暱*浜害*鍔熺巼)
+ //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+ if (Energy.compareTo(new BigDecimal(0)) != 0) {
+ BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos);
+ bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+ }
+
+// saving.add(bigDecimal);
+
+ }
+ return bigEnergy[0];
+
+ /**
+ * 璁$畻鑳借�楃粨鏉�
+ */
+ }
+
private BigDecimal totalEnergy(BigDecimal bigEnergy2, String lightAdress, List<PoleTaskLightPowerBo> poleTaskLightPowerBos) {
@@ -723,6 +899,9 @@
// BigDecimal hour = BigDecimal.valueOf((v2.getHour() - v1.getHour()));
// BigDecimal hour;
+ if (v1.getBrightness() == 0) {
+ return new BigDecimal(1);
+ }
double hour;
double min;
//璁$畻鏃堕暱
@@ -746,8 +925,13 @@
//璁$畻鏃堕暱
BigDecimal totalTime = BigDecimal.valueOf(hour * 60 + min);
- //璁$畻鑺傝兘鐜� ( (1-v1.getBrightness()/100)*totalTime/3600 ) 淇濈暀涓や綅灏忔暟
- BigDecimal energySaving = BigDecimal.valueOf((1 - v1.getBrightness() / 100) * totalTime.doubleValue() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP);
+
+ //璁$畻鑺傝兘鐜� ( (1-v1.getBrightness()/100)*totalTime/1440 ) 淇濈暀涓や綅灏忔暟
+ // 璁$畻 1-v1.getBrightness()/100鐨勫��
+ BigDecimal Brightness = BigDecimal.valueOf(100 - v1.getBrightness());
+ //Brightness/100*totalTime/1440 淇濈暀涓や綅灏忔暟 Brightness娌℃湁闄や互100 鍦ㄦ�绘椂闂�*100
+ BigDecimal energySaving = Brightness.multiply(totalTime).divide(new BigDecimal(144000), 2, BigDecimal.ROUND_HALF_UP);
+
System.out.println(energySaving + "鑺傝兘鐜�");
return energySaving;
}
@@ -755,27 +939,34 @@
//璁$畻鑳借��(閮ㄥ垎 鏃堕暱*浜害)
public BigDecimal calculateEnergyConsumption(ControlLightCommandVO v1, ControlLightCommandVO v2) {
+
+ if (v1.getBrightness() == 0) {
+ return BigDecimal.ZERO;
+ }
+ double hour;
+ double min;
//璁$畻鏃堕暱
- BigDecimal hour;
if (v2.getHour() > v1.getHour()) {
- hour = BigDecimal.valueOf((v2.getHour() - v1.getHour()));
+ hour = v2.getHour() - v1.getHour();
} else if (v2.getHour() < v1.getHour()) {
- hour = BigDecimal.valueOf((v2.getHour() + 24 - v1.getHour()));
+ hour = 24 + (v2.getHour() - v1.getHour());
} else {
- hour = BigDecimal.valueOf(0);
+ hour = 0;
}
- BigDecimal min;
+ //璁$畻鍒嗛挓
+
if (v2.getMin() > v1.getMin()) {
- min = BigDecimal.valueOf((v2.getMin() - v1.getMin()) / 60);
+ min = v2.getMin() - v1.getMin();
} else if (v2.getMin() < v1.getMin()) {
- min = BigDecimal.valueOf((v2.getMin() + 60 - v1.getMin()) / 60);
- hour = hour.subtract(BigDecimal.valueOf(1));
+ min = 60 + (v1.getMin() - v2.getMin());
+ hour = hour - 1;
} else {
- min = BigDecimal.valueOf(0);
+ min = 0;
}
- BigDecimal totalTime = (hour.add(min));
+ //璁$畻鏃堕暱
+ BigDecimal totalTime = BigDecimal.valueOf(hour + min / 60);
//璁$畻浜伅鏃堕暱*浜害
- BigDecimal energyConsumption = totalTime.multiply(BigDecimal.valueOf(v1.getBrightness())).divide(BigDecimal.valueOf(100));
+ BigDecimal energyConsumption = totalTime.multiply(BigDecimal.valueOf(v1.getBrightness())).divide(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
return energyConsumption;
}
--
Gitblit v1.9.3