From 88ac0236bd1e68ba5b851e93a6afa8af7990d73d Mon Sep 17 00:00:00 2001 From: DragonWenLong <552045633@qq.com> Date: Thu, 9 Oct 2025 11:09:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E5=AE=9E=E7=8E=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= =?UTF-8?q?-Dto=20=E6=96=B0=E5=A2=9E=20SystemVersion=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BC=A0=E8=BE=93=E5=AF=B9=E8=B1=A1-=20=E4=BF=AE=E6=94=B9=20Ap?= =?UTF-8?q?pAuthController=20=E7=9A=84=20getAppVersion=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BB=8E=20Redis=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF=20-=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20DeviceXinghanController=20=E7=9A=84=20VersionSettings=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=88=B0=20Redis-=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=20FastJSON=20=E5=92=8C=20Redis=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB=E6=94=AF=E6=8C=81=E7=89=88=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E5=BA=8F=E5=88=97=E5=8C=96=E4=B8=8E=E7=BC=93?= =?UTF-8?q?=E5=AD=98=20-=20=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E6=8E=A7=E5=88=B6=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=AE=BF=E9=97=AE=20-=20=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=85=A8=E5=B1=80=20Redis=20=E9=94=AE=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/AppAuthController.java | 28 +++++++---------- .../device/DeviceXinghanController.java | 30 +++++++++++++++++++ .../web/domain/Dto/SystemVersionDto.java | 10 +++++++ 3 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 fys-admin/src/main/java/com/fuyuanshen/web/domain/Dto/SystemVersionDto.java 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 5e9a0ab..0cd57e2 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 @@ -5,6 +5,7 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson.JSON; import com.fuyuanshen.app.model.AppRegisterBody; import com.fuyuanshen.app.model.AppSmsLoginBody; import com.fuyuanshen.app.service.AppLoginService; @@ -32,6 +33,7 @@ import com.fuyuanshen.system.service.ISysClientService; import com.fuyuanshen.system.service.ISysConfigService; import com.fuyuanshen.system.service.ISysDictTypeService; import com.fuyuanshen.system.service.ISysTenantService; +import com.fuyuanshen.web.domain.Dto.SystemVersionDto; import com.fuyuanshen.web.domain.vo.LoginTenantVo; import com.fuyuanshen.web.domain.vo.LoginVo; import com.fuyuanshen.web.domain.vo.TenantListVo; @@ -54,6 +56,7 @@ import java.util.ArrayList; import java.util.List; import static com.fuyuanshen.common.core.constant.GlobalConstants.DEVICE_SHARE_CODES_KEY; +import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; /** * APP认证 @@ -261,23 +264,14 @@ public class AppAuthController { * @return */ @GetMapping("/version") - public R> getAppVersion() { - List list = dictTypeService.selectDictDataByType("app_version"); - - list.forEach(d -> { - // 1. 安全拆分 - String[] arr = d.getRemark() == null ? new String[0] : d.getRemark().split("\\|"); - if (arr.length < 2) { // 格式不对 - log.warn("字典数据 app_version 格式非法:dictLabel={}, remark={}", d.getDictLabel(), d.getRemark()); - d.setDictValue(""); // 或者 d.setDictValue(d.getDictValue()); - d.setRemark(""); // 下载地址留空 - return; // 跳过 - } - // 2. 正常赋值 - d.setDictValue(arr[0].trim()); // 版本号 - d.setRemark(arr[1].trim()); // 下载地址 - }); - + public R> getAppVersion() { + String versionKey = GLOBAL_REDIS_KEY + "System:Version:Xinghan"; + // 缓存告警消息到Redis + String versionJson = RedisUtils.getCacheObject(versionKey); + if (StringUtils.isBlank(versionJson)) { // hutool 工具,可用 StringUtils.isBlank 代替 + return R.fail(versionJson); + } + List list = JSON.parseArray(versionJson, SystemVersionDto.class); return R.ok(list); } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceXinghanController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceXinghanController.java index 53d5467..5e95b70 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceXinghanController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceXinghanController.java @@ -1,16 +1,21 @@ package com.fuyuanshen.web.controller.device; +import cn.dev33.satoken.annotation.SaCheckPermission; +import com.alibaba.fastjson.JSON; import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo; import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto; import com.fuyuanshen.app.domain.dto.DeviceInstructDto; import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo; import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.core.validate.AddGroup; import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation; import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation; +import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo; import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto; +import com.fuyuanshen.web.domain.Dto.SystemVersionDto; import com.fuyuanshen.web.domain.vo.DeviceXinghanDetailVo; import com.fuyuanshen.web.service.device.DeviceXinghanBizService; import jakarta.validation.constraints.NotNull; @@ -19,6 +24,13 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.time.Duration; +import java.util.List; + +import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; +import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_ALARM_MESSAGE_KEY_PREFIX; +import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX; + /** * 设备控制类 HBY670 */ @@ -130,4 +142,22 @@ public class DeviceXinghanController extends BaseController { deviceXinghanBizService.upShakeBitSettings(params); return R.ok(); } + + /** + * 版本更新 + */ + @SaCheckPermission("system:appVersion:up") + @PostMapping("/UpVersion") + public R VersionSettings(@RequestBody List params) { + // params 已经是 List + // 2. 转 JSON 并写 Redis,key 自己定,带个过期时间 + String versionKey = GLOBAL_REDIS_KEY + "System:Version:Xinghan"; + String json = JSON.toJSONString(params); // fastjson + if (StringUtils.isBlank(json)) { // hutool 工具,可用 StringUtils.isBlank 代替 + return R.fail("信息无效"); + } + // 缓存告警消息到Redis + RedisUtils.setCacheObject(versionKey, json, Duration.ofDays(30)); + return R.ok(); + } } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/domain/Dto/SystemVersionDto.java b/fys-admin/src/main/java/com/fuyuanshen/web/domain/Dto/SystemVersionDto.java new file mode 100644 index 0000000..8e722df --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/domain/Dto/SystemVersionDto.java @@ -0,0 +1,10 @@ +package com.fuyuanshen.web.domain.Dto; + +import lombok.Data; + +@Data +public class SystemVersionDto { + private String dictValue; + private String dictLabel; + private String remark; +}