package com.ruoyi.web.app;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.area.domain.AreaQuery;
import com.ruoyi.bst.area.domain.enums.AreaStatus;
import com.ruoyi.bst.area.service.AreaDashboard;
import com.ruoyi.bst.area.service.AreaService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/app/area")
public class AppAreaController extends BaseController {
    
    @Autowired
    private AreaService areaService;

    @Autowired
    private AreaDashboard areaDashboard;

    // 设置前提条件
    private void setQuery(AreaQuery query) {
        query.setStatus(AreaStatus.ENABLED.getCode());
    }

    @ApiOperation("获取运营区详情")
    @GetMapping("/detail")
    @Anonymous
    public AjaxResult getAreaDetail(Long id) {
        AreaQuery query = new AreaQuery();
        query.setId(id);
        setQuery(query);
        return success(areaService.selectOne(query));
    }

    @ApiOperation("获取附近的运营区")
    @GetMapping("/nearby")
    @Anonymous
    public AjaxResult getNearbyArea(AreaQuery query) {
        if (query.getRadius() == null || query.getRadius().compareTo(BigDecimal.ZERO) <= 0 || query.getRadius().compareTo(BigDecimal.valueOf(10000)) > 0) {
            return error("半径必须在0-10000之间");
        }
        return success(areaService.selectNearBy(query));
    }
    
}
