@ -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_RETRU N_LOCK) ;
int tripLog = tripLogService . tripLog ( order . getOrderNo ( ) , device . getSn ( ) , TRIP_LOG_TYPE_RETUR N_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 < > ( ) ;