1
0

设备分享3

This commit is contained in:
2025-08-16 16:40:58 +08:00
parent 6d9e75d4fa
commit b51e88052f
8 changed files with 44 additions and 17 deletions

View File

@ -5,7 +5,6 @@ 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.AppDeviceShareDetailVo; import com.fuyuanshen.app.domain.vo.AppDeviceShareDetailVo;
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo; import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.app.service.AppDeviceShareService;
import com.fuyuanshen.app.service.IAppDeviceShareService; import com.fuyuanshen.app.service.IAppDeviceShareService;
import com.fuyuanshen.common.core.constant.Constants; import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.domain.R; import com.fuyuanshen.common.core.domain.R;
@ -16,6 +15,7 @@ import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.ratelimiter.annotation.RateLimiter; import com.fuyuanshen.common.ratelimiter.annotation.RateLimiter;
import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.web.service.DeviceShareService;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -45,7 +45,7 @@ public class AppDeviceShareController extends BaseController {
private final IAppDeviceShareService deviceShareService; private final IAppDeviceShareService deviceShareService;
private final AppDeviceShareService appDeviceShareService; private final DeviceShareService appDeviceShareService;
/** /**
* 分享管理列表 * 分享管理列表

View File

@ -52,7 +52,7 @@ public class AppDeviceBJQController extends BaseController {
* 发送信息 * 发送信息
*/ */
@PostMapping(value = "/sendMessage") @PostMapping(value = "/sendMessage")
@FunctionAccessBatcAnnotation("sendMessage") @FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendMessage(bo)); return toAjax(appDeviceService.sendMessage(bo));
} }
@ -61,7 +61,7 @@ public class AppDeviceBJQController extends BaseController {
* 发送报警信息 * 发送报警信息
*/ */
@PostMapping(value = "/sendAlarmMessage") @PostMapping(value = "/sendAlarmMessage")
// @FunctionAccessBatcAnnotation("sendAlarmMessage") @FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendAlarmMessage(bo)); return toAjax(appDeviceService.sendAlarmMessage(bo));
} }

View File

