parent
9b51b10d6e
commit
535bd66fbd
@ -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); |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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> |
@ -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,4 +1,14 @@ |
|||||||
package com.psdc.controller.control; |
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 { |
public class TimerControl { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue