Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9b460ae3
authored
Oct 08, 2023
by
huangjinxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:重写角色新增
1 parent
33a7dc33
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
202 additions
and
22 deletions
project-interface/src/main/java/com/dituhui/pea/user/IRole2.java
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
project-user/src/main/java/com/dituhui/pea/user/dao/RoleDao2.java
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity2.java
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
project-user/src/main/java/com/dituhui/pea/user/service/RoleService2.java
project-interface/src/main/java/com/dituhui/pea/user/IRole2.java
0 → 100644
View file @
9b460ae
package
com
.
dituhui
.
pea
.
user
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
/**
* 角色相关接口
*/
@FeignClient
(
value
=
"project-user"
,
contextId
=
"role"
)
public
interface
IRole2
{
/**
* 添加角色
*
* @param roleInfo 角色信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/role/add2"
,
method
=
RequestMethod
.
POST
)
Result
<
RoleInfo
>
addRole
(
@RequestBody
RoleInfo
roleInfo
);
}
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
View file @
9b460ae
...
...
@@ -35,8 +35,7 @@ public class RoleController implements IRole {
@Override
public
Result
<
RoleInfo
>
addRole
(
@Validated
RoleInfo
roleInfo
)
{
roleInfo
=
roleService
.
addRole
(
roleInfo
);
return
Result
.
success
(
roleInfo
);
return
roleService
.
addRole
(
roleInfo
);
}
...
...
project-user/src/main/java/com/dituhui/pea/user/dao/RoleDao2.java
0 → 100644
View file @
9b460ae
package
com
.
dituhui
.
pea
.
user
.
dao
;
import
com.dituhui.pea.user.entity.RoleEntity2
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
/**
* 角色表(Role)表数据库访问层
*
*/
public
interface
RoleDao2
extends
JpaRepository
<
RoleEntity2
,
String
>,
JpaSpecificationExecutor
<
RoleEntity2
>,
CrudRepository
<
RoleEntity2
,
String
>
{
}
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
View file @
9b460ae
...
...
@@ -9,7 +9,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
/**
...
...
@@ -19,7 +18,7 @@ import java.util.Date;
@Data
@Entity
@Table
(
name
=
"sys_role"
)
//
@EntityListeners(AuditingEntityListener.class)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
RoleEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
71423293715769828L
;
/**
...
...
@@ -55,9 +54,9 @@ public class RoleEntity implements Serializable {
/**
* 创建时间
*/
//
@Column(name = "CREATED_TIME")
@C
olumn
(
name
=
"CREATED_TIME"
,
nullable
=
false
,
updatable
=
false
,
columnDefinition
=
"timestamp default current_timestamp"
)
private
LocalDateTim
e
createdTime
;
@Column
(
name
=
"CREATED_TIME"
)
@C
reatedDate
private
Dat
e
createdTime
;
/**
* 更新人
*/
...
...
@@ -66,9 +65,9 @@ public class RoleEntity implements Serializable {
/**
* 更新时间
*/
//
@Column(name = "UPDATED_TIME")
@
Column
(
name
=
"UPDATED_TIME"
,
nullable
=
false
,
columnDefinition
=
"timestamp default current_timestamp on update current_timestamp"
)
private
LocalDateTim
e
updatedTime
;
@Column
(
name
=
"UPDATED_TIME"
)
@
LastModifiedDate
private
Dat
e
updatedTime
;
/**
* 备注
...
...
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity2.java
0 → 100644
View file @
9b460ae
package
com
.
dituhui
.
pea
.
user
.
entity
;
import
lombok.Data
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 角色表(RoleEntity)实体类
*
*/
@Data
@Entity
@Table
(
name
=
"sys_role"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
RoleEntity2
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
71423293716769828L
;
/**
* 主键
*/
@Id
@GeneratedValue
(
generator
=
"uuid"
)
@GenericGenerator
(
name
=
"uuid"
,
strategy
=
"uuid"
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
,
length
=
60
)
private
String
id
;
/**
* 名称
*/
@Column
(
name
=
"name"
)
@NotBlank
(
message
=
"角色名称不能为空!"
)
private
String
name
;
/**
* 角色组id
*/
@Column
(
name
=
"group_id"
)
private
String
groupId
;
/**
* 角色自定义条件
*/
@Column
(
name
=
"extra"
)
@NotBlank
(
message
=
"角色自定义条件不能为空!"
)
private
String
extra
;
/**
* 创建人
*/
@Column
(
name
=
"CREATED_BY"
)
private
String
createdBy
;
/**
* 创建时间
*/
@Column
(
name
=
"CREATED_TIME"
)
@CreatedDate
private
Date
createdTime
;
/**
* 更新人
*/
@Column
(
name
=
"UPDATED_BY"
)
private
String
updatedBy
;
/**
* 更新时间
*/
@Column
(
name
=
"UPDATED_TIME"
)
@LastModifiedDate
private
Date
updatedTime
;
/**
* 备注
*/
@Column
(
name
=
"notes"
)
private
String
notes
;
}
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
View file @
9b460ae
...
...
@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.enums.RedisKeyGroup
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.exception.BusinessException
;
...
...
@@ -73,15 +74,18 @@ public class RoleService {
@Transactional
public
RoleInfo
addRole
(
RoleInfo
roleInfo
)
{
String
name
=
roleInfo
.
getName
();
String
createdBy
=
roleInfo
.
getCreatedBy
();
String
notes
=
roleInfo
.
getNotes
();
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
name
);
roleEntity
.
setCreatedBy
(
createdBy
);
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setNotes
(
notes
);
public
Result
<
RoleInfo
>
addRole
(
RoleInfo
roleInfo
)
{
// String name = roleInfo.getName();
// String createdBy = roleInfo.getCreatedBy();
// String notes = roleInfo.getNotes();
// RoleEntity roleEntity = new RoleEntity();
// roleEntity.setName(name);
// roleEntity.setCreatedBy(createdBy);
// roleEntity.setCreatedTime(LocalDateTime.now());
// roleEntity.setNotes(notes);
RoleEntity
roleEntity
=
BeanUtil
.
copyProperties
(
roleInfo
,
RoleEntity
.
class
);
// RoleEntity roleEntity = assembleRole(roleInfo);
log
.
info
(
"新增角色入参:"
+
JSONObject
.
toJSONString
(
roleEntity
));
roleEntity
=
roleDao
.
save
(
roleEntity
);
...
...
@@ -95,7 +99,7 @@ public class RoleService {
}
}
log
.
info
(
"新增角色信息:"
+
JSONObject
.
toJSONString
(
roleInfo
));
return
roleInfo
;
return
Result
.
success
(
roleInfo
)
;
}
...
...
@@ -140,7 +144,7 @@ public class RoleService {
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
name
);
roleEntity
.
setCreatedBy
(
createdBy
);
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setCreatedTime
(
new
Date
());
roleEntity
.
setNotes
(
notes
);
// RoleEntity roleEntity = assembleRole(roleInfo);
log
.
info
(
"新增角色入参:"
+
JSONObject
.
toJSONString
(
roleEntity
));
...
...
@@ -291,7 +295,7 @@ public class RoleService {
RoleEntity
roleEntity
=
new
RoleEntity
();
roleEntity
.
setName
(
roleInfo
.
getName
());
roleEntity
.
setCreatedBy
(
roleInfo
.
getCreatedBy
());
roleEntity
.
setCreatedTime
(
LocalDateTime
.
now
());
roleEntity
.
setCreatedTime
(
new
Date
());
roleEntity
.
setNotes
(
roleInfo
.
getNotes
());
return
roleEntity
;
}
...
...
project-user/src/main/java/com/dituhui/pea/user/service/RoleService2.java
0 → 100644
View file @
9b460ae
package
com
.
dituhui
.
pea
.
user
.
service
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.role.RoleResourceInfo
;
import
com.dituhui.pea.user.dao.RoleDao
;
import
com.dituhui.pea.user.dao.RoleDao2
;
import
com.dituhui.pea.user.dao.RoleResourceDao
;
import
com.dituhui.pea.user.entity.RoleEntity
;
import
com.dituhui.pea.user.entity.RoleEntity2
;
import
com.dituhui.pea.user.entity.RoleResourceEntity
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
@Service
@Slf4j
public
class
RoleService2
{
@Autowired
RoleDao2
roleDao
;
@Autowired
RoleResourceDao
roleResourceDao
;
@Transactional
public
Result
<
RoleInfo
>
addRole
(
RoleInfo
roleInfo
)
{
RoleEntity2
roleEntity
=
BeanUtil
.
copyProperties
(
roleInfo
,
RoleEntity2
.
class
);
// RoleEntity roleEntity = assembleRole(roleInfo);
log
.
info
(
"新增角色入参:"
+
JSONObject
.
toJSONString
(
roleEntity
));
roleEntity
=
roleDao
.
save
(
roleEntity
);
// roleInfo = BeanUtil.copyProperties(roleEntity, RoleInfo.class);
roleInfo
.
setId
(
roleEntity
.
getId
());
List
<
RoleResourceInfo
>
resourceInfos
=
roleInfo
.
getResourceInfos
();
if
(
CollectionUtils
.
isNotEmpty
(
resourceInfos
))
{
for
(
RoleResourceInfo
resourceInfo
:
resourceInfos
)
{
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
roleInfo
.
getId
(),
resourceInfo
.
getResourceId
());
roleResourceDao
.
save
(
roleResourceEntity
);
}
}
log
.
info
(
"新增角色信息:"
+
JSONObject
.
toJSONString
(
roleInfo
));
return
Result
.
success
(
roleInfo
);
}
private
RoleResourceEntity
assembleRoleResource
(
String
roleId
,
String
resourceId
)
{
RoleResourceEntity
roleResourceEntity
=
new
RoleResourceEntity
();
roleResourceEntity
.
setRoleId
(
roleId
);
roleResourceEntity
.
setResourceId
(
resourceId
);
return
roleResourceEntity
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment