package org.king.modules.ad.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.king.common.api.vo.Result;
import org.king.common.aspect.annotation.AutoLog;
import org.king.common.system.base.controller.KingController;
import org.king.common.system.query.QueryGenerator;
import org.king.modules.ad.entity.BaseShipInfo;
import org.king.modules.ad.service.IBaseShipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 船舶基本信息
 * @Author: king-boot
 * @Date: 2021-06-15
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "船舶基本信息")
@RestController
@RequestMapping("/ad/baseShipInfo")
public class BaseShipInfoController extends KingController<BaseShipInfo, IBaseShipInfoService> {

	@Autowired
	private IBaseShipInfoService baseShipInfoService;
	
	/**
	 * 分页列表查询
	 *
	 * @param baseShipInfo
	 * @param pageNo 页码
	 * @param pageSize 每页条数
	 * @param req
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-分页列表查询")
	@ApiOperation(value = "船舶基本信息-分页列表查询", notes = "船舶基本信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(BaseShipInfo baseShipInfo,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									  HttpServletRequest req) {
		List<BaseShipInfo> list = baseShipInfoService.list();
		return Result.ok(list);
	}
	
	/**
	 * 添加
	 *
	 * @param baseShipInfo
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-添加")
	@ApiOperation(value = "船舶基本信息-添加", notes = "船舶基本信息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BaseShipInfo baseShipInfo) {
		baseShipInfoService.save(baseShipInfo);
        return Result.ok("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 * @param baseShipInfo
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-编辑")
	@ApiOperation(value = "船舶基本信息-编辑", notes = "船舶基本信息-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BaseShipInfo baseShipInfo) {
		baseShipInfoService.updateById(baseShipInfo);
        return Result.ok("编辑成功!");
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id 主键id
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-通过id删除")
	@ApiOperation(value = "船舶基本信息-通过id删除", notes = "船舶基本信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id") String id) {
		baseShipInfoService.removeById(id);
        return Result.ok("删除成功!");
	}
	
	/**
	 * 批量删除
	 *
	 * @param ids 主键id集合
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-批量删除")
	@ApiOperation(value = "船舶基本信息-批量删除", notes = "船舶基本信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids") String ids) {
		this.baseShipInfoService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id 主键id
	 * @return
	 */
	@AutoLog(value = "船舶基本信息-通过id查询")
	@ApiOperation(value = "船舶基本信息-通过id查询", notes = "船舶基本信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id") String id) {
		BaseShipInfo baseShipInfo = baseShipInfoService.getById(id);
		if (baseShipInfo==null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(baseShipInfo);
	}

    /**
     * 导出excel
     *
     * @param request
     * @param baseShipInfo
     */
    @AutoLog(value = "船舶基本信息-导出excel")
    @ApiOperation(value = "船舶基本信息-导出excel", notes = "船舶基本信息-导出excel")
    @RequestMapping(value = "/exportXls", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView exportXls(HttpServletRequest request, BaseShipInfo baseShipInfo) {
        return super.exportXls(request, baseShipInfo, BaseShipInfo.class, "船舶基本信息");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
     @AutoLog(value = "船舶基本信息-通过excel导入数据")
     @ApiOperation(value = "船舶基本信息-通过excel导入数据", notes = "船舶基本信息-通过excel导入数据")
     @PostMapping(value = "/importExcel")
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, BaseShipInfo.class);
     }

}
