Ver Fonte

:space_invader:feat: 热更新重写

Ritchie há 1 ano atrás
pai
commit
47479235be

+ 28 - 0
src/main/java/com/szwl/controller/ScheduledService.java

@@ -2,8 +2,12 @@ package com.szwl.controller;
 
 import cn.hutool.http.HttpUtil;
 import com.szwl.mapper.TLocationCheckMapper;
+import com.szwl.model.entity.TEquipment;
+import com.szwl.model.entity.THotUpdate;
 import com.szwl.model.entity.TLocationCheck;
 import com.szwl.service.TDepartmentService;
+import com.szwl.service.TEquipmentService;
+import com.szwl.service.THotUpdateService;
 import com.szwl.service.TLocationCheckService;
 import com.szwl.service.es.EsTCoinOrderService;
 import com.szwl.service.es.EsTOrderService;
@@ -21,6 +25,7 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Calendar;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 @Configuration //1.主要用于标记配置类,兼备Component的效果。
@@ -33,6 +38,10 @@ public class ScheduledService {
     EsTCoinOrderService esTCoinOrderService;
     @Autowired
     EsTOrderService esTOrderService;
+    @Autowired
+    THotUpdateService hotUpdateService;
+    @Autowired
+    TEquipmentService equipmentService;
 
     @Resource
     TLocationCheckMapper locationCheckMapper;
@@ -59,6 +68,25 @@ public class ScheduledService {
         }
     }
 
+    // 每天4:30去检查多少设备进行了热更新
+//    @Scheduled(cron = "0 30 4 * * ?")
+//    public void haveUpdateNum() {
+//        // 遍历所有设备的apk_version,看多少台设备的apk_version = patch_veriosn
+//        // 获取热更新表中所有的 patch_version 信息
+//        List<String> patchVersions = hotUpdateService.list().stream().map(THotUpdate::getPatchVersion).collect(Collectors.toList());
+//        for (String patchVersion : patchVersions) {
+//            // 查询所有设备表中的的 apk_version 等于 patch_version的
+//            List<TEquipment> equipmentList = equipmentService.lambdaQuery().eq(TEquipment::getApkVersion, patchVersion).list();
+//            // 计算当前的 patch_version = apk_version 的设备数量
+//            int count = equipmentList.size();
+//
+//            THotUpdate hotUpdate = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one();
+//            if (hotUpdate != null) {
+//                hotUpdate.setHaveUpdateNum(count);
+//                hotUpdateService.updateById(hotUpdate);
+//            }
+//        }
+//    }
 
     // 值日通知1
     // 每天8:20执行一次

+ 367 - 30
src/main/java/com/szwl/controller/THotUpdateController.java

@@ -3,7 +3,10 @@ package com.szwl.controller;
 
 import cn.hutool.http.HttpRequest;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.szwl.constant.ResponseCodesEnum;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
@@ -15,7 +18,9 @@ import com.szwl.service.TEquipmentService;
 import com.szwl.service.THotUpdateService;
 import com.szwl.util.IDGenerator;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.math3.linear.QRDecomposition;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.*;
@@ -28,7 +33,7 @@ import java.util.stream.Stream;
  * </p>
  *
  * @author wuhs
- * @since 2024-01-16
+ * @since 2024-01-24
  */
 @RestController
 @RequestMapping("/tHotUpdate")
@@ -46,41 +51,370 @@ public class THotUpdateController {
         this.adminService = adminService;
     }
 
-    @ApiOperation(value = "获取补丁信息")
-    @GetMapping("/getPatchUrl")
-    public ResponseModel<?> getPatchUrl(String clientId, String isForeign) {
-        if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(isForeign)) {
-            return R.fail(ResponseCodesEnum.B0001, "参数不能为空");
+    @ApiOperation(value = "设备热更新+1")
+    @PostMapping("/upPatchNum")
+    public ResponseModel<?> upPatchNum(String patchVersion) {
+//        Long patchId = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one().getId();
+//        TEquipment equipment = equipmentService.lambdaQuery().eq(TEquipment::getClientId, clientId).one();
+//        Long equipmentId = equipment.getId();
+//        TEquipmentDesc equipmentDesc = equipmentDescService.lambdaQuery().eq(TEquipmentDesc::getEquipmentId, equipmentId).one();
+//        equipmentDesc.setPatchId(patchId);
+//        equipmentDescService.saveOrUpdate(equipmentDesc);
+
+//        UpdateWrapper<THotUpdate> uw = new UpdateWrapper<>();
+//        uw.eq("patch_version", patchVersion)
+//                .setSql("have_update_num = have_update_num + 1, modify_time = NOW()");
+//        hotUpdateService.update(uw);
+
+        THotUpdate hotUpdate = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one();
+        hotUpdate.setModifyTime(new Date());
+
+        Integer haveUpdateNum = Optional.ofNullable(hotUpdate.getHaveUpdateNum()).orElse(0);
+        hotUpdate.setHaveUpdateNum(haveUpdateNum + 1);
+        hotUpdateService.saveOrUpdate(hotUpdate);
+        return R.ok();
+    }
+
+    @ApiOperation(value = "获取所有热更新数据")
+    @GetMapping("/getPatchPage")
+    public ResponseModel<IPage<?>> getPatchPage(long current, long size) {
+
+        LambdaQueryWrapper<THotUpdate> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.orderByDesc(THotUpdate::getCreateTime);
+        Page<THotUpdate> page = new Page<>(current, size, true);
+        IPage<THotUpdate> iPage = hotUpdateService.page(page, queryWrapper);
+        return R.ok(iPage);
+    }
+
+    @ApiOperation(value = "获取热更新补丁信息列表")
+    @GetMapping("/getPatchList")
+    public ResponseModel<?> getPatchList(String ifForeign, String patchVersion) {
+        if (StringUtils.isNotEmpty(patchVersion)) {
+            // 获取特定补丁信息
+            THotUpdate tHotUpdate = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one();
+            if (tHotUpdate == null) {
+                return R.fail(ResponseCodesEnum.A0001, "补丁版本号不存在");
+            }
+            return R.ok(tHotUpdate);
+        } else {
+            // 获取热更新补丁列表
+            String area;
+            if ("0".equals(ifForeign)) {
+                // 国内 targetAreas = 1
+                area = "1";
+            } else if ("1".equals(ifForeign)) {
+                // 海外 targetAreas = 2
+                area = "2";
+            } else {
+                // 直接获取所有的
+                area = "4";
+            }
+            List<THotUpdate> lastTen = hotUpdateService.getLastTen(area);
+            return R.ok(lastTen);
         }
-        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(ResponseCodesEnum.B0001, "海外内不匹配");
+    }
+
+    @ApiOperation(value = "获取补丁信息")
+    @GetMapping("/getPatchInfo")
+    public ResponseModel<?> getPatchInfo(String patchVersion) {
+
+        assert StringUtils.isNotEmpty(patchVersion) : R.fail(ResponseCodesEnum.A0001, "补丁版本号不能为空");
+
+        THotUpdate tHotUpdate = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one();
+        return R.ok(tHotUpdate);
+
+    }
+
+    @ApiOperation(value = "设备获取热更新补丁信息")
+    @GetMapping("/getPatchList1")
+    public ResponseModel<?> getPatchList1(String clientId, String ifForeign) {
+        List<THotUpdate> lastTen = new ArrayList<THotUpdate>();
+        String area;
+//        if (StringUtils.isNotEmpty(clientId)) {
+//            // 部分设备 targetAreas = 0
+//            area = "0";
+//        } else
+        if ("0".equals(ifForeign)) {
+            // 国内 targetAreas = 1
+            area = "1";
+        } else if ("1".equals(ifForeign)) {
+            // 海外 targetAreas = 2
+            area = "2";
+        } else {
+            // 直接获取所有的
+            area = "4";
         }
-        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);
+        lastTen = hotUpdateService.getLastTen(area);
+        return R.ok(lastTen);
     }
 
