Commit 212985ff authored by hongguangwu's avatar hongguangwu

1.5.8-hgw-权限-角色-账号

parent c462d75e
...@@ -86,6 +86,7 @@ public class SysMenu extends BaseEntity { ...@@ -86,6 +86,7 @@ public class SysMenu extends BaseEntity {
/** /**
* 客户权限id * 客户权限id
* 1客户权限;2商机;3报价单;4合同;5项目;6BU;7条线;8部门;9收入归属
*/ */
@Schema(description = "客户权限id") @Schema(description = "客户权限id")
private String customerId; private String customerId;
......
...@@ -150,13 +150,13 @@ public class SysUserInfoController { ...@@ -150,13 +150,13 @@ public class SysUserInfoController {
@Operation(summary = "测试权限sql", description = "测试权限sql") @Operation(summary = "测试权限sql", description = "测试权限sql")
@SysLog("测试权限sql") @SysLog("测试权限sql")
@PostMapping("/testPermission") @PostMapping("/testPermission")
public R<String> testPermission(@RequestParam String menuId, @RequestParam(required = false) String userId) { public R<String> testPermission(@RequestParam String modelId, @RequestParam(required = false) String userId) {
return R.ok(sysUserInfoService.testPermission(menuId, userId)); return R.ok(sysUserInfoService.testPermission(modelId, userId));
} }
/** /**
* 简单分页查询 * 简单分页查询
* * hyc 2023-9-11 15:25:50
* @param page 分页对象 * @param page 分页对象
* @param code 新权限-账号管理表 * @param code 新权限-账号管理表
* @return * @return
......
...@@ -41,4 +41,13 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> { ...@@ -41,4 +41,13 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
* @return * @return
*/ */
List<String> selectColumnList(@Param("modelId") String modelId); List<String> selectColumnList(@Param("modelId") String modelId);
/**
* @param modelId
* @Description: 根据modelId获取菜单
* @Author: hgw
* @Date: 2023/9/11 11:48
* @return: com.yifu.cloud.plus.v1.yifu.permission.entity.SysMenu
**/
SysMenu getSysMenuByModelId(@Param("modelId") String modelId);
} }
...@@ -60,7 +60,7 @@ public interface SysUserInfoMapper extends BaseMapper<SysUserInfo> { ...@@ -60,7 +60,7 @@ public interface SysUserInfoMapper extends BaseMapper<SysUserInfo> {
* @Date: 2023/9/8 17:00 * @Date: 2023/9/8 17:00
* @return: java.lang.int * @return: java.lang.int
**/ **/
int getAuthByUserIdAndMenuId(@Param("menuId") String menuId, @Param("userId") String userId); int getAuthByUserIdAndModelId(@Param("modelId") String modelId, @Param("userId") String userId);
/** /**
* @Description: 根据编码或者登录名简单分页查询 * @Description: 根据编码或者登录名简单分页查询
......
...@@ -172,5 +172,15 @@ public interface SysUserPermissionMapper extends BaseMapper<SysUserPermission> { ...@@ -172,5 +172,15 @@ public interface SysUserPermissionMapper extends BaseMapper<SysUserPermission> {
* @return * @return
*/ */
Integer selectDeptCount(@Param("name") String name); Integer selectDeptCount(@Param("name") String name);
/**
* @param userId
* @Description: 查找当前用户的所有权限
* @Author: hgw
* @Date: 2023/9/11 11:44
* @return: java.util.List<com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserPermission>
**/
List<SysUserPermission> getUserPermissionByUserId(@Param("userId") String userId);
} }
...@@ -75,7 +75,7 @@ public interface SysUserInfoService extends IService<SysUserInfo> { ...@@ -75,7 +75,7 @@ public interface SysUserInfoService extends IService<SysUserInfo> {
* @Date: 2023/9/8 16:35 * @Date: 2023/9/8 16:35
* @return: java.lang.String * @return: java.lang.String
**/ **/
String testPermission(String menuId, String userId); String testPermission(String modelId, String userId);
IPage<SysUserInfo> getUserByCodeOrLoginName(Page<SysUserInfo> page, String code); IPage<SysUserInfo> getUserByCodeOrLoginName(Page<SysUserInfo> page, String code);
......
...@@ -21,7 +21,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -21,7 +21,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.permission.mapper.SysMenuMapper;
import com.yifu.cloud.plus.v1.permission.mapper.SysUserInfoMapper; import com.yifu.cloud.plus.v1.permission.mapper.SysUserInfoMapper;
import com.yifu.cloud.plus.v1.permission.mapper.SysUserPermissionMapper;
import com.yifu.cloud.plus.v1.permission.service.SysMenuService; import com.yifu.cloud.plus.v1.permission.service.SysMenuService;
import com.yifu.cloud.plus.v1.permission.service.SysRoleInfoService; import com.yifu.cloud.plus.v1.permission.service.SysRoleInfoService;
import com.yifu.cloud.plus.v1.permission.service.SysUserInfoService; import com.yifu.cloud.plus.v1.permission.service.SysUserInfoService;
...@@ -31,6 +33,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.R; ...@@ -31,6 +33,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity; import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import com.yifu.cloud.plus.v1.yifu.permission.entity.SysMenu; import com.yifu.cloud.plus.v1.yifu.permission.entity.SysMenu;
import com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserInfo; import com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserInfo;
import com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserPermission;
import com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserRoleRes; import com.yifu.cloud.plus.v1.yifu.permission.entity.SysUserRoleRes;
import com.yifu.cloud.plus.v1.yifu.permission.vo.SysUserInfoSaveVo; import com.yifu.cloud.plus.v1.yifu.permission.vo.SysUserInfoSaveVo;
import com.yifu.cloud.plus.v1.yifu.permission.vo.SysUserInfoSearchVo; import com.yifu.cloud.plus.v1.yifu.permission.vo.SysUserInfoSearchVo;
...@@ -53,6 +56,8 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs ...@@ -53,6 +56,8 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
private final SysUserRoleResService sysUserRoleResService; private final SysUserRoleResService sysUserRoleResService;
private final SysRoleInfoService sysRoleInfoService; private final SysRoleInfoService sysRoleInfoService;
private final SysMenuMapper sysMenuMapper;
private final SysUserPermissionMapper sysUserPermissionMapper;
/** /**
* 新权限-账号管理表简单分页查询 * 新权限-账号管理表简单分页查询
...@@ -173,7 +178,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs ...@@ -173,7 +178,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
private final SysMenuService sysMenuService; private final SysMenuService sysMenuService;
/** /**
* @param menuId * @param modelId
* @param userId * @param userId
* @Description: 给EKP用的,获取权限 * @Description: 给EKP用的,获取权限
* @Author: hgw * @Author: hgw
...@@ -181,7 +186,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs ...@@ -181,7 +186,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
* @return: void * @return: void
**/ **/
@Override @Override
public String testPermission(String menuId, String userId) { public String testPermission(String modelId, String userId) {
//1:获取菜单是否已配置,是:第2步;否:结束,用EKP本身权限; //1:获取菜单是否已配置,是:第2步;否:结束,用EKP本身权限;
//2:获取账号,有:第3步;无:结束,用EKP; //2:获取账号,有:第3步;无:结束,用EKP;
//3:检测账号的角色 是否有 对应的菜单,有,第4不,无:结束,用ekp; //3:检测账号的角色 是否有 对应的菜单,有,第4不,无:结束,用ekp;
...@@ -197,30 +202,69 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs ...@@ -197,30 +202,69 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
//第6步的sql要改为: //第6步的sql要改为:
//or (docCreateUser in (账号id,其他账号id)) //or (docCreateUser in (账号id,其他账号id))
String sql = ""; StringBuilder sql = new StringBuilder();
// 测试权限 // 测试权限
SysMenu menu = sysMenuService.getById(menuId); SysMenu menu = sysMenuMapper.getSysMenuByModelId(modelId);
if (menu != null) { if (menu != null) {
// 返回0:无配置;1:全量;2:继续下一步,找数据权限配置 // 返回0:无配置;1:全量;2:继续下一步,找数据权限配置
int allAuth = baseMapper.getAuthByUserIdAndMenuId(menuId, userId); int allAuth = baseMapper.getAuthByUserIdAndModelId(modelId, userId);
if (allAuth == 0) { if (allAuth == 0) {
sql = " 1=2 "; sql.append(" 1=2 ");
} else if (allAuth == 1) { } else if (allAuth == 1) {
sql = " 1=1 "; sql.append(" 1=1 ");
} else { } else {
// TODO-继续下一步,找数据权限配置 sql.append(" 1=2 ");
// 继续下一步,找数据权限配置
List<SysUserPermission> permissionList = sysUserPermissionMapper.getUserPermissionByUserId(userId);
if (permissionList != null && !permissionList.isEmpty() && Common.isNotNull(menu.getCustomerId())) {
setAuthSql(sql, "1", menu.getCustomerId(), permissionList);
setAuthSql(sql, "2", menu.getBussinessId(), permissionList);
setAuthSql(sql, "3", menu.getQuotationId(), permissionList);
setAuthSql(sql, "4", menu.getContractId(), permissionList);
setAuthSql(sql, "5", menu.getDomainId(), permissionList);
setAuthSql(sql, "6", menu.getBuId(), permissionList);
setAuthSql(sql, "7", menu.getLineId(), permissionList);
setAuthSql(sql, "9", menu.getIncomeId(), permissionList);
// TODO-部门
setAuthSqlByDept(sql, menu.getDeptId(), permissionList);
}
} }
} }
if (Common.isNotNull(sql)) { if (Common.isNotNull(sql)) {
return " or (" + sql + " ) "; return " or ( " + sql + " ) ";
} }
return ""; return "";
} }
private void setAuthSql(StringBuilder sql, String type, String shuXing, List<SysUserPermission> permissionList) {
StringBuilder tempValue = new StringBuilder();
for (SysUserPermission permission : permissionList) {
if (("6".equals(type) || "7".equals(type)) && type.equals(permission.getPermissionType())) {
tempValue.append("'").append(permission.getName()).append("',");
} else if (type.equals(permission.getPermissionType())) {
tempValue.append("'").append(permission.getCode()).append("',");
}
}
if (tempValue.length() > 0) {
tempValue.deleteCharAt(tempValue.length() - 1);
}
sql.append(" or (").append(shuXing).append(" in (").append(tempValue).append("))");
}
private void setAuthSqlByDept(StringBuilder sql, String shuXing, List<SysUserPermission> permissionList) {
StringBuilder tempValue = new StringBuilder();
for (SysUserPermission permission : permissionList) {
if ("8".equals(permission.getPermissionType())) {
tempValue.append("'").append(permission.getCode()).append("',");
}
}
if (tempValue.length() > 0) {
tempValue.deleteCharAt(tempValue.length() - 1);
}
sql.append(" or (").append(shuXing).append(" in (").append(tempValue).append("))");
}
/** /**
* 新权限-账号管理表简单分页查询 * 新权限-账号管理表简单分页查询
......
...@@ -90,4 +90,14 @@ ...@@ -90,4 +90,14 @@
LEFT JOIN sys_xform_db_table b on a.fd_main_id = b.fd_id LEFT JOIN sys_xform_db_table b on a.fd_main_id = b.fd_id
WHERE b.fd_model_id = #{modelId} WHERE b.fd_model_id = #{modelId}
</select> </select>
<!--根据modelId获取菜单-->
<select id="getSysMenuByModelId" resultMap="sysMenuMap">
SELECT
<include refid="Base_Column_List"/>
FROM sys_menu a
where a.DELETE_STATUS = '1' and a.PERMISSION_STATUS='0' and a.MODEL_ID = {modelId}
limit 1
</select>
</mapper> </mapper>
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
<!--给EKP用的,获取列表是否全量的权限--> <!--给EKP用的,获取列表是否全量的权限-->
<!--#全量0;部分全量1;数据权限2;客户a;商机b;报价单c;合同d;项目e;BUf;条线g;收入归属h;)--> <!--#全量0;部分全量1;数据权限2;客户a;商机b;报价单c;合同d;项目e;BUf;条线g;收入归属h;)-->
<select id="getAuthByUserIdAndMenuId" resultType="java.lang.Integer"> <select id="getAuthByUserIdAndModelId" resultType="java.lang.Integer">
select select
case case
when a.data_auth is null then 0 when a.data_auth is null then 0
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
join sys_role_info a on m.role_id = a.fd_id join sys_role_info a on m.role_id = a.fd_id
join sys_user_role_res r on r.role_id = a.fd_id join sys_user_role_res r on r.role_id = a.fd_id
where a.delete_flag = 0 and a.status = 0 and b.DELETE_STATUS='1' and b.PERMISSION_STATUS='0' where a.delete_flag = 0 and a.status = 0 and b.DELETE_STATUS='1' and b.PERMISSION_STATUS='0'
and r.user_id = #{userId} and b.MODEL_ID=#{menuId} and r.user_id = #{userId} and b.MODEL_ID=#{modelId}
) a ) a
</select> </select>
......
...@@ -270,4 +270,15 @@ ...@@ -270,4 +270,15 @@
where a.fd_is_available = '1' and fd_org_type = 2 and a.fd_no = #{name} where a.fd_is_available = '1' and fd_org_type = 2 and a.fd_no = #{name}
</select> </select>
<!-- 查找当前用户的所有权限 -->
<select id="getUserPermissionByUserId" resultMap="sysUserPermissionMap">
select
p.PERMISSION_TYPE,p.NAME,p.CODE,ifnull(p.IS_CONTAINS,'1') IS_CONTAINS
from
sys_user_permission p
where p.DELETE_FLAG='1' and p.PERMISSION_STATUS='0'
and p.USER_ID = #{userId}
ORDER BY p.PERMISSION_TYPE
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment