package com.yh.saas.plugin.news.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.yh.saas.plugin.news.entity.AnnoIssueInfo;
import com.yh.saas.plugin.news.entity.view.DeptStaffTreeView;
import com.yh.saas.plugin.news.service.IAnnoIssueInfoService;
import com.yh.saas.plugin.news.util.HtmlUtil;
import com.yh.saas.common.support.plugin.PluginFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *     公告模块 - 公告详情 Controller
 * </p>
 * @Auther ZhangMingYu
 * @since 2019年8月14日15:48:17
 */
@RestController
@RequestMapping("/announcementIssue")
public class NewsAnnoIssueInfoController {

    @Autowired
    private IAnnoIssueInfoService annoIssueInfoService;

    /**
     * 创建 公司公告
     * @param annoIssueInfo 创建对象
     * @return 是否成功
     */
    @PostMapping("/api/create")
    @PluginFeature(id = "AnnouncementInfo-Issue", name = "公告_发布")
    public Boolean create(@RequestBody AnnoIssueInfo annoIssueInfo){
        return annoIssueInfoService.create(annoIssueInfo);
    }

    /**
     * 删除公告
     * @param annoIssueInfo 删除对象(需要携带主键ID)
     */
    @PostMapping("/api/remove")
    @PluginFeature(id = "AnnouncementInfo-Delete", name = "公告_删除")
    public void remove(@RequestBody AnnoIssueInfo annoIssueInfo){
        annoIssueInfoService.remove(annoIssueInfo);
    }

    /**
     * 修改公告
     * @param annoIssueInfo
     */
    @PostMapping("/api/chagneInfo")
    @PluginFeature(id = "AnnouncementInfo-Issue", name = "公告_发布")
    public void chagneInfo(@RequestBody AnnoIssueInfo annoIssueInfo){
        annoIssueInfoService.chagneInfo(annoIssueInfo);
    }

    /**
     * 分页查询公告
     * @param annoIssueInfo 分页状态
     * @return 分页集合
     */
    @GetMapping("/query/page")
    public Page<AnnoIssueInfo> queryPage(AnnoIssueInfo annoIssueInfo){
        return annoIssueInfoService.queryPage(annoIssueInfo);
    }

    /**
     * 查询公告详情
     */
    @GetMapping("/query/annoInfo")
    public AnnoIssueInfo queryInfo(AnnoIssueInfo annoIssueInfo){
        return annoIssueInfoService.queryInfo(annoIssueInfo);
    }

    /**
     * 查看发送范围
     * @return 范围对象
     */
    @GetMapping("/query/sendScope")
    public List<DeptStaffTreeView> sendScope(){
        return annoIssueInfoService.getCompDepaStaff();
    }

    /**
     * 查看发送范围
     * @return 范围对象
     */
    @GetMapping("/query/sendDeptScope")
    public List<DeptStaffTreeView> sendDeptScope(){
        return annoIssueInfoService.getTenantCompDeptInfo();
    }

    /**
     * 首页新闻查询
     *
     * @param annoIssueInfo 分页状态
     * @return 分页集合
     */
    @GetMapping("/query/queryHomePage")
    public List<AnnoIssueInfo> queryHomePage(AnnoIssueInfo annoIssueInfo) {
        List<AnnoIssueInfo> annoIssueInfos = annoIssueInfoService.queryHomePage(annoIssueInfo);
        annoIssueInfos.forEach(a -> {
            String content = a.getContent();
            a.setNewContent(HtmlUtil.deleteAllHTMLTag(content));
            a.setContent("");
        });
        return annoIssueInfos;
    }

}
