From dda268997ca8f8a364f7c19b45d7a43a50a98efe Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期二, 25 十月 2022 18:00:11 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java | 407 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 338 insertions(+), 69 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 94f8bbd..1eeb4e2 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
@@ -1,33 +1,34 @@
package com.sandu.ximon.admin.service;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.dto.PlanDto;
import com.sandu.ximon.admin.dto.SchedulesDTO;
+import com.sandu.ximon.admin.dto.nova.*;
import com.sandu.ximon.admin.param.PlayPlanParam;
import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.LogUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
import com.sandu.ximon.admin.utils.VnnoxProgramAPIUtil;
-import com.sandu.ximon.admin.dto.nova.PlayerProgram;
-import com.sandu.ximon.admin.utils.response.VnnoxResult;
import com.sandu.ximon.admin.utils.response.VnnoxResultResponse;
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.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.*;
+import java.util.stream.Collectors;
/**
* 鎾斁璁″垝
@@ -42,6 +43,7 @@
private VnnoxAPIUtil vnnoxAPIUtil;
private final LEDProgramService ledProgramService;
private final ClientService clientService;
+ private final LEDProgramFileService fileService;
public boolean addPlan(PlayPlanParam playPlanParam) {
@@ -70,21 +72,14 @@
String s = JSON.toJSONString(schedule.get("plans"));
List<PlanDto> plans = JSON.parseArray(s, PlanDto.class);
- System.out.println(plans.toString()+"plans");
+ System.out.println(plans.toString() + "plans");
// List<PlanDto> plans = (List<PlanDto>) schedule.get("plans");
List<SchedulesDTO> schedulesDTOS = new ArrayList<>();
for (int i = 0; i < plans.size(); i++) {
SchedulesDTO openDto = new SchedulesDTO();
-// if (i % 2 == 0) {
-// schedulesDTO.setExecTime(plans.get(i).getStartTime());
-// schedulesDTO.setStatus("OPEN");
-// } else {
-// schedulesDTO.setWeekDays(plans.get(i).getWeekDays());
-// schedulesDTO.setExecTime(plans.get(i).getEndTime());
-// schedulesDTO.setStatus("CLOSE");
-// }
+
SchedulesDTO closeDto = new SchedulesDTO();
@@ -92,6 +87,19 @@
openDto.setEndDate(schedule.get("endDate").toString());
openDto.setExecTime(plans.get(i).getStartTime());
openDto.setStatus("OPEN");
+
+ /**
+ * 鍒ゆ柇鏃堕棿鐨勫厛鍚�
+ */
+ String startTime = openDto.getStartDate() + " " + plans.get(i).getStartTime();
+ String endTime = openDto.getEndDate() + " " + plans.get(i).getEndTime();
+
+ //杞崲鎴愭椂闂存埑
+ long startTimeStamp = DateUtil.parse(startTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
+ long endTimeStamp = DateUtil.parse(endTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
+ if (startTimeStamp > endTimeStamp) {
+ throw new BusinessException("寮�濮嬫椂闂翠笉鑳藉ぇ浜庣粨鏉熸椂闂�");
+ }
closeDto.setStartDate(schedule.get("startDate").toString());
closeDto.setEndDate(schedule.get("endDate").toString());
@@ -109,8 +117,29 @@
playPlan.setEndTime(playPlanParam.getEndTime());
// BeanUtils.copyProperties(playPlanParam, playPlan);
+ /**
+ * 璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板鏃ュ織璁板綍寮�濮�
+ */
+ boolean save = save(playPlan);
+ String content = "{鎾斁璁″垝锛�" + playPlan.getId()
+ + "锛� 鑺傜洰鍚嶇О锛�" + byId.getName()
+ + "锛� 鎾斁璁″垝璁″垝鍚嶇О锛�"
+ + playPlan.getName()
+ + "锛� 鎾斁璁″垝璁″垝鍐呭锛�"
+ + JSON.toJSONString(playPlan)
+ + "锛� 瀹氭椂浠诲姟鍐呭锛�" + playPlan.getSchedules()
+ + "}," + " 鎺ㄩ�佺粨鏋滐細" + save
+ + " }";
+ if (playPlanParam.getId() == null) {
+ StoreOperationRecordsUtils.storeOperationData(null, null, "璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板", content);
+ } else {
+ StoreOperationRecordsUtils.storeOperationData(null, null, "璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝淇敼", content);
+ }
+ /**
+ * 璇虹摝瀹氭椂浠诲姟/鎾斁璁″垝鏂板鏃ュ織璁板綍缁撴潫
+ */
- return save(playPlan);
+ return save;
}
@@ -119,7 +148,8 @@
if (byId == null) {
throw new BusinessException("鎿嶄綔瀵硅薄涓嶅瓨鍦�");
}
- if(removeById(id)){
+ if (removeById(id)) {
+ playPlanParam.setId(id);
return addPlan(playPlanParam);
}
@@ -137,70 +167,192 @@
return removeByIds(ids);
}
+ /**
+ * 鎺ㄩ�佸畾鏃惰妭鐩�
+ *
+ * @param planId
+ * @param nova
+ * @return
+ */
public Map<String, Object> pushToLed(Long planId, List<NovaPushResultVO> nova) {
-// public PlayerProgram pushToLed(Long planId){
+ if (nova == null) {
+ throw new BusinessException("璇烽�夋嫨姝g‘鐨凩ED灞�");
+ }
PushToLed pushToLed = playPlanMapper.pushToLed(planId);
- PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
+ if (pushToLed.getPages() == null) {
+ throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+ }
+ PlayPlanNv byId = getById(planId);
if (pushToLed == null) {
throw new BusinessException("鏈壘鍒拌鎾斁璁″垝");
}
- List<String> playerIds=new ArrayList<>();
- nova.forEach(
- n->{
- playerIds.add(n.getPlayerId());
- }
- );
-
- PlayerProgram program = new PlayerProgram();
- program.setPlayerIds(playerIds);
- System.out.println(pushToLed.getPages());
-
- //鑾峰彇鑺傜洰瀹炰綋
- program.setPages(JSON.parseObject(pushToLed.getPages(), List.class));
-
-
- //鑾峰彇鑺傜洰瀹氭椂瀹炰綋
- program.setSchedules((JSON.parseObject(pushToLed.getSchedules(), Map.class)));
- //鑾峰彇瀹氭椂寮�鍏冲睆骞�
-// program.setSchedules((JSON.parseArray(pushToLed.getSchedule(), SchedulesDTO.class)));
-
-
- // Map map = JSON.parseObject(pushToLed.getSchedule(), Map.class);
-
- program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
-// VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(program);
- VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
- VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(one.getVolume()).intValue());
-
+ List<String> playerIds = new ArrayList<>();
+ nova.forEach(n -> {
+ playerIds.add(n.getPlayerId());
+ });
List<String> success = new ArrayList<>();
List<String> fail = new ArrayList<>();
- if (vnnoxResultResponse.getData() != null) {
- success = vnnoxResultResponse.getData().getSuccess();
- fail = vnnoxResultResponse.getData().getFail();
- }
-
- // fail.addAll(vnnoxResult.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);
- }
- }
- );
+
+ List<List<String>> split = CollectionUtil.split(playerIds, 100);
+ for (List<String> playIds : split) {
+ PlayerProgram program = new PlayerProgram();
+ program.setPlayerIds(playIds);
+
+ //鑾峰彇鑺傜洰瀹炰綋
+
+ List<PlayerPage> programDtos = JSON.parseArray(pushToLed.getPages(), PlayerPage.class);
+ programDtos.forEach(
+ programDto -> {
+ programDto.getWidgets().forEach(
+ widget -> {
+ if (PlayerWidgetType.PICTURE.equals(widget.getType()) || PlayerWidgetType.VIDEO.equals(widget.getType())) {
+ 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(Long.parseLong(one.getSize()));
+ }
+ }
+ );
+ }
+ );
+
+ program.setPages(programDtos);
+
+ //鑾峰彇鑺傜洰瀹氭椂瀹炰綋
+ PlayerSchedule playerSchedule = JSON.parseObject(pushToLed.getSchedule(), PlayerSchedule.class);
+ //鍒犻櫎鏃堕棿鐨勫悗涓変綅
+ List<PlayerSchedulePlans> plans = playerSchedule.getPlans();
+ plans.forEach(
+ plan -> {
+ plan.setStartTime(plan.getStartTime().substring(0, plan.getStartTime().length() - 3));
+ plan.setEndTime(plan.getEndTime().substring(0, plan.getEndTime().length() - 3));
+ }
+ );
+ program.setSchedule(playerSchedule);
+
+
+ program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
+ LogUtils.error("鑺傜洰鍐呭+++++++++++" + JSON.toJSONString(program));
+ VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
+ vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue());
+
+
+ if (vnnoxResultResponse.getData() != null) {
+ success = vnnoxResultResponse.getData().getSuccess();
+ fail = vnnoxResultResponse.getData().getFail();
+ }
+
+ 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锛�" + planId
+ + "锛� 鑺傜洰鍚嶇О锛�" + byId.getName()
+ + "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佹挱鏀捐鍒�", content);
+ /**
+ * 璇虹摝鎺ㄩ�佽妭鐩棩蹇楄褰曠粨鏉�
+ */
+
return result;
- // return program;
+ }
+
+
+ //鎺ㄩ�佸畾鏃跺埌LED
+ public Map<String, Object> pushSchedule(Long planId, List<NovaPushResultVO> nova) {
+ PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
+ if (one == null) {
+ throw new BusinessException("鏈壘鍒拌妭鐩�");
+ }
+ List<SchedulesDTO> schedulesDTOS = JSON.parseArray(one.getSchedules(), SchedulesDTO.class);
+
+ List<String> success = new ArrayList<>();
+ List<String> fail = new ArrayList<>();
+ //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+ Map<String, Object> result = new HashMap<>();
+ List<NovaPushResultVO> successList = new ArrayList<>();
+ List<NovaPushResultVO> faileList = new ArrayList<>();
+
+ List<List<String>> split = CollectionUtil.split(nova.stream().map(NovaPushResultVO::getPlayerId).collect(Collectors.toList()), 100);
+ for (List<String> playerIds : split) {
+ //璁剧疆
+ ProgramSchedule programSchedule = new ProgramSchedule();
+ programSchedule.setSchedules(schedulesDTOS);
+ programSchedule.setPlayerIds(playerIds);
+ VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(programSchedule);
+
+
+ if (vnnoxResultResponse.getData() != null) {
+ success = vnnoxResultResponse.getData().getSuccess();
+ fail = vnnoxResultResponse.getData().getFail();
+ }
+ 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锛�" + one.getId()
+ + "锛� 鑺傜洰鍚嶇О锛�" + one.getName()
+ + "}," + " 鎺ㄩ�佺粨鏋滐細" + result
+ + " }";
+ StoreOperationRecordsUtils.storeOperationData(listCode, null, "璇虹摝鎺ㄩ�佸畾鏃跺紑鍏冲睆", content);
+ /**
+ * 璇虹摝鎺ㄩ�佸畾鏃舵棩蹇楄褰曠粨鏉�
+ */
+ return result;
}
/**
@@ -231,6 +383,12 @@
return null;
}
+ /**
+ * 鑾峰彇鎾斁璁″垝
+ *
+ * @param planId
+ * @return
+ */
public Object getByPlanId(Long planId) {
PlayPlanNv byId = getById(planId);
if (byId == null) {
@@ -240,7 +398,8 @@
if (byId1 == null) {
throw new BusinessException("鎵句笉鍒拌鑺傜洰");
}
- List schedule = JSON.parseObject(byId.getSchedule(), List.class);
+ List schedule = JSON.parseObject(byId.getSchedules(), List.class);
+ Map schedules = JSON.parseObject(byId.getSchedule(), Map.class);
List pages = JSON.parseObject(byId1.getPages(), List.class);
Map plan = new HashMap();
plan.put("planId", byId.getId());
@@ -251,6 +410,116 @@
plan.put("preview", byId1.getPreview());
plan.put("pages", pages);
plan.put("schedule", schedule);
+ 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.getUserId(), SecurityUtils.getUserId())) {
+ throw new BusinessException("璇蜂笉瑕佹搷浣滃叾浠栦汉鐨勮妭鐩�");
+ }
+ String pages = ledProgram.getPages();
+
+
+ List<String> success = new ArrayList<>();
+ List<String> fail = new ArrayList<>();
+ //鎷兼帴鎴愬姛澶辫触鐨勭粨鏋�
+ Map<String, Object> result = new HashMap<>();
+ List<NovaPushResultVO> successList = new ArrayList<>();
+ List<NovaPushResultVO> faileList = new ArrayList<>();
+
+
+ List<List<String>> split = CollectionUtil.split(nova.stream().map(NovaPushResultVO::getPlayerId).collect(Collectors.toList()), 100);
+
+ for (List<String> playerIds : split) {
+ PlayerProgram program = new PlayerProgram();
+ List<PlayerPage> programDtos = JSON.parseArray(pages, PlayerPage.class);
+ programDtos.forEach(
+ programDto -> {
+ programDto.getWidgets().forEach(
+ widget -> {
+ if (PlayerWidgetType.PICTURE.equals(widget.getType()) || PlayerWidgetType.VIDEO.equals(widget.getType())) {
+ 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(Long.parseLong(one.getSize()));
+ }
+ }
+ );
+ }
+ );
+ program.setPlayerIds(playerIds);
+ //鑾峰彇鑺傜洰瀹炰綋
+ program.setPages(programDtos);
+
+ program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
+ VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.pushProgram(program);
+
+ if (vnnoxResultResponse == null || vnnoxResultResponse.getData() == null) {
+ throw new BusinessException("鎺ㄩ�佸け璐�");
+ }
+
+
+ if (vnnoxResultResponse.getData() != null) {
+ success = vnnoxResultResponse.getData().getSuccess();
+ fail = vnnoxResultResponse.getData().getFail();
+ }
+
+ 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