|
@@ -4,6 +4,7 @@ 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.constant.ResponseCodesEnum;
|
|
|
import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
import com.szwl.model.entity.*;
|
|
@@ -17,9 +18,9 @@ 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;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -34,9 +35,7 @@ import java.util.Objects;
|
|
|
public class THotUpdateController {
|
|
|
|
|
|
THotUpdateService hotUpdateService;
|
|
|
-
|
|
|
TEquipmentService equipmentService;
|
|
|
-
|
|
|
TEquipmentDescService equipmentDescService;
|
|
|
TAdminService adminService;
|
|
|
|
|
@@ -51,7 +50,7 @@ public class THotUpdateController {
|
|
|
@GetMapping("/getPatchUrl")
|
|
|
public ResponseModel<?> getPatchUrl(String clientId, String isForeign) {
|
|
|
if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(isForeign)) {
|
|
|
- return R.fail("参数不能为空");
|
|
|
+ return R.fail(ResponseCodesEnum.B0001, "参数不能为空");
|
|
|
}
|
|
|
LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(TEquipment::getClientId, clientId);
|
|
@@ -60,7 +59,7 @@ public class THotUpdateController {
|
|
|
TAdmin admin = adminService.getById(adminId);
|
|
|
String ifForeign = admin.getIfForeign();
|
|
|
if (!isForeign.equals(ifForeign)) {
|
|
|
- return R.fail("海外内不匹配");
|
|
|
+ return R.fail(ResponseCodesEnum.B0001, "海外内不匹配");
|
|
|
}
|
|
|
Long equipmentId = equipment.getId();
|
|
|
LambdaQueryWrapper<TEquipmentDesc> lqw = Wrappers.lambdaQuery();
|
|
@@ -74,10 +73,13 @@ public class THotUpdateController {
|
|
|
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全球
|
|
@@ -85,14 +87,20 @@ public class THotUpdateController {
|
|
|
String clientIdS = hotUpdate.getClientId(); // 设备编号
|
|
|
String note = hotUpdate.getNote(); // 更新内容
|
|
|
|
|
|
- if (StringUtils.isEmpty(patchVersion) || StringUtils.isEmpty(patchStatus) || StringUtils.isEmpty(patchLink) || StringUtils.isEmpty(note)) {
|
|
|
- return R.fail("参数不完整");
|
|
|
- }
|
|
|
+// if (StringUtils.isEmpty(patchVersion) || StringUtils.isEmpty(patchStatus) || StringUtils.isEmpty(patchLink) || StringUtils.isEmpty(note)) {
|
|
|
+// return R.fail(ResponseCodesEnum.A0001,"参数不完整");
|
|
|
+// }
|
|
|
+
|
|
|
+ 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, "更新内容不能为空");
|
|
|
+
|
|
|
LambdaQueryWrapper<THotUpdate> lqwHot = Wrappers.lambdaQuery();
|
|
|
lqwHot.eq(THotUpdate::getPatchVersion, patchVersion);
|
|
|
List<THotUpdate> hotUpdates = hotUpdateService.list(lqwHot);
|
|
|
if (hotUpdates.size() > 0) {
|
|
|
- return R.fail("该补丁版本号已存在");
|
|
|
+ return R.fail(ResponseCodesEnum.B0001, "该补丁版本号已存在");
|
|
|
}
|
|
|
THotUpdate tHotUpdate = new THotUpdate();
|
|
|
long hotUpdateId = IDGenerator.commonID();
|
|
@@ -108,77 +116,112 @@ public class THotUpdateController {
|
|
|
switch (targetAreas) {
|
|
|
case "0":
|
|
|
if (StringUtils.isEmpty(clientIdS)) {
|
|
|
- return R.fail("推送区域为空时,需要填写设备编号");
|
|
|
+ return R.fail(ResponseCodesEnum.B0001, "推送区域为空时,需要填写设备编号");
|
|
|
}
|
|
|
// 推送指定设备
|
|
|
- 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);
|
|
|
- }
|
|
|
+// tHotUpdate.setClientId(clientIdS);
|
|
|
+// String[] clientIdArray = clientIdS.split(",");
|
|
|
+// ArrayList<Long> equipmentIdList0 = new ArrayList<>();
|
|
|
+//
|
|
|
+// 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(ResponseCodesEnum.B0001, "设备信息不存在");
|
|
|
+// }
|
|
|
+// Long equipmentId = equipment.getId();
|
|
|
+// equipmentIdList0.add(equipmentId);
|
|
|
+//// saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!equipmentIdList0.isEmpty()) {
|
|
|
+//// saveOrUpdateEquipmentDescBatch(equipmentIdList0, hotUpdateId);
|
|
|
+// hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList0, hotUpdateId);
|
|
|
+// }
|
|
|
+
|
|
|
+ List<String> clientIdList = Arrays.asList(clientIdS.split(","));
|
|
|
+ LambdaQueryWrapper<TEquipment> wrapper1 = Wrappers.lambdaQuery();
|
|
|
+ wrapper1.in(TEquipment::getClientId, clientIdList);
|
|
|
+ List<TEquipment> equipmentList1 = equipmentService.list(wrapper1);
|
|
|
+ if (equipmentList1.isEmpty()) {
|
|
|
+ return R.fail(ResponseCodesEnum.B0001,"设备信息不存在");
|
|
|
}
|
|
|
+ List<Long> equipmentIdList = equipmentList1.stream().map(TEquipment::getId).collect(Collectors.toList());
|
|
|
+ hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList, hotUpdateId);
|
|
|
break;
|
|
|
case "1":
|
|
|
// 推送国内
|
|
|
LambdaQueryWrapper<TAdmin> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(TAdmin::getIfForeign,"0");
|
|
|
+ wrapper.eq(TAdmin::getIfForeign, "0");
|
|
|
List<TAdmin> list = adminService.list(wrapper);
|
|
|
+ ArrayList<Long> equipmentIdList1 = new ArrayList<>();
|
|
|
+
|
|
|
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);
|
|
|
+ equipmentIdList1.add(equipmentId);
|
|
|
}
|
|
|
}
|
|
|
+ if (!equipmentIdList1.isEmpty()) {
|
|
|
+// saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
|
|
|
+ hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList1, 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);
|
|
|
- }
|
|
|
+// LambdaQueryWrapper<TAdmin> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
+// lambdaQuery.eq(TAdmin::getIfForeign, "1");
|
|
|
+// List<TAdmin> abroadList = adminService.list(lambdaQuery);
|
|
|
+// ArrayList<Long> equipmentIdList2 = new ArrayList<>();
|
|
|
+// 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();
|
|
|
+// equipmentIdList2.add(equipmentId);
|
|
|
+//// saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!equipmentIdList2.isEmpty()) {
|
|
|
+//// saveOrUpdateEquipmentDescBatch(equipmentIdList2, hotUpdateId);
|
|
|
+// hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList2,hotUpdateId);
|
|
|
+// }
|
|
|
+
|
|
|
+ List<TAdmin> adminList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "1").list();
|
|
|
+ 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);
|
|
|
}
|
|
|
+
|
|
|
break;
|
|
|
case "3":
|
|
|
// 推送全球
|
|
|
- List<TEquipmentDesc> equipmentDescAll = equipmentDescService.list();
|
|
|
- for (TEquipmentDesc equipmentDesc : equipmentDescAll) {
|
|
|
- equipmentDesc.setPatchId(hotUpdateId);
|
|
|
- equipmentDescService.saveOrUpdate(equipmentDesc);
|
|
|
- }
|
|
|
+// List<TEquipmentDesc> equipmentDescAll = equipmentDescService.list();
|
|
|
+// ArrayList<TEquipmentDesc> equipmentDescArrayList = new ArrayList<>();
|
|
|
+//
|
|
|
+// for (TEquipmentDesc equipmentDesc : equipmentDescAll) {
|
|
|
+// equipmentDesc.setPatchId(hotUpdateId);
|
|
|
+// equipmentDescArrayList.add(equipmentDesc);
|
|
|
+//// equipmentDescService.saveOrUpdate(equipmentDesc);
|
|
|
+// }
|
|
|
+// if (!equipmentDescArrayList.isEmpty()) {
|
|
|
+// equipmentDescService.saveOrUpdateBatch(equipmentDescArrayList);
|
|
|
+// }
|
|
|
+
|
|
|
+ List<TEquipmentDesc> equipmentDescList = equipmentDescService.list();
|
|
|
+ equipmentDescList.forEach(d -> d.setPatchId(hotUpdateId));
|
|
|
+ equipmentDescService.saveOrUpdateBatch(equipmentDescList);
|
|
|
|
|
|
break;
|
|
|
default:
|
|
@@ -190,15 +233,5 @@ public class THotUpdateController {
|
|
|
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);
|
|
|
- }
|
|
|
}
|
|
|
|