Commit 62f37383 authored by zhengyi's avatar zhengyi

提供跟进列表数据权限接口供前端调用调试(后端数据权限查询业务待完善)

parent 32cd78e1
......@@ -124,4 +124,9 @@ public class CustomerFollowupQueryVO extends PageParam {
@ApiModelProperty(value = "联系人电话")
private String contactPhone;
@ApiModelProperty(value = "操作用户的所属权限部门ID列表")
private List<Long> deptIdList;
}
package cn.iocoder.yudao.module.customer.controller.admin.customerFollowup;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.customer.dto.CustomerExportReqDTO;
import cn.iocoder.yudao.module.sale.vo.offer.OfferPageReqVO;
import cn.iocoder.yudao.module.system.api.file.FileMakeApi;
import cn.iocoder.yudao.module.system.api.file.dto.FileMakeReqDTO;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.api.permission.dto.RoleRespDTO;
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.system.enums.download.DownloadTypeEnum;
import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......@@ -19,10 +27,14 @@ import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ROLE_NOT_EXISTS;
import cn.iocoder.yudao.module.customer.vo.customerFollowup.*;
import cn.iocoder.yudao.module.customer.dal.dataobject.customerFollowup.CustomerFollowupDO;
import cn.iocoder.yudao.module.customer.convert.customerFollowup.CustomerFollowupConvert;
......@@ -37,7 +49,8 @@ public class CustomerFollowupController {
@Resource
private CustomerFollowupService followupService;
@Resource
private RoleApi roleApi;
@Resource
private FileMakeApi fileMakeApi;
......@@ -110,6 +123,48 @@ public class CustomerFollowupController {
return success(CustomerFollowupConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/data/space/page")
@ApiOperation("数据权限获得客户跟进分页")
// @PreAuthorize("@ss.hasPermission('customer:followup:query')")
public CommonResult<PageResult<CustomerFollowupBackVO>> getDataSpaceFollowupPage(@Valid CustomerFollowupQueryVO query, PageVO page) {
if (Objects.isNull(query)) {
query = new CustomerFollowupQueryVO();
}
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (Objects.isNull(loginUser)){
throw exception(ErrorCodeConstants.USER_NOT_EXISTS);
}
List<RoleRespDTO> roleRespDTOS = roleApi.getRoles(loginUser.getRoleIds());
if (Objects.isNull(roleRespDTOS)){
throw exception(ROLE_NOT_EXISTS);
}
addDataScopeQuery(query, loginUser, roleRespDTOS);
PageResult<CustomerFollowupDO> pageResult = followupService.getFollowupPage(query, page);
return success(CustomerFollowupConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/data/space/export-excel")
@ApiOperation("数据权限导出客户跟进 Excel")
@OperateLog(type = EXPORT)
public CommonResult<Boolean> exportDataSpaceFollowupExcel(@Valid CustomerFollowupQueryVO query,
HttpServletResponse response) throws IOException {
if (Objects.isNull(query)) {
query = new CustomerFollowupQueryVO();
}
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (Objects.isNull(loginUser)){
throw exception(ErrorCodeConstants.USER_NOT_EXISTS);
}
List<RoleRespDTO> roleRespDTOS = roleApi.getRoles(loginUser.getRoleIds());
if (Objects.isNull(roleRespDTOS)){
throw exception(ROLE_NOT_EXISTS);
}
addDataScopeQuery(query, loginUser, roleRespDTOS);
sendFileMake(query, DownloadTypeEnum.CUSTOMER_FOLLOWUP_EXPORT, "跟进纪录导出Excel");
return success(true);
}
@GetMapping("/export-excel")
@ApiOperation("导出客户跟进 Excel")
// @PreAuthorize("@ss.hasPermission('customer:followup:export')")
......@@ -140,4 +195,44 @@ public class CustomerFollowupController {
}
private static void addDataScopeQuery(CustomerFollowupQueryVO query, LoginUser loginUser, List<RoleRespDTO> roleRespDTOS) {
List<Long> deptIdList = new ArrayList<>();
boolean isAll = Boolean.FALSE;
for (RoleRespDTO roleRespDTO : roleRespDTOS) {
DataScopeEnum dataScopeEnum = DataScopeEnum.valueOf(roleRespDTO.getDataScope());
switch (dataScopeEnum){
case ALL:
// 全部数据权限,不限制
isAll = Boolean.TRUE;
break;
case DEPT_CUSTOM:
// 指定部门数据权限
if (CollectionUtil.isNotEmpty(roleRespDTO.getDataScopeDeptIds())) {
deptIdList.addAll(roleRespDTO.getDataScopeDeptIds());
}
break;
case DEPT_ONLY:
// 部门数据权限
if (Objects.nonNull(loginUser.getDeptId())) {
deptIdList.add(loginUser.getDeptId());
}
break;
case DEPT_AND_CHILD:
// 部门及以下数据权限
deptIdList.add(loginUser.getDeptId());
break;
}
}
if (!isAll){
// 非全部数据权限时查询限制条件
if (CollectionUtil.isEmpty(deptIdList) || deptIdList.size() == 0){
// 没有部门限制条件时,只查询当前用户自己的
query.setFollowUserId(String.valueOf(loginUser.getId()));
}else {
// 查询限定部门的数据
query.setDeptIdList(deptIdList);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment