```feat(dept):增加获取部门子部门列表接口和支持多部门查询

新增一个接口用于获取指定部门的所有子部门id列表,并在相关服务中添加实现。同时,对财务支付和工作日志统计功能进行优化,支持多部门查询。

重构财务支付和工作日志统计的查询逻辑,以支持通过部门id列表进行查询,提高查询效率和灵活性。在FinancialPaymentPageReqVO和LogStatisticsDetailsListGroupByUserDTO中添加deptIds字段,用于存放部门id列表。

BREAKING CHANGE: 部门id列表查询功能的引入可能会影响现有的接口调用方式,确保在使用时指定正确的部门id列表。

相关文件修改:
- application-local.yaml: 更新数据库连接信息
- DeptApi.java: 新增获取子部门列表接口
- DeptApiImpl.java: 实现新增的子部门列表接口
- FinancialPaymentMapper.xml: 优化部门id查询逻辑- FinancialPaymentPageReqVO.java: 添加deptIds字段
- FinancialPaymentServiceImpl.java: 支持多部门查询
- LogStatisticsDetailsListGroupByUserDTO.java: 添加deptIds字段
- LogStatisticsMapper.xml:优化部门id查询逻辑
- LogStatisticsServiceImpl.java: 支持多部门查询
```
This commit is contained in:
aikai 2024-08-29 15:34:57 +08:00
parent 838ade5472
commit 85eca99cc1
9 changed files with 73 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -53,4 +54,6 @@ public class FinancialPaymentPageReqVO extends PageParam {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] endTime;
@Schema(description = "部门ids")
private List<Long> deptIds;
}

