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 5e9a0ab30..0cd57e283 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 53d546796..5e95b70ce 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 000000000..8e722df2f --- /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; +}