@ -1,8 +1,7 @@
package com.fuyuanshen.app.service; package com.fuyuanshen.web.service;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -14,11 +13,8 @@ import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
import com.fuyuanshen.app.mapper.AppDeviceShareMapper; import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.exception.ServiceException; import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.core.exception.user.CaptchaExpireException;
import com.fuyuanshen.common.core.utils.MessageUtils;
import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.core.utils.StringUtils;
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;
@ -44,7 +40,7 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
@Service @Service
public class AppDeviceShareService { public class DeviceShareService {
private final AppDeviceShareMapper appDeviceShareMapper; private final AppDeviceShareMapper appDeviceShareMapper;
@ -60,7 +56,7 @@ public class AppDeviceShareService {
Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()); Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
Page<AppDeviceShareVo> result = appDeviceShareMapper.selectAppDeviceShareList(bo, page); Page<AppDeviceShareVo> result = appDeviceShareMapper.selectAppDeviceShareList(bo, page);
List<AppDeviceShareVo> records = result.getRecords(); List<AppDeviceShareVo> records = result.getRecords();
records.forEach(AppDeviceShareService::buildDeviceStatus); records.forEach(DeviceShareService::buildDeviceStatus);
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
@ -231,7 +227,7 @@ public class AppDeviceShareService {
IPage<AppDeviceShareVo> result = appDeviceShareMapper.otherDeviceShareList(bo, page); IPage<AppDeviceShareVo> result = appDeviceShareMapper.otherDeviceShareList(bo, page);
List<AppDeviceShareVo> records = result.getRecords(); List<AppDeviceShareVo> records = result.getRecords();
records.forEach(AppDeviceShareService::buildDeviceStatus); records.forEach(DeviceShareService::buildDeviceStatus);
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }

View File

@ -64,6 +64,9 @@ public class DeviceBJQBizService {
if (device == null) { if (device == null) {
throw new ServiceException("设备不存在" + deviceId); throw new ServiceException("设备不存在" + deviceId);
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
try { try {
ClassPathResource resource = new ClassPathResource("image/background.png"); ClassPathResource resource = new ClassPathResource("image/background.png");
InputStream inputStream = resource.getInputStream(); InputStream inputStream = resource.getInputStream();
@ -139,6 +142,7 @@ public class DeviceBJQBizService {
if (device == null) { if (device == null) {
throw new RuntimeException("请先将设备入库!!!"); throw new RuntimeException("请先将设备入库!!!");
} }
AppDeviceDetailVo vo = new AppDeviceDetailVo(); AppDeviceDetailVo vo = new AppDeviceDetailVo();
vo.setDeviceId(device.getId()); vo.setDeviceId(device.getId());
vo.setDeviceName(device.getDeviceName()); vo.setDeviceName(device.getDeviceName());
@ -213,7 +217,9 @@ public class DeviceBJQBizService {
if (deviceObj == null) { if (deviceObj == null) {
throw new RuntimeException("请先将设备入库!!!"); throw new RuntimeException("请先将设备入库!!!");
} }
if(getDeviceStatus(deviceObj.getDeviceImei())){
throw new ServiceException(deviceObj.getDeviceName()+",设备已断开连接");
}
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>() QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
.eq("device_id", deviceId); .eq("device_id", deviceId);
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw); List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
@ -258,6 +264,9 @@ public class DeviceBJQBizService {
if (device == null) { if (device == null) {
throw new ServiceException("设备不存在"); throw new ServiceException("设备不存在");
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
MultipartFile file = bo.getFile(); MultipartFile file = bo.getFile();
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600); byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
@ -307,6 +316,9 @@ public class DeviceBJQBizService {
if(device == null){ if(device == null){
throw new ServiceException("设备不存在"); throw new ServiceException("设备不存在");
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
Integer instructValue = Integer.parseInt(params.getInstructValue()); Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
intData.add(1); intData.add(1);
@ -334,6 +346,9 @@ public class DeviceBJQBizService {
if(device == null){ if(device == null){
throw new ServiceException("设备不存在"); throw new ServiceException("设备不存在");
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
String instructValue = params.getInstructValue(); String instructValue = params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
intData.add(5); intData.add(5);
@ -368,6 +383,9 @@ public class DeviceBJQBizService {
if(device == null){ if(device == null){
throw new ServiceException("设备不存在"); throw new ServiceException("设备不存在");
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
Integer instructValue = Integer.parseInt(params.getInstructValue()); Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
intData.add(4); intData.add(4);
@ -407,13 +425,17 @@ public class DeviceBJQBizService {
if (deviceIds == null || deviceIds.isEmpty()) { if (deviceIds == null || deviceIds.isEmpty()) {
throw new ServiceException("请选择设备"); throw new ServiceException("请选择设备");
} }
for (Long deviceId : deviceIds) { for (Long deviceId : deviceIds) {
Device device = deviceMapper.selectById(deviceId); Device device = deviceMapper.selectById(deviceId);
if (device == null) { if (device == null) {
throw new ServiceException("设备不存在" + deviceId); throw new ServiceException("设备不存在" + deviceId);
} }
if(getDeviceStatus(device.getDeviceImei())){
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
}
try { try {
ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
intData.add(7); intData.add(7);
intData.add(Integer.parseInt(bo.getInstructValue())); intData.add(Integer.parseInt(bo.getInstructValue()));
@ -444,4 +466,9 @@ public class DeviceBJQBizService {
} }
return 1; return 1;
} }
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);
}
} }

View File

@ -8,4 +8,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface FunctionAccessAnnotation { public @interface FunctionAccessAnnotation {
String value() default ""; String value() default "";
long timeOut() default 30;
} }

View File

@ -8,4 +8,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface FunctionAccessBatcAnnotation { public @interface FunctionAccessBatcAnnotation {
String value() default ""; String value() default "";
long timeOut() default 30;
long batchMaxTimeOut() default 40;
} }

View File

@ -28,6 +28,7 @@ public class FunctionAccessAspect {
// 获取方法参数查找设备ID // 获取方法参数查找设备ID
Object[] args = joinPoint.getArgs(); Object[] args = joinPoint.getArgs();
deviceImei = extractDeviceImei(args); deviceImei = extractDeviceImei(args);
long timeout = functionAccessAnnotation.timeOut();
if (StringUtils.isNotBlank(deviceImei)) { if (StringUtils.isNotBlank(deviceImei)) {
// 生成全局Redis key // 生成全局Redis key
@ -37,7 +38,7 @@ public class FunctionAccessAspect {
throw new ServiceException("设备已存在访问限制,请稍后再试", 500); throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
} }
// //
RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofSeconds(30)); RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofSeconds(timeout));
} }
// 执行原方法 // 执行原方法

View File

@ -41,10 +41,10 @@ public class FunctionAccessBatchAspect {
throw new ServiceException("设备已存在访问限制,请稍后再试", 500); throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
} }
deviceImeiList.forEach(item->{ deviceImeiList.forEach(item->{
RedisUtils.setCacheObject(FUNCTION_ACCESS_KEY + item, "ACTIVE", Duration.ofSeconds(30)); RedisUtils.setCacheObject(FUNCTION_ACCESS_KEY + item, "ACTIVE", Duration.ofSeconds(functionAccessBatchAspect.timeOut()));
}); });
String deviceImeiListStr = JSONUtil.toJsonStr(deviceImeiList); String deviceImeiListStr = JSONUtil.toJsonStr(deviceImeiList);
RedisUtils.setCacheObject(redisKey, deviceImeiListStr , Duration.ofSeconds(40)); RedisUtils.setCacheObject(redisKey, deviceImeiListStr , Duration.ofSeconds(functionAccessBatchAspect.batchMaxTimeOut()));
} }
// 执行原方法 // 执行原方法