package org.king.modules.ad.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.king.common.system.base.controller.KingController;
import org.king.common.api.vo.Result;
import org.king.common.system.query.QueryGenerator;
import org.king.common.aspect.annotation.AutoLog;
import org.king.modules.ad.entity.AdShipFaultReport;
import org.king.modules.ad.service.IAdShipFaultReportService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 船舶故障报告
 * @Author: king-boot
 * @Date: 2021-06-07
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "船舶故障报告")
@RestController
@RequestMapping("/ad/adShipFaultReport")
public class AdShipFaultReportController extends KingController<AdShipFaultReport, IAdShipFaultReportService> {

	@Autowired
	private IAdShipFaultReportService adShipFaultReportService;
	
	/**
	 * 分页列表查询
	 *
	 * @param adShipFaultReport
	 * @param pageNo 页码
	 * @param pageSize 每页条数
	 * @param req
	 * @return
	 */
	@AutoLog(value = "船舶故障报告-分页列表查询")
	@ApiOperation(value = "船舶故障报告-分页列表查询", notes = "船舶故障报告-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(AdShipFaultReport adShipFaultReport,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									  HttpServletRequest req) {
		QueryWrapper<AdShipFaultReport> queryWrapper = QueryGenerator.initQueryWrapper(adShipFaultReport, req.getParameterMap());
		Page<AdShipFaultReport> page = new Page<>(pageNo, pageSize);
		IPage<AdShipFaultReport> pageList = adShipFaultReportService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id 主键id
	 * @return
	 */
	@AutoLog(value = "船舶故障报告-通过id查询")
	@ApiOperation(value = "船舶故障报告-通过id查询", notes = "船舶故障报告-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id") String id) {
		AdShipFaultReport adShipFaultReport = adShipFaultReportService.getById(id);
		if (adShipFaultReport==null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(adShipFaultReport);
	}

    /**
     * 导出excel
     *
     * @param request
     * @param adShipFaultReport
     */
    @AutoLog(value = "船舶故障报告-导出excel")
    @ApiOperation(value = "船舶故障报告-导出excel", notes = "船舶故障报告-导出excel")
    @RequestMapping(value = "/exportXls", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView exportXls(HttpServletRequest request, AdShipFaultReport adShipFaultReport) {
        return super.exportXls(request, adShipFaultReport, AdShipFaultReport.class, "船舶故障报告");
    }

}
