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.AdDevice;
import org.king.modules.ad.service.IAdDeviceService;
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-09
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "岸电设备")
@RestController
@RequestMapping("/ad/adDevice")
public class AdDeviceController extends KingController<AdDevice, IAdDeviceService> {

	@Autowired
	private IAdDeviceService adDeviceService;
	
	/**
	 * 分页列表查询
	 *
	 * @param adDevice
	 * @param pageNo 页码
	 * @param pageSize 每页条数
	 * @param req
	 * @return
	 */
	@AutoLog(value = "岸电设备-分页列表查询")
	@ApiOperation(value = "岸电设备-分页列表查询", notes = "岸电设备-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(AdDevice adDevice,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									  HttpServletRequest req) {
		QueryWrapper<AdDevice> queryWrapper = QueryGenerator.initQueryWrapper(adDevice, req.getParameterMap());
		Page<AdDevice> page = new Page<>(pageNo, pageSize);
		IPage<AdDevice> pageList = adDeviceService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	
	/**
	 * 添加
	 *
	 * @param adDevice
	 * @return
	 */
	@AutoLog(value = "岸电设备-添加")
	@ApiOperation(value = "岸电设备-添加", notes = "岸电设备-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody AdDevice adDevice) {
		adDeviceService.save(adDevice);
        return Result.ok("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 * @param adDevice
	 * @return
	 */
	@AutoLog(value = "岸电设备-编辑")
	@ApiOperation(value = "岸电设备-编辑", notes = "岸电设备-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody AdDevice adDevice) {
		adDeviceService.updateById(adDevice);
        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) {
		adDeviceService.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.adDeviceService.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) {
		AdDevice adDevice = adDeviceService.getById(id);
		if (adDevice==null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(adDevice);
	}

    /**
     * 导出excel
     *
     * @param request
     * @param adDevice
     */
    @AutoLog(value = "岸电设备-导出excel")
    @ApiOperation(value = "岸电设备-导出excel", notes = "岸电设备-导出excel")
    @RequestMapping(value = "/exportXls", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView exportXls(HttpServletRequest request, AdDevice adDevice) {
        return super.exportXls(request, adDevice, AdDevice.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, AdDevice.class);
     }

}
