From 3b8877b6d8c13e37f8c7769282a2751b0faeb499 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期一, 16 五月 2022 18:30:54 +0800
Subject: [PATCH] 日志
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 151 insertions(+), 15 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 d17178b..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,6 +27,7 @@
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;
@@ -43,6 +46,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* @author chenjiantian
@@ -56,6 +60,7 @@
private final PoleService poleService;
private final LightTaskPoleRelationService lightTaskPoleRelationService;
+ private final LightTaskMapper lightTaskMapper;
/**
* 鏂板璺伅浠诲姟
@@ -73,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());
@@ -82,10 +88,32 @@
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)) {
@@ -94,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;
}
@@ -116,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));
@@ -123,10 +165,31 @@
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()));
// 娣诲姞缁戝畾鐏潌
@@ -136,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;
@@ -148,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<>();
@@ -180,8 +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);
@@ -195,7 +295,7 @@
lightTaskPoleRelation.setTaskId(lightTask.getTaskId());
// rrpc 鍙戠敓瀹氭椂鍛戒护
try {
- A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode());
+ A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress);
if (a5LightTimerRespInnerFrame == null) {
lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
} else {
@@ -222,11 +322,26 @@
throw new BusinessException("鍒犻櫎浠诲姟澶辫触");
}
+ boolean del;
// 鍒犻櫎缁戝畾鐏潌
- if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, 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;
}
@@ -299,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