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 962a0ba5
authored
Oct 08, 2023
by
huangjinxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:重写角色
1 parent
1c3c9d10
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
226 additions
and
226 deletions
project-interface/src/main/java/com/dituhui/pea/user/IRole2.java
project-user/src/main/java/com/dituhui/pea/user/controller2/RoleController2.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/RoleService2.java
project-interface/src/main/java/com/dituhui/pea/user/IRole2.java
View file @
962a0ba
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
=
"role2"
)
public
interface
IRole2
{
/**
* 添加角色
*
* @param roleInfo 角色信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/role/add2"
,
method
=
RequestMethod
.
POST
)
Result
<
RoleInfo
>
addRole
(
@RequestBody
RoleInfo
roleInfo
);
}
//
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 = "role2")
//
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/controller2/RoleController2.java
View file @
962a0ba
package
com
.
dituhui
.
pea
.
user
.
controller2
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.pojo.PageRequest
;
import
com.dituhui.pea.pojo.ResourceInfo
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.WebResult
;
import
com.dituhui.pea.user.IRole
;
import
com.dituhui.pea.user.IRole2
;
import
com.dituhui.pea.user.service.RoleService
;
import
com.dituhui.pea.user.service.RoleService2
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* 角色控制层
*/
@RestController
@RefreshScope
public
class
RoleController2
implements
IRole2
{
@Autowired
RoleService2
roleService
;
/**
* 添加角色
*
* @param roleInfo 角色信息
* @return
*/
@RequestMapping
(
value
=
"/pea-user/role/add2"
,
method
=
RequestMethod
.
POST
)
public
Result
<
RoleInfo
>
addRole
(
@RequestBody
RoleInfo
roleInfo
)
{
return
roleService
.
addRole
(
roleInfo
);
}
}
//
package com.dituhui.pea.user.controller2;
//
//
import com.dituhui.pea.common.PageResult;
//
import com.dituhui.pea.common.Result;
//
import com.dituhui.pea.enums.StatusCodeEnum;
//
import com.dituhui.pea.pojo.PageRequest;
//
import com.dituhui.pea.pojo.ResourceInfo;
//
import com.dituhui.pea.pojo.RoleInfo;
//
import com.dituhui.pea.pojo.WebResult;
//
import com.dituhui.pea.user.IRole;
//
import com.dituhui.pea.user.IRole2;
//
import com.dituhui.pea.user.service.RoleService;
//
import com.dituhui.pea.user.service.RoleService2;
//
import org.apache.commons.lang.StringUtils;
//
import org.springframework.beans.factory.annotation.Autowired;
//
import org.springframework.cloud.context.config.annotation.RefreshScope;
//
import org.springframework.validation.annotation.Validated;
//
import org.springframework.web.bind.annotation.RequestBody;
//
import org.springframework.web.bind.annotation.RequestMapping;
//
import org.springframework.web.bind.annotation.RequestMethod;
//
import org.springframework.web.bind.annotation.RestController;
//
//
import java.util.List;
//
/
/ /
**
//
* 角色控制层
//
*/
//
@RestController
//
@RefreshScope
//
public class RoleController2 implements IRole2 {
//
//
//
@Autowired
//
RoleService2 roleService;
//
//
/**
//
* 添加角色
//
*
//
* @param roleInfo 角色信息
//
* @return
//
*/
//
@RequestMapping(value = "/pea-user/role/add2", method = RequestMethod.POST)
//
public Result<RoleInfo> addRole(@RequestBody RoleInfo roleInfo) {
//
return roleService.addRole(roleInfo);
//
}
//
//
}
project-user/src/main/java/com/dituhui/pea/user/dao/RoleDao2.java
View file @
962a0ba
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
>
{
}
//
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 @
962a0ba
...
...
@@ -44,7 +44,7 @@ public class RoleEntity implements Serializable {
* 角色自定义条件
*/
@Column
(
name
=
"extra"
)
@NotBlank
(
message
=
"角色自定义条件不能为空!"
)
//
@NotBlank(message = "角色自定义条件不能为空!")
private
String
extra
;
/**
* 创建人
...
...
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity2.java
View file @
962a0ba
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
;
}
//
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/RoleService2.java
View file @
962a0ba
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
;
}
}
//
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