| | |
| | | public static <T extends MPJLambdaWrapper<?>, S> void appendPermissionCondition(T query, Integer bizType, |
| | | SFunction<S, ?> bizId, |
| | | Long userId, Integer sceneType) { |
| | | appendPermissionCondition(query, bizType, bizId, userId, sceneType, null); |
| | | } |
| | | |
| | | /** |
| | | * 构造售后模块数据【分页】查询条件(支持「处理人」也算可见范围) |
| | | * |
| | | * @param handlerUserIdField 处理人字段(带表别名),为 null 表示该表没有处理人概念 |
| | | */ |
| | | public static <T extends MPJLambdaWrapper<?>, S> void appendPermissionCondition(T query, Integer bizType, |
| | | SFunction<S, ?> bizId, |
| | | Long userId, Integer sceneType, |
| | | String handlerUserIdField) { |
| | | MybatisPlusJoinProperties mybatisPlusJoinProperties = SpringUtil.getBean(MybatisPlusJoinProperties.class); |
| | | final String ownerUserIdField = mybatisPlusJoinProperties.getTableAlias() + ".owner_user_id"; |
| | | // 场景一:我负责的数据 |
| | | final String tableAlias = mybatisPlusJoinProperties.getTableAlias(); |
| | | final String ownerUserIdField = tableAlias + ".owner_user_id"; |
| | | // 处理人字段补齐表别名(避免连表查询时列名歧义) |
| | | final String handlerField = handlerUserIdField != null ? tableAlias + "." + handlerUserIdField : null; |
| | | // 场景一:我负责的数据(或我作为处理人的数据) |
| | | if (AfterSaleSceneTypeEnum.isOwner(sceneType)) { |
| | | if (handlerField != null) { |
| | | query.and(w -> w.eq(ownerUserIdField, userId).or().eq(handlerField, userId)); |
| | | } else { |
| | | query.eq(ownerUserIdField, userId); |
| | | } |
| | | } |
| | | // 场景二:我参与的数据(我有读或写权限,并且不是负责人) |
| | | if (AfterSaleSceneTypeEnum.isInvolved(sceneType)) { |
| | |
| | | query.in(ownerUserIdField, convertSet(subordinateUsers, AdminUserRespDTO::getId)); |
| | | } |
| | | } |
| | | // 场景四:全部数据(需要有 view-all 权限或售后管理员) |
| | | // 场景四:全部数据(需要有 view-all 权限或售后管理员;否则只看自己负责 + 自己处理的) |
| | | if (AfterSaleSceneTypeEnum.isAll(sceneType)) { |
| | | if (isAftersaleAdmin() || hasViewAllPermission()) { |
| | | return; |
| | | } |
| | | if (handlerField != null) { |
| | | query.and(w -> w.eq(ownerUserIdField, userId).or().eq(handlerField, userId)); |
| | | } else { |
| | | query.eq(ownerUserIdField, userId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |