2025-04-11 18:08:08 +08:00
|
|
|
|
package com.ruoyi.web.app;
|
|
|
|
|
|
2025-04-22 14:27:55 +08:00
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
2025-04-11 18:08:08 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.bst.device.domain.DeviceVO;
|
|
|
|
|
import com.ruoyi.bst.device.service.DeviceIotService;
|
|
|
|
|
import com.ruoyi.bst.device.service.DeviceService;
|
2025-04-22 12:00:46 +08:00
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
2025-04-11 18:08:08 +08:00
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
2025-04-22 12:00:46 +08:00
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
|
import com.ruoyi.common.enums.LogBizType;
|
2025-04-22 14:27:55 +08:00
|
|
|
|
import com.ruoyi.common.utils.MathUtils;
|
2025-04-11 18:08:08 +08:00
|
|
|
|
import com.ruoyi.common.utils.ServiceUtil;
|
2025-04-22 14:27:55 +08:00
|
|
|
|
import com.ruoyi.common.utils.map.GeoUtils;
|
2025-04-11 18:08:08 +08:00
|
|
|
|
import com.ruoyi.iot.constants.IotConstants;
|
|
|
|
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/app/device/iot")
|
|
|
|
|
public class AppDeviceIotController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceIotService deviceIotService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceService deviceService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("用户响铃寻车")
|
|
|
|
|
@PutMapping("/ring")
|
2025-04-22 12:00:46 +08:00
|
|
|
|
@Log(title = "用户响铃寻车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.DEVICE)
|
2025-04-22 14:27:55 +08:00
|
|
|
|
public AjaxResult ring(@RequestParam(required = false) Long id,
|
|
|
|
|
@RequestParam(required = false) String sn,
|
|
|
|
|
@RequestParam(required = false) BigDecimal lon,
|
|
|
|
|
@RequestParam(required = false) BigDecimal lat) {
|
2025-04-15 18:16:16 +08:00
|
|
|
|
DeviceVO device = null;
|
|
|
|
|
if (id != null) {
|
|
|
|
|
device = deviceService.selectDeviceById(id);
|
|
|
|
|
} else {
|
|
|
|
|
device = deviceService.selectDeviceBySn(sn);
|
|
|
|
|
}
|
|
|
|
|
ServiceUtil.assertion(device == null, "当前车辆不存在,无法响铃寻车");
|
2025-04-22 14:27:55 +08:00
|
|
|
|
|
|
|
|
|
if (device.getAreaRequiredRingRadius() != null && device.getAreaRequiredRingRadius()) {
|
2025-04-30 11:47:57 +08:00
|
|
|
|
ServiceUtil.assertion(lon == null || lat == null, "请开启定位后重试");
|
2025-04-22 14:27:55 +08:00
|
|
|
|
BigDecimal distance = GeoUtils.calculateDistance(device.getLatitude(), device.getLongitude(), lat, lon);
|
|
|
|
|
ServiceUtil.assertion(MathUtils.biggerThan(distance, device.getAreaRingRadius()),
|
|
|
|
|
"您当前距离车辆%s米,无法响铃寻车。请距离车辆%s米以内再试", distance, device.getAreaRingRadius());
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-14 18:07:16 +08:00
|
|
|
|
return toAjax(deviceIotService.play(device, IotConstants.PLAY_WARNING, "用户响铃寻车", true));
|
2025-04-11 18:08:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|