package com.sky.ioc.controller.notice;

import com.sky.ioc.entity.domain.notice.Notice;
import com.sky.ioc.entity.params.IocParam;
import com.sky.ioc.entity.params.notice.NoticeParam;
import com.sky.ioc.service.notice.NoticeService;
import com.sky.ioc.tool.ExcelUtils;
import com.sky.ioc.tool.ReturnMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags ="通知")
@Slf4j
@RestController
@RequestMapping("/notice")
public class NoticeController {


    @Autowired
    NoticeService noticeService;

    @ApiOperation("分页列表")
    @PostMapping("/getNoticeList")
    public ReturnMsg getNoticeList(@RequestBody NoticeParam noticeParam){
        return noticeService.listPage(noticeParam);
    }

    @ApiOperation("通知设为已读")
    @PostMapping("/readNotice")
    public ReturnMsg readNotice(@RequestBody List<Integer> ids){
        return noticeService.readNotice(ids);
    }

    @ApiOperation("删除通知")
    @PostMapping("/delNotice")
    public ReturnMsg delNotice(@RequestBody List<Integer> ids){
        return noticeService.delNotice(ids);
    }

    @ApiOperation("查看通知")
    @GetMapping("/getNotice")
    public ReturnMsg getNotice(@RequestParam Integer id){
        return noticeService.getNotice(id);
    }

    @ApiOperation("导出文件数据")
    @GetMapping("/exportFile")
    public void exportFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Map<String,Object>> lists = noticeService.exportData(null);
        List<String> columnKey = new ArrayList<>();
        List<String> columnName = new ArrayList<>();
        columnKey.add("title");
        columnName.add("标题");
        ExcelUtils.exportExcel("通知",columnName,columnKey,lists,request,response);
       // return  "";
    }
}
