切换导航条
此项目
正在载入...
登录
朱兆平
/
spring cloud基础开发框架
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
1
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
朱兆平
6 years ago
提交
5019e1102b696eb809e6f471adbe3e62798446a4
1 个父辈
9aa0b28c
用户的权限配置 加入事务
显示空白字符变更
内嵌
并排对比
正在显示
10 个修改的文件
包含
183 行增加
和
19 行删除
pom.xml
readme.md
src/main/java/com/tianbo/warehouse/WarehouseApplication.java
src/main/java/com/tianbo/warehouse/controller/UserController.java
src/main/java/com/tianbo/warehouse/dao/UserRoleMapper.java
src/main/java/com/tianbo/warehouse/model/UserRole.java
src/main/java/com/tianbo/warehouse/service/UserService.java
src/main/java/com/tianbo/warehouse/service/imp/UserServiceImpl.java
src/main/resources/generator/generatorConfig.xml
src/main/resources/mapping/UserRoleMapper.xml
pom.xml
查看文件 @
5019e11
...
...
@@ -18,6 +18,7 @@
<java.version>
1.8
</java.version>
<spring-cloud.version>
Greenwich.BUILD-SNAPSHOT
</spring-cloud.version>
<fastjson_version>
1.2.28
</fastjson_version>
<lombok_sersion>
1.18.6
</lombok_sersion>
</properties>
<dependencies>
...
...
@@ -86,6 +87,13 @@
</dependency>
<!--spring boot-->
<!-- tools-->
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
${lombok_sersion}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
commons-codec
</groupId>
<artifactId>
commons-codec
</artifactId>
...
...
readme.md
查看文件 @
5019e11
...
...
@@ -20,6 +20,6 @@
*
目前在IMF框架中使用,打开IMF_Task里面的定时任务注释就可以启动IMF客户端功能
*
集成Spring Cloud
*
集成websocket
*
将会集成lombok,简化部分代码录入,比如实体类,
使用方法见
[
lombok集成使用说明
](
https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html
)
*
集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,
使用方法见
[
lombok集成使用说明
](
https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html
)
)
...
...
src/main/java/com/tianbo/warehouse/WarehouseApplication.java
查看文件 @
5019e11
...
...
@@ -11,9 +11,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@SpringBootApplication
@EnableScheduling
//@EnableEurekaClient
@EnableTransactionManagement
@MapperScan
(
"com.tianbo.warehouse.dao"
)
public
class
WarehouseApplication
{
...
...
src/main/java/com/tianbo/warehouse/controller/UserController.java
查看文件 @
5019e11
...
...
@@ -5,6 +5,7 @@ import com.tianbo.warehouse.annotation.LogAnnotation;
import
com.tianbo.warehouse.annotation.UserPasswordMd5
;
import
com.tianbo.warehouse.controller.response.ResultJson
;
import
com.tianbo.warehouse.model.USERS
;
import
com.tianbo.warehouse.model.UserRole
;
import
com.tianbo.warehouse.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.context.SecurityContextHolder
;
...
...
@@ -43,12 +44,8 @@ public class UserController {
public
ResultJson
updateUserById
(
@RequestBody
@Valid
USERS
user
){
int
i
=
userService
.
updateByPrimaryKeySelective
(
user
);
ResultJson
resultJson
=
new
ResultJson
();
if
(
1
==
i
){
resultJson
=
new
ResultJson
(
"200"
,
"success"
);
}
else
{
resultJson
=
new
ResultJson
(
"500"
,
"update faild"
);
}
return
resultJson
;
return
i
==
1
?
new
ResultJson
(
"200"
,
"success"
)
:
new
ResultJson
(
"500"
,
"update faild"
);
}
@UserPasswordMd5
...
...
@@ -62,12 +59,8 @@ public class UserController {
int
i
=
userService
.
insertSelective
(
user
);
ResultJson
resultJson
=
new
ResultJson
();
if
(
1
==
i
){
resultJson
=
new
ResultJson
(
"200"
,
"新建账户成功"
);
}
else
{
resultJson
=
new
ResultJson
(
"500"
,
"insert faild"
);
}
return
resultJson
;
return
i
==
1
?
new
ResultJson
(
"200"
,
"新建账户成功"
)
:
new
ResultJson
(
"500"
,
"insert faild"
);
}
@LogAnnotation
(
moduleName
=
"用户管理"
,
operate
=
"用户删除"
)
...
...
@@ -76,12 +69,17 @@ public class UserController {
//String username = getusername();
int
i
=
userService
.
deleteByPrimaryKey
(
user
.
getUserId
());
ResultJson
resultJson
=
new
ResultJson
();
if
(
1
==
i
){
resultJson
=
new
ResultJson
(
"200"
,
"删除账户成功"
);
}
else
{
resultJson
=
new
ResultJson
(
"500"
,
"delete faild"
);
return
i
==
1
?
new
ResultJson
(
"200"
,
"删除账户成功"
)
:
new
ResultJson
(
"500"
,
"delete faild"
);
}
return
resultJson
;
@PutMapping
(
"/user/roleset"
)
public
ResultJson
roleSet
(
@RequestBody
UserRole
userRole
){
int
i
=
userService
.
setUserRole
(
userRole
);
return
i
==
1
?
new
ResultJson
(
"200"
,
"设置权限成功"
)
:
new
ResultJson
(
"500"
,
"设置权限失败"
);
}
}
...
...
src/main/java/com/tianbo/warehouse/dao/UserRoleMapper.java
0 → 100644
查看文件 @
5019e11
package
com
.
tianbo
.
warehouse
.
dao
;
import
com.tianbo.warehouse.model.UserRole
;
public
interface
UserRoleMapper
{
int
deleteByPrimaryKey
(
Integer
id
);
int
deleteByUserId
(
Integer
userId
);
int
insert
(
UserRole
record
);
int
insertSelective
(
UserRole
record
);
UserRole
selectByPrimaryKey
(
Integer
id
);
int
updateByPrimaryKeySelective
(
UserRole
record
);
int
updateByPrimaryKey
(
UserRole
record
);
}
\ No newline at end of file
...
...
src/main/java/com/tianbo/warehouse/model/UserRole.java
0 → 100644
查看文件 @
5019e11
package
com
.
tianbo
.
warehouse
.
model
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
UserRole
{
private
Integer
id
;
private
Integer
userId
;
private
Integer
roleId
;
private
List
<
Integer
>
roleIds
;
public
UserRole
(){
}
public
UserRole
(
Integer
userId
,
Integer
roleId
){
this
.
roleId
=
roleId
;
this
.
userId
=
userId
;
}
}
...
...
src/main/java/com/tianbo/warehouse/service/UserService.java
查看文件 @
5019e11
...
...
@@ -2,6 +2,7 @@ package com.tianbo.warehouse.service;
import
com.github.pagehelper.PageInfo
;
import
com.tianbo.warehouse.model.USERS
;
import
com.tianbo.warehouse.model.UserRole
;
import
java.util.List
;
...
...
@@ -15,4 +16,6 @@ public interface UserService {
int
insertSelective
(
USERS
record
);
int
deleteByPrimaryKey
(
Integer
userId
);
int
setUserRole
(
UserRole
userRole
);
}
...
...
src/main/java/com/tianbo/warehouse/service/imp/UserServiceImpl.java
查看文件 @
5019e11
...
...
@@ -6,12 +6,15 @@ import com.github.pagehelper.PageInfo;
import
com.tianbo.warehouse.dao.PERMISSIONMapper
;
import
com.tianbo.warehouse.dao.ROLEMapper
;
import
com.tianbo.warehouse.dao.USERSMapper
;
import
com.tianbo.warehouse.dao.UserRoleMapper
;
import
com.tianbo.warehouse.model.PERMISSION
;
import
com.tianbo.warehouse.model.ROLE
;
import
com.tianbo.warehouse.model.USERS
;
import
com.tianbo.warehouse.model.UserRole
;
import
com.tianbo.warehouse.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
...
...
@@ -27,6 +30,9 @@ public class UserServiceImpl implements UserService{
@Autowired
private
PERMISSIONMapper
permissionMapper
;
@Autowired
private
UserRoleMapper
userRoleMapper
;
@Override
public
USERS
loadByUsername
(
String
username
){
List
<
USERS
>
userList
=
usersMapper
.
selectByUsername
(
username
);
...
...
@@ -90,4 +96,32 @@ public class UserServiceImpl implements UserService{
return
0
;
}
}
/**重置用户的权限
*这里需要开启事务,删除 或者插入不生效就回滚
* @param userRole
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
int
setUserRole
(
UserRole
userRole
){
try
{
Integer
userId
=
userRole
.
getUserId
();
List
<
Integer
>
ids
=
userRole
.
getRoleIds
();
userRoleMapper
.
deleteByUserId
(
userId
);
if
(
null
!=
ids
&&
!
ids
.
isEmpty
()){
for
(
Integer
id:
ids
)
{
UserRole
ur
=
new
UserRole
(
userId
,
id
);
userRoleMapper
.
insertSelective
(
ur
);
}
}
return
1
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
0
;
}
}
}
...
...
src/main/resources/generator/generatorConfig.xml
查看文件 @
5019e11
...
...
@@ -45,6 +45,6 @@
<property
name=
"enableSubPackages"
value=
"true"
/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table
tableName=
"
log"
domainObjectName=
"LOG
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
></table>
<table
tableName=
"
user_role"
domainObjectName=
"UserRole
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
></table>
</context>
</generatorConfiguration>
\ No newline at end of file
...
...
src/main/resources/mapping/UserRoleMapper.xml
0 → 100644
查看文件 @
5019e11
<?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.tianbo.warehouse.dao.UserRoleMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.tianbo.warehouse.model.UserRole"
>
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"user_id"
property=
"userId"
jdbcType=
"INTEGER"
/>
<result
column=
"role_id"
property=
"roleId"
jdbcType=
"INTEGER"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
id, user_id, role_id
</sql>
<select
id=
"selectByPrimaryKey"
resultMap=
"BaseResultMap"
parameterType=
"java.lang.Integer"
>
select
<include
refid=
"Base_Column_List"
/>
from user_role
where id = #{id,jdbcType=INTEGER}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.Integer"
>
delete from user_role
where id = #{id,jdbcType=INTEGER}
</delete>
<delete
id=
"deleteByUserId"
parameterType=
"java.lang.Integer"
>
delete from user_role
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<insert
id=
"insert"
parameterType=
"com.tianbo.warehouse.model.UserRole"
>
insert into user_role (id, user_id, role_id
)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
)
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.tianbo.warehouse.model.UserRole"
>
insert into user_role
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"userId != null"
>
user_id,
</if>
<if
test=
"roleId != null"
>
role_id,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=INTEGER},
</if>
<if
test=
"userId != null"
>
#{userId,jdbcType=INTEGER},
</if>
<if
test=
"roleId != null"
>
#{roleId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.tianbo.warehouse.model.UserRole"
>
update user_role
<set
>
<if
test=
"userId != null"
>
user_id = #{userId,jdbcType=INTEGER},
</if>
<if
test=
"roleId != null"
>
role_id = #{roleId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.tianbo.warehouse.model.UserRole"
>
update user_role
set user_id = #{userId,jdbcType=INTEGER},
role_id = #{roleId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论