开发手动,控制,定时控制

master
林颖晨 2 years ago
parent 9b51b10d6e
commit 535bd66fbd
  1. 7
      psdc-business/src/main/java/com/psdc/entity/PsdcControlLog.java
  2. 23
      psdc-business/src/main/java/com/psdc/entity/PsdcScene.java
  3. 32
      psdc-business/src/main/java/com/psdc/entity/PsdcTimer.java
  4. 32
      psdc-business/src/main/java/com/psdc/entity/vo/SceneVo.java
  5. 88
      psdc-business/src/main/java/com/psdc/mapper/PsdcSceneMapper.java
  6. 56
      psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java
  7. 21
      psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java
  8. 45
      psdc-business/src/main/java/com/psdc/service/IPsdcSceneService.java
  9. 42
      psdc-business/src/main/java/com/psdc/service/IPsdcTimerService.java
  10. 97
      psdc-business/src/main/java/com/psdc/service/impl/IPsdcSceneServiceImpl.java
  11. 82
      psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java
  12. 64
      psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java
  13. 111
      psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml
  14. 136
      psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml
  15. 6
      psdc-common/src/main/java/com/psdc/core/controller/BaseController.java
  16. 39
      psdc-common/src/main/java/com/psdc/enums/ControlKeyEnum.java
  17. 48
      psdc-web/src/main/java/com/psdc/controller/control/ManualControl.java
  18. 10
      psdc-web/src/main/java/com/psdc/controller/control/TimerControl.java

