|
@@ -0,0 +1,443 @@
|
|
|
+
|
|
|
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
|
+ * Licensed under the Apache License,Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http:
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+package com.example.distschedule.service;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.distschedule.dao.mapper.ScheduleMapper;
|
|
|
+import com.example.distschedule.dao.model.Schedule;
|
|
|
+import com.example.distschedule.dao.model.UserSchedule;
|
|
|
+import com.example.distschedule.dto.CreateScheduleDto;
|
|
|
+import com.example.distschedule.dto.DeviceDto;
|
|
|
+import com.example.distschedule.dto.DeviceTypeDto;
|
|
|
+import com.example.distschedule.dto.ScheduleDto;
|
|
|
+import com.example.distschedule.enums.ScheduleComandType;
|
|
|
+import com.example.distschedule.error.ErrorCode;
|
|
|
+import com.example.distschedule.exception.DistscheduleScheduleException;
|
|
|
+import com.huaweicloud.sdk.core.exception.ConnectionException;
|
|
|
+import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
|
|
|
+import com.huaweicloud.sdk.core.exception.ServiceResponseException;
|
|
|
+import com.huaweicloud.sdk.iotda.v5.model.CreateCommandRequest;
|
|
|
+import com.huaweicloud.sdk.iotda.v5.model.CreateCommandResponse;
|
|
|
+import com.huaweicloud.sdk.iotda.v5.model.DeviceCommandRequest;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ScheduleService {
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(ScheduleService.class);
|
|
|
+ @Autowired
|
|
|
+ private IOTCloudService iotCloudService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceService deviceService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceTypeService deviceTypeService;
|
|
|
+ @Autowired
|
|
|
+ private ScheduleMapper scheduleMapper;
|
|
|
+
|
|
|
+ public Optional<ScheduleDto> getScheduleById(String scheduleId) {
|
|
|
+ Schedule schedule = scheduleMapper.selectScheduleById(scheduleId);
|
|
|
+
|
|
|
+ if (schedule != null) {
|
|
|
+ return Optional.of(new ScheduleDto(schedule));
|
|
|
+ }
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = DistscheduleScheduleException.class)
|
|
|
+ public String saveSchedule(CreateScheduleDto createScheduleDto) throws DistscheduleScheduleException {
|
|
|
+ Schedule schedule = new Schedule();
|
|
|
+ schedule.setId(UUID.randomUUID().toString());
|
|
|
+ schedule.setName(createScheduleDto.getName());
|
|
|
+ schedule.setDeviceConfig(createScheduleDto.getDeviceConfig());
|
|
|
+ schedule.setRemindDay(createScheduleDto.getRemindDay());
|
|
|
+ schedule.setCreatorId(createScheduleDto.getCreatorId());
|
|
|
+ schedule.setSceneId("default");
|
|
|
+ schedule.setStateDetail(createScheduleDto.getStateDetail());
|
|
|
+ schedule.setStartTime(createScheduleDto.getStartTime());
|
|
|
+ schedule.setEndTime(createScheduleDto.getEndTime());
|
|
|
+ schedule.setUserIds(createScheduleDto.getUserIds());
|
|
|
+
|
|
|
+ int res = scheduleMapper.saveSchedule(schedule);
|
|
|
+ if (res == 0) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<UserSchedule> userSchedules = new LinkedList<>();
|
|
|
+ if (StringUtils.isNotBlank(createScheduleDto.getUserIds())) {
|
|
|
+ String[] userIds = createScheduleDto.getUserIds().split(",");
|
|
|
+ for (String userId : userIds) {
|
|
|
+ userSchedules.add(new UserSchedule(userId, schedule.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = scheduleMapper.saveUserSchedule(userSchedules);
|
|
|
+ if (res == 0) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.SCHEDULE_USER_SAVE_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(createScheduleDto.getDeviceConfig())) {
|
|
|
+ JSONArray deviceJsonArray = JSON.parseArray(createScheduleDto.getDeviceConfig());
|
|
|
+
|
|
|
+ for (Iterator<Object> iterator = deviceJsonArray.iterator(); iterator.hasNext(); ) {
|
|
|
+ JSONObject next = (JSONObject) iterator.next();
|
|
|
+ try {
|
|
|
+ sendScheduleComand(next.getString("deviceId"), ScheduleComandType.A, schedule, next.getJSONObject("command"));
|
|
|
+ } catch (DistscheduleScheduleException e) {
|
|
|
+ LOGGER.warn("Fail to send iot command for device " + next.getString("deviceId"), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sendChildWatchSchedule(ScheduleComandType.A, schedule);
|
|
|
+
|
|
|
+ return schedule.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 给儿童手表发送日程
|
|
|
+ *
|
|
|
+ * @param deviceId 设备ID
|
|
|
+ * @param scheduleComandType 命令类型
|
|
|
+ * @param schedule 日程信息
|
|
|
+ */
|
|
|
+ private void sendChildWatchScheduleComand(String deviceId, ScheduleComandType scheduleComandType, Schedule schedule) throws DistscheduleScheduleException {
|
|
|
+ CreateCommandRequest request = new CreateCommandRequest();
|
|
|
+ DeviceCommandRequest body = new DeviceCommandRequest();
|
|
|
+ body.setCommandName("SetSchedule");
|
|
|
+ Optional<DeviceDto> deviceDto = deviceService.getDeviceById(deviceId);
|
|
|
+ if (!deviceDto.isPresent()) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.DEVICE_NOT_FOUND);
|
|
|
+ }
|
|
|
+ Optional<DeviceTypeDto> deviceTypeDto = deviceTypeService.getDeviceTypeById(deviceDto.get().getTypeId());
|
|
|
+ if (!deviceTypeDto.isPresent()) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.DEVICE_TYPE_NOT_EXIST_FAIL);
|
|
|
+ }
|
|
|
+ body.setServiceId(deviceTypeDto.get().getServiceId());
|
|
|
+ try {
|
|
|
+
|
|
|
+ {
|
|
|
+ "service_id":"SmartWatch",
|
|
|
+ "command_name":"SetSchedule",
|
|
|
+ "paras":{
|
|
|
+ "ScheduleID":"0",
|
|
|
+ "option":"A",
|
|
|
+ "Day":"1,2,3,4,5,6,7",
|
|
|
+ "StartHour":11,
|
|
|
+ "StartMinute":59,
|
|
|
+ "Command":{"MessageType":1},
|
|
|
+ "DurationMinutes":5
|
|
|
+ }int
|
|
|
+}
|
|
|
+ */
|
|
|
+ JSONObject paras = new JSONObject();
|
|
|
+ paras.put("ScheduleID", schedule.getId());
|
|
|
+ paras.put("Option", scheduleComandType.name());
|
|
|
+ if (schedule.getStartTime() != null && schedule.getEndTime() != null) {
|
|
|
+ Calendar startCalendar = Calendar.getInstance();
|
|
|
+ startCalendar.setTime(schedule.getStartTime());
|
|
|
+ paras.put("StartHour", startCalendar.get(Calendar.HOUR_OF_DAY));
|
|
|
+ paras.put("StartMinute", startCalendar.get(Calendar.MINUTE));
|
|
|
+ paras.put("DurationMinutes", (schedule.getEndTime().getTime() - schedule.getStartTime().getTime()) / 1000 / 60);
|
|
|
+ } else {
|
|
|
+ paras.put("StartHour", 0);
|
|
|
+ paras.put("StartMinute", 0);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(schedule.getRemindDay())) {
|
|
|
+ paras.put("Day", schedule.getRemindDay());
|
|
|
+ } else {
|
|
|
+ paras.put("Day", "0");
|
|
|
+ }
|
|
|
+ JSONObject command = new JSONObject();
|
|
|
+ command.put("name", schedule.getName());
|
|
|
+ paras.put("Command", command);
|
|
|
+ body.setParas(paras);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error(e.getMessage());
|
|
|
+ throw new DistscheduleScheduleException("Invalid command value", ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ request.setDeviceId(deviceId);
|
|
|
+ request.setBody(body);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ CreateCommandResponse response = iotCloudService.getIoTDAClient().createCommand(request);
|
|
|
+ LOGGER.info("createCommand response= " + response.toString());
|
|
|
+ } catch (ConnectionException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ } catch (RequestTimeoutException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ } catch (ServiceResponseException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 发送定时命令
|
|
|
+ *
|
|
|
+ * @param deviceId 设备ID
|
|
|
+ * @param commandType 命令类型
|
|
|
+ * @param schedule 日程
|
|
|
+ */
|
|
|
+ private void sendScheduleComand(String deviceId, ScheduleComandType commandType, Schedule schedule, JSONObject command) throws DistscheduleScheduleException {
|
|
|
+
|
|
|
+ CreateCommandRequest request = new CreateCommandRequest();
|
|
|
+ DeviceCommandRequest body = new DeviceCommandRequest();
|
|
|
+ body.setCommandName("SetSchedule");
|
|
|
+ Optional<DeviceDto> deviceDto = deviceService.getDeviceById(deviceId);
|
|
|
+ if (!deviceDto.isPresent()) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.DEVICE_NOT_FOUND);
|
|
|
+ }
|
|
|
+ Optional<DeviceTypeDto> deviceTypeDto = deviceTypeService.getDeviceTypeById(deviceDto.get().getTypeId());
|
|
|
+ if (!deviceTypeDto.isPresent()) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.DEVICE_TYPE_NOT_EXIST_FAIL);
|
|
|
+ }
|
|
|
+ body.setServiceId(deviceTypeDto.get().getServiceId());
|
|
|
+ try {
|
|
|
+
|
|
|
+ {
|
|
|
+ "service_id": "SmartLamp",
|
|
|
+ "command_name": "SetLampShedule",
|
|
|
+ "paras":
|
|
|
+ {
|
|
|
+ "ScheduleID":0
|
|
|
+ "option":"A"
|
|
|
+ "Day": "1,3,5",
|
|
|
+
|
|
|
+ "StartHour": 18,
|
|
|
+ "StartMinute": 12,
|
|
|
+ "DurationMinutes": 1
|
|
|
+ }
|
|
|
+}
|
|
|
+ */
|
|
|
+ JSONObject paras = new JSONObject();
|
|
|
+ paras.put("ScheduleID", schedule.getId());
|
|
|
+ paras.put("Option", commandType.name());
|
|
|
+ if (schedule.getStartTime() != null && schedule.getEndTime() != null) {
|
|
|
+ Calendar startCalendar = Calendar.getInstance();
|
|
|
+ startCalendar.setTime(schedule.getStartTime());
|
|
|
+ paras.put("StartHour", startCalendar.get(Calendar.HOUR_OF_DAY));
|
|
|
+ paras.put("StartMinute", startCalendar.get(Calendar.MINUTE));
|
|
|
+ paras.put("DurationMinutes", (schedule.getEndTime().getTime() - schedule.getStartTime().getTime()) / 1000 / 60);
|
|
|
+ } else {
|
|
|
+ paras.put("StartHour", 0);
|
|
|
+ paras.put("StartMinute", 0);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(schedule.getRemindDay())) {
|
|
|
+ paras.put("Day", schedule.getRemindDay());
|
|
|
+ } else {
|
|
|
+ paras.put("Day", "0");
|
|
|
+ }
|
|
|
+ paras.put("Command", command);
|
|
|
+ body.setParas(paras);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error(e.getMessage());
|
|
|
+ throw new DistscheduleScheduleException("Invalid command value", ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ request.setDeviceId(deviceId);
|
|
|
+ request.setBody(body);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ CreateCommandResponse response = iotCloudService.getIoTDAClient().createCommand(request);
|
|
|
+ LOGGER.info("createCommand response= " + response.toString());
|
|
|
+ } catch (ConnectionException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ } catch (RequestTimeoutException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ } catch (ServiceResponseException e) {
|
|
|
+ throw new DistscheduleScheduleException(e.getMessage(), ErrorCode.SCHEDULE_SEND_COMMAND_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = DistscheduleScheduleException.class)
|
|
|
+ public int deleteSchedule(String userId, String scheduleId) throws DistscheduleScheduleException {
|
|
|
+
|
|
|
+ Schedule schedule = scheduleMapper.selectScheduleById(scheduleId);
|
|
|
+ if (schedule == null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.equals(schedule.getCreatorId(), userId)) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.ILLEGAL_PERMISSION);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ scheduleMapper.deleteUserSchedule(scheduleId);
|
|
|
+ int res = scheduleMapper.deleteSchedule(scheduleId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(schedule.getDeviceConfig())) {
|
|
|
+ JSONArray deviceJsonArray = JSON.parseArray(schedule.getDeviceConfig());
|
|
|
+
|
|
|
+ for (Iterator<Object> iterator = deviceJsonArray.iterator(); iterator.hasNext(); ) {
|
|
|
+ JSONObject next = (JSONObject) iterator.next();
|
|
|
+ try {
|
|
|
+ sendScheduleComand(next.getString("deviceId"), ScheduleComandType.D, schedule, new JSONObject());
|
|
|
+ } catch (DistscheduleScheduleException e) {
|
|
|
+ LOGGER.error(e.getMessage(), e);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sendChildWatchSchedule(ScheduleComandType.D, schedule);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int updateSchedule(String userId, String scheduleId, CreateScheduleDto updateScheduleDto) throws DistscheduleScheduleException {
|
|
|
+ Schedule schedule = scheduleMapper.selectScheduleById(scheduleId);
|
|
|
+ if (schedule == null) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.SCHEDULE_NOT_FOUND);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.equals(schedule.getCreatorId(), userId)) {
|
|
|
+ throw new DistscheduleScheduleException(ErrorCode.ILLEGAL_PERMISSION);
|
|
|
+ }
|
|
|
+
|
|
|
+ schedule.setName(updateScheduleDto.getName());
|
|
|
+ schedule.setDeviceConfig(updateScheduleDto.getDeviceConfig());
|
|
|
+ schedule.setRemindDay(updateScheduleDto.getRemindDay());
|
|
|
+
|
|
|
+
|
|
|
+ schedule.setStateDetail(updateScheduleDto.getStateDetail());
|
|
|
+ schedule.setStartTime(updateScheduleDto.getStartTime());
|
|
|
+ schedule.setEndTime(updateScheduleDto.getEndTime());
|
|
|
+
|
|
|
+
|
|
|
+ scheduleMapper.deleteUserSchedule(scheduleId);
|
|
|
+ List<UserSchedule> userSchedules = new LinkedList<>();
|
|
|
+ if (StringUtils.isNotBlank(updateScheduleDto.getUserIds())) {
|
|
|
+ String[] userIds = updateScheduleDto.getUserIds().split(",");
|
|
|
+ for (String scheduleUserId : userIds) {
|
|
|
+ userSchedules.add(new UserSchedule(scheduleUserId, schedule.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ scheduleMapper.saveUserSchedule(userSchedules);
|
|
|
+ int res = scheduleMapper.updateSchedule(schedule);
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(updateScheduleDto.getDeviceConfig())) {
|
|
|
+ JSONArray deviceJsonArray = JSON.parseArray(updateScheduleDto.getDeviceConfig());
|
|
|
+
|
|
|
+ for (Iterator<Object> iterator = deviceJsonArray.iterator(); iterator.hasNext(); ) {
|
|
|
+ JSONObject next = (JSONObject) iterator.next();
|
|
|
+ try {
|
|
|
+ sendScheduleComand(next.getString("deviceId"), ScheduleComandType.U, schedule, next.getJSONObject("command"));
|
|
|
+ } catch (DistscheduleScheduleException e) {
|
|
|
+ LOGGER.error(e.getMessage(), e);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sendChildWatchSchedule(ScheduleComandType.U, schedule);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ScheduleDto> queryScheduleByUser(String userId, Date startTime, Date endTime) {
|
|
|
+ List<ScheduleDto> scheduleDtos = new LinkedList<>();
|
|
|
+
|
|
|
+ List<Schedule> defaultSchedules = scheduleMapper.selectDefaultSchedulesByDatesAndUser(userId, startTime, endTime);
|
|
|
+ for (Schedule defaultSchedule : defaultSchedules) {
|
|
|
+ ScheduleDto scheduleDto = new ScheduleDto(defaultSchedule);
|
|
|
+ scheduleDtos.add(scheduleDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Schedule> noDefaultSchedules = scheduleMapper.selectNotDefaultSchedulesByUser(userId);
|
|
|
+ for (Schedule noDefaultSchedule : noDefaultSchedules) {
|
|
|
+ ScheduleDto scheduleDto = new ScheduleDto(noDefaultSchedule);
|
|
|
+ scheduleDtos.add(scheduleDto);
|
|
|
+ }
|
|
|
+ Collections.sort(scheduleDtos);
|
|
|
+ return scheduleDtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ScheduleDto> searchSchedulesByName(String userId, String name) {
|
|
|
+
|
|
|
+ Calendar calendarStartTime = Calendar.getInstance();
|
|
|
+ calendarStartTime.setTime(new Date());
|
|
|
+ calendarStartTime.add(Calendar.DATE, -30);
|
|
|
+
|
|
|
+ Calendar calendarEndTime = Calendar.getInstance();
|
|
|
+ calendarEndTime.setTime(new Date());
|
|
|
+ calendarEndTime.add(Calendar.DATE, +30);
|
|
|
+
|
|
|
+ List<ScheduleDto> scheduleDtos = new LinkedList<>();
|
|
|
+
|
|
|
+ List<Schedule> defaultSchedules = scheduleMapper.searchDefaultSchedulesByName(userId, calendarStartTime.getTime(), calendarEndTime.getTime(), name);
|
|
|
+ for (Schedule defaultSchedule : defaultSchedules) {
|
|
|
+ ScheduleDto scheduleDto = new ScheduleDto(defaultSchedule);
|
|
|
+ scheduleDtos.add(scheduleDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Schedule> noDefaultSchedules = scheduleMapper.searchNotDefaultSchedulesByName(userId, name);
|
|
|
+ for (Schedule noDefaultSchedule : noDefaultSchedules) {
|
|
|
+ ScheduleDto scheduleDto = new ScheduleDto(noDefaultSchedule);
|
|
|
+ scheduleDtos.add(scheduleDto);
|
|
|
+ }
|
|
|
+ return scheduleDtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteUserAllSchedules(String userId) {
|
|
|
+ scheduleMapper.deleteSchedulesByUserId(userId);
|
|
|
+ scheduleMapper.deleteUserScheduleByUserId(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 给儿童手表发送命令
|
|
|
+ *
|
|
|
+ * @param scheduleComandType 命令类型
|
|
|
+ * @param schedule 日程
|
|
|
+ */
|
|
|
+ private void sendChildWatchSchedule(ScheduleComandType scheduleComandType, Schedule schedule) {
|
|
|
+ if (StringUtils.isNotBlank(schedule.getUserIds())) {
|
|
|
+ String[] userIds = schedule.getUserIds().split(",");
|
|
|
+ for (String userId : userIds) {
|
|
|
+
|
|
|
+ List<DeviceDto> deviceInfos = deviceService.getDevicesByUserId(userId);
|
|
|
+ for (DeviceDto deviceInfo : deviceInfos) {
|
|
|
+ if (deviceInfo.getTypeId() == 12) {
|
|
|
+ try {
|
|
|
+ sendChildWatchScheduleComand(deviceInfo.getId(), scheduleComandType, schedule);
|
|
|
+ } catch (DistscheduleScheduleException e) {
|
|
|
+ LOGGER.warn("Fail to send iot command for device " + deviceInfo.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|