This commit is contained in:
邱贞招 2025-01-27 00:05:45 +08:00
parent fd28903b06
commit b8c28c02a7
4 changed files with 86 additions and 38 deletions

View File

@ -249,14 +249,14 @@ public class AppVerifyController extends BaseController
if(ObjectUtil.isNotNull(currentOrder)){
return error("当前车辆有骑行中的订单,请换车");
}
//根据余额和充值记录判断是否有充值过押金没有充值过押金提示充值押金
if(!asUserService.checkIsDeposit(order.getUserId(),area.getAreaId())){
return error("您还未充值押金,请先充值押金");
}
logger.info("【扫码/编号开锁骑行】请求:{}", JSON.toJSON(order));
if(!etOrderService.isInOrder(order.getUserId(), order.getOrderNo()).isEmpty()){
return error("您有未完成的订单,请先完成订单");
}
//根据余额和充值记录判断是否有充值过押金没有充值过押金提示充值押金
if(!asUserService.checkIsDeposit(order.getUserId(),area.getAreaId())){
return error("您还未充值押金,请先充值押金");
}
//低电量不得骑行判断
if(asDeviceService.isLowBattery(order.getSn())){
return error("低电量不得骑行");

View File

@ -6,10 +6,10 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://47.120.68.19:3306/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://localhost:3306/ele2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://47.120.68.19:3306/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://localhost:3306/ele2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: d0dbe100b71c1d09
password: 123456
# url: jdbc:mysql://117.26.179.22:61110/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: d0dbe100b71c1d09

View File

@ -175,9 +175,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
BigDecimal lon = BigDecimal.valueOf(doubles[1]).setScale(8, RoundingMode.HALF_UP);
// todo 0E-8 排除
BigDecimal lat = BigDecimal.valueOf(doubles[0]).setScale(8, RoundingMode.HALF_UP);
// long 转String
device.setLongitude(lon.toString());
device.setLatitude(lat.toString());
device.setLastLocationTime(new Date(logEntry.getAt()));
updateDevice2(logEntry.getAt(),value,device,lon,lat);
}else{
device.setLongitude(null);
device.setLatitude(null);
@ -188,6 +188,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
//https://dianche.chuantewulian.cn?sn=https://dche.ccttiot.com?sn=3000900
device.setQrText(sysDept.getDomain()+"?sn="+device.getSn());
device.setDeptName(sysDept.getDeptName());
device.setDeptId(sysDept.getDeptId());
}else{
device.setQrText("");
}
@ -3027,6 +3028,37 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
return i;
}
/** 计算电量和里程后更新设备*/
public int updateDevice2(long at,LogEntry.LocationValue locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) {
device.setLatitude(lat.toString());
device.setLongitude(lon.toString());
BigDecimal bat = new BigDecimal(locationVo.getBat());
if(bat.compareTo(new BigDecimal(100)) > 0){
bat = bat.divide(new BigDecimal(10));
}
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
// 根据电压计算续航里程
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
}
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
}
device.setLastTime(new Date(at));
device.setLastLocationTime(new Date(at));
device.setGps("1");
// 信号强度
device.setSignalStrength(locationVo.getCsq());
device.setSatellites(locationVo.getS());
device.setQuality(locationVo.getQ());
return updateLocation(device);
}
/** 无定位更新设备 */
private void noLocationUpdateDevice(String at,LocationVo locationVo, AsDevice device) {
BigDecimal bat = new BigDecimal(locationVo.getBat());

View File

@ -586,15 +586,23 @@ public class EtTask {
*/
public void updateLocation10(){
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压-----开始--------------");
// 记录开始时间
long startTime = System.nanoTime();
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
// log.info("redis缓存中的数据" + JSON.toJSONString(keys));
if (keys == null || keys.isEmpty()) {
log.warn("没有找到需要更新的设备缓存信息");
return;
}
for(String key:keys){
try {
String msg = redisCache.getCacheObject(key);
// log.info("redis缓存中的数据{}", msg);
if (msg == null) {
log.warn("设备缓存数据为空, key: {}", key);
continue;
}
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
// log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
if (logEntry == null || logEntry.getValue() == null || logEntry.getDevName() == null) {
log.warn("设备日志数据解析异常, msg: {}", msg);
continue;
}
LogEntry.LocationValue value = logEntry.getValue();
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
if(ObjectUtil.isNotNull(device) && !isRepeatMsg(msg,logEntry.getDevName())){
@ -602,10 +610,10 @@ public class EtTask {
updateLocationHandle(msg, logEntry, value, device);
}
}
} catch (Exception e) {
log.error("处理设备数据异常, key: {}, error: {}", key, e.getMessage(), e);
}
}
// 计算执行时间以毫秒为单位
long duration = (System.nanoTime() - startTime) / 1_000_000;
// log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
}
private boolean isRepeatMsg(String msg,String mac){
@ -624,24 +632,32 @@ public class EtTask {
*/
public void updateLocation300(){
log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压-----开始--------------");
// 记录开始时间
long startTime = System.nanoTime();
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
// log.info("redis缓存中的数据{}", JSON.toJSONString(keys));
if (keys == null || keys.isEmpty()) {
log.warn("没有找到需要更新的设备缓存信息");
return;
}
for(String key:keys){
try {
String msg = redisCache.getCacheObject(key);
// log.info("redis缓存中的数据{}", msg);
if (msg == null) {
log.warn("设备缓存数据为空, key: {}", key);
continue;
}
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
// log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
if (logEntry == null || logEntry.getValue() == null || logEntry.getDevName() == null) {
log.warn("设备日志数据解析异常, msg: {}", msg);
continue;
}
LogEntry.LocationValue value = logEntry.getValue();
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
if(ObjectUtil.isNotNull(device) && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())){
updateLocationHandle(msg, logEntry, value, device);
}
} catch (Exception e) {
log.error("处理设备数据异常, key: {}, error: {}", key, e.getMessage(), e);
}
}
// 计算执行时间以毫秒为单位
long duration = (System.nanoTime() - startTime) / 1_000_000;
// log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
}
private void updateLocationHandle(String msg, LogEntry logEntry, LogEntry.LocationValue value, AsDevice device) {