Commit a16bf1d3 authored by fangxinjiang's avatar fangxinjiang

Merge remote-tracking branch 'origin/develop' into develop

parents dfba77f2 ee735b39
...@@ -64,4 +64,13 @@ public interface CacheConstants { ...@@ -64,4 +64,13 @@ public interface CacheConstants {
*/ */
String PARAMS_DETAILS = "params_details"; String PARAMS_DETAILS = "params_details";
/**
* 数据权限信息缓存
* data_auth_details0:用户组
* data_auth_details1:用户
* hgw
* 2022-6-9 17:29:49
*/
String DATA_AUTH_DETAILS = "data_auth_details";
} }
...@@ -123,4 +123,10 @@ public interface CommonConstants { ...@@ -123,4 +123,10 @@ public interface CommonConstants {
*/ */
String THREE_STRING = "3"; String THREE_STRING = "3";
/**
* 下划线
* hgw 2022-6-9 17:36:35
*/
String DOWN_LINE = "_";
} }
...@@ -44,15 +44,15 @@ public class SysDict extends BaseEntity { ...@@ -44,15 +44,15 @@ public class SysDict extends BaseEntity {
private Long id; private Long id;
/** /**
* 类型 * 字典编码
*/ */
@Schema(description = "字典类型") @Schema(description = "字典编码")
private String type; private String type;
/** /**
* 描述 * 字典名称
*/ */
@Schema(description = "字典描述") @Schema(description = "字典名称")
private String description; private String description;
/** /**
...@@ -74,4 +74,10 @@ public class SysDict extends BaseEntity { ...@@ -74,4 +74,10 @@ public class SysDict extends BaseEntity {
@Schema(description = "删除标记,1:已删除,0:正常") @Schema(description = "删除标记,1:已删除,0:正常")
private String delFlag; private String delFlag;
/**
* 备注信息
*/
@Schema(description = "联动上级类型")
private String parentItemType;
} }
...@@ -89,7 +89,7 @@ public class DataAuthController { ...@@ -89,7 +89,7 @@ public class DataAuthController {
@Operation(summary = "新增/编辑数据权限配置") @Operation(summary = "新增/编辑数据权限配置")
@SysLog("系统管理-数据权限-新增/编辑数据权限配置") @SysLog("系统管理-数据权限-新增/编辑数据权限配置")
@PostMapping("/saveOrUpdate") @PostMapping("/saveOrUpdate")
@PreAuthorize("@pms.hasPermission('sys_data_auth_add')") //@PreAuthorize("@pms.hasPermission('sys_data_auth_add')")
public R<String> saveOrUpdate(@RequestBody SysDataAuthVO sysDataAuthVO) { public R<String> saveOrUpdate(@RequestBody SysDataAuthVO sysDataAuthVO) {
return sysDataAuthService.saveDataAuth(sysDataAuthVO); return sysDataAuthService.saveDataAuth(sysDataAuthVO);
} }
......
...@@ -24,6 +24,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO; ...@@ -24,6 +24,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeoutException;
/** /**
* @Description: 数据权限配置接口 * @Description: 数据权限配置接口
......
...@@ -23,14 +23,19 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.entity.*; ...@@ -23,14 +23,19 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.entity.*;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO; import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDataAuthMapper; import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDataAuthMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.*; import com.yifu.cloud.plus.v1.yifu.admin.service.*;
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.util.Common; 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.util.R;
import com.yifu.cloud.plus.v1.yifu.common.security.service.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.security.service.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils; import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -54,6 +59,9 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -54,6 +59,9 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 自定义sql-菜单 // 自定义sql-菜单
private final SysDiySqlMenuRelService diySqlMenuRelService; private final SysDiySqlMenuRelService diySqlMenuRelService;
// 缓存信息
private final CacheManager cacheManager;
/** /**
* @Description: 分页查询 * @Description: 分页查询
* @Author: hgw * @Author: hgw
...@@ -99,18 +107,39 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -99,18 +107,39 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
} else { } else {
List<SysDataAuthMenuRel> saveMenuDeptList = new ArrayList<>(); List<SysDataAuthMenuRel> saveMenuDeptList = new ArrayList<>();
// 更新缓存
Cache cache = cacheManager.getCache(CacheConstants.DATA_AUTH_DETAILS + sysDataAuth.getLinkType());
if (cache == null) {
return R.failed("获取Redis缓存失败!");
}
// 编辑 // 编辑
String mainId = sysDataAuth.getId(); String mainId = sysDataAuth.getId();
R<String> failed = null; R<String> failed;
if (mainId == null) { if (mainId == null) {
SysDataAuth old = new SysDataAuth();
old.setLinkId(sysDataAuth.getLinkId());
old.setLinkType(sysDataAuth.getLinkType());
List<SysDataAuth> oldList = this.getSysDataAuthList(old);
if (oldList != null && !oldList.isEmpty()) {
return R.failed(sysDataAuth.getLinkName() + " 已存在,不可新增,请去编辑!");
}
// 新增 // 新增
sysDataAuth.setCreateBy(user.getId());
sysDataAuth.setCreateName(user.getNickname());
sysDataAuth.setCreateTime(LocalDateTime.now());
sysDataAuth.setIsCreateAuth(0);
sysDataAuth.setIsDeptAuth(0);
sysDataAuth.setIsSettleAuth(0);
sysDataAuth.setIsDiySql(0);
this.save(sysDataAuth); this.save(sysDataAuth);
mainId = sysDataAuth.getId(); mainId = sysDataAuth.getId();
} else { } else {
sysDataAuth.setUpdateBy(user.getId());
sysDataAuth.setUpdateTime(LocalDateTime.now());
// 删除之前的关系 // 删除之前的关系
this.deleteSubInfoByMainId(mainId); this.deleteSubInfoByMainId(mainId);
} }
failed = doCore(sysDataAuth, saveMenuDeptList, sysDataAuthVO, mainId); failed = this.doCore(sysDataAuth, saveMenuDeptList, sysDataAuthVO, mainId, cache);
if (failed != null) { if (failed != null) {
return failed; return failed;
} }
...@@ -119,6 +148,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -119,6 +148,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if (!saveMenuDeptList.isEmpty()) { if (!saveMenuDeptList.isEmpty()) {
authMenuRelService.saveOrUpdateBatch(saveMenuDeptList); authMenuRelService.saveOrUpdateBatch(saveMenuDeptList);
} }
return R.ok("保存成功"); return R.ok("保存成功");
} }
} else { } else {
...@@ -133,7 +163,8 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -133,7 +163,8 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String> * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
**/ **/
private R<String> doCore(SysDataAuth sysDataAuth, List<SysDataAuthMenuRel> saveMenuDeptList private R<String> doCore(SysDataAuth sysDataAuth, List<SysDataAuthMenuRel> saveMenuDeptList
, SysDataAuthVO sysDataAuthVO, String mainId) { , SysDataAuthVO sysDataAuthVO, String mainId, Cache cache) {
List<SysDataAuthDeptRel> authDeptList = sysDataAuthVO.getAuthDeptList(); List<SysDataAuthDeptRel> authDeptList = sysDataAuthVO.getAuthDeptList();
List<SysDataAuthDiySql> authSqlList = sysDataAuthVO.getAuthSqlList(); List<SysDataAuthDiySql> authSqlList = sysDataAuthVO.getAuthSqlList();
...@@ -141,28 +172,49 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -141,28 +172,49 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
List<SysDataAuthMenuRel> menuCreateList = sysDataAuthVO.getMenuCreateList(); List<SysDataAuthMenuRel> menuCreateList = sysDataAuthVO.getMenuCreateList();
List<SysDataAuthMenuRel> menuSettleList = sysDataAuthVO.getMenuSettleList(); List<SysDataAuthMenuRel> menuSettleList = sysDataAuthVO.getMenuSettleList();
List<SysDataAuthMenuRel> menuDeptList = sysDataAuthVO.getMenuDeptList(); List<SysDataAuthMenuRel> menuDeptList = sysDataAuthVO.getMenuDeptList();
// 存储sql的map,用作缓存 键:linkId + CommonConstants.DOWN_LINE + menu.getMenuId()
Map<String, String> authSqlMap = new HashMap<>();
StringBuilder sql = new StringBuilder();
String mapSql;
StringBuilder nowMapSql;
// Map里的Key
String linkId = sysDataAuth.getLinkId();
// 处理权限部门 // 处理权限部门
if (sysDataAuth.getIsDeptAuth() == 1 || sysDataAuth.getIsDeptAuth() == 2) { if (sysDataAuth.getIsDeptAuth() == 1 || sysDataAuth.getIsDeptAuth() == 2) {
if (menuDeptList == null || menuDeptList.isEmpty()) { if (menuDeptList == null || menuDeptList.isEmpty()) {
return R.failed("请选择部门关联的菜单!"); return R.failed("请选择部门关联的菜单!");
} else if (sysDataAuth.getIsDeptAuth() == 2) { } else if (sysDataAuth.getIsDeptAuth() == 2) {
sql.append(" or dept.dept_id in ('0' ");
for (SysDataAuthDeptRel dept : authDeptList) { for (SysDataAuthDeptRel dept : authDeptList) {
sql.append(", '").append(dept.getDeptId()).append("'");
dept.setSysDataAuthId(mainId); dept.setSysDataAuthId(mainId);
} }
sql.append(")");
authDeptRelService.saveOrUpdateBatch(authDeptList); authDeptRelService.saveOrUpdateBatch(authDeptList);
} else {
sql.append(" or dept.dept_id = #deptId ");
} }
for (SysDataAuthMenuRel menu : menuDeptList) { for (SysDataAuthMenuRel menu : menuDeptList) {
authSqlMap.put(linkId + CommonConstants.DOWN_LINE + menu.getMenuId(), sql.toString());
menu.setSysDataAuthId(mainId); menu.setSysDataAuthId(mainId);
menu.setType(3); menu.setType(3);
} }
saveMenuDeptList.addAll(menuSettleList); saveMenuDeptList.addAll(menuSettleList);
} }
String nowSql;
// 处理创建人 // 处理创建人
if (menuCreateList != null && !menuCreateList.isEmpty()) { if (menuCreateList != null && !menuCreateList.isEmpty()) {
nowSql = " or a.create_by = #create_by ";
sysDataAuth.setIsCreateAuth(1); sysDataAuth.setIsCreateAuth(1);
for (SysDataAuthMenuRel menu : menuCreateList) { for (SysDataAuthMenuRel menu : menuCreateList) {
mapSql = authSqlMap.get(linkId + CommonConstants.DOWN_LINE + menu.getMenuId());
if (!Common.isEmpty(mapSql)) {
nowMapSql = new StringBuilder(nowSql).append(mapSql);
} else {
nowMapSql = new StringBuilder(nowSql);
}
authSqlMap.put(linkId + CommonConstants.DOWN_LINE + menu.getMenuId(), nowMapSql.toString());
menu.setType(1); menu.setType(1);
menu.setSysDataAuthId(mainId); menu.setSysDataAuthId(mainId);
} }
...@@ -171,8 +223,16 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -171,8 +223,16 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 处理结算主体 // 处理结算主体
if (menuSettleList != null && !menuSettleList.isEmpty()) { if (menuSettleList != null && !menuSettleList.isEmpty()) {
nowSql = " or a.settleDomainId in ('0'#settleDomainId) ";
sysDataAuth.setIsSettleAuth(1); sysDataAuth.setIsSettleAuth(1);
for (SysDataAuthMenuRel menu : menuSettleList) { for (SysDataAuthMenuRel menu : menuSettleList) {
mapSql = authSqlMap.get(linkId + CommonConstants.DOWN_LINE + menu.getMenuId());
if (!Common.isEmpty(mapSql)) {
nowMapSql = new StringBuilder(nowSql).append(mapSql);
} else {
nowMapSql = new StringBuilder(nowSql);
}
authSqlMap.put(linkId + CommonConstants.DOWN_LINE + menu.getMenuId(), nowMapSql.toString());
menu.setType(2); menu.setType(2);
menu.setSysDataAuthId(mainId); menu.setSysDataAuthId(mainId);
} }
...@@ -183,14 +243,22 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -183,14 +243,22 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if (authSqlList != null && !authSqlList.isEmpty()) { if (authSqlList != null && !authSqlList.isEmpty()) {
sysDataAuth.setIsDiySql(1); sysDataAuth.setIsDiySql(1);
List<SysDiySqlMenuRel> menuSqlList; List<SysDiySqlMenuRel> menuSqlList;
for (SysDataAuthDiySql sql : authSqlList) { for (SysDataAuthDiySql sqls : authSqlList) {
menuSqlList = sql.getSqlMenuList(); nowSql = sqls.getDiySql();
menuSqlList = sqls.getSqlMenuList();
if (menuSqlList != null && !menuSqlList.isEmpty()) { if (menuSqlList != null && !menuSqlList.isEmpty()) {
sql.setSysDataAuthId(mainId); sqls.setSysDataAuthId(mainId);
diySqlService.save(sql); diySqlService.save(sqls);
for (SysDiySqlMenuRel menuSql : menuSqlList) { for (SysDiySqlMenuRel menuSql : menuSqlList) {
mapSql = authSqlMap.get(linkId + CommonConstants.DOWN_LINE + menuSql.getMenuId());
if (!Common.isEmpty(mapSql)) {
nowMapSql = new StringBuilder(nowSql).append(mapSql);
} else {
nowMapSql = new StringBuilder(nowSql);
}
authSqlMap.put(linkId + CommonConstants.DOWN_LINE + menuSql.getMenuId(), nowMapSql.toString());
menuSql.setSysDataAuthId(mainId); menuSql.setSysDataAuthId(mainId);
menuSql.setSysDiySqlId(sql.getId()); menuSql.setSysDiySqlId(sqls.getId());
} }
diySqlMenuRelService.saveBatch(menuSqlList); diySqlMenuRelService.saveBatch(menuSqlList);
} else { } else {
...@@ -198,6 +266,18 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa ...@@ -198,6 +266,18 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
} }
} }
} }
// 更新缓存
// 缓存里放入 id_菜单id, sql
if (!authSqlMap.isEmpty()) {
// 前缀
String prefix = " and (1=1 ";
// 后缀
String suffix = " ) ";
for (Map.Entry<String, String> authSql : authSqlMap.entrySet()) {
cache.put(authSql.getKey(), prefix + authSql.getValue() + suffix);
}
}
return null; return null;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<result property="isSettleAuth" column="is_settle_auth"/> <result property="isSettleAuth" column="is_settle_auth"/>
<result property="isDiySql" column="is_diy_sql"/> <result property="isDiySql" column="is_diy_sql"/>
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<result property="createName" column="create_name"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
a.is_settle_auth, a.is_settle_auth,
a.is_diy_sql, a.is_diy_sql,
a.create_by, a.create_by,
a.create_name,
a.create_time, a.create_time,
a.update_by, a.update_by,
a.update_time a.update_time
...@@ -56,6 +58,12 @@ ...@@ -56,6 +58,12 @@
<if test="sysDataAuth.linkName != null and sysDataAuth.linkName.trim() != ''"> <if test="sysDataAuth.linkName != null and sysDataAuth.linkName.trim() != ''">
AND a.link_name like concat('%',#{sysDataAuth.linkName},'%') AND a.link_name like concat('%',#{sysDataAuth.linkName},'%')
</if> </if>
<if test="sysDataAuth.linkId != null and sysDataAuth.linkId.trim() != ''">
AND a.link_id = #{sysDataAuth.linkId}
</if>
<if test="sysDataAuth.linkType != null">
AND a.link_type =#{sysDataAuth.linkType}
</if>
</if> </if>
</sql> </sql>
......
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