Browse Source

add user service

AE86 2 years ago
parent
commit
7a2c6e6f13

+ 0 - 7
dbsyncer-biz/src/main/java/org/dbsyncer/biz/ConfigService.java

@@ -35,13 +35,6 @@ public interface ConfigService {
      */
     String getPassword();
 
-    /**
-     * 获取所有配置
-     *
-     * @return
-     */
-    List<ConfigVo> queryConfig();
-
     /**
      * 获取所有配置
      *

+ 20 - 0
dbsyncer-biz/src/main/java/org/dbsyncer/biz/UserService.java

@@ -0,0 +1,20 @@
+package org.dbsyncer.biz;
+
+import org.dbsyncer.biz.vo.UserVo;
+
+/**
+ * @author AE86
+ * @version 1.0.0
+ * @date 2022/11/17 0:16
+ */
+public interface UserService {
+
+    /**
+     * 获取登录用户信息
+     *
+     * @param username
+     * @return
+     */
+    UserVo getUserVo(String username);
+
+}

+ 9 - 21
dbsyncer-biz/src/main/java/org/dbsyncer/biz/impl/ConfigServiceImpl.java

@@ -12,7 +12,6 @@ import org.dbsyncer.parser.logger.LogType;
 import org.dbsyncer.parser.model.Config;
 import org.dbsyncer.parser.model.ConfigModel;
 import org.dbsyncer.plugin.enums.FileSuffixEnum;
-import org.dbsyncer.storage.constant.ConfigConstant;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -25,7 +24,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * @author AE86
@@ -50,10 +48,7 @@ public class ConfigServiceImpl implements ConfigService {
     @Override
     public String edit(Map<String, String> params) {
         synchronized (this) {
-            Config config = manager.getConfig(ConfigConstant.CONFIG);
-            if (null == config) {
-                configChecker.checkAddConfigModel(params);
-            }
+            getConfigModel();
             ConfigModel model = configChecker.checkEditConfigModel(params);
             manager.editConfig(model);
         }
@@ -62,30 +57,18 @@ public class ConfigServiceImpl implements ConfigService {
 
     @Override
     public ConfigVo getConfig() {
-        List<Config> all = manager.getConfigAll();
-        Config config = CollectionUtils.isEmpty(all) ? (Config) configChecker.checkAddConfigModel(new HashMap<>()) : all.get(0);
-        return convertConfig2Vo(config);
+        return convertConfig2Vo(getConfigModel());
     }
 
     @Override
     public String getPassword() {
-        List<Config> all = manager.getConfigAll();
-        Config config = CollectionUtils.isEmpty(all) ? (Config) configChecker.checkAddConfigModel(new HashMap<>()) : all.get(0);
-        return config.getPassword();
-    }
-
-    @Override
-    public List<ConfigVo> queryConfig() {
-        List<ConfigVo> list = manager.getConfigAll().stream()
-                .map(config -> convertConfig2Vo(config))
-                .collect(Collectors.toList());
-        return list;
+        return getConfigModel().getPassword();
     }
 
     @Override
     public List<ConfigModel> getConfigModelAll() {
         List<ConfigModel> list = new ArrayList<>();
-        manager.getConfigAll().forEach(config -> list.add(config));
+        list.add(getConfig());
         manager.getConnectorAll().forEach(config -> list.add(config));
         manager.getMappingAll().forEach(config -> list.add(config));
         manager.getMetaAll().forEach(config -> list.add(config));
@@ -118,6 +101,11 @@ public class ConfigServiceImpl implements ConfigService {
         }
     }
 
+    private Config getConfigModel() {
+        List<Config> all = manager.getConfigAll();
+        return CollectionUtils.isEmpty(all) ? (Config) configChecker.checkAddConfigModel(new HashMap<>()) : all.get(0);
+    }
+
     private ConfigVo convertConfig2Vo(Config config) {
         ConfigVo configVo = new ConfigVo();
         BeanUtils.copyProperties(config, configVo);

+ 19 - 0
dbsyncer-biz/src/main/java/org/dbsyncer/biz/impl/UserServiceImpl.java

@@ -0,0 +1,19 @@
+package org.dbsyncer.biz.impl;
+
+import org.dbsyncer.biz.UserService;
+import org.dbsyncer.biz.vo.UserVo;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author AE86
+ * @version 1.0.0
+ * @date 2022/11/17 0:16
+ */
+@Service
+public class UserServiceImpl implements UserService {
+
+    @Override
+    public UserVo getUserVo(String username) {
+        return new UserVo(username);
+    }
+}

+ 44 - 0
dbsyncer-biz/src/main/java/org/dbsyncer/biz/vo/UserVo.java

@@ -0,0 +1,44 @@
+package org.dbsyncer.biz.vo;
+
+/**
+ * @author AE86
+ * @version 1.0.0
+ * @date 2022/11/17 0:14
+ */
+public class UserVo {
+
+    /**
+     * 账号
+     */
+    private String username;
+
+    /**
+     * 昵称
+     */
+    private String nickname;
+
+    public UserVo(String username) {
+        this(username, username);
+    }
+
+    public UserVo(String username, String nickname) {
+        this.username = username;
+        this.nickname = nickname;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getNickname() {
+        return nickname;
+    }
+
+    public void setNickname(String nickname) {
+        this.nickname = nickname;
+    }
+}

+ 2 - 2
dbsyncer-storage/src/main/java/org/dbsyncer/storage/support/MysqlStorageServiceImpl.java

@@ -234,9 +234,9 @@ public class MysqlStorageServiceImpl extends AbstractStorageService {
         // order by updateTime,createTime desc
         sql.append(" order by ");
         if (executor.isOrderByUpdateTime()) {
-            sql.append(ConfigConstant.CONFIG_MODEL_UPDATE_TIME).append(",");
+            sql.append(UnderlineToCamelUtils.camelToUnderline(ConfigConstant.CONFIG_MODEL_UPDATE_TIME)).append(",");
         }
-        sql.append(ConfigConstant.CONFIG_MODEL_CREATE_TIME).append(" desc");
+        sql.append(UnderlineToCamelUtils.camelToUnderline(ConfigConstant.CONFIG_MODEL_CREATE_TIME)).append(" desc");
         sql.append(DatabaseConstant.MYSQL_PAGE_SQL);
         args.add((query.getPageNum() - 1) * query.getPageSize());
         args.add(query.getPageSize());

+ 13 - 0
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/index/IndexController.java

@@ -1,11 +1,14 @@
 package org.dbsyncer.web.controller.index;
 
 import org.dbsyncer.biz.ProjectGroupService;
+import org.dbsyncer.biz.UserService;
 import org.dbsyncer.biz.vo.ProjectGroupVo;
 import org.dbsyncer.biz.vo.RestResult;
 import org.dbsyncer.biz.vo.VersionVo;
 import org.dbsyncer.common.config.AppConfig;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -21,6 +24,9 @@ public class IndexController {
     @Autowired
     private ProjectGroupService projectGroupService;
 
+    @Autowired
+    private UserService userService;
+
     @Autowired
     private AppConfig appConfig;
 
@@ -41,4 +47,11 @@ public class IndexController {
         return RestResult.restSuccess(new VersionVo(appConfig.getName(), appConfig.getCopyright()));
     }
 
+    @GetMapping("/getUserInfo.json")
+    @ResponseBody
+    public RestResult getUserInfo() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        return RestResult.restSuccess(userService.getUserVo(authentication.getName()));
+    }
+
 }

+ 1 - 1
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/system/SystemController.java

@@ -47,7 +47,7 @@ public class SystemController extends BaseController {
 	@ResponseBody
 	public RestResult queryConfig(HttpServletRequest request) {
 		try {
-			return RestResult.restSuccess(configService.queryConfig());
+			return RestResult.restSuccess(configService.getConfig());
 		} catch (Exception e) {
 			logger.error(e.getLocalizedMessage(), e.getClass());
 			return RestResult.restFail(e.getMessage());