package com.kym.service.platform.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.mail.MailUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.kym.common.cache.PlatformCache;
import com.kym.common.utils.CommUtil;
import com.kym.common.utils.PlatformAesUtil;
import com.kym.common.utils.PlatformConvertUtil;
import com.kym.entity.admin.ConnectorInfo;
import com.kym.entity.admin.EquipmentInfo;
import com.kym.entity.admin.MonitorLog;
import com.kym.entity.common.RedisKeys;
import com.kym.entity.miniapp.Account;
import com.kym.entity.miniapp.ChargeOrder;
import com.kym.entity.miniapp.WalletDetail;
import com.kym.entity.platform.PlatformCheckChargeOrders;
import com.kym.entity.platform.PlatformConnectorStatusInfo;
import com.kym.service.admin.ConnectorInfoService;
import com.kym.service.admin.EquipmentInfoService;
import com.kym.service.admin.MonitorLogService;
import com.kym.service.cache.KymCache;
import com.kym.service.factory.DiscountStrategyFactory;
import com.kym.service.miniapp.*;
import com.kym.service.platform.PlatformNotifyService;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author skyline
 * 接收处理互联互通平台推送信息
 */

@Service
public class PlatformNotifyServiceImpl implements PlatformNotifyService {
    private static final Logger LOGGER = LoggerFactory.getLogger(PlatformNotifyServiceImpl.class);
    public final StringRedisTemplate redisTemplate;
    private final ChargeOrderService chargeOrderService;
    private final ChargeService chargeService;
    private final AccountService accountService;
    private final WalletDetailService walletDetailService;
    private final MonitorLogService monitorLogService;
    private final EquipmentInfoService equipmentInfoService;
    private final ConnectorInfoService connectorInfoService;
    private final UserStationService userStationService;

    @Value("${kym.notify-email}")
    private String notifyEmail;

    @Value("${kym.notify-email-switch}")
    private boolean notifyEmailSwitch;

    public PlatformNotifyServiceImpl(ChargeOrderService chargeOrderService, ChargeService chargeService,
                                     AccountService accountService, WalletDetailService walletDetailService,
                                     MonitorLogService monitorLogService, EquipmentInfoService equipmentInfoService,
                                     ConnectorInfoService connectorInfoService, StringRedisTemplate redisTemplate,
                                     UserStationService userStationService) {
        this.chargeOrderService = chargeOrderService;
        this.chargeService = chargeService;
        this.accountService = accountService;
        this.walletDetailService = walletDetailService;
        this.monitorLogService = monitorLogService;
        this.equipmentInfoService = equipmentInfoService;
        this.connectorInfoService = connectorInfoService;
        this.redisTemplate = redisTemplate;
        this.userStationService = userStationService;
    }

    @PostConstruct
    void init() {
        KymCache.INSTANCE.putConnectorId2Status(connectorInfoService.list().stream().collect(Collectors.toMap(ConnectorInfo::getConnectorId, ConnectorInfo::getStatus)));
    }

    @Override
    public String queryToken(String platformName, JSONObject json) {
        var data = PlatformAesUtil.signValidation(platformName, json);
        LOGGER.info("【{}互联互通平台推送】收到请求快与慢Token:{},解密数据：{}", platformName, json, data);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        // 查询缓存,存在则返回值和过期时间，不存在则重新生成并缓存
        var token = redisTemplate.opsForValue().get(RedisKeys.PLATFORM_TOKEN + platformName);
        // 过期时间
        var ttl = redisTemplate.getExpire(RedisKeys.PLATFORM_TOKEN + platformName);
        if (CommUtil.isEmptyOrNull(token)) {
            token = IdUtil.simpleUUID();
            ttl = 7 * 24 * 3600L;
            redisTemplate.opsForValue().set(RedisKeys.PLATFORM_TOKEN + platformName, token, ttl, TimeUnit.SECONDS);
        }

        var params = """
                {
                    "OperatorID":"%s",
                    "SuccStat":%d,
                    "AccessToken":"%s",
                    "TokenAvailableTime":%d,
                    "FailReason":%d
                }
                """.formatted(platform.getOperatorId(), 0, token, ttl, 0);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }

