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.EntCompanyGeom;
import org.king.modules.ad.service.IEntCompanyGeomService;
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/entCompanyGeom")
public class EntCompanyGeomController extends KingController<EntCompanyGeom, IEntCompanyGeomService> {

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

    /**
     * 导出excel
     *
     * @param request
     * @param entCompanyGeom
     */
    @AutoLog(value = "公司作业地点关联-导出excel")
    @ApiOperation(value = "公司作业地点关联-导出excel", notes = "公司作业地点关联-导出excel")
    @RequestMapping(value = "/exportXls", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView exportXls(HttpServletRequest request, EntCompanyGeom entCompanyGeom) {
        return super.exportXls(request, entCompanyGeom, EntCompanyGeom.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, EntCompanyGeom.class);
     }

}
