package com.miaxis.app.controller.news;

import com.miaxis.app.news.domain.NewsInfo;
import com.miaxis.app.news.service.INewsInfoService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【新闻(首页资讯、通知、公告相关)】Controller
 *
 * @author miaxis
 * @date 2020-12-22
 */
@RestController
@RequestMapping(Constants.OPEN_PREFIX+"/system/info")
@Api(tags={"【app-新闻(首页资讯、通知、公告相关)】"})
public class NewsInfoController extends BaseController{
    @Autowired
    private INewsInfoService newsInfoService;

    /**
     * 查询新闻(首页资讯、通知、公告相关)列表
     */
    @GetMapping("/list")
    @ApiOperation("查询新闻(首页资讯、通知、公告相关)列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<NewsInfo> list(@ModelAttribute NewsInfo newsInfo){
        startPage();
        List<NewsInfo> list = newsInfoService.selectNewsInfoList(newsInfo);
//        List<NewsInfo> list = newsInfoService.list();
        return toResponsePageInfo(list);
    }


    /**
     * 获取新闻(首页资讯、通知、公告相关)详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取新闻(首页资讯、通知、公告相关)详细信息")
    public Response<NewsInfo> getInfo(
            @ApiParam(name = "id", value = "新闻(首页资讯、通知、公告相关)参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(newsInfoService.selectNewsInfoById(id));
    }

    /**
     * 新增新闻(首页资讯、通知、公告相关)
     */
    @PostMapping
    @ApiOperation("新增新闻(首页资讯、通知、公告相关)")
    public Response<Integer> add(@RequestBody NewsInfo newsInfo){
        return toResponse(newsInfoService.insertNewsInfo(newsInfo));
    }

    /**
     * 修改新闻(首页资讯、通知、公告相关)
     */
    @PutMapping
    @ApiOperation("修改新闻(首页资讯、通知、公告相关)")
    public Response<Integer> edit(@RequestBody NewsInfo newsInfo){
        return toResponse(newsInfoService.updateNewsInfo(newsInfo));
    }

    /**
     * 删除新闻(首页资讯、通知、公告相关)
     */
	@DeleteMapping("/{ids}")
    @ApiOperation("删除新闻(首页资讯、通知、公告相关)")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "新闻(首页资讯、通知、公告相关)ids参数", required = true)
            @PathVariable Long[] ids){
        return toResponse(newsInfoService.deleteNewsInfoByIds(ids));
    }
}
