1. 联调
This commit is contained in:
		
							parent
							
								
									89eea6a4a4
								
							
						
					
					
						commit
						f9086a50ea
					
				| 
						 | 
				
			
			@ -128,18 +128,28 @@ public class AppController extends BaseController
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//    /**
 | 
			
		||||
//     * 根据定位获取运营区信息,并返回所有车辆定位
 | 
			
		||||
//     */
 | 
			
		||||
//    @GetMapping(value = "/vehicleLocalization")
 | 
			
		||||
//    public AjaxResult vehicleLocalization(String longitude,String latitude)
 | 
			
		||||
//    {
 | 
			
		||||
//        if(StrUtil.isBlank(longitude) || StrUtil.isBlank(latitude)){
 | 
			
		||||
//            logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude);
 | 
			
		||||
//            return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】");
 | 
			
		||||
//        }
 | 
			
		||||
////        webSocket.SendMessage("需要发送的消息", "识别唯一session");
 | 
			
		||||
//        List<AsDevice> asDevices = asDeviceService.vehicleLocalization(longitude,latitude);
 | 
			
		||||
//        return success(asDevices);
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据定位获取运营区信息,并返回所有车辆定位
 | 
			
		||||
     * 根据运营区id获取所有车辆
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping(value = "/vehicleLocalization")
 | 
			
		||||
    public AjaxResult vehicleLocalization(String longitude,String latitude)
 | 
			
		||||
    @GetMapping(value = "/allVehicleByArea")
 | 
			
		||||
    public AjaxResult allVehicleByArea(Long areaId)
 | 
			
		||||
    {
 | 
			
		||||
        if(StrUtil.isBlank(longitude) || StrUtil.isBlank(latitude)){
 | 
			
		||||
            logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude);
 | 
			
		||||
            return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】");
 | 
			
		||||
        }
 | 
			
		||||
