设备分享
This commit is contained in:
@ -83,7 +83,7 @@ public class AppDeviceXinghanController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SOS档位
|
* SOS档位s
|
||||||
* SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
* SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||||
*/
|
*/
|
||||||
@PostMapping("/SOSGradeSettings")
|
@PostMapping("/SOSGradeSettings")
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.fuyuanshen.global.mqtt.listener;
|
package com.fuyuanshen.global.mqtt.listener;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import com.baomidou.lock.LockInfo;
|
||||||
|
import com.baomidou.lock.LockTemplate;
|
||||||
|
import com.baomidou.lock.executor.RedissonLockExecutor;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
@ -32,6 +36,9 @@ public class RedisKeyExpirationListener implements MessageListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DeviceMapper deviceMapper;
|
private DeviceMapper deviceMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LockTemplate lockTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(Message message, byte[] pattern) {
|
public void onMessage(Message message, byte[] pattern) {
|
||||||
String expiredKey = new String(message.getBody());
|
String expiredKey = new String(message.getBody());
|
||||||
@ -40,16 +47,43 @@ public class RedisKeyExpirationListener implements MessageListener {
|
|||||||
String element = expiredKey.substring(FUNCTION_ACCESS_KEY.length());
|
String element = expiredKey.substring(FUNCTION_ACCESS_KEY.length());
|
||||||
handleFunctionAccessExpired(element);
|
handleFunctionAccessExpired(element);
|
||||||
}
|
}
|
||||||
if(expiredKey.endsWith(DEVICE_ONLINE_STATUS_KEY_PREFIX)){
|
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);
|
||||||
|
// });
|
||||||
|
|
||||||
threadPoolTaskExecutor.execute(() -> {
|
threadPoolTaskExecutor.execute(() -> {
|
||||||
log.info("设备离线:{}", expiredKey);
|
log.info("设备离线:{}", expiredKey);
|
||||||
String element = expiredKey.substring(GlobalConstants.GLOBAL_REDIS_KEY.length() + DEVICE_KEY_PREFIX.length(), expiredKey.length() - DEVICE_ONLINE_STATUS_KEY_PREFIX.length());
|
String element = expiredKey.substring(GlobalConstants.GLOBAL_REDIS_KEY.length() + DEVICE_KEY_PREFIX.length(), expiredKey.length() - DEVICE_ONLINE_STATUS_KEY_PREFIX.length());
|
||||||
|
|
||||||
|
// 构造设备锁键
|
||||||
|
String deviceLockKey = GlobalConstants.GLOBAL_REDIS_KEY + ":device_lock:" + element;
|
||||||
|
|
||||||
|
// 尝试获取Redis锁
|
||||||
|
LockInfo lockInfo = lockTemplate.lock(deviceLockKey, 30000L, 5000L, RedissonLockExecutor.class); // 30秒过期
|
||||||
|
|
||||||
|
if (lockInfo != null) {
|
||||||
|
try {
|
||||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||||
deviceUpdateWrapper.eq("device_imei", element);
|
deviceUpdateWrapper.eq("device_imei", element);
|
||||||
deviceUpdateWrapper.set("online_status", 0);
|
deviceUpdateWrapper.set("online_status", 0);
|
||||||
deviceMapper.update(deviceUpdateWrapper);
|
deviceMapper.update(deviceUpdateWrapper);
|
||||||
|
} finally {
|
||||||
|
//释放锁
|
||||||
|
lockTemplate.releaseLock(lockInfo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("无法获取设备锁,跳过设备离线处理: {}", element);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 访问key过期事件
|
* 访问key过期事件
|
||||||
|
@ -1,20 +1,35 @@
|
|||||||
package com.fuyuanshen.web.controller.device;
|
package com.fuyuanshen.web.controller.device;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||||
|
import com.fuyuanshen.common.core.constant.Constants;
|
||||||
import com.fuyuanshen.common.core.domain.R;
|
import com.fuyuanshen.common.core.domain.R;
|
||||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import com.fuyuanshen.common.ratelimiter.annotation.RateLimiter;
|
||||||
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
import com.fuyuanshen.common.web.core.BaseController;
|
import com.fuyuanshen.common.web.core.BaseController;
|
||||||
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
|
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
|
||||||
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
||||||
import com.fuyuanshen.web.service.DeviceShareService;
|
import com.fuyuanshen.web.service.DeviceShareService;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.sms4j.api.SmsBlend;
|
||||||
|
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||||
|
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.DEVICE_SHARE_CODES_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备分享管理
|
* 设备分享管理
|
||||||
*
|
*
|
||||||
@ -31,12 +46,11 @@ public class DeviceShareController extends BaseController {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*查询设备分享列表(web)
|
* 分享管理列表
|
||||||
*/
|
*/
|
||||||
// @SaCheckPermission("equipment:alarm:list")
|
@GetMapping("/deviceShareList")
|
||||||
@GetMapping("/list")
|
|
||||||
public TableDataInfo<AppDeviceShareVo> list(AppDeviceShareBo bo, PageQuery pageQuery) {
|
public TableDataInfo<AppDeviceShareVo> list(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||||
return appDeviceShareService.queryWebList(bo, pageQuery);
|
return appDeviceShareService.queryWebPageList(bo, pageQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,4 +62,37 @@ public class DeviceShareController extends BaseController {
|
|||||||
public R<Void> deviceShare(@Validated(AddGroup.class) @RequestBody AppDeviceShareBo bo) {
|
public R<Void> deviceShare(@Validated(AddGroup.class) @RequestBody AppDeviceShareBo bo) {
|
||||||
return toAjax(appDeviceShareService.deviceShare(bo));
|
return toAjax(appDeviceShareService.deviceShare(bo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除分享用户
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(appDeviceShareService.remove(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码
|
||||||
|
*
|
||||||
|
* @param phonenumber 用户手机号
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@RateLimiter(key = "#phonenumber", time = 60, count = 1)
|
||||||
|
@GetMapping("/sms/code")
|
||||||
|
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
|
||||||
|
String key = DEVICE_SHARE_CODES_KEY + phonenumber;
|
||||||
|
String code = RandomUtil.randomNumbers(4);
|
||||||
|
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||||
|
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||||
|
map.put("code", code);
|
||||||
|
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||||
|
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, map);
|
||||||
|
if (!smsResponse.isSuccess()) {
|
||||||
|
return R.fail(smsResponse.getData().toString());
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,16 @@ public class DeviceShareService {
|
|||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TableDataInfo<AppDeviceShareVo> queryWebPageList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||||
|
// Long userId = AppLoginHelper.getUserId();
|
||||||
|
// bo.setCreateBy(userId);
|
||||||
|
Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
||||||
|
Page<AppDeviceShareVo> result = appDeviceShareMapper.selectWebDeviceShareList(bo, page);
|
||||||
|
List<AppDeviceShareVo> records = result.getRecords();
|
||||||
|
records.forEach(DeviceShareService::buildDeviceStatus);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
private static void buildDeviceStatus(AppDeviceShareVo item) {
|
private static void buildDeviceStatus(AppDeviceShareVo item) {
|
||||||
// 设备在线状态
|
// 设备在线状态
|
||||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||||
|
@ -50,18 +50,32 @@
|
|||||||
|
|
||||||
<!-- 查询设备分享列表(web) -->
|
<!-- 查询设备分享列表(web) -->
|
||||||
<select id="selectWebDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
|
<select id="selectWebDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
|
||||||
select *
|
select d.device_name,
|
||||||
|
d.device_mac,
|
||||||
|
d.device_sn,
|
||||||
|
d.device_imei,
|
||||||
|
d.device_pic,
|
||||||
|
dt.type_name,
|
||||||
|
dt.communication_mode,
|
||||||
|
d.bluetooth_name,
|
||||||
|
dt.app_model_dictionary detailPageUrl,
|
||||||
|
c.binding_time,
|
||||||
|
ad.*,u.user_name otherPhonenumber
|
||||||
from
|
from
|
||||||
app_device_share ad
|
app_device_share ad
|
||||||
|
left join device d on ad.device_id = d.id
|
||||||
|
left join app_user u on ad.create_by = u.user_id
|
||||||
|
inner join device_type dt on d.device_type = dt.id
|
||||||
|
inner join app_device_bind_record c on d.id = c.device_id
|
||||||
<where>
|
<where>
|
||||||
<if test="bo.deviceId != null">
|
<if test="bo.deviceId != null">
|
||||||
and ad.device_id = #{bo.deviceId}
|
and ad.device_id = #{bo.deviceId}
|
||||||
</if>
|
</if>
|
||||||
<if test="bo.shareUser != null">
|
<if test="bo.shareUser != null">
|
||||||
and ad.share_user = #{bo.shareUser}
|
and u.user_name = #{bo.shareUser}
|
||||||
</if>
|
</if>
|
||||||
<if test="criteria.shareStartTime != null and criteria.hareEndTime != null">
|
<if test="criteria.shareStartTime != null and criteria.hareEndTime != null">
|
||||||
and d.create_time between #{bo.shareStartTime} and #{bo.shareEndTime}
|
and ad.create_time between #{bo.shareStartTime} and #{bo.shareEndTime}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class ${ClassName}Controller extends BaseController {
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出${functionName}列表
|
* ${functionName}列表
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("${permissionPrefix}:export")
|
@SaCheckPermission("${permissionPrefix}:export")
|
||||||
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
||||||
|
Reference in New Issue
Block a user