package com.qnfhq.modules.c2c.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qnfhq.common.constant.Constant;
import com.qnfhq.common.exception.ErrorCode;
import com.qnfhq.common.page.PageData;
import com.qnfhq.common.redis.RedisUtils;
import com.qnfhq.common.service.impl.BaseServiceImpl;
import com.qnfhq.common.utils.MessageUtils;
import com.qnfhq.common.utils.Result;
import com.qnfhq.modules.c2c.dao.C2cAdDao;
import com.qnfhq.modules.c2c.dto.*;
import com.qnfhq.modules.c2c.entity.*;
import com.qnfhq.modules.c2c.enums.AdStatusEnum;
import com.qnfhq.modules.c2c.enums.DirectionEnum;
import com.qnfhq.modules.c2c.enums.MerchantStatusEnum;
import com.qnfhq.modules.c2c.service.*;
import cn.hutool.core.util.StrUtil;
import com.qnfhq.modules.user.entity.AppAssetEntity;
import com.qnfhq.modules.user.enums.AssetEnum;
import com.qnfhq.modules.user.service.AppAssetService;
import com.qnfhq.utils.OrderUtils;
import io.swagger.v3.oas.models.security.SecurityScheme;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * c2c商家广告
 *
 * @author yelz 30262728@qq.com
 * @since 1.0.0 2025-11-17
 */
@Slf4j
@Service
public class C2cAdServiceImpl extends BaseServiceImpl<C2cAdDao, C2cAdEntity> implements C2cAdService {

    @Resource
    private C2cMerchantService c2cMerchantService;

    @Resource
    private AppAssetService appAssetService;

    @Resource
    private RedisUtils redisUtils;

    @Resource
    private C2cPayWayService c2cPayWayService;

    @Resource
    private C2cLegalCoinService c2cLegalCoinService;

    @Resource
    private C2cAdDao c2cAdDao;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result createAd(C2cAdCreateDTO c2cAdDTO, long loginId) throws Exception {
        Result result = new Result();
        Integer direction = c2cAdDTO.getDirection();
        String symbol = c2cAdDTO.getSymbol().toLowerCase();//usdt小写
        String legalCoin = c2cAdDTO.getLegalCoin().toUpperCase();//法币大写
        Integer priceType = c2cAdDTO.getPriceType();

        BigDecimal price = c2cAdDTO.getPrice().setScale(2, RoundingMode.DOWN);
        //币的数量
        BigDecimal num = c2cAdDTO.getNum().setScale(8, RoundingMode.DOWN);
        BigDecimal minAmount = c2cAdDTO.getMinAmount();
        BigDecimal maxAmount = c2cAdDTO.getMaxAmount();
        String payway = c2cAdDTO.getPayway().trim();
        String remark = c2cAdDTO.getRemark();

        C2cMerchantEntity merchant = c2cMerchantService.getMerchantEntity(loginId);
        if(merchant==null) {
            return result.error(ErrorCode.MERCHANT_SHIMING_VERIFY, MessageUtils.message("merchant.complete.merchant.apply"));//请完成认证商家申请
        }
        if (!Objects.equals(merchant.getStatus(), MerchantStatusEnum.PASS.getCode())) {
            if (Objects.equals(merchant.getStatus(), MerchantStatusEnum.PENDING.getCode())){
                return result.error(MessageUtils.message("merchant.under.review"));//认证商家审批中
            } else if (Objects.equals(merchant.getStatus(), MerchantStatusEnum.LOCK.getCode())) {
                return result.error(MessageUtils.message("merchant.under.lock"));//认证商家锁定中
            } else {
                return result.error(MessageUtils.message("merchant.approval.reject"));//认证商家审批不通过
            }
        }

        //账户可用资金
        BigDecimal avaAmount = BigDecimal.ZERO;
        AppAssetEntity tAppAsset = new AppAssetEntity();
        tAppAsset.setSymbol(symbol);
        tAppAsset.setType(AssetEnum.PLATFORM_ASSETS.getCode());
        tAppAsset.setUserId(merchant.getUserId());
        List<AppAssetEntity> assetList = appAssetService.selectList(tAppAsset);
        AppAssetEntity ptAsset = null;
        if(assetList!=null && !assetList.isEmpty()) {
            ptAsset = (AppAssetEntity)assetList.get(0);
            avaAmount = ptAsset.getAvailable();
        }
        //卖出广告，用户平台资产要大于卖出数量
        if(DirectionEnum.SELL.getCode()==direction) {
            if(avaAmount.compareTo(num) == -1) {
                return result.error(MessageUtils.message("merchant.buyCount.greater.sellCount"));//平台可用资产必须大于卖出数量
            }
        }

        C2cAdEntity c2cAd = new C2cAdEntity();
        c2cAd.setAdNo("AD"+ OrderUtils.generateAdNum());
        c2cAd.setUserId(loginId);
        c2cAd.setUserName(merchant.getUserName());
        c2cAd.setMerchantId(merchant.getId());
        c2cAd.setDirection(direction);
        c2cAd.setLegalCoin(legalCoin);
        c2cAd.setSymbol(symbol);
        c2cAd.setNum(num);
        c2cAd.setAvailableNum(num);
        c2cAd.setPriceType(priceType);
        c2cAd.setPrice(price);
        c2cAd.setMinAmount(minAmount);
        c2cAd.setMaxAmount(maxAmount);
        c2cAd.setPayway(new StringBuilder(",").append(payway).append(",").toString());
        c2cAd.setRemark(remark);
        c2cAd.setStatus(AdStatusEnum.PASS.getCode());
        //成交量
//        c2cAd.setFinishNum(merchant.getFinishNum());
        //成单率
//        c2cAd.setFinishRate(merchant.getFinishRate());
        if(!insert(c2cAd)) {
            throw new Exception(MessageUtils.message("c2c.order.save.fail"));//保存广告失败
        }
        if (direction.intValue() == DirectionEnum.SELL.getCode().intValue()) {
            //卖出广告 冻结卖出数量的币
            if (appAssetService.frozeAssetByUserId(c2cAd.getUserId(), c2cAd.getSymbol(), c2cAd.getNum()) == 0) {
                throw new Exception(MessageUtils.message("seller.asset.freeze.fail"));//冻结卖家资产失败
            }
        }
        setAdCache(c2cAd);
        return result.ok(c2cAd.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result cancelAd(C2cAdEntity ad) throws Exception {
        Result result = new Result();
        ad.setStatus(AdStatusEnum.NOPASS.getCode());
        ad.setReason("商户取消广告");
        if(!updateById(ad)) {
            throw new Exception(MessageUtils.message("c2c.ad.cancel.fail"));//取消广告失败
        }

        if (ad.getDirection().intValue() == DirectionEnum.SELL.getCode().intValue()) {
            if (appAssetService.unblockAssetByUserId(ad.getUserId(), ad.getSymbol(), ad.getAvailableNum()) == 0) {
                throw new Exception(MessageUtils.message("c2c.user.occupied.asset.fail"));//用户资产解冻失败
            }
        }

        deleteAdCache(ad.getId(),ad.getPayway().replaceAll("^,|,$", ""),ad.getLegalCoin(),ad.getSymbol(),ad.getDirection());
        return result;
    }

    private String getAdHKey(Long c2cAdId) {
        return new StringBuilder("c2c_ad_h:").append(c2cAdId).toString();
    }
    private String getViewAdKey(Integer direction,String legalCoin,String symbol) {
        if(DirectionEnum.BUY.getCode().intValue() == direction.intValue()) {
            return new StringBuilder("c2c_ad_buy:").append(legalCoin).append(":").append(symbol).toString();
        } else {
            return new StringBuilder("c2c_ad_sell:").append(legalCoin).append(":").append(symbol).toString();
        }
    }
    private String getQuickAdKey(String zsetKey,String paywayId) {
        return new StringBuilder(zsetKey).append(":").append(paywayId).toString();
    }

    @Override
    public void deleteAdCache(Long c2cAdId,String payway,String legalCoin,String symbol,Integer direction) {
        //1 redis存储广告数据
        String adHKey = getAdHKey(c2cAdId);
        redisUtils.delete(adHKey);

//        //2 按价格排序，用于浏览广告
//        String zsetKey = getViewAdKey(direction, legalCoin, symbol);
//        redisUtils.removeZset(zsetKey, c2cAdId.toString());
//
//        //3 按支付方式、按最小数量排序，用于快捷交易 c2c_ad_payId_buy_cnyusdt
//        String[] paywayAr = payway.split(",");
//        for (String paywayId : paywayAr) {
//            redisUtils.removeZset(getQuickAdKey(zsetKey, paywayId), c2cAdId.toString());
//        }
    }

    @Override
    public void setAdCache(C2cAdEntity c2cAd) {
        //1 存储广告数据
        String adHKey = getAdHKey(c2cAd.getId());
        String payway = c2cAd.getPayway().replaceAll("^,|,$", "");
        Map<String, Object> adMap = MapUtil.of("adNo", c2cAd.getAdNo());
        adMap.put("userId", c2cAd.getUserId());
        adMap.put("adNo",c2cAd.getAdNo());
        adMap.put("userName", c2cAd.getUserName());
        adMap.put("merchantId",c2cAd.getMerchantId());
        adMap.put("direction", c2cAd.getDirection());
        adMap.put("legalCoin", c2cAd.getLegalCoin());
        adMap.put("symbol", c2cAd.getSymbol());
        adMap.put("payway", payway);
        adMap.put("total", c2cAd.getNum());
        //可用数量
        adMap.put("availableNum", c2cAd.getAvailableNum());
        adMap.put("price", c2cAd.getPrice());
        adMap.put("minAmount", c2cAd.getMinAmount());
        adMap.put("maxAmount", c2cAd.getMaxAmount());
        //成交量
//        adMap.put("finishNum", Convert.toInt(c2cAd.getFinishNum(),0));
        //成单率
//        adMap.put("finishRate",Convert.toStr(c2cAd.getFinishRate(),"0%"));
        adMap.put("status",c2cAd.getStatus());
        Random random = new Random();
        long randomHour = random.nextLong(24L)+24L; // 生成24到48之间的随机数
        redisUtils.hMSet(adHKey, adMap, randomHour*3600L);

        //2 按价格排序，用于浏览广告
//        String zsetKey = getViewAdKey(c2cAd.getDirection(), c2cAd.getLegalCoin(), c2cAd.getSymbol());
//        redisUtils.addZSet(zsetKey, c2cAd.getId().toString(), c2cAd.getPrice().doubleValue(), c2cAd.getDirection());

        //3 按支付方式、按最小数量排序，用于快捷交易
//        String[] paywayAr = payway.split(",");
//        for (String paywayId : paywayAr) {
//            redisUtils.addZSet(getQuickAdKey(zsetKey, paywayId), c2cAd.getId().toString(), c2cAd.getMinAmount().doubleValue(), c2cAd.getDirection());
//        }
    }


    @Override
    public PageData<C2cAdEntity> page(Map<String, Object> params) {
        IPage<C2cAdEntity> page = baseDao.selectPage(
                getPage(params, "id", false),
                getWrapper(params)
        );

        return getPageData(page, C2cAdEntity.class);
    }

    private QueryWrapper<C2cAdEntity> getWrapper(Map<String, Object> params){

        Integer merchantId = (Integer) params.get("merchantId");
        Integer status = (Integer) params.get("status");
        Integer direction = (Integer) params.get("direction");

        QueryWrapper<C2cAdEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(merchantId), "merchant_id", merchantId);
        wrapper.eq(Objects.nonNull(direction), "direction", direction);
        wrapper.eq(Objects.nonNull(status), "status", status);

        return wrapper;
    }


    /**
     * 快捷交易查询
     * 优先匹配“新手友好”商家
     * @param tranDTO
     * @return
     */
    @Override
    public Result queryTranAd(C2cAdTranDTO tranDTO) {
        Result result = new Result();
        String tranSymbol = tranDTO.getSymbol().toLowerCase();
        String tranLegalCoin = tranDTO.getLegalCoin().toUpperCase();
        Integer tranDirection = tranDTO.getDirection();
        //支付方式
        List<C2cPayWayEntity> paywayList = c2cPayWayService.selectListByLegalCoin(tranLegalCoin);
        if(CollectionUtils.isEmpty(paywayList)) {
            return result.error(MessageUtils.message("c2c.ad.current.payway.empty"));//当前法币未设置支付方式
        }
        //法币和usdt兑换利率
        C2cLegalCoinEntity tLegalCoin = c2cLegalCoinService.selectC2cLegalCoinByLegalCoin(tranLegalCoin);
        if(Objects.isNull(tLegalCoin)) {
            return result.error(MessageUtils.message("c2c.ad.legalCoin.notset"));//当前法币未设置
        }
        //买入法币金额，卖出是数币
        BigDecimal maxAmount = BigDecimal.ZERO;
        if (tranDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
            maxAmount = tranDTO.getAmount();
        } else {
            maxAmount = tranDTO.getAmount().multiply(tLegalCoin.getExchangeRate());
        }


        Integer direction = 0;
        if (tranDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
            direction = DirectionEnum.SELL.getCode();
        } else {
            direction = DirectionEnum.BUY.getCode();
        }
        //先查新手友好的商行
        List<C2cAdEntity> queryAdList = selectC2cAdTranList(tranSymbol,direction,tranLegalCoin,maxAmount,1);
        setPaywayList(paywayList, queryAdList,tranDirection);

        int total = 0;
        for(C2cPayWayEntity payway : paywayList) {
            if(payway.getAdList()!=null) {
                total += payway.getAdList().size();
            }
        }

        if(total<3) {
            //查其他的商行
            queryAdList = selectC2cAdTranList(tranSymbol,direction,tranLegalCoin,maxAmount,0);
            setPaywayList(paywayList, queryAdList,tranDirection);
        }

        return result.ok(paywayList);
    }

    private List<C2cPayWayEntity> setPaywayList(List<C2cPayWayEntity> paywayList,List<C2cAdEntity> queryAdList,Integer direction) {
        if (!CollectionUtils.isEmpty(queryAdList)) {
            for(C2cPayWayEntity payway : paywayList) {
                List<C2cAdEntity> adList = payway.getAdList()==null ? new ArrayList<>() : payway.getAdList();
                for(C2cAdEntity ad : queryAdList) {
                    String[] payIds = ad.getPayway().split(",");
                    if(Arrays.asList(payIds).contains(payway.getId().toString())) {
                        adList.add(ad);
                        if (adList.size() > 2) {
                            break;
                        }
                    }
                }
                if(adList.size()>0) {
                    sortAdList(adList,direction);
                    payway.setAdList(adList);
                }
            }
        }
        return paywayList;
    }

    /**
     * 查询快捷交易广告
     *
     * @param symbol
     * @param direction
     * @param legalCoin
     * @param tranAmount
     * @return
     */
    private List<C2cAdEntity> selectC2cAdTranList(String symbol,Integer direction,
                                                  String legalCoin,BigDecimal tranAmount,Integer tag) {
        return baseDao.selectList(new LambdaQueryWrapper<C2cAdEntity>()
                    .ne(C2cAdEntity::getUserId, StpUtil.getLoginIdAsLong())
                    .eq(Objects.nonNull(direction),C2cAdEntity::getDirection, direction)
                    .eq(StrUtil.isNotBlank(legalCoin),C2cAdEntity::getLegalCoin, legalCoin)
                    .eq(StrUtil.isNotBlank(symbol),C2cAdEntity::getSymbol, symbol)
                    .eq(C2cAdEntity::getStatus,AdStatusEnum.PASS.getCode())
                    .eq(Objects.nonNull(tag),C2cAdEntity::getTag,tag)
                    .last(" limit 100")
                );
    }

    /**
     * 浏览广告
     * @param viewDTO
     * @return
     */
    @Override
    public Result selectC2cAdViewList(C2cAdViewDTO viewDTO)
    {
        Result result = new Result();
        List<C2cAdEntity> resList = new ArrayList();
        //查询单个广告
        if(viewDTO.getId()!=null) {
            C2cAdEntity ad = selectAdFromRedis(viewDTO.getId());
            if(ad == null) {
                ad = selectById(viewDTO.getId());
            }
            if(ad!=null) {
                resList.add(ad);
                PageData<C2cAdEntity> data = new PageData<C2cAdEntity>(resList,1L);
                return result.ok(data);
            }
        }

        //设置金额
        BigDecimal amount = viewDTO.getAmount();
        //设置支付方式
        String payway = viewDTO.getPayway();
        //标签
        Integer tag = viewDTO.getTag();

        Map<String, Object> params = new HashMap<>();
        //买入\卖出广告
        Integer direction = null;
        String type = "asc";
        if (viewDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
            direction = DirectionEnum.SELL.getCode();
            params.put("direction", DirectionEnum.SELL.getCode());
        } else {
            type = "desc";
            direction = DirectionEnum.BUY.getCode();
            params.put("direction", DirectionEnum.BUY.getCode());
        }
        params.put(Constant.PAGE,viewDTO.getPageNum());
        params.put(Constant.LIMIT,viewDTO.getPageSize());
        String inputSymbol = viewDTO.getSymbol().toLowerCase();
        String inputLegalCoin = viewDTO.getLegalCoin().toUpperCase();

        //2 查数据库
        List paywayList = new ArrayList();
        if (StrUtil.isNotEmpty(payway)) {
            paywayList = Arrays.stream(payway.split(",")).toList();
        }
        LambdaQueryWrapper<C2cAdEntity> wrapper = new LambdaQueryWrapper<C2cAdEntity>()
                .ne(C2cAdEntity::getUserId, StpUtil.getLoginIdAsLong())
                .eq(Objects.nonNull(direction),C2cAdEntity::getDirection, direction)
                .eq(StrUtil.isNotBlank(inputLegalCoin),C2cAdEntity::getLegalCoin, inputLegalCoin)
                .eq(StrUtil.isNotBlank(inputSymbol),C2cAdEntity::getSymbol, inputSymbol)
                .eq(C2cAdEntity::getStatus,AdStatusEnum.PASS.getCode())
                .eq(Objects.nonNull(tag) && tag != -1,C2cAdEntity::getTag,tag)
                .le(Objects.nonNull(amount),C2cAdEntity::getMinAmount,amount)
                .ge(Objects.nonNull(amount),C2cAdEntity::getMaxAmount,amount);
        if(paywayList.size()>0) {
            final List finalPaywayList = paywayList;
            wrapper.and(qw -> createQw(qw, finalPaywayList));
        }

        // 按价格排序
        IPage<C2cAdEntity> page = baseDao.selectPage(
                getPage(params, "price", "asc".equals(type) ? true : false),
                wrapper
        );
        PageData<C2cAdEntity> data = getPageData(page, C2cAdEntity.class);
        return result.ok(data);
    }

    private void createQw(LambdaQueryWrapper<C2cAdEntity> qw, List<String> paywayList) {
        for(int i = 0; i < paywayList.size(); i++) {
            String payway = new StringBuilder(",").append(paywayList.get(i)).append(",").toString();
            qw.or(qw1 -> qw1.like(C2cAdEntity::getPayway, payway));
        }
    }

    @Override
    public C2cAdEntity selectAdFromRedis(Long id) {
        String adHKey = getAdHKey(id);
        Map<String, Object> adMap = null;
        try {
            adMap = redisUtils.hGetAll(adHKey);
        } catch (Exception e) {
            log.error("JSON.parseObject error",e);
            adMap = null;
            redisUtils.delete(adHKey);
        }
        if(adMap == null || adMap.isEmpty()) {
            return null;
        }
        C2cAdEntity c2cAd = new C2cAdEntity();
        c2cAd.setId(id);
        c2cAd.setAdNo(Convert.toStr(adMap.get("adNo")));
        c2cAd.setUserId(Convert.toLong(adMap.get("userId")));
        c2cAd.setUserName(Convert.toStr(adMap.get("userName")));
        c2cAd.setMerchantId(Convert.toLong(adMap.get("merchantId")));
        c2cAd.setDirection(Convert.toInt(adMap.get("direction")));
        c2cAd.setSymbol(Convert.toStr(adMap.get("symbol")));
        c2cAd.setLegalCoin(Convert.toStr(adMap.get("legalCoin")));
        c2cAd.setNum(Convert.toBigDecimal(adMap.get("total")));
        c2cAd.setAvailableNum(Convert.toBigDecimal(adMap.get("availableNum")));
        c2cAd.setPrice(Convert.toBigDecimal(adMap.get("price")));
        c2cAd.setMinAmount(Convert.toBigDecimal(adMap.get("minAmount")));
        c2cAd.setMaxAmount(Convert.toBigDecimal(adMap.get("maxAmount")));
        c2cAd.setPayway(Convert.toStr(adMap.get("payway")));
//        c2cAd.setFinishNum(Convert.toInt(adMap.get("finishNum")));
//        c2cAd.setFinishRate(Convert.toStr(adMap.get("finishRate")));
        c2cAd.setStatus(Convert.toInt(adMap.get("status")));
        return c2cAd;
    }

    //重设置广告缓存
    private void delSetAdCache(C2cAdEntity ad) {
        if(ad != null) {
            if (ad.getStatus().intValue() == AdStatusEnum.NOPASS.getCode().intValue()) {
                deleteAdCache(ad.getId(), ad.getPayway().replaceAll("^,|,$", ""), ad.getLegalCoin(), ad.getSymbol(), ad.getDirection());
            } else {
                deleteAdCache(ad.getId(), ad.getPayway().replaceAll("^,|,$", ""), ad.getLegalCoin(), ad.getSymbol(), ad.getDirection());
                setAdCache(ad);
            }
        }
    }

    /**
     * 买入 从低到高价格排序
     * 卖出 从高到低排序
     * @param adList
     * @param direction
     */
    private void sortAdList(List<C2cAdEntity> adList,Integer direction) {
        if (direction.intValue() == DirectionEnum.BUY.getCode().intValue()) {
            adList.sort((list1, list2) -> list1.getPrice().compareTo(list2.getPrice()));
        } else {
            adList.sort((list1, list2) -> list2.getPrice().compareTo(list1.getPrice()));
        }
    }


    /**
     * 更新广告不可用
     * @param c2cAd c2c商家广告
     * @return
     */
    @Override
    public boolean updateC2cAdDisabled(C2cAdEntity c2cAd) {
        Integer adDirection = c2cAd.getDirection();
        String adLegalCoin = c2cAd.getLegalCoin();
        String adSymbol = c2cAd.getSymbol();
        String adPayway = c2cAd.getPayway().replaceAll("^,|,$", "");
        deleteAdCache(c2cAd.getId(), adPayway, adLegalCoin, adSymbol, adDirection);
        c2cAd.setStatus(AdStatusEnum.NOPASS.getCode());
        return updateById(c2cAd);
    }


    /**
     * 更新广告不可用
     * @param c2cAd c2c商家广告
     * @return
     */
    @Override
    public void deleteC2cAdCache(C2cAdEntity c2cAd) {
        Integer adDirection = c2cAd.getDirection();
        String adLegalCoin = c2cAd.getLegalCoin();
        String adSymbol = c2cAd.getSymbol();
        String adPayway = c2cAd.getPayway().replaceAll("^,|,$", "");
        deleteAdCache(c2cAd.getId(), adPayway, adLegalCoin, adSymbol, adDirection);
    }


    @Override
    public int updateC2cAdAvailableNumById(Long id, BigDecimal symbolNum,BigDecimal maxAmount,Integer status,Long version) {
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("symbolNum",symbolNum);
        map.put("maxAmount",maxAmount);
        map.put("status",status);
        map.put("version",version);
        return c2cAdDao.updateC2cAdAvailableNumById(map);
    }

    @Override
    public int addC2cAdAvailableNumById(Long id, BigDecimal symbolNum,BigDecimal maxAmount,Long version) {
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("symbolNum",symbolNum);
        map.put("maxAmount",maxAmount);
        map.put("version",version);
        return c2cAdDao.addC2cAdAvailableNumById(map);
    }
}