1. 联调

This commit is contained in:
邱贞招 2024-05-31 09:38:47 +08:00
parent d9e8887a60
commit 4796e03f8c
6 changed files with 89 additions and 89 deletions

View File

@ -3,12 +3,10 @@ package com.ruoyi.web.controller.app;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.vo.FeeRuleVo;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.CommonUtil; import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*; import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.common.WebSocket;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -35,15 +33,9 @@ public class AppController extends BaseController
@Autowired @Autowired
private IAsDeviceService asDeviceService; private IAsDeviceService asDeviceService;
@Autowired
private WebSocket webSocket;
@Autowired @Autowired
private IEtFeeRuleService etFeeRuleService; private IEtFeeRuleService etFeeRuleService;
@Autowired
private ISysConfigService sysConfigService;
@Autowired @Autowired
private IEtOrderService etOrderService; private IEtOrderService etOrderService;
@ -88,6 +80,10 @@ public class AppController extends BaseController
@GetMapping(value = "/area/{areaId}") @GetMapping(value = "/area/{areaId}")
public AjaxResult getInfo(@PathVariable("areaId") Long areaId) public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
{ {
if(areaId == null){
logger.info("没有传入areaId参数【areaId={}】",areaId);
return error("请传areaId参数"+"【areaId="+areaId+"");
}
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId);
return success(area); return success(area);
} }
@ -149,6 +145,10 @@ public class AppController extends BaseController
@GetMapping(value = "/allVehicleByArea") @GetMapping(value = "/allVehicleByArea")
public AjaxResult allVehicleByArea(Long areaId) public AjaxResult allVehicleByArea(Long areaId)
{ {
if(areaId == null){
logger.info("没有传入areaId参数【areaId={}】",areaId);
return error("请传areaId参数"+"【areaId="+areaId+"");
}
List<AsDevice> asDevices = asDeviceService.allVehicleByArea(areaId); List<AsDevice> asDevices = asDeviceService.allVehicleByArea(areaId);
return success(asDevices); return success(asDevices);
} }
@ -215,6 +215,10 @@ public class AppController extends BaseController
@PostMapping("/device/ring") @PostMapping("/device/ring")
public AjaxResult ring(String sn) public AjaxResult ring(String sn)
{ {
if(StrUtil.isBlank(sn)){
logger.info("没有sn号参数【sn={}】",sn);
return error("请传sn号参数"+"【sn="+sn+"");
}
Boolean i =asDeviceService.ring(sn); Boolean i =asDeviceService.ring(sn);
return success(i); return success(i);
} }
@ -225,6 +229,10 @@ public class AppController extends BaseController
@GetMapping("/device/info") @GetMapping("/device/info")
public AjaxResult deviceInfo(String sn) public AjaxResult deviceInfo(String sn)
{ {
if(StrUtil.isBlank(sn)){
logger.info("没有sn号参数【sn={}】",sn);
return error("请传sn号参数"+"【sn="+sn+"");
}
AsDevice device = asDeviceService.selectAsDeviceBySn(sn); AsDevice device = asDeviceService.selectAsDeviceBySn(sn);
return success(device); return success(device);
} }
@ -235,6 +243,10 @@ public class AppController extends BaseController
@PostMapping("/user/isInOrder") @PostMapping("/user/isInOrder")
public AjaxResult isInOrder(Long userId) public AjaxResult isInOrder(Long userId)
{ {
if(StrUtil.isBlank(userId.toString())){
logger.info("没有userId参数【userId={}】",userId);
return error("请传userId参数"+"【userId="+userId+"");
}
List<EtOrder> orders = etOrderService.isInOrder(userId,null); List<EtOrder> orders = etOrderService.isInOrder(userId,null);
return success(orders); return success(orders);
} }

View File

