新增岗位关联角色,在特殊业务场景下使用该关系
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
* No deletion without permission, or be held responsible to law.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.dao;
|
||||||
|
|
||||||
|
import com.jeesite.common.dao.CrudDao;
|
||||||
|
import com.jeesite.common.mybatis.annotation.MyBatisDao;
|
||||||
|
import com.jeesite.modules.sys.entity.PostRole;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 岗位角色DAO接口
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2023-6-8
|
||||||
|
*/
|
||||||
|
@MyBatisDao
|
||||||
|
@ConditionalOnProperty(name="user.enabled", havingValue="true", matchIfMissing=true)
|
||||||
|
public interface PostRoleDao extends CrudDao<PostRole> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,7 +35,10 @@ public class Post extends DataEntity<Post> {
|
|||||||
private Integer postSort; // 岗位排序(升序)
|
private Integer postSort; // 岗位排序(升序)
|
||||||
|
|
||||||
private String empCode; // 根据用户查询岗位
|
private String empCode; // 根据用户查询岗位
|
||||||
|
|
||||||
|
private String roleCodes; // 关联的角色编号
|
||||||
|
private String roleNames; // 关联的角色名称
|
||||||
|
|
||||||
public Post() {
|
public Post() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
@@ -106,5 +109,20 @@ public class Post extends DataEntity<Post> {
|
|||||||
public void setEmpCode(String empCode) {
|
public void setEmpCode(String empCode) {
|
||||||
this.empCode = empCode;
|
this.empCode = empCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRoleCodes() {
|
||||||
|
return roleCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleCodes(String roleCodes) {
|
||||||
|
this.roleCodes = roleCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleNames() {
|
||||||
|
return roleNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleNames(String roleNames) {
|
||||||
|
this.roleNames = roleNames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||||
|
* No deletion without permission, or be held responsible to law.
|
||||||
|
*/
|
||||||
|
package com.jeesite.modules.sys.entity;
|
||||||
|
|
||||||
|
import com.jeesite.common.entity.DataEntity;
|
||||||
|
import com.jeesite.common.mybatis.annotation.Column;
|
||||||
|
import com.jeesite.common.mybatis.annotation.JoinTable;
|
||||||
|
import com.jeesite.common.mybatis.annotation.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 岗位角色Entity
|
||||||
|
* @author ThinkGem
|
||||||
|
* @version 2023-6-8
|
||||||
|
*/
|
||||||
|
@Table(name="${_prefix}sys_post_role", alias="a", columns={
|
||||||
|
@Column(name="role_code", attrName="roleCode", label="角色编码", isPK=true),
|
||||||
|
@Column(name="post_code", attrName="postCode", label="岗位编码", isPK=true),
|
||||||
|
},
|
||||||
|
joinTable = {
|
||||||
|
@JoinTable(type=JoinTable.Type.LEFT_JOIN, entity=Role.class, alias="r", lazy = true,
|
||||||
|
on="a.role_code = r.role_code", attrName="role",
|
||||||
|
columns={
|
||||||
|
@Column(name="role_code", attrName="roleCode", label="角色编码", isPK=true),
|
||||||
|
@Column(name="role_name", attrName="roleName", label="角色名称"),
|
||||||
|
})
|
||||||
|
}, orderBy=""
|
||||||
|
)
|
||||||
|
public class PostRole extends DataEntity<PostRole> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String postCode; // 岗位编码
|
||||||
|
private String roleCode; // 角色编码
|
||||||
|
|
||||||
|
private Role role; // sqlMap().loadJoinTableAlias("r")的时候返回数据
|
||||||
|
|
||||||
|
public PostRole() {
|
||||||
|
this(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostRole(String postCode, String roleCode){
|
||||||
|
this.postCode = postCode;
|
||||||
|
this.roleCode = roleCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostCode() {
|
||||||
|
return postCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostCode(String postCode) {
|
||||||
|
this.postCode = postCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleCode() {
|
||||||
|
return roleCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleCode(String roleCode) {
|
||||||
|
this.roleCode = roleCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Role getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(Role role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,9 @@ package com.jeesite.modules.sys.service;
|
|||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.service.api.CrudServiceApi;
|
import com.jeesite.common.service.api.CrudServiceApi;
|
||||||
import com.jeesite.modules.sys.entity.Post;
|
import com.jeesite.modules.sys.entity.Post;
|
||||||
|
import com.jeesite.modules.sys.entity.PostRole;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位管理Service
|
* 岗位管理Service
|
||||||
@@ -32,6 +35,11 @@ public interface PostService extends CrudServiceApi<Post> {
|
|||||||
@Override
|
@Override
|
||||||
Page<Post> findPage(Post post);
|
Page<Post> findPage(Post post);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询岗位角色列表
|
||||||
|
*/
|
||||||
|
List<PostRole> findPostRoleList(PostRole postRole);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存岗位
|
* 保存岗位
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,17 +4,22 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.service.support;
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.jeesite.common.collect.ListUtils;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.config.Global;
|
import com.jeesite.common.config.Global;
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
|
import com.jeesite.common.lang.StringUtils;
|
||||||
import com.jeesite.common.service.CrudService;
|
import com.jeesite.common.service.CrudService;
|
||||||
import com.jeesite.modules.sys.dao.PostDao;
|
import com.jeesite.modules.sys.dao.PostDao;
|
||||||
|
import com.jeesite.modules.sys.dao.PostRoleDao;
|
||||||
import com.jeesite.modules.sys.entity.Post;
|
import com.jeesite.modules.sys.entity.Post;
|
||||||
|
import com.jeesite.modules.sys.entity.PostRole;
|
||||||
import com.jeesite.modules.sys.entity.Role;
|
import com.jeesite.modules.sys.entity.Role;
|
||||||
import com.jeesite.modules.sys.service.PostService;
|
import com.jeesite.modules.sys.service.PostService;
|
||||||
import com.jeesite.modules.sys.utils.CorpUtils;
|
import com.jeesite.modules.sys.utils.CorpUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位管理Service
|
* 岗位管理Service
|
||||||
@@ -24,6 +29,9 @@ import com.jeesite.modules.sys.utils.CorpUtils;
|
|||||||
public class PostServiceSupport extends CrudService<PostDao, Post>
|
public class PostServiceSupport extends CrudService<PostDao, Post>
|
||||||
implements PostService{
|
implements PostService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PostRoleDao postRoleDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询岗位
|
* 查询岗位
|
||||||
*/
|
*/
|
||||||
@@ -50,6 +58,13 @@ public class PostServiceSupport extends CrudService<PostDao, Post>
|
|||||||
return super.findPage(post);
|
return super.findPage(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询岗位角色关系
|
||||||
|
*/
|
||||||
|
public List<PostRole> findPostRoleList(PostRole postRole) {
|
||||||
|
return postRoleDao.findList(postRole);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存岗位
|
* 保存岗位
|
||||||
*/
|
*/
|
||||||
@@ -61,6 +76,23 @@ public class PostServiceSupport extends CrudService<PostDao, Post>
|
|||||||
genIdAndValid(post, post.getViewCode());
|
genIdAndValid(post, post.getViewCode());
|
||||||
}
|
}
|
||||||
super.save(post);
|
super.save(post);
|
||||||
|
// 重新绑定岗位和角色之间的关系
|
||||||
|
if (StringUtils.isNotBlank(post.getPostCode()) && post.getRoleCodes() != null) {
|
||||||
|
PostRole where = new PostRole();
|
||||||
|
where.setPostCode(post.getPostCode());
|
||||||
|
postRoleDao.deleteByEntity(where);
|
||||||
|
List<PostRole> list = ListUtils.newArrayList();
|
||||||
|
for (String code : StringUtils.splitComma(post.getRoleCodes())) {
|
||||||
|
PostRole e = new PostRole();
|
||||||
|
e.setPostCode(post.getPostCode());
|
||||||
|
e.setRoleCode(code);
|
||||||
|
e.setIsNewRecord(true);
|
||||||
|
list.add(e);
|
||||||
|
}
|
||||||
|
if (ListUtils.isNotEmpty(list)) {
|
||||||
|
postRoleDao.insertBatch(list, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,12 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.web;
|
package com.jeesite.modules.sys.web;
|
||||||
|
|
||||||
import java.util.List;
|
import com.jeesite.common.collect.ListUtils;
|
||||||
import java.util.Map;
|
import com.jeesite.common.collect.MapUtils;
|
||||||
|
import com.jeesite.common.config.Global;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import com.jeesite.common.entity.Page;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import com.jeesite.common.lang.StringUtils;
|
||||||
|
import com.jeesite.common.web.BaseController;
|
||||||
|
import com.jeesite.modules.sys.entity.Post;
|
||||||
|
import com.jeesite.modules.sys.entity.PostRole;
|
||||||
|
import com.jeesite.modules.sys.service.PostService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -22,14 +25,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import com.jeesite.common.collect.ListUtils;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import com.jeesite.common.collect.MapUtils;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import com.jeesite.common.config.Global;
|
import java.util.List;
|
||||||
import com.jeesite.common.entity.Page;
|
import java.util.Map;
|
||||||
import com.jeesite.common.lang.StringUtils;
|
|
||||||
import com.jeesite.common.web.BaseController;
|
|
||||||
import com.jeesite.modules.sys.entity.Post;
|
|
||||||
import com.jeesite.modules.sys.service.PostService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位管理Controller
|
* 岗位管理Controller
|
||||||
@@ -44,25 +43,25 @@ public class PostController extends BaseController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostService postService;
|
private PostService postService;
|
||||||
|
|
||||||
@ModelAttribute
|
@ModelAttribute
|
||||||
public Post get(String postCode, boolean isNewRecord) {
|
public Post get(String postCode, boolean isNewRecord) {
|
||||||
return postService.get(postCode, isNewRecord);
|
return postService.get(postCode, isNewRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("sys:post:view")
|
@RequiresPermissions("sys:post:view")
|
||||||
@RequestMapping(value = "list")
|
@RequestMapping(value = "list")
|
||||||
public String list(Post post, Model model) {
|
public String list(Post post, Model model) {
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
return "modules/sys/postList";
|
return "modules/sys/postList";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("sys:post:view")
|
@RequiresPermissions("sys:post:view")
|
||||||
@RequestMapping(value = {"listData"})
|
@RequestMapping(value = {"listData"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Page<Post> listData(Post post, HttpServletRequest request, HttpServletResponse response) {
|
public Page<Post> listData(Post post, HttpServletRequest request, HttpServletResponse response) {
|
||||||
post.setPage(new Page<>(request, response));
|
post.setPage(new Page<>(request, response));
|
||||||
Page<Post> page = postService.findPage(post);
|
Page<Post> page = postService.findPage(post);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +71,22 @@ public class PostController extends BaseController {
|
|||||||
if(post.getIsNewRecord()){
|
if(post.getIsNewRecord()){
|
||||||
post.setPostSort((int)postService.findCount(post) * 10);
|
post.setPostSort((int)postService.findCount(post) * 10);
|
||||||
}
|
}
|
||||||
|
// 查询岗位所关联的角色信息
|
||||||
|
if (StringUtils.isNotBlank(post.getPostCode())){
|
||||||
|
PostRole where = new PostRole();
|
||||||
|
where.setPostCode(post.getPostCode());
|
||||||
|
where.sqlMap().loadJoinTableAlias("r");
|
||||||
|
List<String> roleCodes = ListUtils.newArrayList();
|
||||||
|
List<String> roleNames = ListUtils.newArrayList();
|
||||||
|
postService.findPostRoleList(where).forEach(e -> {
|
||||||
|
if (e.getRole() != null) {
|
||||||
|
roleCodes.add(e.getRoleCode());
|
||||||
|
roleNames.add(e.getRole().getRoleName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
model.addAttribute("roleCodes", StringUtils.joinComma(roleCodes));
|
||||||
|
model.addAttribute("roleNames", StringUtils.joinComma(roleNames));
|
||||||
|
}
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
return "modules/sys/postForm";
|
return "modules/sys/postForm";
|
||||||
}
|
}
|
||||||
@@ -86,7 +101,7 @@ public class PostController extends BaseController {
|
|||||||
postService.save(post);
|
postService.save(post);
|
||||||
return renderResult(Global.TRUE, text("保存岗位''{0}''成功", post.getPostName()));
|
return renderResult(Global.TRUE, text("保存岗位''{0}''成功", post.getPostName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("sys:post:edit")
|
@RequiresPermissions("sys:post:edit")
|
||||||
@RequestMapping(value = "disable")
|
@RequestMapping(value = "disable")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@@ -95,7 +110,7 @@ public class PostController extends BaseController {
|
|||||||
postService.updateStatus(post);
|
postService.updateStatus(post);
|
||||||
return renderResult(Global.TRUE, text("停用岗位''{0}''成功", post.getPostName()));
|
return renderResult(Global.TRUE, text("停用岗位''{0}''成功", post.getPostName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("sys:post:edit")
|
@RequiresPermissions("sys:post:edit")
|
||||||
@RequestMapping(value = "enable")
|
@RequestMapping(value = "enable")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@@ -104,7 +119,7 @@ public class PostController extends BaseController {
|
|||||||
postService.updateStatus(post);
|
postService.updateStatus(post);
|
||||||
return renderResult(Global.TRUE, text("启用岗位''{0}''成功", post.getPostName()));
|
return renderResult(Global.TRUE, text("启用岗位''{0}''成功", post.getPostName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("sys:post:edit")
|
@RequiresPermissions("sys:post:edit")
|
||||||
@RequestMapping(value = "delete")
|
@RequestMapping(value = "delete")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@@ -112,11 +127,11 @@ public class PostController extends BaseController {
|
|||||||
postService.delete(post);
|
postService.delete(post);
|
||||||
return renderResult(Global.TRUE, text("删除岗位''{0}''成功", post.getPostName()));
|
return renderResult(Global.TRUE, text("删除岗位''{0}''成功", post.getPostName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证岗位名是否有效
|
* 验证岗位名是否有效
|
||||||
* @param oldPostName
|
* @param oldPostName
|
||||||
* @param name
|
* @param postName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("user")
|
@RequiresPermissions("user")
|
||||||
@@ -135,7 +150,7 @@ public class PostController extends BaseController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取岗位树结构数据
|
* 获取岗位树结构数据
|
||||||
* @param isShowCode 是否显示编码(true or 1:显示在左侧;2:显示在右侧;false or null:不显示)
|
* @param isShowCode 是否显示编码(true or 1:显示在左侧;2:显示在右侧;false or null:不显示)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("user")
|
@RequiresPermissions("user")
|
||||||
@@ -156,5 +171,5 @@ public class PostController extends BaseController {
|
|||||||
});
|
});
|
||||||
return mapList;
|
return mapList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="control-label col-sm-2" title="">
|
||||||
|
<span class="required hide">*</span> ${text('关联角色')}:<i class="fa icon-question hide"></i></label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<#form:treeselect id="postRole" title="${text('角色选择')}"
|
||||||
|
name="roleCodes" value="${roleCodes!}"
|
||||||
|
labelName="roleNames" labelValue="${roleNames!}"
|
||||||
|
url="${ctx}/sys/role/treeData?userType=__all" checkbox="true"
|
||||||
|
class="" allowClear="true"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
Reference in New Issue
Block a user