Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cneeds-server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangzr
cneeds-server
Commits
f5273af5
Commit
f5273af5
authored
Mar 11, 2020
by
zzrdark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.增加登陆,等
parent
1cfe83c4
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
479 additions
and
29 deletions
+479
-29
cneeds_server.sql
cneeds-common-data/db/cneeds_server.sql
+1
-1
SysDeptDao.java
...ta/src/main/java/com/mx/cneeds/server/dao/SysDeptDao.java
+7
-0
SysUserRoleDao.java
...rc/main/java/com/mx/cneeds/server/dao/SysUserRoleDao.java
+1
-0
SysDeptEntity.java
.../main/java/com/mx/cneeds/server/entity/SysDeptEntity.java
+10
-4
SysDeptDao.xml
cneeds-common-data/src/main/resources/mapper/SysDeptDao.xml
+29
-1
SysUserRoleDao.xml
...-common-data/src/main/resources/mapper/SysUserRoleDao.xml
+3
-0
DepartmentDto.java
...src/main/java/com/mx/cneeds/common/dto/DepartmentDto.java
+32
-0
CascaderVo.java
...ojo/src/main/java/com/mx/cneeds/common/vo/CascaderVo.java
+25
-0
DepartmentVo.java
...o/src/main/java/com/mx/cneeds/common/vo/DepartmentVo.java
+18
-1
TreeToolUtils.java
...ain/java/com/mx/cneeds/common/generate/TreeToolUtils.java
+49
-0
Constant.java
...ls/src/main/java/com/mx/cneeds/common/pager/Constant.java
+2
-1
pom.xml
cneeds-server-authorization/pom.xml
+16
-0
AuthorizaitonApplication.java
...cneeds/server/anthorization/AuthorizaitonApplication.java
+2
-0
MyUserDetailsService.java
...ds/server/anthorization/service/MyUserDetailsService.java
+10
-1
SysUserService.java
...x/cneeds/server/anthorization/service/SysUserService.java
+22
-0
SysUserServiceImpl.java
...server/anthorization/service/impl/SysUserServiceImpl.java
+36
-0
application-dev.yml
...rver-authorization/src/main/resources/application-dev.yml
+8
-0
PasswordEncode.java
...ver-authorization/src/test/java/utils/PasswordEncode.java
+22
-0
pom.xml
cneeds-server-datashow/pom.xml
+6
-0
UserClient.java
...java/com/mx/cneeds/server/datashow/client/UserClient.java
+6
-0
FeignInterceptor.java
...om/mx/cneeds/server/datashow/config/FeignInterceptor.java
+6
-1
SystemController.java
...x/cneeds/server/datashow/web/system/SystemController.java
+43
-4
DataFilterAspect.java
...va/com/mx/cneeds/server/user/common/DataFilterAspect.java
+15
-9
SysDeptService.java
...ava/com/mx/cneeds/server/user/service/SysDeptService.java
+10
-0
SysUserRoleService.java
...com/mx/cneeds/server/user/service/SysUserRoleService.java
+1
-0
SysUserService.java
...ava/com/mx/cneeds/server/user/service/SysUserService.java
+2
-0
SysDeptServiceImpl.java
...x/cneeds/server/user/service/impl/SysDeptServiceImpl.java
+39
-0
SysUserServiceImpl.java
...x/cneeds/server/user/service/impl/SysUserServiceImpl.java
+7
-0
SysDeptController.java
...java/com/mx/cneeds/server/user/web/SysDeptController.java
+25
-4
application-dev.yml
cneeds-server-user/src/main/resources/application-dev.yml
+26
-2
No files found.
cneeds-common-data/db/cneeds_server.sql
View file @
f5273af5
...
...
@@ -92,9 +92,9 @@ CREATE TABLE `sys_dept` (
`dept_id`
bigint
(
20
)
NOT
NULL
,
`parent_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'上级部门ID,一级部门为0'
,
`name`
varchar
(
50
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'部门名称'
,
`order_num`
int
(
11
)
DEFAULT
NULL
COMMENT
'排序'
,
`del_flag`
int
(
11
)
DEFAULT
NULL
COMMENT
'是否删除 -1:已删除 0:正常'
,
`distributor_num`
varchar
(
50
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'渠道商号'
,
`remark`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'描述'
,
PRIMARY
KEY
(
`dept_id`
)
USING
BTREE
)
ENGINE
=
InnoDB
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
COMMENT
=
'部门表'
ROW_FORMAT
=
Dynamic
;
...
...
cneeds-common-data/src/main/java/com/mx/cneeds/server/dao/SysDeptDao.java
View file @
f5273af5
...
...
@@ -5,6 +5,7 @@ import com.mx.cneeds.server.entity.SysDeptEntity;
import
org.apache.ibatis.annotations.Mapper
;
import
java.util.List
;
import
java.util.Map
;
/**
* 部门表
...
...
@@ -16,6 +17,12 @@ import java.util.List;
@Mapper
public
interface
SysDeptDao
extends
BaseMapper
<
SysDeptEntity
>
{
List
<
SysDeptEntity
>
queryListByPage
(
Map
<
String
,
Object
>
params
);
List
<
SysDeptEntity
>
queryList
(
Map
<
String
,
Object
>
params
);
Long
queryCount
(
Map
<
String
,
Object
>
params
);
/**
* 查询子部门ID列表
...
...
cneeds-common-data/src/main/java/com/mx/cneeds/server/dao/SysUserRoleDao.java
View file @
f5273af5
...
...
@@ -21,4 +21,5 @@ public interface SysUserRoleDao extends BaseMapper<SysUserRoleEntity> {
*/
List
<
Long
>
queryRoleIdList
(
Long
userId
);
}
cneeds-common-data/src/main/java/com/mx/cneeds/server/entity/SysDeptEntity.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
...
...
@@ -33,10 +34,6 @@ public class SysDeptEntity implements Serializable {
*/
private
String
name
;
/**
* 排序
*/
private
Integer
orderNum
;
/**
* 是否删除 -1:已删除 0:正常
*/
private
Integer
delFlag
;
...
...
@@ -44,5 +41,14 @@ public class SysDeptEntity implements Serializable {
* 渠道商号
*/
private
String
distributorNum
;
/**
* 描述
*/
private
String
remark
;
/**
* 上级部门名称
*/
@TableField
(
exist
=
false
)
private
String
parentName
;
}
cneeds-common-data/src/main/resources/mapper/SysDeptDao.xml
View file @
f5273af5
...
...
@@ -8,14 +8,41 @@
<result
property=
"deptId"
column=
"dept_id"
/>
<result
property=
"parentId"
column=
"parent_id"
/>
<result
property=
"name"
column=
"name"
/>
<result
property=
"orderNum"
column=
"order_num"
/>
<result
property=
"delFlag"
column=
"del_flag"
/>
<result
property=
"distributorNum"
column=
"distributor_num"
/>
<result
property=
"remark"
column=
"remark"
/>
</resultMap>
<select
id=
"queryListByPage"
resultType=
"com.mx.cneeds.server.entity.SysDeptEntity"
>
select t1.* from sys_dept t1 where
t1.del_flag = 0
<if
test=
"sql_filter != null"
>
and ${sql_filter}
</if>
limit ${startIndex},${limit}
</select>
<select
id=
"queryList"
resultType=
"com.mx.cneeds.server.entity.SysDeptEntity"
>
select t1.* from sys_dept t1 where
t1.del_flag = 0
<if
test=
"sql_filter != null"
>
and ${sql_filter}
</if>
</select>
<select
id=
"queryCount"
resultType=
"long"
>
select count(1) from sys_dept t1 where
t1.del_flag = 0
<if
test=
"sql_filter != null"
>
and ${sql_filter}
</if>
</select>
<select
id=
"queryDetpIdList"
resultType=
"long"
>
select dept_id from sys_dept where parent_id = #{value} and del_flag = 0
</select>
</mapper>
\ No newline at end of file
cneeds-common-data/src/main/resources/mapper/SysUserRoleDao.xml
View file @
f5273af5
...
...
@@ -14,4 +14,6 @@
select role_id from sys_user_role where user_id = #{value}
</select>
</mapper>
\ No newline at end of file
cneeds-common-pojo/src/main/java/com/mx/cneeds/common/dto/DepartmentDto.java
0 → 100644
View file @
f5273af5
package
com
.
mx
.
cneeds
.
common
.
dto
;
import
lombok.Data
;
/**
* @ClassName DepartmentVO
* @Author zzrdark
* @Date 2020-03-10 20:14
* @Description TODO
**/
@Data
public
class
DepartmentDto
{
private
Long
deptId
;
/**
* 上级部门ID,一级部门为0
*/
private
Long
parentId
;
private
String
name
;
/**
* 是否删除 -1:已删除 0:正常
*/
private
Integer
delFlag
;
/**
* 渠道商号
*/
private
String
distributorNum
;
/**
* 描述
*/
private
String
remark
;
}
cneeds-common-pojo/src/main/java/com/mx/cneeds/common/vo/CascaderVo.java
0 → 100644
View file @
f5273af5
package
com
.
mx
.
cneeds
.
common
.
vo
;
import
lombok.Data
;
import
java.util.List
;
/**
* @ClassName CascaderVo
* @Author zzrdark
* @Date 2020-03-11 19:44
* @Description TODO
**/
@Data
public
class
CascaderVo
{
private
Long
value
;
private
String
label
;
private
Long
pid
;
private
List
<
CascaderVo
>
children
;
public
CascaderVo
(
Long
value
,
String
label
,
Long
pid
)
{
this
.
value
=
value
;
this
.
label
=
label
;
this
.
pid
=
pid
;
}
}
cneeds-common-pojo/src/main/java/com/mx/cneeds/common/vo/DepartmentVo.java
View file @
f5273af5
...
...
@@ -10,6 +10,23 @@ import lombok.Data;
**/
@Data
public
class
DepartmentVo
{
private
String
deptName
;
private
Long
deptId
;
/**
* 上级部门ID,一级部门为0
*/
private
Long
parentId
;
private
String
name
;
/**
* 是否删除 -1:已删除 0:正常
*/
private
Integer
delFlag
;
/**
* 渠道商号
*/
private
String
distributorNum
;
/**
* 描述
*/
private
String
remark
;
}
cneeds-common-utils/src/main/java/com/mx/cneeds/common/generate/TreeToolUtils.java
0 → 100644
View file @
f5273af5
package
com
.
mx
.
cneeds
.
common
.
generate
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.mx.cneeds.common.vo.CascaderVo
;
import
java.util.List
;
import
java.util.Map
;
public
class
TreeToolUtils
{
/**
* 根节点对象存放到这里
*/
private
List
<
CascaderVo
>
rootList
;
/**
* 其他节点存放到这里,可以包含根节点
*/
private
List
<
CascaderVo
>
bodyList
;
public
TreeToolUtils
(
List
<
CascaderVo
>
rootList
,
List
<
CascaderVo
>
bodyList
)
{
this
.
rootList
=
rootList
;
this
.
bodyList
=
bodyList
;
}
public
List
<
CascaderVo
>
getTree
(){
//调用的方法入口
if
(
bodyList
!=
null
&&
!
bodyList
.
isEmpty
()){
//声明一个map,用来过滤已操作过的数据
Map
<
Long
,
Long
>
map
=
Maps
.
newHashMapWithExpectedSize
(
bodyList
.
size
());
rootList
.
forEach
(
beanTree
->
getChild
(
beanTree
,
map
));
return
rootList
;
}
return
null
;
}
public
void
getChild
(
CascaderVo
treeDto
,
Map
<
Long
,
Long
>
map
){
List
<
CascaderVo
>
childList
=
Lists
.
newArrayList
();
bodyList
.
stream
()
.
filter
(
c
->
!
map
.
containsKey
(
c
.
getValue
()))
.
filter
(
c
->
c
.
getPid
().
equals
(
treeDto
.
getValue
()))
.
forEach
(
c
->{
map
.
put
(
c
.
getValue
(),
c
.
getPid
());
getChild
(
c
,
map
);
childList
.
add
(
c
);
});
treeDto
.
setChildren
(
childList
);
}
}
\ No newline at end of file
cneeds-common-utils/src/main/java/com/mx/cneeds/common/pager/Constant.java
View file @
f5273af5
...
...
@@ -15,7 +15,8 @@ package com.mx.cneeds.common.pager;
*/
public
class
Constant
{
/** 超级管理员ID */
public
static
final
int
SUPER_ADMIN
=
1
;
public
static
final
int
INT_SUPER_ADMIN
=
1
;
public
static
final
String
STRING_SUPER_ADMIN
=
"admin"
;
/** 数据权限过滤 */
public
static
final
String
SQL_FILTER
=
"sql_filter"
;
/**
...
...
cneeds-server-authorization/pom.xml
View file @
f5273af5
...
...
@@ -11,6 +11,10 @@
<artifactId>
cneeds-server-authorization
</artifactId>
<packaging>
jar
</packaging>
<version>
1.0-SNAPSHOT
</version>
<properties>
<mysql.version>
8.0.16
</mysql.version>
</properties>
<dependencies>
<!-- eureka-client -->
...
...
@@ -37,6 +41,18 @@
<artifactId>
spring-security-jwt
</artifactId>
<version>
1.0.8.RELEASE
</version>
</dependency>
<dependency>
<groupId>
com.mx.cneeds
</groupId>
<artifactId>
cneeds-common-data
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql.version}
</version>
</dependency>
</dependencies>
<build>
...
...
cneeds-server-authorization/src/main/java/com/mx/cneeds/server/anthorization/AuthorizaitonApplication.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
anthorization
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
...
...
@@ -12,6 +13,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
**/
@SpringBootApplication
@EnableEurekaClient
@MapperScan
(
"com.mx.cneeds.server.dao"
)
public
class
AuthorizaitonApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
cneeds-server-authorization/src/main/java/com/mx/cneeds/server/anthorization/service/MyUserDetailsService.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
anthorization
.
service
;
import
com.mx.cneeds.server.entity.SysUserEntity
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.core.userdetails.User
;
...
...
@@ -14,13 +15,21 @@ public class MyUserDetailsService implements UserDetailsService {
@Autowired
private
PasswordEncoder
passwordEncoder
;
@Autowired
private
SysUserService
sysUserService
;
/** (non-Javadoc)
* @see UserDetailsService#loadUserByUsername(String)
*/
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
return
new
User
(
username
,
passwordEncoder
.
encode
(
"123456"
),
SysUserEntity
sysUserEntity
=
sysUserService
.
queryUserByUsername
(
username
);
if
(
sysUserEntity
==
null
){
return
null
;
}
return
new
User
(
username
,
sysUserEntity
.
getPassword
(),
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
"ROLE_admin"
));
}
...
...
cneeds-server-authorization/src/main/java/com/mx/cneeds/server/anthorization/service/SysUserService.java
0 → 100644
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
anthorization
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.mx.cneeds.common.pager.PageUtils
;
import
com.mx.cneeds.server.entity.SysUserEntity
;
import
java.util.Map
;
/**
* 用户信息表
*
* @author Mark
* @email sunlightcs@gmail.com
* @date 2020-01-09 15:09:01
*/
public
interface
SysUserService
extends
IService
<
SysUserEntity
>
{
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
SysUserEntity
queryUserByUsername
(
String
username
);
}
cneeds-server-authorization/src/main/java/com/mx/cneeds/server/anthorization/service/impl/SysUserServiceImpl.java
0 → 100644
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
anthorization
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.mx.cneeds.common.pager.PageUtils
;
import
com.mx.cneeds.common.pager.Query
;
import
com.mx.cneeds.server.anthorization.service.SysUserService
;
import
com.mx.cneeds.server.dao.SysUserDao
;
import
com.mx.cneeds.server.entity.SysUserEntity
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
@Service
(
"sysUserService"
)
public
class
SysUserServiceImpl
extends
ServiceImpl
<
SysUserDao
,
SysUserEntity
>
implements
SysUserService
{
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
SysUserEntity
>
page
=
this
.
page
(
new
Query
<
SysUserEntity
>().
getPage
(
params
),
new
QueryWrapper
<
SysUserEntity
>()
);
return
new
PageUtils
(
page
);
}
@Override
public
SysUserEntity
queryUserByUsername
(
String
username
)
{
return
getBaseMapper
().
selectOne
(
new
QueryWrapper
<
SysUserEntity
>()
.
eq
(
"username"
,
username
));
}
}
cneeds-server-authorization/src/main/resources/application-dev.yml
View file @
f5273af5
spring
:
datasource
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://192.168.2.244:3306/cneeds_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false
password
:
cneeds!QAZ1qaz
username
:
root
eureka
:
client
:
service-url
:
...
...
cneeds-server-authorization/src/test/java/utils/PasswordEncode.java
0 → 100644
View file @
f5273af5
package
utils
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
/**
* @ClassName PasswordEncode
* @Author zzrdark
* @Date 2020-03-11 17:53
* @Description TODO
**/
public
class
PasswordEncode
{
public
static
void
main
(
String
[]
args
)
{
String
password
=
"admin"
;
BCryptPasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
String
enPassword1
=
encoder
.
encode
(
password
);
String
enPassword2
=
encoder
.
encode
(
password
);
System
.
out
.
println
(
enPassword1
);
System
.
out
.
println
(
encoder
.
matches
(
password
,
enPassword1
));
System
.
out
.
println
(
encoder
.
matches
(
password
,
enPassword2
));
}
}
cneeds-server-datashow/pom.xml
View file @
f5273af5
...
...
@@ -47,6 +47,12 @@
<artifactId>
spring-security-jwt
</artifactId>
<version>
1.0.8.RELEASE
</version>
</dependency>
<dependency>
<groupId>
com.mx.cneeds
</groupId>
<artifactId>
cneeds-common-utils
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
...
...
cneeds-server-datashow/src/main/java/com/mx/cneeds/server/datashow/client/UserClient.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
datashow
.
client
;
import
com.mx.cneeds.common.dto.DepartmentDto
;
import
com.mx.cneeds.common.dto.JwtToken
;
import
com.mx.cneeds.common.dto.PageDto
;
import
org.springframework.cloud.openfeign.FeignClient
;
...
...
@@ -7,6 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.List
;
/**
* @ClassName UserClient
* @Author zzrdark
...
...
@@ -71,4 +74,7 @@ public interface UserClient {
@RequestParam
(
"limit"
)
Integer
pageSize
,
@RequestParam
(
"sidx"
)
String
orderField
,
@RequestParam
(
"order"
)
String
order
);
@PostMapping
(
"/sys/dept/listAll"
)
List
<
DepartmentDto
>
deptListAll
();
}
cneeds-server-datashow/src/main/java/com/mx/cneeds/server/datashow/config/FeignInterceptor.java
View file @
f5273af5
...
...
@@ -5,7 +5,7 @@ import feign.RequestInterceptor;
import
feign.RequestTemplate
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.
web.context.request.RequestAttributes
;
import
org.springframework.
security.core.context.SecurityContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
...
@@ -23,8 +23,10 @@ public class FeignInterceptor implements RequestInterceptor {
@Override
public
void
apply
(
RequestTemplate
requestTemplate
)
{
//只支持 servlet
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
String
username
=
(
String
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
if
(
requestAttributes
==
null
){
return
;
...
...
@@ -34,6 +36,9 @@ public class FeignInterceptor implements RequestInterceptor {
if
(
request
.
getRequestURL
().
toString
().
contains
(
"/user/login"
)){
String
authString
=
RequestParamterConverter
.
authorizationConverter
(
"clientapp"
,
"112233"
);
requestTemplate
.
header
(
"Authorization"
,
authString
);
}
else
{
requestTemplate
.
query
(
"username"
,
username
);
}
}
}
cneeds-server-datashow/src/main/java/com/mx/cneeds/server/datashow/web/system/SystemController.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
datashow
.
web
.
system
;
import
com.mx.cneeds.common.converter.RequestParamterConverter
;
import
com.mx.cneeds.common.dto.DepartmentDto
;
import
com.mx.cneeds.common.dto.PageDto
;
import
com.mx.cneeds.common.generate.TreeToolUtils
;
import
com.mx.cneeds.common.result.R
;
import
com.mx.cneeds.common.vo.CascaderVo
;
import
com.mx.cneeds.common.vo.DepartmentVo
;
import
com.mx.cneeds.server.datashow.client.UserClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.
PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.
*
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @ClassName SystemController
...
...
@@ -161,6 +164,42 @@ public class SystemController {
}
@PostMapping
(
"/dept/edit"
)
public
R
editDept
(
DepartmentVo
departmentVo
){
return
R
.
ok
();
}
@PostMapping
(
"/dept/delete"
)
public
R
deleteDept
(
@RequestParam
(
value
=
"ids"
,
required
=
false
)
List
<
Long
>
ids
,
String
e
){
return
R
.
ok
();
}
@PostMapping
(
"/dept/listAll"
)
public
R
selectDeptParent
(){
List
<
DepartmentDto
>
dtos
=
userClient
.
deptListAll
();
List
<
CascaderVo
>
rootList
=
new
ArrayList
<>();
List
<
CascaderVo
>
bodyList
=
new
ArrayList
<>();
dtos
.
forEach
(
dto
->
{
CascaderVo
vo
=
new
CascaderVo
(
dto
.
getDeptId
(),
dto
.
getName
(),
dto
.
getParentId
());
//TODO 这里应该是自己的部门Id
if
(
dto
.
getParentId
()==
0
){
rootList
.
add
(
vo
);
}
else
{
bodyList
.
add
(
vo
);
}
});
TreeToolUtils
utils
=
new
TreeToolUtils
(
rootList
,
bodyList
);
List
<
CascaderVo
>
result
=
utils
.
getTree
();
return
new
R
().
put
(
"data"
,
result
);
}
}
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/common/DataFilterAspect.java
View file @
f5273af5
...
...
@@ -13,9 +13,11 @@ package com.mx.cneeds.server.user.common;
import
com.mx.cneeds.common.annotation.DataFilter
;
import
com.mx.cneeds.common.exception.RRException
;
import
com.mx.cneeds.common.pager.Constant
;
import
com.mx.cneeds.server.entity.SysUserEntity
;
import
com.mx.cneeds.server.user.service.SysDeptService
;
import
com.mx.cneeds.server.user.service.SysRoleDeptService
;
import
com.mx.cneeds.server.user.service.SysUserRoleService
;
import
com.mx.cneeds.server.user.service.SysUserService
;
import
org.apache.commons.lang.StringUtils
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.Aspect
;
...
...
@@ -38,6 +40,9 @@ import java.util.Set;
@Aspect
@Component
public
class
DataFilterAspect
{
@Autowired
private
SysUserService
sysUserService
;
@Autowired
private
SysDeptService
sysDeptService
;
@Autowired
...
...
@@ -51,15 +56,14 @@ public class DataFilterAspect {
}
@Before
(
"dataFilterCut()"
)
public
void
dataFilter
(
JoinPoint
point
)
throws
Throwable
{
public
void
dataFilter
(
JoinPoint
point
){
Object
params
=
point
.
getArgs
()[
0
];
if
(
params
!=
null
&&
params
instanceof
Map
){
// SysUserEntity user = ShiroUtils.getUserEntity();
Long
userId
=
(
Long
)
((
Map
)
params
).
get
(
"userId"
);
String
username
=
(
String
)
((
Map
)
params
).
get
(
"username"
);
//如果不是超级管理员,则进行数据过滤
if
(
userId
!=
Constant
.
SUPER_ADMIN
){
if
(
!
Constant
.
STRING_SUPER_ADMIN
.
equals
(
username
)
){
Map
map
=
(
Map
)
params
;
map
.
put
(
Constant
.
SQL_FILTER
,
getSQLFilter
(
user
Id
,
point
));
map
.
put
(
Constant
.
SQL_FILTER
,
getSQLFilter
(
user
name
,
point
));
}
return
;
}
...
...
@@ -70,7 +74,7 @@ public class DataFilterAspect {
/**
* 获取数据过滤的SQL
*/
private
String
getSQLFilter
(
Long
userId
,
JoinPoint
point
){
private
String
getSQLFilter
(
String
username
,
JoinPoint
point
){
MethodSignature
signature
=
(
MethodSignature
)
point
.
getSignature
();
DataFilter
dataFilter
=
signature
.
getMethod
().
getAnnotation
(
DataFilter
.
class
);
//获取表的别名
...
...
@@ -82,8 +86,10 @@ public class DataFilterAspect {
//部门ID列表
Set
<
Long
>
deptIdList
=
new
HashSet
<>();
SysUserEntity
sysUserEntity
=
sysUserService
.
queryUserByUsername
(
username
);
//用户角色对应的部门ID列表
List
<
Long
>
roleIdList
=
sysUserRoleService
.
queryRoleIdList
(
userId
);
List
<
Long
>
roleIdList
=
sysUserRoleService
.
queryRoleIdList
(
sysUserEntity
.
getUserId
()
);
if
(
roleIdList
.
size
()
>
0
){
List
<
Long
>
userDeptIdList
=
sysRoleDeptService
.
queryDeptIdList
(
roleIdList
.
toArray
(
new
Long
[
roleIdList
.
size
()]));
deptIdList
.
addAll
(
userDeptIdList
);
...
...
@@ -91,7 +97,7 @@ public class DataFilterAspect {
//用户子部门ID列表
if
(
dataFilter
.
subDept
()){
List
<
Long
>
subDeptIdList
=
sysDeptService
.
getSubDeptIdList
(
userId
);
List
<
Long
>
subDeptIdList
=
sysDeptService
.
getSubDeptIdList
(
sysUserEntity
.
getUserId
()
);
deptIdList
.
addAll
(
subDeptIdList
);
}
...
...
@@ -107,7 +113,7 @@ public class DataFilterAspect {
if
(
deptIdList
.
size
()
>
0
){
sqlFilter
.
append
(
" or "
);
}
sqlFilter
.
append
(
tableAlias
).
append
(
dataFilter
.
userId
()).
append
(
"="
).
append
(
userId
);
sqlFilter
.
append
(
tableAlias
).
append
(
dataFilter
.
userId
()).
append
(
"="
).
append
(
sysUserEntity
.
getUserId
()
);
}
sqlFilter
.
append
(
")"
);
...
...
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/service/SysDeptService.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
user
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.mx.cneeds.common.annotation.DataFilter
;
import
com.mx.cneeds.common.pager.PageUtils
;
import
com.mx.cneeds.server.entity.SysDeptEntity
;
...
...
@@ -16,6 +17,11 @@ import java.util.Map;
*/
public
interface
SysDeptService
extends
IService
<
SysDeptEntity
>
{
List
<
SysDeptEntity
>
queryListByPage
(
Map
<
String
,
Object
>
params
);
List
<
SysDeptEntity
>
queryList
(
Map
<
String
,
Object
>
params
);
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
/**
...
...
@@ -24,6 +30,10 @@ public interface SysDeptService extends IService<SysDeptEntity> {
List
<
Long
>
getSubDeptIdList
(
Long
deptId
);
List
<
Long
>
queryDetpIdList
(
Long
parentId
);
List
<
SysDeptEntity
>
queryDeptIdsBydeptName
(
List
<
Long
>
Ids
);
Long
queryDeptCount
(
Map
<
String
,
Object
>
params
);
}
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/service/SysUserRoleService.java
View file @
f5273af5
...
...
@@ -23,5 +23,6 @@ public interface SysUserRoleService extends IService<SysUserRoleEntity> {
* @param userId
*/
List
<
Long
>
queryRoleIdList
(
Long
userId
);
}
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/service/SysUserService.java
View file @
f5273af5
...
...
@@ -16,5 +16,7 @@ import java.util.Map;
public
interface
SysUserService
extends
IService
<
SysUserEntity
>
{
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
SysUserEntity
queryUserByUsername
(
String
username
);
}
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/service/impl/SysDeptServiceImpl.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
user
.
service
.
impl
;
import
com.mx.cneeds.common.annotation.DataFilter
;
import
com.mx.cneeds.common.pager.Constant
;
import
com.mx.cneeds.common.pager.PageUtils
;
import
com.mx.cneeds.common.pager.Query
;
import
com.mx.cneeds.server.dao.SysDeptDao
;
...
...
@@ -19,6 +21,41 @@ import org.springframework.transaction.annotation.Transactional;
@Service
(
"sysDeptService"
)
public
class
SysDeptServiceImpl
extends
ServiceImpl
<
SysDeptDao
,
SysDeptEntity
>
implements
SysDeptService
{
@Override
@DataFilter
(
subDept
=
true
,
user
=
false
,
tableAlias
=
"t1"
)
public
List
<
SysDeptEntity
>
queryListByPage
(
Map
<
String
,
Object
>
params
){
long
curPage
=
1
;
long
limit
=
10
;
if
(
params
.
get
(
Constant
.
PAGE
)
!=
null
){
curPage
=
Long
.
parseLong
((
String
)
params
.
get
(
Constant
.
PAGE
));
}
if
(
params
.
get
(
Constant
.
LIMIT
)
!=
null
){
limit
=
Long
.
parseLong
((
String
)
params
.
get
(
Constant
.
LIMIT
));
}
params
.
put
(
Constant
.
PAGE
,
curPage
);
params
.
put
(
Constant
.
LIMIT
,
limit
);
Long
startIndex
=
curPage
>
1
?
0
:
(
curPage
-
1
)*
limit
;
params
.
put
(
"startIndex"
,
startIndex
);
return
baseMapper
.
queryListByPage
(
params
);
}
@Override
@DataFilter
(
subDept
=
true
,
user
=
false
,
tableAlias
=
"t1"
)
public
List
<
SysDeptEntity
>
queryList
(
Map
<
String
,
Object
>
params
)
{
return
baseMapper
.
queryList
(
params
);
}
@Override
@DataFilter
(
subDept
=
true
,
user
=
false
,
tableAlias
=
"t1"
)
public
Long
queryDeptCount
(
Map
<
String
,
Object
>
params
)
{
Long
count
=
baseMapper
.
queryCount
(
params
);
return
count
;
}
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
SysDeptEntity
>
page
=
this
.
page
(
...
...
@@ -54,6 +91,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptDao, SysDeptEntity> i
.
select
(
"dept_id"
,
"name"
).
in
(
"dept_id"
,
Ids
));
}
/**
* 递归
*/
...
...
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/service/impl/SysUserServiceImpl.java
View file @
f5273af5
...
...
@@ -25,4 +25,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
return
new
PageUtils
(
page
);
}
@Override
public
SysUserEntity
queryUserByUsername
(
String
username
)
{
return
getBaseMapper
().
selectOne
(
new
QueryWrapper
<
SysUserEntity
>()
.
eq
(
"username"
,
username
));
}
}
cneeds-server-user/src/main/java/com/mx/cneeds/server/user/web/SysDeptController.java
View file @
f5273af5
package
com
.
mx
.
cneeds
.
server
.
user
.
web
;
import
com.mx.cneeds.common.dto.DepartmentDto
;
import
com.mx.cneeds.common.pager.Constant
;
import
com.mx.cneeds.common.pager.PageUtils
;
import
com.mx.cneeds.common.result.R
;
import
com.mx.cneeds.common.validator.ValidatorUtils
;
import
com.mx.cneeds.server.entity.SysDeptEntity
;
import
com.mx.cneeds.server.user.service.SysDeptService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Arrays
;
import
java.util.Map
;
import
java.util.*
;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
...
...
@@ -31,12 +33,31 @@ public class SysDeptController {
* 列表
*/
@RequestMapping
(
"/list"
)
// @RequiresPermissions("sys:sysdept:list")
public
PageUtils
list
(
@RequestParam
Map
<
String
,
Object
>
params
){
PageUtils
page
=
sysDeptService
.
queryPage
(
params
);
// PageUtils page = sysDeptService.queryPage(params);
List
<
SysDeptEntity
>
sysDeptEntityList
=
sysDeptService
.
queryListByPage
(
params
);
long
count
=
sysDeptService
.
queryDeptCount
(
params
);
long
limit
=
(
long
)
params
.
get
(
Constant
.
LIMIT
);
long
Curpage
=
(
long
)
params
.
get
(
Constant
.
PAGE
);
PageUtils
page
=
new
PageUtils
(
sysDeptEntityList
,
(
int
)
count
,
(
int
)
limit
,
(
int
)
Curpage
);
return
page
;
}
@RequestMapping
(
"/listAll"
)
public
List
<
DepartmentDto
>
listAll
(
@RequestParam
Map
<
String
,
Object
>
params
){
List
<
SysDeptEntity
>
sysDeptEntityList
=
sysDeptService
.
queryList
(
params
);
List
<
DepartmentDto
>
departmentDtoList
=
new
ArrayList
<>();
sysDeptEntityList
.
forEach
(
sysDeptEntity
->
{
DepartmentDto
departmentDto
=
new
DepartmentDto
();
BeanUtils
.
copyProperties
(
sysDeptEntity
,
departmentDto
);
departmentDtoList
.
add
(
departmentDto
);
});
return
departmentDtoList
;
}
/**
* 信息
...
...
cneeds-server-user/src/main/resources/application-dev.yml
View file @
f5273af5
...
...
@@ -50,4 +50,29 @@ eureka:
defaultZone
:
http://192.168.2.244:8761/eureka/
instance
:
prefer-ip-address
:
true
ip-address
:
192.168.2.244
\ No newline at end of file
# ip-address: 192.168.2.244
mybatis-plus
:
mapper-locations
:
classpath:mapper/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage
:
com.mx.cneeds.server.entity
global-config
:
#数据库相关配置
db-config
:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type
:
AUTO
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
field-strategy
:
NOT_NULL
#驼峰下划线转换
column-underline
:
true
logic-delete-value
:
-1
logic-not-delete-value
:
0
banner
:
false
#原生配置
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
call-setters-on-nulls
:
true
jdbc-type-for-null
:
'
null'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment