This commit is contained in:
磷叶 2025-05-12 17:55:20 +08:00
parent d5168b4c5d
commit c3f3b02a06
8 changed files with 47 additions and 36 deletions

View File

@ -77,4 +77,9 @@ public enum DeviceStatus {
public static List<String> canQLock() {
return canAdminLock();
}
// 不允许处理定位BUG的设备状态
public static List<String> notHandleLocationBug() {
return CollectionUtils.map(DeviceStatus::getCode, STORAGE, DISABLED);
}
}

View File

@ -35,6 +35,10 @@ public class DeviceUtil {
device.setLatitude(coordinates.get(0));
device.setLastLocationTime(at);
}
} else {
device.setLongitude(null);
device.setLatitude(null);
device.setLastLocationTime(null);
}
device.setLastTime(at);

View File

@ -1,8 +1,16 @@
package com.ruoyi.bst.order.domain.query;
import java.util.List;
import com.ruoyi.bst.order.domain.OrderQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class OrderStatQuery {
public class OrderStatQuery extends OrderQuery {
@ApiModelProperty("查询键值")
private List<String> keys;
}

View File

@ -111,6 +111,8 @@ public class RevenueStatVO {
private BigDecimal userBalance;
@ApiModelProperty("运营商数量")
private Integer userMchCount;
@ApiModelProperty("用户数量")
private Integer userCount;
@ApiModelProperty("车型数量")
private Integer modelCount;

View File

@ -281,6 +281,10 @@ public class DashboardService {
if (keys.contains(StatKeys.USER_BALANCE)) {
vo.setUserBalance(userDashboard.selectSumOfBalance(query.toUserQuery()));
}
// 用户数量
if (keys.contains(StatKeys.USER_COUNT)) {
vo.setUserCount(userDashboard.selectCount(query.toUserQuery()));
}
// 运营商数量
if (keys.contains(StatKeys.USER_MCH_COUNT)) {
vo.setUserMchCount(userDashboard.selectMchCount(query.toUserQuery()));

View File

@ -1,7 +1,6 @@
package com.ruoyi.iot.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
@ -26,7 +25,6 @@ import com.ruoyi.bst.device.service.DeviceService;
import com.ruoyi.bst.device.utils.DeviceUtil;
import com.ruoyi.bst.locationLog.domain.LocationLog;
import com.ruoyi.bst.locationLog.service.LocationLogConverter;
import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
@ -102,6 +100,12 @@ public class IotReceiveServiceImpl implements IotReceiveService {
log.error("更新设备信息失败: {}", msg.getDevName());
}
// 定位无效不处理
if (device.getLongitude() == null || device.getLatitude() == null) {
log.info("设备{}定位无效,不处理", device.getMac());
return;
}
// 处理设备定位BUG若出现BUG则重启设备
int handle = this.handleDeviceLocationBug(device, at, lastLocationTime, oldLon, oldLat);
if (handle == 1) {
@ -145,21 +149,15 @@ public class IotReceiveServiceImpl implements IotReceiveService {
if (duration.getSeconds() > 60) {
return 0;
}
// 0,0定位不处理
if (MathUtils.equals(device.getLongitude(), BigDecimal.ZERO) && MathUtils.equals(device.getLatitude(), BigDecimal.ZERO)) {
log.info("设备{}定位异常:{},{},不处理", device.getMac(), device.getLongitude(), device.getLatitude());
// 若设备禁用或者入库则不处理
if (DeviceStatus.notHandleLocationBug().contains(device.getStatus())) {
return 0;
}
boolean isOpen = DeviceQuality.OPEN.getCode().equals(device.getQuality()); // 电门是否开启
// 需要在设备未启动的时候做否则可能有安全问题
if (!isOpen) {
// 若当前数据点的上报时间和设备内上次上报的时间不一样但是定位一样则重启设备
log.info("当前定位:{},{},上次定位:{},{}",
device.getLongitude(),
device.getLatitude(),
oldLon,
oldLat
);
if (at.isAfter(lastLocationTime) && MathUtils.equals(device.getLongitude(), oldLon) && MathUtils.equals(device.getLatitude(), oldLat)) {
String reason = String.format("设备不同时间的两次定位一样,重启设备。新定位:%s,%s旧定位%s,%s", device.getLongitude(), device.getLatitude(), oldLon, oldLat);
deviceIotService.reboot(device, reason, true);
@ -187,11 +185,6 @@ public class IotReceiveServiceImpl implements IotReceiveService {
log.error("卫星数量小于5不处理: {}", device.getMac());
return;
}
// 0,0定位不处理
if (MathUtils.equals(device.getLongitude(), BigDecimal.ZERO) && MathUtils.equals(device.getLatitude(), BigDecimal.ZERO)) {
log.info("设备{}定位异常:{},{},不处理", device.getMac(), device.getLongitude(), device.getLatitude());
return;
}
// 若处理过则不处理
String key = CacheConstants.DEVICE_AREA_HANDLE_KEY + device.getMac();
Integer isHandle = redisCache.getCacheObject(key);
@ -293,17 +286,11 @@ public class IotReceiveServiceImpl implements IotReceiveService {
// 定位日志处理
private void handleLocationLog(DeviceVO device) {
// 卫星数量小于5不处理设备操作
// 卫星数量小于5不保存定位日志
if (device.getSatellites() == null || device.getSatellites() < 5) {
log.error("卫星数量小于5不处理: {}", device.getMac());
return;
}
// 0,0定位不处理
if (MathUtils.equals(device.getLongitude(), BigDecimal.ZERO) && MathUtils.equals(device.getLatitude(), BigDecimal.ZERO)) {
log.info("设备{}定位异常:{},{},不处理", device.getMac(), device.getLongitude(), device.getLatitude());
return;
}
// 转换定位日志
LocationLog po = locationLogConverter.toPo(device);
if (po == null) {

View File

@ -122,9 +122,9 @@ public class AppOrderController extends BaseController {
return success(fee);
}
@ApiOperation("操作订单设备开启")
@ApiOperation("订单开锁")
@PutMapping("/openDevice")
@Log(title = "操作订单设备开启", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
@Log(title = "订单开锁", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
public AjaxResult openDevice(Long orderId) {
OrderVO order = orderService.selectOrderById(orderId);
ServiceUtil.assertion(order == null, "订单不存在");
@ -133,9 +133,9 @@ public class AppOrderController extends BaseController {
return success(orderService.openDevice(order, true));
}
@ApiOperation("操作订单设备关闭")
@ApiOperation("临时锁车")
@PutMapping("/closeDevice")
@Log(title = "操作订单设备关闭", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
@Log(title = "临时锁车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
public AjaxResult closeDevice(@Validated OrderCloseDeviceDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId());
ServiceUtil.assertion(order == null, "订单不存在");
@ -145,9 +145,9 @@ public class AppOrderController extends BaseController {
return success(orderService.closeDevice(dto));
}
@ApiOperation("订单换车")
@ApiOperation("换车")
@PutMapping("/changeDevice")
@Log(title = "订单换车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
@Log(title = "换车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
public AjaxResult changeDevice(@RequestBody @Validated OrderChangeDeviceDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId());
ServiceUtil.assertion(!orderValidator.canChangeDevice(order, getUserId()), "您无权操作ID为%s的订单换车", order.getId());

View File

@ -14,6 +14,7 @@ import com.ruoyi.bst.order.constants.OrderDailyKeys;
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.enums.OrderStatus;
import com.ruoyi.bst.order.domain.query.OrderRefundQuery;
import com.ruoyi.bst.order.domain.query.OrderStatQuery;
import com.ruoyi.bst.order.domain.vo.OrderDailyRefundStatVO;
import com.ruoyi.bst.order.domain.vo.OrderDailyStatVO;
import com.ruoyi.bst.order.domain.vo.OrderRankVO;
@ -78,10 +79,10 @@ public class DashboardOrderController extends BaseController {
return success(list);
}
// @PreAuthorize("@ss.hasPermi('dashboard:order:stat')")
// @GetMapping("/stat")
// public AjaxResult getStat(OrderStatQuery query) {
// query.setScope(true);
// return success(orderDashboard.selectStat(query));
// }
@PreAuthorize("@ss.hasPermi('dashboard:order:stat')")
@GetMapping("/stat")
public AjaxResult getStat(OrderStatQuery query) {
query.setScope(true);
return success(orderDashboard.selectStat(query, query.getKeys()));
}
}