diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 8d2bc7e..ab6f156 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -3,12 +3,10 @@ package com.ruoyi.web.controller.app; import cn.hutool.core.util.StrUtil; import com.ruoyi.common.core.controller.BaseController; 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.utils.CommonUtil; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; -import com.ruoyi.web.controller.common.WebSocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -35,15 +33,9 @@ public class AppController extends BaseController @Autowired private IAsDeviceService asDeviceService; - @Autowired - private WebSocket webSocket; - @Autowired private IEtFeeRuleService etFeeRuleService; - @Autowired - private ISysConfigService sysConfigService; - @Autowired private IEtOrderService etOrderService; @@ -88,6 +80,10 @@ public class AppController extends BaseController @GetMapping(value = "/area/{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); return success(area); } @@ -149,6 +145,10 @@ public class AppController extends BaseController @GetMapping(value = "/allVehicleByArea") public AjaxResult allVehicleByArea(Long areaId) { + if(areaId == null){ + logger.info("没有传入areaId参数:【areaId={}】",areaId); + return error("请传areaId参数"+"【areaId="+areaId+"】"); + } List asDevices = asDeviceService.allVehicleByArea(areaId); return success(asDevices); } @@ -215,6 +215,10 @@ public class AppController extends BaseController @PostMapping("/device/ring") public AjaxResult ring(String sn) { + if(StrUtil.isBlank(sn)){ + logger.info("没有sn号参数:【sn={}】",sn); + return error("请传sn号参数"+"【sn="+sn+"】"); + } Boolean i =asDeviceService.ring(sn); return success(i); } @@ -225,6 +229,10 @@ public class AppController extends BaseController @GetMapping("/device/info") public AjaxResult deviceInfo(String sn) { + if(StrUtil.isBlank(sn)){ + logger.info("没有sn号参数:【sn={}】",sn); + return error("请传sn号参数"+"【sn="+sn+"】"); + } AsDevice device = asDeviceService.selectAsDeviceBySn(sn); return success(device); } @@ -235,6 +243,10 @@ public class AppController extends BaseController @PostMapping("/user/isInOrder") public AjaxResult isInOrder(Long userId) { + if(StrUtil.isBlank(userId.toString())){ + logger.info("没有userId参数:【userId={}】",userId); + return error("请传userId参数"+"【userId="+userId+"】"); + } List orders = etOrderService.isInOrder(userId,null); return success(orders); } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index f3cf793..3283c60 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -141,6 +141,9 @@ public class AppVerifyController extends BaseController public AjaxResult snSwitch(@RequestBody EtOrderVo order) { logger.info("【扫码/编号开锁骑行】请求:{}", JSON.toJSON(order)); + if(order.getRuleId()==null){ + return error("=============================================ruleId未传!!!============================================="); + } //运营时间判断 if(!asDeviceService.isOperatingTime(order.getSn())){ return error("不在营业时间内,不得骑行"); diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index 06a6c9d..4da45a9 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; 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.ServiceConstants; import com.ruoyi.common.core.domain.entity.SysUser; @@ -34,6 +36,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -145,7 +148,7 @@ public class ReceiveController { Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百 device.setRemainingMileage(remainingMileage); device.setRemainingPower(electricQuantity.toString()); - int i = asDeviceService.updateAsDeviceBySn(device); + int i = asDeviceService.updateLocation(device); if(i>0){ log.info("更新定位成功==========================>" +logEntry.getDevName()); /** 2. 判断是否在禁行区内 @@ -154,52 +157,18 @@ public class ReceiveController { boolean noRidingArea = asDeviceService.isNoRidingArea(device.getSn(), device.getAreaId()); if(noRidingArea){ String noRidingOutage = area.getNoRidingOutage(); - //发送播报指令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"禁行区内播报"); - if(noRidingOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//禁行区内断电 - //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); + if (noRidingOutage.equals("1") && value.getStatus() != 3) { // 禁行区内断电 + log.info("禁行区内断电命令--SN:" + device.getSn()); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "禁行区内断电"); } } /** 3.超出运营区外断电*/ boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area); - if(isAreaZone){ + if(!isAreaZone){ String areaOutOutage = area.getAreaOutOutage(); - //发送超出营运区播报指令 - asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY3,"超出营运区播报"); - if(areaOutOutage.equals("1") && !device.getIsAreaOutOutage().equals("1")){//超出营运区断电 - //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); + if (areaOutOutage.equals("1") && value.getStatus() != 3) { // 超出营运区断电 + log.info("超出营运区断电命令--SN:" + device.getSn()); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE, "超出营运区断电"); } } /** 4.行程线路添加,更新订单中的trip_route字段 */ @@ -221,39 +190,10 @@ public class ReceiveController { newPoint.add(lat); // 优化轨迹,如果获取到的定位与最后一个定位相同,则不添加 - if(jsonArray.size() > 0){ - 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()); - } + optimizeRoute(jsonArray, newPoint,lon,lat,etOrder); } } } - /** 5.低于电量(%)不得骑行,声音播报 */ - if(electricQuantity <= model.getLowBatteryReminder()){ - //发送低电量播报指令 -// asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报"); - log.info("低电量播报:" +logEntry.getDevName()); - } /** 6.低电量 生成换电工单*/ Integer replacementOrder = area.getAutoReplacementOrder(); Boolean aBoolean = etAdminOrderService.checkOrderUnique(device.getSn()); @@ -294,7 +234,6 @@ public class ReceiveController { // //发送超出营运区播报指令 // asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY2,"靠近营运边界播报"); // } - }else{ log.info("更新定位失败:" +logEntry.getDevName()); } @@ -315,6 +254,37 @@ public class ReceiveController { 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的值,否则返回其他值。 * @param msg 验证消息 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java index b4002b9..d9a8c3e 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java @@ -220,6 +220,9 @@ public interface IAsDeviceService extends IService */ List allVehicleByArea(Long areaId); + + int updateLocation(AsDevice device); + // /** // * 是否靠近运营区边界 // */ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 549c9fc..49acda9 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; 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.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.IotConstants; @@ -928,14 +929,11 @@ public class AsDeviceServiceImpl extends ServiceImpl i private EtOrder calculateOrderFee(EtOrder order) { String type = order.getType(); if(type.equals("1")){//骑行订单,正常骑行(包含预约费),计时收费,根据开锁时间、起步价和起步时长、时长费和时长分钟等参数,如果有预约,还要加上预约费计算费用,还要判断封顶费用(根据开锁时间) -// /** 预约费*/ -// Date appointmentStartTime = order.getAppointmentStartTime(); -// if(ObjectUtils.isNotEmpty(appointmentStartTime)){ -// //有预约,根据开始时间和结束时间计算费用 预约费 = (预约结束时间 - 开始时间) * 预约服务费 -// calculateAppointmentFee(order); -// } Long ruleId = order.getRuleId(); EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleId(ruleId); + if(ObjectUtil.isNull(rule)){ + throw new ServiceException("计费规则不存在"); + } String rentalUnit = rule.getRentalUnit();//租赁单位 //根据订单的开始时间和还车时间计算出在第几个计费周期,在第一个计费周期内,并没有超过封顶费用,则根据规则算出骑行费, @@ -1291,6 +1289,21 @@ public class AsDeviceServiceImpl extends ServiceImpl i return asDevices; } + /** + * 更新位置信息 + */ + @Override + public int updateLocation(AsDevice device) { + UpdateWrapper 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); + } + + /** * 判断是否靠近边界 */ diff --git a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml index 655db0e..b1a5c2c 100644 --- a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml @@ -192,7 +192,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" picture = #{picture}, device_name = #{deviceName}, mac = #{mac}, - sn = #{sn}, model_id = #{modelId}, vehicle_num = #{vehicleNum}, area_id = #{areaId}, @@ -212,7 +211,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" qrcode = #{qrcode}, longitude = #{longitude}, latitude = #{latitude}, - is_area_out_outage = #{is_area_out_outage}, + is_area_out_outage = #{isAreaOutOutage}, where sn = #{sn}