Parcourir la source

修改授权文件下载接口,版本号改为从列表选取

luoshi il y a 2 ans
Parent
commit
a3f8c236d8

+ 19 - 2
src/main/java/com/qmth/ops/api/controller/admin/DeployController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.exception.ApiException;
+import com.qmth.boot.core.exception.ParameterException;
 import com.qmth.boot.tools.device.DeviceInfo;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.dto.DeployForm;
@@ -13,6 +14,7 @@ import com.qmth.ops.api.vo.*;
 import com.qmth.ops.biz.domain.AppDeploy;
 import com.qmth.ops.biz.domain.Deploy;
 import com.qmth.ops.biz.domain.DeployMode;
+import com.qmth.ops.biz.domain.Version;
 import com.qmth.ops.biz.query.DeployQuery;
 import com.qmth.ops.biz.query.OrgQuery;
 import com.qmth.ops.biz.service.*;
@@ -38,6 +40,9 @@ public class DeployController {
     @Resource
     private AppService appService;
 
+    @Resource
+    private VersionService versionService;
+
     @Resource
     private FileService fileService;
 
@@ -129,11 +134,23 @@ public class DeployController {
     @PostMapping("/license/download")
     public void licenseDownload(@RequestAttribute AdminSession adminSession, HttpServletResponse response,
             @RequestParam Long id, @RequestParam(required = false) String deviceId,
-            @RequestParam(required = false) String version) throws Exception {
+            @RequestParam(required = false) Long versionId) throws Exception {
         adminSession.hasPermission(Permission.DEPLOY_LICENSE_DOWNLOAD, id);
+        Deploy deploy = deployService.findById(id);
+        if (deploy == null) {
+            throw new ParameterException("invalid deploy id");
+        }
+        String versionName = null;
+        if (versionId != null) {
+            Version version = versionService.getById(versionId);
+            if (version == null || version.getArchived() || !version.getAppId().equals(deploy.getAppId())) {
+                throw new ParameterException("invalid versionId");
+            }
+            versionName = version.getName();
+        }
         response.setContentType("application/octet-stream; charset=utf-8");
         response.setHeader("Content-Disposition", "attachment; filename=app.lic");
-        licenseService.buildLicense(deployService.findById(id), deviceId, version, response.getOutputStream());
+        licenseService.buildLicense(deploy, deviceId, versionName, response.getOutputStream());
     }
 
     @PostMapping("/org/list")

+ 1 - 1
src/main/java/com/qmth/ops/biz/service/LicenseService.java

@@ -86,7 +86,7 @@ public class LicenseService {
             ous.write((byte) 1);
             ous.write(AES.encrypt(temp.toByteArray(), deviceId.substring(0, 16), deviceId.substring(16)).value());
         }
-        //不限设,限制版本
+        //不限设,限制版本
         else if (deviceId == null && version != null) {
             String versionMd5 = ByteArray.md5(version).toHexString();
             ous.write((byte) 2);