    /**
     * EN+ 充电站设备状态变化推送
     *
     * @param platformName
     * @param json
     * @return
     */
    @Override
    @DS("db-admin")
    public String handleNotificationStationStatus(String platformName, JSONObject json) {
        var data = PlatformAesUtil.signValidation(platformName, json);
        LOGGER.info("【{}互联互通平台推送】收到充电桩设备状态变化推送:{},解密数据：{}", platformName, json, data);
        // 更新数据库，存入redis,发送邮件通知
        var connectorStatusInfo = JSONObject.parseObject(data).getJSONObject("ConnectorStatusInfo").toJavaObject(PlatformConnectorStatusInfo.class);
        var connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorStatusInfo.getConnectorId());
        var equipmentId = connectorId.substring(0, 16);

        equipmentInfoService.lambdaUpdate().eq(EquipmentInfo::getEquipmentId, equipmentId).set(EquipmentInfo::getServiceStatus, connectorStatusInfo.getStatus()).update();

        connectorInfoService.lambdaUpdate().eq(ConnectorInfo::getConnectorId, connectorId).set(ConnectorInfo::getStatus, connectorStatusInfo.getStatus()).update();


        var connectorStatus = connectorStatusInfo.getStatus();

        if (connectorStatus == 0) {
            LOGGER.info("充电桩设备离线：{}", connectorStatusInfo.getConnectorId());
            // 如果设备离线，则存入redis
            var monitorLog = new MonitorLog().setStationId(KymCache.INSTANCE.getStationIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId())).setSn(connectorStatusInfo.getConnectorId()).setOfflineTime(LocalDateTime.now()).setType(2).setOfflineStatus(connectorStatusInfo.getStatus());
            monitorLogService.save(monitorLog);

