Commit 9641f9f0 authored by hongguangwu's avatar hongguangwu

数据权限2

parent 577c1cb3
......@@ -70,12 +70,8 @@ public class TEmployeeInfoController {
private final TEmployeeInfoService tEmployeeInfoService;
// 缓存信息
private final CacheManager cacheManager;
private final MenuUtil menuUtil;
private final DaprUpmsProperties daprUpmsProperties;
/**
* 分页查询
*
......@@ -94,7 +90,10 @@ public class TEmployeeInfoController {
tEmployeeInfo.setMId("1536922631616278529");
}
menuUtil.setAuthSql(user, tEmployeeInfo);
return R.ok(tEmployeeInfoService.getPage(page, tEmployeeInfo, null));
if (Common.isNotNull(tEmployeeInfo.getAuthSql()) && tEmployeeInfo.getAuthSql().contains(CommonConstants.A_DEPT_ID)) {
tEmployeeInfo.setAuthSql(tEmployeeInfo.getAuthSql().replace(CommonConstants.A_DEPT_ID, "b.id"));
}
return R.ok(tEmployeeInfoService.getPage(page, tEmployeeInfo));
}
/**
......@@ -111,67 +110,14 @@ public class TEmployeeInfoController {
if (user == null || Common.isEmpty(user.getId())) {
return R.failed(CommonConstants.PLEASE_LOG_IN);
}
// 普通用户:
if (CommonConstants.ONE_STRING.equals(user.getSystemFlag())) {
// 菜单id
String menuId = "1536952884128591873";
String linkId = user.getId();
int linkType = 1; // 用户
SysDataAuth sysDataAuth = new SysDataAuth();
sysDataAuth.setLinkId(linkId);
sysDataAuth.setLinkType(linkType);
// 获取缓存菜单权限的步骤:
Cache cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType);
Object obj = null;
if (cache != null) {
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (Common.isEmpty(obj)) {
HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId()
, "/dataAuth/refreshAuth", sysDataAuth, TEmployeeInfo.class, SecurityConstants.FROM_IN);
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (Common.isEmpty(obj)) {
linkId = user.getUserGroup();
linkType = 0; // 用户组
cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + linkType);
if (cache != null) {
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
if (Common.isEmpty(obj)) {
sysDataAuth.setLinkId(linkId);
sysDataAuth.setLinkType(linkType);
HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(), daprUpmsProperties.getAppId()
, "/dataAuth/refreshAuth", sysDataAuth, TEmployeeInfo.class, SecurityConstants.FROM_IN);
obj = cache.get(linkId + CommonConstants.DOWN_LINE_STRING + menuId);
}
}
}
}
}
if (Common.isNotNull(obj)) {
SimpleValueWrapper objs = (SimpleValueWrapper) obj;
if (objs != null) {
String sql = String.valueOf(objs.get());
if (sql.contains("#deptId")) {
// TODO - 需要关联部门表
}
if (sql.contains("#create_by")) {
sql = sql.replace("#create_by", user.getId());
}
if (sql.contains("#settleDomainId")) {
// TODO - 获取人员项目权限
// sql = sql.replace("#settleDomainId", ",'1','2' ")
sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "");
}
if (sql.contains("#deptId")) {
// TODO - 获取人员部门权限
// sql = sql.replace("#settleDomainId", ",'1','2' ")
sql = sql.replace(" or dept.dept_id = #deptId ", "");
}
return R.ok(tEmployeeInfoService.getLeavePage(page, tEmployeeInfo, sql));
}
}
if (Common.isEmpty(tEmployeeInfo.getMId())) {
tEmployeeInfo.setMId("1536952884128591873");
}
menuUtil.setAuthSql(user, tEmployeeInfo);
if (Common.isNotNull(tEmployeeInfo.getAuthSql()) && tEmployeeInfo.getAuthSql().contains(CommonConstants.A_DEPT_ID)) {
tEmployeeInfo.setAuthSql(tEmployeeInfo.getAuthSql().replace(CommonConstants.A_DEPT_ID, "b.id"));
}
return R.ok(tEmployeeInfoService.getLeavePage(page, tEmployeeInfo, null));
return R.ok(tEmployeeInfoService.getLeavePage(page, tEmployeeInfo));
}
......
......@@ -39,9 +39,9 @@ import java.util.List;
@Mapper
public interface TEmployeeInfoMapper extends BaseMapper<TEmployeeInfo> {
IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, @Param("tEmployeeInfo") TEmployeeInfo tEmployeeInfo, @Param("sql") String sql);
IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, @Param("tEmployeeInfo") TEmployeeInfo tEmployeeInfo);
IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, @Param("tEmployeeInfo") TEmployeeInfo tEmployeeInfo, @Param("sql") String sql);
IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, @Param("tEmployeeInfo") TEmployeeInfo tEmployeeInfo);
List<TEmployeeInfo> getList(@Param("tEmployeeInfo") TEmployeeInfo tEmployeeInfo);
......
......@@ -46,7 +46,7 @@ public interface TEmployeeInfoService extends IService<TEmployeeInfo> {
* @Date: 2022/6/20 20:46
* @return: com.baomidou.mybatisplus.core.metadata.IPage<com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeInfo>
**/
IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo, String sql);
IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo);
/**
* @Description: 离职库分页
......@@ -54,7 +54,7 @@ public interface TEmployeeInfoService extends IService<TEmployeeInfo> {
* @Date: 2022/7/4 17:38
* @return: com.baomidou.mybatisplus.core.metadata.IPage<com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeInfo>
**/
IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo, String sql);
IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo);
/**
* @param employeeInfo
......
......@@ -88,13 +88,13 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
@Override
public IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo, String sql) {
return baseMapper.getPage(page, employeeInfo, sql);
public IPage<TEmployeeInfo> getPage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo) {
return baseMapper.getPage(page, employeeInfo);
}
@Override
public IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo, String sql) {
return baseMapper.getLeavePage(page, employeeInfo, sql);
public IPage<TEmployeeInfo> getLeavePage(Page<TEmployeeInfo> page, TEmployeeInfo employeeInfo) {
return baseMapper.getLeavePage(page, employeeInfo);
}
@Override
......
......@@ -491,11 +491,16 @@
select
<include refid="baseParam"/>
from t_employee_info a
<if test="tEmployeeInfo.authSql != null and tEmployeeInfo.authSql.contains('b.id') ">
left join t_employee_project b on a.id=b.EMP_ID
</if>
where a.DELETE_FLAG = '0'
<include refid="employeeInfo_where"/>
<if test="tEmployeeInfo.authSql != null and tEmployeeInfo.authSql.trim() != ''">
and b.DELETE_FLAG = '0'
${tEmployeeInfo.authSql}
</if>
GROUP BY a.id
order by a.CREATE_TIME desc
</select>
......@@ -515,7 +520,9 @@
left join t_employee_project b on a.id = b.EMP_ID
where a.DELETE_FLAG = '0' and b.DELETE_FLAG = '0'
<include refid="employeeInfo_where"/>
${sql}
<if test="tEmployeeInfo.authSql != null and tEmployeeInfo.authSql.trim() != ''">
${tEmployeeInfo.authSql}
</if>
group by a.id order by a.CREATE_TIME desc
) b
where 1=1
......
......@@ -492,4 +492,6 @@ public interface CommonConstants {
public static final String XLSX = ".xlsx";
public static final String ERROR_IMPORT = "执行异常";
// 权限使用的
public static final String A_DEPT_ID = "a.dept_id";
}
package com.yifu.cloud.plus.v1.yifu.common.dapr.util;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDataAuth;
import com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainListVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprArchivesProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprUpmsProperties;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
......@@ -20,7 +24,7 @@ import org.springframework.cache.support.SimpleValueWrapper;
* 2022-9-13 16:14:34
* @Description 公共获取菜单权限的工具
*/
@EnableConfigurationProperties({DaprUpmsProperties.class})
@EnableConfigurationProperties({DaprUpmsProperties.class,DaprArchivesProperties.class})
@RequiredArgsConstructor
@Slf4j
public class MenuUtil {
......@@ -28,7 +32,8 @@ public class MenuUtil {
private final CacheManager cacheManager;
private final DaprUpmsProperties daprUpmsProperties;
private final String DEPT = "#deptId";
private final DaprArchivesProperties daprArchivesProperties;
private static final String START_STR = "start";
public void setAuthSql(YifuUser user, BaseEntity entity) {
// 普通用户:
......@@ -72,19 +77,45 @@ public class MenuUtil {
SimpleValueWrapper objs = (SimpleValueWrapper) obj;
if (objs != null) {
String sql = String.valueOf(objs.get());
if (sql.contains(DEPT)) {
entity.setIsDept(CommonConstants.ONE_INT);
}
if (sql.contains("#create_by")) {
sql = sql.replace("#create_by", user.getId());
}
if (sql.contains("#settleDomainId")) {
// TODO - 获取人员项目权限
// sql = sql.replace("#settleDomainId", ",'1','2' ")
sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "");
// 获取人员项目权限
R<TSettleDomainListVo> res = HttpDaprUtil.invokeMethodPost(daprArchivesProperties.getAppUrl()
, daprArchivesProperties.getAppId(),"/tsettledomain/getSettleDomainIdsByUserId"
, user.getId(), TSettleDomainListVo.class, SecurityConstants.FROM_IN);
StringBuilder deptStr = new StringBuilder();
if (res != null && CommonConstants.SUCCESS != res.getCode()
&& res.getData() != null && res.getData().getDeptIds() != null
&& !res.getData().getDeptIds().isEmpty()) {
for (String deptId : res.getData().getDeptIds()) {
deptStr.append(",'").append(deptId).append("'");
}
}
//sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "")
sql = sql.replace("#settleDomainId", deptStr.toString());
}
if (sql.contains(DEPT)) {
sql = sql.replace(DEPT, String.valueOf(user.getDeptId()));
String userIds = "0";
if (sql.contains(START_STR)) {
String deptIds = StringUtils.substringBetween(sql,START_STR, "end");
R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl()
,daprUpmsProperties.getAppId(),"/user/inner/getUserIdByDeptIds",deptIds
, String.class, SecurityConstants.FROM_IN);
if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) {
userIds = userIdR.getData();
}
sql = sql.replace(START_STR, "").replace("end", "")
.replace(deptIds, userIds);
}
if (sql.contains("#deptId")) {
R<String> userIdR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl()
,daprUpmsProperties.getAppId(),"/user/inner/getUserIdByDeptIds"
,String.valueOf(user.getDeptId()), String.class, SecurityConstants.FROM_IN);
if (userIdR != null && CommonConstants.SUCCESS == userIdR.getCode()) {
userIds = userIdR.getData();
}
sql = sql.replace("#deptId", userIds);
//sql = sql.replace(" or dept.dept_id = #deptId ", "")
}
entity.setAuthSql(sql);
......
......@@ -70,13 +70,6 @@ public class BaseEntity implements Serializable {
@TableField(exist = false)
private String mId;
/**
* 是否关联部门表;0否;1是
*/
@TableField(exist = false)
@ExcelIgnore
private Integer isDept;
/**
* 权限sql
*/
......
......@@ -30,7 +30,6 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserExcelVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserInfoVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysUserService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
......@@ -295,4 +294,24 @@ public class UserController {
}
return naVo;
}
/**
* @Author hgw
* @Description 获取部门下的用户id
* @Date 2022-9-14 11:29:59
**/
@Inner
@PostMapping(value = {"/inner/getUserIdByDeptIds"})
public String getUserIdByDeptIds(@RequestBody String deptIds) {
StringBuilder userIds = new StringBuilder("0");
if (Common.isNotNull(deptIds)) {
List<SysUser> sysUsers = userService.list(Wrappers.<SysUser>query().lambda().in(SysUser::getDeptId, deptIds));
if (Common.isNotEmpty(sysUsers)){
for (SysUser u:sysUsers){
userIds.append(",'").append(u.getUserId()).append("'");
}
}
}
return userIds.toString();
}
}
......@@ -108,13 +108,13 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 处理权限部门
if (sysDataAuth.getIsDeptAuth() == 1 || sysDataAuth.getIsDeptAuth() == 2) {
if (sysDataAuth.getIsDeptAuth() == 2) {
sql.append(" or dept.dept_id in ('0' ");
sql.append(" or a.create_user in (start'0' ");
for (SysDataAuthDeptRel dept : authDeptList) {
sql.append(", '").append(dept.getDeptId()).append("'");
}
sql.append(")");
sql.append("end)");
} else {
sql.append(" or dept.dept_id = #deptId ");
sql.append(" or a.create_user in (#deptId) ");
}
for (SysDataAuthMenuRel menu : menuDeptList) {
authSqlMap.put(linkId + CommonConstants.DOWN_LINE_STRING + menu.getMenuId(), sql.toString());
......@@ -137,7 +137,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 处理项目
if (menuSettleList != null && !menuSettleList.isEmpty()) {
nowSql = " or a.settle_domain_id in ('0'#settleDomainId) ";
nowSql = " or a.dept_id in ('0'#settleDomainId) ";
sysDataAuth.setIsSettleAuth(1);
for (SysDataAuthMenuRel menu : menuSettleList) {
mapSql = authSqlMap.get(linkId + CommonConstants.DOWN_LINE_STRING + menu.getMenuId());
......@@ -314,15 +314,15 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if (menuDeptList == null || menuDeptList.isEmpty()) {
return R.failed("请选择部门关联的菜单!");
} else if (sysDataAuth.getIsDeptAuth() == 2) {
sql.append(" or dept.dept_id in ('0' ");
sql.append(" or a.create_user in (start'0' ");
for (SysDataAuthDeptRel dept : authDeptList) {
sql.append(", '").append(dept.getDeptId()).append("'");
dept.setSysDataAuthId(mainId);
}
sql.append(")");
sql.append("end)");
authDeptRelService.saveOrUpdateBatch(authDeptList);
} else {
sql.append(" or dept.dept_id = #deptId ");
sql.append(" or a.create_user in (#deptId) ");
}
for (SysDataAuthMenuRel menu : menuDeptList) {
authSqlMap.put(linkId + CommonConstants.DOWN_LINE_STRING + menu.getMenuId(), sql.toString());
......@@ -352,7 +352,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 处理项目
if (menuSettleList != null && !menuSettleList.isEmpty()) {
nowSql = " or a.settle_domain_id in ('0'#settleDomainId) ";
nowSql = " or a.dept_id in ('0'#settleDomainId) ";
sysDataAuth.setIsSettleAuth(1);
for (SysDataAuthMenuRel menu : menuSettleList) {
mapSql = authSqlMap.get(linkId + CommonConstants.DOWN_LINE_STRING + menu.getMenuId());
......
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