AppPatchPostController.java
3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.brframework.webapppatch.web;
import com.brframework.commonweb.exception.HandleException;
import com.brframework.commonweb.json.JSONResult;
import com.brframework.webapppatch.domain.AppPatchConfig;
import com.brframework.webapppatch.entity.PatchBranch;
import com.brframework.webapppatch.json.AppPatchBranchBasePackageParam;
import com.brframework.webapppatch.json.AppPatchReleaseVersionParam;
import com.brframework.webapppatch.service.PatchBranchService;
import com.brframework.webapppatch.service.PatchConfigService;
import com.brframework.webapppatch.service.PatchVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
/**
* @author xu
* @date 2019/11/14 17:02
*/
@RestController
@Api(tags = "热更新")
public class AppPatchPostController {
@Autowired
PatchVersionService patchVersionService;
@Autowired
PatchBranchService patchBranchService;
@Autowired
PatchConfigService patchConfigService;
@ApiOperation(value = "发布新版本", notes = "发布新版本")
@PostMapping("v1/app-patch/version/{os}/{branch}/release")
public JSONResult createVersion(@ApiParam(value = "系统") @PathVariable("os") String os,
@ApiParam(value = "分支", required = true) @PathVariable("branch") String branch,
@Valid @RequestBody AppPatchReleaseVersionParam param){
AppPatchConfig appPatchConfig = patchConfigService.get();
if(!param.getSecretKey().equals(appPatchConfig.getSecretKey())){
throw new HandleException("密钥不正确");
}
patchVersionService.createVersion(os, branch,
param.getVersionMessage(), param.getVersionUrl(), param.getPatchUrl(),
param.getBundleUrl(), param.getUpdateType(), param.getUpdateStatus());
return JSONResult.ok();
}
@ApiOperation(value = "设置分支基础包", notes = "设置分支基础包")
@PostMapping("v1/app-patch/branch/{branch}/base-package")
public JSONResult branchBasePackage(
@ApiParam(value = "分支", required = true) @PathVariable("branch") String branch,
@Valid @RequestBody AppPatchBranchBasePackageParam param){
AppPatchConfig appPatchConfig = patchConfigService.get();
if(!param.getSecretKey().equals(appPatchConfig.getSecretKey())){
throw new HandleException("密钥不正确");
}
patchBranchService.updateBasePackage(branch, param.getPackageUrl());
return JSONResult.ok();
}
@ApiOperation(value = "获取分支基础包", notes = "获取分支基础包")
@GetMapping("v1/app-patch/branch/{branch}/base-package")
public JSONResult<PatchBranch> branchBasePackageGet(
@ApiParam(value = "分支", required = true) @PathVariable("branch") String branch){
PatchBranch byBranchName = patchBranchService.findByBranchName(branch);
if(byBranchName == null){
throw new HandleException("当前分支不存在");
}
return JSONResult.ok(byBranchName);
}
}