From 03267d87fade82578087123a1be515b6fde20bfb Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期二, 17 五月 2022 14:19:01 +0800
Subject: [PATCH] 日志
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java | 199 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 159 insertions(+), 40 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 7dad952..d4d8cae 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
@@ -11,7 +11,9 @@
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;
@@ -25,12 +27,13 @@
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.LightTaskStatusAndPole;
import com.sandu.ximon.dao.domain.LightTask;
import com.sandu.ximon.dao.domain.LightTaskPoleRelation;
import com.sandu.ximon.dao.domain.Pole;
-import com.sandu.ximon.dao.enums.IssueStatusEnums;
+import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
import com.sandu.ximon.dao.mapper.LightTaskMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -43,6 +46,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* @author chenjiantian
@@ -54,11 +58,9 @@
@AllArgsConstructor
public class LightTaskService extends BaseServiceImpl<LightTaskMapper, LightTask> {
-
- // private final LightTaskQuartzService lightTaskQuartzService;
private final PoleService poleService;
private final LightTaskPoleRelationService lightTaskPoleRelationService;
-
+ private final LightTaskMapper lightTaskMapper;
/**
* 鏂板璺伅浠诲姟
@@ -76,6 +78,7 @@
lightTask.setClientId(SecurityUtils.getClientId());
lightTask.setTaskName(param.getTaskName());
lightTask.setWeek(week);
+ lightTask.setLightAdress(param.getLightAddress());
lightTask.setCloseOrder(param.getCloseOrder());
lightTask.setOpenOrder(param.getOpenOrder());
lightTask.setControlOrder(param.getControlOrder());
@@ -84,15 +87,33 @@
if (!save(lightTask)) {
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());
+ }
+ }
+ String content = "{浠诲姟ID锛�" + lightTask.getTaskId()
+ + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+ + "}锛寋鍐呭抚鎸囦护" + lightTask.getFramePayload()
+ + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString()
+ + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress()
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "鏂板璺伅浠诲姟", content);
+ /**
+ * 鏂板璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
List<Long> poleIdList = param.getPoleIdList();
if (CollectionUtil.isNotEmpty(poleIdList)) {
- List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList,lightTask.getFramePayload());
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress());
// 娣诲姞缁戝畾鐏潌
if (!lightTaskPoleRelationService.saveBatch(lightTaskPoleRelationList)) {
@@ -101,6 +122,19 @@
// 涓�涓伅鏉嗗彧鑳戒娇鐢ㄤ竴涓换鍔★紝鏂颁换鍔¤瑕嗙洊鏃т换鍔�
lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
+
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+
+ String content1 = "{浠诲姟ID锛�" + lightTask.getTaskId()
+ + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+ + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString()
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
}
return true;
}
@@ -123,6 +157,7 @@
lightTask.setControlOrder(param.getControlOrder());
lightTask.setOpenOrder(param.getOpenOrder());
lightTask.setCloseOrder(param.getCloseOrder());
+ lightTask.setLightAdress(param.getLightAddress());
lightTask.setUpdateTime(LocalDateTime.now());
lightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week));
@@ -130,15 +165,31 @@
throw new BusinessException("缂栬緫浠诲姟澶辫触");
}
-// List<LightTaskQuartz> list = lightTaskQuartzService.updateLightTaskQuartz(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());
+ }
+ }
+ String content = "{浠诲姟ID锛�" + taskId
+ + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+ + "}锛寋鍐呭抚鎸囦护" + lightTask.getFramePayload()
+ + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString()
+ + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress()
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "缂栬緫璺伅浠诲姟", content);
+ /**
+ * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
List<Long> poleIdList = param.getPoleIdList();
if (CollectionUtil.isNotEmpty(poleIdList)) {
- List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList,lightTask.getFramePayload());
+ List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress());
lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
// 娣诲姞缁戝畾鐏潌
@@ -148,6 +199,19 @@
// 涓�涓伅鏉嗗彧鑳戒娇鐢ㄤ竴涓换鍔★紝鏂颁换鍔¤瑕嗙洊鏃т换鍔�
lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
+
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+
+ String content1 = "{浠诲姟ID锛�" + lightTask.getTaskId()
+ + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+ + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString()
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+ /**
+ * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
}
return true;
@@ -160,25 +224,29 @@
* @param deviceCode 璁惧鍚�
* @return 杩斿洖甯�
*/
- public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) {
- IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload))
+ 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);
return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null);
}
- public List<LightTaskDto> listLightTask(int pageNo, int pageSize, String keyword) {
+ public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, 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);
+ //涓嶆槸瓒呯闇�瑕佺瓫閫�
+ if (SecurityUtils.getClientId() != null) {
+ wrapper.eq(LightTask::getClientId, SecurityUtils.getUserId()).or(w -> {
+ w.eq(LightTask::getUserId, SecurityUtils.getUserId());
+ });
}
- PageHelper.startPage(pageNo, pageSize);
+ if (conditionVO != null) {
+ PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize());
+ }
List<LightTask> list = list(wrapper);
Page<LightTaskDto> page = new Page<>();
@@ -192,9 +260,28 @@
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;
+ }
+
// 姣忎釜璺伅鍙戦�佹帶鍒跺抚 杩斿洖鍏宠仈鍒楄〃
- private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList,String framePayload) {
+ private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload, String lightAddress) {
List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>();
List<Pole> poles = poleService.listByIds(poleIdList);
@@ -203,17 +290,21 @@
}
for (Pole pole : poles) {
- // rrpc 鍙戠敓瀹氭椂鍛戒护
- A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode());
-
LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation();
lightTaskPoleRelation.setPoleId(pole.getId());
lightTaskPoleRelation.setTaskId(lightTask.getTaskId());
- if (a5LightTimerRespInnerFrame == null) {
- lightTaskPoleRelation.setIssueStatus(IssueStatusEnums.OTHER_ERROR.getCode());
- } else {
- lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus()));
+ // 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;
@@ -231,16 +322,26 @@
throw new BusinessException("鍒犻櫎浠诲姟澶辫触");
}
+ boolean del;
// 鍒犻櫎缁戝畾鐏潌
- if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList))) {
- throw new BusinessException("鍒犻櫎缁戝畾鐏潌澶辫触");
- }
-
-// // 鍒犻櫎瀹氭椂鍣�
-// if (!lightTaskQuartzService.removeLightTaskQuartz(taskIdList)) {
-// throw new BusinessException("鍒犻櫎瀹氭椂鍣ㄥけ璐�");
+// if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).notIn(LightTaskPoleRelation::getTaskId, taskIdList))) {
+// throw new BusinessException("鏈壘鍒颁换鍔�/鐏潌缁戝畾鍏崇郴");
// }
+// lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList));
+ taskIdList.forEach(
+ taskId -> {
+ lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, taskId));
+ }
+ );
+ /**
+ * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍寮�濮�
+ */
+ String content = "{鎺х伅浠诲姟id锛�" + taskIdList + " }";
+ StoreOperationRecordsUtils.storeOperationData(null, null, "鍒犻櫎鎺х伅浠诲姟", content);
+ /**
+ * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍缁撴潫
+ */
return true;
}
@@ -306,9 +407,6 @@
/**
* 涓嬪彂鍗曚釜鐏潌鐨勪换鍔�
- *
- * @param param
- * @return
*/
public boolean issueLightTask(LightTaskIssueParam param) {
LightTask lightTask = getById(param.getTaskId());
@@ -316,12 +414,33 @@
throw new BusinessException("鎵句笉鍒颁换鍔�");
}
String framePayload = buildControlFramePayload(lightTask.getOpenOrder(), lightTask.getCloseOrder(), lightTask.getControlOrder(), lightTask.getWeek());
- List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()),framePayload);
+ 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;
}
}
--
Gitblit v1.9.3