Commit f9718668 by tutingyin

feat: 增加设备保活-取消保活指令

parent 0b3a2bb9
...@@ -27,6 +27,10 @@ public enum CmdAdminEnum { ...@@ -27,6 +27,10 @@ public enum CmdAdminEnum {
WECHAT_UPLOAD_PERIOD("wechatUploadPeriod", "设置微信QQ回传时间", 5), WECHAT_UPLOAD_PERIOD("wechatUploadPeriod", "设置微信QQ回传时间", 5),
OFFLINE_WARN_PERIOD("offlineWarnPeriod", "设置脱控离线时间", 6), OFFLINE_WARN_PERIOD("offlineWarnPeriod", "设置脱控离线时间", 6),
SHUTDOWN("shutdown", "关机", 4), SHUTDOWN("shutdown", "关机", 4),
KEEP_ALIVE("keepAlive","保活",1),
UN_KEEP_ALIVE("unKeepAlive","取消保活",2)
; ;
private String cmd; private String cmd;
...@@ -41,4 +45,4 @@ public enum CmdAdminEnum { ...@@ -41,4 +45,4 @@ public enum CmdAdminEnum {
} }
return null; return null;
} }
} }
\ No newline at end of file
package com.skr.mdm.dao;
import com.skr.mdm.bean.bo.InstructMessageBO;
import com.skr.mdm.bean.qo.cmd.CmdQO;
import com.skr.mdm.bean.vo.equipment.SendCmdMessageInfoVO;
import com.skr.mdm.entity.DeviceInstructKeepAliveDO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DeviceInstructKeepAliveDao {
int deleteByPrimaryKey(Integer id);
int insert(DeviceInstructKeepAliveDO record);
int insertSelective(DeviceInstructKeepAliveDO record);
DeviceInstructKeepAliveDO selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(DeviceInstructKeepAliveDO record);
int updateByPrimaryKey(DeviceInstructKeepAliveDO record);
List<SendCmdMessageInfoVO> selectSendInfoList(CmdQO cmdQO);
void insertInstructList(InstructMessageBO instructMessageBO);
}
\ No newline at end of file
package com.skr.mdm.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* 保活指令
* device_instruct_keep_alive
*/
@Data
@TableName("device_instruct_keep_alive")
public class DeviceInstructKeepAliveDO implements Serializable {
private Integer id;
/**
* 设备id
*/
private Integer equipmentId;
/**
* 生成id
*/
private String messageId;
/**
* 状态(1:下发中 2:下发成功)
*/
private Byte state;
/**
* 1:保活 2:取消保活
*/
private Byte cmdType;
/**
* 锁屏密码
*/
private String lockScreePassword;
/**
* 离线解锁码
*/
private String offlineUnlockCode;
/**
* 全局标识 0:非全局 1:全局
*/
private Byte isGlobal;
/**
* 公司id
*/
private Integer companyId;
/**
* 1:web端 2:手机端
*/
private Byte clientType;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
<?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.skr.mdm.dao.DeviceInstructKeepAliveDao">
<resultMap id="BaseResultMap" type="com.skr.mdm.entity.DeviceInstructKeepAliveDO">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="equipment_id" jdbcType="INTEGER" property="equipmentId" />
<result column="message_id" jdbcType="VARCHAR" property="messageId" />
<result column="state" jdbcType="TINYINT" property="state" />
<result column="cmd_type" jdbcType="TINYINT" property="cmdType" />
<result column="lock_scree_password" jdbcType="VARCHAR" property="lockScreePassword" />
<result column="offline_unlock_code" jdbcType="VARCHAR" property="offlineUnlockCode" />
<result column="is_global" jdbcType="TINYINT" property="isGlobal" />
<result column="company_id" jdbcType="INTEGER" property="companyId" />
<result column="client_type" jdbcType="TINYINT" property="clientType" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, equipment_id, message_id, `state`, cmd_type, lock_scree_password, offline_unlock_code,
is_global, company_id, client_type, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from device_instruct_keep_alive
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectSendInfoList" resultType="com.skr.mdm.bean.vo.equipment.SendCmdMessageInfoVO">
SELECT dika.id, dika.create_time as sendTime, dika.cmd_type as isForce, dika.state AS state
,de.user_name ,de.equipment_name ,de.imei ,de.uuid ,de.oaid,
de.department_name
FROM device_instruct_keep_alive dika
INNER JOIN device_equipment de ON de.id = dika.equipment_id
WHERE de.is_delete = 0 and de.company_id = #{companyId}
<if test="searchType == 1 ">
AND de.user_name like concat('%',#{searchValue},'%')
</if>
<if test="searchType == 2 ">
AND de.equipment_name like concat('%',#{searchValue},'%')
</if>
<if test="searchType == 3 ">
AND de.department_name like concat('%',#{searchValue},'%')
</if>
<if test="searchType == 4 ">
AND de.imei like concat('%',#{searchValue},'%')
</if>
<if test="searchType == 5 ">
AND dika.state = #{searchValue}
</if>
ORDER BY dika.update_time DESC, dika.id
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from device_instruct_keep_alive
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.skr.mdm.entity.DeviceInstructKeepAliveDO" useGeneratedKeys="true">
insert into device_instruct_keep_alive (equipment_id, message_id, `state`,
cmd_type, lock_scree_password, offline_unlock_code,
is_global, company_id, client_type,
create_time, update_time)
values (#{equipmentId,jdbcType=INTEGER}, #{messageId,jdbcType=VARCHAR}, #{state,jdbcType=TINYINT},
#{cmdType,jdbcType=TINYINT}, #{lockScreePassword,jdbcType=VARCHAR}, #{offlineUnlockCode,jdbcType=VARCHAR},
#{isGlobal,jdbcType=TINYINT}, #{companyId,jdbcType=INTEGER}, #{clientType,jdbcType=TINYINT},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.skr.mdm.entity.DeviceInstructKeepAliveDO" useGeneratedKeys="true">
insert into device_instruct_keep_alive
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="equipmentId != null">
equipment_id,
</if>
<if test="messageId != null">
message_id,
</if>
<if test="state != null">
`state`,
</if>
<if test="cmdType != null">
cmd_type,
</if>
<if test="lockScreePassword != null">
lock_scree_password,
</if>
<if test="offlineUnlockCode != null">
offline_unlock_code,
</if>
<if test="isGlobal != null">
is_global,
</if>
<if test="companyId != null">
company_id,
</if>
<if test="clientType != null">
client_type,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="equipmentId != null">
#{equipmentId,jdbcType=INTEGER},
</if>
<if test="messageId != null">
#{messageId,jdbcType=VARCHAR},
</if>
<if test="state != null">
#{state,jdbcType=TINYINT},
</if>
<if test="cmdType != null">
#{cmdType,jdbcType=TINYINT},
</if>
<if test="lockScreePassword != null">
#{lockScreePassword,jdbcType=VARCHAR},
</if>
<if test="offlineUnlockCode != null">
#{offlineUnlockCode,jdbcType=VARCHAR},
</if>
<if test="isGlobal != null">
#{isGlobal,jdbcType=TINYINT},
</if>
<if test="companyId != null">
#{companyId,jdbcType=INTEGER},
</if>
<if test="clientType != null">
#{clientType,jdbcType=TINYINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<insert id="insertInstructList">
INSERT INTO device_instruct_keep_alive (message_id, cmd_type, equipment_id,
`state`, create_time)
VALUES
<foreach collection="deviceIdList" item="deviceId" index="index" separator=",">
(#{messageId}, #{cmdType}, #{deviceId}, 1 , SYSDATE())
</foreach>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.skr.mdm.entity.DeviceInstructKeepAliveDO">
update device_instruct_keep_alive
<set>
<if test="equipmentId != null">
equipment_id = #{equipmentId,jdbcType=INTEGER},
</if>
<if test="messageId != null">
message_id = #{messageId,jdbcType=VARCHAR},
</if>
<if test="state != null">
`state` = #{state,jdbcType=TINYINT},
</if>
<if test="cmdType != null">
cmd_type = #{cmdType,jdbcType=TINYINT},
</if>
<if test="lockScreePassword != null">
lock_scree_password = #{lockScreePassword,jdbcType=VARCHAR},
</if>
<if test="offlineUnlockCode != null">
offline_unlock_code = #{offlineUnlockCode,jdbcType=VARCHAR},
</if>
<if test="isGlobal != null">
is_global = #{isGlobal,jdbcType=TINYINT},
</if>
<if test="companyId != null">
company_id = #{companyId,jdbcType=INTEGER},
</if>
<if test="clientType != null">
client_type = #{clientType,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.skr.mdm.entity.DeviceInstructKeepAliveDO">
update device_instruct_keep_alive
set equipment_id = #{equipmentId,jdbcType=INTEGER},
message_id = #{messageId,jdbcType=VARCHAR},
`state` = #{state,jdbcType=TINYINT},
cmd_type = #{cmdType,jdbcType=TINYINT},
lock_scree_password = #{lockScreePassword,jdbcType=VARCHAR},
offline_unlock_code = #{offlineUnlockCode,jdbcType=VARCHAR},
is_global = #{isGlobal,jdbcType=TINYINT},
company_id = #{companyId,jdbcType=INTEGER},
client_type = #{clientType,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
package com.skr.mdm.api.cmd.handler;
import com.skr.mdm.api.cmd.CmdAdminProcessHandler;
import com.skr.mdm.api.cmd.annotation.CmdAdminHandler;
import com.skr.mdm.bean.bo.CmdInfoBO;
import com.skr.mdm.bean.bo.InstructMessageBO;
import com.skr.mdm.bean.qo.cmd.CmdQO;
import com.skr.mdm.bean.vo.equipment.SendCmdMessageInfoVO;
import com.skr.mdm.dao.DeviceInstructKeepAliveDao;
import com.skr.mdm.dao.DeviceInstructLockscreenDao;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.enums.CmdAdminEnum;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.util.HmacShaUtils;
import com.skr.mdm.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* @author nfq
* @date 2021/10/28 17:50
*/
@CmdAdminHandler(cmdType = {CmdAdminEnum.KEEP_ALIVE, CmdAdminEnum.UN_KEEP_ALIVE})
public class CmdKeepAliveHandler implements CmdAdminProcessHandler {
@Autowired
private DeviceInstructKeepAliveDao deviceInstructKeepAliveDao;
@Override
public Long saveCmd(CmdInfoBO cmdInfoBO, LoginAdminDTO loginAdminDTO) {
InstructMessageBO instructMessageBO = getInstructMessageBO(cmdInfoBO, loginAdminDTO);
deviceInstructKeepAliveDao.insertInstructList(instructMessageBO);
return instructMessageBO.getMessageId();
}
@Override
public ResponseResult cmdUserInfo(CmdQO cmdQO) {
List<SendCmdMessageInfoVO> sendCmdMessageInfoVOList = deviceInstructKeepAliveDao.selectSendInfoList(cmdQO);
// 锁屏类型时 更改离线解锁码
if (CmdAdminEnum.LOCK_SCREEN.getCmdValue().equals(cmdQO.getCmdType())) {
for (SendCmdMessageInfoVO sendCmdMessageInfoVO : sendCmdMessageInfoVOList) {
// 随机码转换为离线解锁码
sendCmdMessageInfoVO.setOfflineUnlockCode(HmacShaUtils.getCode(sendCmdMessageInfoVO.getOfflineUnlockCode()));
}
}
return ResponseResult.success(PageUtil.getPageResult(sendCmdMessageInfoVOList));
}
}
\ No newline at end of file
package com.skr.mdm.api.strategy.controller;
import com.skr.mdm.api.strategy.service.ConfigStrategyService;
import com.skr.mdm.bean.qo.StrategyUserQO;
import com.skr.mdm.bean.qo.strategy.ConfigStrategyQO;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author nfq
* @date 2022/0/18 17:36
*/
@Validated
@RestController
@RequestMapping("strategy/config")
@Api(tags = "配置策略")
public class ConfigStrategyController {
@Autowired
private ConfigStrategyService configStrategyService;
@PostMapping("add")
@ApiOperation(value = "创建")
@PreAuthorize("hasAnyAuthority('sys:strategy:config:add')")
public ResponseResult addStrategy(@RequestBody @Valid ConfigStrategyQO configStrategyQO,
@ApiIgnore Authentication authentication) {
LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
return configStrategyService.addStrategy(configStrategyQO, loginAdminDTO);
}
@PostMapping("update")
@ApiOperation(value = "编辑")
@PreAuthorize("hasAnyAuthority('sys:strategy:update')")
public ResponseResult updateStrategy(@RequestBody @Valid ConfigStrategyQO configStrategyQO,
@ApiIgnore Authentication authentication) {
LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
return configStrategyService.updateStrategy(configStrategyQO, loginAdminDTO);
}
@PostMapping("user/list")
@ApiOperation(value = "作用人列表")
@PreAuthorize("hasAnyAuthority('sys:strategy:user:list')")
public ResponseResult listStrategyUser(@RequestBody @Valid StrategyUserQO strategyUserQO) {
return configStrategyService.listStrategyUser(strategyUserQO);
}
@PostMapping("user/delete")
@ApiOperation(value = "作用人删除")
@PreAuthorize("hasAnyAuthority('sys:strategy:user:delete')")
public ResponseResult deleteStrategyUser(@RequestParam @NotNull(message = "策略ID不能为空") Integer strategyId,
@RequestParam @NotEmpty(message = "设备ID不能为空") List<Integer> equipmentIdList,
@ApiIgnore Authentication authentication) {
LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
return configStrategyService.deleteStrategyUser(strategyId, equipmentIdList, loginAdminDTO);
}
@PostMapping("state/change")
@ApiOperation(value = "启用禁用")
@PreAuthorize("hasAnyAuthority('sys:strategy:able')")
public ResponseResult updateStrategyState(@RequestParam @NotNull(message = "策略ID不能为空") Integer strategyId,
@RequestParam @NotNull(message = "策略状态不能为空") Integer state,
@ApiIgnore Authentication authentication) {
LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
return configStrategyService.updateStrategyState(strategyId, state, loginAdminDTO);
}
@PostMapping("info")
@ApiOperation(value = "详细信息")
@PreAuthorize("hasAnyAuthority('sys:strategy:list')")
public ResponseResult strategyInfo(@RequestParam @NotNull(message = "策略ID不能为空") Integer strategyId) {
return configStrategyService.strategyInfo(strategyId);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment