Răsfoiți Sursa

适配qmth-boot:1.0.4;去掉App模型的master_verion_id字段,自动查询最新版本号显示

luoshi 2 ani în urmă
părinte
comite
bb27109eb2
24 a modificat fișierele cu 213 adăugiri și 407 ștergeri
  1. 15 49
      src/main/java/com/qmth/ops/api/controller/admin/AppController.java
  2. 0 1
      src/main/java/com/qmth/ops/api/controller/admin/EnvController.java
  3. 0 1
      src/main/java/com/qmth/ops/api/controller/admin/ModuleController.java
  4. 0 2
      src/main/java/com/qmth/ops/api/controller/admin/NginxConfigController.java
  5. 0 6
      src/main/java/com/qmth/ops/api/controller/admin/PropertyController.java
  6. 1 6
      src/main/java/com/qmth/ops/api/controller/admin/UserController.java
  7. 0 2
      src/main/java/com/qmth/ops/api/controller/admin/VersionController.java
  8. 1 9
      src/main/java/com/qmth/ops/api/security/AdminAuthorizationService.java
  9. 1 12
      src/main/java/com/qmth/ops/api/security/AdminSession.java
  10. 3 7
      src/main/java/com/qmth/ops/api/security/OpenAuthorizationService.java
  11. 92 0
      src/main/java/com/qmth/ops/api/vo/AppVersionVO.java
  12. 0 10
      src/main/java/com/qmth/ops/biz/dao/AppDao.java
  13. 0 8
      src/main/java/com/qmth/ops/biz/dao/AppUserDao.java
  14. 0 10
      src/main/java/com/qmth/ops/biz/domain/App.java
  15. 0 74
      src/main/java/com/qmth/ops/biz/domain/AppDTO.java
  16. 0 40
      src/main/java/com/qmth/ops/biz/domain/AppUser.java
  17. 4 16
      src/main/java/com/qmth/ops/biz/query/AppQuery.java
  18. 4 24
      src/main/java/com/qmth/ops/biz/service/AppService.java
  19. 0 44
      src/main/java/com/qmth/ops/biz/service/AppUserService.java
  20. 46 0
      src/main/java/com/qmth/ops/biz/service/InitService.java
  21. 5 0
      src/main/java/com/qmth/ops/biz/service/VersionService.java
  22. 3 1
      src/main/resources/application.properties
  23. 0 32
      src/main/resources/mapper/AppMapper.xml
  24. 38 53
      src/main/resources/script/init.sql

+ 15 - 49
src/main/java/com/qmth/ops/api/controller/admin/AppController.java

@@ -3,19 +3,20 @@ package com.qmth.ops.api.controller.admin;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.security.AdminSession;
+import com.qmth.ops.api.vo.AppVersionVO;
 import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.AppDTO;
-import com.qmth.ops.biz.domain.AppUser;
 import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.query.AppQuery;
 import com.qmth.ops.biz.service.AppService;
-import com.qmth.ops.biz.service.AppUserService;
-import com.qmth.ops.biz.service.UserService;
 import com.qmth.ops.biz.service.VersionService;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+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.stream.Collectors;
 
 @RestController
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/app")
@@ -24,68 +25,33 @@ public class AppController {
     @Resource
     private AppService appService;
 
-    @Resource
-    private AppUserService appUserService;
-
     @Resource
     private VersionService versionService;
 
-    @Resource
-    private UserService userService;
-
     @PostMapping("/query")
-    public IPage<AppDTO> query(@RequestAttribute AdminSession adminSession, AppQuery query) {
-        query.setUser(adminSession.getUser());
-        return appService.query(query);
+    public IPage<AppVersionVO> query(AppQuery query) {
+        return appService.query(query).convert(app -> new AppVersionVO(app, versionService));
     }
 
     @PostMapping("/list")
-    public List<AppDTO> list(@RequestAttribute AdminSession adminSession, AppQuery query) {
-        query.setUser(adminSession.getUser());
-        return appService.list(query);
+    public List<AppVersionVO> list(AppQuery query) {
+        return appService.list(query).stream().map(app -> new AppVersionVO(app, versionService))
+                .collect(Collectors.toList());
     }
 
     @PostMapping("/insert")
-    public AppDTO insert(@RequestAttribute AdminSession adminSession, App app) {
+    public AppVersionVO insert(@RequestAttribute AdminSession adminSession, App app) {
         adminSession.validateRole(Role.ADMIN);
         appService.insert(app);
-        return appService.findDTO(app.getId());
+        return new AppVersionVO(appService.getById(app.getId()), versionService);
     }
 
     @PostMapping("/update")
-    public AppDTO update(@RequestAttribute AdminSession adminSession, App app) {
+    public AppVersionVO update(@RequestAttribute AdminSession adminSession, App app) {
         adminSession.validateRole(Role.ADMIN);
         appService.update(app);
-        return appService.findDTO(app.getId());
+        return new AppVersionVO(appService.getById(app.getId()), versionService);
     }
 
-    @PostMapping("/master_version")
-    public AppDTO updateMasterVersion(@RequestAttribute AdminSession adminSession, @RequestParam Long id,
-            @RequestParam Long versionId) {
-        adminSession.validateRole(Role.ADMIN);
-        appService.setMasterVersion(appService.getById(id), versionService.getById(versionId));
-        return appService.findDTO(id);
-    }
-
-    @PostMapping("/user/list")
-    public List<AppUser> userList(@RequestAttribute AdminSession adminSession, @RequestParam Long id) {
-        adminSession.validateRole(Role.ADMIN);
-        return appUserService.listByApp(appService.getById(id));
-    }
-
-    @PostMapping("/user/bind")
-    public AppUser bindUser(@RequestAttribute AdminSession adminSession, @RequestParam Long id,
-            @RequestParam Long userId) {
-        adminSession.validateRole(Role.ADMIN);
-        return appUserService.insert(appService.getById(id), userService.getById(userId));
-    }
-
-    @PostMapping("/user/unbind")
-    public AppUser unbindUser(@RequestAttribute AdminSession adminSession, @RequestParam Long id,
-            @RequestParam Long userId) {
-        adminSession.validateRole(Role.ADMIN);
-        appUserService.delete(appService.getById(id), userService.getById(userId));
-        return new AppUser(id, userId);
-    }
 }
 

+ 0 - 1
src/main/java/com/qmth/ops/api/controller/admin/EnvController.java

@@ -57,7 +57,6 @@ public class EnvController {
 
     @PostMapping("/list")
     public List<EnvVO> list(@RequestAttribute AdminSession adminSession, Long appId) {
-        adminSession.validateApp(appService.getById(appId));
         return envService.list(appId).stream().map(env -> new EnvVO(env, userService.getById(env.getUserId())))
                 .collect(Collectors.toList());
     }

+ 0 - 1
src/main/java/com/qmth/ops/api/controller/admin/ModuleController.java

@@ -39,7 +39,6 @@ public class ModuleController {
 
     @PostMapping("/list")
     public List<Module> list(@RequestAttribute AdminSession adminSession, ModuleQuery query) {
-        adminSession.validateApp(appService.getById(query.getAppId()));
         return moduleService.list(query);
     }
 

+ 0 - 2
src/main/java/com/qmth/ops/api/controller/admin/NginxConfigController.java

@@ -31,7 +31,6 @@ public class NginxConfigController {
     @PostMapping("/find")
     public NginxConfig find(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam(required = false) Long envId, @RequestParam(required = false) Long moduleId) {
-        adminSession.validateApp(appService.getById(appId));
         return nginxConfigService.find(appService.getById(appId), envId != null ? envService.getById(envId) : null,
                 moduleId != null ? moduleService.getById(moduleId) : null);
     }
@@ -40,7 +39,6 @@ public class NginxConfigController {
     public Object update(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam(required = false) Long envId, @RequestParam(required = false) Long moduleId,
             @RequestParam String content) {
-        adminSession.validateApp(appService.getById(appId));
         if (envId != null) {
             adminSession.validateEnv(envService.getById(envId));
         } else {

+ 0 - 6
src/main/java/com/qmth/ops/api/controller/admin/PropertyController.java

@@ -62,7 +62,6 @@ public class PropertyController {
     @PostMapping("/baseline")
     public List<PropertyItem> listBaseline(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam Long versionId, @RequestParam Long moduleId) {
-        adminSession.validateApp(appService.getById(appId));
         return propertyService.listBaseline(appId, versionId, moduleId);
     }
 
@@ -72,7 +71,6 @@ public class PropertyController {
             @RequestParam FileFormat extension, @RequestParam(required = false) Long inheritVersionId)
             throws IOException {
         adminSession.validateRole(Role.ADMIN, Role.DEV);
-        adminSession.validateApp(appService.getById(appId));
         return propertyService.updateBaseline(appService.getById(appId), versionService.getById(versionId),
                 moduleService.getById(moduleId), file.getInputStream(), extension,
                 inheritVersionId != null ? versionService.getById(inheritVersionId) : null);
@@ -81,14 +79,12 @@ public class PropertyController {
     @PostMapping("/baseline/item/update")
     public PropertyItem updateBaselineItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
         adminSession.validateRole(Role.ADMIN, Role.DEV);
-        adminSession.validateApp(appService.getById(item.getAppId()));
         return propertyService.updateBaselineItem(item);
     }
 
     @PostMapping("/list")
     public List<PropertyItem> listPropertyItem(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam Long versionId, @RequestParam Long moduleId, @RequestParam Long envId) {
-        adminSession.validateApp(appService.getById(appId));
         Env env = envService.getById(envId);
         List<PropertyItem> list = propertyService.listPropertyItem(appId, versionId, moduleId, env.getId());
         //非管理员/运维角色,且非环境维护用户,需要隐藏机密信息
@@ -123,14 +119,12 @@ public class PropertyController {
 
     @PostMapping("/item/update")
     public PropertyItem updatePropertyItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
-        adminSession.validateApp(appService.getById(item.getAppId()));
         adminSession.validateEnv(envService.getById(item.getEnvId()));
         return propertyService.updatePropertyItem(item);
     }
 
     @PostMapping("/item/delete")
     public Object deletePropertyItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
-        adminSession.validateApp(appService.getById(item.getAppId()));
         adminSession.validateEnv(envService.getById(item.getEnvId()));
         propertyService.deletePropertyItem(item);
         Map<String, Object> map = new HashMap<>();

+ 1 - 6
src/main/java/com/qmth/ops/api/controller/admin/UserController.java

@@ -12,7 +12,6 @@ import com.qmth.ops.api.vo.CodeNameVO;
 import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.domain.User;
 import com.qmth.ops.biz.query.UserQuery;
-import com.qmth.ops.biz.service.AppUserService;
 import com.qmth.ops.biz.service.FileService;
 import com.qmth.ops.biz.service.UserService;
 import org.springframework.validation.annotation.Validated;
@@ -29,9 +28,6 @@ public class UserController {
     @Resource
     private UserService userService;
 
-    @Resource
-    private AppUserService appUserService;
-
     @Resource
     private FileService fileService;
 
@@ -48,8 +44,7 @@ public class UserController {
         if (!user.buildPassword(form.getPassword()).equals(user.getPassword())) {
             throw new ParameterException("密码错误");
         }
-        return new AdminSession(userService.changeAccessToken(user), appUserService)
-                .getLoginResult(fileService.getServer());
+        return new AdminSession(userService.changeAccessToken(user)).getLoginResult(fileService.getServer());
     }
 
     @RequestMapping("/roles")

+ 0 - 2
src/main/java/com/qmth/ops/api/controller/admin/VersionController.java

@@ -34,14 +34,12 @@ public class VersionController {
     public Version insert(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam VersionNumber name) {
         adminSession.validateRole(Role.ADMIN, Role.DEV);
-        adminSession.validateApp(appService.getById(appId));
         return versionService.insert(appService.getById(appId), name);
     }
 
     @PostMapping("/update")
     public Version list(@RequestAttribute AdminSession adminSession, Version version) {
         adminSession.validateRole(Role.ADMIN, Role.DEV);
-        adminSession.validateApp(appService.getById(versionService.getById(version.getId()).getAppId()));
         return versionService.update(version);
     }
 

+ 1 - 9
src/main/java/com/qmth/ops/api/security/AdminAuthorizationService.java

@@ -5,7 +5,6 @@ import com.qmth.boot.core.security.service.AuthorizationService;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.biz.domain.User;
-import com.qmth.ops.biz.service.AppUserService;
 import com.qmth.ops.biz.service.UserService;
 
 import javax.annotation.Resource;
@@ -16,20 +15,13 @@ public class AdminAuthorizationService implements AuthorizationService<AdminSess
     @Resource
     private UserService userService;
 
-    @Resource
-    private AppUserService appUserService;
-
     @Override
     public AdminSession findByIdentity(String identity, SignatureType signatureType, String path) {
         User user = userService.getById(Long.parseLong(identity));
         if (user != null) {
-            return new AdminSession(user, appUserService);
+            return new AdminSession(user);
         }
         return null;
     }
 
-    @Override
-    public boolean hasPermission(AdminSession session, String path) {
-        return true;
-    }
 }

+ 1 - 12
src/main/java/com/qmth/ops/api/security/AdminSession.java

@@ -3,21 +3,16 @@ package com.qmth.ops.api.security;
 import com.qmth.boot.core.exception.UnauthorizedException;
 import com.qmth.boot.core.security.model.AccessEntity;
 import com.qmth.ops.api.dto.LoginResult;
-import com.qmth.ops.biz.domain.App;
 import com.qmth.ops.biz.domain.Env;
 import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.domain.User;
-import com.qmth.ops.biz.service.AppUserService;
 
 public class AdminSession implements AccessEntity {
 
     private User user;
 
-    private AppUserService appUserService;
-
-    public AdminSession(User user, AppUserService appUserService) {
+    public AdminSession(User user) {
         this.user = user;
-        this.appUserService = appUserService;
     }
 
     public LoginResult getLoginResult(String fileServer) {
@@ -41,12 +36,6 @@ public class AdminSession implements AccessEntity {
         }
     }
 
-    public void validateApp(App app) {
-        if (!user.hasRole(Role.OPS, Role.ADMIN) && !appUserService.exist(app, user)) {
-            throw new UnauthorizedException("没有应用操作权限");
-        }
-    }
-
     public void validateEnv(Env env) {
         if (!user.hasRole(Role.ADMIN) && !user.getId().equals(env.getUserId())) {
             throw new UnauthorizedException("没有环境操作权限");

+ 3 - 7
src/main/java/com/qmth/ops/api/security/OpenAuthorizationService.java

@@ -3,7 +3,6 @@ package com.qmth.ops.api.security;
 import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.service.AuthorizationService;
 import com.qmth.boot.core.sms.model.SmsConstants;
-import com.qmth.boot.core.solar.model.AppControl;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.biz.domain.Deploy;
@@ -22,14 +21,11 @@ public class OpenAuthorizationService implements AuthorizationService<AccessDepl
     public AccessDeploy findByIdentity(String identity, SignatureType signatureType, String path) {
         Deploy deploy = deployService.findByAccessKey(identity);
         if (deploy != null) {
-            return new AccessDeploy(deploy);
+            if (deploy.getControl() != null && !deploy.getControl().hasExpired()) {
+                return new AccessDeploy(deploy);
+            }
         }
         return null;
     }
 
-    @Override
-    public boolean hasPermission(AccessDeploy accessDeploy, String path) {
-        AppControl control = accessDeploy.getDeploy().getControl();
-        return control == null || !control.hasExpired();
-    }
 }

+ 92 - 0
src/main/java/com/qmth/ops/api/vo/AppVersionVO.java

@@ -0,0 +1,92 @@
+package com.qmth.ops.api.vo;
+
+import com.qmth.ops.biz.domain.App;
+import com.qmth.ops.biz.domain.Version;
+import com.qmth.ops.biz.service.VersionService;
+
+public class AppVersionVO {
+
+    private Long id;
+
+    private String code;
+
+    private String name;
+
+    private Long latestVersionId;
+
+    private String latestVersionName;
+
+    private Long createTime;
+
+    private Long updateTime;
+
+    public AppVersionVO(App app, VersionService versionService) {
+        this.id = app.getId();
+        this.code = app.getCode();
+        this.name = app.getName();
+        this.createTime = app.getCreateTime();
+        this.updateTime = app.getUpdateTime();
+
+        Version version = versionService.findLatestByApp(app.getId());
+        if (version != null) {
+            latestVersionId = version.getId();
+            latestVersionName = version.getName();
+        }
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Long getLatestVersionId() {
+        return latestVersionId;
+    }
+
+    public void setLatestVersionId(Long latestVersionId) {
+        this.latestVersionId = latestVersionId;
+    }
+
+    public String getLatestVersionName() {
+        return latestVersionName;
+    }
+
+    public void setLatestVersionName(String latestVersionName) {
+        this.latestVersionName = latestVersionName;
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+}

+ 0 - 10
src/main/java/com/qmth/ops/biz/dao/AppDao.java

@@ -1,18 +1,8 @@
 package com.qmth.ops.biz.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.AppDTO;
-import com.qmth.ops.biz.query.AppQuery;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
 
 public interface AppDao extends BaseMapper<App> {
 
-    List<AppDTO> findByQuery(@Param("query") AppQuery query);
-
-    IPage<AppDTO> findByQuery(Page page, @Param("query") AppQuery query);
 }

+ 0 - 8
src/main/java/com/qmth/ops/biz/dao/AppUserDao.java

@@ -1,8 +0,0 @@
-package com.qmth.ops.biz.dao;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.qmth.ops.biz.domain.AppUser;
-
-public interface AppUserDao extends BaseMapper<AppUser> {
-
-}

+ 0 - 10
src/main/java/com/qmth/ops/biz/domain/App.java

@@ -18,8 +18,6 @@ public class App implements Serializable {
 
     private String name;
 
-    private Long masterVersionId;
-
     private Long createTime;
 
     private Long updateTime;
@@ -48,14 +46,6 @@ public class App implements Serializable {
         this.name = name;
     }
 
-    public Long getMasterVersionId() {
-        return masterVersionId;
-    }
-
-    public void setMasterVersionId(Long masterVersionId) {
-        this.masterVersionId = masterVersionId;
-    }
-
     public Long getCreateTime() {
         return createTime;
     }

+ 0 - 74
src/main/java/com/qmth/ops/biz/domain/AppDTO.java

@@ -1,74 +0,0 @@
-package com.qmth.ops.biz.domain;
-
-public class AppDTO {
-
-    private Long id;
-
-    private String code;
-
-    private String name;
-
-    private Long masterVersionId;
-
-    private String masterVersionName;
-
-    private Long createTime;
-
-    private Long updateTime;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public Long getMasterVersionId() {
-        return masterVersionId;
-    }
-
-    public void setMasterVersionId(Long masterVersionId) {
-        this.masterVersionId = masterVersionId;
-    }
-
-    public String getMasterVersionName() {
-        return masterVersionName;
-    }
-
-    public void setMasterVersionName(String masterVersionName) {
-        this.masterVersionName = masterVersionName;
-    }
-
-    public Long getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(Long createTime) {
-        this.createTime = createTime;
-    }
-
-    public Long getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(Long updateTime) {
-        this.updateTime = updateTime;
-    }
-}

+ 0 - 40
src/main/java/com/qmth/ops/biz/domain/AppUser.java

@@ -1,40 +0,0 @@
-package com.qmth.ops.biz.domain;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-
-import java.io.Serializable;
-
-@TableName("app_user")
-public class AppUser implements Serializable {
-
-    private static final long serialVersionUID = -7034544322116255919L;
-
-    private Long appId;
-
-    private Long userId;
-
-    public AppUser() {
-
-    }
-
-    public AppUser(Long appId, Long userId) {
-        this.appId = appId;
-        this.userId = userId;
-    }
-
-    public Long getAppId() {
-        return appId;
-    }
-
-    public void setAppId(Long appId) {
-        this.appId = appId;
-    }
-
-    public Long getUserId() {
-        return userId;
-    }
-
-    public void setUserId(Long userId) {
-        this.userId = userId;
-    }
-}

+ 4 - 16
src/main/java/com/qmth/ops/biz/query/AppQuery.java

@@ -1,9 +1,8 @@
 package com.qmth.ops.biz.query;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmth.boot.mybatis.query.BaseQuery;
 import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.Role;
-import com.qmth.ops.biz.domain.User;
 
 public class AppQuery extends BaseQuery<App> {
 
@@ -15,8 +14,6 @@ public class AppQuery extends BaseQuery<App> {
 
     private String nameStartWith;
 
-    private Long userId;
-
     public Long getId() {
         return id;
     }
@@ -41,18 +38,9 @@ public class AppQuery extends BaseQuery<App> {
         this.nameStartWith = nameStartWith;
     }
 
-    public Long getUserId() {
-        return userId;
-    }
-
-    public void setUserId(Long userId) {
-        this.userId = userId;
-    }
-
-    public void setUser(User user) {
-        if (!user.hasRole(Role.OPS, Role.ADMIN)) {
-            setUserId(user.getId());
-        }
+    public LambdaQueryWrapper<App> buildQuery() {
+        return new LambdaQueryWrapper<App>().eq(id != null, App::getId, id).eq(code != null, App::getCode, code)
+                .likeRight(nameStartWith != null, App::getName, nameStartWith);
     }
 
 }

+ 4 - 24
src/main/java/com/qmth/ops/biz/service/AppService.java

@@ -4,17 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.qmth.boot.core.exception.ParameterException;
 import com.qmth.ops.biz.dao.AppDao;
 import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.AppDTO;
-import com.qmth.ops.biz.domain.Version;
 import com.qmth.ops.biz.query.AppQuery;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.validation.constraints.NotNull;
 import java.util.List;
 
 @Service
@@ -38,32 +34,16 @@ public class AppService extends ServiceImpl<AppDao, App> {
                 .set(App::getUpdateTime, System.currentTimeMillis()).eq(App::getId, app.getId()));
     }
 
-    public AppDTO findDTO(Long id) {
-        AppQuery query = new AppQuery();
-        query.setId(id);
-        List<AppDTO> list = list(query);
-        return list.isEmpty() ? null : list.get(0);
+    public IPage<App> query(AppQuery query) {
+        return this.page(query, query.buildQuery());
     }
 
-    public IPage<AppDTO> query(AppQuery query) {
-        return appDao.findByQuery(query, query);
-    }
-
-    public List<AppDTO> list(AppQuery query) {
-        return appDao.findByQuery(query);
+    public List<App> list(AppQuery query) {
+        return this.list(query.buildQuery());
     }
 
     public App findByCode(String code) {
         return appDao.selectOne(new LambdaQueryWrapper<App>().eq(App::getCode, code));
     }
-
-    @Transactional
-    public void setMasterVersion(@NotNull App app, @NotNull Version version) {
-        if (!version.getAppId().equals(app.getId())) {
-            throw new ParameterException("指定版本不属于当前应用");
-        }
-        appDao.update(app, new LambdaUpdateWrapper<App>().set(App::getMasterVersionId, version.getId())
-                .set(App::getUpdateTime, System.currentTimeMillis()).eq(App::getId, app.getId()));
-    }
 }
 

+ 0 - 44
src/main/java/com/qmth/ops/biz/service/AppUserService.java

@@ -1,44 +0,0 @@
-package com.qmth.ops.biz.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.qmth.ops.biz.dao.AppUserDao;
-import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.AppUser;
-import com.qmth.ops.biz.domain.User;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.Resource;
-import javax.validation.constraints.NotNull;
-import java.util.List;
-
-@Service
-public class AppUserService extends ServiceImpl<AppUserDao, AppUser> {
-
-    @Resource
-    private AppUserDao appUserDao;
-
-    public List<AppUser> listByApp(@NotNull App app) {
-        return appUserDao.selectList(new LambdaQueryWrapper<AppUser>().eq(AppUser::getAppId, app.getId()));
-    }
-
-    public boolean exist(@NotNull App app, @NotNull User user) {
-        return appUserDao.selectOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getAppId, app.getId())
-                .eq(AppUser::getUserId, user.getId())) != null;
-    }
-
-    @Transactional
-    public AppUser insert(@NotNull App app, @NotNull User user) {
-        AppUser au = new AppUser(app.getId(), user.getId());
-        appUserDao.insert(au);
-        return au;
-    }
-
-    @Transactional
-    public void delete(@NotNull App app, @NotNull User user) {
-        appUserDao.delete(new LambdaQueryWrapper<AppUser>().eq(AppUser::getAppId, app.getId())
-                .eq(AppUser::getUserId, user.getId()));
-    }
-}
-

+ 46 - 0
src/main/java/com/qmth/ops/biz/service/InitService.java

@@ -0,0 +1,46 @@
+package com.qmth.ops.biz.service;
+
+import com.qmth.boot.mybatis.service.SqlProvider;
+import com.qmth.boot.tools.models.ByteArray;
+import com.qmth.ops.biz.domain.Role;
+import com.qmth.ops.biz.domain.User;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+
+@Service
+public class InitService implements SqlProvider, CommandLineRunner {
+
+    private static final Logger log = LoggerFactory.getLogger(InitService.class);
+
+    @Resource
+    private UserService userService;
+
+    @Override
+    public String get() {
+        try {
+            return ByteArray.fromInputStream(this.getClass().getClassLoader().getResourceAsStream("script/init.sql"))
+                    .toString();
+        } catch (IOException e) {
+            throw new RuntimeException("数据库初始化异常", e);
+        }
+    }
+
+    @Override
+    public void run(String... args) {
+        if (userService.count() == 0) {
+            User user = new User();
+            user.setLoginName("admin");
+            user.setName("系统管理员");
+            user.setPassword("123456");
+            user.setRole(new Role[] { Role.ADMIN });
+            user.setEnable(true);
+            userService.insert(user);
+            log.info("系统管理员初始化完成");
+        }
+    }
+}

+ 5 - 0
src/main/java/com/qmth/ops/biz/service/VersionService.java

@@ -53,5 +53,10 @@ public class VersionService extends ServiceImpl<VersionDao, Version> {
                 .eq(Version::getMainNumber, number.getMain()).eq(Version::getMiddleNumber, number.getMiddle())
                 .eq(Version::getSubNumber, number.getSub()));
     }
+
+    public Version findLatestByApp(@NotNull Long appId) {
+        return versionDao.selectOne(new LambdaQueryWrapper<Version>().eq(Version::getAppId, appId)
+                .orderByDesc(Version::getMainNumber, Version::getMiddleNumber, Version::getSubNumber));
+    }
 }
 

+ 3 - 1
src/main/resources/application.properties

@@ -1,5 +1,7 @@
 server.port=8080
 
+management.endpoints.web.exposure.include=health,metrics,prometheus
+
 com.qmth.api.global-auth=false
 
 com.qmth.datasource.url=jdbc:mysql://192.168.10.83:3306/ops_db?useUnicode=true&characterEncoding=UTF-8
@@ -11,4 +13,4 @@ com.qmth.fss.server=http://oss-file.qmth.com.cn/solar
 
 com.qmth.sms.server=http://127.0.0.1:8090
 
-admin.private-key=
+admin.private-key=/Users/luoshi/Downloads/ops/rsa/test/test-private.key

+ 0 - 32
src/main/resources/mapper/AppMapper.xml

@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.qmth.ops.biz.dao.AppDao">
-
-    <select id="findByQuery" resultType="com.qmth.ops.biz.domain.AppDTO">
-        SELECT
-        a.id,
-        a.code,
-        a.name,
-        a.master_version_id,
-        v.name master_version_name,
-        a.create_time,
-        a.update_time
-        FROM app a
-        left join version v on a.id=v.app_id and a.master_version_id=v.id
-        <if test="query.userId != null">
-            inner join app_user au on a.id=au.app_id and au.user_id=#{query.userId}
-        </if>
-        <where>
-            <if test="query.id != null">
-                and a.id=#{query.id}
-            </if>
-            <if test="query.code != null">
-                and a.code=#{query.code}
-            </if>
-            <if test="query.nameStartWith != null">
-                and a.name like concat(#{query.nameStartWith},'%')
-            </if>
-        </where>
-    </select>
-
-</mapper>

+ 38 - 53
src/main/resources/script/init.sql

@@ -1,36 +1,26 @@
 -- Create syntax for TABLE 'app'
-CREATE TABLE `app`
+CREATE TABLE IF NOT EXISTS `app`
 (
-    `id`                bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-    `code`              varchar(64)         NOT NULL DEFAULT '',
-    `name`              varchar(64)         NOT NULL DEFAULT '',
-    `master_version_id` bigint(20) unsigned          DEFAULT NULL,
-    `create_time`       bigint(20)          NOT NULL,
-    `update_time`       bigint(20)          NOT NULL,
+    `id`          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+    `code`        varchar(64)         NOT NULL,
+    `name`        varchar(64)         NOT NULL,
+    `create_time` bigint(20)          NOT NULL,
+    `update_time` bigint(20)          NOT NULL,
     PRIMARY KEY (`id`),
     UNIQUE KEY `code` (`code`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
--- Create syntax for TABLE 'app_user'
-CREATE TABLE `app_user`
-(
-    `app_id`  bigint(20) unsigned NOT NULL,
-    `user_id` bigint(20) unsigned NOT NULL,
-    PRIMARY KEY (`app_id`, `user_id`)
-) ENGINE = InnoDB
-  DEFAULT CHARSET = utf8mb4;
-
 -- Create syntax for TABLE 'property_item'
-CREATE TABLE `property_item`
+CREATE TABLE IF NOT EXISTS `property_item`
 (
     `app_id`      bigint(20) unsigned NOT NULL,
     `version_id`  bigint(20) unsigned NOT NULL,
     `module_id`   bigint(20) unsigned NOT NULL,
     `env_id`      bigint(20)          NOT NULL,
-    `key`         varchar(64)         NOT NULL DEFAULT '',
-    `value`       text                NOT NULL DEFAULT '',
-    `comment`     varchar(128)                 DEFAULT NULL,
+    `key`         varchar(64)         NOT NULL,
+    `value`       text                NOT NULL,
+    `comment`     varchar(128) DEFAULT NULL,
     `mode`        varchar(16)         NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,
@@ -39,13 +29,13 @@ CREATE TABLE `property_item`
   DEFAULT CHARSET = utf8mb4;
 
 -- Create syntax for TABLE 'env'
-CREATE TABLE `env`
+CREATE TABLE IF NOT EXISTS `env`
 (
     `id`          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
     `app_id`      bigint(20) unsigned NOT NULL,
-    `code`        varchar(64)         NOT NULL DEFAULT '',
-    `name`        varchar(64)         NOT NULL DEFAULT '',
-    `type`        varchar(16)         NOT NULL DEFAULT '',
+    `code`        varchar(64)         NOT NULL,
+    `name`        varchar(64)         NOT NULL,
+    `type`        varchar(16)         NOT NULL,
     `user_id`     bigint(20) unsigned NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,
@@ -55,12 +45,12 @@ CREATE TABLE `env`
   DEFAULT CHARSET = utf8mb4;
 
 -- Create syntax for TABLE 'module'
-CREATE TABLE `module`
+CREATE TABLE IF NOT EXISTS `module`
 (
     `id`          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
     `app_id`      bigint(20) unsigned NOT NULL,
-    `code`        varchar(64)         NOT NULL DEFAULT '',
-    `name`        varchar(64)         NOT NULL DEFAULT '',
+    `code`        varchar(64)         NOT NULL,
+    `name`        varchar(64)         NOT NULL,
     `enable`      tinyint(1)          NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,
@@ -70,16 +60,16 @@ CREATE TABLE `module`
   DEFAULT CHARSET = utf8mb4;
 
 -- Create syntax for TABLE 'user'
-CREATE TABLE `user`
+CREATE TABLE IF NOT EXISTS `user`
 (
     `id`            bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-    `login_name`    varchar(64)         NOT NULL DEFAULT '',
-    `name`          varchar(64)         NOT NULL DEFAULT '',
-    `password`      varchar(64)         NOT NULL DEFAULT '',
-    `role`          varchar(64)         NOT NULL DEFAULT '',
-    `enable`        tinyint(1)          NOT NULL DEFAULT 1,
-    `export_secret` varchar(64)         NOT NULL DEFAULT '',
-    `access_token`  varchar(64)                  DEFAULT NULL,
+    `login_name`    varchar(64)         NOT NULL,
+    `name`          varchar(64)         NOT NULL,
+    `password`      varchar(64)         NOT NULL,
+    `role`          varchar(64)         NOT NULL,
+    `enable`        tinyint(1)          NOT NULL,
+    `export_secret` varchar(64)         NOT NULL,
+    `access_token`  varchar(64) DEFAULT NULL,
     `create_time`   bigint(20)          NOT NULL,
     `update_time`   bigint(20)          NOT NULL,
     PRIMARY KEY (`id`),
@@ -89,11 +79,11 @@ CREATE TABLE `user`
   DEFAULT CHARSET = utf8mb4;
 
 -- Create syntax for TABLE 'version'
-CREATE TABLE `version`
+CREATE TABLE IF NOT EXISTS `version`
 (
     `id`            bigint(20) unsigned NOT NULL AUTO_INCREMENT,
     `app_id`        bigint(20) unsigned NOT NULL,
-    `name`          varchar(64)         NOT NULL DEFAULT '',
+    `name`          varchar(64)         NOT NULL,
     `main_number`   int(11)             NOT NULL,
     `middle_number` int(11)             NOT NULL,
     `sub_number`    int(11)             NOT NULL,
@@ -105,7 +95,7 @@ CREATE TABLE `version`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `nginx_config`
+CREATE TABLE IF NOT EXISTS `nginx_config`
 (
     `app_id`      bigint(20) unsigned NOT NULL,
     `module_id`   bigint(20) unsigned NOT NULL,
@@ -117,7 +107,7 @@ CREATE TABLE `nginx_config`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `deploy`
+CREATE TABLE IF NOT EXISTS `deploy`
 (
     `id`            bigint(11) unsigned NOT NULL AUTO_INCREMENT,
     `app_id`        bigint(11)          NOT NULL,
@@ -135,7 +125,7 @@ CREATE TABLE `deploy`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `deploy_device`
+CREATE TABLE IF NOT EXISTS `deploy_device`
 (
     `deploy_id`   bigint(20) unsigned NOT NULL,
     `device_id`   varchar(128)        NOT NULL,
@@ -145,7 +135,7 @@ CREATE TABLE `deploy_device`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `deploy_org`
+CREATE TABLE IF NOT EXISTS `deploy_org`
 (
     `deploy_id` bigint(20) unsigned NOT NULL,
     `org_id`    bigint(20) unsigned NOT NULL,
@@ -153,7 +143,7 @@ CREATE TABLE `deploy_org`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `org`
+CREATE TABLE IF NOT EXISTS `org`
 (
     `id`            bigint(11) unsigned NOT NULL AUTO_INCREMENT,
     `code`          varchar(16)         NOT NULL,
@@ -172,20 +162,15 @@ CREATE TABLE `org`
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
 
-CREATE TABLE `wxapp`
+CREATE TABLE IF NOT EXISTS `wxapp`
 (
-    `id`           varchar(128) NOT NULL DEFAULT '',
-    `name`         varchar(64)  NOT NULL DEFAULT '',
-    `secret`       varchar(512) NOT NULL DEFAULT '',
-    `access_token` varchar(128)          DEFAULT NULL,
-    `expire_time`  bigint(20)            DEFAULT NULL,
+    `id`           varchar(128) NOT NULL,
+    `name`         varchar(64)  NOT NULL,
+    `secret`       varchar(512) NOT NULL,
+    `access_token` varchar(128) DEFAULT NULL,
+    `expire_time`  bigint(20)   DEFAULT NULL,
     `create_time`  bigint(20)   NOT NULL,
     `update_time`  bigint(20)   NOT NULL,
     PRIMARY KEY (`id`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;
-
-INSERT INTO `user` (`login_name`, `name`, `password`, `role`, `access_token`, `export_secret`, `create_time`,
-                    `update_time`)
-VALUES ('admin', '系统管理员', '51f7be45b644056aa7de7340a56c0409', '[\"ADMIN\"]', '', '42cc190287d3e92c',
-        1663727301414, 1666928704263);