|
@@ -1,6 +1,9 @@
|
|
package com.ruoyi.manage.service.impl;
|
|
package com.ruoyi.manage.service.impl;
|
|
|
|
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
|
+import com.ruoyi.common.utils.mqtt.MqttService;
|
|
import com.ruoyi.manage.domain.ParameterSet;
|
|
import com.ruoyi.manage.domain.ParameterSet;
|
|
import com.ruoyi.manage.mapper.ParameterSetMapper;
|
|
import com.ruoyi.manage.mapper.ParameterSetMapper;
|
|
import com.ruoyi.manage.service.IParameterSetService;
|
|
import com.ruoyi.manage.service.IParameterSetService;
|
|
@@ -8,90 +11,153 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
+
|
|
|
|
+import static com.ruoyi.common.constant.Constants.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 参数设置Service业务层处理
|
|
* 参数设置Service业务层处理
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author boman
|
|
* @author boman
|
|
* @date 2025-06-18
|
|
* @date 2025-06-18
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-public class ParameterSetServiceImpl implements IParameterSetService
|
|
|
|
-{
|
|
|
|
|
|
+public class ParameterSetServiceImpl implements IParameterSetService {
|
|
@Autowired
|
|
@Autowired
|
|
private ParameterSetMapper parameterSetMapper;
|
|
private ParameterSetMapper parameterSetMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MqttService mqttService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询参数设置
|
|
* 查询参数设置
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterId 参数设置主键
|
|
* @param parameterId 参数设置主键
|
|
* @return 参数设置
|
|
* @return 参数设置
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ParameterSet selectParameterSetByParameterId(Long parameterId)
|
|
|
|
- {
|
|
|
|
|
|
+ public ParameterSet selectParameterSetByParameterId(Long parameterId) {
|
|
return parameterSetMapper.selectParameterSetByParameterId(parameterId);
|
|
return parameterSetMapper.selectParameterSetByParameterId(parameterId);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询参数设置列表
|
|
* 查询参数设置列表
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterSet 参数设置
|
|
* @param parameterSet 参数设置
|
|
* @return 参数设置
|
|
* @return 参数设置
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<ParameterSet> selectParameterSetList(ParameterSet parameterSet)
|
|
|
|
- {
|
|
|
|
|
|
+ public List<ParameterSet> selectParameterSetList(ParameterSet parameterSet) {
|
|
return parameterSetMapper.selectParameterSetList(parameterSet);
|
|
return parameterSetMapper.selectParameterSetList(parameterSet);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增参数设置
|
|
* 新增参数设置
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterSet 参数设置
|
|
* @param parameterSet 参数设置
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public int insertParameterSet(ParameterSet parameterSet)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult insertParameterSet(ParameterSet parameterSet) {
|
|
|
|
+ Long channelId = parameterSet.getChannelId();
|
|
|
|
+ ParameterSet parameterSetOld = parameterSetMapper.selectParameterSetByChannelId(channelId);
|
|
|
|
+ if (parameterSetOld != null) {
|
|
|
|
+ return AjaxResult.error("当前通道已设置参数,请勿重复新增");
|
|
|
|
+ }
|
|
|
|
+ AjaxResult ajaxResult = checkParameter(parameterSet);
|
|
|
|
+ if (ajaxResult.isError()) {
|
|
|
|
+ return ajaxResult;
|
|
|
|
+ }
|
|
parameterSet.setCreateTime(DateUtils.getNowDate());
|
|
parameterSet.setCreateTime(DateUtils.getNowDate());
|
|
- return parameterSetMapper.insertParameterSet(parameterSet);
|
|
|
|
|
|
+ parameterSetMapper.insertParameterSet(parameterSet);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //校验是否需要下发参数
|
|
|
|
+ public AjaxResult checkParameter(ParameterSet parameterSet) {
|
|
|
|
+ //下发指令
|
|
|
|
+ String channelRange = parameterSet.getChannelRange();
|
|
|
|
+ String leaveTime = parameterSet.getLeaveTime();
|
|
|
|
+ String playTime = parameterSet.getPlayTime();
|
|
|
|
+ String leaveRate = parameterSet.getLeaveRate();
|
|
|
|
+ String playRate = parameterSet.getPlayRate();
|
|
|
|
+ if (StringUtils.isNotEmpty(channelRange)) {
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture<Void> future = mqttService.publish(DETECTION_RECT, channelRange);
|
|
|
|
+ future.get(10, TimeUnit.SECONDS);
|
|
|
|
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
+ return AjaxResult.error("发布消息失败:" + DETECTION_RECT);
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotEmpty(leaveTime)) {
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVETIME, leaveTime);
|
|
|
|
+ future.get(10, TimeUnit.SECONDS);
|
|
|
|
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
+ return AjaxResult.error("发布消息失败:" + DETECTION_LEAVETIME);
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotEmpty(playTime)) {
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYTIME, playTime);
|
|
|
|
+ future.get(10, TimeUnit.SECONDS);
|
|
|
|
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
+ return AjaxResult.error("发布消息失败:" + DETECTION_PLAYTIME);
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotEmpty(leaveRate)) {
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture<Void> future = mqttService.publish(DETECTION_LEAVERATE, leaveRate);
|
|
|
|
+ future.get(10, TimeUnit.SECONDS);
|
|
|
|
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
+ return AjaxResult.error("发布消息失败:" + DETECTION_LEAVERATE);
|
|
|
|
+ }
|
|
|
|
+ } else if (StringUtils.isNotEmpty(playRate)) {
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture<Void> future = mqttService.publish(DETECTION_PLAYRATE, playRate);
|
|
|
|
+ future.get(10, TimeUnit.SECONDS);
|
|
|
|
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
+ return AjaxResult.error("发布消息失败:" + DETECTION_PLAYRATE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 修改参数设置
|
|
* 修改参数设置
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterSet 参数设置
|
|
* @param parameterSet 参数设置
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public int updateParameterSet(ParameterSet parameterSet)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult updateParameterSet(ParameterSet parameterSet) {
|
|
|
|
+ AjaxResult ajaxResult = checkParameter(parameterSet);
|
|
|
|
+ if (ajaxResult.isError()) {
|
|
|
|
+ return ajaxResult;
|
|
|
|
+ }
|
|
parameterSet.setUpdateTime(DateUtils.getNowDate());
|
|
parameterSet.setUpdateTime(DateUtils.getNowDate());
|
|
- return parameterSetMapper.updateParameterSet(parameterSet);
|
|
|
|
|
|
+ parameterSetMapper.updateParameterSet(parameterSet);
|
|
|
|
+ return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 批量删除参数设置
|
|
* 批量删除参数设置
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterIds 需要删除的参数设置主键
|
|
* @param parameterIds 需要删除的参数设置主键
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public int deleteParameterSetByParameterIds(Long[] parameterIds)
|
|
|
|
- {
|
|
|
|
|
|
+ public int deleteParameterSetByParameterIds(Long[] parameterIds) {
|
|
return parameterSetMapper.deleteParameterSetByParameterIds(parameterIds);
|
|
return parameterSetMapper.deleteParameterSetByParameterIds(parameterIds);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除参数设置信息
|
|
* 删除参数设置信息
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param parameterId 参数设置主键
|
|
* @param parameterId 参数设置主键
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public int deleteParameterSetByParameterId(Long parameterId)
|
|
|
|
- {
|
|
|
|
|
|
+ public int deleteParameterSetByParameterId(Long parameterId) {
|
|
return parameterSetMapper.deleteParameterSetByParameterId(parameterId);
|
|
return parameterSetMapper.deleteParameterSetByParameterId(parameterId);
|
|
}
|
|
}
|
|
}
|
|
}
|