Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
2d2aff92
提交
2d2aff92
authored
1月 05, 2024
作者:
obcy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加mybatisplus分页插件,添加授权用户操作
上级
35f50558
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
249 行增加
和
15 行删除
+249
-15
MybatisPlusConfig.java
...main/java/com/zzsn/knowbase/config/MybatisPlusConfig.java
+22
-0
KbAuthorizedUserController.java
.../zzsn/knowbase/controller/KbAuthorizedUserController.java
+49
-3
KbPermissionsController.java
...com/zzsn/knowbase/controller/KbPermissionsController.java
+12
-0
KbRoleController.java
...n/java/com/zzsn/knowbase/controller/KbRoleController.java
+15
-3
KbRolePermissionMapController.java
...sn/knowbase/controller/KbRolePermissionMapController.java
+12
-1
KbUserRoleMapController.java
...com/zzsn/knowbase/controller/KbUserRoleMapController.java
+12
-1
KbAuthorizedUser.java
src/main/java/com/zzsn/knowbase/entity/KbAuthorizedUser.java
+23
-6
KbKnowledgeProject.java
...ain/java/com/zzsn/knowbase/entity/KbKnowledgeProject.java
+1
-1
KbAuthorizedUserMapper.java
...java/com/zzsn/knowbase/mapper/KbAuthorizedUserMapper.java
+13
-0
KbAuthorizedUserService.java
...va/com/zzsn/knowbase/service/KbAuthorizedUserService.java
+6
-0
KbAuthorizedUserServiceImpl.java
...sn/knowbase/service/impl/KbAuthorizedUserServiceImpl.java
+81
-0
KbKnowledgeProjectServiceImpl.java
.../knowbase/service/impl/KbKnowledgeProjectServiceImpl.java
+3
-0
没有找到文件。
src/main/java/com/zzsn/knowbase/config/MybatisPlusConfig.java
0 → 100644
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
config
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* Description:
* Author: obcy
* Date: 2024/1/4
*/
@Configuration
public
class
MybatisPlusConfig
{
/**
* mybatis-plus分页插件
* */
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
PaginationInterceptor
paginationInterceptor
=
new
PaginationInterceptor
().
setLimit
(-
1
);
return
paginationInterceptor
;
}
}
src/main/java/com/zzsn/knowbase/controller/KbAuthorizedUserController.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
com.zzsn.knowbase.service.KbAuthorizedUserService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* <p>
...
...
@@ -16,5 +18,49 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
(
"/api/knowledgeUser"
)
public
class
KbAuthorizedUserController
{
@Autowired
KbAuthorizedUserService
authorizedUserService
;
/**
* 根据id查询
* */
@GetMapping
public
Result
<?>
getById
(
@RequestParam
(
name
=
"id"
,
required
=
true
)
String
id
){
return
Result
.
OK
(
authorizedUserService
.
getById
(
id
));
}
@PostMapping
(
"/add"
)
public
Result
<?>
add
(
@RequestBody
KbAuthorizedUser
authorizedUser
){
return
authorizedUserService
.
add
(
authorizedUser
);
}
/**
* 编辑知识库
* */
@PostMapping
(
"/edit"
)
public
Result
<?>
edit
(
@RequestBody
KbAuthorizedUser
authorizedUser
){
return
authorizedUserService
.
edit
(
authorizedUser
);
}
/**
* 删除知识库
* */
@GetMapping
(
"/del"
)
public
Result
<?>
del
(
@RequestParam
(
name
=
"id"
,
required
=
true
)
String
id
){
return
Result
.
OK
(
authorizedUserService
.
removeById
(
id
));
}
@GetMapping
(
"/list"
)
public
Result
<?>
list
(
@RequestParam
(
name
=
"roleId"
,
required
=
false
)
String
roleId
,
@RequestParam
(
name
=
"username"
,
required
=
false
)
String
username
,
@RequestParam
(
name
=
"name"
,
required
=
false
)
String
name
,
@RequestParam
(
name
=
"orgId"
,
required
=
false
)
String
orgId
,
@RequestParam
(
name
=
"orgName"
,
required
=
false
)
String
orgName
,
@RequestParam
(
name
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
,
@RequestParam
(
name
=
"PageSize"
,
defaultValue
=
"10"
)
Integer
PageSize
){
return
authorizedUserService
.
lists
(
roleId
,
username
,
name
,
orgId
,
orgName
,
pageNum
,
PageSize
);
}
}
src/main/java/com/zzsn/knowbase/controller/KbPermissionsController.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
controller
;
import
com.zzsn.knowbase.entity.KbPermissions
;
import
com.zzsn.knowbase.service.KbPermissionsService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -16,5 +22,11 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
(
"/api/permissions"
)
public
class
KbPermissionsController
{
@Autowired
KbPermissionsService
permissionsService
;
@PostMapping
(
"/add"
)
public
Result
add
(
@RequestBody
KbPermissions
permission
){
return
Result
.
OK
(
permissionsService
.
save
(
permission
));
}
}
src/main/java/com/zzsn/knowbase/controller/KbRoleController.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.zzsn.knowbase.entity.KbRole
;
import
com.zzsn.knowbase.service.KbRoleService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* <p>
...
...
@@ -16,5 +18,15 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
(
"/api/role"
)
public
class
KbRoleController
{
@Autowired
KbRoleService
roleService
;
@PostMapping
(
"/add"
)
public
Result
add
(
@RequestBody
KbRole
role
){
return
Result
.
OK
(
roleService
.
save
(
role
));
}
@GetMapping
(
"/list"
)
public
Result
list
(){
return
Result
.
OK
(
roleService
.
list
());
}
}
src/main/java/com/zzsn/knowbase/controller/KbRolePermissionMapController.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
controller
;
import
com.zzsn.knowbase.entity.KbRolePermissionMap
;
import
com.zzsn.knowbase.service.KbRolePermissionMapService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
...
...
@@ -16,5 +21,11 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
(
"/api/rolePermission"
)
public
class
KbRolePermissionMapController
{
@Autowired
KbRolePermissionMapService
rolePermissionMapService
;
@PostMapping
(
"/add"
)
public
Result
add
(
@RequestBody
KbRolePermissionMap
map
){
return
Result
.
OK
(
rolePermissionMapService
.
save
(
map
));
}
}
src/main/java/com/zzsn/knowbase/controller/KbUserRoleMapController.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
controller
;
import
com.zzsn.knowbase.entity.KbUserRoleMap
;
import
com.zzsn.knowbase.service.KbUserRoleMapService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
...
...
@@ -16,5 +21,11 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
(
"/api/userRole"
)
public
class
KbUserRoleMapController
{
@Autowired
KbUserRoleMapService
userRoleMapService
;
@PostMapping
(
"/add"
)
public
Result
add
(
@RequestBody
KbUserRoleMap
map
){
return
Result
.
OK
(
userRoleMapService
.
save
(
map
));
}
}
src/main/java/com/zzsn/knowbase/entity/KbAuthorizedUser.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
java.util.Date
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
java.io.Serializable
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.Date
;
/**
* <p>
*
...
...
@@ -45,9 +45,19 @@ public class KbAuthorizedUser extends Model<KbAuthorizedUser> {
*/
@TableField
(
"name"
)
private
String
name
;
/**
* 用户名称
*/
@TableField
(
"org_id"
)
private
String
orgId
;
/**
* 用户名称
*/
@TableField
(
"org_name"
)
private
String
orgName
;
/**
* 状态
* 状态
0启用,1禁用
*/
@TableField
(
"status"
)
private
String
status
;
...
...
@@ -84,4 +94,11 @@ public class KbAuthorizedUser extends Model<KbAuthorizedUser> {
/**
* 角色id
*/
@TableField
(
exist
=
false
)
private
String
roleId
;
}
src/main/java/com/zzsn/knowbase/entity/KbKnowledgeProject.java
浏览文件 @
2d2aff92
...
...
@@ -53,7 +53,7 @@ public class KbKnowledgeProject extends Model<KbKnowledgeProject> {
private
Integer
category
;
/**
* 状态
* 状态
0启用,1禁用
*/
@TableField
(
"status"
)
private
Integer
status
;
...
...
src/main/java/com/zzsn/knowbase/mapper/KbAuthorizedUserMapper.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
mapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
/**
* <p>
...
...
@@ -15,4 +21,11 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public
interface
KbAuthorizedUserMapper
extends
BaseMapper
<
KbAuthorizedUser
>
{
@Select
(
"SELECT a.*,GROUP_CONCAT(b.role_id SEPARATOR ',') as roleId FROM kb_authorized_user a "
+
"LEFT JOIN kb_user_role_map b ON a.id = b.user_id "
+
"${sql}"
+
"${ew.customSqlSegment}"
+
"GROUP BY a.id"
)
IPage
<
KbAuthorizedUser
>
page
(
Page
<
KbAuthorizedUser
>
page
,
@Param
(
Constants
.
WRAPPER
)
QueryWrapper
<
KbAuthorizedUser
>
query
,
String
sql
);
}
src/main/java/com/zzsn/knowbase/service/KbAuthorizedUserService.java
浏览文件 @
2d2aff92
...
...
@@ -2,6 +2,7 @@ package com.zzsn.knowbase.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
com.zzsn.knowbase.vo.Result
;
/**
* <p>
...
...
@@ -13,4 +14,9 @@ import com.zzsn.knowbase.entity.KbAuthorizedUser;
*/
public
interface
KbAuthorizedUserService
extends
IService
<
KbAuthorizedUser
>
{
Result
<?>
add
(
KbAuthorizedUser
authorizedUser
);
Result
<?>
edit
(
KbAuthorizedUser
authorizedUser
);
Result
<?>
lists
(
String
roleId
,
String
username
,
String
name
,
String
orgId
,
String
orgName
,
Integer
pageNum
,
Integer
pageSize
);
}
src/main/java/com/zzsn/knowbase/service/impl/KbAuthorizedUserServiceImpl.java
浏览文件 @
2d2aff92
package
com
.
zzsn
.
knowbase
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
com.zzsn.knowbase.entity.KbUserRoleMap
;
import
com.zzsn.knowbase.mapper.KbAuthorizedUserMapper
;
import
com.zzsn.knowbase.service.KbAuthorizedUserService
;
import
com.zzsn.knowbase.service.KbUserRoleMapService
;
import
com.zzsn.knowbase.vo.Result
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* <p>
...
...
@@ -18,4 +32,71 @@ import org.springframework.stereotype.Service;
@Service
public
class
KbAuthorizedUserServiceImpl
extends
ServiceImpl
<
KbAuthorizedUserMapper
,
KbAuthorizedUser
>
implements
KbAuthorizedUserService
{
@Autowired
KbUserRoleMapService
kbUserRoleMapService
;
@Autowired
KbAuthorizedUserMapper
authorizedUserMapper
;
@Override
@Transactional
public
Result
<?>
add
(
KbAuthorizedUser
authorizedUser
)
{
/**保存授权用户*/
authorizedUser
.
setStatus
(
"0"
);
super
.
save
(
authorizedUser
);
/**插入用户角色关系表*/
if
(
StringUtils
.
isNotBlank
(
authorizedUser
.
getRoleId
())){
String
roleId
=
authorizedUser
.
getRoleId
();
List
<
String
>
list
=
Arrays
.
asList
(
roleId
.
split
(
","
));
List
<
KbUserRoleMap
>
maps
=
new
ArrayList
<>();
list
.
forEach
(
e
->{
KbUserRoleMap
kbUserRoleMap
=
new
KbUserRoleMap
();
kbUserRoleMap
.
setUserId
(
authorizedUser
.
getId
());
kbUserRoleMap
.
setRoleId
(
Long
.
parseLong
(
e
));
maps
.
add
(
kbUserRoleMap
);
});
kbUserRoleMapService
.
saveBatch
(
maps
);
}
return
Result
.
OK
();
}
@Override
@Transactional
public
Result
<?>
edit
(
KbAuthorizedUser
authorizedUser
)
{
String
newRole
=
authorizedUser
.
getRoleId
();
super
.
updateById
(
authorizedUser
);
/**修改用户角色关系表*/
if
(
StringUtils
.
isNotBlank
(
newRole
)){
kbUserRoleMapService
.
remove
(
Wrappers
.<
KbUserRoleMap
>
lambdaQuery
().
eq
(
KbUserRoleMap:
:
getUserId
,
authorizedUser
.
getId
()));
List
<
String
>
list
=
Arrays
.
asList
(
newRole
.
split
(
","
));
List
<
KbUserRoleMap
>
maps
=
new
ArrayList
<>();
list
.
forEach
(
e
->{
KbUserRoleMap
kbUserRoleMap
=
new
KbUserRoleMap
();
kbUserRoleMap
.
setUserId
(
authorizedUser
.
getId
());
kbUserRoleMap
.
setRoleId
(
Long
.
parseLong
(
e
));
maps
.
add
(
kbUserRoleMap
);
});
kbUserRoleMapService
.
saveBatch
(
maps
);
}
return
Result
.
OK
();
}
@Override
public
Result
<?>
lists
(
String
roleId
,
String
username
,
String
name
,
String
orgId
,
String
orgName
,
Integer
pageNum
,
Integer
pageSize
)
{
QueryWrapper
<
KbAuthorizedUser
>
query
=
new
QueryWrapper
<>();
Page
<
KbAuthorizedUser
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
query
.
eq
(
StringUtils
.
isNotBlank
(
username
),
"a.username"
,
username
);
query
.
like
(
StringUtils
.
isNotBlank
(
name
),
"a.name"
,
name
);
query
.
eq
(
StringUtils
.
isNotBlank
(
orgId
),
"a.org_id"
,
orgId
);
query
.
like
(
StringUtils
.
isNotBlank
(
orgName
),
"a.org_name"
,
orgName
);
query
.
eq
(
StringUtils
.
isNotBlank
(
roleId
),
"b.role_id"
,
roleId
);
//根据一些条件动态的关联表
String
sql
=
""
;
IPage
<
KbAuthorizedUser
>
res
=
authorizedUserMapper
.
page
(
page
,
query
,
sql
);
return
Result
.
OK
(
res
);
}
}
src/main/java/com/zzsn/knowbase/service/impl/KbKnowledgeProjectServiceImpl.java
浏览文件 @
2d2aff92
...
...
@@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.List
;
/**
...
...
@@ -42,6 +43,7 @@ public class KbKnowledgeProjectServiceImpl extends ServiceImpl<KbKnowledgeProjec
knowledgeProject
.
setHasChild
(
KbKnowledgeProjectService
.
NOCHILD
);
/**第一次保存赋默认值*/
knowledgeProject
.
setFullPath
(
"0"
);
knowledgeProject
.
setCreateTime
(
new
Date
());
super
.
save
(
knowledgeProject
);
if
(
KbKnowledgeProjectService
.
ROOT_PID_VALUE
.
equals
(
knowledgeProject
.
getPid
())){
knowledgeProject
.
setFullPath
(
knowledgeProject
.
getId
().
toString
());
...
...
@@ -74,6 +76,7 @@ public class KbKnowledgeProjectServiceImpl extends ServiceImpl<KbKnowledgeProjec
if
(!
KbKnowledgeProjectService
.
ROOT_PID_VALUE
.
equals
(
knowledgeProject
.
getPid
()))
{
super
.
update
(
Wrappers
.<
KbKnowledgeProject
>
lambdaUpdate
().
set
(
KbKnowledgeProject:
:
getHasChild
,
KbKnowledgeProjectService
.
HASCHILD
).
eq
(
KbKnowledgeProject:
:
getId
,
newPid
));
}
knowledgeProject
.
setUpdateTime
(
new
Date
());
super
.
updateById
(
knowledgeProject
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论