浏览代码

supersonic登录集成

zhouyy 3 月之前
父节点
当前提交
52c1c232b0

+ 24 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/config/SuperSonicConfig.java

@@ -0,0 +1,24 @@
+package com.management.platform.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Data
+@Configuration
+public class SuperSonicConfig {
+    @Value("${supersonic.use:false}")
+    private Boolean supersonicUse;
+
+    @Value("${supersonic.ip:localhost}")
+    private String supersonicIP;
+
+    @Value("${supersonic.port:9080}")
+    private String supersonicPort;
+
+    @Value("${supersonic.username:admin}")
+    private String supersonicUserName;
+
+    @Value("${supersonic.password:e6+jQ26AESREiBBuKM1u1A==}")
+    private String supersonicPassWord;
+}

+ 26 - 33
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.management.platform.config.SuperSonicConfig;
 import com.management.platform.constant.Constant;
 import com.management.platform.entity.*;
 import com.management.platform.entity.vo.SysRichFunction;
@@ -240,18 +241,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     @Resource
     private SysDictService sysDictService;
 
-
-    @Value("${supersonic.ip:localhost}")
-    private String supersonicIP;
-
-    @Value("${supersonic.port:9080}")
-    private String supersonicPort;
-
-    @Value("${supersonic.username:admin}")
-    private String supersonicUserName;
-
-    @Value("${supersonic.password:e6+jQ26AESREiBBuKM1u1A==}")
-    private String supersonicPassWord;
+    @Resource
+    private SuperSonicConfig  superSonicConfig;
 
 
     //登录网页端
@@ -320,27 +311,29 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                 //获取当前角色的权限菜单
                 setUserRoleMenu(userVO);
                 //获取supersonicToken
-                String superSonicToken = getSuperSonicToken();
-                if(org.apache.commons.lang3.StringUtils.isBlank(superSonicToken)){
-                    httpRespMsg.setError(MessageUtils.message("user.supersonicLogin"));
-                    return httpRespMsg;
-                }else{
-                    userVO.setSupersonicToken(superSonicToken);
-                    Integer count = sysConfigMapper.selectCount(new LambdaQueryWrapper<SysConfig>()
-                            .eq(SysConfig::getParamKey, "supersonicToken")
-                    );
-                    if(count > 0){
-                        sysConfigMapper.update(null,new LambdaUpdateWrapper<SysConfig>()
+                if(superSonicConfig.getSupersonicUse()){
+                    String superSonicToken = getSuperSonicToken();
+                    if(org.apache.commons.lang3.StringUtils.isBlank(superSonicToken)){
+                        httpRespMsg.setError(MessageUtils.message("user.supersonicLogin"));
+                        return httpRespMsg;
+                    }else{
+                        userVO.setSupersonicToken(superSonicToken);
+                        Integer count = sysConfigMapper.selectCount(new LambdaQueryWrapper<SysConfig>()
                                 .eq(SysConfig::getParamKey, "supersonicToken")
-                                .set(SysConfig::getParamValue, superSonicToken)
                         );
-                    }else{
-                        SysConfig sysConfig = new SysConfig();
-                        sysConfig.setParamKey("supersonicToken");
-                        sysConfig.setParamValue(superSonicToken);
-                        sysConfigMapper.insert(sysConfig);
-                    }
+                        if(count > 0){
+                            sysConfigMapper.update(null,new LambdaUpdateWrapper<SysConfig>()
+                                    .eq(SysConfig::getParamKey, "supersonicToken")
+                                    .set(SysConfig::getParamValue, superSonicToken)
+                            );
+                        }else{
+                            SysConfig sysConfig = new SysConfig();
+                            sysConfig.setParamKey("supersonicToken");
+                            sysConfig.setParamValue(superSonicToken);
+                            sysConfigMapper.insert(sysConfig);
+                        }
 
+                    }
                 }
                 httpRespMsg.data = userVO;
             }else {
@@ -352,12 +345,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
     public String getSuperSonicToken(){
         String token = "";
-        String apiUrl = "http://"+supersonicIP+":"+supersonicPort+"/api/auth/user/login";
+        String apiUrl = "http://"+superSonicConfig.getSupersonicIP()+":"+superSonicConfig.getSupersonicPort()+"/api/auth/user/login";
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_JSON);
         JSONObject params = new JSONObject();
-        params.put("name", supersonicUserName);
-        params.put("password", supersonicPassWord);
+        params.put("name", superSonicConfig.getSupersonicUserName());
+        params.put("password", superSonicConfig.getSupersonicPassWord());
         String requestBody = params.toJSONString();
         HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
         ResponseEntity<String> responseEntity = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);

+ 1 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/resources/application.yml

@@ -177,6 +177,7 @@ defaultcommonmodules:
   path: [/customer,/contacts,/tasks]
 
 supersonic:
+  use: true
   ip: localhost
   port: 9080
   username: admin