From 2bdcf12109e62a731eb16e90b6e1c39a67853fb1 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期一, 13 十月 2025 18:46:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaNotificationController.java | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 152 insertions(+), 2 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaNotificationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaNotificationController.java
index 4ec73e1..74b8fe2 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaNotificationController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaNotificationController.java
@@ -1,8 +1,29 @@
package com.ruoyi.web.controller.api;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.basic.PageInfo;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.entity.TDept;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.system.model.OaNotificationUser;
+import com.ruoyi.system.model.OaNotification;
+import com.ruoyi.system.query.NotificationListQuery;
+import com.ruoyi.system.service.*;
+import com.ruoyi.system.vo.system.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* <p>
@@ -13,8 +34,137 @@
* @since 2025-09-15
*/
@RestController
+@Api(tags = "消息通知")
@RequestMapping("/oa-notification")
public class OaNotificationController {
+ @Resource
+ private OaNotificationService oaNotificationService;
+ @Resource
+ private OaNotifationUserService oaNotifationUserService;
+ @Resource
+ private TDeptService deptService;
+ @Resource
+ private ISysUserService sysUserService;
+ /**
+ * 获取部门树列表
+ */
+ @ApiOperation("消息通知分页列表")
+ @PostMapping("/pageList")
+ public R<PageInfo<NotificationVO>> pageList(@RequestBody NotificationListQuery query) {
+ return R.ok(oaNotificationService.pageList(query));
+ }
+
+ @ApiOperation(value = "删除消息通知")
+ @Log(title = "删除消息通知", businessType = BusinessType.DELETE)
+
+ @DeleteMapping(value = "/delete")
+ public R delete(@RequestParam String ids) {
+ List<String> notificationIds = Arrays.asList(ids.split(","));
+ // 删除后 将已发送的消息通知一并删除
+ oaNotificationService.removeBatchByIds(notificationIds);
+ oaNotifationUserService.remove(new LambdaQueryWrapper<OaNotificationUser>()
+ .in(OaNotificationUser::getNotificationId,notificationIds));
+ return R.ok();
+ }
+ @Log(title = "消息通知-新增消息", businessType = BusinessType.INSERT)
+ @ApiOperation(value = "新增消息")
+ @PostMapping(value = "/add")
+ public R<Boolean> add( @RequestBody OaNotification dto) {
+ oaNotificationService.save(dto);
+ ArrayList<OaNotificationUser> oaNotificationUsers = new ArrayList<>();
+ // 发送消息通知
+ if (dto.getType()){
+ // 指定人员发送
+ Arrays.asList(dto.getUserIds().split(","))
+ .forEach(userId -> {
+ OaNotificationUser oaNotificationUser = new OaNotificationUser();
+ oaNotificationUser.setUserId(Integer.parseInt(userId));
+ oaNotificationUser.setNotificationId(dto.getId());
+ oaNotificationUsers.add(oaNotificationUser);
+ });
+ }else{
+ // 所有人发送
+ List<SysUser> sysUsers = sysUserService.selectAllList();
+ sysUsers.forEach(sysUser -> {
+ OaNotificationUser oaNotificationUser = new OaNotificationUser();
+ oaNotificationUser.setUserId(sysUser.getUserId().intValue());
+ oaNotificationUser.setNotificationId(dto.getId());
+ oaNotificationUsers.add(oaNotificationUser);
+ });
+ }
+ oaNotifationUserService.saveBatch(oaNotificationUsers);
+ return R.ok();
+ }
+ @ApiOperation(value = "消息通知详情")
+ @GetMapping(value = "/detail")
+ public R<NotificationDetailVO> detail(String id) {
+ NotificationDetailVO notificationDetailVO = new NotificationDetailVO();
+ OaNotification oaNotification = oaNotificationService.getById(id);
+ BeanUtils.copyProperties(oaNotification, notificationDetailVO);
+ StringBuilder deptName = new StringBuilder();
+ List<TDept> tDepts = deptService.list();
+ List<SysUser> sysUsers = sysUserService.selectAllList();
+ List<OaNotificationUser> notifationUsers = oaNotifationUserService.lambdaQuery().eq(OaNotificationUser::getNotificationId, id)
+ .list();
+ Map<Integer, String> deptMap = tDepts.stream().collect(Collectors.toMap(TDept::getId, TDept::getDeptName));
+ Map<Long, SysUser> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, e->e));
+ if (oaNotification.getType()){
+ for (String deptId : oaNotification.getDeptIds().split(",")) {
+ String orDefault = deptMap.getOrDefault(Integer.parseInt(deptId), "");
+ deptName.append(orDefault).append(",");
+ }
+ if (deptName.length() > 0){
+ notificationDetailVO.setDeptName(deptName.substring(0,deptName.length()-1));
+ }else {
+ notificationDetailVO.setDeptName("");
+ }
+ List<NotificationDeptUserDetailVO> notificationUserVOS = new ArrayList<>();
+ List<Long> userIds = notifationUsers.stream().map(e -> e.getUserId().longValue()).collect(Collectors.toList());
+ if (!userIds.isEmpty()){
+ Map<String, List<SysUser>> deptUserList = sysUsers.stream().filter(e -> userIds.contains(e.getUserId()))
+ .collect(Collectors.groupingBy(SysUser::getDeptId));
+ // 遍历这个map
+ for (Map.Entry<String, List<SysUser>> entry : deptUserList.entrySet()) {
+ List<SysUser> users = entry.getValue();
+ String deptId = entry.getKey();
+ NotificationDeptUserDetailVO notificationDeptUserDetailVO = new NotificationDeptUserDetailVO();
+ notificationDeptUserDetailVO.setDeptName(deptMap.getOrDefault(Integer.parseInt(deptId), ""));
+ notificationDeptUserDetailVO.setUsers(users);
+ // 查询部门下的员工数是否和users一致
+ long count = sysUsers.stream().filter(e -> e.getDeptId().equals(deptId)).count();
+ if (count==users.size()){
+ notificationDeptUserDetailVO.setIsAll(true);
+ }else{
+ notificationDeptUserDetailVO.setIsAll(false);
+ }
+ notificationUserVOS.add(notificationDeptUserDetailVO);
+ }
+ }
+ notificationDetailVO.setNotificationDeptUserDetailVOList(notificationUserVOS);
+
+ }else{
+
+ notificationDetailVO.setDeptName("全部人员");
+ }
+ List<NotificationUserDetailVO> notificationUserDetailVOS = new ArrayList<>();
+
+ for (OaNotificationUser notifationUser : notifationUsers) {
+ NotificationUserDetailVO notificationUserDetailVO = new NotificationUserDetailVO();
+ BeanUtils.copyProperties(notifationUser, notificationUserDetailVO);
+ SysUser sysUser = userMap.get(notifationUser.getUserId().longValue());
+ if (sysUser==null){
+ continue;
+ }
+ notificationUserDetailVO.setDeptName(deptMap.getOrDefault(Integer.parseInt(sysUser.getDeptId()), ""));
+ notificationUserDetailVO.setNickName(sysUser.getNickName());
+ notificationUserDetailVO.setPhonenumber(sysUser.getPhonenumber());
+ notificationUserDetailVO.setPosition(sysUser.getPosition());
+ notificationUserDetailVOS.add(notificationUserDetailVO);
+ }
+
+ notificationDetailVO.setNotificationUserDetailVOS(notificationUserDetailVOS);
+ return R.ok();
+ }
}
--
Gitblit v1.7.1