From 74ac7af1acc588fee71d3d982c633dd841ead6e3 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 12 八月 2022 16:08:30 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java | 871 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 760 insertions(+), 111 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
index 10b12cc..c97437b 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -1,15 +1,20 @@
package com.sandu.ximon.admin.service;
import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
+import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.dto.LightTaskDto;
+import com.sandu.ximon.admin.dto.SingleLightOrderDto;
import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder;
import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightTimerReqInnerFrame;
@@ -17,22 +22,33 @@
import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
+import com.sandu.ximon.admin.manager.iot.rrpc.util.SupplementUtils;
+import com.sandu.ximon.admin.param.LightTaskIssueParam;
import com.sandu.ximon.admin.param.LightTaskParam;
import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.admin.utils.TaskOrderUtil;
+import com.sandu.ximon.dao.bo.LightTaskPoleRelationBo;
+import com.sandu.ximon.dao.bo.LightTaskStatusAndPole;
+import com.sandu.ximon.dao.domain.LightEnergyData;
import com.sandu.ximon.dao.domain.LightTask;
import com.sandu.ximon.dao.domain.LightTaskPoleRelation;
-import com.sandu.ximon.dao.domain.LightTaskQuartz;
import com.sandu.ximon.dao.domain.Pole;
+import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
+import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LightTaskMapper;
+import com.sandu.ximon.dao.mapper.LightTaskPoleRelationMapper;
import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.math.BigDecimal;
import java.time.LocalDateTime;
-import java.util.List;
-import java.util.Map;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* @author chenjiantian
@@ -40,63 +56,324 @@
* 璺伅浠诲姟鎿嶄綔
*/
@Service
+@Slf4j
@AllArgsConstructor
public class LightTaskService extends BaseServiceImpl<LightTaskMapper, LightTask> {
-
- private final LightTaskQuartzService lightTaskQuartzService;
private final PoleService poleService;
private final LightTaskPoleRelationService lightTaskPoleRelationService;
+ private final LightTaskMapper lightTaskMapper;
+ private final ClientService clientService;
+ private final LightEnergyDataService lightEnergyDataService;
/**
* 鏂板璺伅浠诲姟
+ *
+ * @param param
+ * @return
*/
@Transactional(rollbackFor = Exception.class)
- public boolean addLightTask(LightTaskParam param) {
+ public String newAddLightTask(LightTaskParam param) {
if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) {
throw new BusinessException("鐏帶鍛戒护鏍煎紡涓嶆纭�");
}
+// LightTask lightTask = getById(null);
+
+
int week = 0;
for (Integer w : param.getWeekList()) {
week |= w;
}
- LightTask lightTask = new LightTask();
- lightTask.setClientId(SecurityUtils.getClientId());
- lightTask.setTaskName(param.getTaskName());
- lightTask.setWeek(week);
- lightTask.setCloseOrder(param.getCloseOrder());
- lightTask.setOpenOrder(param.getOpenOrder());
- lightTask.setControlOrder(param.getControlOrder());
- lightTask.setCreateUser(SecurityUtils.getUsername());
- if (!save(lightTask)) {
+
+ LightTask newLightTask = new LightTask();
+ newLightTask.setTaskName(param.getTaskName());
+
+ newLightTask.setClientId(clientService.getClientId());
+ newLightTask.setUserId(SecurityUtils.getUserId());
+
+ newLightTask.setWeek(week);
+ newLightTask.setCreateUser(SecurityUtils.getUsername());
+ newLightTask.setControlOrder(param.getControlOrder());
+ newLightTask.setOpenOrder(param.getOpenOrder());
+ newLightTask.setCloseOrder(param.getCloseOrder());
+ newLightTask.setLightAdress(param.getLightAddress());
+ newLightTask.setUpdateTime(LocalDateTime.now());
+ newLightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week));
+
+ if (!save(newLightTask)) {
throw new BusinessException("淇濆瓨璺伅浠诲姟澶辫触");
}
- List<LightTaskQuartz> list = lightTaskQuartzService.addLightTaskQuartz(lightTask);
- if (CollectionUtil.isEmpty(list)) {
- throw new BusinessException("娣诲姞瀹氭椂浠诲姟澶辫触");
+ List<String> poleCodeList = new ArrayList<>();
+ if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
+ List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+ if (CollectionUtil.isNotEmpty(poleList)) {
+ poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+ }
}
- // 娣诲姞缁戝畾鐏潌
- if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) {
- throw new BusinessException("缁戝畾鐏潌澶辫触");
- }
+ String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "鏂板璺伅浠诲姟", content);
+
+ //浼犲叆鐨勭伅鏉唅d闆嗗悎
List<Long> poleIdList = param.getPoleIdList();
- if (CollectionUtil.isNotEmpty(poleIdList)) {
- List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList);
- if (CollectionUtil.isEmpty(deviceCodeList)) {
- throw new BusinessException("鎵句笉鍒扮伅鏉唌ac锛屾棤娉曞彂閫佸畾鏃朵换鍔�");
- }
- // 鑾峰彇瀹氭椂鐏帶鍛戒护
- String framePayload = list.get(0).getFramePayload();
+ //璁板綍杩欎簺鐏潌鍘熷厛鐨勪换鍔�
+ List<LightTaskPoleRelation> oldLightTaskStatusAndPoles;
+ if ("FFFF".equals(param.getLightAddress())) {
+ oldLightTaskStatusAndPoles = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
+ .in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, "0001"));
+ List<LightTaskPoleRelation> list = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
+ .in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, "0002"));
+ oldLightTaskStatusAndPoles.addAll(list);
+ } else {
+ oldLightTaskStatusAndPoles = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, param.getLightAddress()));
+ }
- // rrpc 鍙戠敓瀹氭椂鍛戒护
- for (String deviceCode : deviceCodeList) {
- sendTimeRRpc(framePayload, deviceCode);
+ /**
+ * 閲嶅浠诲姟鐨勭伅澶�
+ */
+ List<Long> taskIds = oldLightTaskStatusAndPoles.stream().map(LightTaskPoleRelation::getTaskId).collect(Collectors.toList());
+ List<Long> poleIds = oldLightTaskStatusAndPoles.stream().map(LightTaskPoleRelation::getPoleId).collect(Collectors.toList());
+ //poleIds涓噸澶嶅厓绱犲彧淇濈暀涓�涓�
+ taskIds = taskIds.stream().distinct().collect(Collectors.toList());
+ poleIds = poleIds.stream().distinct().collect(Collectors.toList());
+ if (!oldLightTaskStatusAndPoles.isEmpty()) {
+ throw new BusinessException("浠诲姟涓瓨鍦ㄥ凡鏈変换鍔$殑鍗曠伅," + "浠诲姟id涓簕" + taskIds + "}, "
+ + "鐏潌id涓簕" + poleIds + "}");
+ }
+
+
+
+ List<LightTaskPoleRelation> newPoleMap = new ArrayList<>();
+ if (!poleIdList.isEmpty()) {
+ //鏂扮伅鏉嗕笅鍙戞柊浠诲姟
+ newPoleMap = sendControllerFrame(newLightTask, poleIdList, newLightTask.getFramePayload(), param.getLightAddress());
+
+ }
+
+
+
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+
+ String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString() + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
+
+ List<LightTaskPoleRelation> all = new ArrayList<>();
+ all.addAll(newPoleMap);
+ int num = (int) newPoleMap.stream().filter(lightTaskPoleRelation -> lightTaskPoleRelation.getIssueStatus() != 0).count();
+
+
+ //淇濆瓨鏂扮伅鏉嗕互鍙婃棫鐏潌瑕嗙洊鎴愬姛鐨勪换鍔″叧绯�
+ if (!all.isEmpty()) {
+ lightTaskPoleRelationService.saveBatch(all);
+ }
+
+ if (!param.getPoleIdList().isEmpty() && num == newPoleMap.size()) {
+ //鎵�鏈夌伅鏉嗛兘涓嬪彂澶辫触 鏂板鐨勪换鍔′笉淇濈暀
+ removeById(newLightTask);
+ throw new BusinessException("鎸囦护涓嬪彂澶辫触,璇锋鏌ョ伅鏉嗙姸鎬佸悗閲嶆柊鏂板浠诲姟");
+ } else {
+ return "浠诲姟鏂板鎴愬姛";
+ }
+
+
+ }
+
+
+ @Transactional(rollbackFor = Exception.class)
+ public String updateLightTask(Long taskId, LightTaskParam param) {
+ if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) {
+ throw new BusinessException("鐏帶鍛戒护鏍煎紡涓嶆纭�");
+ }
+ LightTask lightTask = getById(taskId);
+ if (lightTask == null) {
+ throw new BusinessException("鎵句笉鍒拌矾鐏换鍔�");
+ }
+
+
+ int week = 0;
+ for (Integer w : param.getWeekList()) {
+ week |= w;
+ }
+
+ LightTask newLightTask = new LightTask();
+ newLightTask.setTaskName(param.getTaskName());
+
+ newLightTask.setClientId(clientService.getClientId());
+ newLightTask.setUserId(SecurityUtils.getUserId());
+
+ newLightTask.setWeek(week);
+ newLightTask.setCreateUser(SecurityUtils.getUsername());
+ newLightTask.setControlOrder(param.getControlOrder());
+ newLightTask.setOpenOrder(param.getOpenOrder());
+ newLightTask.setCloseOrder(param.getCloseOrder());
+ newLightTask.setLightAdress(param.getLightAddress());
+ newLightTask.setUpdateTime(LocalDateTime.now());
+ newLightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week));
+
+
+ //缂栬緫鍚庣伅鏉咺D闆嗗悎
+ List<Long> poleIdList = param.getPoleIdList();
+ if (poleIdList.isEmpty()) {
+ throw new BusinessException("缂栬緫浠诲姟鏃惰閫夋嫨鐏潌");
+ }
+ //璁板綍浠诲姟缂栬緫鍣ㄥ墠鐏潌ID闆嗗悎
+ List<LightTaskStatusAndPole> oldLightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId);
+ List<Long> oldList = oldLightTaskStatusAndPoles.stream().map(LightTaskStatusAndPole::getId).collect(Collectors.toList());
+
+ //鍒ゆ柇param.getPoleIdList()涓槸鍚︽湁鏃х殑鐏潌ID (鐩存帴涓嬪彂)
+ List<Long> newPoleIdList = param.getPoleIdList().stream().filter(poleId -> !oldList.contains(poleId)).collect(Collectors.toList());
+ //鍒ゆ柇param.getPoleIdList()涓槸鍚︽湁鏂扮殑鐏潌ID (瑕嗙洊鎿嶄綔)
+ List<Long> oldPoleIdList = param.getPoleIdList().stream().filter(poleId -> oldList.contains(poleId)).collect(Collectors.toList());
+ //oldList涓湁鐨勭伅鏉咺D锛屼絾鏄痯aram.getPoleIdList()涓病鏈� (鍏崇伅鎿嶄綔)
+ List<Long> closeLight = oldList.stream().filter(poleId -> !param.getPoleIdList().contains(poleId)).collect(Collectors.toList());
+
+
+ //鍙栧嚭瑕嗙洊鎿嶄綔鐨勫叧绯讳俊鎭�
+ //璁板綍杩欎簺鐏潌鍘熷厛鐨勪换鍔�
+ List<LightTaskPoleRelation> oldRelation = new ArrayList<>();
+ if ("FFFF".equals(param.getLightAddress())) {
+ // 鐏潌涓瓨鍦ㄥ叾浠栦换鍔$殑鐏ご
+ if (CollectionUtil.isNotEmpty(oldPoleIdList)) {
+ oldRelation = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList)
+ .ne(LightTaskPoleRelation::getTaskId, taskId).eq(LightTaskPoleRelation::getLightAddress, "0001"));
+ List<LightTaskPoleRelation> list = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList)
+ .ne(LightTaskPoleRelation::getTaskId, taskId).eq(LightTaskPoleRelation::getLightAddress, "0002"));
+ oldRelation.addAll(list);
+ }
+ } else {
+ if (CollectionUtil.isNotEmpty(oldPoleIdList)) {
+ oldRelation = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList)
+ .eq(LightTaskPoleRelation::getLightAddress, param.getLightAddress()));
}
}
- return true;
+
+ /**
+ * 閲嶅浠诲姟鐨勭伅澶�
+ */
+ if (!oldRelation.isEmpty()) {
+ List<Long> taskIds = oldRelation.stream().map(LightTaskPoleRelation::getTaskId).collect(Collectors.toList());
+ List<Long> poleIds = oldRelation.stream().map(LightTaskPoleRelation::getPoleId).collect(Collectors.toList());
+ //poleIds涓噸澶嶅厓绱犲彧淇濈暀涓�涓�
+ taskIds = taskIds.stream().distinct().collect(Collectors.toList());
+ poleIds = poleIds.stream().distinct().collect(Collectors.toList());
+ throw new BusinessException("浠诲姟涓瓨鍦ㄥ凡鏈変换鍔$殑鍗曠伅," + "浠诲姟id涓簕" + taskIds + "}, "
+ + "鐏潌id涓簕" + poleIds + "}");
+ }
+
+
+ List<LightTaskPoleRelation> newPoleAll = new ArrayList<>();
+ List<LightTaskPoleRelation> newPoleSuccess = new ArrayList<>();
+ List<LightTaskPoleRelation> newPoleFail = new ArrayList<>();
+ if (CollectionUtil.isNotEmpty(newPoleIdList)) {
+ //鏂扮伅鏉嗕笅鍙戞柊浠诲姟
+ Map<String, List<LightTaskPoleRelation>> newPoleMap = sendControllerFrame(newPoleIdList, lightTask.getFramePayload(), param.getLightAddress());
+
+ //newPoleAll闆嗗悎鍚庨潰鐢ㄤ簬瀛樺偍鍏崇郴琛�
+ newPoleAll = newPoleMap.getOrDefault("all", new ArrayList<>());
+ newPoleSuccess = newPoleMap.getOrDefault("success", new ArrayList<>());
+ newPoleFail = newPoleMap.getOrDefault("fail", new ArrayList<>());
+ }
+
+
+ List<LightTaskPoleRelation> closePoleFail = new ArrayList<>();
+ List<LightTaskPoleRelation> closePoleSuccess = new ArrayList<>();
+ if (CollectionUtil.isNotEmpty(closeLight)) {
+ //鍏崇伅鍐呭抚
+ String framePayloadClose = "7f0000007f173b00";
+ //瑕嗙洊鎿嶄綔鐏潌
+ Map<String, List<LightTaskPoleRelation>> closePoleMap = sendControllerFrame(closeLight, framePayloadClose, param.getLightAddress());
+ closePoleFail = closePoleMap.getOrDefault("fail", new ArrayList<>());
+ closePoleSuccess = closePoleMap.getOrDefault("success", new ArrayList<>());
+ }
+
+
+ if (closePoleFail.size() == 0) {
+ //鏃т换鍔′腑鍏ㄩ儴鍙戦�佹寚浠ゆ垚鍔燂紝鏇存柊鍘熸湰浠诲姟涓殑鏁版嵁
+ newLightTask.setTaskId(lightTask.getTaskId());
+ updateById(newLightTask);
+ } else {
+ if (!newPoleSuccess.isEmpty()) {
+ //鏈夊け鏁楃殑闇�瑕佷繚瀛樻棫鐨勪换鍕欙紝鏂板鏂扮殑浠诲姟鏁版嵁杩涜淇濆瓨
+ save(newLightTask);
+ }
+ }
+
+ /**
+ * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+ List<String> poleCodeList = new ArrayList<>();
+ if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
+ List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+ if (CollectionUtil.isNotEmpty(poleList)) {
+ poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+ }
+ }
+ String content = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}锛寋鍐呭抚鎸囦护" + newLightTask.getFramePayload() + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString() + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress() + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "缂栬緫璺伅浠诲姟", content);
+ /**
+ * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
+
+ for (LightTaskPoleRelation bean : newPoleSuccess) {
+ bean.setTaskId(newLightTask.getTaskId());
+ }
+
+ //澶辫触鐢ㄦ棫鐨勪换鍔D
+ for (LightTaskPoleRelation bean : closePoleFail) {
+ bean.setTaskId(lightTask.getTaskId());
+ }
+
+ List<LightTaskPoleRelation> all = new ArrayList<>();
+ all.addAll(newPoleSuccess);
+// all.addAll(closePoleFail);
+
+
+ List<Long> allPoleId = new ArrayList<>();
+ for (LightTaskPoleRelation bean : newPoleSuccess) {
+ allPoleId.add(bean.getPoleId());
+ }
+ for (LightTaskPoleRelation bean : closePoleSuccess) {
+ allPoleId.add(bean.getPoleId());
+ }
+
+ if (!allPoleId.isEmpty()) {
+ lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, allPoleId));
+
+ }
+
+ if (!all.isEmpty()) {
+ lightTaskPoleRelationService.saveBatch(all);
+ }
+
+
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+ String content1 = "{浠诲姟ID锛�" + newLightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + newLightTask.getTaskName() + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString() + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
+
+ if (newPoleFail.isEmpty() && closePoleFail.isEmpty()) {
+ return "缂栬緫鎴愬姛";
+ } else if (newPoleSuccess.isEmpty() && closePoleSuccess.isEmpty()) {
+ throw new BusinessException("缂栬緫澶辫触,璇锋鏌ュ師鏈夎澶囧拰缂栬緫鍚庣殑璁惧鏄惁鍦ㄧ嚎!");
+ } else if (!closePoleFail.isEmpty() && !newPoleSuccess.isEmpty()) {
+ return "鍘熶换鍔′腑瀛樺湪涓嬪彂寮傚父锛屽師浠诲姟淇濈暀锛屽垱寤烘柊浠诲姟杩涜淇濆瓨";
+ } else if (!newPoleFail.isEmpty() && !newPoleSuccess.isEmpty()) {
+ return "鏂颁换鍔′腑瀛樺湪涓嬪彂寮傚父锛屽拷鐣ュ紓甯告搷浣滅殑鐏潌";
+ } else {
+ return "鎿嶄綔寮傚父";
+ }
}
+
/**
* 鍙戦�佺伅鎺ц姹�
@@ -105,92 +382,309 @@
* @param deviceCode 璁惧鍚�
* @return 杩斿洖甯�
*/
- public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) {
- IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload))
- .orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build();
- WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance()
- .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class);
- System.out.println("鍙戦�佺粨鏋�");
- A5LightTimerRespInnerFrame responseInnerFrame = responseCommonFrame.getResponseInnerFrame();
- System.out.println(responseInnerFrame.getResponseStatus());
- return responseInnerFrame;
+ public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode, String lightAddress) {
+ IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload, lightAddress)).orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build();
+ WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class);
+
+ StoreOperationRecordsUtils.storeInnerFrameData(deviceCode, "鍗曠伅甯�-鎺х伅", requestFrame, responseCommonFrame);
+
+ return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null);
}
- public List<LightTaskDto> listLightTask(int pageNo, int pageSize, String keyword) {
- LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class);
- if (StrUtil.isNotBlank(keyword)) {
- wrapper.like(LightTask::getTaskName, keyword);
- }
- Long clientId = SecurityUtils.getClientId();
- if (clientId != null) {
- wrapper.eq(LightTask::getClientId, clientId);
- }
+ public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, String keyword, Integer order, Integer seq) {
- PageHelper.startPage(pageNo, pageSize);
- List<LightTask> list = list(wrapper);
+ //鎺掑簭瀛楁
+ String orderByResult = "task_id";
+ //姝e簭銆佸�掑彊
+ String orderBySeq = OrderByEnums.ASC.getCode();
+ if (order != null) {
+ switch (order) {
+ case 1:
+ orderByResult = OrderByEnums.LIGHT_TASK_UPDATE_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(conditionVO.getPageNo(), conditionVO.getPageSize(), orderBy);
+ List<LightTask> list = baseMapper.listTask(SecurityUtils.getClientId(), keyword, orderBy);
+
Page<LightTaskDto> page = new Page<>();
- BeanUtils.copyProperties(list,page);
+ BeanUtils.copyProperties(list, page);
for (LightTask lightTask : list) {
LightTaskDto lightTaskDto = new LightTaskDto();
- BeanUtils.copyProperties(lightTask,lightTaskDto);
+ BeanUtils.copyProperties(lightTask, lightTaskDto);
+ lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek()));
+
+
+ //鍒ゆ柇鐏ご鏄惁瀛樺湪浠诲姟
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = lightTaskPoleRelationService.list(Wrappers.<LightTaskPoleRelation>lambdaQuery().eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
+
+ //涓嬪彂鎴愬姛鐨勭伅鏉嗘暟閲�
+ Integer successCount = baseMapper.successCount(lightTaskDto.getTaskId());
+ ///浠诲姟涓�荤殑鐏潌鏁伴噺
+ Integer toTalCount = baseMapper.toTalCount(lightTaskDto.getTaskId());
+ if (successCount == null) {
+ successCount = 0;
+ }
+ if (toTalCount == null) {
+ toTalCount = 0;
+ }
+ if (toTalCount == 0) {
+ //浠诲姟涓病鏈夌伅鏉�
+ lightTaskDto.setSyncStatus("鏈悓姝�");
+ } else {
+ //浠诲姟涓湁鐏潌
+ if (successCount == 0) {
+ //涓嬪彂鎴愬姛鏈�0
+ lightTaskDto.setSyncStatus("鏈悓姝�");
+ } else if (successCount != 0 && successCount < toTalCount) {
+ //瀛樺湪涓嬪彂鎴愬姛 浣嗗苟鏈叏閮ㄦ垚鍔�
+ lightTaskDto.setSyncStatus("閮ㄥ垎鍚屾");
+ } else if (toTalCount.equals(successCount) && toTalCount != 0 && successCount != 0) {
+ //鍏ㄩ儴鎴愬姛
+ lightTaskDto.setSyncStatus("宸插悓姝�");
+ } else {
+ //鏈煡绫诲瀷
+ lightTaskDto.setSyncStatus("鍚屾鐘舵�佸嚭閿�");
+ }
+ }
+ page.add(lightTaskDto);
+ }
+ return page;
+ }
+
+ /**
+ * 鎵ц涓殑璺伅浠诲姟
+ *
+ * @return
+ */
+ public List<LightTaskDto> listTask() {
+ Long clientId = SecurityUtils.getClientId();
+ List<LightTask> lightTasks = lightTaskMapper.listLightTask(clientId);
+ Page<LightTaskDto> page = new Page<>();
+ BeanUtils.copyProperties(lightTasks, page);
+ for (LightTask lightTask : lightTasks) {
+ LightTaskDto lightTaskDto = new LightTaskDto();
+ BeanUtils.copyProperties(lightTask, lightTaskDto);
lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek()));
page.add(lightTaskDto);
}
return page;
}
+ /**
+ * 鐢ㄤ簬浠诲姟鏂板,涓嬪彂
+ *
+ * @param lightTask
+ * @param poleIdList
+ * @param framePayload
+ * @param lightAddress
+ * @return
+ */
+ private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload, String lightAddress) {
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>();
+ //鎴愬姛
+ List<LightTaskPoleRelation> success = new ArrayList<>();
+ //澶辫触
+ List<LightTaskPoleRelation> fail = new ArrayList<>();
- @Transactional(rollbackFor = Exception.class)
- public boolean updateLightTask(Long taskId, LightTaskParam param) {
- if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) {
- throw new BusinessException("鐏帶鍛戒护鏍煎紡涓嶆纭�");
- }
- LightTask lightTask = getById(taskId);
- if (lightTask == null) {
- throw new BusinessException("鎵句笉鍒拌矾鐏换鍔�");
- }
- int week = 0;
- for (Integer w : param.getWeekList()) {
- week |= w;
- }
- lightTask.setTaskName(param.getTaskName());
- lightTask.setWeek(week);
- lightTask.setControlOrder(param.getControlOrder());
- lightTask.setOpenOrder(param.getOpenOrder());
- lightTask.setCloseOrder(param.getCloseOrder());
- lightTask.setUpdateTime(LocalDateTime.now());
+ Map map = new HashMap();
- if (!updateById(lightTask)) {
- throw new BusinessException("缂栬緫浠诲姟澶辫触");
+ List<Pole> poles = poleService.listByIds(poleIdList);
+ if (CollectionUtil.isEmpty(poles)) {
+ return null;
}
- List<LightTaskQuartz> list = lightTaskQuartzService.updateLightTaskQuartz(lightTask);
- if (CollectionUtil.isEmpty(list)) {
- throw new BusinessException("缂栬緫瀹氭椂浠诲姟澶辫触");
- }
-
- // 娣诲姞缁戝畾鐏潌
- if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) {
- throw new BusinessException("缁戝畾鐏潌澶辫触");
- }
- List<Long> poleIdList = param.getPoleIdList();
- if (CollectionUtil.isNotEmpty(poleIdList)) {
- List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList);
- if (CollectionUtil.isEmpty(deviceCodeList)) {
- throw new BusinessException("鎵句笉鍒扮伅鏉唌ac锛屾棤娉曞彂閫佸畾鏃朵换鍔�");
+ for (Pole pole : poles) {
+ if (pole.getDeviceCode() == null || pole.getDeviceCode().equals("")) {
+ removeById(lightTask.getTaskId());
+ throw new BusinessException("鐏潌涓嶅瓨鍦╩ac,涓嶈兘涓嬪彂浠诲姟 璇锋鏌ョ伅鏉嗘槸鍚﹀瓨鍦ㄥ崟鐏�");
}
- // 鑾峰彇瀹氭椂鐏帶鍛戒护
- String framePayload = list.get(0).getFramePayload();
+ LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation();
+ lightTaskPoleRelation.setPoleId(pole.getId());
+ lightTaskPoleRelation.setTaskId(lightTask.getTaskId());
+ // rrpc 鍙戠敓瀹氭椂鍛戒护
+ if ("FFFF".equals(lightAddress)) {
+ LightTaskPoleRelation lightTaskPoleRelation01 = new LightTaskPoleRelation();
+ lightTaskPoleRelation01.setPoleId(pole.getId());
+ lightTaskPoleRelation01.setTaskId(lightTask.getTaskId());
+ lightTaskPoleRelation01.setLightAddress("0001");
+
+ LightTaskPoleRelation lightTaskPoleRelation02 = new LightTaskPoleRelation();
+ lightTaskPoleRelation02.setPoleId(pole.getId());
+ lightTaskPoleRelation02.setTaskId(lightTask.getTaskId());
+ lightTaskPoleRelation02.setLightAddress("0002");
+
+ // 鐏ご1 rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame01 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0001");
+ //鐏ご1
+ if (a5LightTimerRespInnerFrame01 == null) {
+ lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ } else {
+ lightTaskPoleRelation01.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame01.getResponseStatus()));
+ }
+
+ } catch (BusinessException e) {
+ lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ }
+
+ // 鐏ご2 rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame02 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0002");
+ //鐏ご2
+ if (a5LightTimerRespInnerFrame02 == null) {
+ lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ } else {
+ lightTaskPoleRelation02.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame02.getResponseStatus()));
+ }
+
+ } catch (BusinessException e) {
+ lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ }
+
+ lightTaskPoleRelationList.add(lightTaskPoleRelation01);
+ lightTaskPoleRelationList.add(lightTaskPoleRelation02);
+ } else {
+ lightTaskPoleRelation.setLightAddress(lightAddress);
+ // rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress);
+ if (a5LightTimerRespInnerFrame == null) {
+ lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ } else {
+ lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus()));
+ }
+ } catch (BusinessException e) {
+ lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ }
+ lightTaskPoleRelationList.add(lightTaskPoleRelation);
+ }
+
+ }
+ return lightTaskPoleRelationList;
+ }
+
+ /**
+ * 鐢ㄤ簬浠诲姟缂栬緫
+ *
+ * @param poleIdList
+ * @param framePayload
+ * @param lightAddress
+ * @return
+ */
+ private Map<String, List<LightTaskPoleRelation>> sendControllerFrame(List<Long> poleIdList, String framePayload, String lightAddress) {
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>();
+ //鎴愬姛
+ List<LightTaskPoleRelation> success = new ArrayList<>();
+ //澶辫触
+ List<LightTaskPoleRelation> fail = new ArrayList<>();
+
+ Map<String, List<LightTaskPoleRelation>> map = new HashMap();
+
+ List<Pole> poles = poleService.listByIds(poleIdList);
+ if (CollectionUtil.isEmpty(poles)) {
+ return null;
+ }
+
+ for (Pole pole : poles) {
+ if (pole.getDeviceCode() == null || pole.getDeviceCode().equals("")) {
+ throw new BusinessException("鐏潌涓嶅瓨鍦╩ac,涓嶈兘涓嬪彂浠诲姟 璇锋鏌ョ伅鏉嗘槸鍚﹀瓨鍦ㄥ崟鐏�");
+ }
+ LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation();
+ lightTaskPoleRelation.setPoleId(pole.getId());
+ //鍏崇郴琛ㄦ彃鍏ョ伅澶村湴鍧�
+ lightTaskPoleRelation.setLightAddress(lightAddress);
+
// rrpc 鍙戠敓瀹氭椂鍛戒护
- for (String deviceCode : deviceCodeList) {
- sendTimeRRpc(framePayload, deviceCode);
- }
- }
+ if ("FFFF".equals(lightAddress)) {
+ LightTaskPoleRelation lightTaskPoleRelation01 = new LightTaskPoleRelation();
+ lightTaskPoleRelation01.setPoleId(pole.getId());
+ lightTaskPoleRelation01.setLightAddress("0001");
- return true;
+ LightTaskPoleRelation lightTaskPoleRelation02 = new LightTaskPoleRelation();
+ lightTaskPoleRelation02.setPoleId(pole.getId());
+ lightTaskPoleRelation02.setLightAddress("0002");
+
+ // 鐏ご1 rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame01 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0001");
+ //鐏ご1
+ if (a5LightTimerRespInnerFrame01 == null) {
+ lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation01);
+ } else {
+ lightTaskPoleRelation01.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame01.getResponseStatus()));
+ success.add(lightTaskPoleRelation01);
+ }
+
+ } catch (BusinessException e) {
+ lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation01);
+ }
+
+ // 鐏ご2 rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame02 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0002");
+ //鐏ご2
+ if (a5LightTimerRespInnerFrame02 == null) {
+ lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation02);
+ } else {
+ lightTaskPoleRelation02.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame02.getResponseStatus()));
+ success.add(lightTaskPoleRelation02);
+ }
+
+ } catch (BusinessException e) {
+ lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation02);
+ }
+
+ lightTaskPoleRelationList.add(lightTaskPoleRelation01);
+ lightTaskPoleRelationList.add(lightTaskPoleRelation02);
+ } else {
+ lightTaskPoleRelation.setLightAddress(lightAddress);
+ // rrpc 鍙戠敓瀹氭椂鍛戒护
+ try {
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress);
+ if (a5LightTimerRespInnerFrame == null) {
+ lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation);
+ } else {
+ lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus()));
+ success.add(lightTaskPoleRelation);
+ }
+ } catch (BusinessException e) {
+ lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
+ fail.add(lightTaskPoleRelation);
+ }
+ lightTaskPoleRelationList.add(lightTaskPoleRelation);
+ }
+
+ }
+ map.put("success", success);
+ map.put("fail", fail);
+ map.put("all", lightTaskPoleRelationList);
+ return map;
}
+
@Transactional(rollbackFor = Exception.class)
public boolean delLightTask(List<Long> taskIdList) {
@@ -199,31 +693,186 @@
throw new BusinessException("鎵句笉鍒颁换鍔′俊鎭�");
}
+ List<LightTaskPoleRelation> list = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList));
+ if (list.size() != 0) {
+ throw new BusinessException("鍒犻櫎浠诲姟澶辫触锛屽垹闄ょ殑浠诲姟鏈夌伅鏉嗘鍦ㄤ娇鐢�");
+ }
+
// 鍒犻櫎浠诲姟
if (!removeByIds(taskIdList)) {
throw new BusinessException("鍒犻櫎浠诲姟澶辫触");
}
- // 鍒犻櫎缁戝畾鐏潌
- if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList))) {
- throw new BusinessException("鍒犻櫎缁戝畾鐏潌澶辫触");
+ /**
+ * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+ String content = "{鎺х伅浠诲姟id锛�" + taskIdList + " }";
+ StoreOperationRecordsUtils.storeOperationData(null, null, "鍒犻櫎鎺х伅浠诲姟", content);
+ /**
+ * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
+ return true;
+ }
+
+ /**
+ * 浠诲姟璇︽儏
+ */
+ public Map<Object, Object> detailLightTask(Long taskId) {
+ LightTask lightTask = getById(taskId);
+ if (lightTask == null) {
+ throw new BusinessException("鎵句笉鍒颁换鍔�");
+ }
+ List<LightTaskStatusAndPole> lightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId);
+ return MapUtil.builder().put("task", lightTask).put("poles", lightTaskStatusAndPoles).build();
+ }
+
+ /**
+ * 鏍规嵁浠诲姟淇℃伅杞垚甯ц礋鑽�
+ *
+ * @return 璺伅瀹氭椂鍣ㄥ垪琛�
+ */
+ private String buildControlFramePayload(String openOrder, String closeOrder, String controlOrder, Integer week) {
+
+ // 娣诲姞寮�鐏畾鏃跺櫒
+ SingleLightOrderDto openLightOrder = TaskOrderUtil.parseLightOrder(openOrder);
+ SingleLightOrderDto closeLightOrder = TaskOrderUtil.parseLightOrder(closeOrder);
+ String[] controlOrderArray = StrUtil.split(controlOrder, LightTaskParam.REQUEST_ORDER_LENGTH);
+ Integer[] weekArrays = TaskOrderUtil.parseLightCronWeek2List(week).toArray(new Integer[0]);
+ if (openLightOrder == null || closeLightOrder == null) {
+ throw new BusinessException("瑙f瀽鍗曠伅鍛戒护澶辫触");
+ }
+ if (ArrayUtil.isEmpty(weekArrays)) {
+ throw new BusinessException("璇疯缃槦鏈�");
}
- // 鍒犻櫎瀹氭椂鍣�
- if (!lightTaskQuartzService.removeLightTaskQuartz(taskIdList)) {
- throw new BusinessException("鍒犻櫎瀹氭椂鍣ㄥけ璐�");
+ StringBuilder sb = new StringBuilder();
+ String weekHex = SupplementUtils.suppleZero(HexUtil.toHex(week), 2);
+
+ // 鎷兼帴寮�鐏懡浠�
+ sb.append(weekHex);
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getHour()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getMinute()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getBrightness()), 2));
+
+ // 鎷兼帴鍏崇伅鍛戒护
+ sb.append(weekHex);
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getHour()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getMinute()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getBrightness()), 2));
+
+ // 鎷兼帴浜害鎺х伅鍛戒护
+ for (String controlOrderStr : controlOrderArray) {
+ SingleLightOrderDto controlLightOrder = TaskOrderUtil.parseLightOrder(controlOrderStr);
+ if (controlLightOrder != null) {
+ sb.append(weekHex);
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getHour()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getMinute()), 2));
+ sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getBrightness()), 2));
+ }
}
+
+ return sb.toString();
+ }
+
+ /**
+ * 涓嬪彂鍗曚釜鐏潌鐨勪换鍔�
+ */
+ public boolean issueLightTask(LightTaskIssueParam param) {
+ LightTask lightTask = getById(param.getTaskId());
+ if (lightTask == null) {
+ throw new BusinessException("鎵句笉鍒颁换鍔�");
+ }
+ String framePayload = buildControlFramePayload(lightTask.getOpenOrder(), lightTask.getCloseOrder(), lightTask.getControlOrder(), lightTask.getWeek());
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()), framePayload, lightTask.getLightAdress());
+
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+ List<String> poleCodeList = new ArrayList<>();
+ List<Pole> list = SpringContextHolder.getBean(PoleService.class).list(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, param.getPoleId()));
+ if (CollectionUtil.isNotEmpty(list)) {
+ poleCodeList = list.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+ }
+ String content = "{浠诲姟ID锛�" + lightTask.getTaskId() + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName() + "}," + " 鐏潌ID锛�" + param.getPoleId() + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content);
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
+
+
+ if (CollectionUtil.isNotEmpty(lightTaskPoleRelationList)) {
+ return lightTaskPoleRelationService.update(lightTaskPoleRelationList.get(0), Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, param.getPoleId()).eq(LightTaskPoleRelation::getTaskId, param.getTaskId()));
+ }
+
return true;
}
- public Map<Object, Object> detailLightTask(Long taskId) {
- LightTask lightTask = getById(taskId);
- if(lightTask == null){
- throw new BusinessException("鎵句笉鍒颁换鍔�");
+
+ /**
+ * 璁$畻鍔熺巼鍙婅兘鑰�
+ */
+ public void energy() {
+ List<LightTask> lightTasks = list(Wrappers.lambdaQuery(LightTask.class));
+
+ List<Long> taskIdList = new ArrayList<>();
+ for (LightTask bean : lightTasks) {
+ taskIdList.add(bean.getTaskId());
}
- List<Long> poleIdList = lightTaskPoleRelationService.listPoleIdByTaskId(taskId);
- List<Pole> poles = poleService.listByIds(poleIdList);
- return MapUtil.builder().put("task",lightTask).put("poles",poles).build();
+ if (taskIdList.size() != 0) {
+ List<LightTaskPoleRelationBo> list = SpringContextHolder.getBean(LightTaskPoleRelationMapper.class).test(taskIdList);
+ for (LightTaskPoleRelationBo bean : list) {
+
+ LightTaskDto lightTaskDto = new LightTaskDto();
+ BeanUtils.copyProperties(bean, lightTaskDto);
+ lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(bean.getWeek()));
+ BigDecimal energySaving;
+ BigDecimal energy;
+ //鑾峰彇鏄ㄥぉ鐨勬槦鏈熸暟
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime yesterday = now.minusDays(1);
+ int week = yesterday.getDayOfWeek().getValue();
+ if (!list.isEmpty()) {
+ //鏈夌粦瀹氱伅鏉� 杩涜璁$畻
+ if (lightTaskDto.getWeekList().contains(week)) {
+ //浠诲姟鏈夎鏄熸湡鏁� 璁$畻
+ energySaving = SpringContextHolder.getBean(LightService.class).jisuan(lightTaskDto);
+ energy = SpringContextHolder.getBean(LightService.class).jisuanEnergy(lightTaskDto);
+ } else {
+ //浠诲姟鏃犺鏄熸湡鏁� 杩斿洖
+ energySaving = new BigDecimal(1);
+ energy = BigDecimal.ZERO;
+ }
+ for (int i = 0; i < list.size(); i++) {
+ LightTaskPoleRelation relation = list.get(i);
+ if (relation.getIssueStatus() != 0) {
+ //浠诲姟涓嬪彂澶辫触 杩斿洖
+ energySaving = new BigDecimal(1);
+ energy = BigDecimal.ZERO;
+ }
+ }
+ } else {
+ //鏈粦瀹氱伅鏉� 鐩存帴杩斿洖
+ energySaving = new BigDecimal(1);
+ energy = BigDecimal.ZERO;
+ }
+
+ /**
+ * 瀛樺偍鏁版嵁
+ */
+
+ LightEnergyData lightEnergyData = new LightEnergyData();
+ lightEnergyData.setTaskId(bean.getTaskId());
+ lightEnergyData.setYtdTime(yesterday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ lightEnergyData.setEnergySaving(energySaving);
+ lightEnergyData.setEnergy(energy);
+ lightEnergyData.setUserId(bean.getUserId());
+ lightEnergyData.setClientId(bean.getClientId());
+ lightEnergyData.setPoleId(bean.getPoleId());
+ //淇濆瓨鑳借�楁暟鎹埌鏁版嵁搴�
+ lightEnergyDataService.save(lightEnergyData);
+ }
+
+ }
}
}
--
Gitblit v1.9.3