无关风月
4 天以前 7cf455d9e9dd66a13c01b3e5d6536a4b3ce7bfbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.ruoyi.web.controller.api;
 
 
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.framework.web.service.TokenService;
import com.ruoyi.system.model.OaNotification;
import com.ruoyi.system.model.OaNotificationUser;
import com.ruoyi.system.query.NotificationListQuery;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.OaNotifationUserService;
import com.ruoyi.system.service.OaNotificationService;
import com.ruoyi.system.service.TDeptService;
import com.ruoyi.system.vo.system.NotificationDeptUserDetailVO;
import com.ruoyi.system.vo.system.NotificationDetailVO;
import com.ruoyi.system.vo.system.NotificationUserDetailVO;
import com.ruoyi.system.vo.system.NotificationVO;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
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>
 * 通知用户关联表 前端控制器
 * </p>
 *
 * @author WuGuanFengYue
 * @since 2025-09-15
 */
@RestController
@RequestMapping("/oa-notifation-user")
public class OaNotifationUserController {
    @Resource
    private OaNotificationService oaNotificationService;
    @Resource
    private OaNotifationUserService oaNotifationUserService;
    @Resource
    private TDeptService deptService;
    @Resource
    private ISysUserService sysUserService;
    @Resource
    private TokenService tokenService;
 
    /**
     * 获取部门树列表
     */
    @ApiOperation("消息通知分页列表")
    @PostMapping("/pageList")
    public R<PageInfo<NotificationVO>> pageListUser(@RequestBody NotificationListQuery query) {
        Long userId = tokenService.getLoginUser().getUserId();
        query.setUserId(userId);
        return R.ok(oaNotificationService.pageListUser(query));
    }
 
 
    @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(notificationDetailVO);
    }
}