From 370783b4574c09929adfad664bb6aacf72efdf5d Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Thu, 31 Jul 2025 18:09:20 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/domain/dto/DeviceInstructDto.java | 2 +- .../app/service/AppDeviceBizService.java | 100 ++++++++++-------- .../constants/DeviceRedisKeyConstants.java | 12 +++ .../rule/ActiveReportingDeviceDataRule.java | 9 +- ...lInfoRule.java => DeviceBootLogoRule.java} | 7 +- .../global/mqtt/rule/LocationDataRule.java | 16 ++- .../app/domain/vo/AppDeviceDetailVo.java | 26 ++++- .../equipment/domain/vo/AppDeviceVo.java | 9 ++ 8 files changed, 121 insertions(+), 60 deletions(-) create mode 100644 fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/DeviceRedisKeyConstants.java rename fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/{PersonnelInfoRule.java => DeviceBootLogoRule.java} (89%) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java index f176699..074bed3 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/DeviceInstructDto.java @@ -11,6 +11,6 @@ public class DeviceInstructDto { /** * 下发指令 */ - private Object instructValue; + private String instructValue; } diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index c5acd24..4489ba0 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -13,7 +13,6 @@ import com.fuyuanshen.app.domain.dto.APPReNameDTO; import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto; import com.fuyuanshen.app.domain.dto.DeviceInstructDto; import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo; -import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo; import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; @@ -38,12 +37,9 @@ import com.fuyuanshen.equipment.enums.BindingStatusEnum; import com.fuyuanshen.equipment.enums.CommunicationModeEnum; import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; - -import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.*; -import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal; - import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap; import com.fuyuanshen.global.mqtt.config.MqttGateway; +import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import com.fuyuanshen.global.mqtt.constants.MqttConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -53,6 +49,11 @@ import org.springframework.web.multipart.MultipartFile; import java.time.Duration; import java.util.*; +import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; +import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr; +import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData; +import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal; + @Slf4j @Service @@ -117,6 +118,31 @@ public class AppDeviceBizService { bo.setBindingUserId(userId); } Page result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo); + List records = result.getRecords(); + if(records != null && !records.isEmpty()){ + records.forEach(item -> { + if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){ + + //设备在线状态 + String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + item.getDeviceImei()); + if(StringUtils.isNotBlank(onlineStatus)){ + + item.setOnlineStatus(1); + }else{ + item.setOnlineStatus(0); + } + String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + item.getDeviceImei()); + // 获取电量 + if(StringUtils.isNotBlank(deviceStatus)){ + JSONObject jsonObject = JSONObject.parseObject(deviceStatus); + item.setBattery(jsonObject.getString("batteryPercentage")); + }else{ + item.setBattery("0"); + } + + } + }); + } return TableDataInfo.build(result); } @@ -275,44 +301,28 @@ public class AppDeviceBizService { AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class); vo.setPersonnelInfo(personnelInfoVo); } + //设备在线状态 + String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + device.getDeviceImei()); + if(StringUtils.isNotBlank(onlineStatus)){ + vo.setOnlineStatus(1); + }else{ + vo.setOnlineStatus(0); + } + String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + device.getDeviceImei()); + // 获取电量 + if(StringUtils.isNotBlank(deviceStatus)){ + JSONObject jsonObject = JSONObject.parseObject(deviceStatus); + vo.setMainLightMode(jsonObject.getString("mainLightMode")); + vo.setLaserLightMode(jsonObject.getString("laserLightMode")); + vo.setBatteryPercentage(jsonObject.getString("batteryPercentage")); + vo.setChargeState(jsonObject.getString("chargeState")); + vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime")); + }else{ + vo.setBatteryPercentage("0"); + } return vo; } - public static void main(String[] args) { - byte[] unitName = generateFixedBitmapData("富源晟科技", 120); - byte[] position = generateFixedBitmapData("研发", 120); - byte[] name = generateFixedBitmapData("张三", 120); - byte[] id = generateFixedBitmapData("123456", 120); -// int[] intUnitNames = Bitmap80x12Generator.convertHexToDecimal(unitName); -// int[] intPosition = Bitmap80x12Generator.convertHexToDecimal(position); -// int[] intNames = Bitmap80x12Generator.convertHexToDecimal(position); -// int[] intIds = Bitmap80x12Generator.convertHexToDecimal(position); -// Map map = new HashMap<>(); -// map.put("instruct", 2); -// System.out.println(JSON.toJSONString( map)); -// StringBuilder sb = new StringBuilder(); -// sb.append("[") -// buildStr(unitName, sb); -// System.out.println(sb.toString()); -// Object[] arr = new Object[]{2, Bitmap80x12Generator , Arrays.toString(name), Arrays.toString(id)}; - -// System.out.println(Arrays.deepToString(arr)); -// int[] a = new int[]{6,6,6,6,6,6}; - ArrayList intData = new ArrayList<>(); - intData.add(2); - buildArr(convertHexToDecimal(unitName), intData); - buildArr(convertHexToDecimal(position), intData); - buildArr(convertHexToDecimal(name), intData); - buildArr(convertHexToDecimal(id), intData); - intData.add(0); - intData.add(0); - intData.add(0); - intData.add(0); - Map map = new HashMap<>(); - map.put("instruct", intData); - System.out.println(JSON.toJSONString(map)); - } - public boolean registerPersonInfo(AppPersonnelInfoBo bo) { Long deviceId = bo.getDeviceId(); @@ -373,9 +383,9 @@ public class AppDeviceBizService { System.out.println("原始数据大小: " + largeData.length + " 字节"); int[] ints = convertHexToDecimal(largeData); - RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L)); + RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L)); - String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei()); + String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei()); byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512); @@ -410,7 +420,7 @@ public class AppDeviceBizService { if(device == null){ throw new ServiceException("设备不存在"); } - Integer instructValue = (Integer) params.getInstructValue(); + Integer instructValue = Integer.parseInt(params.getInstructValue()); ArrayList intData = new ArrayList<>(); intData.add(1); intData.add(instructValue); @@ -434,7 +444,7 @@ public class AppDeviceBizService { if(device == null){ throw new ServiceException("设备不存在"); } - String instructValue = (String)params.getInstructValue(); + String instructValue = params.getInstructValue(); ArrayList intData = new ArrayList<>(); intData.add(5); String[] values = instructValue.split("\\."); @@ -466,7 +476,7 @@ public class AppDeviceBizService { if(device == null){ throw new ServiceException("设备不存在"); } - Integer instructValue = (Integer) params.getInstructValue(); + Integer instructValue = Integer.parseInt(params.getInstructValue()); ArrayList intData = new ArrayList<>(); intData.add(4); intData.add(instructValue); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/DeviceRedisKeyConstants.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/DeviceRedisKeyConstants.java new file mode 100644 index 0000000..d92ec38 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/DeviceRedisKeyConstants.java @@ -0,0 +1,12 @@ +package com.fuyuanshen.global.mqtt.constants; + +public class DeviceRedisKeyConstants { + // 将设备上报状态 + public static final String DEVICE_STATUS_KEY_PREFIX = "device:status:"; + // 在线状态 + public static final String DEVICE_ONLINE_STATUS_KEY_PREFIX = "device:onlineStatus:"; + // 将设备状态信息存储到Redis中 + public static final String DEVICE_LOCATION_KEY_PREFIX = "device:location:"; + // 存储到一个列表中,保留历史位置信息 + public static final String DEVICE_LOCATION_HISTORY_KEY_PREFIX = "device:location:history:"; +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java index bad3faa..fecffbe 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java @@ -1,10 +1,12 @@ package com.fuyuanshen.global.mqtt.rule; +import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.json.utils.JsonUtils; import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.global.mqtt.base.MqttMessageRule; import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.config.MqttGateway; +import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -78,11 +80,14 @@ public class ActiveReportingDeviceDataRule implements MqttMessageRule { deviceInfo.put("timestamp", System.currentTimeMillis()); // 将设备状态信息存储到Redis中 - String deviceRedisKey = "device:status:" + deviceImei; + String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + deviceImei; String deviceInfoJson = JsonUtils.toJsonString(deviceInfo); // 存储到Redis,设置过期时间(例如24小时) - RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson, Duration.ofSeconds(24 * 60 * 60)); + RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson); + //在线状态 + String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + deviceImei; + RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1"); log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}", deviceImei, mainLightMode, laserLightMode, batteryPercentage); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/PersonnelInfoRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java similarity index 89% rename from fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/PersonnelInfoRule.java rename to fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java index eed9bde..2d605a9 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/PersonnelInfoRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java @@ -1,5 +1,6 @@ package com.fuyuanshen.global.mqtt.rule; +import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.utils.ImageToCArrayConverter; import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.json.utils.JsonUtils; @@ -26,13 +27,13 @@ import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHex @Component @RequiredArgsConstructor @Slf4j -public class PersonnelInfoRule implements MqttMessageRule { +public class DeviceBootLogoRule implements MqttMessageRule { private final MqttGateway mqttGateway; @Override public String getCommandType() { - return LightingCommandTypeConstants.PERSONNEL_INFO; + return LightingCommandTypeConstants.BOOT_LOGO; } @Override @@ -43,7 +44,7 @@ public class PersonnelInfoRule implements MqttMessageRule { return; } - String data = RedisUtils.getCacheObject("894078:app_logo_data:" + context.getDeviceImei()); + String data = RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY+"app_logo_data:" + context.getDeviceImei()); if (StringUtils.isEmpty(data)) { return; } diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java index feae373..37b4302 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java @@ -1,5 +1,6 @@ package com.fuyuanshen.global.mqtt.rule; +import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.json.utils.JsonUtils; import com.fuyuanshen.common.redis.utils.RedisUtils; @@ -8,6 +9,7 @@ import com.fuyuanshen.equipment.utils.map.LngLonUtil; import com.fuyuanshen.global.mqtt.base.MqttMessageRule; import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.config.MqttGateway; +import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants; import com.fuyuanshen.global.mqtt.constants.MqttConstants; import lombok.RequiredArgsConstructor; @@ -118,12 +120,16 @@ public class LocationDataRule implements MqttMessageRule { // 将位置信息存储到Redis中 - String redisKey = "device:location:" + deviceImei; + String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei; String locationJson = JsonUtils.toJsonString(locationInfo); // 存储到Redis - RedisUtils.setCacheObject(redisKey, locationJson, Duration.ofSeconds(24 * 60 * 60)); + RedisUtils.setCacheObject(redisKey, locationJson); + // 存储到一个列表中,保留历史位置信息 + String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei; + RedisUtils.addCacheList(locationHistoryKey, locationJson); + RedisUtils.expire(locationHistoryKey, Duration.ofDays(90)); log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude); } catch (Exception e) { log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e); @@ -138,9 +144,11 @@ public class LocationDataRule implements MqttMessageRule { ArrayList intData = new ArrayList<>(); intData.add(11); intData.add(Integer.parseInt(latArr[0])); - intData.add(Integer.parseInt(latArr[1])); + String str1 = latArr[1]; + intData.add(Integer.parseInt(str1.substring(0,4))); + String str2 = lonArr[1]; intData.add(Integer.parseInt(lonArr[0])); - intData.add(Integer.parseInt(lonArr[1])); + intData.add(Integer.parseInt(str2.substring(0,4))); Map map = new HashMap<>(); map.put("instruct", intData); diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java index d90f808..c2c3be8 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java @@ -16,11 +16,6 @@ public class AppDeviceDetailVo { @ExcelProperty(value = "设备ID") private Long deviceId; - /** - * 手机号 - */ - @ExcelProperty(value = "手机号") - private String phonenumber; /** * 设备名称 @@ -74,4 +69,25 @@ public class AppDeviceDetailVo { * 发送信息 */ private String sendMsg; + + //"{\"deviceImei\":\"AA\",\"mainLightMode\":\"1\",\"laserLightMode\":\"0\",\"batteryPercentage\":\"60\",\"chargeState\":\"1\",\"batteryRemainingTime\":\"200\",\"timestamp\":1753871635241}" + //设备主灯档位 + private String mainLightMode; + + //激光灯档位 + private String laserLightMode; + + //电量百分比 + private String batteryPercentage; + + //充电状态(0没有充电,1正在充电,2为已充满) + private String chargeState; + + //电池剩余续航时间200分钟 + private String batteryRemainingTime; + + /** + * 在线状态(0离线,1在线) + */ + private Integer onlineStatus; } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java index e948312..ac35877 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java @@ -57,4 +57,13 @@ public class AppDeviceVo implements Serializable { */ private Date bindingTime; + /** + * 在线状态(0离线,1在线) + */ + private Integer onlineStatus; + + /** + * 电量 百分比 + */ + private String battery; } From 74be5321ec9b2a98d252d1f2e223f6bb866939d7 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Thu, 31 Jul 2025 19:03:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/AppAuthController.java | 9 ++++++++ .../app/service/AppDeviceBizService.java | 11 ++++++++++ .../app/service/AppLoginService.java | 22 ++++++++++++++++++- .../app/domain/vo/AppDeviceDetailVo.java | 9 ++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java index 9d32a5a..d483e45 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppAuthController.java @@ -104,6 +104,15 @@ public class AppAuthController { return R.ok("退出成功"); } + /** + * 用户注销 + */ + @PostMapping("/cancelAccount") + public R cancelAccount() { + loginService.cancelAccount(); + return R.ok("用户注销成功"); + } + /** * 用户注册 */ diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 4489ba0..1a0cd9d 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -18,6 +18,7 @@ import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper; import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper; +import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.exception.ServiceException; import com.fuyuanshen.common.core.utils.ImageToCArrayConverter; import com.fuyuanshen.common.core.utils.MapstructUtils; @@ -320,6 +321,16 @@ public class AppDeviceBizService { }else{ vo.setBatteryPercentage("0"); } + + // 获取经度纬度 + String locationInfo = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei(); + if(StringUtils.isNotBlank(locationInfo)){ + JSONObject jsonObject = JSONObject.parseObject(locationInfo); + vo.setLongitude((String)jsonObject.get("longitude")); + vo.setLatitude((String)jsonObject.get("latitude")); + vo.setAddress((String)jsonObject.get("address")); + } + return vo; } diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java index bd92c2b..0c86da2 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppLoginService.java @@ -51,7 +51,7 @@ public class AppLoginService { private Integer lockTime; private final ISysTenantService tenantService; - private final IAppRoleService roleService; + private final IAppUserService appUserService; /** @@ -185,4 +185,24 @@ public class AppLoginService { } } + public void cancelAccount() { + try { + AppLoginUser loginUser = AppLoginHelper.getLoginUser(); + if (ObjectUtil.isNull(loginUser)) { + return; + } + appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true); + if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) { + // 超级管理员 登出清除动态租户 + TenantHelper.clearDynamic(); + } + recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, "用户注销成功"); + } catch (NotLoginException ignored) { + } finally { + try { + StpUtil.logout(); + } catch (NotLoginException ignored) { + } + } + } } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java index c2c3be8..6478ea4 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/vo/AppDeviceDetailVo.java @@ -90,4 +90,13 @@ public class AppDeviceDetailVo { * 在线状态(0离线,1在线) */ private Integer onlineStatus; + + // 经度 + private String longitude; + + // 纬度 + private String latitude; + + // 逆解析地址 + private String address; } From 51d9d7319a920592dc7b77e9e531b77cfe1c700f Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 11:11:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?app=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=96=B0=E5=A2=9E=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E7=BB=8F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/AppDeviceBizService.java | 12 +++++++++++- .../mqtt/receiver/ReceiverMessageHandler.java | 17 ++++++++++++----- .../rule/ActiveReportingDeviceDataRule.java | 3 --- .../global/mqtt/rule/DeviceBootLogoRule.java | 2 +- .../app/service/impl/AppUserServiceImpl.java | 9 +++++++++ .../equipment/domain/vo/AppDeviceVo.java | 10 ++++++++++ 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 1a0cd9d..1815dcf 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -141,6 +141,15 @@ public class AppDeviceBizService { item.setBattery("0"); } + String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + item.getDeviceImei()); + // 获取电量 + if(StringUtils.isNotBlank(location)){ + JSONObject jsonObject = JSONObject.parseObject(location); + item.setLatitude(jsonObject.getString("latitude")); + item.setLongitude(jsonObject.getString("longitude")); + }else{ + item.setBattery("0"); + } } }); } @@ -323,7 +332,8 @@ public class AppDeviceBizService { } // 获取经度纬度 - String locationInfo = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei(); + String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei(); + String locationInfo = RedisUtils.getCacheObject(locationKey); if(StringUtils.isNotBlank(locationInfo)){ JSONObject jsonObject = JSONObject.parseObject(locationInfo); vo.setLongitude((String)jsonObject.get("longitude")); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java index f7619a6..5baddf6 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java @@ -1,10 +1,14 @@ package com.fuyuanshen.global.mqtt.receiver; import cn.hutool.core.lang.Dict; +import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.utils.ImageToCArrayConverter; +import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.json.utils.JsonUtils; +import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.base.MqttRuleEngine; +import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; @@ -37,16 +41,19 @@ public class ReceiverMessageHandler implements MessageHandler { if (receivedTopic == null || payloadDict == null) { return; } - + String[] subStr = receivedTopic.split("/"); + String deviceImei = subStr[1]; + if(StringUtils.isNotBlank(deviceImei)){ + //在线状态 + String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + deviceImei; + RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1"); + } + String state = payloadDict.getStr("state"); Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state); if (convertArr.length > 0) { Byte val1 = (Byte) convertArr[0]; - String[] subStr = receivedTopic.split("/"); - System.out.println("收到设备id: " + subStr[1]); - String deviceImei = subStr[1]; - MqttRuleContext context = new MqttRuleContext(); context.setCommandType(val1); context.setConvertArr(convertArr); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java index fecffbe..6b37a47 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/ActiveReportingDeviceDataRule.java @@ -85,9 +85,6 @@ public class ActiveReportingDeviceDataRule implements MqttMessageRule { // 存储到Redis,设置过期时间(例如24小时) RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson); - //在线状态 - String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + deviceImei; - RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1"); log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}", deviceImei, mainLightMode, laserLightMode, batteryPercentage); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java index 2d605a9..8b83e0f 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/DeviceBootLogoRule.java @@ -52,7 +52,7 @@ public class DeviceBootLogoRule implements MqttMessageRule { byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512); System.out.println("第" + val2 + "块数据大小: " + specificChunk.length + " 字节"); - System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk)); +// System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk)); ArrayList intData = new ArrayList<>(); intData.add(3); diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppUserServiceImpl.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppUserServiceImpl.java index a362fe4..5c18916 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppUserServiceImpl.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/AppUserServiceImpl.java @@ -1,5 +1,10 @@ package com.fuyuanshen.app.service.impl; +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.util.ObjectUtil; +import com.fuyuanshen.common.core.constant.Constants; +import com.fuyuanshen.common.core.domain.model.AppLoginUser; import com.fuyuanshen.common.core.utils.MapstructUtils; import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; @@ -7,6 +12,9 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.fuyuanshen.common.satoken.utils.AppLoginHelper; +import com.fuyuanshen.common.satoken.utils.LoginHelper; +import com.fuyuanshen.common.tenant.helper.TenantHelper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -16,6 +24,7 @@ import com.fuyuanshen.app.domain.AppUser; import com.fuyuanshen.app.mapper.AppUserMapper; import com.fuyuanshen.app.service.IAppUserService; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Collection; diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java index ac35877..1642c7f 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AppDeviceVo.java @@ -66,4 +66,14 @@ public class AppDeviceVo implements Serializable { * 电量 百分比 */ private String battery; + + /** + * 纬度 + */ + private String latitude; + + /** + * 经度 + */ + private String longitude; } From 6fb8e73535610c0bc038da5ca668f5d09e0e2b14 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 14:24:03 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=BB=8F=E7=BA=AC=E5=BA=A6bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LightingCommandTypeConstants.java | 34 +------------------ .../global/mqtt/rule/LocationDataRule.java | 2 +- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/LightingCommandTypeConstants.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/LightingCommandTypeConstants.java index 5687f33..64c8449 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/LightingCommandTypeConstants.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/constants/LightingCommandTypeConstants.java @@ -40,37 +40,5 @@ public class LightingCommandTypeConstants { * 主动上报设备数据 (Active Reporting Device Data) */ public static final String ACTIVE_REPORTING_DEVICE_DATA = "Light_12"; - - /** - * 获取命令类型描述 - * - * @param commandType 命令类型 - * @return 命令类型描述 - */ - public static String getCommandTypeDescription(String commandType) { - return switch (commandType) { - case LIGHT_MODE -> "灯光模式 (Light Mode)"; - case PERSONNEL_INFO -> "人员信息 (Personnel Information)"; - case BOOT_LOGO -> "开机LOGO (Boot Logo)"; - case LASER_LIGHT -> "激光灯 (Laser Light)"; - case MAIN_LIGHT_BRIGHTNESS -> "主灯亮度 (Main Light Brightness)"; - case LOCATION_DATA -> "定位数据 (Location Data)"; - default -> "未知命令类型 (Unknown Command Type)"; - }; - } - - /** - * 检查是否为有效命令类型 - * - * @param commandType 命令类型 - * @return 是否有效 - */ - public static boolean isValidCommandType(String commandType) { - return commandType.equals(LIGHT_MODE) || - commandType.equals(PERSONNEL_INFO) || - commandType.equals(BOOT_LOGO) || - commandType.equals(LASER_LIGHT) || - commandType.equals(MAIN_LIGHT_BRIGHTNESS) || - commandType.equals(LOCATION_DATA); - } + } diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java index 37b4302..94499cf 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java @@ -105,7 +105,7 @@ public class LocationDataRule implements MqttMessageRule { public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) { CompletableFuture.runAsync(() -> { try { - if(StringUtils.isNotBlank(latitude) || StringUtils.isNotBlank(longitude)){ + if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){ return; } // 构造位置信息对象