+//    @ApiOperation(value = "获取补丁下载链接")
+//    @GetMapping("/getPatchUrl")
+//    public ResponseModel<?> getPatchUrl(String clientId, String isForeign) {
+//
+//        if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(isForeign)) {
+//            return R.fail(ResponseCodesEnum.B0001, "参数不能为空");
+//        }
+//        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(ResponseCodesEnum.B0001, "海外内不匹配");
+//        }
+//        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("/test")
+//    public ResponseModel<?> test() {
+//        // 遍历所有设备的apk_version,看多少台设备的apk_version = patch_veriosn
+//        // 获取热更新表中所有的 patch_version 信息
+//        List<String> patchVersions = hotUpdateService.list().stream().map(THotUpdate::getPatchVersion).collect(Collectors.toList());
+//        for (String patchVersion : patchVersions) {
+//            // 查询所有设备表中的的 apk_version 等于 patch_version的
+//            List<TEquipment> equipmentList = equipmentService.lambdaQuery().eq(TEquipment::getApkVersion, patchVersion).list();
+//            // 计算当前的 patch_version = apk_version 的设备数量
+//            int count = equipmentList.size();
+//            System.out.println("count 》》》" + count);
+//            THotUpdate hotUpdate = hotUpdateService.lambdaQuery().eq(THotUpdate::getPatchVersion, patchVersion).one();
+//            if (hotUpdate != null) {
+//                hotUpdate.setHaveUpdateNum(count);
+//                hotUpdateService.updateById(hotUpdate);
+//            }
+//        }
+//        return R.ok();
+//    }
 
