Compare commits
3 Commits
6ebdec199b
...
feat/auth_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b8d33b50d | ||
|
|
8866d152d7 | ||
|
|
cb9ddf4681 |
@@ -1,38 +1,26 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.api.TokenApi;
|
||||
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.RefreshRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RouterVo;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserDTO;
|
||||
import com.xiang.xservice.auth.service.service.XMenuService;
|
||||
import com.xiang.xservice.auth.service.service.XUserService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class TokenController implements TokenApi {
|
||||
public class TokenController {
|
||||
|
||||
private final XUserService userService;
|
||||
private final XMenuService menuService;
|
||||
|
||||
@PostMapping("/public/auth/login")
|
||||
public Result<LoginResp> login(@RequestBody @NotNull(message = "请求参数不能为空") @Valid LoginRequest request) {
|
||||
@@ -48,11 +36,6 @@ public class TokenController implements TokenApi {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/private/auth/getInfo")
|
||||
public Result<UserDTO> getUserInfo(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||
return Result.data(userService.getUserDetail(request.getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("/publish/auth/refresh")
|
||||
public Result<LoginResp> refresh(@RequestBody @NotNull(message = "请求参数不能为空") @Valid RefreshRequest request) {
|
||||
try {
|
||||
@@ -66,47 +49,4 @@ public class TokenController implements TokenApi {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/user/userRegister")
|
||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
||||
try {
|
||||
RegisterResp registerResp = userService.userRegister(request);
|
||||
if (Objects.nonNull(registerResp)) {
|
||||
return Result.data(registerResp);
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/private/user/getUserId")
|
||||
public Result<Long> getUserId(@RequestParam("token") String token) {
|
||||
try {
|
||||
return Result.data(userService.getUserId(token));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/private/user/getTenantId")
|
||||
public Result<Long> getTenantId(@RequestParam("token") String token) {
|
||||
try {
|
||||
return Result.data(userService.getTenantId(token));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/private/menu/getRouter")
|
||||
public Result<List<RouterVo>> getRouter(@RequestParam("userId") Long userId) {
|
||||
return Result.data(menuService.getRouter(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserResetPwdRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateStatusRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
||||
import com.xiang.xservice.auth.service.service.XUserService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final XUserService userService;
|
||||
|
||||
@PostMapping("/private/user/list")
|
||||
public Result<Page<UserResp>> getUserList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||
return Result.data(userService.getUserList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/private/user/info/{id}")
|
||||
public Result<UserResp> getUserById(@PathVariable("id") Long id) {
|
||||
return Result.data(userService.getUserInfo(id));
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/add")
|
||||
public Result<Boolean> addUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserAddRequest request) {
|
||||
try {
|
||||
return Result.data(userService.addUser(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户新增异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
@PostMapping("/private/user/updateStatus")
|
||||
public Result<Boolean> updateStatus(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateStatusRequest request) {
|
||||
return Result.data(userService.updateStatus(request.getId(), request.getStatus()));
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/update")
|
||||
public Result<Boolean> updateUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateRequest request) {
|
||||
try {
|
||||
return Result.data(userService.updateUser(request));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户编辑异常,请求:{}", JSON.toJSONString(request), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/del")
|
||||
public Result<Boolean> delUser(@RequestBody @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
try {
|
||||
return Result.data(userService.delUser(ids));
|
||||
} catch (BusinessException e) {
|
||||
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("用户删除异常,请求:{}", JSON.toJSONString(ids), e);
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/resetUserPwd")
|
||||
public Result<Boolean> resetPwd(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserResetPwdRequest request) {
|
||||
return Result.data(userService.resetPwd(request.getUserId(), request.getPassword()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,14 +11,26 @@ spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
headless: true
|
||||
cloud:
|
||||
loadbalancer:
|
||||
retry:
|
||||
enabled: false
|
||||
cache:
|
||||
enabled: true
|
||||
cache:
|
||||
type: caffeine
|
||||
caffeine:
|
||||
spec: initialCapacity=100,maximumSize=1000,expireAfterWrite=30s
|
||||
|
||||
mybatis:
|
||||
mapper-locations:
|
||||
- classpath*:mapper/*/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
reasonable: true
|
||||
support-methods-arguments: true
|
||||
params: count=countSql
|
||||
|
||||
feign:
|
||||
client:
|
||||
config:
|
||||
default:
|
||||
connectTimeout: 1000
|
||||
readTimeout: 3000
|
||||
@@ -1,102 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
|
||||
<!-- 应用名称:和统一配置中的项目代码保持一致(小写) -->
|
||||
<property name="APP_NAME" value="xservice-auth-center"/>
|
||||
<contextName>${APP_NAME}</contextName>
|
||||
|
||||
<!--日志文件保留天数 -->
|
||||
<property name="LOG_MAX_HISTORY" value="30"/>
|
||||
<!--应用日志文件保存路径 -->
|
||||
<!--在没有定义${LOG_HOME}系统变量的时候,可以设置此本地变量。提交测试、上线时,要将其注释掉,使用系统变量。 -->
|
||||
<property name="LOG_HOME" value="logs/${APP_NAME}"/>
|
||||
<!--<property name="LOG_HOME" msg="/home/logs/${APP_NAME}" />-->
|
||||
|
||||
<!--控制台输出appender-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!--设置输出格式-->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%boldGreen(%contextName): %boldCyan(%d{yyyy-MM-dd HH:mm:ss:SSS}) %highlight([%c]) %boldMagenta([%t]) %boldCyan([%L]) %highlight([traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}]) %boldGreen([%p]) - %msg%n
|
||||
</pattern>
|
||||
<!--设置编码-->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/debug-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件只记录debug级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/info-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件只记录info级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 按照每天生成日志文件:主项目日志 -->
|
||||
<appender name="APP_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名 -->
|
||||
<FileNamePattern>${LOG_HOME}/error-%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数 -->
|
||||
<MaxHistory>${LOG_MAX_HISTORY}</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件只记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>error</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!--日志输出到文件-->
|
||||
<root level="info">
|
||||
<appender-ref ref="APP_DEBUG"/>
|
||||
<appender-ref ref="APP_INFO"/>
|
||||
<appender-ref ref="APP_ERROR"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!-- mybatis 日志级别 -->
|
||||
<logger name="com.xiang" level="debug"/>
|
||||
|
||||
</configuration>
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.xiang.xservice.auth.service.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -20,6 +22,7 @@ public class XMenuDO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 菜单ID */
|
||||
@TableId
|
||||
private Long menuId;
|
||||
|
||||
/** 菜单名称 */
|
||||
|
||||
@@ -21,13 +21,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
||||
*/
|
||||
XUser selectByUsername(String username);
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
int insertBatch(List<XUser> list);
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param user
|
||||
@@ -42,12 +35,6 @@ public interface XUserMapper extends BaseMapper<XUser> {
|
||||
*/
|
||||
XUser getUserById(Long id);
|
||||
|
||||
/**
|
||||
* 编辑用户
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
int update(XUser user);
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
|
||||
@@ -165,7 +165,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
// 4. db 存储token
|
||||
user.setToken(token);
|
||||
user.setRefreshToken(refreshToken);
|
||||
userMapper.update(user);
|
||||
userMapper.updateById(user);
|
||||
return loginResp;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
user.setCreateTime(request.getDateTime());
|
||||
user.setUpdateBy(request.getOperator());
|
||||
user.setUpdateTime(request.getDateTime());
|
||||
return userMapper.update(user) > 0;
|
||||
return userMapper.updateById(user) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -343,7 +343,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
// 更新 Redis 和 DB
|
||||
redisService.set(RedisConstant.LOGIN_TOKEN + request.getUsername(), newToken, 3, TimeUnit.HOURS);
|
||||
user.setToken(newToken);
|
||||
userMapper.update(user);
|
||||
userMapper.updateById(user);
|
||||
LoginResp loginResp = new LoginResp();
|
||||
loginResp.setToken(newToken);
|
||||
loginResp.setUsername(request.getUsername());
|
||||
@@ -358,7 +358,7 @@ public class XUserServiceImpl implements XUserService {
|
||||
throw new BusinessException(Code01UserErrorCode.USER_NOT_EXISTS);
|
||||
}
|
||||
user.setStatus(status);
|
||||
return userMapper.update(user) > 0;
|
||||
return userMapper.updateById(user) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -391,6 +391,6 @@ public class XUserServiceImpl implements XUserService {
|
||||
}
|
||||
String encodePwd = passwordEncoder.encode(password);
|
||||
user.setPassword(encodePwd);
|
||||
return userMapper.update(user) > 0;
|
||||
return userMapper.updateById(user) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,40 +44,11 @@
|
||||
token,
|
||||
refresh_token
|
||||
</sql>
|
||||
<insert id="insertBatch">
|
||||
insert into x_user(name, username, password, email, phone, status, tenant_id) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.name}, #{item.username}, #{item.password}, #{item.email}, #{item.phone}, #{item.status}, #{item.tenantId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="delete" >
|
||||
<update id="del" >
|
||||
update x_user set del_flag = 1 where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XUser">
|
||||
UPDATE x_user
|
||||
<set>
|
||||
<if test="null != name and '' != name">name = #{name},</if>
|
||||
<if test="null != username and '' != username">username = #{username},</if>
|
||||
<if test="null != password and '' != password">password = #{password},</if>
|
||||
<if test="null != email and '' != email">email = #{email},</if>
|
||||
<if test="null != phone and '' != phone">phone = #{phone},</if>
|
||||
<if test="null != avatar and '' != avatar">avatar = #{avatar},</if>
|
||||
<if test="null != loginIp and '' != loginIp">login_ip = #{loginIp},</if>
|
||||
<if test="null != loginDate ">login_date = #{loginDate},</if>
|
||||
<if test="null != delFlag ">del_flag = #{delFlag},</if>
|
||||
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
||||
<if test="null != createTime ">create_time = #{createTime},</if>
|
||||
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
||||
<if test="null != updateTime ">update_time = #{updateTime},</if>
|
||||
<if test="null != tenantId ">tenant_id = #{tenantId},</if>
|
||||
<if test="null != token and '' != token ">token = #{token},</if>
|
||||
<if test="null != refreshToken and '' != refreshToken ">refresh_token = #{refreshToken},</if>
|
||||
<if test="status != null">status = #{status}</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
<update id="deleteBatch">
|
||||
update x_user set del_flag = 1, update_time = #{time}, update_by = #{operator} where id in
|
||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||
|
||||
Reference in New Issue
Block a user