xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
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
package com.mindskip.xzs.controller.admin;
 
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.Notify;
import com.mindskip.xzs.domain.enums.NotifyRefType;
import com.mindskip.xzs.domain.vo.AdminNotifyVO;
import com.mindskip.xzs.service.NotifyService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author:xp
 * @date:2024/7/15 15:05
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin/notify")
public class NotifyController extends BaseApiController {
 
    private final NotifyService notifyService;
 
    /**
     * 管理员通知列表
     *
     * @return
     */
    @GetMapping("/admin")
    public RestResponse adminNotifyList() {
        List<Notify> notifies = notifyService.adminNotifyList();
        AdminNotifyVO data = new AdminNotifyVO();
        data.setTotal(notifies.size());
        long feedback = notifies.stream().filter(notify -> NotifyRefType.FEEDBACK.getValue().equals(notify.getRefType())).count();
        long mobilize = notifies.stream().filter(notify -> NotifyRefType.MOBILIZE.getValue().equals(notify.getRefType())).count();
        long status = notifies.stream().filter(notify -> NotifyRefType.STATUS.getValue().equals(notify.getRefType())).count();
        data.setFeedBack(feedback);
        data.setMobilize(mobilize);
        data.setStatus(status);
        List<Integer> ids = notifies.stream().map(Notify::getId).collect(Collectors.toList());
        data.setIds(ids);
        data.setRole(getCurrentUser().getRole());
        return RestResponse.ok(data);
    }
 
    @GetMapping("/me")
    public RestResponse notifyMeList() {
        return RestResponse.ok(notifyService.notifyMeList());
    }
 
 
    @PostMapping("/read")
    public RestResponse readNotify(@RequestBody @NotEmpty List<Integer> ids) {
        notifyService.setHasRead(ids);
        return RestResponse.ok();
    }
}