|
@@ -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);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|