            // 离线设备放入队列，60分钟之后如果还未恢复则放入长时间离线设备集合中并发送提醒，上线后发送提醒
            redisTemplate.opsForZSet().add(RedisKeys.OFFLINE, connectorStatusInfo.getConnectorId(), System.currentTimeMillis() + 60 * 60 * 1000);
        } else {
            // 先删除离线设备队列的记录,再删除离线超时队列中的记录
            var isDelete = redisTemplate.opsForZSet().remove(RedisKeys.OFFLINE, connectorStatusInfo.getConnectorId());
            var exist = redisTemplate.opsForSet().remove(RedisKeys.OFFLINE_EXPIRED, connectorStatusInfo.getConnectorId());
            if ((isDelete != null && isDelete > 0) || (exist != null && exist > 0)) {
                // 更新设备监控表
                monitorLogService.lambdaUpdate().eq(MonitorLog::getSn, connectorStatusInfo.getConnectorId()).eq(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_未恢复) // 未恢复的记录
                        .set(MonitorLog::getRecoverTime, LocalDateTime.now()).set(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_已恢复) // 设置为已恢复
                        .update();
            }
            if (exist != null && exist > 0 && notifyEmailSwitch) {
                MailUtil.send(notifyEmail, "【设备上线通知】", "站点:%s,设备%s恢复上线".formatted(KymCache.INSTANCE.getStationNameByConnectorId(connectorStatusInfo.getConnectorId()), KymCache.INSTANCE.getShortIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId())), false);
            }
        }

        // 设备状态变为空闲，校验是否有预约订单，有则清除预约订单数据。
        if (connectorStatus == EquipmentInfo.SERVICE_STATUS_空闲 && KymCache.INSTANCE.getConnectorStatus(connectorId) != EquipmentInfo.SERVICE_STATUS_空闲) {
            LOGGER.info("设备:{}状态转为空闲，清除设备预约数据...", connectorId);
            chargeService.cancelBookingByConnector(connectorId);
        }
        KymCache.INSTANCE.putConnectorId2Status(Map.of(connectorId, connectorStatus));

        var params = """
                {
                    "Status":%d
                }
                """.formatted(0);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }


    /**
     * EN+ 推送启动充电结果
     *
     * @param platformName
     * @param json
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    @DS("db-miniapp")
    public String handleNotificationStartChargeResult(String platformName, JSONObject json) {
        var data = PlatformAesUtil.signValidation(platformName, json);
        LOGGER.info("【{}互联互通平台推送】收到启动充电结果推送：{}，解密数据：{}", platformName, json, data);
        var obj = JSONObject.parseObject(data);
        var startChargeSeq = obj.getString("StartChargeSeq");
        var startChargeSeqStat = obj.getIntValue("StartChargeSeqStat");
        var connectorId = PlatformConvertUtil.parse2LocalConnectorId(obj.getString("ConnectorID"));
        var startTime = LocalDateTime.parse(obj.getString("StartTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        // 更新订单状态
        UpdateWrapper<ChargeOrder> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("connector_id", connectorId);
        updateWrapper.eq("start_charge_seq", startChargeSeq);
        updateWrapper.set("order_status", startChargeSeqStat == ChargeOrder.CHARGE_STATUS_已结束 ? ChargeOrder.ORDER_STATUS_失败 : ChargeOrder.ORDER_STATUS_未知);
        updateWrapper.set("charge_status", startChargeSeqStat);
        updateWrapper.set("start_time", startTime);
        chargeOrderService.update(updateWrapper);
        var params = """
                {
                    "StartChargeSeq":"%s",
                    "SuccStat":%d,
                    "FailReason":%d
                }
                """.formatted(startChargeSeq, 0, 0);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }

    /**
     * 推送充电状态，1分钟推送一次
     *
     * @param platformName
     * @param json
     * @return
     * @see com.kym.miniapp.jobs.EquipmentChargeStatusJob#executeMpUserRelationJob()
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String handleNotificationEquipChargeStatus(String platformName, JSONObject json) {
        var dataStr = PlatformAesUtil.signValidation(platformName, json);
        var data = JSONObject.parseObject(dataStr);
        LOGGER.info("【{}互联互通平台推送】 ：{}，解密数据：{}", platformName, json, data);
        var startChargeSeq = data.getString("StartChargeSeq");
        var chargeOrder = chargeOrderService.getChargingOrderByStartChargeSeq(startChargeSeq);
        // 如果订单已结束，则不更新订单信息
        if (chargeOrder.getOrderStatus() == ChargeOrder.ORDER_STATUS_未知) {
            // 更新订单信息
            chargeOrder.setSoc(data.getDoubleValue("Soc"));
            chargeOrder.setTotalPower(data.getDoubleValue("TotalPower"));
            chargeOrder.setTotalMoney((data.getBigDecimal("TotalMoney").multiply(BigDecimal.valueOf(100))).intValue());
            chargeOrder.setElecMoney((data.getBigDecimal("ElecMoney").multiply(BigDecimal.valueOf(100))).intValue());
            chargeOrder.setServiceMoney((data.getBigDecimal("SeviceMoney").multiply(BigDecimal.valueOf(100))).intValue()); // 这里文档service单词错误，按文档填写
            chargeOrder.setSumPeriod(data.getIntValue("SumPeriod"));
            chargeOrder.setChargeDetail(data.getString("ChargeDetails"));
            chargeOrder.setChargeStatus(data.getIntValue("StartChargeSeqStat"));
            // 优化点 EN+一分钟推送一次，同时充电人数多的时候写入数据库过于频繁
            // redis保存（更新）订单信息
            redisTemplate.opsForHash().put(RedisKeys.CHARGE_ORDER_EQUIP_CHARGE_STATUS, startChargeSeq, JSONObject.toJSONString(chargeOrder));
            // 将数据库写入操作放到定时任务中
            // chargeOrderService.updateById(chargeOrder);
        }
        var params = """
                {
                    "StartChargeSeq":"%s",
                    "SuccStat":%d
                }
                """.formatted(startChargeSeq, 0);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }

    /**
     * 推送停止充电结果
     *
     * @param platformName
     * @param json
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String handleNotificationStopChargeResult(String platformName, JSONObject json) {
        var dataStr = PlatformAesUtil.signValidation(platformName, json);
        var data = JSONObject.parseObject(dataStr);
        LOGGER.info("【{}互联互通平台推送】收到停止充电结果推送：{}，解密数据：{}", platformName, json, data);
        var startChargeSeq = data.getString("StartChargeSeq");
        var chargeOrder = chargeOrderService.getChargingOrderByStartChargeSeq(startChargeSeq);
        // 订单已结算或已到终态，跳过处理，防止覆盖已结算数据
        if (chargeOrder == null || chargeOrder.getOrderStatus() != ChargeOrder.ORDER_STATUS_未知) {
            LOGGER.info("【{}互联互通平台推送】停止充电结果：订单{}已到终态，跳过处理", platformName, startChargeSeq);
            var params = """
                    {
                        "StartChargeSeq":"%s",
                        "SuccStat":%d,
                        "FailReason":%d
                    }
                    """.formatted(startChargeSeq, 0, 0);
            var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
            return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
        }
        if (data.containsKey("SuccStat") && data.getIntValue("SuccStat") == 0) {
            chargeOrder.setChargeStatus(data.getIntValue("StartChargeSeqStat"));
            chargeOrderService.updateById(chargeOrder);
            // 删除Redis缓存，防止定时任务用脏数据覆盖DB
            redisTemplate.opsForHash().delete(RedisKeys.CHARGE_ORDER_EQUIP_CHARGE_STATUS, startChargeSeq);
        }
        var params = """
                {
                    "StartChargeSeq":"%s",
                    "SuccStat":%d,
                    "FailReason":%d
                }
                """.formatted(startChargeSeq, 0, 0);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }

    /**
     * 推送充电订单信息（订单结算）
     *
     * @param platformName
     * @param json
     * @return
     */
    @Override
    @DSTransactional(rollbackFor = Exception.class)
    public String handleNotificationChargeOrderInfo(String platformName, JSONObject json) {
        var dataStr = PlatformAesUtil.signValidation(platformName, json);
        var data = JSONObject.parseObject(dataStr);
        LOGGER.info("【{}互联互通平台推送】收到充电订单信息推送：{}，解密数据：{}", platformName, json, data);
        var startChargeSeq = data.getString("StartChargeSeq");
        var chargeOrder = chargeOrderService.getChargingOrderByStartChargeSeq(startChargeSeq);

        // 账户
        var account = accountService.getAccountByUserId(chargeOrder.getUserId());

        // EN+平台推送重试策略是当天失败第二天再推送一次，仅此一次。EN+订单页面可以多次手动推送，所以这里要先判断订单状态，避免重复处理。
        if (chargeOrder.getChargeStatus() != ChargeOrder.CHARGE_STATUS_已结束 || chargeOrder.getOrderStatus() != ChargeOrder.ORDER_STATUS_成功) {
            // 更新订单信息
            chargeOrder.setStartTime(LocalDateTime.parse(data.getString("StartTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                    .setEndTime(LocalDateTime.parse(data.getString("EndTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                    .setTotalPower(data.getDoubleValue("TotalPower"))
                    .setElecMoney((int) Math.round(data.getDouble("TotalElecMoney") * 100))
                    .setServiceMoney((int) Math.round(data.getDoubleValue("TotalSeviceMoney") * 100)) // 这里文档service单词错误，按文档填写
                    .setTotalMoney((int) Math.round(data.getDoubleValue("TotalMoney") * 100))
                    .setStopReason(data.getIntValue("StopReason"))
                    .setSumPeriod(data.getIntValue("SumPeriod"))
                    .setChargeDetail(data.getString("ChargeDetails"))
                    // 实付金额初始化为订单总金额
                    .setPayAmount(chargeOrder.getTotalMoney())
                    // 强制更新订单状态，防止订单手动结算重复扣费
                    .setChargeStatus(ChargeOrder.CHARGE_STATUS_已结束)
                    .setOrderStatus(ChargeOrder.ORDER_STATUS_成功);

            // 结束时间
            var endTime = LocalDateTime.parse(data.getString("EndTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

            // 处理充值权益优惠逻辑/优惠券优惠逻辑/账户优惠金额记录处理逻辑（涉及退款扣减优惠，在NoDiscountHandle中处理）
            DiscountStrategyFactory.getDiscountStrategy(chargeOrder.getDiscountType()).computeDiscount(chargeOrder, account);

            // 更新订单优惠金额
            chargeOrderService.updateById(chargeOrder);

            // 扣费等资金操作
            deductions(chargeOrder, account, endTime);
            // redis删除缓存订单信息（订单结算完调用）
            redisTemplate.opsForHash().delete(RedisKeys.CHARGE_ORDER_EQUIP_CHARGE_STATUS, startChargeSeq);

            // 更新用户站点数据
            userStationService.updateUserStation(chargeOrder);
        }

        var params = """
                {
                    "StartChargeSeq":"%s",
                    "ConnectorID":"%s",
                    "ConfirmResult":%d
                }
                """.formatted(startChargeSeq, chargeOrder.getConnectorId(), 0);
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), params);
    }

    /**
     * 推送订单对账结果信息（订单对账）
     *
     * @param platformName
     * @param json
     */
    @Override
    public String handleCheckChargeOrders(String platformName, JSONObject json) {
        var dataStr = PlatformAesUtil.signValidation(platformName, json);
        var data = JSONObject.parseObject(dataStr, PlatformCheckChargeOrders.class);
        LOGGER.info("【{}互联互通平台推送】收到订单对账结果信息推送：{}，解密数据：{}", platformName, json, data);

        var startChargeSeqs = data.getCheckOrders().stream().map(PlatformCheckChargeOrders.PlatformCheckOrder::getStartChargeSeq).toList();
        AtomicInteger disputeCount = new AtomicInteger();
        var chargeOrdersMap = chargeOrderService.lambdaQuery().in(ChargeOrder::getStartChargeSeq, startChargeSeqs).list().stream().collect(Collectors.toMap(ChargeOrder::getStartChargeSeq, Function.identity()));
        // 循环和map中的chargeOrder进行对比，如果订单的totalPower或者totalMoney不一致，则记录该订单
        var res = data.getCheckOrders().stream().map(platformCheckOrder -> {
            var disputeOrder = new PlatformCheckChargeOrders.DisputeOrder()
                    .setStartChargeSeq(platformCheckOrder.getStartChargeSeq());

            var chargeOrder = chargeOrdersMap.get(platformCheckOrder.getStartChargeSeq());
            if (chargeOrder == null) {
                // 交易不存在
                disputeCount.getAndIncrement();
                disputeOrder.setDisputeReason(PlatformCheckChargeOrders.DisputeOrder.DISPUTE_REASON_TRANSACTION_NOT_EXIST);
            } else {
                if (!Objects.equals(chargeOrder.getTotalMoney(), platformCheckOrder.getTotalOrderMoney() * 100)) {
                    // 交易金额错误
                    disputeCount.getAndIncrement();
                    disputeOrder.setTotalMoney(Math.round(chargeOrder.getTotalMoney() / 100.0));
                    disputeOrder.setTotalPower(chargeOrder.getTotalPower());
                    disputeOrder.setDisputeReason(PlatformCheckChargeOrders.DisputeOrder.DISPUTE_REASON_TRANSACTION_MONEY_ERROR);
                }
                if (!Objects.equals(chargeOrder.getTotalPower(), platformCheckOrder.getTotalOrderPower())) {
                    // 交易电量错误
                    disputeCount.getAndIncrement();
                    disputeOrder.setTotalMoney(Math.round(chargeOrder.getTotalMoney() / 100.0));
                    disputeOrder.setTotalPower(chargeOrder.getTotalPower());
                    disputeOrder.setDisputeReason(PlatformCheckChargeOrders.DisputeOrder.DISPUTE_REASON_TRANSACTION_POWER_ERROR);
                }
            }
            return disputeOrder;
        }).toList();

        var params = Map.of(
                "CheckOrderSeq", data.getCheckOrderSeq(),
                "StartTime", data.getStartTime(),
                "EndTime", data.getEndTime(),
                "TotalDisputeOrder", disputeCount.get(),
                "TotalDisputePower", res.stream().collect(Collectors.summarizingDouble(PlatformCheckChargeOrders.DisputeOrder::getTotalPower)),
                "TotalDisputeMoney", res.stream().collect(Collectors.summarizingDouble(PlatformCheckChargeOrders.DisputeOrder::getTotalMoney)),
                "DisputeOrders", JSONArray.parseArray(JSON.toJSONString(res))
        );
        var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
        return PlatformAesUtil.encrypt(platform.getUserDataSecret(), platform.getUserDataSecretIv(), JSON.toJSONString(params));
    }


    /**
     * 扣费等资金操作
     *
     * @param chargeOrder
     * @param account
     * @param endTime
     */
    private void deductions(ChargeOrder chargeOrder, Account account, LocalDateTime endTime) {
        // 订单成功
        chargeOrder.setOrderStatus(ChargeOrder.ORDER_STATUS_成功);
        // 充电结束
        chargeOrder.setChargeStatus(ChargeOrder.CHARGE_STATUS_已结束);
        chargeOrderService.updateById(chargeOrder);

        // 账户扣费
        account.setBalance(account.getBalance() - chargeOrder.getPayAmount());
        accountService.updateById(account);

        // 记录资金流水
        var walletDetail = new WalletDetail();
        walletDetail.setUserId(chargeOrder.getUserId());
        walletDetail.setOrderNo(chargeOrder.getStartChargeSeq());
        // 消费
        walletDetail.setType(WalletDetail.TYPE_消费);
        walletDetail.setAmount(chargeOrder.getPayAmount());
        walletDetail.setTransactionTime(endTime);
        // 已确认
        walletDetail.setStatus(WalletDetail.STATUS_已确认);
        walletDetailService.save(walletDetail);

    }
}
