订单详情调整

This commit is contained in:
邱贞招 2025-03-04 11:15:42 +08:00
parent 250076a990
commit 9787c88219
14 changed files with 305 additions and 136 deletions

View File

@ -1,13 +1,10 @@
package com.ruoyi.web.controller.app;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.AsUser;
@ -21,7 +18,10 @@ import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.tm.TmPayService;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.verify.vo.IDResponse;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
@ -33,9 +33,7 @@ import com.ruoyi.system.service.*;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -1366,6 +1364,16 @@ public class AppVerifyController extends BaseController
return success(i);
}
/**
* 静音
*/
@Log(title = "静音", businessType = BusinessType.REFRESH)
@PostMapping("/device/mute/{sn}")
public AjaxResult mute(@PathVariable String sn)
{
return toAjax(asDeviceService.mute(sn));
}
/**
* 坐垫锁用mac

View File

@ -372,6 +372,7 @@ public class ReceiveController {
if (lastCommandTime == null || (currentTime - lastCommandTime) > COOLDOWN_PERIOD_MS) {
// 冷却时间已过可以发送命令
try {
// 正在进行中的订单
asDeviceService.sendCommand(device.getMac(), Token.getToken(), command, message, null, null);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();

View File

@ -169,6 +169,18 @@ public class AsDeviceController extends BaseController
return toAjax(asDeviceService.refreshDevice(deviceIds));
}
/**
* 静音
*/
@PreAuthorize("@ss.hasPermi('system:device:mute')")
@Log(title = "静音", businessType = BusinessType.REFRESH)
@PostMapping("/mute/{sn}")
public AjaxResult mute(@PathVariable String sn)
{
return toAjax(asDeviceService.mute(sn));
}
/**
* 响铃寻车
*/

View File

