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();
|
}
|
}
|