-    @ApiOperation(value = "录入热更新补丁信息")
+    @ApiOperation(value = "添加热更新信息")
     @PostMapping("/postPatchInfo")
     public ResponseModel<?> postPatchInfo(@RequestBody THotUpdate hotUpdate) {
+        String originalVersion = hotUpdate.getOriginalVersion(); // 原版本号
+        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(); // 更新内容
+
+        assert StringUtils.isNotEmpty(originalVersion) : R.fail(ResponseCodesEnum.B0001, "原版本号不能为空");
+        assert StringUtils.isNotEmpty(patchVersion) : R.fail(ResponseCodesEnum.B0001, "目标补丁版本号不能为空");
+        assert StringUtils.isNotEmpty(patchStatus) : R.fail(ResponseCodesEnum.B0001, "补丁状态不能为空");
+        assert StringUtils.isNotEmpty(patchLink) : R.fail(ResponseCodesEnum.B0001, "补丁外链不能为空");
+        assert StringUtils.isNotEmpty(note) : R.fail(ResponseCodesEnum.B0001, "更新内容不能为空");
+
+        THotUpdate tHotUpdate;
+        // 目标补丁号是否已经存在
+        LambdaQueryWrapper<THotUpdate> lqw = Wrappers.lambdaQuery();
+        lqw.eq(THotUpdate::getPatchVersion, patchVersion);
+        List<THotUpdate> hotUpdates = hotUpdateService.list(lqw);
+        long hotUpdateId;
+        if (hotUpdates.size() > 0) {
+            // 目标补丁号是可以被修改的
+            tHotUpdate = hotUpdates.get(0);
+            hotUpdateId = tHotUpdate.getId();
+        } else {
+            tHotUpdate = new THotUpdate();
+            hotUpdateId = IDGenerator.commonID();
+            tHotUpdate.setId(hotUpdateId);
+            tHotUpdate.setCreateTime(new Date());
+        }
+
+        tHotUpdate.setModifyTime(new Date());
+        tHotUpdate.setOriginalVersion(originalVersion);
+        tHotUpdate.setPatchVersion(patchVersion);
+        tHotUpdate.setPatchStatus(patchStatus);
+        tHotUpdate.setPatchLink(patchLink);
+        tHotUpdate.setTargetAreas(targetAreas);
+        tHotUpdate.setNote(note);
+        tHotUpdate.setHaveUpdateNum(0);
+
+        switch (targetAreas) {
+            case "0":
+                // 推送指定设备
+                if (StringUtils.isEmpty(clientIds)) { // 查看clientIds是否为空
+                    return R.fail(ResponseCodesEnum.B0001, "推送区域为空时,需要填写设备编号");
+                }
+                List<String> clientIdList = Arrays.asList(clientIds.split(","));
+                LambdaQueryWrapper<TEquipment> queryWrapper = Wrappers.lambdaQuery();
+                queryWrapper.in(TEquipment::getClientId, clientIdList);
+                List<TEquipment> equipmentList = equipmentService.list(queryWrapper);
+                int size = equipmentList.size();
+                tHotUpdate.setShouldUpdateNum(size);
+                break;
+            case "1":
+                // 推送国内
+                int count1 = equipmentService.getForeignEquipmentCount("0");
+                tHotUpdate.setShouldUpdateNum(count1);
+                break;
+            case "2":
+                // 推送海外
+                int count2 = equipmentService.getForeignEquipmentCount("1");
+                tHotUpdate.setShouldUpdateNum(count2);
+                break;
+            case "3":
+                // 推送全球
+                int count3 = equipmentService.getForeignEquipmentCount("2");
+                tHotUpdate.setShouldUpdateNum(count3);
+                break;
+            default:
+                return R.fail("不支持的推送区域参数:" + targetAreas);
+        }
+        hotUpdateService.saveOrUpdate(tHotUpdate);
+
+        return R.ok("录入成功");
+    }
+
+
+    @ApiOperation(value = "添加热更新信息1")
+    @PostMapping("/postPatchInfo1")
+    public ResponseModel<?> postPatchInfo1(@RequestBody THotUpdate hotUpdate) {
+        String originalVersion = hotUpdate.getOriginalVersion(); // 原版本号
+        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(); // 更新内容
+
+        assert StringUtils.isNotEmpty(originalVersion) : R.fail(ResponseCodesEnum.B0001, "原版本号不能为空");
+        assert StringUtils.isNotEmpty(patchVersion) : R.fail(ResponseCodesEnum.B0001, "目标补丁版本号不能为空");
+        assert StringUtils.isNotEmpty(patchStatus) : R.fail(ResponseCodesEnum.B0001, "补丁状态不能为空");
+        assert StringUtils.isNotEmpty(patchLink) : R.fail(ResponseCodesEnum.B0001, "补丁外链不能为空");
+        assert StringUtils.isNotEmpty(note) : R.fail(ResponseCodesEnum.B0001, "更新内容不能为空");
+
+        THotUpdate tHotUpdate;
+        // 目标补丁号是否已经存在
+        LambdaQueryWrapper<THotUpdate> lqw = Wrappers.lambdaQuery();
+        lqw.eq(THotUpdate::getPatchVersion, patchVersion);
+        List<THotUpdate> hotUpdates = hotUpdateService.list(lqw);
+        long hotUpdateId;
+        if (hotUpdates.size() > 0) {
+            // 目标补丁号是可以被修改的
+            tHotUpdate = hotUpdates.get(0);
+            hotUpdateId = tHotUpdate.getId();
+        } else {
+            tHotUpdate = new THotUpdate();
+            hotUpdateId = IDGenerator.commonID();
+            tHotUpdate.setId(hotUpdateId);
+            tHotUpdate.setCreateTime(new Date());
+        }
+
+        tHotUpdate.setModifyTime(new Date());
+        tHotUpdate.setOriginalVersion(originalVersion);
+        tHotUpdate.setPatchVersion(patchVersion);
+        tHotUpdate.setPatchStatus(patchStatus);
+        tHotUpdate.setPatchLink(patchLink);
+        tHotUpdate.setTargetAreas(targetAreas);
+        tHotUpdate.setNote(note);
+        tHotUpdate.setHaveUpdateNum(0);
+
+        switch (targetAreas) {
+            case "0":
+                // 推送指定设备
+                if (StringUtils.isEmpty(clientIds)) { // 查看clientIds是否为空
+                    return R.fail(ResponseCodesEnum.B0001, "推送区域为空时,需要填写设备编号");
+                }
+                // 查询这些设备信息
+                List<String> clientIdList = Arrays.asList(clientIds.split(","));
+                LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
+                wrapper.in(TEquipment::getClientId, clientIdList);
+                List<TEquipment> equipmentList0 = equipmentService.list(wrapper);
+                if (equipmentList0.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001, "设备信息不存在");
+                }
+                // 查询这些设备的所有id
+                List<Long> equipmentIdList = equipmentList0.stream().map(TEquipment::getId).collect(Collectors.toList());
+                if (equipmentIdList.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001, "没有符合要求的设备");
+                }
+//                if (CollectionUtils.isEmpty(equipmentIdList)) {
+//                    return R.fail(ResponseCodesEnum.B0001, "没有符合要求的设备");
+//                }
+//                equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList, hotUpdateId);
+                tHotUpdate.setShouldUpdateNum(equipmentIdList.size());
+                break;
+            case "1":
+                // 推送国内
+                // 查询所有的国内用户
+//                LambdaQueryWrapper<TAdmin> wrapper1 = Wrappers.lambdaQuery();
+//                wrapper1.eq(TAdmin::getIfForeign, "0");
+//                List<TAdmin> domesticAdminList = adminService.list(wrapper1);
+                List<TAdmin> domesticAdminList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "0").list();
+
+                ArrayList<Long> equipmentIdList1 = new ArrayList<>();
+
+                // 批量查询国内用户的设备信息
+                LambdaQueryWrapper<TEquipment> queryWrapper = Wrappers.lambdaQuery();
+                queryWrapper.in(TEquipment::getAdminId, domesticAdminList.stream().map(TAdmin::getId).collect(Collectors.toList()));
+                List<TEquipment> equipmentList = equipmentService.list(queryWrapper);
+
+                // 将equipmentId添加到list
+                equipmentIdList1.addAll(equipmentList.stream().map(TEquipment::getId).collect(Collectors.toList()));
+
+                if (equipmentIdList1.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001, "没有符合要求的设备");
+                }
+//                if (!equipmentIdList1.isEmpty()) {
+//                    equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
+//                }
+                tHotUpdate.setShouldUpdateNum(equipmentIdList1.size());
+
+                break;
+            case "2":
+                // 推送海外
+                // 查询所有海外用户信息
+                List<TAdmin> foreignAdminList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "1").list();
+                // 查询海外用户的所有设备的id
+                List<Long> equipmentIdList2 = foreignAdminList.stream().flatMap(admin -> equipmentService.lambdaQuery().eq(TEquipment::getAdminId, admin.getId()).list().stream()).map(TEquipment::getId).collect(Collectors.toList());
+                if (equipmentIdList2.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001, "没有符合要求的设备");
+                }
+//                if (!equipmentIdList2.isEmpty()) {
+//                    equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList2, hotUpdateId);
+//                }
+                tHotUpdate.setShouldUpdateNum(equipmentIdList2.size());
+                break;
+            case "3":
+                // 推送全球
+                // 所有设备id
+                List<Long> equipmentIdList3 = equipmentService.list().stream().map(TEquipment::getId).collect(Collectors.toList());
+                if (equipmentIdList3.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001, "没有符合要求的设备");
+                }
+//                equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
+
+//                List<TEquipmentDesc> equipmentDescList = equipmentDescService.list();
+//                equipmentDescList.forEach(d -> d.setPatchId(hotUpdateId));
+//                equipmentDescService.saveOrUpdateBatch(equipmentDescList);
+                tHotUpdate.setShouldUpdateNum(equipmentIdList3.size());
+                break;
+            default:
+                return R.fail("不支持的推送区域参数:" + targetAreas);
+        }
+        hotUpdateService.save(tHotUpdate);
+
+        return R.ok("录入成功");
+    }
+
 
