|
|
@@ -8,7 +8,9 @@ import com.izouma.nineth.service.AppVersionService;
|
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -22,9 +24,10 @@ public class AppVersionController extends BaseController {
|
|
|
private AppVersionService appVersionService;
|
|
|
private AppVersionRepo appVersionRepo;
|
|
|
|
|
|
- //@PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
public AppVersion save(@RequestBody AppVersion record) {
|
|
|
+ record.setVersionNum(convertVersion(record.getVersion()));
|
|
|
if (record.getId() != null) {
|
|
|
AppVersion orig = appVersionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
ObjUtils.merge(orig, record);
|
|
|
@@ -33,8 +36,16 @@ public class AppVersionController extends BaseController {
|
|
|
return appVersionRepo.save(record);
|
|
|
}
|
|
|
|
|
|
+ private int convertVersion(String version) {
|
|
|
+ String[] arr = version.split("\\.");
|
|
|
+ StringBuilder str = new StringBuilder();
|
|
|
+ for (int i = 0; i < arr.length; i++) {
|
|
|
+ str.insert(0, String.format("%03d", Integer.parseInt(arr[arr.length - 1 - i])));
|
|
|
+ }
|
|
|
+ return Integer.parseInt(str.toString());
|
|
|
+ }
|
|
|
|
|
|
- //@PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/all")
|
|
|
public Page<AppVersion> all(@RequestBody PageQuery pageQuery) {
|
|
|
return appVersionService.all(pageQuery);
|
|
|
@@ -45,6 +56,7 @@ public class AppVersionController extends BaseController {
|
|
|
return appVersionRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
}
|
|
|
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/del/{id}")
|
|
|
public void del(@PathVariable Long id) {
|
|
|
appVersionRepo.softDelete(id);
|
|
|
@@ -66,5 +78,18 @@ public class AppVersionController extends BaseController {
|
|
|
public AppVersion checkAndroidReview(@RequestParam String version) {
|
|
|
return appVersionRepo.findByPlatformAndVersion("Android", version).orElseThrow(new BusinessException("版本不存在"));
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/getVersion")
|
|
|
+ public AppVersion checkReview(@RequestParam String platform, @RequestParam String version) {
|
|
|
+ return appVersionRepo.findByPlatformAndVersion(platform, version).orElseThrow(new BusinessException("版本不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/checkUpdate")
|
|
|
+ @Cacheable(value = "checkUpdate", key = "#platform+'@'+#version")
|
|
|
+ public AppVersion checkUpdate(@RequestParam String platform, @RequestParam String version) {
|
|
|
+
|
|
|
+ return appVersionRepo.findFirstByPlatformOrderByVersionNumDesc(platform)
|
|
|
+ .orElseThrow(new BusinessException("版本不存在"));
|
|
|
+ }
|
|
|
}
|
|
|
|