package cn.com.tenlion.systembase.controller.api.grid;

import cn.com.tenlion.systembase.pojo.dtos.grid.GridDTO;
import cn.com.tenlion.systembase.remote.grid.IGridRemoteService;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.properties.ApiPathProperties;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: GridController
 * @Description: 网格管理
 * @Author: CodeFactory
 * @Date: 2021-09-17 14:43:53
 * @Version: 3.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "网格表接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/grid")
public class GridController extends DefaultBaseController {

    @Autowired
    private IGridRemoteService gridRemoteService;
    @Autowired
    private ApiPathProperties apiPathProperties;

    @ApiOperation(value = "网格列表", notes = "网格列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("grid-list/{areaCode}")
    public List<GridDTO> getGridList(@PathVariable("areaCode") String areaCode) {
        String sendUrl = apiPathProperties.getUserCenter();
        // String sendUrl = "http://192.168.28.87:8081/systembase/";
        String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken();
        return gridRemoteService.getGridList(sendUrl, areaCode, accessToken);
    }

}