Commit 23967958 by tutingyin

feat: 增加设备保活 客户端回调

parent f9718668
package com.skr.mdm.controller;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
/**
* @Author tty
* @Date 2024/9/9 16:37
* @Description 指令回调
*/
@RestController
@RequestMapping("status")
@Api(tags = "指令回调")
public class DeviceInstructCmdController {
@PostMapping("callback")
@ApiOperation("指令回调")
public ResponseResult equipmentStatusCallback(@RequestParam @ApiParam(value = "回调内容", required = true) String data,
@ApiIgnore Authentication authentication) {
LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.KEEP_ALIVE);
return strategy.cmdHandler(loginUserDTO.getId(), data);
}
}
\ No newline at end of file
package com.skr.mdm.service.impl.cmd;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dao.DeviceInstructKeepAliveDao;
import com.skr.mdm.dto.CmdCallBackDTO;
import com.skr.mdm.entity.DeviceInstructKeepAliveDO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
/**
* @author nfq
* @date 2020/8/3 18:38
*/
@Slf4j
@CmdHandler(cmdType = {CmdTypeConstants.KEEP_ALIVE})
public class KeepAliveServiceImpl implements CmdHandlerService {
@Autowired
private DeviceInstructKeepAliveDao deviceInstructKeepAliveDao;
@Override
public ResponseResult cmdHandler(Integer equipmentId, String data) {
try {
// 锁屏解锁回调
JSONArray jsonArray = JSONUtil.parseArray(data);
List<CmdCallBackDTO> cmdCallBackDTOList = JSONUtil.toList(jsonArray, CmdCallBackDTO.class);
List<Integer> cidList = new ArrayList<>(cmdCallBackDTOList.size());
cmdCallBackDTOList.forEach(cmdCallBackDTO -> {
LambdaUpdateChainWrapper<DeviceInstructKeepAliveDO> updateChainWrapper = new LambdaUpdateChainWrapper<>(deviceInstructKeepAliveDao);
updateChainWrapper
.set(DeviceInstructKeepAliveDO::getState, cmdCallBackDTO.getState())
.eq(DeviceInstructKeepAliveDO::getMessageId, cmdCallBackDTO.getId())
.eq(DeviceInstructKeepAliveDO::getEquipmentId, equipmentId)
.update();
cidList.add(cmdCallBackDTO.getCid());
});
return ResponseResult.success(JSONUtil.toJsonStr(cidList));
} catch (Exception e) {
log.error("指令保活回调异常: " + equipmentId + data, e);
return ResponseResult.failure();
}
}
}
\ No newline at end of file
......@@ -84,9 +84,9 @@ public class CmdTypeConstants {
*/
public static final short ELIMINATED = 0x3A7;
/**
* 点名回调
* 保活
*/
public static final short ROLL_CALL = 0x3A8;
public static final short KEEP_ALIVE = 0x3A8;
/**
* 上传拍照
*/
......
package com.skr.mdm.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skr.mdm.bean.bo.InstructMessageBO;
import com.skr.mdm.bean.qo.cmd.CmdQO;
import com.skr.mdm.bean.vo.equipment.SendCmdMessageInfoVO;
......@@ -9,7 +10,7 @@ import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DeviceInstructKeepAliveDao {
public interface DeviceInstructKeepAliveDao extends BaseMapper<DeviceInstructKeepAliveDO> {
int deleteByPrimaryKey(Integer id);
int insert(DeviceInstructKeepAliveDO record);
......
......@@ -29,27 +29,17 @@ public class DeviceInstructKeepAliveDO implements Serializable {
/**
* 状态(1:下发中 2:下发成功)
*/
private Byte state;
private Integer state;
/**
* 1:保活 2:取消保活
*/
private Byte cmdType;
/**
* 锁屏密码
*/
private String lockScreePassword;
/**
* 离线解锁码
*/
private String offlineUnlockCode;
private Integer cmdType;
/**
* 全局标识 0:非全局 1:全局
*/
private Byte isGlobal;
private Integer isGlobal;
/**
* 公司id
......@@ -57,11 +47,6 @@ public class DeviceInstructKeepAliveDO implements Serializable {
private Integer companyId;
/**
* 1:web端 2:手机端
*/
private Byte clientType;
/**
* 创建时间
*/
private Date createTime;
......
......@@ -7,17 +7,14 @@
<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
id, equipment_id, message_id, `state`, cmd_type,
is_global, company_id, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
......@@ -55,12 +52,11 @@
</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,
cmd_type,
is_global, company_id,
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},
#{cmdType,jdbcType=TINYINT}, #{isGlobal,jdbcType=TINYINT}, #{companyId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.skr.mdm.entity.DeviceInstructKeepAliveDO" useGeneratedKeys="true">
......@@ -78,21 +74,12 @@
<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>
......@@ -113,21 +100,12 @@
<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>
......@@ -159,21 +137,12 @@
<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>
......@@ -189,11 +158,8 @@
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}
......
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