Compare commits

..

2 Commits

Author SHA1 Message Date
furongxin
4712f74476 Merge branch 'dev' of http://git.znkjfw.com/ak/zn-cloud into frx 2024-11-14 10:01:29 +08:00
furongxin
e0d77b7893 feat(system): 获取用户所在公司信息接口
- 新增 getUserCompanyDept 接口,用于获取用户所在公司的信息
- 实现 getUserCompanyDept 方法,通过用户ID查询所在部门,并获取该公司信息
- 在 DeptMapper 中添加 selectDeptByUserId 方法,用于根据用户ID查询部门信息
- 优化数据权限配置,移除不必要的数据权限设置
2024-11-14 10:00:51 +08:00
6 changed files with 60 additions and 2 deletions

View File

@ -95,4 +95,9 @@ public interface DeptApi {
@GetMapping("/getCompanyDept")
@Operation(summary = "获取部门类型为公司的部门信息")
CommonResult<List<DeptRespDTO>> getCompanyDept();
@GetMapping("/getUserCompanyDept")
@Operation(summary = "获取用户所在公司的信息")
@Parameter(name = "userId", description = "用户编号", example = "1024", required = true)
CommonResult<DeptRespDTO> getUserCompanyDept(@RequestParam("userId") Long userId);
}

View File

@ -134,4 +134,12 @@ public class DeptApiImpl implements DeptApi {
List<DeptDO> deptDOS = deptService.getCompanyDept();
return success(BeanUtils.toBean(deptDOS, DeptRespDTO.class));
}
@Override
@DataPermission(enable = false)
public CommonResult<DeptRespDTO> getUserCompanyDept(Long userId) {
DeptDO deptDO = deptService.getUserCompanyDept(userId);
return success(BeanUtils.toBean(deptDO, DeptRespDTO.class));
}
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.system.dal.mysql.dept;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
@ -46,4 +49,15 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
return selectList(new LambdaQueryWrapperX<DeptDO>().orderByAsc(DeptDO::getFlag));
}
default DeptDO selectDeptByUserId(Long userId) {
MPJLambdaWrapperX<DeptDO> query = new MPJLambdaWrapperX<DeptDO>();
query.selectAll(DeptDO.class);
query.innerJoin(AdminUserDO.class, on -> on
.eq(AdminUserDO::getDeptId, DeptDO::getId)
.eq(AdminUserDO::getId, userId));
return selectJoinOne(DeptDO.class, query);
}
}

View File

@ -23,7 +23,6 @@ public class DataPermissionConfiguration {
// dept
rule.addDeptColumn(AdminUserDO.class);
rule.addDeptColumn(DeptDO.class, "id");
rule.addDeptColumn(LogUseDO.class, "use_user_dept");
rule.addDeptColumn(LogStatisticsDO.class, "dept_id");
rule.addDeptColumn(LogInstanceDO.class, "dept_id");
rule.addDeptColumn(DeptAssetsDO.class, "dept_id");
@ -31,7 +30,6 @@ public class DataPermissionConfiguration {
// user
rule.addUserColumn(AdminUserDO.class, "id");
rule.addUserColumn(LogUseDO.class, "use_user_id");
rule.addUserColumn(LogStatisticsDO.class, "user_id");
rule.addUserColumn(LogInstanceDO.class, "start_user_id");
};

View File

@ -160,4 +160,11 @@ public interface DeptService {
* @return
*/
List<DeptDO> getDeptListByFactoryIds(List<Long> factoryIds);
/**
* 获取用户所在公司的信息
* @param userId 用户编号
* @return 公司信息
*/
DeptDO getUserCompanyDept(Long userId);
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.service.dept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -24,6 +25,7 @@ import java.util.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.TASK_OPERATE_FAIL_USER_NO_DEPT;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
@ -319,6 +321,7 @@ public class DeptServiceImpl implements DeptService {
}
@Override
@DataPermission(enable = false)
public List<DeptDO> getCompanyDept() {
return deptMapper.selectList(new LambdaQueryWrapperX<DeptDO>()
@ -345,4 +348,27 @@ public class DeptServiceImpl implements DeptService {
return deptMapper.selectList(new LambdaQueryWrapper<DeptDO>()
.in(DeptDO::getFactoryId, factoryIds));
}
@Override
@DataPermission(enable = false)
public DeptDO getUserCompanyDept(Long userId) {
// 获取用户所在部门信息
DeptDO deptDo = deptMapper.selectDeptByUserId(userId);
if (deptDo == null) {
throw exception(TASK_OPERATE_FAIL_USER_NO_DEPT);
}
// 根据所在部门信息获取 所在公司信息
List<DeptDO> companyDeptList = deptMapper.selectList(new LambdaQueryWrapperX<DeptDO>()
.likeIfPresent(DeptDO::getFlag, deptDo.getFlag())
.eq(DeptDO::getType, 0));
if (CollectionUtil.isEmpty(companyDeptList)) {
return new DeptDO();
}
return companyDeptList.get(0);
}
}