岗位管理

This commit is contained in:
赵肖云
2021-06-24 10:43:53 +08:00
parent 7aeb6b099a
commit b0751be63a
18 changed files with 501 additions and 16 deletions
@@ -3,16 +3,15 @@ package com.adc.da.slrs.sarRole.controller;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.login.util.UserUtils;
import com.adc.da.slrs.sarRole.service.ITsRoleService;
import com.adc.da.sys.entity.UserEO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import com.adc.da.slrs.sarRole.entity.TsRole;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.adc.da.base.web.BaseController;
import java.util.List;
@@ -48,7 +47,19 @@ public class TsRoleController extends BaseController<TsRole> {
@ApiOperation("新增角色")
@PostMapping
public ResponseMessage<List<TsRole>> addRole(@Validated(TsRole.insert.class) TsRole tsRole){
return null;
public ResponseMessage<Object> addRole(@Validated(TsRole.insert.class) TsRole tsRole){
//设置操作人
UserEO userEO=UserUtils.getUser();
tsRole.setOperator(userEO.getUname());
return tsRoleService.addRole(tsRole);
}
@ApiOperation("编辑角色")
@PutMapping
public ResponseMessage<Object> updateRole(@Validated(TsRole.update.class) TsRole tsRole){
//设置操作人
UserEO userEO=UserUtils.getUser();
tsRole.setOperator(userEO.getUname());
return tsRoleService.updateRole(tsRole);
}
}
@@ -2,6 +2,8 @@ package com.adc.da.slrs.sarRole.entity;
import com.adc.da.base.entity.BaseEntity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.sql.Timestamp;
@@ -35,11 +37,14 @@ import javax.validation.constraints.NotNull;
public class TsRole extends BaseEntity {
public interface insert{
}
public interface update{
}
private static final long serialVersionUID = 1L;
@NotNull(message = "id不能为空",groups = {update.class})
@ApiModelProperty(value = "主键")
@TableId("ID")
@TableId(value = "ID",type = IdType.UUID)
private String id;
@NotNull(message = "name不能为空",groups = {insert.class})
@@ -99,8 +104,8 @@ public class TsRole extends BaseEntity {
private String parentId;
@ApiModelProperty(value = "角色层级")
@TableField("role_level")
private Integer roleLevel;
@TableField("ROLE_HIERARCHY")
private Integer roleHierarchy;
@ApiModelProperty(value = "对应部门id")
@TableField("DY_ORG_ID")
@@ -1,5 +1,6 @@
package com.adc.da.slrs.sarRole.service;
import com.adc.da.http.ResponseMessage;
import com.adc.da.slrs.sarRole.entity.TsRole;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -27,4 +28,18 @@ public interface ITsRoleService extends IService<TsRole> {
* @return List<TsRole>
*/
List<TsRole> getByName(String name);
/**
* 添加角色
* @param tsRole :角色信息
* @return ResponseMessage<Object>
*/
ResponseMessage<Object> addRole(TsRole tsRole);
/**
* 编辑角色
* @param tsRole:角色信息
* @return ResponseMessage<Object>
*/
ResponseMessage<Object> updateRole(TsRole tsRole);
}
@@ -1,5 +1,7 @@
package com.adc.da.slrs.sarRole.service.impl;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.sarRole.entity.TsRole;
import com.adc.da.slrs.sarRole.dao.TsRoleDao;
import com.adc.da.slrs.sarRole.service.ITsRoleService;
@@ -30,7 +32,7 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
@Override
public List<TsRole> getAll() {
QueryWrapper<TsRole> tsRoleQueryWrapper=new QueryWrapper<>();
tsRoleQueryWrapper.eq("role_level",1);
tsRoleQueryWrapper.eq("ROLE_HIERARCHY",1);
List<TsRole> rootRole=tsRoleDao.selectList(tsRoleQueryWrapper);
for(TsRole tsRole:rootRole){
tsRole.setChildren(recursionGetRole(tsRole));
@@ -46,7 +48,7 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
private List<TsRole> recursionGetRole(TsRole tsRole){
QueryWrapper<TsRole> tsRoleQueryWrapper=new QueryWrapper<>();
tsRoleQueryWrapper.eq("parent_id",tsRole.getId());
tsRoleQueryWrapper.eq("role_level",tsRole.getRoleLevel()+1);
tsRoleQueryWrapper.eq("ROLE_HIERARCHY",tsRole.getRoleHierarchy()+1);
List<TsRole> tsRoles=tsRoleDao.selectList(tsRoleQueryWrapper);
for(TsRole tsRoleNode:tsRoles){
tsRoleNode.setChildren(recursionGetRole(tsRoleNode));
@@ -66,5 +68,46 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
return tsRoleDao.selectList(tsRoleQueryWrapper);
}
/**
* 添加角色
* @param tsRole :角色信息
* @return TsRole
*/
@Override
public ResponseMessage<Object> addRole(TsRole tsRole) {
//判断是否是顶级角色
if(tsRole.getParentId()==null){
tsRole.setRoleHierarchy(1);
}else {
QueryWrapper<TsRole> parentQueryWrapper=new QueryWrapper<>();
parentQueryWrapper.eq("id",tsRole.getParentId());
TsRole parentRole=tsRoleDao.selectOne(parentQueryWrapper);
if(parentRole==null){
return Result.error("父角色不存在");
}
tsRole.setRoleHierarchy(parentRole.getRoleHierarchy()+1);
}
tsRoleDao.insert(tsRole);
return Result.success();
}
/**
* 编辑角色
* @param tsRole:角色信息
* @return ResponseMessage<Object>
*/
@Override
public ResponseMessage<Object> updateRole(TsRole tsRole) {
TsRole oldRole=tsRoleDao.selectById(tsRole.getParentId());
if(oldRole==null){
return Result.error("该角色不存在");
}
//不允许修改父节点
tsRole.setRoleHierarchy(null);
tsRole.setParentId(null);
tsRoleDao.updateById(tsRole);
return Result.success();
}
}