瀏覽代碼

:space_invader:feat: 热更新的信息录入和获取

Ritchie 1 年之前
父節點
當前提交
2a89db5a4c

文件差異過大導致無法顯示
+ 1 - 1
src/main/java/com/szwl/aspect/MyWebMvcConfigurer.java


+ 0 - 11
src/main/java/com/szwl/controller/TAdminController.java

@@ -710,9 +710,7 @@ public class TAdminController {
     @ApiOperation(value = "获取账号信息")
     @GetMapping("/getAdmin")
     public ResponseModel<TAdmin> getAdmin(@RequestParam String id) {
-//        TAdmin tAdmin = tAdminService.getById(id);
         LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
-//        query.eq(TAdmin::getUsername,username);
         query.eq(TAdmin::getId, id);
         TAdmin tAdmin = Optional.ofNullable(tAdminService.getOnly(query))
                 .orElseThrow(() -> new BizException(ResponseCodesEnum.L0002));
@@ -723,15 +721,6 @@ public class TAdminController {
         }
         UserDetailBO userDetailBO = BeanUtil.copyProperties(tAdmin, UserDetailBO.class);
 
-//        String token = IdUtil.simpleUUID();
-//        userDetailBO.setCurrentToken(token);
-//        // 获取拥有的权限菜单
-//        Set<String> menuList = sysRoleService.listAuthMenuByUserId(userDetailBO.getId());
-//        userDetailBO.setMenuCodeList(CollUtil.newArrayList(menuList));
-        // 抹除密码
-//        userDetailBO.setPassword(null);
-        // 保存到redis
-//        tokenManager.saveAuthentication(token,userDetailBO);
         return R.ok(userDetailBO);
     }
 

+ 1 - 1
src/main/java/com/szwl/controller/TEquipmentDescController.java

@@ -28,7 +28,7 @@ import java.util.List;
  * </p>
  *
  * @author wuhs
- * @since 2022-04-23
+ * @since 2024-01-18
  */
 @RestController
 @RequestMapping("/tEquipmentDesc")

+ 204 - 0
src/main/java/com/szwl/controller/THotUpdateController.java

@@ -0,0 +1,204 @@
+package com.szwl.controller;
+
+
+import cn.hutool.http.HttpRequest;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.*;
+import com.szwl.model.utils.PushUtils;
+import com.szwl.service.TAdminService;
+import com.szwl.service.TEquipmentDescService;
+import com.szwl.service.TEquipmentService;
+import com.szwl.service.THotUpdateService;
+import com.szwl.util.IDGenerator;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * <p>
+ * 前端控制器
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-16
+ */
+@RestController
+@RequestMapping("/tHotUpdate")
+public class THotUpdateController {
+
+    THotUpdateService hotUpdateService;
+
+    TEquipmentService equipmentService;
+
+    TEquipmentDescService equipmentDescService;
+    TAdminService adminService;
+
+    public THotUpdateController(THotUpdateService hotUpdateService, TEquipmentService equipmentService, TEquipmentDescService equipmentDescService, TAdminService adminService) {
+        this.hotUpdateService = hotUpdateService;
+        this.equipmentService = equipmentService;
+        this.equipmentDescService = equipmentDescService;
+        this.adminService = adminService;
+    }
+
+    @ApiOperation(value = "获取补丁信息")
+    @GetMapping("/getPatchUrl")
+    public ResponseModel<?> getPatchUrl(String clientId, String isForeign) {
+        if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(isForeign)) {
+            return R.fail("参数不能为空");
+        }
+        LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(TEquipment::getClientId, clientId);
+        TEquipment equipment = equipmentService.getOne(wrapper);
+        Long adminId = equipment.getAdminId();
+        TAdmin admin = adminService.getById(adminId);
+        String ifForeign = admin.getIfForeign();
+        if (!isForeign.equals(ifForeign)) {
+            return R.fail("海外内不匹配");
+        }
+        Long equipmentId = equipment.getId();
+        LambdaQueryWrapper<TEquipmentDesc> lqw = Wrappers.lambdaQuery();
+        lqw.eq(TEquipmentDesc::getEquipmentId, equipmentId);
+        TEquipmentDesc equipmentDesc = equipmentDescService.getOne(lqw);
+        Long patchId = equipmentDesc.getPatchId();
+
+        LambdaQueryWrapper<THotUpdate> qw = Wrappers.lambdaQuery();
+        qw.eq(THotUpdate::getId, patchId);
+        THotUpdate hotUpdate = hotUpdateService.getOne(qw);
+        return R.ok(hotUpdate);
+    }
+
+    @ApiOperation(value = "录入热更新补丁信息")
+    @PostMapping("/postPatchInfo")
+    public ResponseModel<?> postPatchInfo(@RequestBody THotUpdate hotUpdate) {
+
+        String patchVersion = hotUpdate.getPatchVersion(); // 补丁版本号
+        String patchStatus = hotUpdate.getPatchStatus(); // 补丁状态,0停止,1发布
+        String targetAreas = hotUpdate.getTargetAreas(); // 目标区域,0部分设备,1国内,2海外,3全球
+        String patchLink = hotUpdate.getPatchLink(); // 补丁外链
+        String clientIdS = hotUpdate.getClientId(); // 设备编号
+        String note = hotUpdate.getNote(); // 更新内容
+
+        if (StringUtils.isEmpty(patchVersion) || StringUtils.isEmpty(patchStatus) || StringUtils.isEmpty(patchLink) || StringUtils.isEmpty(note)) {
+            return R.fail("参数不完整");
+        }
+        LambdaQueryWrapper<THotUpdate> lqwHot = Wrappers.lambdaQuery();
+        lqwHot.eq(THotUpdate::getPatchVersion, patchVersion);
+        List<THotUpdate> hotUpdates = hotUpdateService.list(lqwHot);
+        if (hotUpdates.size() > 0) {
+            return R.fail("该补丁版本号已存在");
+        }
+        THotUpdate tHotUpdate = new THotUpdate();
+        long hotUpdateId = IDGenerator.commonID();
+        tHotUpdate.setId(hotUpdateId);
+        tHotUpdate.setCreateTime(new Date());
+        tHotUpdate.setModifyTime(new Date());
+        tHotUpdate.setPatchVersion(patchVersion);
+        tHotUpdate.setPatchStatus(patchStatus);
+        tHotUpdate.setPatchLink(patchLink);
+        tHotUpdate.setTargetAreas(targetAreas);
+        tHotUpdate.setNote(note);
+
+        switch (targetAreas) {
+            case "0":
+                if (StringUtils.isEmpty(clientIdS)) {
+                    return R.fail("推送区域为空时,需要填写设备编号");
+                }
+                // 推送指定设备
+                tHotUpdate.setClientId(clientIdS);
+                String[] clientIdArray = clientIdS.split(",");
+                for (String s : clientIdArray) {
+                    String clientId = s.trim();
+                    if (StringUtils.isNotEmpty(clientId)) {
+                        LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
+                        wrapper.eq(TEquipment::getClientId, clientId);
+                        TEquipment equipment = equipmentService.getOne(wrapper);
+                        if (Objects.isNull(equipment)) {
+                            return R.fail("设备信息不存在");
+                        }
+                        Long equipmentId = equipment.getId();
+
+                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+                    }
+                }
+                break;
+            case "1":
+                // 推送国内
+                LambdaQueryWrapper<TAdmin> wrapper = Wrappers.lambdaQuery();
+                wrapper.eq(TAdmin::getIfForeign,"0");
+                List<TAdmin> list = adminService.list(wrapper);
+                for (TAdmin admin : list) {
+                    Long adminId = admin.getId();
+
+                    LambdaQueryWrapper<TEquipment> lqw = Wrappers.lambdaQuery();
+                    lqw.eq(TEquipment::getAdminId, adminId);
+                    List<TEquipment> equipmentList = equipmentService.list(lqw);
+                    for (TEquipment equipment : equipmentList) {
+                        Long equipmentId = equipment.getId();
+                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+                    }
+                }
+
+                break;
+            case "2":
+                // 推送海外
+                LambdaQueryWrapper<TAdmin> lambdaQuery = Wrappers.lambdaQuery();
+                lambdaQuery.eq(TAdmin::getIfForeign,"1");
+                List<TAdmin> abroadList = adminService.list(lambdaQuery);
+                for (TAdmin admin : abroadList) {
+                    Long adminId = admin.getId();
+                    LambdaQueryWrapper<TEquipment> lqw = Wrappers.lambdaQuery();
+                    lqw.eq(TEquipment::getAdminId, adminId);
+                    List<TEquipment> equipmentList = equipmentService.list(lqw);
+                    for (TEquipment equipment : equipmentList) {
+                        Long equipmentId = equipment.getId();
+//                        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
+//                        if (Objects.isNull(equipmentDesc)) {
+//                            TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
+//                            equipmentDesc1.setEquipmentId(equipmentId);
+//                            equipmentDesc1.setPatchId(hotUpdateId);
+//                            equipmentDescService.save(equipmentDesc1);
+//                        } else {
+//                            equipmentDesc.setPatchId(hotUpdateId);
+//                            equipmentDescService.saveOrUpdate(equipmentDesc);
+//                        }
+                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+                    }
+                }
+                break;
+            case "3":
+                // 推送全球
+                List<TEquipmentDesc> equipmentDescAll = equipmentDescService.list();
+                for (TEquipmentDesc equipmentDesc : equipmentDescAll) {
+                    equipmentDesc.setPatchId(hotUpdateId);
+                    equipmentDescService.saveOrUpdate(equipmentDesc);
+                }
+
+                break;
+            default:
+                return R.fail("不支持的推送区域参数:" + targetAreas);
+        }
+
+        hotUpdateService.save(tHotUpdate);
+
+        return R.ok("录入成功");
+    }
+
+
+    private void saveOrUpdateEquipmentDesc(Long equipmentId, Long hotUpdateId) {
+        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
+        if (Objects.isNull(equipmentDesc)) {
+            equipmentDesc = new TEquipmentDesc();
+            equipmentDesc.setEquipmentId(equipmentId);
+        }
+        equipmentDesc.setPatchId(hotUpdateId);
+        equipmentDescService.saveOrUpdate(equipmentDesc);
+    }
+}
+

+ 1 - 1
src/main/java/com/szwl/mapper/TEquipmentDescMapper.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * </p>
  *
  * @author wuhs
- * @since 2022-04-23
+ * @since 2024-01-18
  */
 public interface TEquipmentDescMapper extends BaseMapper<TEquipmentDesc> {
 

+ 16 - 0
src/main/java/com/szwl/mapper/THotUpdateMapper.java

@@ -0,0 +1,16 @@
+package com.szwl.mapper;
+
+import com.szwl.model.entity.THotUpdate;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-16
+ */
+public interface THotUpdateMapper extends BaseMapper<THotUpdate> {
+
+}

+ 2 - 1
src/main/java/com/szwl/mapper/xml/TEquipmentDescMapper.xml

@@ -30,11 +30,12 @@
         <result column="outside_hd" property="outsideHd" />
         <result column="diy_flower_status" property="diyFlowerStatus" />
         <result column="language" property="language" />
+        <result column="patch_id" property="patchId" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        equipment_id, flowers, white_sugar, red_sugar, yellow_sugar, blue_sugar, stick, water, waste_water, is_material_use, pay_type, note, status, coupon_status, out_door, in_door, sleep_desc, cup_quantity, stir_tm, corn_generator_tm, number_one, candy_generator_tm, outside_tm, outside_hd, diy_flower_status, language
+        equipment_id, flowers, white_sugar, red_sugar, yellow_sugar, blue_sugar, stick, water, waste_water, is_material_use, pay_type, note, status, coupon_status, out_door, in_door, sleep_desc, cup_quantity, stir_tm, corn_generator_tm, number_one, candy_generator_tm, outside_tm, outside_hd, diy_flower_status, language, patch_id
     </sql>
 
 </mapper>

+ 23 - 0
src/main/java/com/szwl/mapper/xml/THotUpdateMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.szwl.mapper.THotUpdateMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.szwl.model.entity.THotUpdate">
+        <id column="id" property="id" />
+        <result column="create_time" property="createTime" />
+        <result column="modify_time" property="modifyTime" />
+        <result column="patch_version" property="patchVersion" />
+        <result column="patch_status" property="patchStatus" />
+        <result column="client_id" property="clientId" />
+        <result column="note" property="note" />
+        <result column="target_areas" property="targetAreas" />
+        <result column="patch_link" property="patchLink" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, create_time, modify_time, patch_version, patch_status, client_id, note, target_areas, patch_link
+    </sql>
+
+</mapper>

+ 4 - 1
src/main/java/com/szwl/model/entity/TEquipmentDesc.java

@@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode;
  * </p>
  *
  * @author wuhs
- * @since 2023-11-06
+ * @since 2024-01-18
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -101,5 +101,8 @@ public class TEquipmentDesc implements Serializable {
     @ApiModelProperty(value = "设备当前设置语言")
     private String language;
 
+    @ApiModelProperty(value = "热更新补丁id")
+    private Long patchId;
+
 
 }

+ 53 - 0
src/main/java/com/szwl/model/entity/THotUpdate.java

@@ -0,0 +1,53 @@
+package com.szwl.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-16
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="THotUpdate对象", description="")
+public class THotUpdate implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+
+    private Date createTime;
+
+    private Date modifyTime;
+
+    @ApiModelProperty(value = "补丁版本号")
+    private String patchVersion;
+
+    @ApiModelProperty(value = "补丁状态,0停止,1发布")
+    private String patchStatus;
+
+    @ApiModelProperty(value = "设备编号")
+    private String clientId;
+
+    @ApiModelProperty(value = "更新内容")
+    private String note;
+
+    @ApiModelProperty(value = "目标区域,0部分设备,1国内,2海外,3全球")
+    private String targetAreas;
+
+    @ApiModelProperty(value = "补丁外链")
+    private String patchLink;
+
+
+}