@ -52,6 +52,10 @@ public class PsdcControlLog implements Serializable {
* 控制结果描述
*/
private String controlContext;
/**
* 控制结果1-控制中2-控制成功3-控制失败
*/
private Integer controlMethod;
/**
* 创建者
*/
@ -69,7 +73,7 @@ public class PsdcControlLog implements Serializable {
*/
private String updateTime;
public PsdcControlLog(Integer deviceId, String deviceName, String deviceSn, String controlKey, String controlValue, Integer controlResult,String controlContext, String createBy) {
public PsdcControlLog(Integer deviceId, String deviceName, String deviceSn, String controlKey, String controlValue,Integer controlMethod, Integer controlResult,String controlContext, String createBy) {
this.deviceId = deviceId;
this.deviceName = deviceName;
this.deviceSn = deviceSn;
@ -77,6 +81,7 @@ public class PsdcControlLog implements Serializable {
this.controlValue = controlValue;
this.controlResult = controlResult;
this.controlContext = controlContext;
this.controlMethod = controlMethod;
this.createBy = createBy;
}
}

@ -14,12 +14,23 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class PsdcScene {
private long scene;
private String sceneName;
private long deviceId;
private String deviceSn;
private String sceneKey;
private String sceneValue;
/** 场景值 */
private Integer sceneId ;
/** 场景名 */
private String sceneName ;
/** 用户id */
private Integer userId;
/** 设备id */
private Integer deviceId ;
/** 设备sn */
private String deviceSn ;
/** 控制键描述 */
private String sceneContext ;
/** 控制键 */
private String sceneKey ;
/** 控制值 */
private String sceneValue ;
}

@ -0,0 +1,32 @@
package com.psdc.entity;
import com.psdc.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public class PsdcTimer extends BaseEntity {
/** 定时控制任务主键 */
private Integer timerId ;
/** 设备id */
private Integer deviceId ;
/** 用户id */
private Integer userId ;
/** 执行时间 */
private String runtimer ;
/** 执行指令 */
private String controlKey ;
/** 指令描述 */
private String controlContext ;
/** 指令值 */
private String controlValue ;
/** cron表达式 */
private String cronText ;
/** 状态:1-开启,2-暂停 */
private Integer timerStatus ;
}

@ -0,0 +1,32 @@
package com.psdc.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SceneVo {
/** 场景值 */
private Integer sceneId ;
/** 场景名 */
private String sceneName ;
/** 用户id */
private Integer userId;
/** 设备id */
private Integer deviceId ;
/** 设备名称 */
private String deviceName;
/** 设备sn */
private String deviceSn ;
/** 控制键描述 */
private String sceneContext ;
/** 控制键 */
private String sceneKey ;
/** 控制值 */
private String sceneValue ;
}

@ -0,0 +1,88 @@
package com.psdc.mapper;
import com.psdc.entity.PsdcScene;
import com.psdc.entity.vo.SceneVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 场景设定;(psdc_scene)表数据库访问层
* @author : http://www.chiner.pro
* @date : 2023-5-10
*/
@Mapper
public interface PsdcSceneMapper{
/**
* 通过ID查询单条数据
*
* @param undefinedId 主键
* @return 实例对象
*/
PsdcScene queryById(Integer sceneId);
/**
* 新增数据
*
* @param psdcScene 实例对象
* @return 影响行数
*/
int insert(PsdcScene psdcScene);
/**
* 更新数据
*
* @param psdcScene 实例对象
* @return 影响行数
*/
int update(PsdcScene psdcScene);
/**
* 通过主键删除数据
*
* @param undefinedId 主键
* @return 影响行数
*/
int deleteById(Integer sceneId);
/**
* 根据用户ID查询策略信息
* @param userId
* @return
*/
List<SceneVo> queryByUserId(Long userId);
/**
* 获取场景名称分组
* @param userId
* @return
*/
List<String> querySceneGroup(Long userId);
/**
* 根据设备id获取配置场景
* @param userId
* @param deviceId
* @return
*/
List<SceneVo> querySceneByDeviceId(@Param(value = "userId") Long userId,
@Param(value = "deviceId") Integer deviceId);
/**
* 根据设备id获取配置场景
* @param userId
* @param deviceId
* @return
*/
List<SceneVo> querySceneByDeviceIdAndSceneName(@Param(value = "userId") Long userId,
@Param(value = "deviceId") Integer deviceId,
@Param(value = "sceneName") String sceneName);
/**
* 根据策略名称查询策略信息
* @param sceneName
* @return
*/
List<SceneVo> queryBySceneName(String sceneName);
}

@ -0,0 +1,56 @@
package com.psdc.mapper;
import java.util.List;
import com.psdc.entity.PsdcTimer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
/**
* 定时控制任务表;(psdc_timer)表数据库访问层
* @date : 2023-5-10
*/
@Mapper
public interface PsdcTimerMapper{
/**
* 通过ID查询单条数据
*
* @param timerId 主键
* @return 实例对象
*/
PsdcTimer queryById(Integer timerId);
/**
* 分页查询指定行数据
*
* @param psdcTimer 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<PsdcTimer> queryAllByLimit(PsdcTimer psdcTimer);
/**
* 新增数据
*
* @param psdcTimer 实例对象
* @return 影响行数
*/
int insert(PsdcTimer psdcTimer);
/**
* 更新数据
*
* @param psdcTimer 实例对象
* @return 影响行数
*/
int update(PsdcTimer psdcTimer);
/**
* 通过主键删除数据
*
* @param timerId 主键
* @return 影响行数
*/
int deleteById(Integer timerId);
}

@ -3,6 +3,7 @@ package com.psdc.service;
import com.psdc.entity.PsdcDevice;
import com.psdc.entity.vo.DeviceStatusVo;
import java.util.HashMap;
import java.util.List;
public interface IPsdcDeviceService {
@ -64,6 +65,24 @@ public interface IPsdcDeviceService {
* @param runStatus
* @return
*/
int controlDeviceStartAndStop(Integer deviceId,Integer runStatus,String controlBy);
int controlDeviceStartAndStop(Integer deviceId,Integer runStatus,String controlBy,Integer controlMethod);
/**
* 设置温度指令
*
* @param deviceId
* @param data
*/
int setTemperature(Integer deviceId, List<HashMap> data, String controlBym,Integer controlMethod);
/**
* 设置单条温度指令
* @param deviceId
* @param key
* @param value
* @param controlBym
* @param controlMethod
* @return
*/
int setTemperature(Integer deviceId, String key,String value, String controlBym,Integer controlMethod);
}

@ -0,0 +1,45 @@
package com.psdc.service;
import com.psdc.entity.PsdcScene;
import com.psdc.entity.vo.SceneVo;
import java.util.List;
import java.util.Map;
/**
* 场景设定;(psdc_scene)表服务接口
* @date : 2023-5-10
*/
public interface IPsdcSceneService {
/**
* 通过ID查询单条数据
*
* @param undefinedId 主键
* @return 实例对象
*/
PsdcScene queryById(Integer sceneId);
/**
* 新增数据
*
* @param psdcScene 实例对象
* @return 实例对象
*/
PsdcScene insert(PsdcScene psdcScene);
/**
* 更新数据
*
* @param psdcScene 实例对象
* @return 实例对象
*/
PsdcScene update(PsdcScene psdcScene);
/**
* 通过主键删除数据
*
* @param undefinedId 主键
* @return 是否成功
*/
boolean deleteById(Integer sceneId);
List<Map<String, Object>> getStrategyList();
}

@ -0,0 +1,42 @@
package com.psdc.service;
import com.psdc.entity.PsdcTimer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
/**
* 定时控制任务表;(psdc_timer)表服务接口
* @date : 2023-5-10
*/
public interface IPsdcTimerService {
/**
* 通过ID查询单条数据
*
* @param timerId 主键
* @return 实例对象
*/
PsdcTimer queryById(Integer timerId);
/**
* 新增数据
*
* @param psdcTimer 实例对象
* @return 实例对象
*/
PsdcTimer insert(PsdcTimer psdcTimer);
/**
* 更新数据
*
* @param psdcTimer 实例对象
* @return 实例对象
*/
PsdcTimer update(PsdcTimer psdcTimer);
/**
* 通过主键删除数据
*
* @param timerId 主键
* @return 是否成功
*/
boolean deleteById(Integer timerId);
}

@ -0,0 +1,97 @@
package com.psdc.service.impl;
import com.psdc.entity.PsdcScene;
import com.psdc.entity.vo.SceneVo;
import com.psdc.mapper.PsdcSceneMapper;
import com.psdc.service.IPsdcSceneService;
import com.psdc.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 场景设定;(psdc_scene)表服务实现类
* @date : 2023-5-10
*/
@Service
public class IPsdcSceneServiceImpl implements IPsdcSceneService {
@Autowired
private PsdcSceneMapper psdcSceneMapper;
/**
* 通过ID查询单条数据
*
* @param sceneId 主键
* @return 实例对象
*/
public PsdcScene queryById(Integer sceneId){
return psdcSceneMapper.queryById(sceneId);
}
/**
* 新增数据
*
* @param psdcScene 实例对象
* @return 实例对象
*/
public PsdcScene insert(PsdcScene psdcScene){
psdcSceneMapper.insert(psdcScene);
return psdcScene;
}
/**
* 更新数据
*
* @param psdcScene 实例对象
* @return 实例对象
*/
public PsdcScene update(PsdcScene psdcScene){
psdcSceneMapper.update(psdcScene);
return queryById(psdcScene.getSceneId());
}
/**
* 通过主键删除数据
*
* @param undefinedId 主键
* @return 是否成功
*/
public boolean deleteById(Integer sceneId){
int total = psdcSceneMapper.deleteById(sceneId);
return total > 0;
}
@Override
public List<Map<String, Object>> getStrategyList() {
List<String> scenes = psdcSceneMapper.querySceneGroup(SecurityUtils.getUserId());
List<Map<String, Object>> collectList = scenes.stream()
.map(scene -> {
List<SceneVo> sceneVoList = psdcSceneMapper.queryBySceneName(scene);
Integer[] flag = {null};
List<Map<String, Object>> collect = sceneVoList.stream()
.filter(sceneVo -> !Objects.equals(flag[0], sceneVo.getDeviceId()))
.peek(sceneVo -> flag[0] = sceneVo.getDeviceId())
.map(sceneVo -> {
Map<String, Object> map1 = new HashMap<>();
map1.put("device_name", sceneVo.getDeviceName());
map1.put("device_id", sceneVo.getDeviceId());
List<SceneVo> sceneVoList1 = psdcSceneMapper.querySceneByDeviceIdAndSceneName(SecurityUtils.getUserId(), sceneVo.getDeviceId(), scene);
map1.put("value", sceneVoList1);
return map1;
})
.collect(Collectors.toList());
Map<String, Object> map = new HashMap<>();
map.put("sceneName", scene);
map.put("data", collect);
return map;
})
.collect(Collectors.toList());
return collectList;
}
}

@ -3,6 +3,7 @@ package com.psdc.service.impl;
import com.psdc.entity.PsdcControlLog;
import com.psdc.entity.PsdcDevice;
import com.psdc.entity.vo.DeviceStatusVo;
import com.psdc.enums.ControlKeyEnum;
import com.psdc.exception.ControlException;
import com.psdc.mapper.PsdcControlLogMapper;
import com.psdc.mapper.PsdcDeviceMapper;
@ -13,7 +14,10 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
@ -104,29 +108,93 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{
* @return
*/
@Override
public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus,String controlBy) {
public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus,String controlBy,Integer controlMethod) {
String s = "";
String value = "";
if(runStatus == 1){
s = "启动";
value = "启动";
} else if ( runStatus == 2 ) {
s = "停止";
value = "停止";
}
log.info("设备id:{}",deviceId);
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId);
if(psdcDevice == null){
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设备启停",s,2,"未找到该设备",controlBy));
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设备启停",value,controlMethod,3,"未找到该设备",controlBy));
throw new ControlException("控制失败,未找到该设备");
}
//TODO 发送MQTT指令
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",s,2,"等待终端响应超时",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,3,"手动控制,等待终端响应超时",controlBy));
//发送成功
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",s,2,"控制成功",controlBy));
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,2,"手动控制,控制成功",controlBy));
return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId,runStatus);
}
@Override
public int setTemperature(Integer deviceId, List<HashMap> data, String controlBy,Integer controlMethod) {
log.info("设备id:{}",deviceId);
log.info("控制指令:{}",data);
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId);
if(psdcDevice == null){
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设定温度",null,controlMethod,3,"未找到该设备",controlBy));
throw new ControlException("控制失败,未找到该设备");
}
AtomicInteger atomicInteger = new AtomicInteger(0);
for (Map map: data) {
String controlKey = map.get("controlKey").toString();
String controlValue = map.get("controlValue").toString();
String controlContext = ControlKeyEnum.getControlContext(controlKey);
//TODO 发送MQTT指令
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy));
//发送成功
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy));
atomicInteger.incrementAndGet();
}
return atomicInteger.get();
}
/**
* 单条控制指令
* @param deviceId
* @param key
* @param value
* @param controlBy
* @param controlMethod
* @return
*/
@Override
public int setTemperature(Integer deviceId, String key,String value, String controlBy,Integer controlMethod) {
log.info("设备id:{}",deviceId);
log.info("控制指令:{}",key);
log.info("控制内容:{}",value);
String controlContext = ControlKeyEnum.getControlContext(key);
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId);
if(psdcDevice == null){
psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,controlContext,null,controlMethod,3,"未找到该设备",controlBy));
throw new ControlException("控制失败,未找到该设备");
}
//TODO 发送MQTT指令
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,2,"控制成功",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,3,"等待终端响应超时",controlBy));
//发送成功
return psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,value,controlMethod,2,"控制成功",controlBy));
}
}

