88 lines
2.9 KiB
Java
88 lines
2.9 KiB
Java
package com.ruoyi.web.app;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.List;
|
||
import java.util.Objects;
|
||
|
||
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 com.ruoyi.common.domain.vo.LongIntegerVO;
|
||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||
|
||
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之间");
|
||
}
|
||
if (query.getCenter() == null) {
|
||
return error("中心坐标不能为空");
|
||
}
|
||
if (query.getCenter().size() != 2) {
|
||
return error("中心坐标格式错误,必须包含经度和纬度");
|
||
}
|
||
setQuery(query);
|
||
|
||
// 按设备数量排序,查询附近的运营区
|
||
Long areaId = query.getId();
|
||
query.setId(null);
|
||
List<LongIntegerVO> list = areaDashboard.selectMaxOfDeviceCountAreaId(query);
|
||
if (CollectionUtils.isEmptyElement(list)) {
|
||
return success();
|
||
}
|
||
|
||
// 如果有传运营区ID,则优先找运营区
|
||
LongIntegerVO max = null;
|
||
if (areaId != null) {
|
||
max = list.stream().filter(item -> Objects.equals(item.getKey(), areaId)).findFirst().orElse(null);
|
||
}
|
||
// 若没有找到对应运营区,则取设备数量最多的运营区
|
||
if (max == null) {
|
||
max = list.get(0);
|
||
}
|
||
|
||
// 查询运营区详情
|
||
return success(areaService.selectAreaById(max.getKey()));
|
||
}
|
||
|
||
}
|