Pu Zhibing
2024-10-22 8019eb016f806c1166223b1e2f08c1f9d7a96117
Merge remote-tracking branch 'origin/master'
3个文件已修改
185 ■■■■■ 已修改文件
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java 174 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TShoppingOrderServiceImpl.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TShoppingOrderMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -651,116 +651,10 @@
        
        log.error(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------" + platformStartCharging.toString());
        sendMessageClient.platformStartCharging(platformStartCharging);
        //异步线程检测远程启动的应答结果。如果失败,则需要全额退款
        Long id = chargingOrder.getId();
        //执行5分钟的定时任务检测
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(()->{
            if(timingDetection(id)){
                scheduler.shutdown();
            }
        }, 5, 1, TimeUnit.SECONDS);
        return AjaxResult.success();
    }
    
    /**
     * 定时检测mongodb数据库数据
     * @param id
     * @return
     */
    public boolean timingDetection(Long id){
        TChargingOrder chargingOrder = this.getById(id);
        if(chargingOrder.getStatus() != 2){
            return true;
        }
        String code = chargingOrder.getCode();
        String key = "AQJC_" + chargingOrder.getChargingGunId();
        //获取安全校验
        com.ruoyi.integration.api.model.SecurityDetection securityDetection = securityDetectionClient.getSecurityDetection(chargingOrder.getCode()).getData();
        if(null != securityDetection){
            PreChargeCheck preChargeCheck1 =  redisService.getCacheObject("AQJC_" + chargingOrder.getChargingGunId());
            if(null != preChargeCheck1){
                preChargeCheck1.setElectronicLockLock(true);
                preChargeCheck1.setInsulationTesting(true);
                preChargeCheck1.setSecureConnectionDetection(securityDetection.getSecure_connection() == 1);
                preChargeCheck1.setStartupSuccess(1);
                redisService.setCacheObject("AQJC_" + chargingOrder.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS);
            }
        }
        List<PlatformStartChargingReply> data = platformStartChargingReplyClient.getPlatformStartChargingReply(code).getData();
        if(null == data){
            return false;
        }
        log.error(code + ":-------------------开始检查调起充电结果-------------------" + data.toString());
        if(data.size() != 0){
            PlatformStartChargingReply platformStartChargingReply = data.get(1);
            Integer startup_result = platformStartChargingReply.getStartup_result();
            Integer failure_cause = platformStartChargingReply.getFailure_cause();
            Integer counter = counter_map.get(code);
            PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key);
            //5分钟内还未插枪则取消充电,退回金额。
            if(failure_cause == 5 && (null == counter || counter < 300)){
                counter = (null == counter ? 0 : counter) + 1;
                counter_map.put(code, counter);
                //启动失败
                preChargeCheck1.setStartupSuccess(3);
                preChargeCheck1.setFailureCause(failure_cause);
                redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
                return false;
            }
            //清除计时器中的无效数据
            counter_map.remove(code);
            TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code));
            if(0 == startup_result){
                //启动失败
                preChargeCheck1.setStartupSuccess(3);
                preChargeCheck1.setFailureCause(failure_cause);
                //启动失败后取消订单,退款操作
                refund(code);
                order.setStatus(-1);
                order.setEndMode(0);
            }else{
                //启动成功
                preChargeCheck1.setStartupSuccess(2);
                order.setStatus(3);
                order.setStartTime(LocalDateTime.now());
            }
            this.updateById(order);
            redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
            return true;
        }else{
            Integer counter = boot_failed_map.get(code);
            log.error(code + ":-------------------未上传开启充电结果-------------------" + counter);
            PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key);
            //5分钟内未启动成功,退回金额。
            if(null == counter || counter < 300){
                counter = (null == counter ? 0 : counter) + 1;
                boot_failed_map.put(code, counter);
                //启动失败
                preChargeCheck1.setStartupSuccess(3);
                preChargeCheck1.setFailureCause(0);
                redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
                return false;
            }
            //清除计时器中的无效数据
            boot_failed_map.remove(code);
            TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code));
            //启动失败
            preChargeCheck1.setStartupSuccess(3);
            preChargeCheck1.setFailureCause(0);
            //启动失败后取消订单,退款操作
            refund(code);
            order.setStatus(-1);
            order.setEndMode(0);
            this.updateById(order);
            redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
            return true;
        }
    }
    
    
    /**
@@ -982,70 +876,6 @@
            sendMessageClient.platformStopCharging(platformStopCharging);
            log.error(code1 + ":-------------------远程停止充电请求-------------------");
            log.error(platformStopCharging.toString());
            //开始查询停机应答,成功后开始计费费用
            boolean stop_status = false;
            for (int i = 0; i < 60; i++) {
                TChargingOrder chargingOrder1 = this.getById(id);
                if(chargingOrder1.getStatus() != 3){
                    stop_status = true;
                    break;
                }
                GetPlatformStopChargingReply query = new GetPlatformStopChargingReply();
                query.setCharging_gun_code(chargingGun.getCode());
                query.setCharging_pile_code(chargingPile.getCode());
                //将时间转换成UTC时间后查询数据(mongodb存储时间以UTC格式存储)
                ZoneId zoneId = ZoneId.systemDefault();
                ZonedDateTime zonedDateTime = ZonedDateTime.of(chargingOrder.getEndTime(), zoneId);
                ZonedDateTime endTime = zonedDateTime.withZoneSameInstant(ZoneId.of("UTC"));
                query.setEnd_time(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                PlatformStopChargingReply reply = platformStopChargingReplyClient.getPlatformStopChargingReply(query).getData();
                log.error(code1 + ":-------------------查询远程停止充电应答-------------------");
                if(null == reply){
                    log.error(code1 + ":-------------------远程停止充电应答无数据-------------------");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    continue;
                }
                log.error(reply.toString());
                if(0 == reply.getStop_result()){
                    String failure_cause = "";
                    switch (reply.getFailure_cause()){
                        case 0:
                            failure_cause = "无";
                            break;
                        case 1:
                            failure_cause = "设备编号不匹配";
                            break;
                        case 2:
                            failure_cause = "枪未处于充电状态";
                            break;
                        case 3:
                            failure_cause = "其他";
                            break;
                    }
                    log.error(code1 + ":停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }else{
                    log.error(code1 + ":-------------------远程停止充电请求成功-------------------");
                    stop_status = true;
                    break;
                }
            }
            if(stop_status){
                chargingOrder.setEndMode(1);
                this.updateById(chargingOrder);
            }else{
                log.error(code1 + ":-------------------远程停止充电应答最终失败-------------------");
            }
        });
        return AjaxResult.success();
    }
@@ -1883,7 +1713,7 @@
            //服务费折扣
            discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount())));
            periodServicePrice_total = periodServicePrice_total.multiply(chargingOrder.getVipDiscount());
            TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
            if(null != appUser.getVipId()){
                //判断会员是否还有充电优惠次数
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TShoppingOrderServiceImpl.java
@@ -153,7 +153,9 @@
                        discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount());
                        stringBuilder1.append("会员抵扣").append("+");
                    }
                    stringBuilder1.deleteCharAt(stringBuilder1.length()-1);
                    if (stringBuilder1.length()>0){
                        stringBuilder1.deleteCharAt(stringBuilder1.length()-1);
                    }
                    tActivityStatisticslVO.setType(stringBuilder1.toString());
                    tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime());
                    break;
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TShoppingOrderMapper.xml
@@ -107,13 +107,13 @@
                and t2.code  LIKE CONCAT('%',#{req.code},'%')
            </if>
            <if test="req.type != null and req.type != '' and req.type == 1">
                and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
                and (t2.coupon_discount_amount  > 0)
            </if>
            <if test="req.type != null and req.type != '' and req.type == 2">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0
                and ( t2.vip_discount_amount  > 0)
            </if>
            <if test="req.type == null ">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0 and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
                and (t2.vip_discount_amount  > 0 or t2.coupon_discount_amount  > 0)
            </if>
            <if test="null != req.userIds and req.userIds.size()>0" >
                and t2.app_user_id in
@@ -124,7 +124,6 @@
            <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                AND (t2.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
            </if>
            and t2.refund_status !=2
            and t2.payment_status =2
            AND t2.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </if>