设备控制完善日志
parent
29ba2bd5bb
commit
f6bf679a77
|
|
@ -42,6 +42,10 @@ public class SysUser extends BaseEntity
|
|||
@Excel(name = "部门编号", type = Type.IMPORT)
|
||||
private Long deptId;
|
||||
|
||||
/** 用户账号 */
|
||||
@Excel(name = "clientId")
|
||||
private String clientId;
|
||||
|
||||
/** 用户账号 */
|
||||
@Excel(name = "登录名称")
|
||||
private String userName;
|
||||
|
|
@ -115,6 +119,15 @@ public class SysUser extends BaseEntity
|
|||
|
||||
}
|
||||
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public SysUser(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
|
|
@ -334,6 +347,7 @@ public class SysUser extends BaseEntity
|
|||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("userId", getUserId())
|
||||
.append("deptId", getDeptId())
|
||||
.append("clientId", getClientId())
|
||||
.append("userName", getUserName())
|
||||
.append("nickName", getNickName())
|
||||
.append("email", getEmail())
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package com.agri.framework.interceptor;
|
||||
|
||||
import com.agri.common.core.domain.entity.SysUser;
|
||||
import com.agri.framework.config.MqttConfig;
|
||||
import com.agri.framework.manager.MqttAutoOffManager;
|
||||
import com.agri.system.domain.SysAgriInfo;
|
||||
import com.agri.system.domain.SysAgriLimit;
|
||||
import com.agri.system.domain.SysDevOperLog;
|
||||
import com.agri.system.mapper.SysUserMapper;
|
||||
import com.agri.system.service.ISysAgriInfoService;
|
||||
import com.agri.system.service.ISysAgriLimitService;
|
||||
import com.agri.system.service.ISysDevOperLogService;
|
||||
import com.agri.system.service.ISysUserService;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
|
|
@ -67,6 +70,8 @@ public class FrontendControlHandler {
|
|||
@Autowired
|
||||
private ISysDevOperLogService sysDevOperLogService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Value("${spring.mqtt.dtu-ctl-lock-ttl}")
|
||||
private int dtuCtlLockTTL;
|
||||
|
|
@ -144,7 +149,7 @@ public class FrontendControlHandler {
|
|||
);
|
||||
if (lockSuccess == null || !lockSuccess) {
|
||||
String errorTopic = "frontend/" + clientId + "/dtu/" + deviceId + "/listener";
|
||||
mqttMessageSender.publish(errorTopic, "{\"msg\":\"设备" + funcType + "功能忙,请稍后重试\"}");
|
||||
mqttMessageSender.publish(errorTopic, "{\"msg\":\"设备" + funcType + "功能忙,请稍后重试\",\"clientId\":"+clientId+"}");
|
||||
log.warn("【分布式锁】前端{}操作设备{}的{}功能失败;可能其他用户正在操作此功能", clientId, deviceId, funcType);
|
||||
return;
|
||||
}
|
||||
|
|
@ -152,11 +157,13 @@ public class FrontendControlHandler {
|
|||
// 3. 记录日志
|
||||
log.info("【指令处理】前端{}于{}控制设备{}的{}功能,指令:{}",
|
||||
clientId, LocalDateTime.now(), deviceId, funcType, payload);
|
||||
|
||||
|
||||
//todo
|
||||
mqttMessageSender.publish(deviceTopic, payload);
|
||||
|
||||
SysUser sysUser = sysUserService.lambdaQuery()
|
||||
.eq(SysUser::getClientId, clientId)
|
||||
.one();
|
||||
String operator = "手动控制";
|
||||
if (sysUser!=null) {
|
||||
operator = sysUser.getUserName();
|
||||
}
|
||||
SysAgriInfo agriInfo = sysAgriInfoService.lambdaQuery()
|
||||
.eq(SysAgriInfo::getImei, deviceId)
|
||||
.one();
|
||||
|
|
@ -170,9 +177,10 @@ public class FrontendControlHandler {
|
|||
logDto.setPayload(payload);
|
||||
logDto.setLockAcquired(1);
|
||||
logDto.setLockHolder(clientId);
|
||||
logDto.setExecResult(1);
|
||||
logDto.setCreateBy("手动控制");
|
||||
boolean save = sysDevOperLogService.save(logDto);
|
||||
logDto.setCreateBy(operator);
|
||||
sysDevOperLogService.save(logDto);
|
||||
//todo
|
||||
mqttMessageSender.publish(deviceTopic, payload);
|
||||
// if (save) {
|
||||
// testAutoOffTask(deviceId,funcCodeMap);
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.agri.framework.manager;
|
||||
|
||||
import com.agri.common.core.domain.entity.SysUser;
|
||||
import com.agri.common.utils.SecurityUtils;
|
||||
import com.agri.system.domain.SysAgriInfo;
|
||||
import com.agri.system.service.ISysAgriInfoService;
|
||||
import com.agri.system.service.ISysUserService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
|
|
@ -45,6 +48,9 @@ public class MqttSubscriptionManager {
|
|||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 农业信息服务,查询用户名下设备
|
||||
*/
|
||||
|
|
@ -171,6 +177,14 @@ public class MqttSubscriptionManager {
|
|||
return 0;
|
||||
}
|
||||
Long userId = SecurityUtils.getLoginUser().getUserId();
|
||||
boolean update = sysUserService.lambdaUpdate()
|
||||
.eq(SysUser::getUserId, userId)
|
||||
.set(SysUser::getClientId, clientId)
|
||||
.update();
|
||||
if (update) {
|
||||
log.info("【全量订阅】用户端mqtt客户端绑定成功!");
|
||||
}
|
||||
|
||||
// 3. 查询该用户名下的所有设备ID(替换为你的实际设备查询逻辑)
|
||||
List<String> deviceIds = new ArrayList<>(queryImeiByUserId(userId));
|
||||
if (userId == 1) {
|
||||
|
|
@ -308,7 +322,7 @@ public class MqttSubscriptionManager {
|
|||
// 比如:return deviceService.listDeviceIdsByUserId(userId);
|
||||
SysAgriInfo sysAgriInfo = new SysAgriInfo();
|
||||
if (!SecurityUtils.isAdmin()) {
|
||||
sysAgriInfo.setUserId(SecurityUtils.getUserId());
|
||||
sysAgriInfo.setUserId(userId);
|
||||
}
|
||||
List<SysAgriInfo> agriInfos = agriInfoService.findAgriByUser(sysAgriInfo);
|
||||
if (CollectionUtils.isEmpty(agriInfos)) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<resultMap type="SysUser" id="SysUserResult">
|
||||
<id property="userId" column="user_id" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="userName" column="user_name" />
|
||||
<result property="nickName" column="nick_name" />
|
||||
<result property="email" column="email" />
|
||||
|
|
@ -48,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectUserVo">
|
||||
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.remark,
|
||||
select u.user_id, u.dept_id, u.client_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.remark,
|
||||
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
|
||||
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
|
||||
from sys_user u
|
||||
|
|
@ -58,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</sql>
|
||||
|
||||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
|
||||
select u.user_id, u.dept_id, u.client_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
where u.del_flag = '0'
|
||||
<if test="userId != null and userId != 0">
|
||||
|
|
@ -67,6 +68,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="clientId != null and clientId != ''">
|
||||
AND u.client_id like concat('%', #{clientId}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND u.status = #{status}
|
||||
</if>
|
||||
|
|
@ -87,7 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
select distinct u.user_id, u.dept_id, u.client_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
|
|
@ -99,12 +103,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<if test="clientId != null and clientId != ''">
|
||||
AND u.client_id like concat('%', #{clientId}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
|
||||
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
select distinct u.user_id, u.dept_id, u.client_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
|
|
@ -117,6 +124,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="phonenumber != null and phonenumber != ''">
|
||||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
<if test="clientId != null and clientId != ''">
|
||||
AND u.client_id like concat('%', #{clientId}, '%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue