Skip to content

Commit

Permalink
feat: 完善职位权限功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolincku committed Jun 29, 2024
1 parent b38257e commit cab10ca
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.zerolinck.passiflora.common.util;

import java.util.HashSet;
import java.util.Set;

/**
* @author linck
* @since 2024-06-29
*/
public class SetUtil {

/**
* 返回 set2 相对于 set1 多出的值
*/
public static Set<String> differenceSet2FromSet1(Set<String> set1, Set<String> set2) {
Set<String> difference = new HashSet<>(set2);
difference.removeAll(set1);
return difference;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import com.zerolinck.passiflora.model.valid.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
* @author linck
* @since 2024-05-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@
import com.zerolinck.passiflora.common.api.Result;
import com.zerolinck.passiflora.common.util.QueryCondition;
import com.zerolinck.passiflora.feign.config.FeignConfiguration;
import com.zerolinck.passiflora.model.system.dto.PositionPermissionSaveDto;
import com.zerolinck.passiflora.model.system.entity.SysPosition;
import com.zerolinck.passiflora.model.system.vo.SysPositionVo;
import com.zerolinck.passiflora.model.valid.Insert;
import com.zerolinck.passiflora.model.valid.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
* @author linck
* @since 2024-05-14
Expand Down Expand Up @@ -91,4 +93,16 @@ Result<SysPosition> detail(
Result<String> updateOrder(
@RequestBody @Validated(Update.class) List<SysPositionVo> sysPositionVos
);

@Operation(summary = "根据职位ids获取权限ids")
@PostMapping("permissionIdsByPositionIds")
Result<List<String>> permissionIdsByPositionIds(
@RequestBody List<String> positionIds
);

@Operation(summary = "保存职位权限")
@PostMapping("savePositionPermission")
Result<String> savePositionPermission(
@RequestBody @Validated PositionPermissionSaveDto positionPermissionSaveDto
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.zerolinck.passiflora.model.system.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import java.util.List;

/**
* @author linck
* @since 2024-06-29
*/
@Data
public class PositionPermissionSaveDto {

@Schema(description = "职位ID", maxLength = 20)
@Length(
max = 20,
message = "职位ID长度不能大于20"
)
@NotBlank(message = "职位ID不能为空")
private String positionId;

private List<String> permissionIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import com.zerolinck.passiflora.model.system.vo.SysPermissionTableVo;
import com.zerolinck.passiflora.model.system.vo.SysPermissionVo;
import com.zerolinck.passiflora.system.service.SysPermissionService;
import com.zerolinck.passiflora.system.service.SysPositionPermissionService;
import jakarta.annotation.Resource;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author linck
* @since 2024-05-06
Expand All @@ -46,6 +48,9 @@ public class SysPermissionController implements SysPermissionApi {
@Resource
private SysPermissionService sysPermissionService;

@Resource
private SysPositionPermissionService sysPositionPermissionService;

@Override
public Result<ListWithPage<SysPermission>> page(
QueryCondition<SysPermission> condition
Expand Down Expand Up @@ -110,12 +115,14 @@ public Result<String> updateOrder(

@Override
public Result<String> disable(List<String> permissionIds) {
AssertUtil.notEmpty(permissionIds);
sysPermissionService.disable(permissionIds);
return Result.ok();
}

@Override
public Result<String> enable(List<String> permissionIds) {
AssertUtil.notEmpty(permissionIds);
sysPermissionService.enable(permissionIds);
return Result.ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
import com.zerolinck.passiflora.common.util.AssertUtil;
import com.zerolinck.passiflora.common.util.QueryCondition;
import com.zerolinck.passiflora.feign.system.SysPositionApi;
import com.zerolinck.passiflora.model.system.dto.PositionPermissionSaveDto;
import com.zerolinck.passiflora.model.system.entity.SysPosition;
import com.zerolinck.passiflora.model.system.vo.SysPositionVo;
import com.zerolinck.passiflora.system.service.SysPositionPermissionService;
import com.zerolinck.passiflora.system.service.SysPositionService;
import jakarta.annotation.Resource;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author linck
* @since 2024-05-14
Expand All @@ -45,6 +48,9 @@ public class SysPositionController implements SysPositionApi {
@Resource
private SysPositionService sysPositionService;

@Resource
private SysPositionPermissionService sysPositionPermissionService;

@Override
public Result<ListWithPage<SysPosition>> page(
QueryCondition<SysPosition> condition
Expand Down Expand Up @@ -111,4 +117,16 @@ public Result<String> updateOrder(List<SysPositionVo> sysPositionVos) {
sysPositionService.updateOrder(sysPositionVos);
return Result.ok();
}

@Override
public Result<List<String>> permissionIdsByPositionIds(List<String> positionIds) {
AssertUtil.notEmpty(positionIds);
return Result.ok(sysPositionPermissionService.permissionIdsByPositionIds(positionIds));
}

@Override
public Result<String> savePositionPermission(PositionPermissionSaveDto positionPermissionSaveDto) {
sysPositionPermissionService.savePositionPermission(positionPermissionSaveDto);
return Result.ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zerolinck.passiflora.model.system.entity.SysPermission;
import com.zerolinck.passiflora.model.system.vo.SysPermissionTableVo;
import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;

/**
* @author linck
* @since 2024-05-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zerolinck.passiflora.model.system.entity.SysPositionPermission;
import java.util.Collection;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
* @author linck
* @since 2024-05-06
Expand All @@ -49,4 +51,6 @@ int deleteByPositionIds(
@Param("positionIds") Collection<String> positionIds,
@Param("updateBy") String updateBy
);

List<String> permissionIdsByPositionIds(@Param("positionIds") List<String> positionIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@
</foreach>
</delete>


<select id="permissionIdsByPositionIds" resultType="java.lang.String">
SELECT permission_id from sys_permission
WHERE permission_status = 1
AND del_flag = 0
AND permission_id IN (
SELECT permission_id from sys_position_permission
WHERE del_flag = 0
AND position_id IN
<foreach item="id" index="index" collection="positionIds" open="(" separator="," close=")">
#{id}
</foreach>
)
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
import com.zerolinck.passiflora.model.system.vo.SysPermissionTableVo;
import com.zerolinck.passiflora.model.system.vo.SysPermissionVo;
import com.zerolinck.passiflora.system.mapper.SysPermissionMapper;
import java.util.*;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
* @author linck
* @since 2024-05-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
*/
package com.zerolinck.passiflora.system.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zerolinck.passiflora.common.exception.BizException;
import com.zerolinck.passiflora.common.util.CurrentUtil;
import com.zerolinck.passiflora.common.util.OnlyFieldCheck;
import com.zerolinck.passiflora.common.util.QueryCondition;
import com.zerolinck.passiflora.common.util.SetUtil;
import com.zerolinck.passiflora.common.util.lock.LockUtil;
import com.zerolinck.passiflora.common.util.lock.LockWrapper;
import com.zerolinck.passiflora.model.system.dto.PositionPermissionSaveDto;
import com.zerolinck.passiflora.model.system.entity.SysPositionPermission;
import com.zerolinck.passiflora.system.mapper.SysPositionPermissionMapper;
import java.util.Collection;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
* @author linck
* @since 2024-05-06
Expand Down Expand Up @@ -104,4 +108,36 @@ public SysPositionPermission detail(String bindId) {
}
return sysPositionPermission;
}

public List<String> permissionIdsByPositionIds(List<String> positionIds) {
return baseMapper.permissionIdsByPositionIds(positionIds);
}

public void savePositionPermission(PositionPermissionSaveDto positionPermissionSaveDto) {
LockUtil.lockAndTransactionalLogic(LOCK_KEY + "sysPosition",
new LockWrapper<PositionPermissionSaveDto>()
.lock(PositionPermissionSaveDto::getPositionId, positionPermissionSaveDto.getPositionId())
,
() -> {
Set<String> exitPermissionIdSet = new HashSet<>(this.permissionIdsByPositionIds(List.of(positionPermissionSaveDto.getPositionId())));
Set<String> newPermissionIdSet = new HashSet<>(positionPermissionSaveDto.getPermissionIds());
Set<String> needAdd = SetUtil.differenceSet2FromSet1(exitPermissionIdSet, newPermissionIdSet);
Set<String> needDelete = SetUtil.differenceSet2FromSet1(newPermissionIdSet, exitPermissionIdSet);
if (CollectionUtil.isNotEmpty(needDelete)) {
this.deleteByIds(needDelete);
}
if (CollectionUtil.isNotEmpty(needAdd)) {
List<SysPositionPermission> addList = new ArrayList<>();
needAdd.forEach(permissionId -> {
SysPositionPermission sysPositionPermission = new SysPositionPermission();
sysPositionPermission.setPositionId(positionPermissionSaveDto.getPositionId());
sysPositionPermission.setPermissionId(permissionId);
addList.add(sysPositionPermission);
});
this.saveBatch(addList);
}
return null;
}
);
}
}
16 changes: 8 additions & 8 deletions passiflora-ui/src/api/system/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface permissionPageParams
extends Partial<PermissionRecord>,
BasePageParam {}

export function menuPage(params: permissionPageParams) {
export function permissionPage(params: permissionPageParams) {
return axios.get<Result<Page<PermissionRecord>>>(
'/system-api/sysPermission/page',
{
Expand All @@ -40,43 +40,43 @@ export function permissionTableTree() {
);
}

export function menuUpdateOrder(data: PermissionRecord[]) {
export function permissionUpdateOrder(data: PermissionRecord[]) {
return axios.post<Result<string>>(
'/system-api/sysPermission/updateOrder',
data
);
}

export function menuAdd(data: PermissionRecord) {
export function permissionAdd(data: PermissionRecord) {
return axios.post<Result<string>>('/system-api/sysPermission/add', data);
}

export function menuUpdate(data: PermissionRecord) {
export function permissionUpdate(data: PermissionRecord) {
return axios.post<Result<string>>('/system-api/sysPermission/update', data);
}

export function menuDetail(data: string) {
export function permissionDetail(data: string) {
return axios.post<Result<PermissionRecord>>(
'/system-api/sysPermission/detail',
data
);
}

export function menuDelete(data: string[]) {
export function permissionDelete(data: string[]) {
return axios.post<Result<PermissionRecord>>(
'/system-api/sysPermission/delete',
data
);
}

export function menuDisable(data: string[]) {
export function permissionDisable(data: string[]) {
return axios.post<Result<PermissionRecord>>(
'/system-api/sysPermission/disable',
data
);
}

export function menuEnable(data: string[]) {
export function permissionEnable(data: string[]) {
return axios.post<Result<PermissionRecord>>(
'/system-api/sysPermission/enable',
data
Expand Down
Loading

0 comments on commit cab10ca

Please sign in to comment.