0.3.0 数据隔离
This commit is contained in:
parent
38bd16189e
commit
904cb75554
|
@ -1,6 +1,10 @@
|
|||
package com.ruoyi.common.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 数据权限过滤注解
|
||||
|
@ -13,15 +17,25 @@ import java.lang.annotation.*;
|
|||
public @interface DataScope
|
||||
{
|
||||
/**
|
||||
* 部门表的别名,可多选,逗号分隔
|
||||
* 部门字段别名,可多选,逗号分隔
|
||||
*/
|
||||
public String deptAlias() default "";
|
||||
|
||||
/**
|
||||
* 用户表的别名
|
||||
* 部门集合字段别名,可多选,逗号分隔
|
||||
*/
|
||||
public String deptSetAlias() default "";
|
||||
|
||||
/**
|
||||
* 用户字段别名,可多选,逗号分隔
|
||||
*/
|
||||
public String userAlias() default "";
|
||||
|
||||
/**
|
||||
* 用户集合字段别名,可多选,逗号分隔
|
||||
*/
|
||||
public String userSetAlias() default "";
|
||||
|
||||
/**
|
||||
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@ss获取,多个权限用逗号分隔开来
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package com.ruoyi.framework.aspectj;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
|
@ -8,10 +13,6 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.security.context.PermissionContextHolder;
|
||||
import com.ruoyi.framework.util.DataScopeUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 数据过滤处理
|
||||
|
@ -46,7 +47,7 @@ public class DataScopeAspect
|
|||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
{
|
||||
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias(), permission);
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,13 +57,19 @@ public class DataScopeAspect
|
|||
*
|
||||
* @param joinPoint 切点
|
||||
* @param user 用户
|
||||
* @param deptAlias 部门别名
|
||||
* @param userAlias 用户别名
|
||||
* @param scope 注解
|
||||
* @param permission 权限字符
|
||||
*/
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission)
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, DataScope scope, String permission)
|
||||
{
|
||||
StringBuilder sqlString = DataScopeUtil.getSqlString(user, deptAlias, userAlias, permission);
|
||||
StringBuilder sqlString = DataScopeUtil.getSqlString(
|
||||
user,
|
||||
scope.deptAlias(),
|
||||
scope.userAlias(),
|
||||
scope.deptSetAlias(),
|
||||
scope.userSetAlias(),
|
||||
permission
|
||||
);
|
||||
JoinSqlString(joinPoint, sqlString);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
|
@ -11,10 +15,6 @@ import com.ruoyi.common.utils.StringUtils;
|
|||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.framework.security.context.PermissionContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/13
|
||||
|
@ -51,11 +51,24 @@ public class DataScopeUtil {
|
|||
* 仅本人数据权限
|
||||
*/
|
||||
public static final String DATA_SCOPE_SELF = "5";
|
||||
|
||||
/**
|
||||
* 负责部门数据权限
|
||||
*/
|
||||
public static final String DATA_SCOPE_LEADER_DEPT = "6";
|
||||
|
||||
/**
|
||||
* 本部门及本人数据权限
|
||||
*/
|
||||
public static final String DATA_SCOPE_DEPT_AND_SELF = "7";
|
||||
|
||||
/**
|
||||
* Mybatis直接使用的方法
|
||||
* @param deptAlias
|
||||
* @param userAlias
|
||||
* @param needScope
|
||||
* @return
|
||||
*/
|
||||
public static String dataScope(String deptAlias, String userAlias, boolean needScope) {
|
||||
if (needScope) {
|
||||
// 获取当前的用户
|
||||
|
@ -66,7 +79,7 @@ public class DataScopeUtil {
|
|||
// 如果是超级管理员,则不过滤数据
|
||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
{
|
||||
StringBuilder sqlString = getSqlString(currentUser, deptAlias, userAlias, PermissionContextHolder.getContext());
|
||||
StringBuilder sqlString = getSqlString(currentUser, deptAlias, userAlias, null, null, PermissionContextHolder.getContext());
|
||||
if (StringUtils.isNotBlank(sqlString.toString())) {
|
||||
return getJoinSqlString(sqlString, "");
|
||||
}
|
||||
|
@ -76,9 +89,11 @@ public class DataScopeUtil {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static StringBuilder getSqlString(SysUser user, String deptAlias, String userAlias, String permission) {
|
||||
List<String> deptList = StringUtils.hasText(deptAlias) ? Arrays.asList(deptAlias.split(",")) : new ArrayList<>();
|
||||
List<String> userList = StringUtils.hasText(userAlias) ? Arrays.asList(userAlias.split(",")) : new ArrayList<>();
|
||||
public static StringBuilder getSqlString(SysUser user, String deptAlias, String userAlias, String deptSetAlias, String userSetAlias, String permission) {
|
||||
List<String> deptAliasList = StringUtils.hasText(deptAlias) ? Arrays.asList(deptAlias.split(",")) : new ArrayList<>();
|
||||
List<String> userAliasList = StringUtils.hasText(userAlias) ? Arrays.asList(userAlias.split(",")) : new ArrayList<>();
|
||||
List<String> deptSetAliasList = StringUtils.hasText(deptSetAlias) ? Arrays.asList(deptSetAlias.split(",")) : new ArrayList<>();
|
||||
List<String> userSetAliasList = StringUtils.hasText(userSetAlias) ? Arrays.asList(userSetAlias.split(",")) : new ArrayList<>();
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
List<String> conditions = new ArrayList<String>();
|
||||
List<String> scopeCustomIds = new ArrayList<String>();
|
||||
|
@ -107,34 +122,76 @@ public class DataScopeUtil {
|
|||
// 自定义数据范围
|
||||
else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
|
||||
if (scopeCustomIds.size() > 1) {
|
||||
// 多个自定数据权限使用in查询,避免多次拼接。
|
||||
sqlString.append(getForeachSql(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptList, String.join(",", scopeCustomIds)));
|
||||
// 处理普通部门ID字段
|
||||
sqlString.append(getForeachSql(" OR {} IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAliasList, String.join(",", scopeCustomIds)));
|
||||
// 处理逗号分隔的部门ID字段
|
||||
if (CollectionUtils.isNotEmpty(deptSetAliasList)) {
|
||||
sqlString.append(" OR EXISTS ( SELECT 1 FROM sys_role_dept rd WHERE rd.role_id in (")
|
||||
.append(String.join(",", scopeCustomIds))
|
||||
.append(") AND (")
|
||||
.append(getForeachSql("find_in_set(rd.dept_id, {}) OR ", deptSetAliasList))
|
||||
.append(" 1=0)) ");
|
||||
}
|
||||
} else {
|
||||
sqlString.append(getForeachSql(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptList, role.getRoleId()));
|
||||
// 处理普通部门ID字段
|
||||
sqlString.append(getForeachSql(" OR {} IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAliasList, role.getRoleId()));
|
||||
// 处理逗号分隔的部门ID字段
|
||||
if (CollectionUtils.isNotEmpty(deptSetAliasList)) {
|
||||
sqlString.append(" OR EXISTS ( SELECT 1 FROM sys_role_dept rd WHERE rd.role_id = ")
|
||||
.append(role.getRoleId())
|
||||
.append(" AND (")
|
||||
.append(getForeachSql("find_in_set(rd.dept_id, {}) OR ", deptSetAliasList))
|
||||
.append(" 1=0)) ");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 仅本部门
|
||||
else if (DATA_SCOPE_DEPT.equals(dataScope)) {
|
||||
sqlString.append(getForeachSql(" OR {}.dept_id = {} ", deptList, user.getDeptId()));
|
||||
else if (DATA_SCOPE_DEPT.equals(dataScope) || DATA_SCOPE_DEPT_AND_SELF.equals(dataScope)) {
|
||||
sqlString.append(getForeachSql(" OR {} = {} ", deptAliasList, user.getDeptId()));
|
||||
if (CollectionUtils.isNotEmpty(deptSetAliasList)) {
|
||||
sqlString.append(getForeachSql(" OR find_in_set({}, {}) ", user.getDeptId(), deptSetAliasList));
|
||||
}
|
||||
}
|
||||
// 本部门及下级部门
|
||||
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
|
||||
sqlString.append(getForeachSql(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptList, user.getDeptId(), user.getDeptId()));
|
||||
sqlString.append(getForeachSql(" OR {} IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
|
||||
deptAliasList, user.getDeptId(), user.getDeptId()));
|
||||
if (CollectionUtils.isNotEmpty(deptSetAliasList)) {
|
||||
sqlString.append(" OR EXISTS ( SELECT 1 FROM sys_dept d WHERE (d.dept_id = ")
|
||||
.append(user.getDeptId())
|
||||
.append(" OR find_in_set(")
|
||||
.append(user.getDeptId())
|
||||
.append(", d.ancestors)) AND (")
|
||||
.append(getForeachSql("find_in_set(d.dept_id, {}) OR ", deptSetAliasList))
|
||||
.append(" 1=0)) ");
|
||||
}
|
||||
}
|
||||
// 仅本人
|
||||
else if (DATA_SCOPE_SELF.equals(dataScope)) {
|
||||
if (CollectionUtils.isNotEmpty(userList)) {
|
||||
sqlString.append(getForeachSql(" OR {}.user_id = {} ", userList, user.getUserId()));
|
||||
} else {
|
||||
// 数据权限为仅本人且没有userAlias别名不查询任何数据
|
||||
else if (DATA_SCOPE_SELF.equals(dataScope) || DATA_SCOPE_DEPT_AND_SELF.equals(dataScope)) {
|
||||
if (CollectionUtils.isNotEmpty(userAliasList)) {
|
||||
sqlString.append(getForeachSql(" OR {} = {} ", userAliasList, user.getUserId()));
|
||||
}
|
||||
// 处理存储多个用户ID的字段
|
||||
if (CollectionUtils.isNotEmpty(userSetAliasList)) {
|
||||
sqlString.append(getForeachSql(" OR find_in_set({}, {}) ", user.getUserId(), userSetAliasList));
|
||||
}
|
||||
// 如果两种字段都没有,则不查询任何数据
|
||||
if (CollectionUtils.isEmpty(userAliasList) && CollectionUtils.isEmpty(userSetAliasList)) {
|
||||
sqlString.append(" OR 1=0 ");
|
||||
}
|
||||
}
|
||||
// 负责部门数据权限
|
||||
else if (DATA_SCOPE_LEADER_DEPT.equals(dataScope)) {
|
||||
String sql = getForeachSql(" OR {}.dept_id in ( SELECT dept_id FROM sys_dept WHERE find_in_set({}, leader_ids) )", deptList, user.getUserId());
|
||||
sqlString.append(sql);
|
||||
}
|
||||
sqlString.append(getForeachSql(" OR {} in ( SELECT dept_id FROM sys_dept WHERE find_in_set({}, leader_ids) )",
|
||||
deptAliasList, user.getUserId()));
|
||||
if (CollectionUtils.isNotEmpty(deptSetAliasList)) {
|
||||
sqlString.append(" OR EXISTS ( SELECT 1 FROM sys_dept d WHERE find_in_set(")
|
||||
.append(user.getUserId())
|
||||
.append(", d.leader_ids) AND (")
|
||||
.append(getForeachSql("find_in_set(d.dept_id, {}) OR ", deptSetAliasList))
|
||||
.append(" 1=0)) ");
|
||||
}
|
||||
}
|
||||
conditions.add(dataScope);
|
||||
}
|
||||
|
||||
|
@ -160,6 +217,15 @@ public class DataScopeUtil {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String getForeachSql(String template, Object obj, List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : list) {
|
||||
sb.append(StringUtils.format(template, obj, s));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void joinSqlString(BaseEntity baseEntity, StringBuilder sqlString) {
|
||||
String scope = (String) baseEntity.getParams().get(DATA_SCOPE);
|
||||
|
|
|
@ -84,4 +84,7 @@ public class Customer extends BaseEntity
|
|||
@ApiModelProperty("最近跟进时间")
|
||||
private LocalDateTime lastFollowTime;
|
||||
|
||||
@Excel(name = "创建人ID")
|
||||
@ApiModelProperty("创建人ID")
|
||||
private Long createId;
|
||||
}
|
||||
|
|
|
@ -8,5 +8,8 @@ public class CustomerVO extends Customer{
|
|||
|
||||
@ApiModelProperty("跟进人名称")
|
||||
private String followName;
|
||||
|
||||
@ApiModelProperty("创建人名称")
|
||||
private String createName;
|
||||
|
||||
}
|
||||
|
|
|
@ -50,22 +50,6 @@ public interface CustomerMapper
|
|||
*/
|
||||
public int updateCustomer(@Param("data") Customer customer);
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*
|
||||
* @param id 客户主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteCustomerById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除客户
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCustomerByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询客户数量
|
||||
* @param query
|
||||
|
@ -87,4 +71,11 @@ public interface CustomerMapper
|
|||
* @return
|
||||
*/
|
||||
int updateLastFollowTime(@Param("customerId") Long customerId, @Param("lastFollowTime") LocalDateTime lastFollowTime);
|
||||
|
||||
/**
|
||||
* 逻辑删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
int logicDel(@Param("ids") List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bc.create_time,
|
||||
bc.update_time,
|
||||
bc.deleted,
|
||||
suf.nick_name as follow_name
|
||||
suf.nick_name as follow_name,
|
||||
su.nick_name as create_name
|
||||
from bst_customer bc
|
||||
left join sys_user suf on suf.user_id = bc.follow_id
|
||||
left join sys_user su on su.user_id = bc.create_id
|
||||
</sql>
|
||||
|
||||
<sql id="searchCondition">
|
||||
|
@ -48,6 +50,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="query.excludeId != null "> and bc.id != #{query.excludeId}</if>
|
||||
<if test="query.createDate != null "> and date(bc.create_time) = #{query.createDate}</if>
|
||||
<if test="query.followName != null and query.followName != ''"> and suf.nick_name like concat('%', #{query.followName}, '%')</if>
|
||||
<if test="query.createName != null and query.createName != ''"> and su.nick_name like concat('%', #{query.createName}, '%')</if>
|
||||
<if test="query.createId != null "> and su.user_id = #{query.createId}</if>
|
||||
<if test="query.ids != null and query.ids.size() > 0">
|
||||
and bc.id in
|
||||
<foreach collection="query.ids" item="item" open="(" separator="," close=")">
|
||||
|
@ -86,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="deleted != null">deleted,</if>
|
||||
<if test="createId != null">create_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="code != null and code != ''">#{code},</if>
|
||||
|
@ -102,6 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="deleted != null">#{deleted},</if>
|
||||
<if test="createId != null">#{createId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -128,18 +134,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.createTime != null">create_time = #{data.createTime},</if>
|
||||
<if test="data.updateTime != null">update_time = #{data.updateTime},</if>
|
||||
<if test="data.deleted != null">deleted = #{data.deleted},</if>
|
||||
<if test="data.createId != null">create_id = #{data.createId},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deleteCustomerById" parameterType="Long">
|
||||
delete from bst_customer where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteCustomerByIds" parameterType="String">
|
||||
delete from bst_customer where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- selectCount -->
|
||||
|
||||
|
@ -169,5 +166,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where id = #{customerId}
|
||||
and last_follow_time < #{lastFollowTime}
|
||||
</update>
|
||||
|
||||
|
||||
<!-- logicDel -->
|
||||
|
||||
<update id="logicDel">
|
||||
update bst_customer
|
||||
set deleted = true
|
||||
where id in
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
and deleted = false
|
||||
</update>
|
||||
</mapper>
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import com.ruoyi.bst.customer.domain.Customer;
|
||||
import com.ruoyi.bst.customer.domain.CustomerQuery;
|
||||
import com.ruoyi.bst.customer.domain.CustomerVO;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.vo.StringIntegerVO;
|
||||
|
||||
/**
|
||||
|
@ -48,22 +49,6 @@ public interface CustomerService
|
|||
*/
|
||||
public int updateCustomer(Customer customer);
|
||||
|
||||
/**
|
||||
* 批量删除客户
|
||||
*
|
||||
* @param ids 需要删除的客户主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCustomerByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除客户信息
|
||||
*
|
||||
* @param id 客户主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCustomerById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户数量
|
||||
* @param query
|
||||
|
@ -92,4 +77,21 @@ public interface CustomerService
|
|||
* @return
|
||||
*/
|
||||
int updateLastFollowTime(Long customerId, LocalDateTime lastFollowTime);
|
||||
|
||||
/**
|
||||
* 查询客户列表,并根据数据权限过滤
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
@DataScope(userAlias = "bc.create_id,bc.follow_id")
|
||||
default List<CustomerVO> selectCustomerListScope(CustomerQuery query) {
|
||||
return selectCustomerList(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
int logicDel(List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.ruoyi.bst.customer.mapper.CustomerMapper;
|
|||
import com.ruoyi.bst.customer.service.CustomerService;
|
||||
import com.ruoyi.bst.customer.service.CustomerValidator;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.SnowFlakeUtil;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.common.vo.StringIntegerVO;
|
||||
|
@ -72,6 +73,7 @@ public class CustomerServiceImpl implements CustomerService
|
|||
{
|
||||
customer.setCode(String.valueOf(SnowFlakeUtil.newId()));
|
||||
customer.setCreateTime(DateUtils.getNowDate());
|
||||
customer.setCreateId(SecurityUtils.getUserId());
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
int insert = customerMapper.insertCustomer(customer);
|
||||
|
@ -107,30 +109,6 @@ public class CustomerServiceImpl implements CustomerService
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除客户
|
||||
*
|
||||
* @param ids 需要删除的客户主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCustomerByIds(Long[] ids)
|
||||
{
|
||||
return customerMapper.deleteCustomerByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户信息
|
||||
*
|
||||
* @param id 客户主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCustomerById(Long id)
|
||||
{
|
||||
return customerMapper.deleteCustomerById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int selectCount(CustomerQuery query) {
|
||||
|
@ -159,4 +137,12 @@ public class CustomerServiceImpl implements CustomerService
|
|||
}
|
||||
return customerMapper.updateLastFollowTime(customerId, lastFollowTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int logicDel(List<Long> ids) {
|
||||
if (CollectionUtils.isEmptyElement(ids)) {
|
||||
return 0;
|
||||
}
|
||||
return customerMapper.logicDel(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import com.ruoyi.bst.customerFollow.domain.CustomerFollow;
|
||||
import com.ruoyi.bst.customerFollow.domain.CustomerFollowQuery;
|
||||
import com.ruoyi.bst.customerFollow.domain.CustomerFollowVO;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
|
||||
/**
|
||||
* 客户跟进记录Service接口
|
||||
|
@ -61,4 +62,14 @@ public interface CustomerFollowService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteCustomerFollowByFollowId(Long followId);
|
||||
|
||||
/**
|
||||
* 查询客户跟进记录列表,并根据数据权限过滤
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
@DataScope(userAlias = "bcf.user_id")
|
||||
default List<CustomerFollowVO> selectCustomerFollowListScope(CustomerFollowQuery query) {
|
||||
return selectCustomerFollowList(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import com.ruoyi.bst.notice.domain.Notice;
|
||||
import com.ruoyi.bst.notice.domain.NoticeQuery;
|
||||
import com.ruoyi.bst.notice.domain.NoticeVO;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
|
||||
/**
|
||||
* 公告Service接口
|
||||
|
@ -61,4 +62,9 @@ public interface NoticeService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteNoticeById(Long id);
|
||||
|
||||
@DataScope(deptSetAlias = "bn.receive_dept_ids", userAlias = "bn.user_id", userSetAlias = "bn.receive_user_ids")
|
||||
default List<NoticeVO> selectNoticeListScope(NoticeQuery query) {
|
||||
return this.selectNoticeList(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.ruoyi.bst.project.domain.ProjectVO;
|
|||
import com.ruoyi.bst.project.domain.dto.ProjectMaintenanceDTO;
|
||||
import com.ruoyi.bst.project.domain.dto.ProjectStartDTO;
|
||||
import com.ruoyi.bst.project.domain.vo.ProjectNameVO;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.vo.IntegerIntegerVO;
|
||||
import com.ruoyi.common.vo.StringIntegerVO;
|
||||
|
||||
|
@ -137,4 +138,14 @@ public interface ProjectService
|
|||
* 处理维护超期的项目,并打上超期标识
|
||||
*/
|
||||
int handleMaintenanceOverdueProject(ProjectQuery query);
|
||||
|
||||
/**
|
||||
* 查询项目列表,并按照数据隔离
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
@DataScope(userAlias = "bp.owner_id,bp.follow_id,bp.create_id", userSetAlias = "bp.member_ids")
|
||||
default List<ProjectVO> selectProjectListScope(ProjectQuery query) {
|
||||
return this.selectProjectList(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.ruoyi.bst.task.domain.TaskQuery;
|
|||
import com.ruoyi.bst.task.domain.TaskVO;
|
||||
import com.ruoyi.bst.task.domain.dto.TaskCancelDTO;
|
||||
import com.ruoyi.bst.task.domain.dto.TaskSubmitDTO;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.vo.LongIntegerVO;
|
||||
import com.ruoyi.common.vo.StringIntegerVO;
|
||||
|
||||
|
@ -113,4 +114,9 @@ public interface TaskService
|
|||
* @param taskId
|
||||
*/
|
||||
int startTask(Long taskId);
|
||||
|
||||
@DataScope(userAlias = "bt.create_id,bt.cancel_user_id", userSetAlias = "bt.owner_ids")
|
||||
default List<TaskVO> selectTaskListScope(TaskQuery query) {
|
||||
return this.selectTaskList(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
where d.dept_id = #{deptId}
|
||||
${@com.ruoyi.framework.util.DataScopeUtil@dataScope("d", null, scope)}
|
||||
</select>
|
||||
|
||||
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
|
@ -23,7 +22,6 @@ import com.ruoyi.common.exception.ServiceException;
|
|||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.dept.domain.SysDeptQuery;
|
||||
import com.ruoyi.system.dept.domain.SysDeptVO;
|
||||
import com.ruoyi.system.dept.domain.vo.SysDeptNameVO;
|
||||
|
@ -58,7 +56,6 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
* @return 部门信息集合
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysDeptVO> selectDeptList(SysDeptQuery query)
|
||||
{
|
||||
return deptMapper.selectDeptList(query);
|
||||
|
@ -73,7 +70,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
@Override
|
||||
public List<TreeSelect> selectDeptTreeList(SysDeptQuery query)
|
||||
{
|
||||
List<SysDeptVO> depts = SpringUtils.getAopProxy(this).selectDeptList(query);
|
||||
List<SysDeptVO> depts = this.selectDeptList(query);
|
||||
return buildDeptTreeSelect(depts);
|
||||
}
|
||||
|
||||
|
@ -208,7 +205,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
{
|
||||
SysDeptQuery dept = new SysDeptQuery();
|
||||
dept.setDeptId(deptId);
|
||||
List<SysDeptVO> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
|
||||
List<SysDeptVO> depts = this.selectDeptList(dept);
|
||||
if (StringUtils.isEmpty(depts))
|
||||
{
|
||||
throw new ServiceException("没有权限访问部门数据!");
|
||||
|
|
|
@ -5,17 +5,17 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
|
@ -52,7 +52,6 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
* @return 角色数据集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysRole> selectRoleList(SysRole role)
|
||||
{
|
||||
return roleMapper.selectRoleList(role);
|
||||
|
@ -112,7 +111,7 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
@Override
|
||||
public List<SysRole> selectRoleAll()
|
||||
{
|
||||
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
|
||||
return this.selectRoleList(new SysRole());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +202,7 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
{
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleId(roleId);
|
||||
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
|
||||
List<SysRole> roles = this.selectRoleList(role);
|
||||
if (StringUtils.isEmpty(roles))
|
||||
{
|
||||
throw new ServiceException("没有权限访问角色数据!");
|
||||
|
|
|
@ -134,8 +134,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${@com.ruoyi.framework.util.DataScopeUtil@dataScope("d", "u", needScope)}
|
||||
${params.dataScope}
|
||||
</sql>
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
|
@ -31,7 +30,6 @@ import com.ruoyi.common.utils.ServiceUtil;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanValidators;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.dept.domain.SysDeptVO;
|
||||
import com.ruoyi.system.dept.service.ISysDeptService;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
|
@ -107,7 +105,6 @@ public class UserServiceImpl implements UserService
|
|||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUserVO> selectUserListScope(SysUserQuery user) {
|
||||
return userMapper.selectUserList(user);
|
||||
}
|
||||
|
@ -119,7 +116,6 @@ public class UserServiceImpl implements UserService
|
|||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectAllocatedList(SysUser user)
|
||||
{
|
||||
return userMapper.selectAllocatedList(user);
|
||||
|
@ -132,7 +128,6 @@ public class UserServiceImpl implements UserService
|
|||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectUnallocatedList(SysUser user)
|
||||
{
|
||||
return userMapper.selectUnallocatedList(user);
|
||||
|
@ -258,7 +253,7 @@ public class UserServiceImpl implements UserService
|
|||
{
|
||||
SysUserQuery user = new SysUserQuery();
|
||||
user.setUserId(userId);
|
||||
List<SysUserVO> users = SpringUtils.getAopProxy(this).selectUserListScope(user);
|
||||
List<SysUserVO> users = this.selectUserListScope(user);
|
||||
if (StringUtils.isEmpty(users))
|
||||
{
|
||||
throw new ServiceException("没有权限访问用户数据!");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class CustomerController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
List<CustomerVO> list = customerService.selectCustomerList(query);
|
||||
List<CustomerVO> list = customerService.selectCustomerListScope(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,8 @@ public class CustomerController extends BaseController
|
|||
@PreAuthorize("@ss.hasPermi('bst:customer:remove')")
|
||||
@Log(title = "客户", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
public AjaxResult remove(@PathVariable List<Long> ids)
|
||||
{
|
||||
return toAjax(customerService.deleteCustomerByIds(ids));
|
||||
return toAjax(customerService.logicDel(ids));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CustomerFollowController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
List<CustomerFollowVO> list = customerFollowService.selectCustomerFollowList(query);
|
||||
List<CustomerFollowVO> list = customerFollowService.selectCustomerFollowListScope(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class NoticeController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
List<NoticeVO> list = noticeService.selectNoticeList(query);
|
||||
List<NoticeVO> list = noticeService.selectNoticeListScope(query);
|
||||
noticeAssembler.assembleReceiveUserList(list);
|
||||
noticeAssembler.assembleReceiveDeptList(list);
|
||||
return getDataTable(list);
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ProjectController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
List<ProjectVO> list = projectService.selectProjectList(query);
|
||||
List<ProjectVO> list = projectService.selectProjectListScope(query);
|
||||
projectAssembler.assembleTaskCount(list);
|
||||
projectAssembler.assembleTaskPassCount(list);
|
||||
projectAssembler.assembleTaskWaitConfirmCount(list);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class TaskController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
startOrderBy();
|
||||
List<TaskVO> list = taskService.selectTaskList(query);
|
||||
List<TaskVO> list = taskService.selectTaskListScope(query);
|
||||
taskAssembler.assembleOwnerList(list);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user