Revert "refactor: 简化JobBatchServiceImpl.getJobBatchPage代码,抽取UserSessionUtils.hasGroupPermission函数"
This reverts commit 8322d510fe
.
This commit is contained in:
parent
8322d510fe
commit
278d7a9658
@ -1,5 +1,6 @@
|
||||
package com.aizuda.snailjob.server.web.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
@ -14,6 +15,7 @@ import com.aizuda.snailjob.server.web.service.JobBatchService;
|
||||
import com.aizuda.snailjob.server.web.service.convert.JobBatchResponseVOConverter;
|
||||
import com.aizuda.snailjob.server.web.service.handler.JobHandler;
|
||||
import com.aizuda.snailjob.server.web.util.UserSessionUtils;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.dataobject.JobBatchQueryDO;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.dataobject.JobBatchResponseDO;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.mapper.JobMapper;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.mapper.JobTaskBatchMapper;
|
||||
@ -21,12 +23,15 @@ import com.aizuda.snailjob.template.datasource.persistence.mapper.WorkflowNodeMa
|
||||
import com.aizuda.snailjob.template.datasource.persistence.po.Job;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.po.JobTaskBatch;
|
||||
import com.aizuda.snailjob.template.datasource.persistence.po.WorkflowNode;
|
||||
import com.aizuda.snailjob.server.web.service.convert.JobBatchResponseVOConverter;
|
||||
import com.aizuda.snailjob.server.web.service.handler.JobHandler;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -47,24 +52,46 @@ public class JobBatchServiceImpl implements JobBatchService {
|
||||
|
||||
@Override
|
||||
public PageResult<List<JobBatchResponseVO>> getJobBatchPage(final JobBatchQueryVO queryVO) {
|
||||
|
||||
PageDTO<JobTaskBatch> pageDTO = new PageDTO<>(queryVO.getPage(), queryVO.getSize());
|
||||
|
||||
UserSessionVO userSessionVO = UserSessionUtils.currentUserSession();
|
||||
if (!UserSessionUtils.hasGroupPermission(queryVO.getGroupName())) {
|
||||
return new PageResult<>(pageDTO, Lists.newArrayList());
|
||||
List<String> groupNames = Lists.newArrayList();
|
||||
if (userSessionVO.isUser()) {
|
||||
groupNames = userSessionVO.getGroupNames();
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(queryVO.getGroupName())) {
|
||||
// 说明当前组不在用户配置的权限中
|
||||
if (!CollectionUtils.isEmpty(groupNames) && !groupNames.contains(queryVO.getGroupName())) {
|
||||
return new PageResult<>(pageDTO, Lists.newArrayList());
|
||||
} else {
|
||||
groupNames = Lists.newArrayList(queryVO.getGroupName());
|
||||
}
|
||||
}
|
||||
|
||||
JobBatchQueryDO queryDO = new JobBatchQueryDO();
|
||||
if (StrUtil.isNotBlank(queryVO.getJobName())) {
|
||||
queryDO.setJobName(queryVO.getJobName() + "%");
|
||||
}
|
||||
|
||||
queryDO.setJobId(queryVO.getJobId());
|
||||
queryDO.setTaskBatchStatus(queryVO.getTaskBatchStatus());
|
||||
queryDO.setGroupNames(groupNames);
|
||||
queryDO.setNamespaceId(userSessionVO.getNamespaceId());
|
||||
QueryWrapper<JobTaskBatch> wrapper = new QueryWrapper<JobTaskBatch>()
|
||||
.eq("a.namespace_id", userSessionVO.getNamespaceId())
|
||||
.eq("a.system_task_type", SyetemTaskTypeEnum.JOB.getType())
|
||||
.eq(queryVO.getJobId() != null, "a.job_id", queryVO.getJobId())
|
||||
.eq(StrUtil.isNotBlank(queryVO.getGroupName()), "a.group_name", queryVO.getGroupName())
|
||||
.eq(queryVO.getTaskBatchStatus() != null, "task_batch_status", queryVO.getTaskBatchStatus())
|
||||
.likeRight(StrUtil.isNotBlank(queryVO.getJobName()), "job_name", queryVO.getJobName())
|
||||
.eq("a.deleted", 0)
|
||||
.orderByDesc("a.id");
|
||||
.eq("a.namespace_id", queryDO.getNamespaceId())
|
||||
.eq("a.system_task_type", 3)
|
||||
.eq(queryDO.getJobId() != null, "a.job_id", queryDO.getJobId())
|
||||
.in(CollUtil.isNotEmpty(queryDO.getGroupNames()), "a.group_name", queryDO.getGroupNames())
|
||||
.eq(queryDO.getTaskBatchStatus() != null, "task_batch_status", queryDO.getTaskBatchStatus())
|
||||
.eq(StrUtil.isNotBlank(queryDO.getJobName()), "job_name", queryDO.getJobName())
|
||||
.eq("a.deleted", 0)
|
||||
.orderByDesc("a.id");
|
||||
List<JobBatchResponseDO> batchResponseDOList = jobTaskBatchMapper.selectJobBatchPageList(pageDTO, wrapper);
|
||||
|
||||
List<JobBatchResponseVO> batchResponseVOList = JobBatchResponseVOConverter.INSTANCE.toJobBatchResponseVOs(
|
||||
batchResponseDOList);
|
||||
batchResponseDOList);
|
||||
|
||||
return new PageResult<>(pageDTO, batchResponseVOList);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.aizuda.snailjob.server.web.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.server.web.model.request.UserSessionVO;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import com.aizuda.snailjob.server.web.model.request.UserSessionVO;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2023-11-22 23:14:53
|
||||
@ -18,23 +18,4 @@ public final class UserSessionUtils {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
return (UserSessionVO) request.getAttribute("currentUser");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前用户是否具备组权限
|
||||
*
|
||||
* @param groupName 组名称
|
||||
* @return true, 具备权限,否则返回false
|
||||
*/
|
||||
public static boolean hasGroupPermission(String groupName) {
|
||||
if (StrUtil.isBlank(groupName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
UserSessionVO userSessionVO = currentUserSession();
|
||||
if (userSessionVO.isUser() && CollUtil.isNotEmpty(userSessionVO.getGroupNames())) {
|
||||
return userSessionVO.getGroupNames().contains(groupName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user