package ink.wgink.module.map.controller.resource.grid;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.map.pojo.dtos.grid.GridUserDTO;
import ink.wgink.module.map.service.grid.IGridUserService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.pojo.vos.IdsVO;
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: GridUserController
 * @Description: 网格用户
 * @Author: wanggeng
 * @Date: 2021/10/20 5:42 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "网格用户接口")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/grid/user")
public class GridUserResourceController extends DefaultBaseController {

    @Autowired
    private IGridUserService gridUserService;

    @ApiOperation(value = "修改网格用户", notes = "修改网格用户接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
            @ApiImplicitParam(name = "gridIdId", value = "网格ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update/{gridId}")
    @CheckRequestBodyAnnotation
    public SuccessResult update(@PathVariable("gridId") String gridId, @RequestBody IdsVO idsVO) throws Exception {
        gridUserService.update(gridId, idsVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "网格用户ID列表", notes = "网格用户ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-user-id/{gridId}")
    public List<String> listUserId(@PathVariable("gridId") String gridId) {
        Map<String, Object> params = requestParams();
        return gridUserService.listUserId(gridId, params);
    }

    @ApiOperation(value = "网格用户列表", notes = "网格用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/{gridId}")
    public List<GridUserDTO> list(@PathVariable("gridId") String gridId) {
        Map<String, Object> params = requestParams();
        return gridUserService.list(gridId, params);
    }

    @ApiOperation(value = "网格用户分页列表", notes = "网格用户分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
            @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/{gridId}")
    public SuccessResultList<List<GridUserDTO>> listPage(@PathVariable("gridId") String gridId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return gridUserService.listPage(gridId, page);
    }

}
