Parcourir la source

添加release版本

徐勤民 il y a 2 mois
Parent
commit
5834d5e66d

+ 77 - 0
src/main/java/com/xuqm/server/appmanager/controller/releases/ReleaseV1Controller.java

@@ -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);
+    }
+
+}

+ 20 - 0
src/main/java/com/xuqm/server/appmanager/controller/releases/data/ReleaseAddData.java

@@ -0,0 +1,20 @@
+package com.xuqm.server.appmanager.controller.releases.data;
+
+import com.xuqm.server.appmanager.enums.AppStatus;
+import lombok.Data;
+
+@Data
+public class ReleaseAddData {
+    private String appId;
+    private boolean huawei;
+    private boolean xiaomi;
+    private boolean meizu;
+    private boolean rongyao;
+    private boolean oppo;
+    private boolean vivo;
+    private boolean google;
+    private String url;
+    private String versionCode;
+    private String versionName;
+    private String content;
+}

+ 9 - 0
src/main/java/com/xuqm/server/appmanager/controller/releases/data/ReleaseListData.java

@@ -0,0 +1,9 @@
+package com.xuqm.server.appmanager.controller.releases.data;
+
+import com.xuqm.server.appmanager.data.PageData;
+import lombok.Data;
+
+@Data
+public class ReleaseListData extends PageData {
+    private String appId;
+}

+ 2 - 0
src/main/java/com/xuqm/server/appmanager/entitys/sys/v1/ReleaseEntity.java

@@ -10,6 +10,7 @@ import lombok.Data;
 @Data
 public class ReleaseEntity extends AbstractBaseTimeEntity {
     private String appId;
+    private String tenantNo;
     @Enumerated(EnumType.STRING)
     private AppStatus huawei;
     @Enumerated(EnumType.STRING)
@@ -27,4 +28,5 @@ public class ReleaseEntity extends AbstractBaseTimeEntity {
     private String url;
     private String versionCode;
     private String versionName;
+    private String content;
 }

+ 1 - 0
src/main/java/com/xuqm/server/appmanager/repository/sys/v1/ApplicationRepository.java

@@ -11,6 +11,7 @@ import java.util.List;
 @Repository
 public interface ApplicationRepository extends JpaRepository<ApplicationEntity, Long> {
     ApplicationEntity findFirstByAppNameAndTenantNo(String appName, String tenantNo);
+    ApplicationEntity findFirstByAppIdAndTenantNo(String appId, String tenantNo);
 
     ApplicationEntity findFirstByTenantNoAndPackageNameOrAppName(String tenantNo, String packageName, String appName);
 

+ 14 - 0
src/main/java/com/xuqm/server/appmanager/repository/sys/v1/ReleaseRepository.java

@@ -0,0 +1,14 @@
+package com.xuqm.server.appmanager.repository.sys.v1;
+
+import com.xuqm.server.appmanager.entitys.sys.v1.ApplicationEntity;
+import com.xuqm.server.appmanager.entitys.sys.v1.ReleaseEntity;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ReleaseRepository extends JpaRepository<ReleaseEntity, Long> {
+    ReleaseEntity findFirstByAppIdAndTenantNoAndVersionCodeGreaterThanEqual(String appId, String tenantNo, String versionCode);
+    Page<ReleaseEntity> findAllByAppIdAndTenantNo(String appId, String tenantNo, Pageable pageable);
+}