ApkController.java
4.19 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.huaheng.mobile.download;
import com.alibaba.fastjson.JSONException;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.common.mapper.ApkMapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* @author
*/
@RestController
@RequestMapping("/mobile/download")
public class ApkController {
@Resource
ApkMapper apkMapper;
@PostMapping("/getUpdateApkInfo")
@ApiOperation("获取apk更新信息")
public AjaxResult getUpdateApkInfo(@RequestBody Map<String, String> param) {
System.out.println("getUpdateApkInfo pkgName:" + param.get("pkgName"));
if (param.get("pkgName") == null) {
throw new JSONException("pkgName不能为空");
}
if (param.get("versionCode") == null) {
throw new JSONException("versionCode不能为空");
}
List<ApkInfo> apkinfos = apkMapper.getApkInfoByPkgName(param.get("pkgName"));
if(apkinfos == null || apkinfos.size() <= 0) {
return AjaxResult.error("当前已经是最新版本");
}
ApkInfo apkInfo = apkinfos.get(0);
int maxVersion = Integer.MAX_VALUE;
String project = param.containsKey("project") ? param.get("project") : null;
if(project != null) {
if(project.equals(Constant.PROJECT_XIANGJI)) {
maxVersion = Constant.PROJECT_XIANGJI_MAX_LEVEL;
}
}
//循环找到版本最大值
for (ApkInfo apkInfo2 : apkinfos)
{
if (apkInfo.getVersionCode() < apkInfo2.getVersionCode()) {
if(apkInfo2.getVersionCode() > maxVersion) {
continue;
}
apkInfo = apkInfo2;
}
}
int versionCode = Integer.parseInt(param.get("versionCode"));
System.out.println("getUpdateApkInfo versionCode:" + versionCode);
System.out.println("apkInfo.getVersionCode():" + apkInfo.getVersionCode());
if(versionCode >= apkInfo.getVersionCode()) {
return AjaxResult.error("当前已经是最新版本");
}
return AjaxResult.success(apkInfo);
}
@PostMapping("/insertApkInfo")
@ApiOperation("插入apk更新信息")
public ApkInfo insertApkInfo(@RequestBody Map<String, String> param) {
System.out.println("insertApkInfo pkgName:" + param.get("pkgName"));
if (param.get("pkgName") == null) {
throw new JSONException("pkgName不能为空");
}
if (param.get("versionCode") == null) {
throw new JSONException("versionCode不能为空");
}
if (param.get("versionName") == null) {
throw new JSONException("versionName");
}
if (param.get("url") == null) {
throw new JSONException("url");
}
if (param.get("md5") == null) {
throw new JSONException("md5");
}
ApkInfo apkInfo = buildApkInfo(param);
try {
apkMapper.insertApkInfo(apkInfo.getPkgName(), apkInfo.getVersionCode(), apkInfo.getVersionName(), apkInfo.getUrl(), apkInfo.getMd5());
} catch(Exception e) {
}
return apkInfo;
}
@PostMapping("/clearApkInfo")
@ApiOperation("删除apk信息")
public AjaxResult clearApkInfo(@RequestBody Map<String, String> param) {
System.out.println("clearApkInfo");
try {
apkMapper.clearApkInfo();
} catch(Exception e) {
}
return AjaxResult.success("删除apk信息成功");
}
private ApkInfo buildApkInfo(Map<String, String> param) {
ApkInfo apkInfo = new ApkInfo();
apkInfo.setPkgName(param.get("pkgName"));
apkInfo.setVersionCode(Integer.parseInt(param.get("versionCode")));
apkInfo.setVersionName(param.get("versionName"));
apkInfo.setUrl(param.get("url"));
apkInfo.setMd5(param.get("md5"));
return apkInfo;
}
}