+    @ApiOperation(value = "录入热更新补丁信息0")
+    @PostMapping("/postPatchInfo0")
+    public ResponseModel<?> postPatchInfo0(@RequestBody THotUpdate hotUpdate) {
 
-        String patchVersion = hotUpdate.getPatchVersion(); // 补丁版本号
+        String originalVersion = hotUpdate.getOriginalVersion(); // 原版本号
+        String patchVersion = hotUpdate.getPatchVersion(); // 目标补丁版本号
         String patchStatus = hotUpdate.getPatchStatus(); // 补丁状态,0停止,1发布
         String targetAreas = hotUpdate.getTargetAreas(); // 目标区域,0部分设备,1国内,2海外,3全球
         String patchLink = hotUpdate.getPatchLink(); // 补丁外链
@@ -112,6 +446,9 @@ public class THotUpdateController {
         tHotUpdate.setPatchLink(patchLink);
         tHotUpdate.setTargetAreas(targetAreas);
         tHotUpdate.setNote(note);
+        tHotUpdate.setOriginalVersion(originalVersion);
+        tHotUpdate.setHaveUpdateNum(0);
+//        tHotUpdate.setShouldUpdateNum(0);
 
         switch (targetAreas) {
             case "0":
@@ -147,10 +484,10 @@ public class THotUpdateController {
                 wrapper1.in(TEquipment::getClientId, clientIdList);
                 List<TEquipment> equipmentList1 = equipmentService.list(wrapper1);
                 if (equipmentList1.isEmpty()) {
-                    return R.fail(ResponseCodesEnum.B0001,"设备信息不存在");
+                    return R.fail(ResponseCodesEnum.B0001, "设备信息不存在");
                 }
                 List<Long> equipmentIdList = equipmentList1.stream().map(TEquipment::getId).collect(Collectors.toList());
-                hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList, hotUpdateId);
+                equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList, hotUpdateId);
                 break;
             case "1":
                 // 推送国内
@@ -171,7 +508,7 @@ public class THotUpdateController {
                 }
                 if (!equipmentIdList1.isEmpty()) {
 //                    saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
-                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
+                    equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
                 }
 
                 break;
@@ -201,7 +538,7 @@ public class THotUpdateController {
                 List<Long> equipmentIdList3 = adminList.stream().flatMap(admin -> equipmentService.lambdaQuery().eq(TEquipment::getAdminId, admin.getId()).list().stream()).map(TEquipment::getId).collect(Collectors.toList());
                 if (!equipmentIdList3.isEmpty()) {
 //                    saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
-                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
+                    equipmentDescService.saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
                 }
 
                 break;

+ 0 - 1
src/main/java/com/szwl/controller/TLogoController.java

@@ -80,7 +80,6 @@ public class TLogoController {
 //        return R.fail(P0001,"仅管理员可修改logo");
 //    }
 
-    // TODO: 2024-01-27
 
     @ApiOperation(value = "定制logo")
     @PostMapping("/customLogo")

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

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * </p>
  *
  * @author wuhs
- * @since 2024-01-16
+ * @since 2024-01-24
  */
 public interface THotUpdateMapper extends BaseMapper<THotUpdate> {
 

+ 4 - 1
src/main/java/com/szwl/mapper/xml/THotUpdateMapper.xml

@@ -13,11 +13,14 @@
         <result column="note" property="note" />
         <result column="target_areas" property="targetAreas" />
         <result column="patch_link" property="patchLink" />
+        <result column="original_version" property="originalVersion" />
+        <result column="have_update_num" property="haveUpdateNum" />
+        <result column="should_update_num" property="shouldUpdateNum" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, create_time, modify_time, patch_version, patch_status, client_id, note, target_areas, patch_link
+        id, create_time, modify_time, patch_version, patch_status, client_id, note, target_areas, patch_link, original_version, have_update_num, should_update_num
     </sql>
 
 </mapper>

+ 10 - 1
src/main/java/com/szwl/model/entity/THotUpdate.java

@@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode;
  * </p>
  *
  * @author wuhs
- * @since 2024-01-16
+ * @since 2024-01-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -49,5 +49,14 @@ public class THotUpdate implements Serializable {
     @ApiModelProperty(value = "补丁外链")
     private String patchLink;
 
+    @ApiModelProperty(value = "原始版本号")
+    private String originalVersion;
+
+    @ApiModelProperty(value = "已更新的设备数量")
+    private Integer haveUpdateNum;
+
+    @ApiModelProperty(value = "应该被更新的设备数量")
+    private Integer shouldUpdateNum;
+
 
 }

+ 4 - 0
src/main/java/com/szwl/service/TEquipmentDescService.java

@@ -3,6 +3,8 @@ package com.szwl.service;
 import com.szwl.model.entity.TEquipmentDesc;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TEquipmentDescService extends IService<TEquipmentDesc> {
 
+    void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId);
+
 }

+ 2 - 0
src/main/java/com/szwl/service/TEquipmentService.java

@@ -25,4 +25,6 @@ public interface TEquipmentService extends MyIService<TEquipment> {
     public String findMachineUseNum(StatisticsParam param);
 
     Optional<String> syncOneEquipmentByClientId(String clientId);
+
+    int getForeignEquipmentCount(String area); // 0 国内,1 海外,2 全球
 }

+ 3 - 2
src/main/java/com/szwl/service/THotUpdateService.java

@@ -11,9 +11,10 @@ import java.util.List;
  * </p>
  *
  * @author wuhs
- * @since 2024-01-16
+ * @since 2024-01-24
  */
 public interface THotUpdateService extends IService<THotUpdate> {
 
-    void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId);
+    // 根据 地区 查询最近十条记录
+   List<THotUpdate> getLastTen(String area);
 }

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

@@ -4,8 +4,13 @@ import com.szwl.model.entity.TEquipmentDesc;
 import com.szwl.mapper.TEquipmentDescMapper;
 import com.szwl.service.TEquipmentDescService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +22,38 @@ import org.springframework.stereotype.Service;
 @Service
 public class TEquipmentDescServiceImpl extends ServiceImpl<TEquipmentDescMapper, TEquipmentDesc> implements TEquipmentDescService {
 
+    @Autowired
+    private TEquipmentDescService equipmentDescService;
+
+    @Override
+    public void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId) {
+
+        ArrayList<TEquipmentDesc> descList = new ArrayList<>(equipmentIdList.size());
+
+        for (Long equipmentId : equipmentIdList) {
+            TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
+            if (Objects.isNull(equipmentDesc)) {
+                equipmentDesc = new TEquipmentDesc();
+            }
+            equipmentDesc.setPatchId(hotUpdateId);
+            descList.add(equipmentDesc);
+        }
+        equipmentDescService.saveOrUpdateBatch(descList);
+
+
+        //
+//        List<TEquipmentDesc> tEquipmentDescs = equipmentDescService.listByIds(equipmentIdList);
+//        List<TEquipmentDesc> updateList = new ArrayList<>(tEquipmentDescs.size());
+//        for (TEquipmentDesc desc : tEquipmentDescs) {
+//            if (Objects.isNull(desc)) {
+//                TEquipmentDesc equipmentDesc = new TEquipmentDesc();
+//                equipmentDesc.setEquipmentId(equipmentIdList);
+//            }
+//            desc.setPatchId(hotUpdateId);
+//            updateList.add(desc);
+//        }
+//        equipmentDescService.saveOrUpdateBatch(updateList);
+
+
+    }
 }

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

@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.szwl.feign.bean.SyncOldFeign;
 import com.szwl.model.bo.R;
+import com.szwl.model.entity.TAdmin;
 import com.szwl.model.entity.TEquipment;
 import com.szwl.mapper.TEquipmentMapper;
 import com.szwl.model.query.StatisticsParam;
 import com.szwl.model.utils.PushUtils;
+import com.szwl.service.TAdminService;
 import com.szwl.service.TEquipmentService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
@@ -20,6 +22,7 @@ import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -33,8 +36,10 @@ import java.util.Optional;
 public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipment> implements TEquipmentService {
     @Autowired
     private AmqpTemplate amqpTemplate;
-    @Autowired
+    @Resource
     TEquipmentMapper tEquipmentMapper;
+    @Autowired
+    TAdminService adminService;
     @Resource
     SyncOldFeign syncOldFeign;
     @Resource
@@ -217,6 +222,25 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
         }
     }
 
+    @Override
+    public int getForeignEquipmentCount(String area) {
+        switch (area) {
+            case "0":
+                // 统计国内
+                List<Long> domesticAdminIdList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "0").list().stream().map(TAdmin::getId).collect(Collectors.toList());
+                return equipmentService.lambdaQuery().in(TEquipment::getAdminId, domesticAdminIdList).count();
+            case "1":
+                // 统计海外
+                List<Long> overseasAdminIdList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "1").list().stream().map(TAdmin::getId).collect(Collectors.toList());
+                return equipmentService.lambdaQuery().in(TEquipment::getAdminId, overseasAdminIdList).count();
+            case "2":
+                // 统计全球
+                return equipmentService.list().size();
+            default:
+                return 0;
+        }
+    }
+
 //    @Override
 //    public Integer insertBatchSomeColumn(List<TEquipment> entityList) {
 //        return tEquipmentMapper.insertBatchSomeColumn(entityList);

