Compare commits

7 Commits

Author SHA1 Message Date
1e4ee840a3 Merge branch 'dyf-device' into 6170 2025-09-06 11:48:00 +08:00
b945420446 离线状态变更3 2025-09-05 13:32:32 +08:00
c057af7cd0 离线状态变更2 2025-09-05 11:46:29 +08:00
452c37c4ca 离线状态变更 2025-09-04 18:40:08 +08:00
429c0f1307 Merge branch 'dyf-device' into 6170 2025-09-04 11:29:55 +08:00
377579dd14 Merge branch 'dyf-device' into 6170 2025-09-03 15:57:21 +08:00
98cb67b136 修改获取经纬度 2025-09-03 15:11:24 +08:00
8 changed files with 77 additions and 36 deletions

View File

@ -1,23 +1,37 @@
package com.fuyuanshen.global.mqtt.listener;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
@Component
@Slf4j
public class RedisKeyExpirationListener implements MessageListener {
@Autowired
@Qualifier("threadPoolTaskExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private DeviceMapper deviceMapper;
@Override
public void onMessage(Message message, byte[] pattern) {
String expiredKey = new String(message.getBody());
@ -26,8 +40,17 @@ public class RedisKeyExpirationListener implements MessageListener {
String element = expiredKey.substring(FUNCTION_ACCESS_KEY.length());
handleFunctionAccessExpired(element);
}
if(expiredKey.endsWith(DEVICE_ONLINE_STATUS_KEY_PREFIX)){
threadPoolTaskExecutor.execute(() -> {
log.info("设备离线:{}", expiredKey);
String element = expiredKey.substring(GlobalConstants.GLOBAL_REDIS_KEY.length() + DEVICE_KEY_PREFIX.length(), expiredKey.length() - DEVICE_ONLINE_STATUS_KEY_PREFIX.length());
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("device_imei", element);
deviceUpdateWrapper.set("online_status", 0);
deviceMapper.update(deviceUpdateWrapper);
});
}
}
/**
* 访问key过期事件
* @param element 批次ID

View File

@ -117,28 +117,28 @@ public class BjqLocationDataRule implements MqttMessageRule {
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
return;
}
String[] latArr = latitude.split("\\.");
String[] lonArr = longitude.split("\\.");
// 将位置信息存储到Redis中
// String[] latArr = latitude.split("\\.");
// String[] lonArr = longitude.split("\\.");
// // 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
String redisObj = RedisUtils.getCacheObject(redisKey);
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
if(jsonOBj != null){
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
String[] latArr1 = cacheLatitude.split("\\.");
String[] lonArr1 = cacheLongitude.split("\\.");
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
return;
}
}
// String redisObj = RedisUtils.getCacheObject(redisKey);
// JSONObject jsonOBj = JSONObject.parseObject(redisObj);
// if(jsonOBj != null){
// String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
// String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
//
// String cacheLatitude = jsonOBj.getString("wgs84_latitude");
// String cacheLongitude = jsonOBj.getString("wgs84_longitude");
// String[] latArr1 = cacheLatitude.split("\\.");
// String[] lonArr1 = cacheLongitude.split("\\.");
//
// String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
// String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
// if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
// log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
// return;
// }
// }
// 构造位置信息对象
Map<String, Object> locationInfo = new LinkedHashMap<>();

View File

@ -2,15 +2,16 @@ package com.fuyuanshen.web.controller.device;
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.web.service.DeviceShareService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 设备分享管理
@ -37,5 +38,12 @@ public class DeviceShareController extends BaseController {
}
/**
* 新增设备分享
*/
@RepeatSubmit()
@PostMapping("/deviceShare")
public R<Void> deviceShare(@Validated(AddGroup.class) @RequestBody AppDeviceShareBo bo) {
return toAjax(appDeviceShareService.deviceShare(bo));
}
}

View File

@ -100,7 +100,6 @@ public class DeviceBJQBizService {
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", deviceId)
.eq("binding_user_id", AppLoginHelper.getUserId())
.set("send_msg", bo.getSendMsg());
deviceMapper.update(updateWrapper);
@ -538,6 +537,6 @@ public class DeviceBJQBizService {
private boolean getDeviceStatus(String deviceImei) {
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
return StringUtils.isBlank(deviceOnlineStatusRedisKey);
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
}
}

View File

@ -330,10 +330,10 @@ public class DeviceXinghanBizService {
AppLoginHelper.getUserId());
}
private boolean isDeviceOffline(String imei) {
// 原方法名语义相反,这里取反,使含义更清晰
return getDeviceStatus(imei);
}
// private boolean isDeviceOffline(String imei) {
// // 原方法名语义相反,这里取反,使含义更清晰
// return getDeviceStatus(imei);
// }
/**
* 记录设备操作日志
@ -359,9 +359,9 @@ public class DeviceXinghanBizService {
}
}
private boolean getDeviceStatus(String deviceImei) {
private boolean isDeviceOffline(String deviceImei) {
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
return StringUtils.isBlank(deviceOnlineStatusRedisKey);
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey)==null;
}
}

View File

@ -114,4 +114,10 @@ public class DeviceQueryCriteria extends BaseEntity {
private String content;
/**
* 设备在线状态
* 0:离线;1:在线
*/
private Integer onlineStatus;
}

View File

@ -103,6 +103,7 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource());
lqw.like(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
lqw.in(CollectionUtil.isNotEmpty(bo.getDeviceIds()), DeviceLog::getDeviceId, bo.getDeviceIds());
lqw.orderByDesc(DeviceLog::getCreateTime);
return lqw;
}

View File

@ -281,6 +281,10 @@
<if test="criteria.groupId != null">
and d.group_id = #{criteria.groupId}
</if>
<if test="criteria.onlineStatus != null">
and d.online_status = #{criteria.onlineStatus}
</if>
ORDER BY d.create_time DESC
</select>
<select id="getLocationHistory" resultType="com.fuyuanshen.equipment.domain.vo.LocationHistoryVo">
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a