Browse Source

部分权限

zyh
Loki 3 years ago
parent
commit
cd55670218
  1. 27
      yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java
  2. 2
      yudao-ui-admin
  3. 25
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/config/FarmPermissionRuleCustomizer.java
  4. 1
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java
  5. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaBaseVO.java
  6. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaExcelVO.java
  7. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaExportReqVO.java
  8. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java
  9. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java
  10. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/area/AreaDO.java
  11. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java
  12. 32
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java
  13. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

27
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java

@ -147,33 +147,6 @@ public class YudaoSwaggerAutoConfiguration {
.securityContexts(securityContexts());
}
@Bean("ERP")
@SuppressWarnings("all")
public Docket createErpApi() {
SwaggerProperties properties = swaggerProperties();
ParameterBuilder ticketPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
ticketPar.name("token").description("token")
.modelRef(new ModelRef("string"))
.parameterType("header")
.defaultValue("token" + " ")
.required(true)
.build();
pars.add(ticketPar.build());
return new Docket(DocumentationType.SWAGGER_2)
.groupName("进销存")
.enable(true)
.apiInfo(apiInfo(properties))
.select()
.apis(RequestHandlerSelectors.basePackage("com.zsw.erp"))
.paths(PathSelectors.regex("/error.*").negate())
.build()
.globalOperationParameters(pars)
//添加登陆认证
.securitySchemes(securitySchemes())
.globalRequestParameters(globalRequestParameters())
.securityContexts(securityContexts());
}
// ========== apiInfo ==========

2
yudao-ui-admin

@ -1 +1 @@
Subproject commit 940f54e876f1c6ccc6e239c5990d34e83fb02b78
Subproject commit beb44f8aa54a4e20a48985d771a0353641df4787

25
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/config/FarmPermissionRuleCustomizer.java

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.farm.config;
import cn.iocoder.yudao.framework.datapermission.core.dept.rule.DeptDataPermissionRuleCustomizer;
import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FarmPermissionRuleCustomizer {
@Bean
public DeptDataPermissionRuleCustomizer farmCustomizer(){
return rule -> {
rule.addDeptColumn(ProjectDO.class);
// user隔离不起作用
rule.addUserColumn(ProjectDO.class,"creator");
rule.addDeptColumn(TaskDO.class);
rule.addUserColumn(TaskDO.class,"creator");
};
}
}

1
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java

@ -8,4 +8,5 @@ public class AreaDTO {
String firstAreaName;
String secondAreaName;
}

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaBaseVO.java

@ -19,6 +19,8 @@ public class AreaBaseVO {
private Long parentId;
private Double area;
private Boolean pretendDelete;

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaExcelVO.java

@ -22,6 +22,8 @@ public class AreaExcelVO {
private Long parentId;
private Double area;
@ExcelProperty("")
private Date createTime;

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/vo/AreaExportReqVO.java

@ -17,6 +17,8 @@ public class AreaExportReqVO {
private Long parentId;
private Double area;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始")
private Date beginCreateTime;

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.farm.controller.admin.project;
import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.module.farm.annotation.FarmMsg;
import cn.iocoder.yudao.module.farm.annotation.FarmMsgTypeEnum;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO;
@ -87,6 +88,7 @@ public class ProjectController {
@GetMapping("/page")
@ApiOperation("获得农场项目分页")
@DataPermission
@PreAuthorize("@ss.hasPermission('farm:project:query')")
public CommonResult<PageResult<ProjectRespVO>> getProjectPage(@Valid ProjectPageReqVO pageVO) {
PageResult<ProjectDO> pageResult = projectService.getProjectPage(pageVO);

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.task;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.module.farm.annotation.FarmMsg;
import cn.iocoder.yudao.module.farm.annotation.FarmMsgTypeEnum;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.*;
@ -90,6 +91,7 @@ public class TaskController {
@GetMapping("/page")
@ApiOperation("获得农场项目分页")
@DataPermission
@PreAuthorize("@ss.hasPermission('farm:task:query')")
public CommonResult<PageResult<TaskAssemblyDTO>> getTaskPage(@Valid TaskPageReqVO pageVO) {
PageResult<TaskAssemblyDTO> pageResult = taskService.getTaskPage(pageVO);

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/area/AreaDO.java

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.area;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@ -32,6 +34,8 @@ public class AreaDO extends BaseDO {
private Long parentId;
private Double area;
@ApiModelProperty("假装删除")
private Boolean pretendDelete;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.farm.dal.dataobject.project;
import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum;
import cn.iocoder.yudao.module.system.dict.Dict;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
@ -77,4 +78,7 @@ public class ProjectDO extends BaseDO {
@ApiModelProperty("假装删除")
private Boolean pretendDelete;
@Dict(dictTable = "system_dept",dicCode = "id",dicText = "name")
private Long deptId;
}

32
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java

@ -1,9 +1,16 @@
package cn.iocoder.yudao.module.farm.dal.dataobject.task;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.mybatis.core.handler.ListIntToListLongTypeHandler;
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.dict.Dict;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiModelProperty;
import cn.iocoder.yudao.module.farm.enums.TaskStatus;
import lombok.*;
@ -85,4 +92,29 @@ public class TaskDO extends BaseDO {
@ApiModelProperty("假装删除")
private Boolean pretendDelete;
@ApiModelProperty("部门Id")
@Dict(dictTable = "system_dept",dicCode = "id",dicText = "name")
private Long deptId;
@TableField(exist = false)
private Map<String, Boolean> actions;
public Map<String, Boolean> getActions() {
actions = Maps.newHashMap();
// 当前用户是否有资格编辑删除这个项目
RoleService roleService = SpringUtil.getBean("roleServiceImpl");
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
assert loginUser != null;
List<RoleDO> roles = roleService.getRolesFromCache(loginUser.getRoleIds());
Optional<RoleDO> 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;
}
}

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

@ -10,6 +10,7 @@ import cn.hutool.system.oshi.CpuInfo;
import cn.iocoder.yudao.framework.common.page.PageUtil;
import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO;
@ -81,6 +82,7 @@ public class ProjectServiceImpl implements ProjectService {
public Long createProject(ProjectCreateReqVO createReqVO) {
// 插入
ProjectDO project = ProjectConvert.INSTANCE.convert(createReqVO);
project.setDeptId(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUser()).getDeptId());
projectMapper.insert(project);
// 返回
return project.getId();

Loading…
Cancel
Save