+ 39 - 11
src/main/java/com/szwl/service/impl/THotUpdateServiceImpl.java

@@ -1,39 +1,67 @@
 package com.szwl.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.szwl.model.entity.TEquipmentDesc;
 import com.szwl.model.entity.THotUpdate;
 import com.szwl.mapper.THotUpdateMapper;
 import com.szwl.service.TEquipmentDescService;
 import com.szwl.service.THotUpdateService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author wuhs
- * @since 2024-01-16
+ * @since 2024-01-24
  */
 @Service
 public class THotUpdateServiceImpl extends ServiceImpl<THotUpdateMapper, THotUpdate> implements THotUpdateService {
 
     @Autowired
-    private TEquipmentDescService equipmentDescService;
+    THotUpdateService hotUpdateService;
+    @Resource
+    THotUpdateMapper hotUpdateMapper;
+
     @Override
-    public void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId) {
-        ArrayList<TEquipmentDesc> descList = new ArrayList<>();
-        for (Long equipmentId : equipmentIdList) {
-            TEquipmentDesc equipmentDesc = new TEquipmentDesc();
-            equipmentDesc.setEquipmentId(equipmentId);
-            equipmentDesc.setPatchId(hotUpdateId);
-            descList.add(equipmentDesc);
+    public List<THotUpdate> getLastTen(String area) {
+        List<THotUpdate> tHotUpdates = new ArrayList<>();
+
+        switch (area) {
+            case "0": // 部分设备
+                LambdaQueryWrapper<THotUpdate> wrapper = Wrappers.lambdaQuery();
+                wrapper.eq(THotUpdate::getTargetAreas, "0");
+                wrapper.orderByDesc(THotUpdate::getModifyTime).last("LIMIT 10");
+                tHotUpdates = hotUpdateMapper.selectList(wrapper);
+                return tHotUpdates;
+            case "1": // 国内
+                LambdaQueryWrapper<THotUpdate> wrapper1 = Wrappers.lambdaQuery();
+                wrapper1.eq(THotUpdate::getTargetAreas, "1");
+                wrapper1.orderByDesc(THotUpdate::getModifyTime).last("LIMIT 10");
+                tHotUpdates = hotUpdateMapper.selectList(wrapper1);
+                return tHotUpdates;
+            case "2": // 海外
+                LambdaQueryWrapper<THotUpdate> wrapper2 = Wrappers.lambdaQuery();
+                wrapper2.eq(THotUpdate::getTargetAreas, "2");
+                wrapper2.orderByDesc(THotUpdate::getModifyTime).last("LIMIT 10");
+                tHotUpdates = hotUpdateMapper.selectList(wrapper2);
+                return tHotUpdates;
+            case "4": // 所有的
+                LambdaQueryWrapper<THotUpdate> wrapper4 = Wrappers.lambdaQuery();
+                wrapper4.orderByDesc(THotUpdate::getModifyTime).last("LIMIT 10");
+                tHotUpdates = hotUpdateMapper.selectList(wrapper4);
         }
-        equipmentDescService.saveOrUpdateBatch(descList);
+        return tHotUpdates;
     }
 }

+ 1 - 1
src/test/java/com/szwl/AutoGeneratorTests.java

@@ -47,7 +47,7 @@ class AutoGeneratorTests {
 		strategyConfig
 //				.setCapitalMode(true)//设置全局大写命名
 				.setInclude(new String[]{
-						"t_location_check"
+						"t_hot_update"
 				})//只会生成该表
 				.setEntityLombokModel(true)//实体类生成之后自动添加lombok注解
 				.setNaming(NamingStrategy.underline_to_camel)//数据库表映射到实体的命名策略