debug:设备状态问题
This commit is contained in:
parent
1622cac9a9
commit
08d8520aee
|
@ -1,15 +1,15 @@
|
|||
package com.ruoyi.bst.commandLog.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 命令日志对象 bst_command_log
|
||||
|
@ -61,4 +61,11 @@ public class CommandLog extends BaseEntity
|
|||
@ApiModelProperty("返回值code")
|
||||
private Integer iotCode;
|
||||
|
||||
@Excel(name = "经度")
|
||||
@ApiModelProperty("经度")
|
||||
private BigDecimal longitude;
|
||||
|
||||
@Excel(name = "纬度")
|
||||
@ApiModelProperty("纬度")
|
||||
private BigDecimal latitude;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bcl.user_id,
|
||||
bcl.user_name,
|
||||
bcl.opera_time,
|
||||
bcl.iot_code
|
||||
bcl.iot_code,
|
||||
bcl.longitude,
|
||||
bcl.latitude
|
||||
from bst_command_log bcl
|
||||
</sql>
|
||||
|
||||
|
@ -59,6 +61,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
user_name,
|
||||
opera_time,
|
||||
iot_code,
|
||||
longitude,
|
||||
latitude
|
||||
</trim>
|
||||
values
|
||||
<foreach collection="list" item="i" separator=",">
|
||||
|
@ -81,6 +85,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="i.operaTime == null ">default,</if>
|
||||
<if test="i.iotCode != null ">#{i.iotCode},</if>
|
||||
<if test="i.iotCode == null ">default,</if>
|
||||
<if test="i.longitude != null ">#{i.longitude},</if>
|
||||
<if test="i.longitude == null ">default,</if>
|
||||
<if test="i.latitude != null ">#{i.latitude},</if>
|
||||
<if test="i.latitude == null ">default,</if>
|
||||
</trim>
|
||||
</foreach>
|
||||
</insert>
|
||||
|
@ -97,6 +105,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userName != null">user_name,</if>
|
||||
<if test="operaTime != null">opera_time,</if>
|
||||
<if test="iotCode != null">iot_code,</if>
|
||||
<if test="longitude != null">longitude,</if>
|
||||
<if test="latitude != null">latitude,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="type != null and type != ''">#{type},</if>
|
||||
|
@ -108,6 +118,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userName != null">#{userName},</if>
|
||||
<if test="operaTime != null">#{operaTime},</if>
|
||||
<if test="iotCode != null">#{iotCode},</if>
|
||||
<if test="longitude != null">#{longitude},</if>
|
||||
<if test="latitude != null">#{latitude},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -129,6 +141,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.userName != null">user_name = #{data.userName},</if>
|
||||
<if test="data.operaTime != null">opera_time = #{data.operaTime},</if>
|
||||
<if test="data.iotCode != null">iot_code = #{data.iotCode},</if>
|
||||
<if test="data.longitude != null">longitude = #{data.longitude},</if>
|
||||
<if test="data.latitude != null">latitude = #{data.latitude},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deleteCommandLogById" parameterType="Long">
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.ruoyi.bst.commandLog.domain.CommandLog;
|
|||
import com.ruoyi.bst.commandLog.domain.CommandLogQuery;
|
||||
import com.ruoyi.bst.commandLog.domain.CommandLogVO;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.iot.interfaces.IotDevice;
|
||||
|
||||
/**
|
||||
* 命令日志Service接口
|
||||
|
@ -74,7 +75,7 @@ public interface CommandLogService
|
|||
* @param loginUser
|
||||
* @param iotCode
|
||||
*/
|
||||
int addApiLog(String mac, String command, String result, String reason, LoginUser loginUser, Integer iotCode);
|
||||
int addApiLog(IotDevice device, String command, String result, String reason, LoginUser loginUser, Integer iotCode);
|
||||
|
||||
/**
|
||||
* 插入一条蓝牙命令日志
|
||||
|
|
|
@ -4,20 +4,21 @@ import java.time.LocalDate;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.bst.commandLog.domain.enums.CommandLogType;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ruoyi.bst.commandLog.domain.CommandLog;
|
||||
import com.ruoyi.bst.commandLog.domain.CommandLogQuery;
|
||||
import com.ruoyi.bst.commandLog.domain.CommandLogVO;
|
||||
import com.ruoyi.bst.commandLog.domain.enums.CommandLogType;
|
||||
import com.ruoyi.bst.commandLog.mapper.CommandLogMapper;
|
||||
import com.ruoyi.bst.commandLog.service.CommandLogService;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.interfaces.IotDevice;
|
||||
|
||||
/**
|
||||
* 命令日志Service业务层处理
|
||||
|
@ -108,14 +109,16 @@ public class CommandLogServiceImpl implements CommandLogService
|
|||
|
||||
|
||||
@Override
|
||||
public int addApiLog(String mac, String command, String result, String reason, LoginUser loginUser, Integer iotCode) {
|
||||
public int addApiLog(IotDevice device, String command, String result, String reason, LoginUser loginUser, Integer iotCode) {
|
||||
CommandLog po = new CommandLog();
|
||||
po.setType(CommandLogType.API.getType());
|
||||
po.setMac(mac);
|
||||
po.setMac(device.mac());
|
||||
po.setCommand(command);
|
||||
po.setResult(result);
|
||||
po.setReason(reason);
|
||||
po.setIotCode(iotCode);
|
||||
po.setLongitude(device.longitude());
|
||||
po.setLatitude(device.latitude());
|
||||
return this.addLog(po, loginUser);
|
||||
}
|
||||
|
||||
|
|
|
@ -150,4 +150,14 @@ public class Device extends BaseEntity implements IotDevice
|
|||
public String mac() {
|
||||
return this.mac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal longitude() {
|
||||
return this.longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal latitude() {
|
||||
return this.latitude;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,14 +52,28 @@ public enum DeviceStatus {
|
|||
return CollectionUtils.map(DeviceStatus::getCode, IN_USE, AVAILABLE, TEMP_LOCKED);
|
||||
}
|
||||
|
||||
// 允许锁车的设备状态
|
||||
public static List<String> canLock() {
|
||||
// 允许用户锁车的设备状态
|
||||
public static List<String> canUserLock() {
|
||||
return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, TEMP_LOCKED, DISPATCHING, IN_USE);
|
||||
}
|
||||
|
||||
// 允许管理员锁车的状态
|
||||
public static List<String> canAdminLock() {
|
||||
return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, TEMP_LOCKED, DISPATCHING, IN_USE, Q_LOCKED);
|
||||
}
|
||||
|
||||
// 允许用户使用的设备状态
|
||||
public static List<String> canUse() {
|
||||
return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE);
|
||||
}
|
||||
|
||||
}
|
||||
// 允许返回运营区上电
|
||||
public static List<String> canBackUnlock() {
|
||||
return CollectionUtils.map(DeviceStatus::getCode, Q_LOCKED);
|
||||
}
|
||||
|
||||
// 允许强制锁车的状态
|
||||
public static List<String> canQLock() {
|
||||
return canAdminLock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.ruoyi.bst.device.domain.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceUnLockType {
|
||||
ADMIN("ADMIN", "管理员开锁"),
|
||||
USER("USER", "用户开锁"),
|
||||
BACK_AREA("BACK_AREA", "返回运营区上电");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
}
|
|
@ -4,17 +4,19 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
|
||||
public interface DeviceIotService {
|
||||
|
||||
/**
|
||||
* 开锁
|
||||
*
|
||||
* @param device 设备
|
||||
* @param isAdmin 是否管理员操作
|
||||
* @param type 是否管理员操作
|
||||
* @param reason 原因
|
||||
* @return 结果
|
||||
*/
|
||||
int unlock(DeviceVO device, boolean isAdmin, String reason, boolean requiredIot);
|
||||
int unlock(DeviceVO device, DeviceUnLockType type, String reason, boolean requiredIot);
|
||||
|
||||
/**
|
||||
* 锁车
|
||||
|
@ -28,13 +30,13 @@ public interface DeviceIotService {
|
|||
|
||||
/**
|
||||
* 强制断电
|
||||
* @param device 设备
|
||||
* @param isAdmin 是否管理员操作
|
||||
* @param reason 原因
|
||||
*
|
||||
* @param device 设备
|
||||
* @param reason 原因
|
||||
* @param requiredIot 是否IOT操作必须成功
|
||||
* @return 结果
|
||||
*/
|
||||
int qLock(DeviceVO device, boolean isAdmin, String reason, boolean requiredIot);
|
||||
int qLock(DeviceVO device, String reason, boolean requiredIot);
|
||||
|
||||
/**
|
||||
* 播放语音
|
||||
|
@ -45,7 +47,7 @@ public interface DeviceIotService {
|
|||
*/
|
||||
boolean play(DeviceVO device, String type, String reason);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 重启
|
||||
* @param device 设备
|
||||
* @param reason 原因
|
||||
|
@ -97,12 +99,13 @@ public interface DeviceIotService {
|
|||
|
||||
/**
|
||||
* 开锁
|
||||
* @param id 设备ID
|
||||
* @param isAdmin 是否管理员操作
|
||||
*
|
||||
* @param id 设备ID
|
||||
* @param type 是否管理员操作
|
||||
* @param reason 原因
|
||||
* @return 结果
|
||||
*/
|
||||
int unlock(Long id, boolean isAdmin, String reason, boolean requiredIot);
|
||||
int unlock(Long id, DeviceUnLockType type, String reason, boolean requiredIot);
|
||||
|
||||
/**
|
||||
* 监控设备
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Objects;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
@ -53,33 +54,38 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
private final static Integer SUB_SLOW = 300; // 上报频率(慢)
|
||||
|
||||
@Override
|
||||
public int unlock(DeviceVO device, boolean isAdmin, String reason, boolean requiredIot) {
|
||||
public int unlock(DeviceVO device, DeviceUnLockType type, String reason, boolean requiredIot) {
|
||||
if (device == null || device.getId() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isAdmin) {
|
||||
// 更新设备状态
|
||||
Device data = new Device();
|
||||
data.setLockStatus(DeviceLockStatus.OPEN.getCode());
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setId(device.getId());
|
||||
|
||||
// 管理员解锁
|
||||
if (DeviceUnLockType.ADMIN.equals(type)) {
|
||||
ServiceUtil.assertion(!DeviceStatus.canAdminUnlock().contains(device.getStatus()), "设备%s当前状态不允许管理员开锁", device.getSn());
|
||||
} else {
|
||||
data.setStatus(DeviceStatus.DISPATCHING.getCode());
|
||||
query.setStatusList(DeviceStatus.canAdminUnlock());
|
||||
}
|
||||
// 用户解锁
|
||||
else if (DeviceUnLockType.USER.equals(type)) {
|
||||
ServiceUtil.assertion(!DeviceStatus.canUserUnlock().contains(device.getStatus()), "设备%s当前状态不允许用户开锁", device.getSn());
|
||||
data.setStatus(DeviceStatus.IN_USE.getCode());
|
||||
query.setStatusList(DeviceStatus.canUserUnlock());
|
||||
}
|
||||
// 返回运营区上电
|
||||
else if (DeviceUnLockType.BACK_AREA.equals(type)) {
|
||||
ServiceUtil.assertion(!DeviceStatus.canBackUnlock().contains(device.getStatus()), "设备%s当前状态不允许返回运营区开锁", device.getSn());
|
||||
data.setStatus(DeviceStatus.IN_USE.getCode());
|
||||
query.setStatusList(DeviceStatus.canBackUnlock());
|
||||
}
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 更新设备状态
|
||||
Device data = new Device();
|
||||
data.setLockStatus(DeviceLockStatus.OPEN.getCode());
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setId(device.getId());
|
||||
// 管理员开锁
|
||||
if (isAdmin) {
|
||||
data.setStatus(DeviceStatus.DISPATCHING.getCode());
|
||||
query.setStatusList(DeviceStatus.canAdminUnlock());
|
||||
}
|
||||
// 用户开锁
|
||||
else {
|
||||
data.setStatus(DeviceStatus.IN_USE.getCode());
|
||||
query.setStatusList(DeviceStatus.canUserUnlock());
|
||||
}
|
||||
// 更新数据库
|
||||
int rows = deviceMapper.updateByQuery(data, query);
|
||||
|
||||
if (rows > 0) {
|
||||
|
@ -104,20 +110,25 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
if (device == null || device.getId() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ServiceUtil.assertion(!DeviceStatus.canLock().contains(device.getStatus()), "设备%s当前状态不允许锁车", device.getSn());
|
||||
|
||||
// 是否有正在进行的订单
|
||||
boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus());
|
||||
|
||||
// 构造数据
|
||||
Device data = new Device();
|
||||
data.setLockStatus(DeviceLockStatus.CLOSE.getCode());
|
||||
data.setStatus(hasOrder ? DeviceStatus.TEMP_LOCKED.getCode() : DeviceStatus.AVAILABLE.getCode());
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setId(device.getId());
|
||||
if (isAdmin) {
|
||||
ServiceUtil.assertion(!DeviceStatus.canAdminLock().contains(device.getStatus()), "设备%s当前状态不允许管理员锁车", device.getSn());
|
||||
query.setStatusList(DeviceStatus.canAdminLock());
|
||||
} else {
|
||||
ServiceUtil.assertion(!DeviceStatus.canUserLock().contains(device.getStatus()), "设备%s当前状态不允许用户锁车", device.getSn());
|
||||
query.setStatusList(DeviceStatus.canUserLock());
|
||||
}
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 更新设备状态
|
||||
Device data = new Device();
|
||||
data.setLockStatus(DeviceLockStatus.CLOSE.getCode());
|
||||
data.setStatus(hasOrder ? DeviceStatus.TEMP_LOCKED.getCode() : DeviceStatus.AVAILABLE.getCode());
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setId(device.getId());
|
||||
query.setStatusList(DeviceStatus.canLock());
|
||||
int rows = deviceMapper.updateByQuery(data, query);
|
||||
|
||||
if (rows > 0) {
|
||||
|
@ -138,11 +149,11 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int qLock(DeviceVO device, boolean isAdmin, String reason, boolean requiredIot) {
|
||||
public int qLock(DeviceVO device, String reason, boolean requiredIot) {
|
||||
if (device == null || device.getId() == null) {
|
||||
return 0;
|
||||
}
|
||||
ServiceUtil.assertion(!DeviceStatus.canLock().contains(device.getStatus()), "设备%s当前状态不允许锁车", device.getSn());
|
||||
ServiceUtil.assertion(!DeviceStatus.canQLock().contains(device.getStatus()), "设备%s当前状态不允许强制锁车", device.getSn());
|
||||
|
||||
// 是否有正在进行的订单
|
||||
boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus());
|
||||
|
@ -154,7 +165,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
data.setStatus(hasOrder ? DeviceStatus.Q_LOCKED.getCode() : DeviceStatus.AVAILABLE.getCode());
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setId(device.getId());
|
||||
query.setStatusList(DeviceStatus.canLock());
|
||||
query.setStatusList(DeviceStatus.canQLock());
|
||||
int rows = deviceMapper.updateByQuery(data, query);
|
||||
|
||||
if (rows > 0) {
|
||||
|
@ -296,7 +307,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int unlock(Long id, boolean isAdmin, String reason, boolean requiredIot) {
|
||||
public int unlock(Long id, DeviceUnLockType type, String reason, boolean requiredIot) {
|
||||
if (id == null) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -304,7 +315,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
if (device == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.unlock(device, isAdmin, reason, requiredIot);
|
||||
return this.unlock(device, type, reason, requiredIot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,13 +9,13 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class OrderEndDTO {
|
||||
|
||||
|
||||
@ApiModelProperty("订单ID")
|
||||
@NotNull(message = "订单ID不能为空")
|
||||
private Long orderId;
|
||||
|
||||
@ApiModelProperty("是否忽略还车位置(辅助还车)")
|
||||
private Boolean ignoreInParking;
|
||||
@ApiModelProperty("是否辅助还车(管理员还车)")
|
||||
private Boolean isAdmin;
|
||||
|
||||
@ApiModelProperty("手机定位(经度)")
|
||||
private BigDecimal lon;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.bst.order.service.impl;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import com.ruoyi.bst.device.service.DeviceIotService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -73,7 +74,7 @@ public class OrderPayHandlerImpl implements PayHandler {
|
|||
int start = orderDeviceService.start(orderDevice);
|
||||
ServiceUtil.assertion(start != 1, "开始使用ID为%s的订单设备失败", orderDevice.getId());
|
||||
|
||||
int unlock = deviceIotService.unlock(orderDevice.getDeviceId(), false, "订单支付成功开锁:" + order.getNo(), false);
|
||||
int unlock = deviceIotService.unlock(orderDevice.getDeviceId(), DeviceUnLockType.USER, "订单支付成功开锁:" + order.getNo(), false);
|
||||
ServiceUtil.assertion(unlock <= 0, "ID为%s的设备解锁失败", orderDevice.getDeviceId());
|
||||
|
||||
return rows;
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
@ -382,7 +383,7 @@ public class OrderServiceImpl implements OrderService
|
|||
// 转为BO对象
|
||||
OrderEndBO bo = orderConverter.toEndBO(dto);
|
||||
// 校验参数
|
||||
boolean ignoreInParking = dto.getIgnoreInParking() != null && dto.getIgnoreInParking();
|
||||
boolean ignoreInParking = dto.getIsAdmin() != null && dto.getIsAdmin();
|
||||
orderValidator.validate(bo, ignoreInParking);
|
||||
|
||||
OrderVO order = bo.getOrder();
|
||||
|
@ -451,7 +452,7 @@ public class OrderServiceImpl implements OrderService
|
|||
ServiceUtil.assertion(finish != 1, "结束ID为%s的订单设备失败", orderDevice.getId());
|
||||
|
||||
// 设备上锁(必须放最后,因为会操作设备)
|
||||
int lock = deviceIotService.lock(orderDevice.getDeviceId(), false, "订单结束上锁:" + orderDevice.getOrderNo(), false);
|
||||
int lock = deviceIotService.lock(orderDevice.getDeviceId(), dto.getIsAdmin(), "订单结束上锁:" + orderDevice.getOrderNo(), false);
|
||||
ServiceUtil.assertion(lock != 1, "ID为%s的设备上锁失败", orderDevice.getDeviceId());
|
||||
|
||||
return rows;
|
||||
|
@ -567,7 +568,7 @@ public class OrderServiceImpl implements OrderService
|
|||
ServiceUtil.assertion(orderDevice == null, "ID为%s的订单设备不存在", order.getId());
|
||||
ServiceUtil.assertion(!OrderDeviceStatus.inUse().contains(orderDevice.getStatus()), "ID为%s的订单设备当前状态并非使用中,无法操作设备", order.getId());
|
||||
|
||||
return deviceIotService.unlock(orderDevice.getDeviceId(), false, "订单开锁:" + order.getNo(), requiredIot);
|
||||
return deviceIotService.unlock(orderDevice.getDeviceId(), DeviceUnLockType.USER, "订单开锁:" + order.getNo(), requiredIot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -629,7 +630,7 @@ public class OrderServiceImpl implements OrderService
|
|||
int lock = deviceIotService.lock(oldOrderDevice.getDeviceId(), false, "订单换车上锁:" + order.getNo(), false);
|
||||
ServiceUtil.assertion(lock != 1, "ID为%s的旧设备上锁失败", oldOrderDevice.getDeviceId());
|
||||
// 新设备解锁
|
||||
int unlock = deviceIotService.unlock(newOrderDevice.getDeviceId(), false, "订单换车开锁:" + order.getNo(), false);
|
||||
int unlock = deviceIotService.unlock(newOrderDevice.getDeviceId(), DeviceUnLockType.USER, "订单换车开锁:" + order.getNo(), false);
|
||||
ServiceUtil.assertion(unlock <= 0, "ID为%s的新设备解锁失败", newOrderDevice.getDeviceId());
|
||||
|
||||
return start;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.ruoyi.iot.interfaces;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/9/25
|
||||
|
@ -9,4 +11,10 @@ public interface IotDevice {
|
|||
// 获取MAC-1
|
||||
String mac();
|
||||
|
||||
// 定位(经度)
|
||||
BigDecimal longitude();
|
||||
|
||||
// 定位(纬度)
|
||||
BigDecimal latitude();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.time.LocalDateTime;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -161,9 +162,9 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
|
||||
// 在运营区内,并且不在禁行区内,并且车辆为强制断电状态,为车辆上电
|
||||
if (isInAreaMax && !isInNoRidingArea && isQLocked && !isOpen && hasOrder) {
|
||||
deviceIotService.unlock(device, false, "重新返回运营区上电", false);
|
||||
deviceIotService.unlock(device, DeviceUnLockType.BACK_AREA, "重新返回运营区上电", false);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 靠近运营区内边界,且车辆为开锁状态,播报语音警告
|
||||
if(isOpen) {
|
||||
|
@ -172,7 +173,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
if (areaOutOutage) {
|
||||
// 超出运营区最大边界,强制断电
|
||||
if (!isInAreaMax) {
|
||||
deviceIotService.qLock(device, false, "超出运营区外边界最大值,强制断电", false);
|
||||
deviceIotService.qLock(device, "超出运营区外边界最大值,强制断电", false);
|
||||
return 1;
|
||||
}
|
||||
boolean isInArea = AreaUtil.isInArea(area, device.getLongitude(), device.getLatitude()); // 是否在运营区内
|
||||
|
@ -186,14 +187,14 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
if(!isInArea && isInAreaMax) {
|
||||
deviceIotService.play(device, IotConstants.PLAY_BOUNDARY_OUT, "超出运营区外边界,还未到达断电距离");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean noRidingOutage = area.getNoRidingOutage() != null && area.getNoRidingOutage(); // 禁行区内断电
|
||||
if (noRidingOutage) {
|
||||
// 进入禁行区,强制断电
|
||||
if (isInNoRidingArea) {
|
||||
deviceIotService.qLock(device, false, "进入禁行区,强制断电", false);
|
||||
deviceIotService.qLock(device, "进入禁行区,强制断电", false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -206,7 +207,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class IotServiceImpl implements IotService {
|
|||
String status = redisCache.getCacheObject(cacheKey);
|
||||
if (StringUtils.isBlank(status)) {
|
||||
// 发送命令
|
||||
CommandResponse res = uploadData(deviceName, productId, "获取在线状态");
|
||||
CommandResponse res = uploadData(device, "获取在线状态");
|
||||
status = this.parseToOnlineStatus(res, deviceName, false);
|
||||
}
|
||||
|
||||
|
@ -251,15 +251,19 @@ public class IotServiceImpl implements IotService {
|
|||
return paramsObj.getInteger("code");
|
||||
}
|
||||
|
||||
private CommandResponse sendCommand(String deviceName, String command, String productId, String reason) {
|
||||
return sendCommand(deviceName, command, null, productId, reason);
|
||||
private CommandResponse sendCommand(IotDevice device, String command, String reason) {
|
||||
return sendCommand(device, command, null, reason);
|
||||
}
|
||||
|
||||
// 发送MQTT命令
|
||||
private CommandResponse sendCommand(String deviceName, String command, Integer timeout, String productId, String reason) {
|
||||
private CommandResponse sendCommand(IotDevice device, String command, Integer timeout, String reason) {
|
||||
if (device == null || StringUtils.isAnyBlank(device.mac(), command)) {
|
||||
return null;
|
||||
}
|
||||
if (timeout == null) {
|
||||
timeout = this.timeout;
|
||||
}
|
||||
String deviceName = device.mac();
|
||||
String sendUrl = iotHost + IotConstants.ADDS_COMMAND;
|
||||
String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
|
||||
sendUrl = sendUrl + "?" + param;
|
||||
|
@ -271,7 +275,7 @@ public class IotServiceImpl implements IotService {
|
|||
CommandResponse res = JSON.parseObject(result, CommandResponse.class);
|
||||
|
||||
// 记录成功日志
|
||||
this.addCommandLog(deviceName, command, res.getMsg(), reason, res.getCode());
|
||||
this.addCommandLog(device, command, res.getMsg(), reason, res.getCode());
|
||||
|
||||
// 转为在线状态,并缓存结果30秒
|
||||
String status = this.parseToOnlineStatus(res, deviceName, true);
|
||||
|
@ -286,77 +290,59 @@ public class IotServiceImpl implements IotService {
|
|||
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
this.addCommandLog(deviceName, command, "操作失败:" + e.getMessage(), reason, null);
|
||||
this.addCommandLog(device, command, "操作失败:" + e.getMessage(), reason, null);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// 异步添加日志
|
||||
private void addCommandLog(String deviceName, String command, String result, String reason, Integer iotCode) {
|
||||
// 新增命令日志
|
||||
private void addCommandLog(IotDevice device, String command, String result, String reason, Integer iotCode) {
|
||||
LoginUser loginUser = null;
|
||||
try {
|
||||
loginUser = SecurityUtils.getLoginUser();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
commandLogService.addApiLog(deviceName, command, result, reason, loginUser, iotCode);
|
||||
commandLogService.addApiLog(device, command, result, reason, loginUser, iotCode);
|
||||
}
|
||||
|
||||
private CommandResponse uploadData(String deviceName, String productId, String reason) {
|
||||
if (StringUtils.isBlank(deviceName) || StringUtils.isBlank(productId)) {
|
||||
return null;
|
||||
}
|
||||
return sendCommand(deviceName, IotConstants.COMMAND_UPLOAD_DATA, productId, reason);
|
||||
private CommandResponse uploadData(IotDevice device, String reason) {
|
||||
return sendCommand(device, IotConstants.COMMAND_UPLOAD_DATA, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse unlock(IotDevice device, int sub, String reason) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
String command = IotConstants.COMMAND_UNLOCK + IotConstants.COMMAND_SUB + sub + IotConstants.COMMAND_SEPARATOR;
|
||||
return sendCommand(device.mac(), command, productId, reason);
|
||||
return sendCommand(device, command, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse lock(IotDevice device, int sub, String reason) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
String command = IotConstants.COMMAND_LOCK + IotConstants.COMMAND_SUB + sub + IotConstants.COMMAND_SEPARATOR;
|
||||
return sendCommand(device.mac(), command, productId, reason);
|
||||
return sendCommand(device, command, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse qLock(IotDevice device, int sub, String reason) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
String command = IotConstants.COMMAND_QLOSE + IotConstants.COMMAND_SUB + sub + IotConstants.COMMAND_SEPARATOR;
|
||||
return sendCommand(device.mac(), command, productId, reason);
|
||||
return sendCommand(device, command, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse play(IotDevice device, String type, String reason) {
|
||||
if (device == null || StringUtils.isBlank(type)) {
|
||||
if (StringUtils.isBlank(type)) {
|
||||
return null;
|
||||
}
|
||||
return sendCommand(device.mac(), IotConstants.COMMAND_PLAY + type, productId, reason);
|
||||
return sendCommand(device, IotConstants.COMMAND_PLAY + type, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse reboot(IotDevice device, String reason) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
return sendCommand(device.mac(), IotConstants.COMMAND_REBOOT, productId, reason);
|
||||
return sendCommand(device, IotConstants.COMMAND_REBOOT, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse unlockSeat(IotDevice device, String reason) {
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
return sendCommand(device.mac(), IotConstants.COMMAND_HPEN, productId, reason);
|
||||
return sendCommand(device, IotConstants.COMMAND_HPEN, reason);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,9 @@ public class OrderTask implements ApplicationRunner {
|
|||
for (OrderVO order : orderList) {
|
||||
try {
|
||||
OrderEndDTO dto = new OrderEndDTO();
|
||||
dto.setIgnoreInParking(true);
|
||||
dto.setIsAdmin(true);
|
||||
dto.setOrderId(order.getId());
|
||||
dto.setEndReason("系统自动结束");
|
||||
dto.setEndReason("超时系统自动结束");
|
||||
orderService.endOrder(dto);
|
||||
} catch (Exception e) {
|
||||
log.error("结束订单失败,订单ID:{}", order.getId(), e);
|
||||
|
|
|
@ -104,7 +104,7 @@ public class AppOrderController extends BaseController {
|
|||
public AjaxResult endOrder(@RequestBody @Validated OrderEndDTO dto) {
|
||||
OrderVO order = orderService.selectOrderById(dto.getOrderId());
|
||||
ServiceUtil.assertion(!orderValidator.canEnd(order, getUserId()), "您无权结束ID为%s的订单", order.getId());
|
||||
dto.setIgnoreInParking(false);
|
||||
dto.setIsAdmin(false);
|
||||
dto.setEndReason("用户【" + getNickName() + "】手动还车");
|
||||
return success(orderService.endOrder(dto));
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class AppOrderController extends BaseController {
|
|||
@ApiOperation("计算订单费用")
|
||||
@PostMapping("/calcFee")
|
||||
public AjaxResult calcFee(@RequestBody @Validated OrderEndDTO dto) {
|
||||
dto.setIgnoreInParking(false);
|
||||
dto.setIsAdmin(false);
|
||||
OrderFeeVO fee = orderService.calcOrderFee(dto);
|
||||
ServiceUtil.assertion(fee == null, "价格计算失败");
|
||||
return success(fee);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.web.bst;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
@ -42,7 +43,7 @@ public class DeviceIotController extends BaseController {
|
|||
@PutMapping("/unlock")
|
||||
public AjaxResult unlock(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn) {
|
||||
DeviceVO device = this.getDevice(id, sn);
|
||||
return toAjax(deviceIotService.unlock(device, true, "管理员开锁", true));
|
||||
return toAjax(deviceIotService.unlock(device, DeviceUnLockType.ADMIN, "管理员开锁", true));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:device:lock')")
|
||||
|
|
|
@ -82,7 +82,7 @@ public class OrderController extends BaseController
|
|||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:order:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id,
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id,
|
||||
@RequestParam(required = false, defaultValue = "false") Boolean assembleOrderDeviceList)
|
||||
{
|
||||
OrderVO order = orderService.selectOrderById(id, true);
|
||||
|
@ -100,7 +100,7 @@ public class OrderController extends BaseController
|
|||
public AjaxResult end(@RequestBody @Validated OrderEndDTO dto) {
|
||||
OrderVO order = orderService.selectOrderById(dto.getOrderId(), true);
|
||||
ServiceUtil.assertion(order == null, "订单不存在");
|
||||
dto.setIgnoreInParking(true);
|
||||
dto.setIsAdmin(true);
|
||||
dto.setEndReason("管理员【" + getNickName() + "】手动还车");
|
||||
return toAjax(orderService.endOrder(dto));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user