package cn.stylefeng.guns.zjxl.cnotroller;

import cn.stylefeng.guns.zjxl.model.ZjxlCompanyCase;
import cn.stylefeng.guns.zjxl.model.ZjxlNewsCenter;
import cn.stylefeng.guns.zjxl.service.ZjxlNewsCenterService;
import cn.stylefeng.guns.zjxlUtil.BaseController;
import cn.stylefeng.guns.zjxlUtil.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * @ClassName: ZjxlNewsCenterController
 * @Description:
 * @Auther: shi kejing
 * @Date: 2020/11/17 14:22
 */
@RestController
@Api(description = "公司官网主页-新闻中心列表页")
@RequestMapping(value = "/zjxl/newsCenter")
public class ZjxlNewsCenterController extends BaseController {

    private Logger logger = (Logger) LoggerFactory.getLogger(ZjxlCompanyCaseController.class);

    @Autowired
    private ZjxlNewsCenterService newsCenterService;

    @RequestMapping(value = "/findNewsCenterById", method = RequestMethod.GET)
    @ApiOperation(value = "查看CompanyCase")
    public String findNewsCenterById(@ApiParam(name = "id", value = "companyId", required = false) @RequestParam(value = "id", required = false)String id,
                                      @ApiParam(name = "name", value = "companyName", required = false) @RequestParam(value = "name", required = false)String name,
                                      @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo,
                                      @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){
        try {
            List<ZjxlNewsCenter> newsCenterList = newsCenterService.findById(id,pageNo-1,pageSize);
            return write(200,"查询成功","data", PageUtil.getPage(newsCenterList,pageNo,pageSize,newsCenterService.allCount()));
        }catch (Exception e){
            e.printStackTrace();
            return write(-1,"查询失败");
        }
    }
}
