diff --git a/passiflora-server/modules/passiflora-common/src/main/java/com/zerolinck/passiflora/common/util/SetUtil.java b/passiflora-server/modules/passiflora-common/src/main/java/com/zerolinck/passiflora/common/util/SetUtil.java new file mode 100644 index 0000000..cde49af --- /dev/null +++ b/passiflora-server/modules/passiflora-common/src/main/java/com/zerolinck/passiflora/common/util/SetUtil.java @@ -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 differenceSet2FromSet1(Set set1, Set set2) { + Set difference = new HashSet<>(set2); + difference.removeAll(set1); + return difference; + } + +} diff --git a/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPermissionApi.java b/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPermissionApi.java index aa65263..970951c 100644 --- a/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPermissionApi.java +++ b/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPermissionApi.java @@ -27,7 +27,6 @@ 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; @@ -35,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; + /** * @author linck * @since 2024-05-06 diff --git a/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPositionApi.java b/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPositionApi.java index 268dc1c..eeee513 100644 --- a/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPositionApi.java +++ b/passiflora-server/modules/passiflora-feign/src/main/java/com/zerolinck/passiflora/feign/system/SysPositionApi.java @@ -20,13 +20,13 @@ 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; @@ -34,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; + /** * @author linck * @since 2024-05-14 @@ -91,4 +93,16 @@ Result detail( Result updateOrder( @RequestBody @Validated(Update.class) List sysPositionVos ); + + @Operation(summary = "根据职位ids获取权限ids") + @PostMapping("permissionIdsByPositionIds") + Result> permissionIdsByPositionIds( + @RequestBody List positionIds + ); + + @Operation(summary = "保存职位权限") + @PostMapping("savePositionPermission") + Result savePositionPermission( + @RequestBody @Validated PositionPermissionSaveDto positionPermissionSaveDto + ); } diff --git a/passiflora-server/modules/passiflora-model/src/main/java/com/zerolinck/passiflora/model/system/dto/PositionPermissionSaveDto.java b/passiflora-server/modules/passiflora-model/src/main/java/com/zerolinck/passiflora/model/system/dto/PositionPermissionSaveDto.java new file mode 100644 index 0000000..6577c49 --- /dev/null +++ b/passiflora-server/modules/passiflora-model/src/main/java/com/zerolinck/passiflora/model/system/dto/PositionPermissionSaveDto.java @@ -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 permissionIds; +} diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPermissionController.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPermissionController.java index 7be378b..639ff19 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPermissionController.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPermissionController.java @@ -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 @@ -46,6 +48,9 @@ public class SysPermissionController implements SysPermissionApi { @Resource private SysPermissionService sysPermissionService; + @Resource + private SysPositionPermissionService sysPositionPermissionService; + @Override public Result> page( QueryCondition condition @@ -110,12 +115,14 @@ public Result updateOrder( @Override public Result disable(List permissionIds) { + AssertUtil.notEmpty(permissionIds); sysPermissionService.disable(permissionIds); return Result.ok(); } @Override public Result enable(List permissionIds) { + AssertUtil.notEmpty(permissionIds); sysPermissionService.enable(permissionIds); return Result.ok(); } diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPositionController.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPositionController.java index 4d70108..f4e9bc9 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPositionController.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/controller/SysPositionController.java @@ -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 @@ -45,6 +48,9 @@ public class SysPositionController implements SysPositionApi { @Resource private SysPositionService sysPositionService; + @Resource + private SysPositionPermissionService sysPositionPermissionService; + @Override public Result> page( QueryCondition condition @@ -111,4 +117,16 @@ public Result updateOrder(List sysPositionVos) { sysPositionService.updateOrder(sysPositionVos); return Result.ok(); } + + @Override + public Result> permissionIdsByPositionIds(List positionIds) { + AssertUtil.notEmpty(positionIds); + return Result.ok(sysPositionPermissionService.permissionIdsByPositionIds(positionIds)); + } + + @Override + public Result savePositionPermission(PositionPermissionSaveDto positionPermissionSaveDto) { + sysPositionPermissionService.savePositionPermission(positionPermissionSaveDto); + return Result.ok(); + } } diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPermissionMapper.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPermissionMapper.java index f59ba3c..0d1ef3e 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPermissionMapper.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPermissionMapper.java @@ -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 diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPositionPermissionMapper.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPositionPermissionMapper.java index e00487b..df33b9d 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPositionPermissionMapper.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/SysPositionPermissionMapper.java @@ -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 @@ -49,4 +51,6 @@ int deleteByPositionIds( @Param("positionIds") Collection positionIds, @Param("updateBy") String updateBy ); + + List permissionIdsByPositionIds(@Param("positionIds") List positionIds); } diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/xml/SysPositionPermissionMapper.xml b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/xml/SysPositionPermissionMapper.xml index 957bff0..8e2a3ba 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/xml/SysPositionPermissionMapper.xml +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/mapper/xml/SysPositionPermissionMapper.xml @@ -43,4 +43,18 @@ + + \ No newline at end of file diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPermissionService.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPermissionService.java index 51485f5..de59161 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPermissionService.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPermissionService.java @@ -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 diff --git a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPositionPermissionService.java b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPositionPermissionService.java index 6d77163..1ddebec 100644 --- a/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPositionPermissionService.java +++ b/passiflora-server/passiflora-system-app/src/main/java/com/zerolinck/passiflora/system/service/SysPositionPermissionService.java @@ -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 @@ -104,4 +108,36 @@ public SysPositionPermission detail(String bindId) { } return sysPositionPermission; } + + public List permissionIdsByPositionIds(List positionIds) { + return baseMapper.permissionIdsByPositionIds(positionIds); + } + + public void savePositionPermission(PositionPermissionSaveDto positionPermissionSaveDto) { + LockUtil.lockAndTransactionalLogic(LOCK_KEY + "sysPosition", + new LockWrapper() + .lock(PositionPermissionSaveDto::getPositionId, positionPermissionSaveDto.getPositionId()) + , + () -> { + Set exitPermissionIdSet = new HashSet<>(this.permissionIdsByPositionIds(List.of(positionPermissionSaveDto.getPositionId()))); + Set newPermissionIdSet = new HashSet<>(positionPermissionSaveDto.getPermissionIds()); + Set needAdd = SetUtil.differenceSet2FromSet1(exitPermissionIdSet, newPermissionIdSet); + Set needDelete = SetUtil.differenceSet2FromSet1(newPermissionIdSet, exitPermissionIdSet); + if (CollectionUtil.isNotEmpty(needDelete)) { + this.deleteByIds(needDelete); + } + if (CollectionUtil.isNotEmpty(needAdd)) { + List 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; + } + ); + } } diff --git a/passiflora-ui/src/api/system/permission.ts b/passiflora-ui/src/api/system/permission.ts index deb5d3f..662cbd4 100644 --- a/passiflora-ui/src/api/system/permission.ts +++ b/passiflora-ui/src/api/system/permission.ts @@ -22,7 +22,7 @@ export interface permissionPageParams extends Partial, BasePageParam {} -export function menuPage(params: permissionPageParams) { +export function permissionPage(params: permissionPageParams) { return axios.get>>( '/system-api/sysPermission/page', { @@ -40,43 +40,43 @@ export function permissionTableTree() { ); } -export function menuUpdateOrder(data: PermissionRecord[]) { +export function permissionUpdateOrder(data: PermissionRecord[]) { return axios.post>( '/system-api/sysPermission/updateOrder', data ); } -export function menuAdd(data: PermissionRecord) { +export function permissionAdd(data: PermissionRecord) { return axios.post>('/system-api/sysPermission/add', data); } -export function menuUpdate(data: PermissionRecord) { +export function permissionUpdate(data: PermissionRecord) { return axios.post>('/system-api/sysPermission/update', data); } -export function menuDetail(data: string) { +export function permissionDetail(data: string) { return axios.post>( '/system-api/sysPermission/detail', data ); } -export function menuDelete(data: string[]) { +export function permissionDelete(data: string[]) { return axios.post>( '/system-api/sysPermission/delete', data ); } -export function menuDisable(data: string[]) { +export function permissionDisable(data: string[]) { return axios.post>( '/system-api/sysPermission/disable', data ); } -export function menuEnable(data: string[]) { +export function permissionEnable(data: string[]) { return axios.post>( '/system-api/sysPermission/enable', data diff --git a/passiflora-ui/src/views/organization/position/index.vue b/passiflora-ui/src/views/organization/position/index.vue index 89a0923..26fbab3 100644 --- a/passiflora-ui/src/views/organization/position/index.vue +++ b/passiflora-ui/src/views/organization/position/index.vue @@ -142,6 +142,12 @@ 编辑 + 权限 @@ -238,6 +244,32 @@ + + +
+ +
+
@@ -245,6 +277,11 @@ import { computed, ref, reactive, watch, nextTick, onMounted, h } from 'vue'; import useLoading from '@/hooks/loading'; import { + PermissionRecord, + permissionTableTree, + } from '@/api/system/permission'; + import { + positionPermissionSaveDto, PositionRecord, positionTree, positionDelete, @@ -253,6 +290,8 @@ positionUpdateOrder, positionDisable, positionEnable, + permissionIdsByPositionIds, + savePositionPermission, } from '@/api/organization/position'; import { TableColumnData, @@ -276,6 +315,8 @@ const cloneColumns = ref([]); const showColumns = ref([]); const selectedKeys = ref([]); + const permissionCheckedKeys = ref([]); + const permissionTreeModel = ref([]); const size = ref('large'); @@ -361,7 +402,6 @@ ); }; - const appStore = useAppStore(); const tableChange = async (a: PositionRecord[]) => { renderData.value = a; assignOrder(renderData.value); @@ -488,6 +528,15 @@ editFormVisible.value = true; }; + const permissionButton = async (recode: PositionRecord) => { + const { data } = await permissionTableTree(); + permissionTreeModel.value = data.data; + const req = await permissionIdsByPositionIds([recode.positionId as string]); + permissionCheckedKeys.value = req.data.data; + positionPermission.positionId = recode.positionId; + permissionFormVisible.value = true; + }; + const batchDisable = async (ids: string[]) => { const { data } = await positionDisable(ids); if (data.code === 200) { @@ -545,6 +594,27 @@ positionStatus: 1, }); }; + + const positionPermission: positionPermissionSaveDto = { + positionId: '', + permissionIds: [], + }; + // 权限抽屉 + const permissionFormVisible = ref(false); + const permissionHandleCancel = () => { + permissionFormVisible.value = false; + }; + const permissionHandleOk = async () => { + positionPermission.permissionIds = permissionCheckedKeys.value; + const { data } = await savePositionPermission(positionPermission); + if (data.code === 200) { + Message.success({ + content: `保存成功`, + duration: 5 * 1000, + }); + permissionFormVisible.value = false; + } + };