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 5d11e58..6c8459d 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 @@ -6,7 +6,9 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.AsArticleClassify; @@ -30,7 +32,6 @@ import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.refund.model.Refund; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -39,6 +40,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.List; /** @@ -684,4 +686,42 @@ public class AppController extends BaseController return success(list); } + /** + * 不同状态的订单 + */ + @GetMapping("/getErrorOrder") + public AjaxResult getErrorOrder() + { + List<EtOrder> errorOrders = new ArrayList<>(); + // 当前有骑行中的订单 + List<EtOrder> orders = etOrderService.getCurrentOrderList(); + for (EtOrder order:orders) { + AsDevice device = asDeviceMapper.selectAsDeviceBySn(order.getSn()); + if(ObjectUtil.isNotNull(device) && device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NORMAL)){ + errorOrders.add(order); + } + } + return success(errorOrders); + } + + /** + * 不同状态的车辆 + */ + @GetMapping("/getErrorDevice") + public AjaxResult getErrorDevice() + { + List<AsDevice> errorDevices = new ArrayList<>(); + // 2. 如果车辆状态是骑行中或临时锁车,查询当前没有订单,则修改车辆状态为待骑行 + QueryWrapper<AsDevice> wrapper = new QueryWrapper<>(); + wrapper.in("status", "3","4"); // 设备状态正常 + // 查询所有设备 + List<AsDevice> allDevices = asDeviceMapper.selectList(wrapper); + for(AsDevice device:allDevices){ + if(ObjectUtil.isNull(etOrderService.getCurrentOrder2(device.getSn()))){ + errorDevices.add(device); + } + } + return success(errorDevices); + } + } 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 2ad0490..35e3c90 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 @@ -390,6 +390,11 @@ public interface IAsDeviceService extends IService<AsDevice> */ boolean updateLatestLocation(String sn); + /** + * 获取最新的位置信息 + */ + double[] getLatestLocation(String mac); + /** * 根据时间查询车辆轨迹 */ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java index 180072b..c8b5427 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOrderService.java @@ -185,6 +185,11 @@ public interface IEtOrderService */ EtOrder getCurrentOrder(String sn); + /** + * 获取当前正在骑行中的订单 + */ + EtOrder getCurrentOrder2(String sn); + /** * 查询所有正在骑行中的订单 */ 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 ce44f19..41f1603 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 @@ -2244,7 +2244,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i inCircle = true; break; }else{ - log.info("位置【{},{}】在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName()); + log.info("位置【{},{}】不在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName()); } } return inCircle; @@ -2495,7 +2495,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i } /** - * 判断是否在停车区申请人 + * 判断是否在停车区 */ @Override public IsInParkingAreaVo isInParkingArea(String longitude, String latitude,String areaId,String sn){ @@ -2504,13 +2504,17 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i IsInParkingAreaVo isInParkingAreaVo = new IsInParkingAreaVo(); if(StringUtils.isNotEmpty(sn)){ AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn); - String longitude1 = device.getLongitude(); - String latitude1 = device.getLatitude(); - Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude1, latitude1, Long.parseLong(areaId)); - if(parkingZoneByLocation){ - isInParkingAreaVo.setIsInParkingArea(parkingZoneByLocation); - isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn())); - return isInParkingAreaVo; + double[] latestLocation = getLatestLocation(device.getMac()); + if(ObjectUtil.isNotNull(latestLocation)){ + BigDecimal longitude1 = new BigDecimal(latestLocation[1]).setScale(8, RoundingMode.HALF_UP); + BigDecimal latitude1 = new BigDecimal(latestLocation[0]).setScale(8, RoundingMode.HALF_UP); + log.info("【判断是否在停车区】,lon:{},lat:{}",longitude1,latitude1); + Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude1.toString(), latitude1.toString(), Long.parseLong(areaId)); + if(parkingZoneByLocation){ + isInParkingAreaVo.setIsInParkingArea(true); + isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn())); + return isInParkingAreaVo; + } } } Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude, latitude, Long.parseLong(areaId)); @@ -2736,6 +2740,48 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i return false; } + /** + * 获取最新的位置信息 + */ + @Override + @SneakyThrows + public double[] getLatestLocation(String mac) { + AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac); + String token = Token.getToken(); + DataPointRes datapoints = historyDatapoints(mac, token); + if(datapoints.getCode() == 0){ + Data data = datapoints.getData(); + List<Datastream> datastreams = data.getDevices(); + for (Datastream datastream: datastreams) { + List<Datapoint> datapointList = datastream.getDatastreams(); + if(ObjectUtil.isNotNull(datapointList)){ + for (Datapoint datapoint:datapointList) { + if(datapoint.getId().equals(IotConstants.ONENET_LOCATION)){ + String string = JSON.toJSONString(datapoint.getValue()); + String at = datapoint.getAt(); + if(StrUtil.isNotBlank(string)){ + LocationVo locationVo = JSONObject.parseObject(string, LocationVo.class); + log.info("【手动更新】: locationVo---【{}】" , JSON.toJSONString(locationVo)); + double[] doubles = CommonUtil.coordinateConvert(locationVo.getLon(), locationVo.getLat()); + BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP); + BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP); + log.info("转换后的GCJ02经纬度:" + lon + "---" + lat); + if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ + /** 计算电量和里程后更新设备*/ + int i = updateDevice(at,locationVo, device, lon, lat); + return doubles; + }else{ + noLocationUpdateDevice(at,locationVo,device); + } + } + } + } + } + } + } + return null; + } + /** 计算电量和里程后更新设备*/ public int updateDevice(String at,LocationVo locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) { device.setLatitude(lat.toString()); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index f555076..8c0bca4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -371,6 +371,23 @@ public class EtOrderServiceImpl implements IEtOrderService return null; } + /** + * 获取当前正在骑行中的订单 + * @param sn + * @return + */ + @Override + public EtOrder getCurrentOrder2(String sn) { + EtOrder etOrder = new EtOrder(); + etOrder.setSn(sn); + etOrder.setStatus(ServiceConstants.ORDER_STATUS_RIDING); + List<EtOrder> etOrders = etOrderMapper.selectEtOrderListNoRoute(etOrder); + if(ObjectUtil.isNotEmpty(etOrders)){ + return etOrders.get(0); + } + return null; + } + /** * 查询所有正在骑行中的订单 * @return diff --git a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java index 15a0418..0be7797 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java +++ b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java @@ -444,7 +444,7 @@ public class EtTask { // 查询所有设备 List<AsDevice> allDevices = asDeviceMapper.selectList(wrapper); for(AsDevice device:allDevices){ - if(ObjectUtil.isNotNull(etOrderService.getCurrentOrder(device.getSn()))){ + if(ObjectUtil.isNotNull(etOrderService.getCurrentOrder2(device.getSn()))){ continue; }else{ AsDevice device1 = new AsDevice(); diff --git a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml index e469000..fc892ee 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml @@ -112,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="deptId != null"> and d.dept_id = #{deptId}</if> <if test="areaId != null"> and a.area_id = #{areaId}</if> </where> + order by a.area_name </select> </mapper>