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/PlayPlanNvService.java | 142 +++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 130 insertions(+), 12 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
index 2b57a7a..31ca00f 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
@@ -11,6 +11,8 @@
import com.sandu.ximon.admin.dto.PlanDto;
import com.sandu.ximon.admin.dto.SchedulesDTO;
import com.sandu.ximon.admin.dto.nova.PlayerProgram;
+import com.sandu.ximon.admin.dto.nova.ProgramDto;
+import com.sandu.ximon.admin.dto.nova.ProgramPush;
import com.sandu.ximon.admin.dto.nova.ProgramSchedule;
import com.sandu.ximon.admin.entity.Plans;
import com.sandu.ximon.admin.param.PlayPlanParam;
@@ -22,18 +24,12 @@
import com.sandu.ximon.admin.vo.NovaOpenVO;
import com.sandu.ximon.admin.vo.NovaPushResultVO;
import com.sandu.ximon.admin.vo.PlansVO;
-import com.sandu.ximon.dao.domain.LEDProgram;
-import com.sandu.ximon.dao.domain.LedPlayerEntity;
-import com.sandu.ximon.dao.domain.PlayPlanNv;
-import com.sandu.ximon.dao.domain.PushToLed;
+import com.sandu.ximon.dao.domain.*;
import com.sandu.ximon.dao.mapper.PlayPlanNvMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* 鎾斁璁″垝
@@ -48,6 +44,7 @@
private VnnoxAPIUtil vnnoxAPIUtil;
private final LEDProgramService ledProgramService;
private final ClientService clientService;
+ private final LEDProgramFileService fileService;
public boolean addPlan(PlayPlanParam playPlanParam) {
@@ -131,7 +128,7 @@
+ playPlan.getName()
+ "锛� 鎾斁璁″垝璁″垝鍐呭锛�"
+ JSON.toJSONString(playPlan)
- + "锛� 瀹氭椂浠诲姟鍐呭锛�" + playPlan.getSchedule()
+ + "锛� 瀹氭椂浠诲姟鍐呭锛�" + playPlan.getSchedules()
+ "}," + " 鎺ㄩ�佺粨鏋滐細" + save
+ " }";
if (playPlanParam.getId() == null) {
@@ -172,7 +169,13 @@
}
public Map<String, Object> pushToLed(Long planId, List<NovaPushResultVO> nova) {
+ if (nova == null) {
+ throw new BusinessException("璇烽�夋嫨姝g‘鐨凩ED灞�");
+ }
PushToLed pushToLed = playPlanMapper.pushToLed(planId);
+ if (pushToLed.getPages() == null) {
+ throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+ }
PlayPlanNv byId = getById(planId);
if (pushToLed == null) {
throw new BusinessException("鏈壘鍒拌鎾斁璁″垝");
@@ -186,8 +189,26 @@
program.setPlayerIds(playerIds);
//鑾峰彇鑺傜洰瀹炰綋
- program.setPages(JSON.parseObject(pushToLed.getPages(), List.class));
+
+ List<ProgramDto> programDtos = JSON.parseArray(pushToLed.getPages(), ProgramDto.class);
+ programDtos.forEach(
+ programDto -> {
+ programDto.getWidgets().forEach(
+ widget -> {
+ String url = widget.getUrl();
+ LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
+ if (one == null) {
+ throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+ }
+ widget.setMd5(one.getMd5());
+ widget.setSize(one.getSize());
+ }
+ );
+ }
+ );
+
+ program.setPages(programDtos);
//鑾峰彇鑺傜洰瀹氭椂瀹炰綋
program.setSchedule((JSON.parseObject(pushToLed.getSchedule(), Map.class)));
@@ -245,7 +266,7 @@
+ "锛� 鑺傜洰鍚嶇О锛�" + byId.getName()
+ "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+ " }";
- StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佸畾鏃朵换鍔�", content);
+ StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佹挱鏀捐鍒�", content);
/**
* 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曠粨鏉�
*/
@@ -313,7 +334,7 @@
+ "锛� 鑺傜洰鍚嶇О锛�" + one.getName()
+ "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+ " }";
- StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佸畾鏃朵换鍔�", content);
+ StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佸畾鏃跺紑鍏冲睆", content);
/**
* 璇虹摝鎺ㄩ�佸畾鏃舵棩蹇楄褰曠粨鏉�
*/
@@ -378,4 +399,101 @@
plan.put("schedules", schedules);
return plan;
}
+
+
+ /**
+ * 鎺ㄩ�佸疄鏃惰妭鐩�
+ *
+ * @param pid
+ * @param nova
+ * @return
+ */
+ public Map<String, Object> pushProgram(Long pid, List<NovaPushResultVO> nova) {
+ LEDProgram ledProgram = ledProgramService.getById(pid);
+ if (ledProgram == null) {
+ throw new BusinessException("鏈壘鍒拌妭鐩�");
+ }
+ if (ledProgram.getPages() == null) {
+ throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+ }
+ if (SecurityUtils.getClientId() != null && !Objects.equals(ledProgram.getClientId(), SecurityUtils.getUserId()) && !Objects.equals(ledProgram.getClientId(), SecurityUtils.getClientId())) {
+ throw new BusinessException("璇蜂笉瑕佹搷浣滃叾浠栦汉鐨勮妭鐩�");
+ }
+ String pages = ledProgram.getPages();
+ List<String> playerIds = new ArrayList<>();
+ nova.forEach(n -> {
+ playerIds.add(n.getPlayerId());
+ });
+
+ ProgramPush program = new ProgramPush();
+ List<ProgramDto> programDtos = JSON.parseArray(pages, ProgramDto.class);
+ programDtos.forEach(
+ programDto -> {
+ programDto.getWidgets().forEach(
+ widget -> {
+ String url = widget.getUrl();
+ LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url));
+ if (one == null) {
+ throw new BusinessException("鑺傜洰鏂囦欢宸插け鏁�");
+ }
+ widget.setMd5(one.getMd5());
+ widget.setSize(one.getSize());
+ }
+ );
+ }
+ );
+
+ program.setPlayerIds(playerIds);
+ //鑾峰彇鑺傜洰瀹炰綋
+ program.setPages(programDtos);
+
+ program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
+ VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.pushProgram(program);
+
+ List<String> success = new ArrayList<>();
+ List<String> fail = new ArrayList<>();
+ if (vnnoxResultResponse.getData() != null) {
+ success = vnnoxResultResponse.getData().getSuccess();
+ fail = vnnoxResultResponse.getData().getFail();
+ }
+
+ //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+ Map<String, Object> result = new HashMap<>();
+ List<NovaPushResultVO> successList = new ArrayList<>();
+ List<NovaPushResultVO> faileList = new ArrayList<>();
+ List<String> finalSuccess = success;
+ List<String> finalFail = fail;
+ nova.forEach(n -> {
+ if (finalSuccess.contains(n.getPlayerId())) {
+ successList.add(n);
+ } else if (finalFail.contains(n.getPlayerId())) {
+ faileList.add(n);
+ }
+ });
+
+ result.put("success", successList);
+ result.put("fail", faileList);
+
+ /**
+ * 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曞紑濮�
+ */
+ List<LedPlayerEntity> list = SpringContextHolder.getBean(LedPlayerEntityService.class)
+ .list(Wrappers.lambdaQuery(LedPlayerEntity.class).in(LedPlayerEntity::getId, nova.stream().map(NovaPushResultVO::getPlayerId).toArray()));
+ List<String> listCode = new ArrayList<>();
+ for (LedPlayerEntity temp : list) {
+ listCode.add(temp.getSn());
+ }
+
+ String content = "{鑺傜洰ID锛�" + pid
+ + "锛� 鑺傜洰鍚嶇О锛�" + ledProgram.getName()
+ + "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佽妭鐩�", content);
+ /**
+ * 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曠粨鏉�
+ */
+
+ return result;
+ }
+
}
--
Gitblit v1.9.3