forked from dyf/fys-Multi-tenant
Merge remote-tracking branch 'origin/6170' into 6170
This commit is contained in:
@ -25,6 +25,7 @@ public class OnlineStatusTask {
|
|||||||
@Scheduled(cron = "0 */3 * * * ?")
|
@Scheduled(cron = "0 */3 * * * ?")
|
||||||
public void cronTask() {
|
public void cronTask() {
|
||||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("online_status", 1);
|
||||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||||
devices.forEach(item -> {
|
devices.forEach(item -> {
|
||||||
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||||
|
|||||||
@ -179,7 +179,7 @@ public class DeviceBizService {
|
|||||||
}
|
}
|
||||||
Device device = devices.get(0);
|
Device device = devices.get(0);
|
||||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||||
throw new RuntimeException("设备已绑定");
|
throw new RuntimeException("设备已经被绑定!");
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||||
@ -189,7 +189,6 @@ public class DeviceBizService {
|
|||||||
if (appDeviceBindRecord != null) {
|
if (appDeviceBindRecord != null) {
|
||||||
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||||
deviceUpdateWrapper.eq("device_id", device.getId())
|
deviceUpdateWrapper.eq("device_id", device.getId())
|
||||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
||||||
.set("binding_user_id", userId)
|
.set("binding_user_id", userId)
|
||||||
.set("communication_mode", 0)
|
.set("communication_mode", 0)
|
||||||
.set("update_time", new Date())
|
.set("update_time", new Date())
|
||||||
@ -283,6 +282,25 @@ public class DeviceBizService {
|
|||||||
.set("binding_time", null);
|
.set("binding_time", null);
|
||||||
deviceMapper.update(null, deviceUpdateWrapper);
|
deviceMapper.update(null, deviceUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||||
|
brqWrapper.eq("device_id", device.getId());
|
||||||
|
brqWrapper.eq("binding_user_id", userId);
|
||||||
|
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||||
|
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||||
|
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||||
|
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||||
|
}
|
||||||
|
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||||
|
if(appUserVo != null){
|
||||||
|
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||||
|
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||||
|
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||||
|
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||||
|
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||||
|
appDeviceShareList.forEach(appDeviceShare ->
|
||||||
|
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||||
@ -296,25 +314,17 @@ public class DeviceBizService {
|
|||||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||||
.set("binding_time", null);
|
.set("binding_time", null);
|
||||||
deviceMapper.update(null, deviceUpdateWrapper);
|
deviceMapper.update(null, deviceUpdateWrapper);
|
||||||
}
|
|
||||||
|
|
||||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||||
brqWrapper.eq("device_id", device.getId());
|
brqWrapper.eq("device_id", device.getId());
|
||||||
if(userId != null){
|
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||||
brqWrapper.eq("binding_user_id", userId);
|
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||||
}
|
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||||
|
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
|
||||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
|
||||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
|
||||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
|
||||||
if(appUserVo != null){
|
|
||||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
|
||||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||||
appDeviceShareList.forEach(appDeviceShare ->
|
appDeviceShareList.forEach(appDeviceShare ->
|
||||||
@ -384,7 +394,7 @@ public class DeviceBizService {
|
|||||||
|
|
||||||
String deviceImei = device.getDeviceImei();
|
String deviceImei = device.getDeviceImei();
|
||||||
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||||
Collection<String> list = RedisUtils.zRangeByScore(a, startTime, endTime);
|
Collection<String> list = RedisUtils.zRangeByScoreDesc(a, startTime, endTime);
|
||||||
if (CollectionUtil.isEmpty(list)) {
|
if (CollectionUtil.isEmpty(list)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -394,6 +394,26 @@ public class RedisUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 根据时间范围查询Sorted Set中的元素并降序排列
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @param startTime 开始时间戳
|
||||||
|
* @param endTime 结束时间戳
|
||||||
|
* @return 指定时间范围内的元素集合(降序)
|
||||||
|
*/
|
||||||
|
public static Collection<String> zRangeByScoreDesc(String key, Long startTime, Long endTime) {
|
||||||
|
try {
|
||||||
|
RScoredSortedSet<String> sortedSet = CLIENT.getScoredSortedSet(key);
|
||||||
|
// 使用 valueRangeReversed 方法获取降序排列的结果
|
||||||
|
return sortedSet.valueRangeReversed(startTime, true, endTime, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 记录错误日志(如果项目中有日志工具的话)
|
||||||
|
// log.error("根据时间范围查询Sorted Set中的元素失败: key={}, startTime={}, endTime={}, error={}",
|
||||||
|
// key, startTime, endTime, e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -311,7 +311,7 @@
|
|||||||
AND a.device_name like concat('%',#{bo.deviceName},'%')
|
AND a.device_name like concat('%',#{bo.deviceName},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="bo.deviceMac != null and bo.deviceMac != ''">
|
<if test="bo.deviceMac != null and bo.deviceMac != ''">
|
||||||
AND a.device_mac = #{bo.deviceMac}
|
AND a.device_mac like concat('%',#{bo.deviceMac},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="bo.deviceImei != null and bo.deviceImei != ''">
|
<if test="bo.deviceImei != null and bo.deviceImei != ''">
|
||||||
and a.device_imei like concat('%',#{bo.deviceImei}, '%')
|
and a.device_imei like concat('%',#{bo.deviceImei}, '%')
|
||||||
|
|||||||
Reference in New Issue
Block a user