@ -141,6 +141,9 @@ public class AppVerifyController extends BaseController
public AjaxResult snSwitch(@RequestBody EtOrderVo order) public AjaxResult snSwitch(@RequestBody EtOrderVo order)
{ {
logger.info("【扫码/编号开锁骑行】请求:{}", JSON.toJSON(order)); logger.info("【扫码/编号开锁骑行】请求:{}", JSON.toJSON(order));
if(order.getRuleId()==null){
return error("=============================================ruleId未传=============================================");
}
//运营时间判断 //运营时间判断
if(!asDeviceService.isOperatingTime(order.getSn())){ if(!asDeviceService.isOperatingTime(order.getSn())){
return error("不在营业时间内,不得骑行"); return error("不在营业时间内,不得骑行");

View File

@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.constant.IotConstants;
import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
@ -34,6 +36,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -145,7 +148,7 @@ public class ReceiveController {
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百 Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage); device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString()); device.setRemainingPower(electricQuantity.toString());
int i = asDeviceService.updateAsDeviceBySn(device); int i = asDeviceService.updateLocation(device);
if(i>0){ if(i>0){
log.info("更新定位成功==========================>" +logEntry.getDevName()); log.info("更新定位成功==========================>" +logEntry.getDevName());
/** 2. 判断是否在禁行区内 /** 2. 判断是否在禁行区内
@ -154,52 +157,18 @@ public class ReceiveController {
boolean noRidingArea = asDeviceService.isNoRidingArea(device.getSn(), device.getAreaId()); boolean noRidingArea = asDeviceService.isNoRidingArea(device.getSn(), device.getAreaId());
if(noRidingArea){ if(noRidingArea){
String noRidingOutage = area.getNoRidingOutage(); String noRidingOutage = area.getNoRidingOutage();
//发送播报指令 if (noRidingOutage.equals("1") && value.getStatus() != 3) { // 禁行区内断电
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"禁行区内播报"); log.info("禁行区内断电命令--SN" + device.getSn());
if(noRidingOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//禁行区内断电 asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "禁行区内断电");
//x秒后发送断电命令
scheduledExecutorService.schedule(() -> {
try {
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"超出营运区断电");
device.setIsAreaOutOutage("0");
asDeviceService.updateAsDevice(device);
log.info("禁行区内发送断电命令:" +logEntry.getDevName());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
}, area.getOutage(), TimeUnit.SECONDS);
device.setIsAreaOutOutage("1");
asDeviceService.updateAsDevice(device);
} }
} }
/** 3.超出运营区外断电*/ /** 3.超出运营区外断电*/
boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area); boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area);
if(isAreaZone){ if(!isAreaZone){
String areaOutOutage = area.getAreaOutOutage(); String areaOutOutage = area.getAreaOutOutage();
//发送超出营运区播报指令 if (areaOutOutage.equals("1") && value.getStatus() != 3) { // 超出营运区断电
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"超出营运区播报"); log.info("超出营运区断电命令--SN" + device.getSn());
if(areaOutOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//超出营运区断电 asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "超出营运区断电");
//x秒后发送断电命令
scheduledExecutorService.schedule(() -> {
try {
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_QLOSE,"超出营运区断电");
device.setIsAreaOutOutage("0");
asDeviceService.updateAsDevice(device);
log.info("超出营运区发送断电命令:" +logEntry.getDevName());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
}, area.getOutage(), TimeUnit.SECONDS);
device.setIsAreaOutOutage("1");
asDeviceService.updateAsDevice(device);
} }
} }
/** 4.行程线路添加更新订单中的trip_route字段 */ /** 4.行程线路添加更新订单中的trip_route字段 */
@ -221,39 +190,10 @@ public class ReceiveController {
newPoint.add(lat); newPoint.add(lat);
// 优化轨迹如果获取到的定位与最后一个定位相同则不添加 // 优化轨迹如果获取到的定位与最后一个定位相同则不添加
if(jsonArray.size() > 0){ optimizeRoute(jsonArray, newPoint,lon,lat,etOrder);
JSONArray lastPoint = (JSONArray) jsonArray.get(jsonArray.size() - 1);
if(lastPoint.get(0).equals(lon) && lastPoint.get(1).equals(lat)){
log.info("获取到的定位与最后一个定位相同,不添加线路");
}else{
jsonArray.add(newPoint);
jsonArray.toJSONString();
}
}else{
jsonArray.add(newPoint);
jsonArray.toJSONString();
}
log.info("更新行程jsonArray" +jsonArray.toJSONString());
etOrder.setTripRouteStr(jsonArray.toJSONString());
Geometry geometry = GeoUtils.toGeometryByLinearRing(jsonArray.toJSONString());
String wkt = GeoUtils.wkt(geometry);
etOrder.setTripRoute(wkt);
int updateEtOrder = etOrderService.updateEtOrder(etOrder);
if (updateEtOrder > 0) {
log.info("更新行程线路成功==========================>" +logEntry.getDevName());
}else{
log.info("更新行程线路失败==========================>" +logEntry.getDevName());
}
} }
} }
} }
/** 5.低于电量(%)不得骑行,声音播报 */
if(electricQuantity <= model.getLowBatteryReminder()){
//发送低电量播报指令
// asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报");
log.info("低电量播报:" +logEntry.getDevName());
}
/** 6.低电量 生成换电工单*/ /** 6.低电量 生成换电工单*/
Integer replacementOrder = area.getAutoReplacementOrder(); Integer replacementOrder = area.getAutoReplacementOrder();
Boolean aBoolean = etAdminOrderService.checkOrderUnique(device.getSn()); Boolean aBoolean = etAdminOrderService.checkOrderUnique(device.getSn());
@ -294,7 +234,6 @@ public class ReceiveController {
// //发送超出营运区播报指令 // //发送超出营运区播报指令
// asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY2,"靠近营运边界播报"); // asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY2,"靠近营运边界播报");
// } // }
}else{ }else{
log.info("更新定位失败:" +logEntry.getDevName()); log.info("更新定位失败:" +logEntry.getDevName());
} }
@ -315,6 +254,37 @@ public class ReceiveController {
return "ok"; return "ok";
} }
private boolean isLastPointSame(JSONArray jsonArray, BigDecimal lon, BigDecimal lat) {
if (jsonArray.size() > 0) {
JSONArray lastPoint = (JSONArray) jsonArray.get(jsonArray.size() - 1);
return lastPoint.get(0).equals(lon) && lastPoint.get(1).equals(lat);
}
return false;
}
public void optimizeRoute(JSONArray jsonArray, JSONArray newPoint, BigDecimal lon, BigDecimal lat, EtOrder etOrder) {
if (isLastPointSame(jsonArray, lon, lat)) {
log.info("获取到的定位与最后一个定位相同,不添加线路");
} else {
jsonArray.add(newPoint);
String tripRouteStr = jsonArray.toJSONString();
log.info("更新行程jsonArray" + tripRouteStr);
etOrder.setTripRouteStr(tripRouteStr);
Geometry geometry = GeoUtils.toGeometryByLinearRing(tripRouteStr);
String wkt = GeoUtils.wkt(geometry);
etOrder.setTripRoute(wkt);
int updateEtOrderResult = etOrderService.updateEtOrder(etOrder);
if (updateEtOrderResult > 0) {
log.info("更新行程线路成功==========================>" + etOrder.getSn());
} else {
log.info("更新行程线路失败==========================>" + etOrder.getSn());
}
}
}
/** /**
* 功能说明 URL&Token验证接口如果验证成功返回msg的值否则返回其他值 * 功能说明 URL&Token验证接口如果验证成功返回msg的值否则返回其他值
* @param msg 验证消息 * @param msg 验证消息

View File

@ -220,6 +220,9 @@ public interface IAsDeviceService extends IService<AsDevice>
*/ */
List<AsDevice> allVehicleByArea(Long areaId); List<AsDevice> allVehicleByArea(Long areaId);
int updateLocation(AsDevice device);
// /** // /**
// * 是否靠近运营区边界 // * 是否靠近运营区边界
// */ // */

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.constant.IotConstants;
@ -928,14 +929,11 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
private EtOrder calculateOrderFee(EtOrder order) { private EtOrder calculateOrderFee(EtOrder order) {
String type = order.getType(); String type = order.getType();
if(type.equals("1")){//骑行订单,正常骑行包含预约费计时收费根据开锁时间起步价和起步时长时长费和时长分钟等参数如果有预约还要加上预约费计算费用,还要判断封顶费用根据开锁时间 if(type.equals("1")){//骑行订单,正常骑行包含预约费计时收费根据开锁时间起步价和起步时长时长费和时长分钟等参数如果有预约还要加上预约费计算费用,还要判断封顶费用根据开锁时间
// /** 预约费*/
// Date appointmentStartTime = order.getAppointmentStartTime();
// if(ObjectUtils.isNotEmpty(appointmentStartTime)){
// //有预约根据开始时间和结束时间计算费用 预约费 = (预约结束时间 - 开始时间) * 预约服务费
// calculateAppointmentFee(order);
// }
Long ruleId = order.getRuleId(); Long ruleId = order.getRuleId();
EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(ruleId); EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(ruleId);
if(ObjectUtil.isNull(rule)){
throw new ServiceException("计费规则不存在");
}
String rentalUnit = rule.getRentalUnit();//租赁单位 String rentalUnit = rule.getRentalUnit();//租赁单位
//根据订单的开始时间和还车时间计算出在第几个计费周期在第一个计费周期内并没有超过封顶费用则根据规则算出骑行费 //根据订单的开始时间和还车时间计算出在第几个计费周期在第一个计费周期内并没有超过封顶费用则根据规则算出骑行费
@ -1291,6 +1289,21 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
return asDevices; return asDevices;
} }
/**
* 更新位置信息
*/
@Override
public int updateLocation(AsDevice device) {
UpdateWrapper<AsDevice> wrapper = new UpdateWrapper<>();
wrapper.eq("sn",device.getSn())
.set("longitude",device.getLongitude())
.set("latitude",device.getLatitude())
.set("remaining_power",device.getRemainingPower())
.set("voltage",device.getVoltage());
return asDeviceMapper.update(null,wrapper);
}
/** /**
* 判断是否靠近边界 * 判断是否靠近边界
*/ */

View File

@ -192,7 +192,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="picture != null">picture = #{picture},</if> <if test="picture != null">picture = #{picture},</if>
<if test="deviceName != null">device_name = #{deviceName},</if> <if test="deviceName != null">device_name = #{deviceName},</if>
<if test="mac != null">mac = #{mac},</if> <if test="mac != null">mac = #{mac},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="modelId != null">model_id = #{modelId},</if> <if test="modelId != null">model_id = #{modelId},</if>
<if test="vehicleNum != null">vehicle_num = #{vehicleNum},</if> <if test="vehicleNum != null">vehicle_num = #{vehicleNum},</if>
<if test="areaId != null">area_id = #{areaId},</if> <if test="areaId != null">area_id = #{areaId},</if>
@ -212,7 +211,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="qrcode != null">qrcode = #{qrcode},</if> <if test="qrcode != null">qrcode = #{qrcode},</if>
<if test="longitude != null">longitude = #{longitude},</if> <if test="longitude != null">longitude = #{longitude},</if>
<if test="latitude != null">latitude = #{latitude},</if> <if test="latitude != null">latitude = #{latitude},</if>
<if test="is_area_out_outage != null">is_area_out_outage = #{is_area_out_outage},</if> <if test="isAreaOutOutage != null">is_area_out_outage = #{isAreaOutOutage},</if>
</trim> </trim>
where sn = #{sn} where sn = #{sn}
</update> </update>