package jnpf.notice.controller.app;


import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.model.notice.domain.FtbNoticeManager;
import jnpf.model.notice.dto.NoticeManagerAuthorityDto;
import jnpf.notice.service.FtbNoticeManagerService;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * app公告管理员模块
 *
 * @author makejava
 * @since 2024-05-08 09:51:36
 */
@RestController
@RequestMapping("/app/noticeManager")
public class AppNoticeManagerController {
    /**
     * 服务对象
     */
    @Autowired
    private FtbNoticeManagerService ftbNoticeManagerService;

    /**
     * 查询当前用户是否是通知公告管理员
     *
     * @return {@link ActionResult}
     */
    @GetMapping("/queryMyNoticeManagerAuthority")
    public ActionResult<NoticeManagerAuthorityDto> queryMyNoticeManagerAuthority() {
        UserInfo userInfo = UserProvider.getUser();
        NoticeManagerAuthorityDto noticeManagerAuthorityDto = new NoticeManagerAuthorityDto();
        if (StringUtil.isEmpty(userInfo.getUserId())) {
            noticeManagerAuthorityDto.setIsNoticeManager(false);
            return ActionResult.success("成功", noticeManagerAuthorityDto);
        }
        if (userInfo.getIsAdministrator()) {
            noticeManagerAuthorityDto.setIsNoticeManager(true);
            return ActionResult.success("成功", noticeManagerAuthorityDto);
        }


        //非系统管理员 判断是否添加了通知公告权限
        FtbNoticeManager ftbNoticeManager = ftbNoticeManagerService.queryByUserId(userInfo.getUserId());
        if (null != ftbNoticeManager) {
            noticeManagerAuthorityDto.setIsNoticeManager(true);
            return ActionResult.success("成功", noticeManagerAuthorityDto);
        }

        noticeManagerAuthorityDto.setIsNoticeManager(false);
        return ActionResult.success("成功", noticeManagerAuthorityDto);

    }


}

