feat: 接口设计: user&user.tag
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package com.rainbus.dlp.controller;
|
package com.rainbus.dlp.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.rainbus.dlp.entity.pojo.user.SysResource;
|
||||||
import com.rainbus.dlp.entity.req.user.*;
|
import com.rainbus.dlp.entity.req.user.*;
|
||||||
import com.rainbus.dlp.entity.resp.Resp;
|
import com.rainbus.dlp.entity.resp.Resp;
|
||||||
import com.rainbus.dlp.entity.resp.user.GetTagResp;
|
import com.rainbus.dlp.entity.resp.user.GetTagResp;
|
||||||
import com.rainbus.dlp.entity.resp.user.GetUserResp;
|
import com.rainbus.dlp.entity.resp.user.GetUserResp;
|
||||||
import com.rainbus.dlp.entity.resp.user.LoginResp;
|
import com.rainbus.dlp.entity.resp.user.LoginResp;
|
||||||
|
import com.rainbus.dlp.repository.mapper.user.SysResourceMapper;
|
||||||
|
import com.rainbus.dlp.repository.mapper.user.SysRoleMapper;
|
||||||
import com.rainbus.dlp.service.UserServ;
|
import com.rainbus.dlp.service.UserServ;
|
||||||
import com.rainbus.dlp.util.RedisUtil;
|
import com.rainbus.dlp.util.RedisUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -21,6 +24,8 @@ public class UserCtrl {
|
|||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
private final UserServ userServ;
|
private final UserServ userServ;
|
||||||
|
private final SysRoleMapper sysRoleMapper;
|
||||||
|
private final SysResourceMapper sysResourceMapper;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@Operation(summary = "登录接口")
|
@Operation(summary = "登录接口")
|
||||||
@@ -82,4 +87,14 @@ public class UserCtrl {
|
|||||||
return Resp.success(null);
|
return Resp.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/test")
|
||||||
|
private Resp<Object> test() {
|
||||||
|
SysResource resource = new SysResource();
|
||||||
|
resource.setResource("/user/test");
|
||||||
|
resource.setRequestMethod(RequestMethod.GET);
|
||||||
|
List<SysResource> resources = List.of(resource);
|
||||||
|
return Resp.success(sysResourceMapper.batchInsert(resources));
|
||||||
|
// return Resp.success(sysRoleMapper.selectRoleIdsByUserId(List.of(1L, 2L)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/main/java/com/rainbus/dlp/entity/dto/Pair.java
Normal file
4
src/main/java/com/rainbus/dlp/entity/dto/Pair.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package com.rainbus.dlp.entity.dto;
|
||||||
|
|
||||||
|
public record Pair<T1, T2>(T1 v1, T2 v2) {
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.rainbus.dlp.entity.dto;
|
package com.rainbus.dlp.entity.dto;
|
||||||
|
|
||||||
public record Tuple<T1, T2, T3>(T1 t1, T2 t2, T3 t3) {
|
public record Tuple<T1, T2, T3>(T1 v1, T2 v2, T3 v3) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public class SysResource {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt = LocalDateTime.now();
|
||||||
|
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt = LocalDateTime.now();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.rainbus.dlp.repository.dao;
|
package com.rainbus.dlp.repository.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.rainbus.dlp.entity.pojo.user.SysOrg;
|
import com.rainbus.dlp.entity.pojo.user.SysOrg;
|
||||||
import com.rainbus.dlp.entity.pojo.user.SysRole;
|
import com.rainbus.dlp.entity.pojo.user.SysRole;
|
||||||
import com.rainbus.dlp.entity.pojo.user.SysUser;
|
import com.rainbus.dlp.entity.pojo.user.SysUser;
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ public interface SysResourceMapper extends BaseMapper<SysResource> {
|
|||||||
List<SysResource> selectListByRoleId(Long roleId);
|
List<SysResource> selectListByRoleId(Long roleId);
|
||||||
|
|
||||||
@Insert("""
|
@Insert("""
|
||||||
|
<script>
|
||||||
insert into sys_resource (request_method, resource, created_at, description, updated_at) values
|
insert into sys_resource (request_method, resource, created_at, description, updated_at) values
|
||||||
<foreach collection="resources" item="item" index="index" separator=",">
|
<foreach collection="resources" item="item" index="index" separator=",">
|
||||||
(#{item.requestMethod}, #{item.resource}, #{item.createdAt}, #{item.description}, #{item.updatedAt})
|
(#{item.requestMethod}, #{item.resource}, #{item.createdAt}, #{item.description}, #{item.updatedAt})
|
||||||
</foreach>
|
</foreach>
|
||||||
|
</script>
|
||||||
""")
|
""")
|
||||||
Long batchInsert(List<SysResource> resources);
|
Long batchInsert(List<SysResource> resources);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.rainbus.dlp.repository.mapper.user;
|
package com.rainbus.dlp.repository.mapper.user;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.rainbus.dlp.entity.dto.Pair;
|
||||||
import com.rainbus.dlp.entity.pojo.user.SysRole;
|
import com.rainbus.dlp.entity.pojo.user.SysRole;
|
||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
@@ -32,4 +33,14 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
|
|||||||
List<SysRole> selectAllRoleResource();
|
List<SysRole> selectAllRoleResource();
|
||||||
|
|
||||||
|
|
||||||
|
@Select("""
|
||||||
|
select * from sys_user_roles where sys_user_id in #{userId}
|
||||||
|
""")
|
||||||
|
@Results({
|
||||||
|
@Result(property = "v1", column = "sys_user_id"),
|
||||||
|
@Result(property = "v2", column = "roles_id")
|
||||||
|
})
|
||||||
|
List<Pair<Long, Long>> selectRoleIdsByUserId(List<Long> userId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,4 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
})
|
})
|
||||||
SysUser selectUserRoleOrgByUsername(@Param("username") String username);
|
SysUser selectUserRoleOrgByUsername(@Param("username") String username);
|
||||||
|
|
||||||
@Select("""
|
|
||||||
select roles_id from sys_user_roles where sys_user_id = #{userId}
|
|
||||||
""")
|
|
||||||
List<Long> selectRoleIdsByUserId(Long userId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,22 @@ public class SqlUtil {
|
|||||||
|
|
||||||
record TableInfo(String tableName, List<String> columName) {}
|
record TableInfo(String tableName, List<String> columName) {}
|
||||||
|
|
||||||
// public static <T> String generateBatchInsertSql(String fieldName, Class<T> tClass) {
|
public static <T> String generateBatchInsertSql(String fieldName, Class<T> tClass) {
|
||||||
// TableInfo tableInfo = getTableInfo(tClass);
|
TableInfo tableInfo = getTableInfo(tClass);
|
||||||
// return STR."""
|
return STR."""
|
||||||
// INSERT INTO \{tableInfo.tableName} (\{String.join(", ", tableInfo.columName)})
|
INSERT INTO \{tableInfo.tableName} (\{String.join(", ", tableInfo.columName)})
|
||||||
// VALUES
|
VALUES
|
||||||
// <foreach collection="\{fieldName}" item="item" index="index" separator=",">
|
<foreach collection="\{fieldName}" item="item" index="index" separator=",">
|
||||||
// (\{String.join(", ", tableInfo.columName.stream().map(colum -> STR."#{item.\{colum}}").toList())})
|
(\{String.join(", ", tableInfo.columName.stream().map(colum -> STR."#{item.\{colum}}").toList())})
|
||||||
// </foreach>
|
</foreach>
|
||||||
// """;
|
""";
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private static <T> TableInfo getTableInfo(Class<T> tClass) {
|
private static <T> TableInfo getTableInfo(Class<T> tClass) {
|
||||||
// String tableName = TextUtil.camelToSnake(tClass.getSimpleName());
|
String tableName = TextUtil.camelToSnake(tClass.getSimpleName());
|
||||||
// List<String> columName = Arrays.stream(tClass.getDeclaredFields())
|
List<String> columName = Arrays.stream(tClass.getDeclaredFields())
|
||||||
// .map(field -> TextUtil.camelToSnake(field.getName()))
|
.map(field -> TextUtil.camelToSnake(field.getName()))
|
||||||
// .toList();
|
.toList();
|
||||||
// return new TableInfo(tableName, columName);
|
return new TableInfo(tableName, columName);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/main/resources/mapper/SysResourceMapper.xml
Normal file
9
src/main/resources/mapper/SysResourceMapper.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?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.rainbus.dlp.repository.mapper.user.SysResourceMapper">
|
||||||
|
<!-- <insert id="batchInsert">-->
|
||||||
|
<!-- ${@com.rainbus.dlp.util.SqlUtil@generateBatchInsertSql("resources", @com.rainbus.dlp.entity.pojo.user.SysResource@class)}-->
|
||||||
|
<!-- </insert>-->
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user