package ink.wgink.module.map.controller.app.api.grid;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.map.pojo.dtos.grid.GridDTO;
import ink.wgink.module.map.service.grid.IGridService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: GridControler
 * @Description: 网格管理
 * @Author: wanggeng
 * @Date: 2021/10/19 10:21 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "网格接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/grid")
public class GridAppController extends DefaultBaseController {

    @Autowired
    private IGridService gridService;

    @ApiOperation(value = "网格详情", notes = "网格详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "gridIdId", value = "网格ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get/{gridId}")
    public GridDTO get(@RequestHeader("token") String token, @PathVariable("gridId") String gridId) {
        return gridService.get(gridId, true, true);
    }

    @ApiOperation(value = "网格列表", notes = "网格列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list")
    public List<GridDTO> list(@RequestHeader("token") String token) {
        Map<String, Object> params = requestParams();
        return gridService.list(params);
    }

    @ApiOperation(value = "网格列表", notes = "网格列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/area-code/{areaCode}")
    public List<GridDTO> listByAreaCode(@PathVariable("areaCode") String areaCode) {
        Map<String, Object> params = requestParams();
        return gridService.listByAreaCode(areaCode, params);
    }

    @ApiOperation(value = "网格（排除查询网格）列表", notes = "网格（排除查询网格）列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/except/{gridId}")
    public List<GridDTO> listExcept(@RequestHeader("token") String token,
                                    @PathVariable("gridId") String gridId) {
        Map<String, Object> params = requestParams();
        return gridService.listExcept(gridId, params);
    }

    @ApiOperation(value = "网格分页列表", notes = "网格分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage")
    public SuccessResultList<List<GridDTO>> listPage(@RequestHeader("token") String token, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return gridService.listPage(page);
    }

    @ApiOperation(value = "网格分页列表", notes = "网格分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/area-code/{areaCode}")
    public SuccessResultList<List<GridDTO>> listPageByAreaCode(@RequestHeader("token") String token, @PathVariable("areaCode") String areaCode, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return gridService.listPageByAreaCode(areaCode, page);
    }

}
