package com.dgtly.api.controller;

import com.dgtly.common.annotation.ApiNoCheckSign;
import com.dgtly.common.annotation.ApiPassToken;
import com.dgtly.common.core.controller.ApiBaseController;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.core.domain.ParameterObject;
import com.dgtly.common.utils.StringUtils;
import com.dgtly.system.domain.SysNotice;
import com.dgtly.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
  * @descption: 内容管理相关接口
  * @author LiuLingChao
  * @version 1.0
  * @company 神州数码通用软件（洛阳）有限公司
  * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
  * @date 2019-11-04 11:08
  * @since JDK1.8
  */
@RestController
@RequestMapping("/interface/notice")
@ApiPassToken
@ApiNoCheckSign
public class SysNoticeInterface extends ApiBaseController {

    @Autowired
    private ISysNoticeService sysNoticeService;

    /**
     * @descption: 根据类型查询内容列表前五个
     * @param:类型
     * @return: 内容列表五个
     * @auther: LiuLingChao
     * @date: 2019-11-04 11:46
     */
    @PostMapping("getNoticeListTop5")
    public AjaxResult getNoticeList(){

        ParameterObject obj =  getParameterObject();
        SysNotice sysNotice = obj.parseBean(SysNotice.class);
        String noticeType = sysNotice.getNoticeType();
        if(StringUtils.isNotEmpty(noticeType)){
            sysNotice.setLimitFlag("true");
            List<SysNotice> sysNoticeList = sysNoticeService.selectNoticeTop3ByRole(sysNotice);
            List<String> banner = new ArrayList<String>();
            for(SysNotice n:sysNoticeList){
                banner.add(n.getFmzFileUrl());
            }
            AjaxResult result = AjaxResult.success("查询成功").putKV("list",sysNoticeList);
            result.putKV("banner",banner);
            return result;
        }else{
            return AjaxResult.error("参数为空");
        }


    }

    /**
     * @descption: 根据类型查询全部内容列表
     * @param:类型
     * @return: 内容列表
     * @auther: LiuLingChao
     * @date: 2019-11-04 15:01
     */
    @PostMapping("getNoticeListAll")
    public AjaxResult getNoticeListAll(){
        ParameterObject obj =  getParameterObject();
        SysNotice sysNotice = obj.parseBean(SysNotice.class);
        String noticeType = sysNotice.getNoticeType();
        if(StringUtils.isNotEmpty(noticeType)){
            startPage(obj);/*向分页传递 分页参数*/
            List<SysNotice> sysNoticeList = sysNoticeService.selectNoticeList(sysNotice);
            return AjaxResult.success(getDataTable(sysNoticeList));
        }else{
            return AjaxResult.error("参数为空");
        }


    }

    /**
     * @descption: 根据id查询详情
     * @param:
     * @return:
     * @auther: LiuLingChao
     * @date: 2020-2-27 10:31
     */
    @RequestMapping("getNoticeListById")
    public AjaxResult getNoticeListById(){
        ParameterObject obj =  getParameterObject();
        SysNotice sysNotice = obj.parseBean(SysNotice.class);
        Long noticeId = sysNotice.getNoticeId();
        if(null != noticeId){
            SysNotice sysNotice1 = sysNoticeService.selectNoticeById(noticeId);
            return AjaxResult.success().putKV("sysNotice",sysNotice1);
        }else{
            return AjaxResult.error("参数为空");
        }


    }
}
