saas 优化

dev.breakdown
刘武 2024-09-25 22:44:44 +08:00
parent 0930eabf51
commit 981706944a
13 changed files with 172 additions and 22 deletions

View File

@ -57,6 +57,10 @@
<groupId>com.muyu</groupId> <groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId> <artifactId>cloud-common-api-doc</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@ -1,7 +1,9 @@
package com.muyu.auth.controller; package com.muyu.auth.controller;
import com.muyu.auth.form.Firm;
import com.muyu.auth.form.LoginBody; import com.muyu.auth.form.LoginBody;
import com.muyu.auth.form.RegisterBody; import com.muyu.auth.form.RegisterBody;
import com.muyu.auth.service.SysFirmService;
import com.muyu.auth.service.SysLoginService; import com.muyu.auth.service.SysLoginService;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.JwtUtils; import com.muyu.common.core.utils.JwtUtils;
@ -30,9 +32,19 @@ public class TokenController {
@Autowired @Autowired
private SysLoginService sysLoginService; private SysLoginService sysLoginService;
@Autowired
private SysFirmService sysFirmService;
@PostMapping("login") @PostMapping("login")
public Result<?> login (@RequestBody LoginBody form) { public Result<?> login (@RequestBody LoginBody form) {
//查询用户公司是否存在
Firm firm = sysFirmService.findFirmByName(form.getFirmName());
//不能存在提示
if (firm==null){
return Result.error(null,"公司不存在");
}
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
// 获取登录token // 获取登录token

View File

@ -0,0 +1,20 @@
package com.muyu.auth.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Firm {
private Integer id;
private String firmName;
private String databaseName;
}

View File

@ -1,11 +1,22 @@
package com.muyu.auth.form; package com.muyu.auth.form;
import lombok.Data;
/** /**
* *
* *
* @author muyu * @author muyu
*/ */
@Data
public class LoginBody { public class LoginBody {
/**
*
*/
private String firmName;
/** /**
* *
*/ */
@ -17,19 +28,5 @@ public class LoginBody {
private String password; private String password;
public String getUsername () {
return username;
}
public void setUsername (String username) {
this.username = username;
}
public String getPassword () {
return password;
}
public void setPassword (String password) {
this.password = password;
}
} }

View File

@ -0,0 +1,56 @@
package com.muyu.auth.service;
import com.muyu.auth.form.Firm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
@Component
public class SysFirmService {
static final String USER="root";
static final String PASSWORD="Lw030106";
@Autowired
private RedisTemplate redisTemplate;
public Firm findFirmByName(String firmName){
Firm firm = new Firm();
try {
// Class.forName("com.mysql.cj.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
String sql="select * from `datasource` where firm_name = '"+firmName+"'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
firm.setId(rs.getInt("id"));
firm.setFirmName(rs.getString("firm_name"));
firm.setDatabaseName(rs.getString("database_name"));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//数据源不为空
if (firm!=null){
redisTemplate.opsForValue().set("datasource",firm.getDatabaseName());
}
return firm;
};
}

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# Spring # Spring
spring: spring:
application: application:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# Spring # Spring
spring: spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring # Spring
spring: spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# Spring # Spring
spring: spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring # Spring
spring: spring:

View File

@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -99,7 +100,67 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public SysUser selectUserByUserName (String userName) { public SysUser selectUserByUserName (String userName) {
return userMapper.selectUserByUserName(userName); String user="root";
String password="Lw030106";
SysUser sysUser=new SysUser();
try {
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection connection = DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false", user, password);
String sql="select u.user_id,\n" +
" u.dept_id,\n" +
" u.user_name,\n" +
" u.nick_name,\n" +
" u.email,\n" +
" u.avatar,\n" +
" u.phonenumber,\n" +
" u.password,\n" +
" u.sex,\n" +
" u.status,\n" +
" u.database_name,\n" +
" u.del_flag,\n" +
" u.login_ip,\n" +
" u.login_date,\n" +
" u.create_by,\n" +
" u.create_time,\n" +
" u.remark,\n" +
" d.dept_id,\n" +
" d.parent_id,\n" +
" d.ancestors,\n" +
" d.dept_name,\n" +
" d.order_num,\n" +
" d.leader,\n" +
" d.status as dept_status,\n" +
" r.role_id,\n" +
" r.role_name,\n" +
" r.role_key,\n" +
" r.role_sort,\n" +
" r.data_scope,\n" +
" r.status as role_status\n" +
" from sys_user u\n" +
" left join sys_dept d on u.dept_id = d.dept_id\n" +
" left join sys_user_role ur on u.user_id = ur.user_id\n" +
" left join sys_role r on r.role_id = ur.role_id" +
"where u.del_flag = '0' and u.user_name = '"+userName+"'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
sysUser.setUserId(rs.getLong("user_id"));
sysUser.setDeptId(rs.getLong("dept_id"));
sysUser.setUserName(rs.getString("user_name"));
sysUser.setNickName(rs.getString("nick_name"));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return sysUser;
// return userMapper.selectUserByUserName(userName);
} }
/** /**

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring # Spring
spring: spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848 addr: 47.101.53.251:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: yzl namespace: four
# Spring # Spring
spring: spring: