zainali5120
2020-11-29 83e2fd8d61d116ce9bf2034e8d05346910f96260
卖出额度限制
2 files modified
66 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/blackchain/service/DateUtil.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java 62 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/DateUtil.java
@@ -82,7 +82,8 @@
        //        System.out.println("222="+dateDiffStr("2014-06-11 00:00:00","2014-06-25 23:59:59"));
//        System.out.println("getUTCTimeStr()=="+DateUtil.currentTimeDiffToHour("2015-01-22 18:12:59"));
        //System.out.println(DateUtil.dateDiff("2015-09-02 09:55:14",DateUtil.dateToString(new Date())));
        System.out.println(DateUtil.currentTimeDiff("2018-07-11 18:00:00"));
        String yyyyMMdd = dateToString(new Date(), "yyyyMMdd");
        System.out.println(yyyyMMdd);
    }
    
    /**
@@ -325,6 +326,7 @@
        return simpleDateFormat.format(date);
    }
    /**
     * 把日期格式转换为YYMMDDHHMMSS格式
     * @param
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.modules.coin.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -11,6 +12,7 @@
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.modules.blackchain.service.DateUtil;
import com.xcong.excoin.modules.blackchain.service.RocService;
import com.xcong.excoin.modules.coin.mapper.OrderCoinsDealMapper;
import com.xcong.excoin.modules.coin.service.CoinService;
@@ -101,6 +103,13 @@
    @Resource
    private CoinService coinService;
    private static BigDecimal PERSENT = new BigDecimal("100");
    /**
     *  每日卖出限制 日期 20201128 会员ID
     */
    String LIMIT_SELL_PERSENT_KEY ="SELL:PERSENT:%s:%s";
    @Override
@@ -367,28 +376,6 @@
                    return Result.fail("");
                }
                // 不能超过800个
//                if (amount != null && amount.compareTo(new BigDecimal("800")) > 0) {
//                    return Result.fail("买入额度受限");
//                }
//                BigDecimal bigDecimal = orderCoinDealDao.sumTodayBuyAmount(memberId, symbol);
//                if (bigDecimal == null) {
//                    bigDecimal = BigDecimal.ZERO;
//                }
//                amount = amount == null ? BigDecimal.ZERO : amount;
//                bigDecimal = bigDecimal.add(amount);
//                if (bigDecimal != null && bigDecimal.compareTo(new BigDecimal("800")) > 0) {
//                    return Result.fail("买入额度受限");
//                }
//                // 挂单不能超过800
//                BigDecimal bigDecimal1 = orderCoinDealDao.sumTodayEntrustCntBuyAmount(memberId, symbol);
//                if (bigDecimal1 == null) {
//                    bigDecimal1 = BigDecimal.ZERO;
//                }
//                bigDecimal1 = bigDecimal1.add(amount);
//                if (bigDecimal1 != null && bigDecimal1.compareTo(new BigDecimal("800")) > 0) {
//                    return Result.fail("买入额度受限");
//                }
            } else {
                // 判断redis开关
                //String string = redisUtils.getString("SELL_LIMIT_KEY");
@@ -400,6 +387,7 @@
                if (StringUtils.isNotBlank(string) && StringUtils.isNotBlank(memberEntity.getEmail()) && string.contains(memberEntity.getEmail())) {
                    return Result.fail("");
                }
            }
        }
@@ -466,6 +454,26 @@
            BigDecimal availableBalance = walletCoin.getAvailableBalance();
            if (amount.compareTo(availableBalance) > 0) {
                return Result.fail(MessageSourceUtils.getString("order_service_0010"));
            }
            // 控制这个用户每日的挂卖额度 TODO
            // 每天3% 第一次的为基数
            BigDecimal spread = memberEntity.getSpread();
            if(spread!=null && spread.compareTo(BigDecimal.ZERO)>0 && spread.compareTo(PERSENT)<0){
                // 获取当日的额度
                String yyyyMMdd = DateUtil.dateToString(new Date(), "yyyyMMdd");
                String persentKey = String.format(LIMIT_SELL_PERSENT_KEY,yyyyMMdd,memberId.toString());
                BigDecimal aviSell  =BigDecimal.ZERO;
                if(StringUtils.isBlank(persentKey)){
                    // 当日可以卖的数量
                     aviSell = spread.divide(PERSENT,4, RoundingMode.HALF_UP).multiply(availableBalance);
                }
                if(aviSell.compareTo(amount)<0){
                    return Result.fail("卖出超过上限"+spread+"%");
                }
                aviSell = aviSell.subtract(amount);
                // 设置
                redisUtils.set(persentKey,aviSell.toPlainString());
                //redisUtils.getString()
            }
        }
@@ -746,11 +754,21 @@
                    return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                }
            } else {
                //如果是限价卖出,撤单将对应的钱包冻结金额返回
                MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
                if (ObjectUtil.isNotEmpty(walletCoin)) {
                    // 卖出按卖出的数量计算手续费
                    BigDecimal returnBalance = orderCoinsEntity.getEntrustCnt().subtract(coinsEntityCancel.getDealCnt());
                    // 取消订单 则退回额度
                    String yyyyMMdd = DateUtil.dateToString(new Date(), "yyyyMMdd");
                    String persentKey = String.format(LIMIT_SELL_PERSENT_KEY,yyyyMMdd,memberId.toString());
                    String aviSell = redisUtils.getString(persentKey);
                    // TODO
                    if(StringUtils.isNotBlank(aviSell)){
                        BigDecimal needSub = new BigDecimal(aviSell).add(returnBalance);
                        redisUtils.set(persentKey,needSub.toPlainString());
                    }
                    walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
                    walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
                    //memberWalletCoinDao.updateById(walletCoin);