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 bd9b700..7a191c0 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,8 +5,6 @@ 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; @@ -37,7 +35,6 @@ 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; @@ -185,17 +182,22 @@ public class ReceiveController { if (noRidingOutage.equals("1") && value.getStatus() != 3) { // 禁行区内断电 log.info("禁行区内断电命令--SN:" + device.getSn()); asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "禁行区内断电"); + device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); + int updateAsDevice = asDeviceService.updateAsDevice(device); + if (updateAsDevice > 0) { + log.info("禁行区内断电--更新设备锁状态成功SN:" + device.getSn()); + } } } /** 3.超出运营区外断电*/ boolean isAreaZone = asDeviceService.isAreaZone(device.getSn(), area); if(!isAreaZone){ - //是否在20米范围内 - boolean inPolygon = GeoUtils.isInPolygonWithTolerance(lon.toString(), lat.toString(), GeoUtils.fromWkt(area.getBoundary()), 20); + //是否在30米范围内 + boolean inPolygon = GeoUtils.isInPolygonWithTolerance(lon.toString(), lat.toString(), GeoUtils.fromWkt(area.getBoundary()), 60); if(inPolygon){ //在20米范围内,发报警 - log.info("超出运营区20米内发送警告命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区20米内"); + log.info("超出运营区30米内发送警告命令--SN:" + device.getSn()); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区30米内"); }else{ //超出运营区外断电 String isAdminUnlocking = device.getIsAdminUnlocking();// 是否管理员开锁 @@ -203,6 +205,27 @@ public class ReceiveController { if (areaOutOutage.equals("1") && value.getStatus() != 3 && !isAdminUnlocking.equals("1")) { // 超出营运区断电 log.info("超出营运区断电命令--SN:" + device.getSn()); asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "超出营运区断电"); + device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); + int updateAsDevice = asDeviceService.updateAsDevice(device); + if (updateAsDevice > 0) { + log.info("禁行区内断电--更新设备锁状态成功SN:" + device.getSn()); + } + } + } + }else{ + // 判断该车辆是否在进行中的订单,并且车辆的锁状态是关,状态是骑行中 + Boolean inOrderBySn = etOrderService.isInOrderBySn(device.getSn()); + if (inOrderBySn && ServiceConstants.VEHICLE_STATUS_IN_USING.equals(device.getStatus()) && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())) { // 有正在骑行的订单,给车辆上电 + log.info("返回营运区上电,有正在骑行的订单,给车辆上电--SN:" + device.getSn()); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "返回营运区上电"); + // 更新车辆状态和锁状态 + /** 3.更新车辆状态*/ + device.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); + device.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING); + device.setIsAdminUnlocking("0"); + int i1 = asDeviceService.updateAsDevice(device); + if(i1>1){ + log.info("【返回营运区上电】更新车辆状态成功"); } } } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index 43e6279..9ba7519 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -138,6 +138,7 @@ public class SysLoginController log.info("没有传入areaId参数:【areaId={}】",areaId); return AjaxResult.error("请传areaId参数"+"【areaId="+areaId+"】"); } + log.info("【微信登录/wxlogin】areaId参数:【areaId={}】",areaId); AjaxResult ajax = AjaxResult.success(); // 生成令牌 String token = loginService.wxloing(mobileCode,jsCode,areaId); diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java index a108622..a71785c 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java @@ -119,7 +119,7 @@ public class IotConstants { /** * 命令 频率:5秒 */ - public static final String COMMAND_FREQUENCY_5 = "sub10@"; + public static final String COMMAND_FREQUENCY_5 = "sub5@"; /** * 命令 频率:20秒 diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java b/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java index 95a0fa4..d282cb2 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java @@ -232,7 +232,7 @@ public class GeoUtils { /** * 判断一个点是否在一个圆形区域内(考虑误差距离) * */ - public static boolean isInPolygonWithTolerance (String longitude, String latitude, Geometry polygon, double tolerance) { + public static boolean isInPolygonWithTolerance(String longitude, String latitude, Geometry polygon, double tolerance) { double lon = Double.parseDouble(longitude); double lat = Double.parseDouble(latitude); @@ -247,6 +247,7 @@ public class GeoUtils { Coordinate[] coordinates = polygon.getCoordinates(); for (Coordinate coord : coordinates) { double distance = calculateDistance(lat, lon, coord.y, coord.x); + log.info("距离----distance:{}",distance); if (distance <= tolerance) { return true; } diff --git a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 26558d3..762fdb9 100644 --- a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -4,6 +4,7 @@ import javax.annotation.Resource; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.entity.AsUser; import com.ruoyi.common.core.domain.entity.SysDept; @@ -13,6 +14,7 @@ import com.ruoyi.common.utils.wx.AccessTokenUtil; import com.ruoyi.common.utils.wx.vo.WeChatMiniAuthorizeVo; import com.ruoyi.system.service.IAsUserService; import com.ruoyi.system.service.IWxPayService; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; @@ -47,6 +49,7 @@ import com.ruoyi.system.service.ISysUserService; * * @author ruoyi */ +@Slf4j @Component public class SysLoginService { @@ -206,13 +209,15 @@ public class SysLoginService */ public String wxloing(String mobileCode,String jsCode,String areaId) { //根据jsCode换取openid - String openId = getOpenId(jsCode); + SysDept dept = wxPayService.getDeptObjByAreaId(Long.parseLong(areaId)); + log.info("【微信登录/wxlogin】获取到运营商对象:【{}】", JSON.toJSON(dept)); + String openId = getOpenId(jsCode,dept.getAppid(),dept.getAppSecret()); String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="; String phoneNumber = null; AsUser user = null; /** 根据手机号获取到用户名*/ - SysDept dept = wxPayService.getDeptObjByAreaId(Long.parseLong(areaId)); + String token = AccessTokenUtil.getToken(dept.getAppid(), dept.getAppSecret()); url = url+token; JSONObject jsonObject = new JSONObject(); @@ -286,8 +291,10 @@ public class SysLoginService */ public String loginByopenid(String jsCode,String areaId) { //根据jsCode换取openid - String openid = getOpenId(jsCode); - AsUser user = asUserService.selectUserByWxopenid(openid); + SysDept dept = wxPayService.getDeptObjByAreaId(Long.parseLong(areaId)); + log.info("【微信登录/wxlogin】获取到运营商对象:【{}】", JSON.toJSON(dept)); + String openId = getOpenId(jsCode,dept.getAppid(),dept.getAppSecret()); + AsUser user = asUserService.selectUserByWxopenid(openId); if(ObjectUtils.isEmpty(user)){ throw new ServiceException("未查询到用户信息"); }else{ @@ -318,10 +325,8 @@ public class SysLoginService return tokenService.createToken(loginUser); } - private String getOpenId(String jsCode) { + private String getOpenId(String jsCode,String appId,String secret) { //根据jsCode换取openid - String appId = SpringUtils.getRequiredProperty("wx.appid"); - String secret = SpringUtils.getRequiredProperty("wx.appSecret"); String url = StrUtil.format("https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code", appId, secret, jsCode); String s = HttpUtils.sendGet(url); WeChatMiniAuthorizeVo authorizeVo = JSONObject.parseObject(s, WeChatMiniAuthorizeVo.class); diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java index 9a27e28..e2d8c21 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java @@ -94,6 +94,14 @@ public interface EtOrderMapper */ public List isInOrder(@Param("userId") Long userId,@Param("orderNo") String orderNo); + /** + * 查询当前车辆是否有正在进行中的订单 + * + * @param sn 用户id + * @return 结果 + */ + public List isInOrderBySn(@Param("sn") String sn); + /** * 检验预约订单只能有一个 * 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 cf31db8..751d1d7 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 @@ -110,6 +110,11 @@ public interface IEtOrderService */ List isInOrder(Long userId,String orderNo); + /** + * 查询当前车辆是否有正在进行中的订单 + */ + Boolean isInOrderBySn(String sn); + /** * 创建订单 * @param order 订单信息 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 19b60be..8df2764 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 @@ -812,4 +812,12 @@ public class EtOrderServiceImpl implements IEtOrderService } return inOrder; } + /** + * 查询当前车辆是否有正在进行中的订单 + */ + @Override + public Boolean isInOrderBySn(String sn) { + List inOrder = etOrderMapper.isInOrderBySn(sn); + return inOrder.size() > 0; + } } diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml index 424f0a0..0f5fe85 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml @@ -146,6 +146,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + +