|
|
@@ -23,9 +23,11 @@ import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.util.PmsUtil;
|
|
|
import org.jeecg.common.util.TokenUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.modules.system.entity.*;
|
|
|
import org.jeecg.modules.system.model.TreeModel;
|
|
|
import org.jeecg.modules.system.service.*;
|
|
|
+import org.jeecg.modules.system.vo.RolePermissionVO;
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
@@ -68,19 +70,22 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
public class SysRoleController {
|
|
|
@Autowired
|
|
|
private ISysRoleService sysRoleService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysPermissionDataRuleService sysPermissionDataRuleService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysRolePermissionService sysRolePermissionService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysPermissionService sysPermissionService;
|
|
|
|
|
|
@Autowired
|
|
|
private ISysUserRoleService sysUserRoleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseCommonService baseCommonService;
|
|
|
+
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
* @param role
|
|
|
@@ -111,7 +116,93 @@ public class SysRoleController {
|
|
|
result.setResult(pageList);
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @param rolePermissionVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/saveRoleAndPermission", method = RequestMethod.POST)
|
|
|
+ //@RequiresRoles({"admin"})
|
|
|
+ public Result<SysRole> saveRoleAndPermission(@RequestBody RolePermissionVO rolePermissionVO) {
|
|
|
+ Result<SysRole> result = new Result<SysRole>();
|
|
|
+ if(rolePermissionVO==null) {
|
|
|
+ result.error500("参数错误");
|
|
|
+ }
|
|
|
+ SysRole role = rolePermissionVO.getRole();
|
|
|
+ JSONObject json = rolePermissionVO.getPermissionJson();
|
|
|
+ try {
|
|
|
+ role.setCreateTime(new Date());
|
|
|
+ // 如果当前登录人是租户,添加的角色应该有租户id
|
|
|
+ String userTenant = TokenUtils.currentTenantId();
|
|
|
+ if(userTenant != null && !userTenant.isEmpty()){
|
|
|
+ role.setTenantId(Integer.parseInt(userTenant));
|
|
|
+ }
|
|
|
+ sysRoleService.save(role);
|
|
|
+
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String roleId = role.getId();
|
|
|
+ String permissionIds = json.getString("permissionIds");
|
|
|
+ String lastPermissionIds = json.getString("lastpermissionIds");
|
|
|
+ this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
|
|
|
+ //update-begin---author:wangshuai ---date:20220316 for:[VUEN-234]用户管理角色授权添加敏感日志------------
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ baseCommonService.addLog("修改角色ID: "+roleId+" 的权限配置,操作人: " +loginUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
|
|
+ //update-end---author:wangshuai ---date:20220316 for:[VUEN-234]用户管理角色授权添加敏感日志------------
|
|
|
+ log.info("======角色授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
+
|
|
|
+ result.success("添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ * @param rolePermissionVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@RequiresRoles({"admin"})
|
|
|
+ @RequestMapping(value = "/editRoleAndPermission",method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ public Result<SysRole> editRoleAndPermission(@RequestBody RolePermissionVO rolePermissionVO) {
|
|
|
+ Result<SysRole> result = new Result<SysRole>();
|
|
|
+ if(rolePermissionVO==null) {
|
|
|
+ result.error500("参数错误");
|
|
|
+ }
|
|
|
+ SysRole role = rolePermissionVO.getRole();
|
|
|
+ JSONObject json = rolePermissionVO.getPermissionJson();
|
|
|
+ SysRole sysrole = sysRoleService.getById(role.getId());
|
|
|
+ if(sysrole==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ role.setUpdateTime(new Date());
|
|
|
+ // 编辑是默认给编辑的内容当前角色的租户
|
|
|
+ if(sysrole.getTenantId() != null) {
|
|
|
+ role.setTenantId(sysrole.getTenantId());
|
|
|
+ }
|
|
|
+ boolean ok = sysRoleService.updateById(role);
|
|
|
+ //TODO 返回false说明什么? qh:说明脑子有病毒,得清理一下
|
|
|
+ if(ok) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String roleId = role.getId();
|
|
|
+ String permissionIds = json.getString("permissionIds");
|
|
|
+ String lastPermissionIds = json.getString("lastpermissionIds");
|
|
|
+ this.sysRolePermissionService.saveRolePermission(roleId, permissionIds, lastPermissionIds);
|
|
|
+ //update-begin---author:wangshuai ---date:20220316 for:[VUEN-234]用户管理角色授权添加敏感日志------------
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ baseCommonService.addLog("修改角色ID: "+roleId+" 的权限配置,操作人: " +loginUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
|
|
+ //update-end---author:wangshuai ---date:20220316 for:[VUEN-234]用户管理角色授权添加敏感日志------------
|
|
|
+ log.info("======角色授权成功=====耗时:" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
+
|
|
|
+ result.success("修改成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
* @param role
|
|
|
@@ -136,7 +227,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 编辑
|
|
|
* @param role
|
|
|
@@ -161,10 +252,10 @@ public class SysRoleController {
|
|
|
result.success("修改成功!");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 通过id删除
|
|
|
* @param id
|
|
|
@@ -176,7 +267,7 @@ public class SysRoleController {
|
|
|
sysRoleService.deleteRole(id);
|
|
|
return Result.ok("删除角色成功");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 批量删除
|
|
|
* @param ids
|
|
|
@@ -194,7 +285,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 通过id查询
|
|
|
* @param id
|
|
|
@@ -212,7 +303,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@RequestMapping(value = "/queryall", method = RequestMethod.GET)
|
|
|
public Result<List<SysRole>> queryall() {
|
|
|
Result<List<SysRole>> result = new Result<>();
|
|
|
@@ -225,7 +316,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 校验角色编码唯一
|
|
|
*/
|
|
|
@@ -317,7 +408,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return Result.error("文件导入失败!");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查询数据规则数据
|
|
|
*/
|
|
|
@@ -346,7 +437,7 @@ public class SysRoleController {
|
|
|
//TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 保存数据规则至角色菜单关联表
|
|
|
*/
|
|
|
@@ -373,8 +464,8 @@ public class SysRoleController {
|
|
|
}
|
|
|
return Result.ok("保存成功!");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 用户角色授权功能,查询菜单权限树
|
|
|
* @param request
|
|
|
@@ -420,7 +511,7 @@ public class SysRoleController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void getTreeModelList(List<TreeModel> treeList,List<SysPermission> metaList,TreeModel temp) {
|
|
|
for (SysPermission permission : metaList) {
|
|
|
String tempPid = permission.getParentId();
|
|
|
@@ -436,9 +527,9 @@ public class SysRoleController {
|
|
|
getTreeModelList(treeList, metaList, tree);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|