@ -0,0 +1,64 @@
package com.psdc.service.impl;
import com.psdc.entity.PsdcTimer;
import com.psdc.mapper.PsdcTimerMapper;
import com.psdc.service.IPsdcTimerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 定时控制任务表;(psdc_timer)表服务实现类
* @author : http://www.chiner.pro
* @date : 2023-5-10
*/
@Service
public class PsdcTimerServiceImpl implements IPsdcTimerService {
@Autowired
private PsdcTimerMapper psdcTimerMapper;
/**
* 通过ID查询单条数据
*
* @param timerId 主键
* @return 实例对象
*/
public PsdcTimer queryById(Integer timerId){
return psdcTimerMapper.queryById(timerId);
}
/**
* 新增数据
*
* @param psdcTimer 实例对象
* @return 实例对象
*/
public PsdcTimer insert(PsdcTimer psdcTimer){
psdcTimerMapper.insert(psdcTimer);
return psdcTimer;
}
/**
* 更新数据
*
* @param psdcTimer 实例对象
* @return 实例对象
*/
public PsdcTimer update(PsdcTimer psdcTimer){
psdcTimerMapper.update(psdcTimer);
return queryById(psdcTimer.getTimerId());
}
/**
* 通过主键删除数据
*
* @param timerId 主键
* @return 是否成功
*/
public boolean deleteById(Integer timerId){
int total = psdcTimerMapper.deleteById(timerId);
return total > 0;
}
}

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.psdc.mapper.PsdcSceneMapper">
<resultMap type="com.psdc.entity.PsdcScene" id="PsdcSceneMap">
<result property="sceneId" column="scene_id" />
<result property="sceneName" column="scene_name" />
<result property="userId" column="user_id"/>
<result property="deviceId" column="device_id" />
<result property="deviceSn" column="device_sn" />
<result property="sceneContext" column="scene_context" />
<result property="sceneKey" column="scene_key" />
<result property="sceneValue" column="scene_value" />
</resultMap>
<resultMap type="com.psdc.entity.vo.SceneVo" id="SceneVoMap">
<result property="sceneName" column="scene_name" />
<result property="userId" column="user_id"/>
<result property="deviceName" column="device_name"/>
<result property="deviceId" column="device_id" />
<result property="deviceSn" column="device_sn" />
<result property="sceneContext" column="scene_context" />
<result property="sceneKey" column="scene_key" />
<result property="sceneValue" column="scene_value" />
</resultMap>
<!-- 通过ID查询单条数据 -->
<select id="queryById" resultMap="PsdcSceneMap">
select
scene_id,scene_name,user_id,device_id,device_sn,scene_context,scene_key,scene_value
from psdc_scene
where scene_id = #{sceneId}
</select>
<!--新增数据-->
<insert id="insert" keyProperty="UNDEFINED_ID" useGeneratedKeys="true">
insert into psdc_scene(scene_name,user_id,device_id,device_sn,scene_context,scene_key,scene_value)
values (#{sceneName},#{userId},#{deviceId},#{deviceSn},#{sceneContext},#{sceneKey},#{sceneValue})
</insert>
<!-- 更新数据 -->
<update id="update">
update psdc_scene
<set>
<if test="sceneName != null and sceneName != ''">
scene_name = #{sceneName},
</if>
<if test="userId != null and userId != ''">
user_id = #{userId},
</if>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId},
</if>
<if test="deviceSn != null and deviceSn != ''">
device_sn = #{deviceSn},
</if>
<if test="sceneContext != null and sceneContext != ''">
scene_context = #{sceneContext},
</if>
<if test="sceneKey != null and sceneKey != ''">
scene_key = #{sceneKey},
</if>
<if test="sceneValue != null and sceneValue != ''">
scene_value = #{sceneValue},
</if>
</set>
where scene_id = #{sceneId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from psdc_scene where scene_id = #{sceneId}
</delete>
<!-- 根据用户ID查询策略信息-->
<select id="queryByUserId" resultMap="SceneVoMap">
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
left join psdc_device pd on ps.device_id = pd.device_id
where su.user_id = #{userId}
</select>
<!-- 根据用户ID查询策略信息-->
<select id="querySceneGroup" resultType="string">
select ps.scene_name
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
where su.user_id = #{userId} group by ps.scene_name
</select>
<!-- 根据用户ID查询策略信息-->
<select id="querySceneByDeviceId" resultMap="SceneVoMap">
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
left join psdc_device pd on ps.device_id = pd.device_id
where su.user_id = #{userId} and pd.device_id = #{deviceId}
</select>
<!-- 根据用户ID查询策略信息-->
<select id="querySceneByDeviceIdAndSceneName" resultMap="SceneVoMap">
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
left join psdc_device pd on ps.device_id = pd.device_id
where su.user_id = #{userId} and ps.device_id = #{deviceId} and ps.scene_name = #{sceneName}
</select>
<!-- 根据策略名称查询策略信息-->
<select id="queryBySceneName" resultMap="SceneVoMap">
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
from psdc_scene ps left join psdc_device pd on ps.device_id = pd.device_id
where ps.scene_name like concat('%', #{sceneName}, '%')
</select>
</mapper>

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.psdc.mapper.PsdcTimerMapper">
<resultMap type="com.psdc.entity.PsdcTimer" id="PsdcTimerMap">
<result property="timerId" column="timer_id" />
<result property="deviceId" column="device_id" />
<result property="userId" column="user_id" />
<result property="runtimer" column="runtimer" />
<result property="controlKey" column="control_key" />
<result property="controlContext" column="control_context" />
<result property="controlValue" column="control_value" />
<result property="cronText" column="cron_text" />
<result property="timerStatus" column="timer_status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<!-- 通过ID查询单条数据 -->
<select id="queryById" resultMap="PsdcTimerMap">
select
timer_id,device_id,user_id,runtimer,control_key,control_context,control_value,cron_text,timer_status,create_by,create_time,update_by,update_time
from psdc_timer
where timer_id = #{timerId}
</select>
<!--分页查询指定行数据-->
<select id="queryAllByLimit" resultMap="PsdcTimerMap">
select
timer_id,device_id,user_id,runtimer,control_key,control_context,control_value,cron_text,timer_status,create_by,create_time,update_by,update_time
from psdc_timer
<where>
<if test="timerId != null and timerId != ''">
and timer_id = #{timerId}
</if>
<if test="deviceId != null and deviceId != ''">
and device_id = #{deviceId}
</if>
<if test="userId != null and userId != ''">
and user_id = #{userId}
</if>
<if test="runtimer != null and runtimer != ''">
and runtimer = #{runtimer}
</if>
<if test="controlKey != null and controlKey != ''">
and control_key = #{controlKey}
</if>
<if test="controlContext != null and controlContext != ''">
and control_context = #{controlContext}
</if>
<if test="controlValue != null and controlValue != ''">
and control_value = #{controlValue}
</if>
<if test="cronText != null and cronText != ''">
and cron_text = #{cronText}
</if>
<if test="timerStatus != null and timerStatus != ''">
and timer_status = #{timerStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null and createTime != ''">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null and updateTime != ''">
and update_time = #{updateTime}
</if>
</where>
</select>
<!--新增数据-->
<insert id="insert" keyProperty="timer_id" useGeneratedKeys="true">
insert into psdc_timer(timer_id,device_id,user_id,runtimer,control_key,control_context,control_value,cron_text,timer_status,create_by,create_time,update_by,update_time)
values (#{timerId},#{deviceId},#{userId},#{runtimer},#{controlKey},#{controlContext},#{controlValue},#{cronText},#{timerStatus},#{createBy},#{createTime},#{updateBy},#{updateTime})
</insert>
<!-- 更新数据 -->
<update id="update">
update psdc_timer
<set>
<if test="timerId != null and timerId != ''">
timer_id = #{timerId},
</if>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId},
</if>
<if test="userId != null and userId != ''">
user_id = #{userId},
</if>
<if test="runtimer != null and runtimer != ''">
runtimer = #{runtimer},
</if>
<if test="controlKey != null and controlKey != ''">
control_key = #{controlKey},
</if>
<if test="controlContext != null and controlContext != ''">
control_context = #{controlContext},
</if>
<if test="controlValue != null and controlValue != ''">
control_value = #{controlValue},
</if>
<if test="cronText != null and cronText != ''">
cron_text = #{cronText},
</if>
<if test="timerStatus != null and timerStatus != ''">
timer_status = #{timerStatus},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="createTime != null and createTime != ''">
create_time = #{createTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null and updateTime != ''">
update_time = #{updateTime},
</if>
</set>
where timer_id = #{timerId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from psdc_timer where timer_id = #{timerId}
</delete>
</mapper>

@ -60,6 +60,12 @@ public class BaseController
PageUtils.startPage();
}
protected <T> T myPage(JSONObject jsonObject,Class<T> tClass){
PageMethod.startPage(jsonObject.getInteger("pageNum"),jsonObject.getInteger("pageSize"));
T t = JSON.parseObject(String.valueOf(jsonObject), tClass);
return t;
}
/**
* 设置请求排序数据
*/

@ -0,0 +1,39 @@
package com.psdc.enums;
public enum ControlKeyEnum {
TEMPERATURE("temp","设定温度"),
IN_TEMPERATURE("intemp","设定进水温度"),
OUT_TEMPERATURE("outtemp","设定出水温度");
/**
* 设备指令
*/
private final String controlKey;
/**
* 控制描述
*/
private final String controlContext;
ControlKeyEnum(String controlKey, String controlContext) {
this.controlKey = controlKey;
this.controlContext = controlContext;
}
public String getControlContext() {
return controlContext;
}
public static String getControlContext(String controlKey) {
switch (controlKey){
case "temp":return TEMPERATURE.getControlContext();
case "intemp":return IN_TEMPERATURE.getControlContext();
case "outtemp":return OUT_TEMPERATURE.getControlContext();
default:return null;
}
}
}

@ -1,8 +1,6 @@
package com.psdc.controller.control;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.page.PageMethod;
import com.psdc.core.controller.BaseController;
import com.psdc.core.domain.AjaxResult;
import com.psdc.core.page.TableDataInfo;
@ -10,16 +8,20 @@ import com.psdc.entity.PsdcControlLog;
import com.psdc.entity.vo.DeviceStatusVo;
import com.psdc.service.IPsdcControlLogService;
import com.psdc.service.IPsdcDeviceService;
import com.psdc.service.IPsdcSceneService;
import com.psdc.utils.SecurityUtils;
import org.apache.poi.ss.formula.functions.T;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@Slf4j
@RequestMapping("/control/manual")
public class ManualControl extends BaseController {
@ -30,6 +32,9 @@ public class ManualControl extends BaseController {
@Autowired
private IPsdcControlLogService psdcControlLogService;
@Autowired
private IPsdcSceneService psdcSceneService;
/**
* 查询设备状态列表
* @return
@ -49,7 +54,7 @@ public class ManualControl extends BaseController {
@PreAuthorize("@ss.hasPermi('control:manual:startstop')")
@PostMapping("/startAndStop")
public AjaxResult deviceStartAndStop(@RequestBody JSONObject jsonObject){
int i = psdcDeviceService.controlDeviceStartAndStop(jsonObject.getInteger("deviceId"), jsonObject.getInteger("runStatus"), SecurityUtils.getUsername());
int i = psdcDeviceService.controlDeviceStartAndStop(jsonObject.getInteger("deviceId"), jsonObject.getInteger("runStatus"), SecurityUtils.getUsername(),1);
if ( i == 1){
return AjaxResult.success("控制成功");
} else {
@ -57,17 +62,48 @@ public class ManualControl extends BaseController {
}
}
/**
* 获取调控日志列表
*/
@PreAuthorize("@ss.hasPermi('control:manual:controlLogList')")
@PostMapping("/controlLogList")
public TableDataInfo controlLogList(@RequestBody JSONObject jsonObject) {
PageMethod.startPage(jsonObject.getInteger("pageNum"),jsonObject.getInteger("pageSize"));
PsdcControlLog psdcControlLog = JSON.parseObject(String.valueOf(jsonObject), PsdcControlLog.class);
PsdcControlLog psdcControlLog = myPage(jsonObject, PsdcControlLog.class);
List<PsdcControlLog> list = psdcControlLogService.query(psdcControlLog);
return getDataTable(list);
}
/**
* 获取策略控制
* @return
*/
@PreAuthorize("@ss.hasPermi('control:manual:strategy')")
@GetMapping("/strategyList")
public AjaxResult getStrategyList(){
List<Map<String, Object>> strategyList = psdcSceneService.getStrategyList();
return AjaxResult.success(strategyList);
}
/**
* 设置温度
* @param jsonObject
* @return
*/
@PreAuthorize("@ss.hasPermi('control:manual:temperature')")
@PostMapping("/setTemperature")
public AjaxResult setTemperature(@RequestBody JSONObject jsonObject){
Integer deviceId = jsonObject.getInteger("deviceId");
List<HashMap> data = jsonObject.getList("data", HashMap.class);
int i = psdcDeviceService.setTemperature(deviceId, data, SecurityUtils.getUsername(),1);
if (i == data.size()) {
return AjaxResult.success("控制成功");
} else {
log.info("控制设备失败。返回数据库实际插入数据:{}",i);
return AjaxResult.error("控制失败,请联系管理员");
}
}
}

@ -1,4 +1,14 @@
package com.psdc.controller.control;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
@RequestMapping("/control/timer")
public class TimerControl {
}

Loading…
Cancel
Save