//        webSocket.SendMessage("需要发送的消息", "识别唯一session");
 | 
			
		||||
        List<AsDevice> asDevices = asDeviceService.vehicleLocalization(longitude,latitude);
 | 
			
		||||
        List<AsDevice> asDevices = asDeviceService.allVehicleByArea(areaId);
 | 
			
		||||
        return success(asDevices);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -140,6 +140,7 @@ public class AppVerifyController extends BaseController
 | 
			
		|||
    @PostMapping("/device/snSwitch")
 | 
			
		||||
    public AjaxResult snSwitch(@RequestBody EtOrderVo order)
 | 
			
		||||
    {
 | 
			
		||||
        logger.info("【扫码/编号开锁骑行】请求:{}", JSON.toJSON(order));
 | 
			
		||||
        //运营时间判断
 | 
			
		||||
        if(!asDeviceService.isOperatingTime(order.getSn())){
 | 
			
		||||
            return error("不在营业时间内,不得骑行");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
 | 
			
		|||
import javax.annotation.Resource;
 | 
			
		||||
import java.io.UnsupportedEncodingException;
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 接收硬件参数
 | 
			
		||||
| 
						 | 
				
			
			@ -121,11 +122,11 @@ public class ReceiveController {
 | 
			
		|||
                        BigDecimal lat = new BigDecimal(value.getLat());
 | 
			
		||||
                        log.info("WGS84经纬度:" + lon + "---" + lat);
 | 
			
		||||
                        double[] doubles = GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
 | 
			
		||||
                        lon = new BigDecimal(doubles[0]);
 | 
			
		||||
                        lat = new BigDecimal(doubles[1]);
 | 
			
		||||
                        lat = new BigDecimal(doubles[0]).setScale(4, RoundingMode.HALF_UP);
 | 
			
		||||
                        lon = new BigDecimal(doubles[1]).setScale(4, RoundingMode.HALF_UP);
 | 
			
		||||
                        log.info("转换后的GCJ02经纬度:" + lon + "---" + lat);
 | 
			
		||||
                        device.setLatitude(lon.toString());
 | 
			
		||||
                        device.setLongitude(lat.toString());
 | 
			
		||||
                        device.setLatitude(lat.toString());
 | 
			
		||||
                        device.setLongitude(lon.toString());
 | 
			
		||||
                        Integer bat = value.getBat();
 | 
			
		||||
                        BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10));
 | 
			
		||||
                        log.info("保存电压:" + divide);
 | 
			
		||||
| 
						 | 
				
			
			@ -165,13 +166,14 @@ public class ReceiveController {
 | 
			
		|||
                                    log.info("超出营运区发送断电命令:" +logEntry.getDevName());
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            /** TODO 4.行程线路添加,更新订单中的trip_route字段 */
 | 
			
		||||
                            /** 4.行程线路添加,更新订单中的trip_route字段 */
 | 
			
		||||
                            Integer status = value.getStatus();
 | 
			
		||||
                            if(status == 1){//上电运行
 | 
			
		||||
                                log.info("上电运行:" +logEntry.getDevName());
 | 
			
		||||
                                if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
 | 
			
		||||
                                    //获取当前正在骑行中的订单
 | 
			
		||||
                                    EtOrder etOrder = etOrderService.getCurrentOrder(device.getSn());
 | 
			
		||||
                                    if(ObjectUtil.isNotNull(etOrder)){
 | 
			
		||||
                                        JSONArray jsonArray;
 | 
			
		||||
                                        if(StrUtil.isNotBlank(etOrder.getTripRouteStr())){
 | 
			
		||||
                                            jsonArray = JSON.parseArray(etOrder.getTripRouteStr());
 | 
			
		||||
| 
						 | 
				
			
			@ -181,8 +183,20 @@ public class ReceiveController {
 | 
			
		|||
                                        JSONArray newPoint = new JSONArray();
 | 
			
		||||
                                        newPoint.add(lon);
 | 
			
		||||
                                        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());
 | 
			
		||||
| 
						 | 
				
			
			@ -197,6 +211,7 @@ public class ReceiveController {
 | 
			
		|||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            /** 5.低于电量(%)不得骑行,声音播报 */
 | 
			
		||||
                            if(electricQuantity <= model.getLowBatteryReminder()){
 | 
			
		||||
                                //发送低电量播报指令
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,7 @@ public class CommonUtil {
 | 
			
		|||
            log.info("【根据定位获取地址】address=:【{}】",result);
 | 
			
		||||
            return address;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error("geocode regeo", e);
 | 
			
		||||
            log.error("【根据定位获取地址】转换地址报错", e);
 | 
			
		||||
        }
 | 
			
		||||
        return address;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -215,6 +215,11 @@ public interface IAsDeviceService extends IService<AsDevice>
 | 
			
		|||
     */
 | 
			
		||||
    Boolean isOperatingTime(String sn);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据运营区id获取所有车辆
 | 
			
		||||
     */
 | 
			
		||||
    List<AsDevice> allVehicleByArea(Long areaId);
 | 
			
		||||
 | 
			
		||||
//    /**
 | 
			
		||||
//     * 是否靠近运营区边界
 | 
			
		||||
//     */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -145,6 +145,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
 | 
			
		|||
            asDevice.setModel(model.getModel());
 | 
			
		||||
        }
 | 
			
		||||
        asDevice.setLocation(CommonUtil.getAddressByGeo(asDevice.getLongitude() + ","+asDevice.getLatitude()));
 | 
			
		||||
        asDevice.setRemainingMileage(CommonUtil.getRemainingMileage(asDevice.getVoltage(),model.getFullVoltage(),model.getLowVoltage(),model.getFullEndurance()));
 | 
			
		||||
        //正在进行中的订单
 | 
			
		||||
        EtOrder order = new EtOrder();
 | 
			
		||||
        order.setType(ServiceConstants.ORDER_TYPE_RIDING);
 | 
			
		||||
| 
						 | 
				
			
			@ -401,13 +402,6 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
 | 
			
		|||
        Boolean execute = transactionTemplate.execute(e -> {
 | 
			
		||||
            /** 2.发送命令*/
 | 
			
		||||
            sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN,"编号开锁");
 | 
			
		||||
            //间隔1秒
 | 
			
		||||
//            try {
 | 
			
		||||
//                Thread.sleep(1000);
 | 
			
		||||
//            } catch (InterruptedException ex) {
 | 
			
		||||
//                ex.printStackTrace();
 | 
			
		||||
//            }
 | 
			
		||||
//            sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY0,"编号开锁播报");
 | 
			
		||||
            /** 3.更新车辆状态*/
 | 
			
		||||
            asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
 | 
			
		||||
            asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_USING);
 | 
			
		||||
| 
						 | 
				
			
			@ -1089,12 +1083,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
 | 
			
		|||
                Integer end = intervalRule.getEnd();
 | 
			
		||||
                Integer unit = intervalRule.getEachUnit();
 | 
			
		||||
                BigDecimal fee = intervalRule.getFee();
 | 
			
		||||
                log.info("骑行时长---duration: " + duration + ", start: " + start + ", end: " + end + ", unit: " + unit + ", fee: " + fee);
 | 
			
		||||
                // 判断duration是否在当前区间内
 | 
			
		||||
                if (duration >= start && duration < end) {
 | 
			
		||||
                if (duration > start && duration <= end) {
 | 
			
		||||
                    // duration位于当前区间[start, end]内
 | 
			
		||||
                    System.out.println("费用为: " + fee + "元/每" + unit + formatUnit(rentalUnit));
 | 
			
		||||
                    ridingFee = new BigDecimal(fee.toString()).multiply(new BigDecimal(duration / unit));
 | 
			
		||||
                } else if (duration == end && intervalRule.getEnd() != 9999) {
 | 
			
		||||
                    log.info("不在区间内--骑行时长---duration: " + duration + ", start: " + start + ", end: " + end + ", unit: " + unit + ", fee: " + fee);
 | 
			
		||||
                    // 特殊处理结束边界为具体值的情况,避免与默认无限大区间混淆
 | 
			
		||||
                    System.out.println("达到区间的上限,但不落入下一个区间,费用为: " + fee + "元/每" + unit + formatUnit(rentalUnit));
 | 
			
		||||
                    throw new ServiceException("达到区间的上限,但不落入下一个区间,费用为: " + fee + "元/每" + unit + formatUnit(rentalUnit));
 | 
			
		||||
| 
						 | 
				
			
			@ -1284,6 +1280,17 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
 | 
			
		|||
        return Boolean.TRUE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取所有车辆
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AsDevice> allVehicleByArea(Long areaId) {
 | 
			
		||||
        QueryWrapper<AsDevice> wrapper = new QueryWrapper<>();
 | 
			
		||||
        wrapper.eq("area_id",areaId);
 | 
			
		||||
        List<AsDevice> asDevices = asDeviceMapper.selectList(wrapper);
 | 
			
		||||
        return asDevices;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断是否靠近边界
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,7 @@ import com.ruoyi.common.utils.http.HttpUtils;
 | 
			
		|||
import com.ruoyi.common.utils.onenet.Token;
 | 
			
		||||
import com.ruoyi.system.domain.*;
 | 
			
		||||
import com.ruoyi.system.domain.vo.AttachVo;
 | 
			
		||||
import com.ruoyi.system.mapper.AsUserMapper;
 | 
			
		||||
import com.ruoyi.system.mapper.SysUserMapper;
 | 
			
		||||
import com.ruoyi.system.service.*;
 | 
			
		||||
import com.wechat.pay.java.core.notification.Notification;
 | 
			
		||||
| 
						 | 
				
			
			@ -90,13 +91,15 @@ public class CallbackServiceImpl implements CallbackService {
 | 
			
		|||
    @Resource
 | 
			
		||||
    private SysUserMapper userMapper;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    private AsUserMapper asUserMapper;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 微信支付回调
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional
 | 
			
		||||
    @SneakyThrows
 | 
			
		||||
    public void weChat(HttpServletRequest request) {
 | 
			
		||||
        String body = HttpUtils.getBody(request);
 | 
			
		||||
        logger.info("【微信支付回调】接收对象 : " + JSON.toJSONString(body));
 | 
			
		||||
| 
						 | 
				
			
			@ -116,13 +119,11 @@ public class CallbackServiceImpl implements CallbackService {
 | 
			
		|||
                EtOrder order = orderService.selectEtOrderByOutTradeNo(outTradeNo);
 | 
			
		||||
                logger.info("【微信支付回调】订单信息 : " + JSON.toJSONString(order));
 | 
			
		||||
 | 
			
		||||
                AsUser asUser = userService.selectUserById(order.getUserId());
 | 
			
		||||
                AsUser asUser = asUserMapper.selectUserById(order.getUserId());
 | 
			
		||||
                /** 支付回调逻辑  1. 处理预约还是开锁  电压 */
 | 
			
		||||
                AsDevice asDevice = null;
 | 
			
		||||
                if(StrUtil.isNotBlank(order.getSn())){
 | 
			
		||||
                    asDevice = asDeviceService.selectAsDeviceBySn(order.getSn());
 | 
			
		||||
                }else{
 | 
			
		||||
                    throw new ServiceException("设备sn不存在"+order.getSn());
 | 
			
		||||
                }
 | 
			
		||||
                //先判断是骑行订单还是押金,如果是骑行订单
 | 
			
		||||
                // 还要区分是取消预约支付
 | 
			
		||||
| 
						 | 
				
			
			@ -270,8 +271,6 @@ public class CallbackServiceImpl implements CallbackService {
 | 
			
		|||
                    logger.error("【微信支付回调】更新用户押金失败");
 | 
			
		||||
                    throw new ServiceException("【微信支付回调】更新用户押金失败");
 | 
			
		||||
                }
 | 
			
		||||
                // 调用任务调度方法处理分账  一分钟后执行
 | 
			
		||||
//                paymentService.scheduleProfitSharing(outTradeNo);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user