徐勤民 hai 2 meses
pai
achega
95a4bf8b4e

+ 11 - 10
src/main/java/com/xuqm/server/appmanager/controller/manager/v1/ManagerV1Controller.java

@@ -2,17 +2,16 @@ package com.xuqm.server.appmanager.controller.manager.v1;
 
 import com.xuqm.server.appmanager.common.CommonHelper;
 import com.xuqm.server.appmanager.common.JWTHelper;
-import com.xuqm.server.appmanager.common.TimeHelper;
+import com.xuqm.server.appmanager.controller.manager.v1.data.ManagerListData;
 import com.xuqm.server.appmanager.entitys.UserInfo;
 import com.xuqm.server.appmanager.entitys.sys.v1.ApplicationEntity;
 import com.xuqm.server.appmanager.http.HttpResult;
 import com.xuqm.server.appmanager.repository.sys.v1.ApplicationRepository;
 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.*;
 
-import java.util.List;
-import java.util.Random;
-
 @RestController
 @RequestMapping("manager/v1")
 public class ManagerV1Controller {
@@ -22,13 +21,13 @@ public class ManagerV1Controller {
 
     @PostMapping("/manager/create")
     public HttpResult<String> appCreate(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
+        UserInfo userInfo = JWTHelper.getUser(token);
+        if (null == userInfo) {
+            return new HttpResult<>(401, "登录失效", null);
+        }
         if (null == application.getAppName() || null == application.getPackageName()) {
             return new HttpResult<>(201, "参数错误", null);
         } else {
-            UserInfo userInfo = JWTHelper.getUser(token);
-            if (null == userInfo) {
-                return new HttpResult<>(401, "登录失效", null);
-            }
             ApplicationEntity app = applicationRepository.findFirstByAppNameAndTenantNo(application.getAppName(), userInfo.getTenantNo());
             if (null != app) return new HttpResult<>(201, "已创建相关类型的同名应用", null);
             app = new ApplicationEntity();
@@ -45,15 +44,17 @@ public class ManagerV1Controller {
     }
 
     @PostMapping("/manager/list")
-    public HttpResult<List<ApplicationEntity>> appList(@RequestBody ApplicationEntity application, @RequestHeader(name = "token") String token) throws Exception {
+    public HttpResult<Page<ApplicationEntity>> appList(@RequestBody ManagerListData 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);
 
 
-        List<ApplicationEntity> apps = applicationRepository.findAllByTenantNo(userInfo.getTenantNo());
+        Page<ApplicationEntity> apps = applicationRepository.findAllByTenantNo(userInfo.getTenantNo(), PageRequest.of(data.getPageNumber(), data.getPageSize()));
 
         return new HttpResult<>(200, "成功", apps);
     }

+ 8 - 0
src/main/java/com/xuqm/server/appmanager/controller/manager/v1/data/ManagerListData.java

@@ -0,0 +1,8 @@
+package com.xuqm.server.appmanager.controller.manager.v1.data;
+
+import com.xuqm.server.appmanager.data.PageData;
+import lombok.Data;
+
+@Data
+public class ManagerListData extends PageData {
+}

+ 0 - 6
src/main/java/com/xuqm/server/appmanager/controller/user/v1/UserV1Controller.java

@@ -4,8 +4,6 @@ import com.xuqm.server.appmanager.common.JWTHelper;
 import com.xuqm.server.appmanager.entitys.UserLogin;
 import com.xuqm.server.appmanager.entitys.sys.v1.TenantUserEntity;
 import com.xuqm.server.appmanager.http.HttpResult;
-import com.xuqm.server.appmanager.repository.sys.v1.ApplicationRepository;
-import com.xuqm.server.appmanager.repository.sys.v1.TenantRepository;
 import com.xuqm.server.appmanager.repository.sys.v1.TenantUserRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -17,12 +15,8 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("user/v1")
 public class UserV1Controller {
 
-    @Autowired
-    private TenantRepository tenantRepository;
     @Autowired
     private TenantUserRepository tenantUserRepository;
-    @Autowired
-    private ApplicationRepository applicationRepository;
 
     @PostMapping("/login")
     public HttpResult<String> userLogin(@RequestBody UserLogin user) throws Exception {

+ 11 - 0
src/main/java/com/xuqm/server/appmanager/data/PageData.java

@@ -0,0 +1,11 @@
+package com.xuqm.server.appmanager.data;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class PageData {
+    private int pageNumber;
+    private int pageSize;
+}

+ 7 - 2
src/main/java/com/xuqm/server/appmanager/repository/sys/v1/ApplicationRepository.java

@@ -1,7 +1,8 @@
 package com.xuqm.server.appmanager.repository.sys.v1;
 
 import com.xuqm.server.appmanager.entitys.sys.v1.ApplicationEntity;
-import com.xuqm.server.appmanager.enums.AppType;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
@@ -10,6 +11,10 @@ import java.util.List;
 @Repository
 public interface ApplicationRepository extends JpaRepository<ApplicationEntity, Long> {
     ApplicationEntity findFirstByAppNameAndTenantNo(String appName, String tenantNo);
-    List<ApplicationEntity> findAllByTenantNo(String tenantNo);
+
+    ApplicationEntity findFirstByTenantNoAndPackageNameOrAppName(String tenantNo, String packageName, String appName);
+
+    Page<ApplicationEntity> findAllByTenantNo(String tenantNo, Pageable pageable);
+
     boolean existsByAppId(String appId);
 }