|
|
@@ -0,0 +1,469 @@
|
|
|
+package cn.start.tz.module.pressure2.service.announcement;
|
|
|
+
|
|
|
+import cn.start.tz.framework.common.pojo.CommonResult;
|
|
|
+import cn.start.tz.framework.common.pojo.PageResult;
|
|
|
+import cn.start.tz.framework.common.util.object.BeanUtils;
|
|
|
+import cn.start.tz.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.announcement.vo.AnnouncementPageReqVO;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.announcement.vo.AnnouncementSaveReqVO;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.readconfirm.vo.ReadConfirmPageReqVO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.announcement.AnnouncementDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.readconfirm.ReadConfirmDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.announcement.AnnouncementMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.readconfirm.ReadConfirmMapper;
|
|
|
+import cn.start.tz.module.pressure2.service.readconfirm.ReadConfirmService;
|
|
|
+import cn.start.tz.module.system.api.dept.DeptApi;
|
|
|
+import cn.start.tz.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import cn.start.tz.module.system.api.user.AdminUserApi;
|
|
|
+import cn.start.tz.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.start.tz.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.start.tz.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
|
|
|
+import static cn.start.tz.module.pressure2.enums.ErrorCodeConstants.*;
|
|
|
+import static cn.start.tz.module.system.enums.ErrorCodeConstants.ANNOUNCEMENT_NOT_EXISTS;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公告 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 特种管理员
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, AnnouncementDO> implements AnnouncementService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AnnouncementMapper announcementMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeptApi deptApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ReadConfirmService readConfirmService; // 新增注入
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ReadConfirmMapper readConfirmMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String createAnnouncement(AnnouncementSaveReqVO createReqVO) {
|
|
|
+ try {
|
|
|
+ log.info("开始创建公告: {}", createReqVO.getTitle());
|
|
|
+
|
|
|
+ // 插入公告,如果是多部门,前端传递的值就应该是 100,101这样
|
|
|
+ AnnouncementDO announcement = BeanUtils.toBean(createReqVO, AnnouncementDO.class);
|
|
|
+ announcementMapper.insert(announcement);
|
|
|
+
|
|
|
+ String announcementId = announcement.getId();
|
|
|
+ log.info("公告创建成功,ID: {}", announcementId);
|
|
|
+
|
|
|
+ // 获取部门下的所有用户
|
|
|
+ List<AdminUserRespDTO> users = getDistinctUsersByDepartmentAndSubDepartments(createReqVO.getDeptId());
|
|
|
+
|
|
|
+ if (users != null && !users.isEmpty()) {
|
|
|
+ log.info("找到 {} 个用户需要创建已读记录", users.size());
|
|
|
+
|
|
|
+ List<ReadConfirmDO> readConfirmList = new ArrayList<>();
|
|
|
+ for (AdminUserRespDTO user : users) {
|
|
|
+ ReadConfirmDO readConfirm = ReadConfirmDO.builder()
|
|
|
+ .userId(user.getId())
|
|
|
+ .laboratoryAnnouncementId(announcementId)
|
|
|
+ .readStatus(0)
|
|
|
+ .deptId(user.getDeptId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ readConfirmList.add(readConfirm);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量保存
|
|
|
+ if (!readConfirmList.isEmpty()) {
|
|
|
+ boolean saveResult = readConfirmService.saveBatch(readConfirmList);
|
|
|
+ if (!saveResult) {
|
|
|
+ log.error("保存已读确认记录失败");
|
|
|
+ throw new RuntimeException("保存已读确认记录失败");
|
|
|
+ }
|
|
|
+ log.info("成功创建 {} 条已读确认记录", readConfirmList.size());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("未找到部门 {} 下的用户", createReqVO.getDeptId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return announcementId;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建公告失败: {}", e.getMessage(), e);
|
|
|
+ throw e; // 抛出异常触发事务回滚
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateAnnouncement(AnnouncementSaveReqVO updateReqVO) {
|
|
|
+ try {
|
|
|
+ log.info("开始更新公告: {}", updateReqVO.getId());
|
|
|
+
|
|
|
+ // 校验存在并获取原始公告信息
|
|
|
+ AnnouncementDO originalAnnouncement = Optional.ofNullable(announcementMapper.selectById(updateReqVO.getId()))
|
|
|
+ .orElseThrow(() -> exception(ANNOUNCEMENT_NOT_EXISTS));
|
|
|
+
|
|
|
+ // 检查部门是否发生变化
|
|
|
+ boolean deptChanged = !originalAnnouncement.getDeptId().equals(updateReqVO.getDeptId());
|
|
|
+
|
|
|
+ if (deptChanged) {
|
|
|
+ log.info("公告部门发生变化,原部门: {} -> 新部门: {}",
|
|
|
+ originalAnnouncement.getDeptId(), updateReqVO.getDeptId());
|
|
|
+
|
|
|
+ // 删除原部门的已读确认记录
|
|
|
+ deleteReadConfirmByAnnouncementId(updateReqVO.getId());
|
|
|
+
|
|
|
+ // 获取新部门及其子部门的所有用户
|
|
|
+ List<AdminUserRespDTO> newDeptUsers = getDistinctUsersByDepartmentAndSubDepartments(updateReqVO.getDeptId());
|
|
|
+
|
|
|
+ // 为新部门用户创建已读确认记录
|
|
|
+ if (newDeptUsers != null && !newDeptUsers.isEmpty()) {
|
|
|
+ createReadConfirmRecords(updateReqVO.getId(), newDeptUsers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新公告
|
|
|
+ AnnouncementDO updateObj = BeanUtils.toBean(updateReqVO, AnnouncementDO.class);
|
|
|
+ announcementMapper.updateById(updateObj);
|
|
|
+
|
|
|
+ log.info("公告更新成功,ID: {}", updateReqVO.getId());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新公告失败: {}", e.getMessage(), e);
|
|
|
+ throw e; // 抛出异常触发事务回滚
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除指定公告的已读确认记录
|
|
|
+ */
|
|
|
+ private boolean deleteReadConfirmByAnnouncementId(String announcementId) {
|
|
|
+ return Optional.ofNullable(announcementId)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .map(id -> {
|
|
|
+ QueryWrapper<ReadConfirmDO> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ReadConfirmDO::getLaboratoryAnnouncementId, id);
|
|
|
+ int deleteCount = readConfirmService.remove(queryWrapper) ? 1 : 0;
|
|
|
+ log.info("删除公告 {} 的已读确认记录,删除数量: {}", id, deleteCount);
|
|
|
+ return deleteCount > 0;
|
|
|
+ })
|
|
|
+ .orElse(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 为指定公告创建已读确认记录
|
|
|
+ */
|
|
|
+ private void createReadConfirmRecords(String announcementId, List<AdminUserRespDTO> users) {
|
|
|
+ List<ReadConfirmDO> readConfirmList = users.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(user -> ReadConfirmDO.builder()
|
|
|
+ .userId(user.getId())
|
|
|
+ .laboratoryAnnouncementId(announcementId)
|
|
|
+ .readStatus(0)
|
|
|
+ .deptId(user.getDeptId())
|
|
|
+ .build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!readConfirmList.isEmpty()) {
|
|
|
+ boolean saveResult = readConfirmService.saveBatch(readConfirmList);
|
|
|
+ if (!saveResult) {
|
|
|
+ throw new RuntimeException("创建已读确认记录失败");
|
|
|
+ }
|
|
|
+ log.info("为公告 {} 创建了 {} 条已读确认记录", announcementId, readConfirmList.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteAnnouncement(String id) {
|
|
|
+ // 校验ID不为空
|
|
|
+ Optional.ofNullable(id)
|
|
|
+ .orElseThrow(() -> new IllegalArgumentException("公告ID不能为空"));
|
|
|
+
|
|
|
+ // 校验公告是否存在
|
|
|
+ AnnouncementDO announcement = Optional.ofNullable(announcementMapper.selectById(id))
|
|
|
+ .orElseThrow(() -> exception(ANNOUNCEMENT_NOT_EXISTS));
|
|
|
+
|
|
|
+ // 使用Lambda删除关联的已读确认记录
|
|
|
+ QueryWrapper<ReadConfirmDO> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ReadConfirmDO::getLaboratoryAnnouncementId, id);
|
|
|
+ readConfirmService.remove(queryWrapper);
|
|
|
+
|
|
|
+ // 删除公告
|
|
|
+ int deleteCount = announcementMapper.deleteById(id);
|
|
|
+ if (deleteCount == 0) {
|
|
|
+ throw new RuntimeException("删除公告失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("成功删除公告 {} 及其关联数据", id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateAnnouncementExists(String id) {
|
|
|
+ if (announcementMapper.selectById(id) == null) {
|
|
|
+ throw exception(ANNOUNCEMENT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AnnouncementDO getAnnouncement(String id) {
|
|
|
+ return announcementMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<AnnouncementDO> getAnnouncementPage(AnnouncementPageReqVO pageReqVO) {
|
|
|
+ String userId = getLoginUserId();
|
|
|
+
|
|
|
+ if (userId == null) {
|
|
|
+ // 用户未登录,返回空公告列表
|
|
|
+ return new PageResult<>(Collections.emptyList(), 0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建 ReadConfirmPageReqVO,并设置公告表条件
|
|
|
+ ReadConfirmPageReqVO readConfirmPageReqVO = new ReadConfirmPageReqVO();
|
|
|
+ readConfirmPageReqVO.setPageNo(pageReqVO.getPageNo());
|
|
|
+ readConfirmPageReqVO.setPageSize(pageReqVO.getPageSize());
|
|
|
+ readConfirmPageReqVO.setUserId(userId);
|
|
|
+
|
|
|
+ // 设置公告表条件
|
|
|
+ readConfirmPageReqVO.setTitle(pageReqVO.getTitle());
|
|
|
+ readConfirmPageReqVO.setType(pageReqVO.getType());
|
|
|
+// readConfirmPageReqVO.setAnnouncementDeptId(pageReqVO.getDeptId()); // 注意:AnnouncementPageReqVO 的 deptId 是公告表的部门ID
|
|
|
+// readConfirmPageReqVO.setContent(pageReqVO.getContent());
|
|
|
+// readConfirmPageReqVO.setFileUrl(pageReqVO.getFileUrl());
|
|
|
+// readConfirmPageReqVO.setFileName(pageReqVO.getFileName());
|
|
|
+
|
|
|
+ // 创建分页对象
|
|
|
+ Page<ReadConfirmDO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
|
|
|
+
|
|
|
+ // 调用联表查询方法
|
|
|
+ IPage<ReadConfirmDO> readConfirmDOPage = readConfirmMapper.selectPageWithAnnouncement(page, readConfirmPageReqVO);
|
|
|
+
|
|
|
+ // 转换为 PageResult
|
|
|
+ PageResult<ReadConfirmDO> readConfirmDOPageResult = new PageResult<>(
|
|
|
+ readConfirmDOPage.getRecords(),
|
|
|
+ readConfirmDOPage.getTotal()
|
|
|
+ );
|
|
|
+ if (readConfirmDOPageResult.getList().isEmpty()) {
|
|
|
+ return new PageResult<>(Collections.emptyList(), readConfirmDOPageResult.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取公告ID列表
|
|
|
+ List<String> announcementIds = readConfirmDOPageResult.getList().stream()
|
|
|
+ .map(ReadConfirmDO::getLaboratoryAnnouncementId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (announcementIds.isEmpty()) {
|
|
|
+ return new PageResult<>(Collections.emptyList(), readConfirmDOPageResult.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据公告ID查询公告详细信息
|
|
|
+ List<AnnouncementDO> announcements = announcementMapper.selectList(
|
|
|
+ new LambdaQueryWrapperX<AnnouncementDO>()
|
|
|
+ .in(AnnouncementDO::getId, announcementIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 创建阅读状态映射(公告ID -> 阅读状态)
|
|
|
+ Map<String, Integer> readStatusMap = readConfirmDOPageResult.getList().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ReadConfirmDO::getLaboratoryAnnouncementId,
|
|
|
+ ReadConfirmDO::getReadStatus,
|
|
|
+ (existing, replacement) -> existing
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 设置阅读状态并保持原始顺序
|
|
|
+ List<AnnouncementDO> sortedAnnouncements = new ArrayList<>();
|
|
|
+ for (String announcementId : announcementIds) {
|
|
|
+ announcements.stream()
|
|
|
+ .filter(announcement -> announcementId.equals(announcement.getId()))
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(announcement -> {
|
|
|
+ announcement.setReadStatus(readStatusMap.get(announcementId));
|
|
|
+ sortedAnnouncements.add(announcement);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量设置创建人名称
|
|
|
+ setCreatorNamesInBatch(sortedAnnouncements);
|
|
|
+
|
|
|
+ return new PageResult<>(sortedAnnouncements, readConfirmDOPageResult.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量设置创建人名称
|
|
|
+ */
|
|
|
+ private void setCreatorNamesInBatch(List<AnnouncementDO> announcements) {
|
|
|
+ if (announcements.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取创建人ID(去重)
|
|
|
+ Set<String> creatorIds = announcements.stream()
|
|
|
+ .map(AnnouncementDO::getCreator)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (creatorIds.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询用户信息
|
|
|
+ Map<String, AdminUserRespDTO> userMap = adminUserApi.getUserMap(creatorIds);
|
|
|
+
|
|
|
+ // 设置创建人名称到公告对象中
|
|
|
+ announcements.forEach(announcement -> {
|
|
|
+ if (announcement.getCreator() != null && userMap.containsKey(announcement.getCreator())) {
|
|
|
+ AdminUserRespDTO user = userMap.get(announcement.getCreator());
|
|
|
+ // 这里需要为 AnnouncementDO 添加 creatorName 字段
|
|
|
+ announcement.setCreatorName(user.getNickname());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setReadStatusInBatch(List<AnnouncementDO> announcements, String userId) {
|
|
|
+ if (announcements.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取公告ID
|
|
|
+ List<String> announcementIds = announcements.stream()
|
|
|
+ .map(AnnouncementDO::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量查询阅读状态
|
|
|
+ Map<String, Integer> statusMap = readConfirmService.selectReadStatusBatch(userId, announcementIds);
|
|
|
+
|
|
|
+ // 设置阅读状态
|
|
|
+ announcements.forEach(announcement -> {
|
|
|
+ Integer status = statusMap.get(announcement.getId());
|
|
|
+ announcement.setReadStatus(status != null ? status : 0); // 0=未读
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定部门及其所有子部门的所有用户
|
|
|
+ *
|
|
|
+ * @param deptId 部门ID
|
|
|
+ * @return 用户列表
|
|
|
+ */
|
|
|
+ public List<AdminUserRespDTO> getUsersByDepartmentAndSubDepartments(String deptId) {
|
|
|
+ // 1. 获取所有部门ID(包括当前部门和所有子部门)
|
|
|
+ Set<String> allDeptIds = getAllDepartmentIdsIncludingChildren(deptId);
|
|
|
+
|
|
|
+ // 2. 如果没有找到任何部门,返回空列表
|
|
|
+ if (allDeptIds.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取这些部门的所有用户
|
|
|
+ CommonResult<List<AdminUserRespDTO>> result = adminUserApi.getUserListByDeptIds(allDeptIds);
|
|
|
+
|
|
|
+ // 系统管理员虽然属于部门,但是需要单独增加。
|
|
|
+ CommonResult<AdminUserRespDTO> user = adminUserApi.getUser("1");
|
|
|
+ if (result.getCheckedData() != null && user.getCheckedData() != null) {
|
|
|
+ result.getCheckedData().add(user.getCheckedData());
|
|
|
+ }
|
|
|
+ // 4. 返回用户列表,如果结果为空则返回空列表
|
|
|
+ return result.getCheckedData() != null ? result.getCheckedData() : Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ 获取指定部门及其所有子部门的ID集合
|
|
|
+ @param deptIds 部门ID字符串,多个ID用逗号分隔
|
|
|
+ @return 去重后的部门ID集合
|
|
|
+ */
|
|
|
+ private Set<String> getAllDepartmentIdsIncludingChildren(String deptIds) {
|
|
|
+ Set<String> allDeptIds = new HashSet<>();
|
|
|
+ if (StringUtils.isBlank(deptIds)) {
|
|
|
+ return allDeptIds;
|
|
|
+ }
|
|
|
+ // 按逗号分割部门ID
|
|
|
+ String[] deptIdArray = deptIds.split(",");
|
|
|
+
|
|
|
+ for (String deptId : deptIdArray) {
|
|
|
+ if (StringUtils.isBlank(deptId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ deptId = deptId.trim();
|
|
|
+
|
|
|
+ // 调用API获取所有子部门(包括递归的子部门)
|
|
|
+ CommonResult<List<DeptRespDTO>> childDeptsResult = deptApi.getChildDeptList(deptId);
|
|
|
+ List<DeptRespDTO> childDepts = childDeptsResult.getCheckedData();
|
|
|
+
|
|
|
+ if (childDepts != null && !childDepts.isEmpty()) {
|
|
|
+ // 提取所有子部门ID
|
|
|
+ Set<String> childDeptIds = childDepts.stream()
|
|
|
+ .map(DeptRespDTO::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ allDeptIds.addAll(childDeptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加当前部门ID
|
|
|
+ allDeptIds.add(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return allDeptIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定部门及其所有子部门的所有用户(带去重)
|
|
|
+ *
|
|
|
+ * @param deptId 部门ID
|
|
|
+ * @return 去重的用户列表
|
|
|
+ */
|
|
|
+ public List<AdminUserRespDTO> getDistinctUsersByDepartmentAndSubDepartments(String deptId) {
|
|
|
+ List<AdminUserRespDTO> users = getUsersByDepartmentAndSubDepartments(deptId);
|
|
|
+
|
|
|
+ // 根据用户ID去重
|
|
|
+ return users.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.collectingAndThen(
|
|
|
+ Collectors.toMap(AdminUserRespDTO::getId, user -> user, (existing, replacement) -> existing),
|
|
|
+ map -> new ArrayList<>(map.values())
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定部门及其所有子部门的用户数量
|
|
|
+ *
|
|
|
+ * @param deptId 部门ID
|
|
|
+ * @return 用户数量
|
|
|
+ */
|
|
|
+ public int getUserCountByDepartmentAndSubDepartments(String deptId) {
|
|
|
+ List<AdminUserRespDTO> users = getUsersByDepartmentAndSubDepartments(deptId);
|
|
|
+ return users.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定部门及其所有子部门的用户Map(按部门分组)
|
|
|
+ *
|
|
|
+ * @param deptId 部门ID
|
|
|
+ * @return 按部门分组的用户Map
|
|
|
+ */
|
|
|
+ public Map<String, List<AdminUserRespDTO>> getUsersGroupedByDepartment(String deptId) {
|
|
|
+ List<AdminUserRespDTO> users = getUsersByDepartmentAndSubDepartments(deptId);
|
|
|
+
|
|
|
+ return users.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.groupingBy(AdminUserRespDTO::getDeptId));
|
|
|
+ }
|
|
|
+}
|