@ -56,6 +56,16 @@ public class IotConstants {
*/
public static final String COMMAND_CLOSE = "close";
/**
* 命令 静音
*/
public static final String COMMAND_MUTE = "music0@";
/**
* 命令 关闭静音
*/
public static final String COMMAND_CLOSE_MUTE = "music1@";
/**
* 命令 subXX@ xx是上报时间修改例如20 则上报20秒一次 关闭订单之后为5倍的上报间隔也就是100秒上报一次数据
*/

View File

@ -412,7 +412,7 @@ public class ServiceConstants {
/**
* 批量操作类型4-还车关锁
*/
public static final String TRIP_LOG_TYPE_RETRUN_LOCK = "4";
public static final String TRIP_LOG_TYPE_RETURN_LOCK = "4";
/**
* 批量操作类型5-换车关锁
@ -424,6 +424,26 @@ public class ServiceConstants {
*/
public static final String TRIP_LOG_TYPE_CHANGE_UNLOCK = "6";
/**
* 批量操作类型7-还车失败
*/
public static final String TRIP_LOG_TYPE_RETURN_FAILED = "7";
/**
* 批量操作类型8-靠近运营区边界
*/
public static final String TRIP_LOG_TYPE_NEAR_BOUNDARY= "8";
/**
* 批量操作类型9-超出运营区
*/
public static final String TRIP_LOG_TYPE_EXCEED_BOUNDARY= "9";
/**
* 批量操作类型10-返回运营区上电
*/
public static final String TRIP_LOG_TYPE_RETURN_POWER= "10";
/**----------------------------行程记录类型end----------------------------*/
/**----------------------------退款类型start----------------------------*/
@ -770,4 +790,18 @@ public class ServiceConstants {
*/
public static final String PLATFORM_TYPE_ALIPAY = "2";
/**----------------------------平台类型end----------------------------*/
/**----------------------------声音状态start----------------------------*/
/**
* 当前是否有声音0-静音1-非静音
*/
/**
* 0-静音
*/
public static final String SOUND_STATE_MUTE = "0";
/**
* 1-非静音
*/
public static final String SOUND_STATE_UNMUTE = "1";
/**----------------------------声音状态end----------------------------*/
}

View File

@ -206,4 +206,7 @@ public class AsDevice extends BaseEntityPlus implements Serializable {
/** 小程序名称*/
public String appName;
/** 当前是否有声音 0-静音1-非静音 默认是1*/
public String isSound;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
@ -70,6 +71,10 @@ public class EtCommandLog extends BaseEntity
@Excel(name = "onenet上报的消息")
private String msg;
/** 排序 */
@TableField(exist = false)
private String sortOrder;
// /** 是否蓝牙控制 0-否1-是否 */
// @Excel(name = "是否蓝牙控制 0-否1-是否 ")
// private String isBluetooth;

View File

@ -236,6 +236,10 @@ public class EtOrder extends BaseEntity
@TableField(exist = false)
private List<EtTripLog> tripLogs;
/** 命令日志 */
@TableField(exist = false)
private List<EtCommandLog> commandLogs;
/** 经度 */
@TableField(exist = false)
private String longitude;

View File

@ -142,6 +142,13 @@ public interface IAsDeviceService extends IService<AsDevice>
*/
int refreshDevice(Long[] deviceIds);
/**
* 静音
*/
int mute(String sn);
/**
* 更新设备
*

View File

@ -38,11 +38,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -51,8 +48,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static com.ruoyi.common.constant.HttpStatus.ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG;
import static com.ruoyi.common.constant.ServiceConstants.TRIP_LOG_TYPE_CHANGE_LOCK;
import static com.ruoyi.common.constant.ServiceConstants.TRIP_LOG_TYPE_CHANGE_UNLOCK;
import static com.ruoyi.common.constant.ServiceConstants.*;
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
/**
@ -152,8 +148,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNotNull(status)){
String typeName = sysDictDataService.selectDictLabel("as_device_status", status);
device.setStatusStr(typeName);
if(status.equals(ServiceConstants.VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(device.getAreaId())){
device.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_LISTING);
if(status.equals(VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(device.getAreaId())){
device.setStatus(VEHICLE_STATUS_NOT_LISTING);
int i = asDeviceMapper.updateAsDevice(device);
}
}
@ -293,7 +289,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
@DataScope(deptAlias = "d")
public List<AsDevice> selectAsDeviceListWithIsolate(AsDevice asDevice)
{
if(ServiceConstants.VEHICLE_STATUS_NOT_BAND.equals(asDevice.getStatus())){
if(VEHICLE_STATUS_NOT_BAND.equals(asDevice.getStatus())){
asDevice.setUnBand("1");
asDevice.setStatus(null);
}
@ -315,13 +311,13 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNotNull(status)){
String typeName = sysDictDataService.selectDictLabel("as_device_status", status);
asDevice1.setStatusStr(typeName);
if(status.equals(ServiceConstants.VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(asDevice1.getAreaId())){
asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_LISTING);
if(status.equals(VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(asDevice1.getAreaId())){
asDevice1.setStatus(VEHICLE_STATUS_NOT_LISTING);
int i = asDeviceMapper.updateAsDevice(asDevice1);
}
}
if(ObjectUtil.isNull(asDevice1.getAreaId())){
asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_BAND);
asDevice1.setStatus(VEHICLE_STATUS_NOT_BAND);
int i = asDeviceMapper.updateAsDevice(asDevice1);
}
if(ObjectUtil.isNotNull(areaId) && areaId!=0){
@ -401,7 +397,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
{
AsDevice device = asDeviceMapper.selectAsDeviceByDeviceId(asDevice.getDeviceId());//
if(!device.getStatus().equals(asDevice.getStatus())){
if(asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
if(asDevice.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
Boolean inOrderBySn = etOrderService.isInOrderBySn(device.getSn());
if(inOrderBySn){
throw new ServiceException("还有正在骑行中的订单【"+device.getSn()+"】,不能回仓");
@ -410,7 +406,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
asynchronousSaveLog(null,null,asDevice.getMac(),null,"回仓",null,getUsername());
}
}
if(asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE)){
if(asDevice.getStatus().equals(VEHICLE_STATUS_IN_OFFLINE)){
Boolean inOrderBySn = etOrderService.isInOrderBySn(device.getSn());
if(inOrderBySn){
throw new ServiceException("还有正在骑行中的订单【"+device.getSn()+"】,不能禁用");
@ -419,11 +415,11 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
asynchronousSaveLog(null,null,asDevice.getMac(),null,"禁用",null,getUsername());
}
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING) && asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NORMAL)){
if(device.getStatus().equals(VEHICLE_STATUS_NOT_LISTING) && asDevice.getStatus().equals(VEHICLE_STATUS_NORMAL)){
//记录日志
asynchronousSaveLog(null,null,asDevice.getMac(),null,"出仓",null,getUsername());
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE) && asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NORMAL)){
if(device.getStatus().equals(VEHICLE_STATUS_IN_OFFLINE) && asDevice.getStatus().equals(VEHICLE_STATUS_NORMAL)){
//记录日志
asynchronousSaveLog(null,null,asDevice.getMac(),null,"解禁",null,getUsername());
}
@ -442,9 +438,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
asDevice.setUpdateTime(DateUtils.getNowDate());
if(asDevice.getAreaId() == null){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NOT_BAND);
asDevice.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE);
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
asDevice.setStatus(VEHICLE_STATUS_NOT_BAND);
asDevice.setOnlineStatus(VEHICLE_STATUS_OFFLINE);
asDevice.setLockStatus(LOCK_STATUS_CLOSE);
}
return asDeviceMapper.updateAsDevice2(asDevice);
}
@ -489,7 +485,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNull(device)){
throw new ServiceException("车辆【"+deviceId+"】不存在");
}
if(!device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE)){
if(!device.getStatus().equals(VEHICLE_STATUS_IN_OFFLINE)){
throw new ServiceException("车辆【"+device.getSn()+"】非解禁状态,请重新选择!");
}
//记录日志
@ -513,7 +509,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNull(device)){
throw new ServiceException("车辆【"+deviceId+"】不存在");
}
if(!device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
if(!device.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
throw new ServiceException("车辆【"+device.getSn()+"】非仓库中状态,请重新选择!");
}
//记录日志
@ -541,19 +537,19 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNull(device)){
throw new ServiceException("车辆【"+deviceId+"】不存在");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT)){
if(device.getStatus().equals(VEHICLE_STATUS_IN_APPOINTMENT)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘预约中’状态不能禁用");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_USING)){
if(device.getStatus().equals(VEHICLE_STATUS_IN_USING)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘使用中’状态不能禁用");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK)){
if(device.getStatus().equals(VEHICLE_STATUS_TEMPORARILY_LOCK)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘临时停车’状态不能禁用");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
if(device.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘未上架’状态不能禁用");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_ABANDON)){
if(device.getStatus().equals(VEHICLE_STATUS_ABANDON)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘废弃’状态不能禁用");
}
//记录日志
@ -581,19 +577,19 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNull(device)){
throw new ServiceException("车辆【"+deviceId+"】不存在");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT)){
if(device.getStatus().equals(VEHICLE_STATUS_IN_APPOINTMENT)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘预约中’状态不能入仓");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_USING)){
if(device.getStatus().equals(VEHICLE_STATUS_IN_USING)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘使用中’状态不能入仓");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK)){
if(device.getStatus().equals(VEHICLE_STATUS_TEMPORARILY_LOCK)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘临时停车’状态不能入仓");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
if(device.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘仓库中’状态不能入仓");
}
if(device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_ABANDON)){
if(device.getStatus().equals(VEHICLE_STATUS_ABANDON)){
throw new ServiceException("车辆【"+device.getSn()+"】为‘废弃’状态不能入仓");
}
//记录日志
@ -636,6 +632,47 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
return 1;
}
/**
* 静音
*
* @return 结果
*/
@SneakyThrows
@Override
public int mute(String sn)
{
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
/** 1.获取token*/
String token = Token.getToken();
String type;
String commandMute = "";
String isSound = "1";
if(SOUND_STATE_MUTE.equals(asDevice.getIsSound())){//静音
commandMute = IotConstants.COMMAND_CLOSE_MUTE;
type = "关闭静音";
isSound = "1";
}else{
commandMute = IotConstants.COMMAND_MUTE;
type = "静音";
isSound = "0";
}
String finalCommandMute = commandMute;
String finalIsSound = isSound;
Boolean execute = transactionTemplate.execute(e -> {
/** 2.发送命令*/
sendCommand(asDevice.getMac(), token, finalCommandMute,type,null,null);
/** 更新设备静音状态*/
AsDevice asDevice1 = new AsDevice();
asDevice1.setIsSound(finalIsSound);
asDevice1.setDeviceId(asDevice.getDeviceId());
asDeviceMapper.updateAsDevice(asDevice1);
return Boolean.TRUE;
});
if(Boolean.FALSE.equals(execute))throw new ServiceException(type+"失败");
return 1;
}
/**
* 根据sn更新设备
* @param sn sn
@ -791,22 +828,22 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
Integer allNum = asDeviceMapper.selectCount(wrapper);
deviceNumVo.setAllNum(allNum);//所有车辆
Integer ridingNum = setNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_IN_USING,areaId);
Integer ridingNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_IN_USING,areaId);
deviceNumVo.setRidingNum(ridingNum);//骑行中
Integer inOperation = setInOperationNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_NOT_LISTING,areaId);
Integer inOperation = setInOperationNum(powerStart, powerEnd, VEHICLE_STATUS_NOT_LISTING,areaId);
deviceNumVo.setInOperation(inOperation);//投放中
Integer temporarilyLockNum = setNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK,areaId);
Integer temporarilyLockNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_TEMPORARILY_LOCK,areaId);
deviceNumVo.setTemporarilyLockNum(temporarilyLockNum);//临时锁车
Integer disabledNum = setNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_IN_OFFLINE,areaId);
Integer disabledNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_IN_OFFLINE,areaId);
deviceNumVo.setDisabledNum(disabledNum);//已禁用
Integer normalNum = setNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_NORMAL,areaId);
Integer normalNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_NORMAL,areaId);
deviceNumVo.setNormalNum(normalNum);//正常待租
Integer inStashNum = setNum(powerStart, powerEnd,ServiceConstants.VEHICLE_STATUS_NOT_LISTING,areaId);
Integer inStashNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_NOT_LISTING,areaId);
deviceNumVo.setInStashNum(inStashNum);
QueryWrapper<AsDevice> wrapperForOffline = new QueryWrapper<>();
@ -828,7 +865,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
List<AsDevice> devices = asDeviceMapper.selectList(wrapperForOffline);
deviceNumVo.setOfflineDevices(devices);
Integer inAppointmentNum = setNum(powerStart, powerEnd, ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT,areaId);
Integer inAppointmentNum = setNum(powerStart, powerEnd, VEHICLE_STATUS_IN_APPOINTMENT,areaId);
deviceNumVo.setInAppointmentNum(inAppointmentNum);//预约中
QueryWrapper<AsDevice> wrapperForDispatch = new QueryWrapper<>();
@ -899,7 +936,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}else{
throw new ServiceException("ruleId未传");
}
order.setStatus(ServiceConstants.ORDER_STATUS_RIDING);
order.setStatus(ORDER_STATUS_RIDING);
order.setUnlockTime(DateUtils.getNowDate());
order.setAppointmentEndTime(DateUtils.getNowDate());
//计算预约费
@ -918,7 +955,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
ServiceUtil.assertion(etOrder == 0, "【扫码/编号开锁骑行】保存订单失败");
}
/** 5.记录行程*/
int tripLog = tripLogService.tripLog(order.getOrderNo(),order.getSn(),ServiceConstants.TRIP_LOG_TYPE_UNLOCK_RIDE);
int tripLog = tripLogService.tripLog(order.getOrderNo(),order.getSn(), TRIP_LOG_TYPE_UNLOCK_RIDE);
if(tripLog==0){
log.info("【扫码/编号开锁骑行】记录行程失败");
throw new ServiceException("【扫码/编号开锁骑行】记录行程失败");
@ -938,8 +975,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
asDevice.setLastTime(DateUtils.getNowDate());
}
/** 3.更新车辆状态*/
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);
asDevice.setLockStatus(LOCK_STATUS_OPEN);
asDevice.setStatus(VEHICLE_STATUS_IN_USING);
asDevice.setIsAdminUnlocking("0");
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
@ -998,10 +1035,10 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
/** 2.发送命令*/
sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁",null,userName);
asDevice.setIsAdminUnlocking("1");
if(!asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_SCHEDULING);
if(!asDevice.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(VEHICLE_STATUS_SCHEDULING);
}
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int i = asDeviceMapper.updateAsDevice(asDevice);
if(i>0){
log.info("管理员开锁,更新设备状态成功");
@ -1025,10 +1062,10 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
/** 2.发送命令*/
sendCommand(mac, token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁",null,userName);
asDevice.setIsAdminUnlocking("1");
if(!asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_SCHEDULING);
if(!asDevice.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(VEHICLE_STATUS_SCHEDULING);
}
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int i = asDeviceMapper.updateAsDevice(asDevice);
if(i>0){
log.info("管理员开锁,更新设备状态成功");
@ -1048,7 +1085,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
Boolean inOrderBySn = etOrderService.isInOrderBySn(sn);//有进行中的订单跳过
if(!inOrderBySn){
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//车辆解禁
asDevice.setStatus(VEHICLE_STATUS_NORMAL);//车辆解禁
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
log.info("车辆解禁状态失败");
@ -1072,13 +1109,13 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
throw new ServiceException("还有正在骑行中的订单【"+sn+"】,不能禁用");
}
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
if(ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT.equals(asDevice.getStatus())){
if(VEHICLE_STATUS_IN_APPOINTMENT.equals(asDevice.getStatus())){
throw new ServiceException("车辆处于预约中,不能禁用");
}
if(ServiceConstants.VEHICLE_STATUS_IN_USING.equals(asDevice.getStatus())){
if(VEHICLE_STATUS_IN_USING.equals(asDevice.getStatus())){
throw new ServiceException("车辆使用中,不能禁用");
}
if(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK.equals(asDevice.getStatus())){
if(VEHICLE_STATUS_TEMPORARILY_LOCK.equals(asDevice.getStatus())){
throw new ServiceException("车辆临时停车中,不能禁用");
}
asDevice.setStatus(status);
@ -1240,9 +1277,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac);
//异步更新在线状态
scheduledExecutorService.schedule(() -> {
if(device.getOnlineStatus().equals(ServiceConstants.VEHICLE_STATUS_ONLINE)){
if(device.getOnlineStatus().equals(VEHICLE_STATUS_ONLINE)){
log.info("【接收onenet推送】异步更新在线状态"+JSON.toJSONString(device));
device.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE);
device.setOnlineStatus(VEHICLE_STATUS_OFFLINE);
int i = asDeviceMapper.updateAsDevice(device);
if(i>0){
log.info("【接收onenet推送】异步保存在线状态成功");
@ -1251,7 +1288,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
EtOnlineLog etOnlineLog = new EtOnlineLog();
etOnlineLog.setMac(device.getMac());
etOnlineLog.setSn(device.getSn());
etOnlineLog.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE);
etOnlineLog.setOnlineStatus(VEHICLE_STATUS_OFFLINE);
etOnlineLog.setLongitude(device.getLongitude());
etOnlineLog.setLatitude(device.getLatitude());
etOnlineLog.setCreateTime(DateUtils.getNowDate());
@ -1263,7 +1300,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
/* 异步保存发送命令日志*/
private void asynchronousSaveLog(String url,String command,String mac,String result,String type,String orderNo,String userName) {
private void asynchronousSaveLog(String url,String command,String mac,String result,String type,final String orderNo,String userName) {
//异步保存发送命令日志
scheduledExecutorService.schedule(() -> {
EtCommandLog etCommandLog = new EtCommandLog();
@ -1284,7 +1321,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}else{
etCommandLog.setCallStatus("0");
}
etCommandLog.setOrderNo(orderNo);
if(StrUtil.isEmpty(orderNo)){
EtOrder inOrderBySn = etOrderMapper.getInOrderBySn(device.getSn());
if(inOrderBySn != null){
etCommandLog.setOrderNo(inOrderBySn.getOrderNo());
}
}else{
etCommandLog.setOrderNo(orderNo);
}
etCommandLog.setCreateBy(userName);
int i = etCommandLogMapper.insertEtCommandLog(etCommandLog);
if(i>0){
@ -1422,7 +1466,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"响铃寻车",null,null);
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("响铃寻车失败");
if(Boolean.FALSE.equals(execute))throw new ServiceException("响铃寻车失败");
return Boolean.TRUE;
}
@ -1442,7 +1486,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_HPEN,"开坐垫锁",null,null);
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("开坐垫锁失败");
if(Boolean.FALSE.equals(execute))throw new ServiceException("开坐垫锁失败");
return Boolean.TRUE;
}
@ -1570,12 +1614,12 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
asDevice.setLatitude(lat);
asDevice.setLastTime(DateUtils.getNowDate());
}
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
asDevice.setLockStatus(LOCK_STATUS_CLOSE);
if(StrUtil.isNotBlank(orderNo)){//有订单号则是用户临时锁车
/** 改变车辆状态4-临时锁车 */
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK);//临时锁车
asDevice.setStatus(VEHICLE_STATUS_TEMPORARILY_LOCK);//临时锁车
/** 5.记录行程*/
int tripLog = tripLogService.tripLog(orderNo, sn,ServiceConstants.TRIP_LOG_TYPE_TEMPORARILY_LOCK);
int tripLog = tripLogService.tripLog(orderNo, sn, TRIP_LOG_TYPE_TEMPORARILY_LOCK);
if(tripLog==0){
log.info("【临时锁车】记录行程失败");
throw new ServiceException("【临时锁车】记录行程失败");
@ -1602,14 +1646,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
/** 2.发送命令*/
sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车",null,userName);
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
asDevice.setLockStatus(LOCK_STATUS_CLOSE);
// 判断该sn是否有正在骑行中的订单如果有骑行中的订单则修改为临时锁车
EtOrder etOrder = etOrderService.getCurrentOrder(sn);
if(ObjectUtil.isNotNull(etOrder)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK);
asDevice.setStatus(VEHICLE_STATUS_TEMPORARILY_LOCK);
}else{
if(!asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//管理员锁车
if(!asDevice.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(VEHICLE_STATUS_NORMAL);//管理员锁车
}
}
asDevice.setIsAdminUnlocking("0");
@ -1634,14 +1678,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
AsDevice asDevice = asDeviceMapper.selectAsDeviceByMac(mac);
/** 2.发送命令*/
sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车",null,userName);
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
asDevice.setLockStatus(LOCK_STATUS_CLOSE);
// 判断该sn是否有正在骑行中的订单如果有骑行中的订单则修改为临时锁车
EtOrder etOrder = etOrderService.getCurrentOrder(asDevice.getSn());
if(ObjectUtil.isNotNull(etOrder)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK);
asDevice.setStatus(VEHICLE_STATUS_TEMPORARILY_LOCK);
}else{
if(!asDevice.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//管理员锁车
if(!asDevice.getStatus().equals(VEHICLE_STATUS_NOT_LISTING)){
asDevice.setStatus(VEHICLE_STATUS_NORMAL);//管理员锁车
}
}
asDevice.setIsAdminUnlocking("0");
@ -1679,22 +1723,22 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
if(StrUtil.isNotBlank(orderNo)){//有订单号则是用户骑行中解锁
/** 改变车辆状态3-骑行中 */
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);//骑行中
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setStatus(VEHICLE_STATUS_IN_USING);//骑行中
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
log.info("【临时解锁】改变车辆状态失败");
throw new ServiceException("【临时解锁】改变车辆状态失败");
}
/** 5.记录行程*/
int tripLog = tripLogService.tripLog(orderNo, finalSn,ServiceConstants.TRIP_LOG_TYPE_TEMPORARILY_UNLOCK);
int tripLog = tripLogService.tripLog(orderNo, finalSn, TRIP_LOG_TYPE_TEMPORARILY_UNLOCK);
if(tripLog==0){
log.info("【临时解锁】记录行程失败");
throw new ServiceException("【临时解锁】记录行程失败");
}
}else{
/** 改变车辆锁状态1-开 */
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
log.info("【临时解锁】改变车辆状态失败");
@ -1722,7 +1766,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
orderResponse.setOrderNo(orderNo);
orderResponse.setSessionId(IdUtils.randomUUIDByDigit(8));
//改变车辆状态
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT);
asDevice.setStatus(VEHICLE_STATUS_IN_APPOINTMENT);
int u = asDeviceMapper.updateAsDevice(asDevice);
if(u==0){
throw new ServiceException("【车辆预约】:更新车辆状态失败");
@ -1735,13 +1779,13 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
log.error("【车辆超时预约】系统自动取消");
EtOrder order1 = etOrderService.selectEtOrderByOrderNo(order.getOrderNo());
log.info("【定时取消预约】重新获取订单信息:{}",JSON.toJSON(order1));
if(order1.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_PAID)){//已支付订单跳过
if(order1.getPaid().equals(ORDER_PAY_STATUS_PAID)){//已支付订单跳过
log.error("【车辆超时预约】订单已支付,跳过");
return;
}
log.error("【车辆超时预约】订单未支付,系统自动处理");
//未支付 订单更新最后预约时间并结束订单做超出预约时间标记
order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT);
order.setStatus(ORDER_STATUS_CANCEL_APPOINTMENT);
order.setAppointmentEndTime(new Date());
order.setAppointmentTimeout("1");
//计算预约费
@ -1756,8 +1800,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
throw new ServiceException("【车辆超时预约】:更新订单状态失败");
}
// 改变车辆状态
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//定时取消预约
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setStatus(VEHICLE_STATUS_NORMAL);//定时取消预约
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
log.error("【车辆超时预约】更新车辆状态失败");
@ -1781,7 +1825,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
String orderNo = appointmentVo.getOrderNo();
EtOrder order = etOrderService.selectEtOrderByOrderNo(orderNo);
/** 5.记录行程*/
int tripLog = tripLogService.tripLog(order.getOrderNo(),order.getSn(),ServiceConstants.TRIP_LOG_TYPE_UNLOCK_RIDE);
int tripLog = tripLogService.tripLog(order.getOrderNo(),order.getSn(), TRIP_LOG_TYPE_UNLOCK_RIDE);
if(tripLog==0){
log.info("【套餐取消预约】记录行程失败");
throw new ServiceException("【套餐取消预约】记录行程失败");
@ -1792,14 +1836,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
calculateAppointmentFee(order);
order.setTotalFee(order.getAppointmentFee());
order.setPayFee(order.getAppointmentFee());
order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT);
order.setStatus(ORDER_STATUS_CANCEL_APPOINTMENT);
log.info("【取消预约】更新订单信息,{}",JSON.toJSON(order));
int i = etOrderService.updateEtOrder(order);
if(i==0){
throw new ServiceException("【取消预约】:更新订单失败");
}
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//取消预约
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
asDevice.setStatus(VEHICLE_STATUS_NORMAL);//取消预约
asDevice.setLockStatus(LOCK_STATUS_OPEN);
int device = asDeviceMapper.updateAsDevice(asDevice);
if(device==0){
log.error("【取消预约】更新车辆状态失败");
@ -1850,15 +1894,15 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if(ObjectUtil.isNull(order)){
throw new ServiceException("订单不存在");
}
if(!ServiceConstants.ORDER_TYPE_RIDING.equals(order.getType())){
if(!ORDER_TYPE_RIDING.equals(order.getType())){
throw new ServiceException("该订单非骑行订单");
}
if(!ServiceConstants.ORDER_STATUS_RIDING.equals(order.getStatus())){
if(!ORDER_STATUS_RIDING.equals(order.getStatus())){
throw new ServiceException("该订单状态非骑行中");
}
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
if(ServiceConstants.RETURN_TYPE_NORMAL.equals(returnType)){
if(ServiceConstants.RETURN_VERIFY_YES.equals(area.getReturnVerify()) && StrUtil.isBlank(order.getVideoUrl())){
if(RETURN_TYPE_NORMAL.equals(returnType)){
if(RETURN_VERIFY_YES.equals(area.getReturnVerify()) && StrUtil.isBlank(order.getVideoUrl())){
throw new ServiceException("请先拍摄还车视频!");
}
//判断是否在禁停区内如果在禁停区内不能还车 noParkingArea
@ -1880,7 +1924,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
/** 1. 记录还车时间*/
order.setReturnType(returnType);
order.setStatus(ServiceConstants.ORDER_STATUS_RIDING_END);
order.setStatus(ORDER_STATUS_RIDING_END);
order.setReturnTime(DateUtils.getNowDate());
// order.setReturnTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, "2024-07-23 17:09:32"));//2024-06-28 18:15:56
String token = Token.getToken();
@ -1898,7 +1942,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
order.setSn(usedSn);
}
}
if(ServiceConstants.RETURN_TYPE_NORMAL.equals(returnType)){
if(RETURN_TYPE_NORMAL.equals(returnType)){
if(!"true".equals(isBluetooth)){
/** 2. 车辆远程关锁*/
ResponseVo responseVo = sendCommandWithResp(device.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "还车关锁",orderNo,lon,lat);
@ -1936,8 +1980,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
if(ObjectUtil.isNotNull(device)){
/** 4. 更新车辆状态*/
device.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);//还车
device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
device.setStatus(VEHICLE_STATUS_NORMAL);//还车
device.setLockStatus(LOCK_STATUS_CLOSE);
int deviceUpdate = asDeviceMapper.updateAsDevice(device);
if(deviceUpdate==0){
log.info("【还车关锁】更新车辆状态失败");
@ -1980,7 +2024,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
/** 5.记录行程*/
if(ObjectUtil.isNotNull(device)){
int tripLog = tripLogService.tripLog(order.getOrderNo(),device.getSn(),ServiceConstants.TRIP_LOG_TYPE_RETRUN_LOCK);
int tripLog = tripLogService.tripLog(order.getOrderNo(),device.getSn(), TRIP_LOG_TYPE_RETURN_LOCK);
if(tripLog==0){
log.info("【还车关锁】记录行程失败");
throw new ServiceException("【还车关锁】记录行程失败");
@ -2105,7 +2149,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
String chargingCycle = order.getChargingCycle();
String chargingCycleValue = order.getChargingCycleValue();
if(ServiceConstants.CHARGING_CYCLE_HOUR.equals(chargingCycle)) {//订单生成后__小时 第几个
if(CHARGING_CYCLE_HOUR.equals(chargingCycle)) {//订单生成后__小时 第几个
cycle = inHowManyChargingCycle(startTime, endTime, chargingCycleValue);
BigDecimal ridingFee;
if(cycle == 1){
@ -2132,7 +2176,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
}
order.setRidingFee(ridingFee);
}else if(ServiceConstants.CHARGING_CYCLE_CUSTOM.equals(chargingCycle)){//自定义时刻
}else if(CHARGING_CYCLE_CUSTOM.equals(chargingCycle)){//自定义时刻
// todo 自定义计费周期时刻 获取到自定义时刻判断骑行的这段时间是否在自定义时刻里 ____.___.___|___________|
SimpleDateFormat timeFormat = new SimpleDateFormat(DateUtils.DATE_FORMAT_HHMMSS);
Calendar calendar = Calendar.getInstance();
@ -2174,7 +2218,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
order.setRidingFee(ridingFee);
}else{
if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_DAY)){
if(rentalUnit.equals(RENTAL_UNIT_DAY)){
}
}
@ -2235,9 +2279,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
String timeoutPrice = startingRule.getTimeoutPrice();//超时价格
Integer timeoutTime = Integer.parseInt(startingRule.getTimeoutTime());//超时时间
if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_HOURS)){//租赁单位hours-小时
if(rentalUnit.equals(RENTAL_UNIT_HOURS)){//租赁单位hours-小时
timeoutTime = timeoutTime*60;
}else if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_DAY)){//租赁单位day-
}else if(rentalUnit.equals(RENTAL_UNIT_DAY)){//租赁单位day-
timeoutTime = timeoutTime*60*24;
}
@ -2262,17 +2306,17 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
return ridingFee;
}
if(order.getRidingRule().equals(ServiceConstants.RIDING_RULE_STARTING_PRICE_MODE)){//1-起步价计费
if(order.getRidingRule().equals(RIDING_RULE_STARTING_PRICE_MODE)){//1-起步价计费
StartingRuleVo startingRule = JSONObject.parseObject(order.getRidingRuleJson(), StartingRuleVo.class);
String startingPrice = startingRule.getStartingPrice();//起步价
Integer startingTime = Integer.parseInt(startingRule.getStartingTime());//起步时间
String timeoutPrice = startingRule.getTimeoutPrice();//超时价格
Integer timeoutTime = Integer.parseInt(startingRule.getTimeoutTime());//超时时间
if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_HOURS)){//租赁单位hours-小时
if(rentalUnit.equals(RENTAL_UNIT_HOURS)){//租赁单位hours-小时
startingTime = startingTime*60;
timeoutTime = timeoutTime*60;
}else if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_DAY)){//租赁单位day-
}else if(rentalUnit.equals(RENTAL_UNIT_DAY)){//租赁单位day-
startingTime = startingTime*60*24;
timeoutTime = timeoutTime*60*24;
}
@ -2302,10 +2346,10 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
//骑行时长
int duration = DateUtils.timeDifferenceInMinutes(returnTime,unlockTime);//计算相隔多少分钟
BigDecimal durationInMinutes = new BigDecimal(duration);
if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_HOURS)){//租赁单位hours-小时
if(rentalUnit.equals(RENTAL_UNIT_HOURS)){//租赁单位hours-小时
BigDecimal durationInHours = durationInMinutes.divide(BigDecimal.valueOf(60), 0, RoundingMode.CEILING);
duration = durationInHours.setScale(0, RoundingMode.CEILING).intValue();
}else if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_DAY)){//租赁单位day-
}else if(rentalUnit.equals(RENTAL_UNIT_DAY)){//租赁单位day-
BigDecimal durationInDays = durationInMinutes.divide(BigDecimal.valueOf(60*24), 0, RoundingMode.CEILING); // 转换为天数并向上取整
duration = durationInDays.setScale(0, RoundingMode.CEILING).intValue(); // 转换为整数天数
}
@ -2351,11 +2395,11 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
* 格式化单位
*/
private String formatUnit(String rentalUnit) {
if(ServiceConstants.RENTAL_UNIT_MINUTES.equals(rentalUnit)){
if(RENTAL_UNIT_MINUTES.equals(rentalUnit)){
return "分钟";
}else if(ServiceConstants.RENTAL_UNIT_HOURS.equals(rentalUnit)){
}else if(RENTAL_UNIT_HOURS.equals(rentalUnit)){
return "小时";
} else if(ServiceConstants.RENTAL_UNIT_DAY.equals(rentalUnit)){
} else if(RENTAL_UNIT_DAY.equals(rentalUnit)){
return "";
} else {
return "";
@ -2423,7 +2467,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
EtParkingArea parkingArea = new EtParkingArea();
parkingArea.setAreaId(areaId);
parkingArea.setStatus("0");
parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_PARKFING);
parkingArea.setType(PARKING_AREA_TYPE_PARKFING);
List<EtParkingArea> parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea);
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId);
if(ObjectUtil.isNull(parkingAreas) || parkingAreas.isEmpty()){
@ -2439,6 +2483,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
inCircle = GeoUtils.isInPolygonWithTolerance(longitude, latitude, geometry, tolerance);
if(inCircle){
log.info("位置【{}{}】在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName());
return true;
}else{
log.info("位置【{}{}】不在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName());
}
@ -2485,7 +2530,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
// throw new ServiceException("运营区【{}】没有禁停区"+areaId.toString());
}
for (EtParkingArea etParkingArea : parkingAreas) {
if(etParkingArea.getType().equals(ServiceConstants.PARKING_AREA_TYPE_NO_PARKFING)){
if(etParkingArea.getType().equals(PARKING_AREA_TYPE_NO_PARKFING)){
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
String latitude = device.getLatitude();
String longitude = device.getLongitude();
@ -2511,7 +2556,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
EtParkingArea parkingArea = new EtParkingArea();
parkingArea.setAreaId(areaId);
parkingArea.setStatus("0");
parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_NO_PARKFING);
parkingArea.setType(PARKING_AREA_TYPE_NO_PARKFING);
List<EtParkingArea> parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea);
if(ObjectUtil.isNull(parkingAreas) || parkingAreas.isEmpty()){
log.info("【临时锁车】运营区【{}】没有禁停区,",areaId);
@ -2550,7 +2595,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
log.info("运营区【{}】没有禁行区,",areaId);
}
for (EtParkingArea etParkingArea : parkingAreas) {
if(etParkingArea.getType().equals(ServiceConstants.PARKING_AREA_TYPE_BANNED_RIDING)){
if(etParkingArea.getType().equals(PARKING_AREA_TYPE_BANNED_RIDING)){
Geometry geometry = GeoUtils.fromWkt(etParkingArea.getBoundary());
isNoRiding = GeoUtils.isInCircle(lon, lat, geometry);
if(isNoRiding){
@ -2579,7 +2624,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
// throw new ServiceException("运营区【{}】没有禁行区"+areaId.toString());
}
for (EtParkingArea etParkingArea : parkingAreas) {
if(etParkingArea.getType().equals(ServiceConstants.PARKING_AREA_TYPE_BANNED_RIDING)){
if(etParkingArea.getType().equals(PARKING_AREA_TYPE_BANNED_RIDING)){
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
String latitude = device.getLatitude();
String longitude = device.getLongitude();
@ -2621,7 +2666,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
public Boolean isOperatingTime(String sn) {
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(device.getAreaId());
if(area.getAreaTime().equals(ServiceConstants.AREA_TIME_CUSTOM) && !DateUtils.isInTime(area.getAreaTimeStart(),area.getAreaTimeEnd())){
if(area.getAreaTime().equals(AREA_TIME_CUSTOM) && !DateUtils.isInTime(area.getAreaTimeStart(),area.getAreaTimeEnd())){
log.info("不在运营时间内,运营时间为:【{}】--【{}】",area.getAreaTimeStart(),area.getAreaTimeEnd());
return Boolean.FALSE;
}
@ -2728,8 +2773,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
// 线判断车的定位是否在停车区内如果在停车区内则直接返回如果不在拿手机的定位再判断是否在停车区内
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(Long.parseLong(areaId));
IsInParkingAreaVo isInParkingAreaVo = new IsInParkingAreaVo();
if(StringUtils.isNotEmpty(sn)){
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
if(StringUtils.isNotEmpty(sn) && ObjectUtil.isNotNull(device)){
double[] latestLocation = getLatestLocation(device.getMac());
if(ObjectUtil.isNotNull(latestLocation)){
BigDecimal longitude1 = BigDecimal.valueOf(latestLocation[1]).setScale(8, RoundingMode.HALF_UP);
@ -2738,33 +2783,44 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude1.toString(), latitude1.toString(), Long.parseLong(areaId));
if(parkingZoneByLocation){
return getParkingAreaVo(isInParkingAreaVo, true, area,sn,"1",longitude1.toString(),latitude1.toString());
return getParkingAreaVo(isInParkingAreaVo, true, area,device,"1",longitude1.toString(),latitude1.toString());
}
// 如果longitude1和latitude1定位距离最近的停车点的距离小于50米则可以用手机定位判断是否在停车区如果大于50米则直接返回不在停车区
double minDistanceToParkingArea = findMinDistanceToParkingAreas(Double.parseDouble(longitude1.toString()), Double.parseDouble(latitude1.toString()), Long.parseLong(areaId));
log.info("【判断是否在停车区(不在停车点内)--距离停车点最小距离】minDistanceToParkingArea:{}",minDistanceToParkingArea);
if (minDistanceToParkingArea > 50) { // 如果距离大于50米直接返回不在停车区
log.info("【判断是否在停车区--大于50米不在停车点内】不在停车区");
return getParkingAreaVo(isInParkingAreaVo, false, area,sn,"1",longitude1.toString(),latitude1.toString());
return getParkingAreaVo(isInParkingAreaVo, false, area,device,"1",longitude1.toString(),latitude1.toString());
}
}
}
Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude, latitude, Long.parseLong(areaId));
return getParkingAreaVo(isInParkingAreaVo, parkingZoneByLocation, area,sn,"2",longitude,latitude);
return getParkingAreaVo(isInParkingAreaVo, parkingZoneByLocation, area,device,"2",longitude,latitude);
}
private @NotNull IsInParkingAreaVo getParkingAreaVo(IsInParkingAreaVo isInParkingAreaVo, boolean isInParkingArea, EtOperatingArea area, String sn,
private @NotNull IsInParkingAreaVo getParkingAreaVo(IsInParkingAreaVo isInParkingAreaVo, boolean isInParkingArea, EtOperatingArea area, AsDevice device,
String returnMode, String longitude, String latitude) {
isInParkingAreaVo.setIsInParkingArea(isInParkingArea);
isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn()));
EtOrder inOrderBySn = etOrderMapper.getInOrderBySn(sn);
EtOrder inOrderBySn = etOrderMapper.getInOrderBySn(device.getSn());
if(ObjectUtil.isNotNull(inOrderBySn)){
EtOrder etOrder = new EtOrder();
etOrder.setOrderNo(inOrderBySn.getOrderNo());
etOrder.setReturnMode(returnMode);
etOrder.setReturnLon(longitude);
etOrder.setReturnLat(latitude);
etOrderMapper.updateEtOrderByOrderNo(etOrder);
Boolean execute = transactionTemplate.execute(e -> {
int i = etOrderMapper.updateEtOrderByOrderNo(etOrder);
ServiceUtil.assertion(i==0,"【判断是否在停车区】更新订单失败");
if(!isInParkingArea){//不在停车点时发起停车请求记录行程
/** 记录行程*/
int tripLog = tripLogService.tripLog(inOrderBySn.getOrderNo(),device.getSn(), TRIP_LOG_TYPE_RETURN_FAILED);
ServiceUtil.assertion(tripLog==0,"【判断是否在停车区】记录行程失败");
asynchronousSaveLog(null,null,device.getMac(),null,"还车失败",inOrderBySn.getOrderNo(),getUsername());
}
return Boolean.TRUE;
});
if(Boolean.FALSE.equals(execute))throw new ServiceException("【判断是否在停车区】更新订单失败");
}
return isInParkingAreaVo;
}
@ -2773,7 +2829,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
EtParkingArea parkingArea = new EtParkingArea();
parkingArea.setAreaId(areaId);
parkingArea.setStatus("0");
parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_PARKFING);
parkingArea.setType(PARKING_AREA_TYPE_PARKFING);
List<EtParkingArea> parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea);
double minDistance = Double.MAX_VALUE;
@ -2887,7 +2943,11 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(StrUtil.isBlank(order.getUsedSn())){
return trajectoryDetails(order.getSn(), sdf.format(order.getUnlockTime()), sdf.format(order.getReturnTime()));
Date returnTime = order.getReturnTime();
if(returnTime == null){
returnTime = new Date();
}
return trajectoryDetails(order.getSn(), sdf.format(order.getUnlockTime()), sdf.format(returnTime));
}
List<EtLocationLog> allLocationLogs = new ArrayList<>();

View File

@ -163,6 +163,9 @@ public class EtOrderServiceImpl implements IEtOrderService
@Resource
private IEtTripLogService tripLogService;
@Autowired
private IEtCommandLogService commandLogService;
/**
* 查询订单
*
@ -189,11 +192,18 @@ public class EtOrderServiceImpl implements IEtOrderService
order.setTripRouteStr(trajectory);
order.setRule(etFeeRule);
//行程记录
EtTripLog tripLog = new EtTripLog();
tripLog.setOrderNo(order.getOrderNo());
List<EtTripLog> tripLogs = etTripLogService.selectEtTripLogList(tripLog);
if(ObjectUtils.isNotEmpty(tripLogs)){
order.setTripLogs(tripLogs);
EtCommandLog etCommandLog = new EtCommandLog();
etCommandLog.setOrderNo(order.getOrderNo());
etCommandLog.setSortOrder("asc");
List<EtCommandLog> list = commandLogService.selectEtCommandLogList(etCommandLog);
if(!list.isEmpty()){
// 遍历列表并修改指定字段
for (EtCommandLog log : list) {
if ("临时解锁".equals(log.getType())) { // 检查type是否为"临时解锁"
log.setType("解锁"); // 修改为"解锁"
}
}
order.setCommandLogs(list);
}
// 退款记录
List<EtRefund> refunds = etRefundService.selectEtRefundByOrderNo(order.getOrderNo());

View File

@ -38,20 +38,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="appid" column="appid" />
<result property="appName" column="app_name" />
<result property="deptId" column="dept_id" />
<result property="isSound" column="is_sound" />
</resultMap>
<sql id="selectAsDeviceVo">
select device_id, picture, device_name, mac, sn, model_id, hardware_version_id, vehicle_num, area_id, activation_time,
online_status, create_by, create_time, update_by, update_time, last_time, last_location_time, gps, remark, status,
lock_status, location, remaining_power, voltage, version, qrcode, longitude, latitude, is_area_out_outage, is_admin_unlocking,
signal_strength, satellites, quality, appid, app_name, dept_id from et_device
signal_strength, satellites, quality, appid, app_name, dept_id, is_sound from et_device
</sql>
<select id="selectAsDeviceList" parameterType="AsDevice" resultMap="AsDeviceResult">
select de.device_id, de.picture, de.device_name, de.mac, de.sn, de.model_id, de.hardware_version_id, de.vehicle_num, de.area_id,
de.activation_time, de.online_status, de.create_by, de.create_time, de.update_by,
de.update_time, de.last_time, de.last_location_time, de.gps, de.remark, de.status, de.lock_status, de.location,
de.remaining_power, de.voltage, de.version, de.qrcode, de.longitude, de.latitude, de.is_area_out_outage, de.is_admin_unlocking,de.appid, de.app_name, de.dept_id from et_device de
de.remaining_power, de.voltage, de.version, de.qrcode, de.longitude, de.latitude, de.is_area_out_outage, de.is_admin_unlocking,de.appid, de.app_name, de.dept_id, de.is_sound from et_device de
left join et_area_dept ad on ad.area_id = de.area_id
left join sys_dept d on d.dept_id = ad.dept_id
where 1 = 1
@ -74,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
de.activation_time, de.online_status, de.create_by, de.create_time, de.update_by,d.dept_id,
de.update_time, de.last_time, de.last_location_time, de.gps, de.remark, de.status, de.lock_status, de.location,
de.remaining_power, de.voltage, de.version, de.qrcode, de.longitude, de.latitude, de.is_area_out_outage, de.is_admin_unlocking, de.signal_strength,
de.satellites, de.quality,de.appid, de.app_name from et_device de
de.satellites, de.quality,de.appid, de.app_name, de.is_sound from et_device de
left join et_area_dept ad on ad.area_id = de.area_id
left join sys_dept d on d.dept_id = ad.dept_id
left join et_hardware_version hv on hv.id = de.hardware_version_id
@ -211,6 +212,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appid != null">appid,</if>
<if test="appName != null">app_name,</if>
<if test="deptId != null">dept_id,</if>
<if test="isSound != null">is_sound,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="picture != null">#{picture},</if>
@ -244,6 +246,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appid != null">#{appid},</if>
<if test="appName != null">#{appName},</if>
<if test="deptId != null">#{deptId},</if>
<if test="isSound != null">#{isSound},</if>
</trim>
</insert>
@ -282,6 +285,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appid != null">appid = #{appid},</if>
<if test="appName != null">app_name = #{appName},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="isSound != null">is_sound = #{isSound},</if>
</trim>
where device_id = #{deviceId}
</update>
@ -321,6 +325,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appid != null">appid = #{appid},</if>
<if test="appName != null">app_name = #{appName},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="isSound != null">is_sound = #{isSound},</if>
</trim>
where device_id = #{deviceId}
</update>
@ -359,6 +364,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appid != null">appid = #{appid},</if>
<if test="appName != null">app_name = #{appName},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="isSound != null">is_sound = #{isSound},</if>
</trim>
where sn = #{sn}
</update>

View File

@ -40,7 +40,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
<if test="callStatus != null and callStatus != ''"> and call_status = #{callStatus}</if>
</where>
order by create_time desc
<!-- 动态排序 -->
order by create_time
<if test="sortOrder != null and sortOrder == 'asc'">
asc
</if>
<if test="sortOrder == null or sortOrder != 'asc'">
desc
</if>
</select>
<select id="selectEtCommandLogById" parameterType="Long" resultMap="EtCommandLogResult">

View File

@ -1170,6 +1170,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dispatchFee != null">dispatch_fee = #{dispatchFee},</if>
<if test="manageFee != null">manage_fee = #{manageFee},</if>
<if test="ridingFee != null">riding_fee = #{ridingFee},</if>
<if test="depositOrderNo != null">deposit_order_no = #{depositOrderNo},</if>
<if test="appointmentFee != null">appointment_fee = #{appointmentFee},</if>
<if test="mark != null">mark = #{mark},</if>
<if test="duration != null">duration = #{duration},</if>
@ -1233,6 +1234,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dispatchFee != null">dispatch_fee = #{dispatchFee},</if>
<if test="manageFee != null">manage_fee = #{manageFee},</if>
<if test="ridingFee != null">riding_fee = #{ridingFee},</if>
<if test="depositOrderNo != null">deposit_order_no = #{depositOrderNo},</if>
<if test="appointmentFee != null">appointment_fee = #{appointmentFee},</if>
<if test="mark != null">mark = #{mark},</if>
<if test="duration != null">duration = #{duration},</if>