|
@@ -0,0 +1,77 @@
|
|
|
+package com.xuqm.server.appmanager.controller.releases;
|
|
|
+
|
|
|
+import com.xuqm.server.appmanager.common.JWTHelper;
|
|
|
+import com.xuqm.server.appmanager.controller.releases.data.ReleaseAddData;
|
|
|
+import com.xuqm.server.appmanager.controller.releases.data.ReleaseListData;
|
|
|
+import com.xuqm.server.appmanager.entitys.UserInfo;
|
|
|
+import com.xuqm.server.appmanager.entitys.sys.v1.ApplicationEntity;
|
|
|
+import com.xuqm.server.appmanager.entitys.sys.v1.ReleaseEntity;
|
|
|
+import com.xuqm.server.appmanager.enums.AppStatus;
|
|
|
+import com.xuqm.server.appmanager.http.HttpResult;
|
|
|
+import com.xuqm.server.appmanager.repository.sys.v1.ApplicationRepository;
|
|
|
+import com.xuqm.server.appmanager.repository.sys.v1.ReleaseRepository;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("release/v1")
|
|
|
+public class ReleaseV1Controller {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationRepository applicationRepository;
|
|
|
+ @Autowired
|
|
|
+ private ReleaseRepository releaseRepository;
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ public HttpResult<String> ReleaseAdd(@RequestBody ReleaseAddData data, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
+ }
|
|
|
+ if (null == data.getAppId() || null == data.getUrl() || null == data.getVersionCode() || null == data.getVersionName()) {
|
|
|
+ return new HttpResult<>(201, "参数错误", null);
|
|
|
+ } else {
|
|
|
+ ApplicationEntity app = applicationRepository.findFirstByAppIdAndTenantNo(data.getAppId(), userInfo.getTenantNo());
|
|
|
+ if (null == app) return new HttpResult<>(201, "appId不存在", null);
|
|
|
+ ReleaseEntity release = releaseRepository.findFirstByAppIdAndTenantNoAndVersionCodeGreaterThanEqual(data.getAppId(), userInfo.getTenantNo(), data.getVersionCode());
|
|
|
+ if (null != release) return new HttpResult<>(201, "存在更高版本", null);
|
|
|
+ release = new ReleaseEntity();
|
|
|
+ release.setAppId(data.getAppId());
|
|
|
+ release.setTenantNo(userInfo.getTenantNo());
|
|
|
+ release.setUrl(data.getUrl());
|
|
|
+ release.setVersionCode(data.getVersionCode());
|
|
|
+ release.setVersionName(data.getVersionName());
|
|
|
+ release.setContent(data.getContent());
|
|
|
+ release.setVivo(data.isVivo() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setXiaomi(data.isXiaomi() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setOppo(data.isOppo() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setMeizu(data.isMeizu() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setHuawei(data.isHuawei() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setGoogle(data.isGoogle() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ release.setRongyao(data.isRongyao() ? AppStatus.ABSENT : AppStatus.NOT);
|
|
|
+ releaseRepository.save(release);
|
|
|
+
|
|
|
+ return new HttpResult<>(200, "创建成功", app.getAppId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public HttpResult<Page<ReleaseEntity>> ReleaseList(@RequestBody ReleaseListData data, @RequestHeader(name = "token") String token) throws Exception {
|
|
|
+
|
|
|
+ UserInfo userInfo = JWTHelper.getUser(token);
|
|
|
+ if (null == userInfo) {
|
|
|
+ return new HttpResult<>(401, "登录失效", null);
|
|
|
+ }
|
|
|
+ if (data.getPageNumber() < 0) return new HttpResult<>(201, "参数错误", null);
|
|
|
+ if (data.getPageSize() < 0) return new HttpResult<>(201, "参数错误", null);
|
|
|
+
|
|
|
+
|
|
|
+ Page<ReleaseEntity> apps = releaseRepository.findAllByAppIdAndTenantNo(data.getAppId(), userInfo.getTenantNo(), PageRequest.of(data.getPageNumber(), data.getPageSize()));
|
|
|
+
|
|
|
+ return new HttpResult<>(200, "成功", apps);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|