+ 1 - 1
src/main/java/com/szwl/service/TEquipmentDescService.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * </p>
  *
  * @author wuhs
- * @since 2023-08-17
+ * @since 2024-01-18
  */
 public interface TEquipmentDescService extends IService<TEquipmentDesc> {
 

+ 16 - 0
src/main/java/com/szwl/service/THotUpdateService.java

@@ -0,0 +1,16 @@
+package com.szwl.service;
+
+import com.szwl.model.entity.THotUpdate;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-16
+ */
+public interface THotUpdateService extends IService<THotUpdate> {
+
+}

+ 1 - 1
src/main/java/com/szwl/service/impl/TEquipmentDescServiceImpl.java

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
  * </p>
  *
  * @author wuhs
- * @since 2022-04-23
+ * @since 2024-01-18
  */
 @Service
 public class TEquipmentDescServiceImpl extends ServiceImpl<TEquipmentDescMapper, TEquipmentDesc> implements TEquipmentDescService {

+ 20 - 0
src/main/java/com/szwl/service/impl/THotUpdateServiceImpl.java

@@ -0,0 +1,20 @@
+package com.szwl.service.impl;
+
+import com.szwl.model.entity.THotUpdate;
+import com.szwl.mapper.THotUpdateMapper;
+import com.szwl.service.THotUpdateService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-16
+ */
+@Service
+public class THotUpdateServiceImpl extends ServiceImpl<THotUpdateMapper, THotUpdate> implements THotUpdateService {
+
+}