From 27ba31bf4f2e535b255fcebe11eeecec65cbcef8 Mon Sep 17 00:00:00 2001 From: "WIN-IDGBLFHC1K6\\Administrator" <787952492@qq.com> Date: Thu, 30 Jun 2022 13:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=20=E5=92=8C=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=20actions=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/task/vo/TaskBaseVO.java | 30 ++++++++++++++++++- .../dal/dataobject/project/ProjectDO.java | 28 +++++++++++++++++ .../service/project/ProjectServiceImpl.java | 1 - 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java index cdb3151b..4f63f860 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java @@ -1,9 +1,16 @@ package cn.iocoder.yudao.module.farm.controller.admin.task.vo; +import cn.hutool.extra.spring.SpringUtil; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; +import cn.iocoder.yudao.module.system.service.permission.RoleService; import com.alibaba.fastjson.JSONArray; import cn.iocoder.yudao.module.farm.enums.TaskStatus; import com.fasterxml.jackson.annotation.JsonManagedReference; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.collect.Maps; import lombok.*; import java.util.*; import io.swagger.annotations.*; @@ -16,7 +23,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class TaskBaseVO { +public class TaskBaseVO extends BaseDO { private Long projectId; private Long cropId; @@ -56,4 +63,25 @@ public class TaskBaseVO { private Boolean draft = false; private Boolean pretendDelete; + + private Map actions; + public Map getActions() { + actions = Maps.newHashMap(); + // 当前用户是否有资格编辑删除这个项目 + + RoleService roleService = SpringUtil.getBean("roleServiceImpl"); + + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + assert loginUser != null; + List roles = roleService.getRolesFromCache(loginUser.getRoleIds()); + + Optional admin = roles.stream().filter(roleDO -> roleDO.getName().contains("管理员") || roleDO.getCode().contains("admin")).findAny(); +// // 是创建者 或者 是 租户的管理员,可以更改项目 + actions.put("edit",this.getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + // 应该加上,项目下面没有运行中的任务才可以删除 ,或者是在删除部分再做判断 ,此处只做权限显示 + actions.put("delete",this.getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + return actions; + } } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java index 872b800f..d49c2804 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java @@ -1,10 +1,16 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.project; +import cn.hutool.extra.spring.SpringUtil; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dict.Dict; +import cn.iocoder.yudao.module.system.service.permission.RoleService; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.fasterxml.jackson.annotation.JsonFormat; +import com.google.common.collect.Maps; import io.swagger.annotations.ApiModelProperty; import lombok.*; import java.util.*; @@ -81,4 +87,26 @@ public class ProjectDO extends BaseDO { @Dict(dictTable = "system_dept",dicCode = "id",dicText = "name") private Long deptId; + @TableField(exist = false) + private Map actions; + + public Map getActions() { + actions = Maps.newHashMap(); + // 当前用户是否有资格编辑删除这个项目 + RoleService roleService = SpringUtil.getBean("roleServiceImpl"); + + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + assert loginUser != null; + List roles = roleService.getRolesFromCache(loginUser.getRoleIds()); + + Optional admin = roles.stream().filter(roleDO -> roleDO.getName().contains("管理员") || roleDO.getCode().contains("admin")).findAny(); + // 是创建者 或者 是 租户的管理员,可以更改项目 + actions.put("edit",getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + // 应该加上,项目下面没有运行中的任务才可以删除 ,或者是在删除部分再做判断 ,此处只做权限显示 + actions.put("delete",getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + return actions; + } + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java index 54b25f12..efc2e0c1 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java @@ -159,7 +159,6 @@ public class ProjectServiceImpl implements ProjectService { } queryWrapperX.orderByDesc(ProjectDO::getId); - projectMapper.selectList(queryWrapperX); PageParam pageParam = new PageParam(); pageParam.setPageNo(pageDTO.getPageNum()); pageParam.setPageSize(pageDTO.getPageSize());