package jnpf.notice.controller.web;


import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.notice.dto.FtbNoticeAnnouncementsReceiveDto;
import jnpf.model.notice.dto.MyNoticeAnnouncementsDetailDto;
import jnpf.model.notice.dto.MyNoticeAnnouncementsDto;
import jnpf.model.notice.dto.MyNoticeAnnouncementsMsgDto;
import jnpf.model.notice.req.announcement.QueryMyWebAnnouncementListReq;
import jnpf.model.notice.req.announcement.QueryUserListReq;
import jnpf.notice.service.FtbNoticeAnnouncementsReceiveService;
import jnpf.notice.service.FtbNoticeAnnouncementsService;
import jnpf.util.FtbUtil;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * web 我的公告模块
 *
 * @author xgl
 * @since 2024-05-08 09:51:26
 */
@RestController
@RequestMapping("/web/myNoticeAnnouncements")
public class FtbMyNoticeAnnouncementsController {
    /**
     * 服务对象
     */
    @Autowired
    private FtbNoticeAnnouncementsService ftbNoticeAnnouncementsService;

    @Autowired
    private FtbNoticeAnnouncementsReceiveService ftbNoticeAnnouncementsReceiveService;

    /**
     * 查询我的公告列表
     *
     * @param req
     * @return {@link ActionResult}<{@link MyNoticeAnnouncementsDto}>
     */
    @GetMapping("/queryList")
    public ActionResult<PageListVO<MyNoticeAnnouncementsDto>> pageLists(@Validated QueryMyWebAnnouncementListReq req) {
        PageInfo<MyNoticeAnnouncementsDto> pageVo = ftbNoticeAnnouncementsService.getMyWebPageList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

    /**
     * 查询公告详情
     *
     * @param announcementId 公告ID
     * @return {@link ActionResult}
     */
    @GetMapping("/get/{announcementId}")
    public ActionResult<MyNoticeAnnouncementsDetailDto> get(@PathVariable("announcementId") String announcementId) {
        return ActionResult.success("成功", ftbNoticeAnnouncementsService.getMyAnnouncementInfo(announcementId,  UserProvider.getLoginUserId()));
    }

    /**
     * 公告完成阅读接口
     *
     * @param announcementId 公告ID
     * @return {@link ActionResult}
     */
    @GetMapping("/completeRead/{announcementId}")
    public ActionResult<Boolean> completeRead(@PathVariable("announcementId") String announcementId) {
        ftbNoticeAnnouncementsService.completeRead(announcementId, UserProvider.getLoginUserId());
        return ActionResult.success("成功", true);
    }

    /**
     * 查询公告中已读/未读人员列表
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbNoticeAnnouncementsReceiveDto}>
     */
    @GetMapping("/queryUser")
    public ActionResult<PageListVO<FtbNoticeAnnouncementsReceiveDto>> queryUserList(@Validated QueryUserListReq req) {
        PageInfo<FtbNoticeAnnouncementsReceiveDto> pageVo = ftbNoticeAnnouncementsReceiveService.queryUserListForReadStatus(req, true);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }


    /**
     * 轮训我的未读公告
     *
     * @return {@link ActionResult}
     */
    @GetMapping("/queryAllNoRead")
    public ActionResult<List<MyNoticeAnnouncementsMsgDto>> queryAllNoRead() {
        //needRead 0:全部 1：非必读，2：必读
        return ActionResult.success("成功", ftbNoticeAnnouncementsService.queryAllWebMyNoRead(UserProvider.getLoginUserId(), 0));
    }

    /**
     * web轮训用户X掉轮训不显示
     *
     * @param announcementId 公告ID
     * @return {@link ActionResult}
     */
    @GetMapping("/cancelWebAlert/{announcementId}")
    public ActionResult<Boolean> cancelWebAlert(@PathVariable("announcementId") String announcementId) {
        ftbNoticeAnnouncementsReceiveService.cancelWebAlert(announcementId, UserProvider.getLoginUserId());
        return ActionResult.success("成功", true);
    }


}