View File

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.bpm.service.financialpayment;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.Constants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
@ -26,6 +28,7 @@ import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOAReimbursementMapper;
import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmProcessInstanceExtMapper;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
@ -36,6 +39,8 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
@ -68,6 +73,8 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
private AdminUserApi userApi;
@Resource
private BpmProcessInstanceExtMapper processInstanceExtMapper;
@Resource
private DeptApi deptApi;
@Override
public Long createFinancialPayment(FinancialPaymentSaveVO vo) {
@ -152,6 +159,15 @@ public class FinancialPaymentServiceImpl implements FinancialPaymentService {
@Override
public PageResult<FinancialPaymentDO> getFinancialPaymentPage(FinancialPaymentPageReqVO pageReqVO) {
pageReqVO.setReceiveUserId(getLoginUserId());
List<Long> deptIds = new ArrayList<>();
if (pageReqVO.getDeptId() != null) {
deptIds.add(pageReqVO.getDeptId());
CommonResult<List<Long>> childDeptList = deptApi.getChildDeptList(pageReqVO.getDeptId());
if (childDeptList.isSuccess()) {
deptIds.addAll(childDeptList.getData());
}
pageReqVO.setDeptIds(deptIds);
}
IPage<FinancialPaymentDO> vos = financialPaymentMapper.getFinancialPaymentPage(pageReqVO, MyBatisUtils.buildPage(pageReqVO));
return new PageResult<>(vos.getRecords(), vos.getTotal());
}

View File

@ -22,8 +22,11 @@
left join system_users as d on a.receive_user_id = d.id
<where>
a.deleted = 0
<if test="vo.deptId != null">
and c.id = #{vo.deptId}
<if test="vo.deptIds != null and vo.deptIds.size() > 0">
AND c.id IN
<foreach collection="vo.deptIds" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</if>
<if test="vo.nickname != null and vo.nickname != ''">
and b.nickname like concat('%', #{vo.nickname}, '%')

View File

@ -41,25 +41,25 @@ spring:
primary: master
datasource:
master:
name: ruoyi-vue-pro
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
name: ruoyi-vue-pro-dev
url: jdbc:mysql://rm-bp1yloyj508qld78jno.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例
username: root
password: 123456
password: Znalyrds2024
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
slave: # 模拟从库,可根据自己需要修改
name: ruoyi-vue-pro
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
name: ruoyi-vue-pro-dev
url: jdbc:mysql://rm-bp1yloyj508qld78jno.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例
username: root
password: 123456
password: Znalyrds2024
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W

View File

@ -42,7 +42,7 @@ public interface DeptApi {
@GetMapping(PREFIX + "/getByLeaderId")
@Operation(summary = "获取特定部门信息")
@Parameter(name = "leaderUserId", description = "部门负责人", example = "12", required = true)
CommonResult<List<DeptRespDTO>> getDeptByLeaderId(@RequestParam("leaderUserId")Long leaderUserId);
CommonResult<List<DeptRespDTO>> getDeptByLeaderId(@RequestParam("leaderUserId") Long leaderUserId);
@GetMapping(PREFIX + "/getList")
@Operation(summary = "获取所有部门信息")
@ -81,4 +81,9 @@ public interface DeptApi {
List<DeptRespDTO> list = getDeptList(ids).getCheckedData();
return CollectionUtils.convertMap(list, DeptRespDTO::getId);
}
@GetMapping(PREFIX + "/getChildDeptList")
@Operation(summary = "获得指定部门的所有子部门id")
@Parameter(name = "deptId", description = "用户id", example = "146", required = true)
CommonResult<List<Long>> getChildDeptList(@RequestParam("deptId") Long deptId);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.api.dept;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -14,7 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -108,4 +111,14 @@ public class DeptApiImpl implements DeptApi {
List<DeptDO> deptDOS = deptService.getDeptByLeaderId(userId);
return success(BeanUtils.toBean(deptDOS, DeptRespDTO.class));
}
@Override
public CommonResult<List<Long>> getChildDeptList(Long deptId) {
List<DeptDO> deptDOS = deptService.getChildDeptList(deptId);
if (CollectionUtil.isEmpty(deptDOS)) {
return success(Collections.emptyList());
}
List<Long> ids = deptDOS.stream().map(DeptDO::getId).collect(Collectors.toList());
return success(ids);
}
}

View File

@ -28,4 +28,8 @@ public class LogStatisticsDetailsListGroupByUserDTO {
*/
private List<String> dateList;
/**
* 部门ids
*/
private List<Long> deptIds;
}

View File

@ -17,16 +17,18 @@ import cn.iocoder.yudao.module.system.controller.admin.worklog.dto.statistics.My
import cn.iocoder.yudao.module.system.controller.admin.worklog.dto.statistics.NeedWriteHistoryDTO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statistics.*;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statisticsrecord.LogStatisticsDetailsListGroupByUserVO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statisticsrecord.LogStatisticsGroupByUserVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.*;
import cn.iocoder.yudao.module.system.dal.mysql.worklog.LogFormMapper;
import cn.iocoder.yudao.module.system.dal.mysql.worklog.LogStatisticsMapper;
import cn.iocoder.yudao.module.system.dal.mysql.worklog.LogUseMapper;
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import cn.iocoder.yudao.module.system.service.worklog.dto.LogUseVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -57,6 +59,9 @@ public class LogStatisticsServiceImpl implements LogStatisticsService {
@Resource
private LogStatisticsMapper logStatisticsMapper;
@Resource
@Lazy
private DeptService deptService;
@Override
public Long createLogStatistics(LogStatisticsSaveReqVO createReqVO) {
@ -406,6 +411,15 @@ public class LogStatisticsServiceImpl implements LogStatisticsService {
throw exception(ErrorCodeConstants.PLEASE_SELECT_A_TIME_RANGE);
}
dto.setDateList(dateList);
List<Long> deptIds = new ArrayList<>();
if (dto.getDeptId() != null) {
deptIds.add(dto.getDeptId());
List<DeptDO> deptList = deptService.getChildDeptList(dto.getDeptId());
if (CollectionUtil.isNotEmpty(deptList)) {
deptIds.addAll(deptList.stream().map(DeptDO::getId).collect(Collectors.toList()));
}
dto.setDeptIds(deptIds);
}
// 获取到所有数据 然后在java代码中分组
List<LogStatisticsDetailsVO> vos = logStatisticsMapper.getStatisticsGroupByUser(dto);
// 根据用户id/部门id分组

View File

@ -175,10 +175,12 @@
<if test="dto.type != null">
and b.type = #{dto.type}
</if>
<if test="dto.deptId != null">
and b.dept_id = #{dto.deptId}
<if test="dto.deptIds != null and dto.deptIds.size() > 0">
AND b.dept_id IN
<foreach collection="dto.deptIds" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</if>
</where>
</select>
</mapper>