package com.ruoyi.ibs.custmap.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.ibs.custmap.domain.dto.CustMapCircleDTO;
import com.ruoyi.ibs.custmap.domain.vo.CustMapVO;
import com.ruoyi.ibs.custmap.service.CustMapSelectService;
import com.ruoyi.ibs.custmap.service.DeptAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

@Api(tags = "地图拓客接口")
@Slf4j
@RestController
@RequestMapping("/cust/map")
public class CustMapController extends BaseController {
    @Resource
    private CustMapSelectService custMapSelectService;
    @Resource
    private DeptAddressService deptAddressService;

    @ApiOperation("坐标和半径查询用户列表")
    @PostMapping("/search/circle")
    public AjaxResult searchCustByCircle(@RequestBody @Valid CustMapCircleDTO custMapCircleDTO) {
        if (Objects.isNull(custMapCircleDTO.getNum()) || Objects.isNull(custMapCircleDTO.getSize())){
            throw new ServiceException("请输入页码和每页条数");
        }
        List<CustMapVO> custMapVOS = custMapSelectService.selectCustListByCircle(custMapCircleDTO);
        return success(custMapVOS);
    }

    @ApiOperation("坐标和半径搜索用户数量")
    @PostMapping("/search/circle/count")
    public AjaxResult countCustMapListByCircle(@RequestBody @Valid CustMapCircleDTO custMapCircleDTO) {
        return success(custMapSelectService.countCustMapListByCircle(custMapCircleDTO));
    }

    @ApiOperation("获取用户默认地址")
    @GetMapping("/loc")
    public AjaxResult getDefaultLoc() {
        return success(deptAddressService.selectDeptAddressById());
    }

    @ApiOperation("获取新华社数据")
    @GetMapping("/info")
    public AjaxResult getRadarInfo(@RequestParam Integer id) {
        return success(custMapSelectService.selectCustInfoRadarById(id));
    }

}
