Helius
2020-07-01 94c55976479131ad79e100e551a06d84b071d504
add coin entrust to deal
6 files modified
1 files added
983 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/coin/dao/OrderCoinsDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/mapper/OrderCoinsDealMapper.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/OrderCoinService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java 932 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/LoopExecutorJob.java 16 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/walletCoinOrder/OrderCoinsDao.xml 8 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/dao/OrderCoinsDao.java
@@ -14,4 +14,6 @@
    List<OrderCoinsEntity> findCoinOrderListByMemberIdAndSysmbol(@Param("memberId")Long memberId,@Param("symbol")String symbol,@Param("status")int status);
    OrderCoinsEntity findWalletCoinOrderByOrderNo(@Param("orderNo")String orderNo);
    List<OrderCoinsEntity> selectAllEntrustingCoinOrderList();
}
src/main/java/com/xcong/excoin/modules/coin/mapper/OrderCoinsDealMapper.java
New file
@@ -0,0 +1,21 @@
package com.xcong.excoin.modules.coin.mapper;
import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
 * @author wzy
 * @date 2020-07-01
 **/
@Mapper
public abstract class OrderCoinsDealMapper {
    public static final OrderCoinsDealMapper INSTANCE = Mappers.getMapper(OrderCoinsDealMapper.class);
    @Mapping(target = "symbolCnt", source = "entrustCnt")
    public abstract OrderCoinsDealEntity orderToOrderDeal(OrderCoinsEntity orderCoinsEntity);
}
src/main/java/com/xcong/excoin/modules/coin/service/OrderCoinService.java
@@ -32,4 +32,6 @@
    public Result searchSymbolResultList();
    public void dealEntrustCoinOrder();
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -12,6 +12,7 @@
import javax.annotation.Resource;
import com.xcong.excoin.modules.coin.mapper.OrderCoinsDealMapper;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import com.xcong.excoin.modules.platform.entity.PlatformSymbolsCoinEntity;
@@ -63,454 +64,523 @@
import cn.hutool.core.util.StrUtil;
@Service
public class OrderCoinServiceImpl extends ServiceImpl<OrderCoinsDao, OrderCoinsEntity> implements OrderCoinService{
    @Resource
    TradeSettingDao platformTradeSettingDao;
    @Resource
    MemberWalletCoinDao memberWalletCoinDao;
    @Resource
    MemberSelectSymbolsDao memberSelectSymbolsDao;
    @Resource
public class OrderCoinServiceImpl extends ServiceImpl<OrderCoinsDao, OrderCoinsEntity> implements OrderCoinService {
    @Resource
    TradeSettingDao platformTradeSettingDao;
    @Resource
    MemberWalletCoinDao memberWalletCoinDao;
    @Resource
    MemberSelectSymbolsDao memberSelectSymbolsDao;
    @Resource
    PlatformCnyUsdtExchangeDao cnyUsdtExchangeDao;
    @Resource
    OrderCoinsDao orderCoinsDao;
    @Resource
    OrderCoinDealDao orderCoinDealDao;
    @Resource
    MemberAccountFlowEntityDao memberAccountFlowEntityDao;
    @Resource
    OrderCoinsDao orderCoinsDao;
    @Resource
    OrderCoinDealDao orderCoinDealDao;
    @Resource
    MemberAccountFlowEntityDao memberAccountFlowEntityDao;
    @Resource
    RedisUtils redisUtils;
    @Resource
    PlatformSymbolsCoinDao platformSymbolsCoinDao;
    @Override
    public String generateSimpleSerialno(String userId) {
        StringBuilder sb = new StringBuilder();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
        Date now = new Date();
        sb.append(sd.format(now));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(now);
        calendar.add(calendar.DATE, 1);
        Date nextDate = calendar.getTime();
        if (StrUtil.isNotEmpty(userId)) {
            sb.append(userId);
        }
        sb.append(RandomUtil.randomInt(2));
        long count = orderCoinsDao.getOrderCountByToday(sdf.format(now), sdf.format(nextDate));
        count++;
        int size = 4;
        for (int i = 0; i < size - String.valueOf(count).length(); i++) {
            sb.append("0");
        }
        sb.append(count);
        return sb.toString();
    }
    @Override
    public Result enterTransactionPageOfWalletCoin(String symbol) {
        if (StrUtil.isBlank(symbol)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0001"));
        }
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        //获取该币种的币币账户信息
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
        PlatformTradeSettingEntity tradeSetting = platformTradeSettingDao.findTradeSetting();
        if (ObjectUtil.isEmpty(tradeSetting)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0003"));
        }
        //获取USDT的币币账户信息
        MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,
                                                            MemberWalletCoinEnum.WALLETCOINCODE.getValue());
        BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
        List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
    @Override
    public String generateSimpleSerialno(String userId) {
        StringBuilder sb = new StringBuilder();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
        Date now = new Date();
        sb.append(sd.format(now));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(now);
        calendar.add(calendar.DATE, 1);
        Date nextDate = calendar.getTime();
        if (StrUtil.isNotEmpty(userId)) {
            sb.append(userId);
        }
        sb.append(RandomUtil.randomInt(2));
        long count = orderCoinsDao.getOrderCountByToday(sdf.format(now), sdf.format(nextDate));
        count++;
        int size = 4;
        for (int i = 0; i < size - String.valueOf(count).length(); i++) {
            sb.append("0");
        }
        sb.append(count);
        return sb.toString();
    }
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
        BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
        TransactionPageOfWalletCoinVo transactionPageOfWalletCoinVo = new TransactionPageOfWalletCoinVo();
        //是否自选
        if(CollUtil.isEmpty(memSymbols)) {
            transactionPageOfWalletCoinVo.setIsCollect(TransactionPageOfWalletCoinVo.ISCOLLECT_NO);
        }else {
            transactionPageOfWalletCoinVo.setIsCollect(TransactionPageOfWalletCoinVo.ISCOLLECT_YES);
        }
        if (ObjectUtil.isEmpty(walletCoin))
            return Result.fail(MessageSourceUtils.getString("order_service_0003"));
        // 点差
        transactionPageOfWalletCoinVo.setSpread(tradeSetting.getSpread().setScale(4, BigDecimal.ROUND_DOWN));
        // 手续费用率
        transactionPageOfWalletCoinVo.setFeeRatio(tradeSetting.getCoinFeeRatio().setScale(4, BigDecimal.ROUND_DOWN));
        // 用户可用金额
        transactionPageOfWalletCoinVo.setAvailableBalanceBuy(walletCoinUsdt.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
        transactionPageOfWalletCoinVo.setAvailableBalanceSell(walletCoin.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
        //当前价
        transactionPageOfWalletCoinVo.setCurrentPrice(closePrice.setScale(4, BigDecimal.ROUND_DOWN));
        //比例
        transactionPageOfWalletCoinVo.setCnyUsdt(cnyUsdt.setScale(4, BigDecimal.ROUND_DOWN));
        //换算成人民币的币种价格
        transactionPageOfWalletCoinVo.setCurrentPriceCny(cnyUsdt.multiply(closePrice).setScale(4, BigDecimal.ROUND_DOWN));
        transactionPageOfWalletCoinVo.setSymbol(symbol);
        return Result.ok(transactionPageOfWalletCoinVo);
    }
    @Override
    public Result enterTransactionPageOfWalletCoin(String symbol) {
        if (StrUtil.isBlank(symbol)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0001"));
        }
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        //获取该币种的币币账户信息
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
    @Override
    @Transactional
    public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,BigDecimal amount) {
            //获取用户ID
            Long memberId = LoginUserUtils.getAppLoginUser().getId();
            //查询当前价
            BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
            // 获取交易管理的杠杠倍率,手续费率等信息,由平台进行设置
            symbol = symbol.toUpperCase();
            MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
            if (ObjectUtil.isEmpty(walletCoin)) {
                return Result.fail(MessageSourceUtils.getString("order_service_0003"));
            }
            // 查询交易设置
            PlatformTradeSettingEntity tradeSetting = platformTradeSettingDao.findTradeSetting();
            if(ObjectUtil.isEmpty(tradeSetting)) {
                return Result.fail(MessageSourceUtils.getString("order_service_0009"));
            }
            // 手续费用(手续费=建仓价X数量X手续费率)
            BigDecimal closingPrice = price.multiply(amount).multiply(tradeSetting.getCoinFeeRatio());
            //总费用 = 成交价*数量+手续费
            BigDecimal totalPayPrice = price.multiply(amount).add(closingPrice);
            String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
            MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,walletCode);
            if(OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                //买入,所需总费用跟用户USDT金额进行比较
                BigDecimal availableBalance = walletCoinUsdt.getAvailableBalance();
                if (totalPayPrice.compareTo(availableBalance) > 0) {
                    return Result.fail(MessageSourceUtils.getString("order_service_0010"));
                }
            }else {
                //卖出,所需总费用跟用户所对应的币种金额进行比较
                BigDecimal availableBalance = walletCoin.getAvailableBalance();
                if (amount.compareTo(availableBalance) > 0) {
                    return Result.fail(MessageSourceUtils.getString("order_service_0010"));
                }
            }
            // 创建订单
            OrderCoinsEntity order = new OrderCoinsEntity();
            if (OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType)) {
                // 如果是限价交易直接插入主表数据
                order.setMemberId(memberId);
                order.setOrderNo(generateSimpleSerialno(memberId.toString()));
                order.setOrderType(type);
                order.setSymbol(symbol);
                order.setMarkPrice(nowPrice);
                order.setEntrustCnt(amount);
                order.setEntrustPrice(price);
                order.setDealCnt(amount);
                order.setDealPrice(price);
                order.setDealAmount(totalPayPrice);
                order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DODING);
                order.setTradeType(tradeType);
                order.setFeeAmount(closingPrice);
                orderCoinsDao.insert(order);
                //更新用户钱包信息
                //冻结相应的资产
                if(OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                    //如果是买入,所对应的币种增加,USDT账户减少金额
                    BigDecimal availableBalance = walletCoinUsdt.getAvailableBalance().subtract(totalPayPrice);
                    BigDecimal frozenBalance = walletCoinUsdt.getFrozenBalance().add(totalPayPrice);
                    walletCoinUsdt.setAvailableBalance(availableBalance);
                    walletCoinUsdt.setFrozenBalance(frozenBalance);
                    memberWalletCoinDao.updateById(walletCoinUsdt);
                }else {
                    //如果是卖出,币种减少,USDT增加
                    BigDecimal availableBalance = walletCoin.getAvailableBalance().subtract(amount);
                    BigDecimal frozenBalance = walletCoin.getFrozenBalance().add(amount);
                    walletCoin.setAvailableBalance(availableBalance);
                    walletCoin.setFrozenBalance(frozenBalance);
                    memberWalletCoinDao.updateById(walletCoin);
                }
            } else {
                //如果是市价交易,主表和附表都需要插入数据
                order.setMemberId(memberId);
                order.setOrderNo(generateSimpleSerialno(memberId.toString()));
                order.setOrderType(type);
                order.setSymbol(symbol);
                order.setMarkPrice(nowPrice);
                order.setEntrustCnt(amount);
                order.setEntrustPrice(price);
                order.setDealCnt(amount);
                order.setDealPrice(price);
                order.setDealAmount(totalPayPrice);
                order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE);
                order.setTradeType(tradeType);
                order.setFeeAmount(closingPrice);
                orderCoinsDao.insert(order);
                OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
                detail.setMemberId(memberId);
                detail.setOrderId(order.getId());
                detail.setOrderNo(order.getOrderNo());
                detail.setOrderType(type);
                detail.setTradeType(tradeType);
                detail.setSymbol(symbol);
                detail.setSymbolCnt(amount);
                detail.setEntrustPrice(price);
                detail.setDealPrice(price);
                detail.setDealAmount(totalPayPrice);
                detail.setFeeAmount(closingPrice);
                detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
                orderCoinDealDao.insert(detail);
                if(OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                    //如果是买入,所对应的币种增加,USDT账户减少金额
                    // 更新用户的可用金额
                    walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(amount));
                    memberWalletCoinDao.updateById(walletCoin);
                    walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().subtract(totalPayPrice));
                    memberWalletCoinDao.updateById(walletCoinUsdt);
                }else {
                    //如果是卖出,币种减少,USDT增加
                    walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().subtract(amount));
                    memberWalletCoinDao.updateById(walletCoin);
                    BigDecimal subtract = totalPayPrice.subtract(closingPrice).subtract(closingPrice);
                    walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(subtract));
                    memberWalletCoinDao.updateById(walletCoinUsdt);
                }
            }
            // 流水记录
            MemberAccountFlowEntity record = new MemberAccountFlowEntity();
            record.setMemberId(memberId);
            if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                record.setPrice(totalPayPrice.setScale(4, BigDecimal.ROUND_DOWN));
                record.setSource(MemberAccountFlowEntity.SOURCE_BUY+symbol);
                record.setRemark(MemberAccountFlowEntity.REMARK_BUY+symbol+":"+amount);
            } else {
                record.setPrice(totalPayPrice.negate().setScale(4, BigDecimal.ROUND_DOWN));
                record.setSource(MemberAccountFlowEntity.SOURCE_SALE+symbol);
                record.setRemark(MemberAccountFlowEntity.REMARK_SALE+symbol+":"+amount);
            }
            record.setSymbol(symbol);
            record.setBalance(walletCoinUsdt.getAvailableBalance());
            memberAccountFlowEntityDao.insert(record);
        return Result.ok(MessageSourceUtils.getString("order_service_0011"));
    }
        PlatformTradeSettingEntity tradeSetting = platformTradeSettingDao.findTradeSetting();
        if (ObjectUtil.isEmpty(tradeSetting)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0003"));
        }
        //获取USDT的币币账户信息
        MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,
                MemberWalletCoinEnum.WALLETCOINCODE.getValue());
    @Override
    public Result getEntrustWalletCoinOrder(String symbol, Integer status) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        OrderWalletCoinListVo orderWalletCoinListVo = new OrderWalletCoinListVo();
        List<OrderWalletCoinVo> arrayList = new ArrayList<>();
        List<OrderCoinsEntity> findCoinOrderListByMemberIdAndSysmbol = orderCoinsDao.findCoinOrderListByMemberIdAndSysmbol(memberId, symbol, status);
        if(CollUtil.isNotEmpty(findCoinOrderListByMemberIdAndSysmbol)) {
            for(OrderCoinsEntity orderCoinsEntity : findCoinOrderListByMemberIdAndSysmbol) {
                OrderWalletCoinVo entityToVo = OrderWalletCoinMapper.INSTANCE.entityToVo(orderCoinsEntity);
                arrayList.add(entityToVo);
            }
        }
        orderWalletCoinListVo.setOrderWalletCoinVo(arrayList);
        return Result.ok(arrayList);
    }
        BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol + "/USDT")));
    @Override
    @Transactional
    public Result cancelEntrustWalletCoinOrder(String orderId) {
            //获取用户ID
            Long memberId = LoginUserUtils.getAppLoginUser().getId();
            OrderCoinsEntity orderCoinsEntity = orderCoinsDao.selectById(orderId);
                if(ObjectUtil.isNotEmpty(orderCoinsEntity) && orderCoinsEntity.getMemberId() == memberId) {
                    if(orderCoinsEntity.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_CANCEL){
                        return Result.fail(MessageSourceUtils.getString("order_service_0012"));
                    }
                    orderCoinsEntity.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_CANCEL);
                    orderCoinsDao.updateById(orderCoinsEntity);
                    String symbol = orderCoinsEntity.getSymbol();
                    OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
                    detail.setMemberId(memberId);
                    detail.setOrderId(orderCoinsEntity.getId());
                    detail.setOrderNo(generateSimpleSerialno(memberId.toString()));
                    detail.setOrderType(orderCoinsEntity.getOrderType());
                    detail.setTradeType(orderCoinsEntity.getTradeType());
                    detail.setSymbol(symbol);
                    detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_CANCEL);
                    detail.setSymbolCnt(orderCoinsEntity.getEntrustCnt());
                    detail.setEntrustPrice(orderCoinsEntity.getEntrustPrice());
                    detail.setDealPrice(orderCoinsEntity.getDealPrice());
                    detail.setDealAmount(orderCoinsEntity.getDealAmount());
                    detail.setFeeAmount(orderCoinsEntity.getFeeAmount());
                    orderCoinDealDao.insert(detail);
                    if(OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
                        //如果是限价买入,撤单将USDT账户冻结金额返回
                        String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
                        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
                        if (ObjectUtil.isNotEmpty(walletCoin)) {
                            //手续费 = 开仓价*数量*手续费率
                            //返还金额=开仓价*未成交数量+手续费
                            BigDecimal returnBalance = orderCoinsEntity.getDealAmount();
                            walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
                            walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
                            memberWalletCoinDao.updateById(walletCoin);
                            // 流水记录
                            MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                            record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
                            record.setRemark(MemberAccountFlowEntity.REMARK_CANCEL+symbol+MemberAccountFlowEntity.REMARK_RETURNBALANCE+returnBalance);
                            record.setBalance(walletCoin.getAvailableBalance());
                            record.setMemberId(memberId);
                            record.setSymbol(symbol);
                            record.setPrice(returnBalance);
                            memberAccountFlowEntityDao.insert(record);
                            return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                        }
                    }else {
                        //如果是限价卖出,撤单将对应的钱包冻结金额返回
                        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
                        if (ObjectUtil.isNotEmpty(walletCoin)) {
                            BigDecimal returnBalance = orderCoinsEntity.getEntrustCnt();
                            walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
                            walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
                            memberWalletCoinDao.updateById(walletCoin);
                            // 流水记录
                            MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                            record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
                            record.setRemark(MemberAccountFlowEntity.REMARK_CANCEL+symbol+MemberAccountFlowEntity.REMARK_RETURNBALANCE+returnBalance);
                            record.setBalance(walletCoin.getAvailableBalance());
                            record.setMemberId(memberId);
                            record.setSymbol(symbol);
                            record.setPrice(walletCoin.getFrozenBalance());
                            memberAccountFlowEntityDao.insert(record);
                            return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                        }
                    }
                }
        return Result.fail(MessageSourceUtils.getString("order_service_0043"));
    }
        List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
    @Override
    public Result findAllWalletCoinOrder(FindAllWalletCoinOrderDto findAllWalletCoinOrderDto) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        Page<OrderCoinsDealEntity> page = new Page<>(findAllWalletCoinOrderDto.getPageNum(), findAllWalletCoinOrderDto.getPageSize());
        OrderCoinsDealEntity orderCoinsDealEntity = new OrderCoinsDealEntity();
        orderCoinsDealEntity.setMemberId(memberId);
        orderCoinsDealEntity.setSymbol(findAllWalletCoinOrderDto.getSymbol());
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
        BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
        TransactionPageOfWalletCoinVo transactionPageOfWalletCoinVo = new TransactionPageOfWalletCoinVo();
        //是否自选
        if (CollUtil.isEmpty(memSymbols)) {
            transactionPageOfWalletCoinVo.setIsCollect(TransactionPageOfWalletCoinVo.ISCOLLECT_NO);
        } else {
            transactionPageOfWalletCoinVo.setIsCollect(TransactionPageOfWalletCoinVo.ISCOLLECT_YES);
        }
        if (ObjectUtil.isEmpty(walletCoin))
            return Result.fail(MessageSourceUtils.getString("order_service_0003"));
        // 点差
        transactionPageOfWalletCoinVo.setSpread(tradeSetting.getSpread().setScale(4, BigDecimal.ROUND_DOWN));
        // 手续费用率
        transactionPageOfWalletCoinVo.setFeeRatio(tradeSetting.getCoinFeeRatio().setScale(4, BigDecimal.ROUND_DOWN));
        // 用户可用金额
        transactionPageOfWalletCoinVo.setAvailableBalanceBuy(walletCoinUsdt.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
        transactionPageOfWalletCoinVo.setAvailableBalanceSell(walletCoin.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
        //当前价
        transactionPageOfWalletCoinVo.setCurrentPrice(closePrice.setScale(4, BigDecimal.ROUND_DOWN));
        //比例
        transactionPageOfWalletCoinVo.setCnyUsdt(cnyUsdt.setScale(4, BigDecimal.ROUND_DOWN));
        //换算成人民币的币种价格
        transactionPageOfWalletCoinVo.setCurrentPriceCny(cnyUsdt.multiply(closePrice).setScale(4, BigDecimal.ROUND_DOWN));
        transactionPageOfWalletCoinVo.setSymbol(symbol);
        return Result.ok(transactionPageOfWalletCoinVo);
    }
    @Override
    @Transactional
    public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price, BigDecimal amount) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        //查询当前价
        BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol + "/USDT")));
        // 获取交易管理的杠杠倍率,手续费率等信息,由平台进行设置
        symbol = symbol.toUpperCase();
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
        if (ObjectUtil.isEmpty(walletCoin)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0003"));
        }
        // 查询交易设置
        PlatformTradeSettingEntity tradeSetting = platformTradeSettingDao.findTradeSetting();
        if (ObjectUtil.isEmpty(tradeSetting)) {
            return Result.fail(MessageSourceUtils.getString("order_service_0009"));
        }
        // 手续费用(手续费=建仓价X数量X手续费率)
        BigDecimal closingPrice = price.multiply(amount).multiply(tradeSetting.getCoinFeeRatio());
        //总费用 = 成交价*数量+手续费
        BigDecimal totalPayPrice = price.multiply(amount).add(closingPrice);
        String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
        MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
        if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
            //买入,所需总费用跟用户USDT金额进行比较
            BigDecimal availableBalance = walletCoinUsdt.getAvailableBalance();
            if (totalPayPrice.compareTo(availableBalance) > 0) {
                return Result.fail(MessageSourceUtils.getString("order_service_0010"));
            }
        } else {
            //卖出,所需总费用跟用户所对应的币种金额进行比较
            BigDecimal availableBalance = walletCoin.getAvailableBalance();
            if (amount.compareTo(availableBalance) > 0) {
                return Result.fail(MessageSourceUtils.getString("order_service_0010"));
            }
        }
        // 创建订单
        OrderCoinsEntity order = new OrderCoinsEntity();
        if (OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType)) {
            // 如果是限价交易直接插入主表数据
            order.setMemberId(memberId);
            order.setOrderNo(generateSimpleSerialno(memberId.toString()));
            order.setOrderType(type);
            order.setSymbol(symbol);
            order.setMarkPrice(nowPrice);
            order.setEntrustCnt(amount);
            order.setEntrustPrice(price);
            order.setDealCnt(amount);
            order.setDealPrice(price);
            order.setDealAmount(totalPayPrice);
            order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DODING);
            order.setTradeType(tradeType);
            order.setFeeAmount(closingPrice);
            orderCoinsDao.insert(order);
            //更新用户钱包信息
            //冻结相应的资产
            if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                //如果是买入,所对应的币种增加,USDT账户减少金额
                BigDecimal availableBalance = walletCoinUsdt.getAvailableBalance().subtract(totalPayPrice);
                BigDecimal frozenBalance = walletCoinUsdt.getFrozenBalance().add(totalPayPrice);
                walletCoinUsdt.setAvailableBalance(availableBalance);
                walletCoinUsdt.setFrozenBalance(frozenBalance);
                memberWalletCoinDao.updateById(walletCoinUsdt);
            } else {
                //如果是卖出,币种减少,USDT增加
                BigDecimal availableBalance = walletCoin.getAvailableBalance().subtract(amount);
                BigDecimal frozenBalance = walletCoin.getFrozenBalance().add(amount);
                walletCoin.setAvailableBalance(availableBalance);
                walletCoin.setFrozenBalance(frozenBalance);
                memberWalletCoinDao.updateById(walletCoin);
            }
        } else {
            //如果是市价交易,主表和附表都需要插入数据
            order.setMemberId(memberId);
            order.setOrderNo(generateSimpleSerialno(memberId.toString()));
            order.setOrderType(type);
            order.setSymbol(symbol);
            order.setMarkPrice(nowPrice);
            order.setEntrustCnt(amount);
            order.setEntrustPrice(price);
            order.setDealCnt(amount);
            order.setDealPrice(price);
            order.setDealAmount(totalPayPrice);
            order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE);
            order.setTradeType(tradeType);
            order.setFeeAmount(closingPrice);
            orderCoinsDao.insert(order);
            OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
            detail.setMemberId(memberId);
            detail.setOrderId(order.getId());
            detail.setOrderNo(order.getOrderNo());
            detail.setOrderType(type);
            detail.setTradeType(tradeType);
            detail.setSymbol(symbol);
            detail.setSymbolCnt(amount);
            detail.setEntrustPrice(price);
            detail.setDealPrice(price);
            detail.setDealAmount(totalPayPrice);
            detail.setFeeAmount(closingPrice);
            detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
            orderCoinDealDao.insert(detail);
            if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
                //如果是买入,所对应的币种增加,USDT账户减少金额
                // 更新用户的可用金额
                walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(amount));
                memberWalletCoinDao.updateById(walletCoin);
                walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().subtract(totalPayPrice));
                memberWalletCoinDao.updateById(walletCoinUsdt);
            } else {
                //如果是卖出,币种减少,USDT增加
                walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().subtract(amount));
                memberWalletCoinDao.updateById(walletCoin);
                BigDecimal subtract = totalPayPrice.subtract(closingPrice).subtract(closingPrice);
                walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(subtract));
                memberWalletCoinDao.updateById(walletCoinUsdt);
            }
        }
        // 流水记录
        MemberAccountFlowEntity record = new MemberAccountFlowEntity();
        record.setMemberId(memberId);
        if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
            record.setPrice(totalPayPrice.setScale(4, BigDecimal.ROUND_DOWN));
            record.setSource(MemberAccountFlowEntity.SOURCE_BUY + symbol);
            record.setRemark(MemberAccountFlowEntity.REMARK_BUY + symbol + ":" + amount);
        } else {
            record.setPrice(totalPayPrice.negate().setScale(4, BigDecimal.ROUND_DOWN));
            record.setSource(MemberAccountFlowEntity.SOURCE_SALE + symbol);
            record.setRemark(MemberAccountFlowEntity.REMARK_SALE + symbol + ":" + amount);
        }
        record.setSymbol(symbol);
        record.setBalance(walletCoinUsdt.getAvailableBalance());
        memberAccountFlowEntityDao.insert(record);
        return Result.ok(MessageSourceUtils.getString("order_service_0011"));
    }
    @Override
    public Result getEntrustWalletCoinOrder(String symbol, Integer status) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        OrderWalletCoinListVo orderWalletCoinListVo = new OrderWalletCoinListVo();
        List<OrderWalletCoinVo> arrayList = new ArrayList<>();
        List<OrderCoinsEntity> findCoinOrderListByMemberIdAndSysmbol = orderCoinsDao.findCoinOrderListByMemberIdAndSysmbol(memberId, symbol, status);
        if (CollUtil.isNotEmpty(findCoinOrderListByMemberIdAndSysmbol)) {
            for (OrderCoinsEntity orderCoinsEntity : findCoinOrderListByMemberIdAndSysmbol) {
                OrderWalletCoinVo entityToVo = OrderWalletCoinMapper.INSTANCE.entityToVo(orderCoinsEntity);
                arrayList.add(entityToVo);
            }
        }
        orderWalletCoinListVo.setOrderWalletCoinVo(arrayList);
        return Result.ok(arrayList);
    }
    @Override
    @Transactional
    public Result cancelEntrustWalletCoinOrder(String orderId) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        OrderCoinsEntity orderCoinsEntity = orderCoinsDao.selectById(orderId);
        if (ObjectUtil.isNotEmpty(orderCoinsEntity) && orderCoinsEntity.getMemberId() == memberId) {
            if (orderCoinsEntity.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_CANCEL) {
                return Result.fail(MessageSourceUtils.getString("order_service_0012"));
            }
            orderCoinsEntity.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_CANCEL);
            orderCoinsDao.updateById(orderCoinsEntity);
            String symbol = orderCoinsEntity.getSymbol();
            OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
            detail.setMemberId(memberId);
            detail.setOrderId(orderCoinsEntity.getId());
            detail.setOrderNo(generateSimpleSerialno(memberId.toString()));
            detail.setOrderType(orderCoinsEntity.getOrderType());
            detail.setTradeType(orderCoinsEntity.getTradeType());
            detail.setSymbol(symbol);
            detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_CANCEL);
            detail.setSymbolCnt(orderCoinsEntity.getEntrustCnt());
            detail.setEntrustPrice(orderCoinsEntity.getEntrustPrice());
            detail.setDealPrice(orderCoinsEntity.getDealPrice());
            detail.setDealAmount(orderCoinsEntity.getDealAmount());
            detail.setFeeAmount(orderCoinsEntity.getFeeAmount());
            orderCoinDealDao.insert(detail);
            if (OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
                //如果是限价买入,撤单将USDT账户冻结金额返回
                String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
                MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
                if (ObjectUtil.isNotEmpty(walletCoin)) {
                    //手续费 = 开仓价*数量*手续费率
                    //返还金额=开仓价*未成交数量+手续费
                    BigDecimal returnBalance = orderCoinsEntity.getDealAmount();
                    walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
                    walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
                    memberWalletCoinDao.updateById(walletCoin);
                    // 流水记录
                    MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                    record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
                    record.setRemark(MemberAccountFlowEntity.REMARK_CANCEL + symbol + MemberAccountFlowEntity.REMARK_RETURNBALANCE + returnBalance);
                    record.setBalance(walletCoin.getAvailableBalance());
                    record.setMemberId(memberId);
                    record.setSymbol(symbol);
                    record.setPrice(returnBalance);
                    memberAccountFlowEntityDao.insert(record);
                    return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                }
            } else {
                //如果是限价卖出,撤单将对应的钱包冻结金额返回
                MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
                if (ObjectUtil.isNotEmpty(walletCoin)) {
                    BigDecimal returnBalance = orderCoinsEntity.getEntrustCnt();
                    walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
                    walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
                    memberWalletCoinDao.updateById(walletCoin);
                    // 流水记录
                    MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                    record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
                    record.setRemark(MemberAccountFlowEntity.REMARK_CANCEL + symbol + MemberAccountFlowEntity.REMARK_RETURNBALANCE + returnBalance);
                    record.setBalance(walletCoin.getAvailableBalance());
                    record.setMemberId(memberId);
                    record.setSymbol(symbol);
                    record.setPrice(walletCoin.getFrozenBalance());
                    memberAccountFlowEntityDao.insert(record);
                    return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                }
            }
        }
        return Result.fail(MessageSourceUtils.getString("order_service_0043"));
    }
    @Override
    public Result findAllWalletCoinOrder(FindAllWalletCoinOrderDto findAllWalletCoinOrderDto) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        Page<OrderCoinsDealEntity> page = new Page<>(findAllWalletCoinOrderDto.getPageNum(), findAllWalletCoinOrderDto.getPageSize());
        OrderCoinsDealEntity orderCoinsDealEntity = new OrderCoinsDealEntity();
        orderCoinsDealEntity.setMemberId(memberId);
        orderCoinsDealEntity.setSymbol(findAllWalletCoinOrderDto.getSymbol());
        IPage<OrderCoinsDealEntity> list = orderCoinDealDao.findAllWalletCoinOrderInPage(page, orderCoinsDealEntity);
        Page<OrderWalletCoinDealVo> pageEntityToPageVo = OrderWalletCoinDealMapper.INSTANCE.pageEntityToPageVo(list);
        return Result.ok(pageEntityToPageVo);
    }
    @Override
    public Result findWalletCoinOrder(Long orderId) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        OrderCoinsDealEntity selectWalletCoinOrder = orderCoinDealDao.selectWalletCoinOrder(orderId,memberId);
        OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVoOrder(selectWalletCoinOrder);
        return Result.ok(entityToVo);
    }
        return Result.ok(pageEntityToPageVo);
    }
    @Override
    public Result findCollect(String symbol, Integer type) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        if(type==1) {
            //添加自选
            MemberSelectSymbolsEntity symbols = new MemberSelectSymbolsEntity();
            symbols.setMemberId(memberId);
            symbols.setSymbol(symbol);
            memberSelectSymbolsDao.insert(symbols);
            return Result.ok(MessageSourceUtils.getString("order_service_0015"));
        }else {
            Map<String, Object> columnMap = new HashMap<>();
            columnMap.put("symbol", symbol);
            columnMap.put("member_id", memberId);
            memberSelectSymbolsDao.deleteByMap(columnMap);;
            return Result.ok(MessageSourceUtils.getString("order_service_0016"));
        }
    }
    @Override
    public Result findWalletCoinOrder(Long orderId) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        OrderCoinsDealEntity selectWalletCoinOrder = orderCoinDealDao.selectWalletCoinOrder(orderId, memberId);
        OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVoOrder(selectWalletCoinOrder);
        return Result.ok(entityToVo);
    }
    @Override
    public Result checkIsCollect(String symbol) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
        List<MemberSelectSymbolsEntity> selectSymbolByMemIdAndSymbol = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
        if(CollUtil.isNotEmpty(selectSymbolByMemIdAndSymbol)) {
            memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_YES);
        }else {
            memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_NO);
        }
        memberSelectSymbolsVo.setSymbol(symbol);
        return Result.ok(memberSelectSymbolsVo);
    }
    @Override
    public Result findCollect(String symbol, Integer type) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        if (type == 1) {
            //添加自选
            MemberSelectSymbolsEntity symbols = new MemberSelectSymbolsEntity();
            symbols.setMemberId(memberId);
            symbols.setSymbol(symbol);
            memberSelectSymbolsDao.insert(symbols);
            return Result.ok(MessageSourceUtils.getString("order_service_0015"));
        } else {
            Map<String, Object> columnMap = new HashMap<>();
            columnMap.put("symbol", symbol);
            columnMap.put("member_id", memberId);
            memberSelectSymbolsDao.deleteByMap(columnMap);
            ;
            return Result.ok(MessageSourceUtils.getString("order_service_0016"));
        }
    }
    @Override
    public Result findCollectList() {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        List<MemberSelectSymbolsEntity> selectByMap = memberSelectSymbolsDao.selectSymbolByMemId(memberId);
        FindCollectListVo findCollectListVo = new FindCollectListVo();
        List<MemberSelectSymbolsVo> arrayList = new ArrayList<>();
        if(CollUtil.isNotEmpty(selectByMap)) {
            for(MemberSelectSymbolsEntity memberSelectSymbolsEntity : selectByMap) {
                MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
                memberSelectSymbolsVo.setSymbol(memberSelectSymbolsEntity.getSymbol());
                arrayList.add(memberSelectSymbolsVo);
            }
        }
        findCollectListVo.setMemberSelectSymbolsVo(arrayList);
        return Result.ok(findCollectListVo);
    }
    @Override
    public Result checkIsCollect(String symbol) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
        List<MemberSelectSymbolsEntity> selectSymbolByMemIdAndSymbol = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
    @Override
    public Result searchSymbolResultList() {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        FindCollectListVo findCollectListVo = new FindCollectListVo();
        List<MemberSelectSymbolsVo> list = new ArrayList<>();
        Map<String, Object> columnMap = new HashMap<>();
        List<PlatformSymbolsCoinEntity> selectByMap = platformSymbolsCoinDao.selectByMap(columnMap);
        List<MemberSelectSymbolsEntity> selectSymbolByMemIdAndSymbol = memberSelectSymbolsDao.selectSymbolByMemId(memberId);
        for(PlatformSymbolsCoinEntity platformSymbolsCoinEntity : selectByMap) {
            MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
            memberSelectSymbolsVo.setSymbol(platformSymbolsCoinEntity.getName());
            if(CollUtil.isNotEmpty(selectSymbolByMemIdAndSymbol)) {
                for(MemberSelectSymbolsEntity memberSelectSymbolsEntity : selectSymbolByMemIdAndSymbol) {
                    if(platformSymbolsCoinEntity.getName().equals(memberSelectSymbolsEntity.getSymbol())) {
                        memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_YES);
                    }
                }
            }else {
                memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_NO);
            }
            list.add(memberSelectSymbolsVo);
        }
        findCollectListVo.setMemberSelectSymbolsVo(list);
        return Result.ok(findCollectListVo);
    }
        if (CollUtil.isNotEmpty(selectSymbolByMemIdAndSymbol)) {
            memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_YES);
        } else {
            memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_NO);
        }
        memberSelectSymbolsVo.setSymbol(symbol);
        return Result.ok(memberSelectSymbolsVo);
    }
    @Override
    public Result findCollectList() {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        List<MemberSelectSymbolsEntity> selectByMap = memberSelectSymbolsDao.selectSymbolByMemId(memberId);
        FindCollectListVo findCollectListVo = new FindCollectListVo();
        List<MemberSelectSymbolsVo> arrayList = new ArrayList<>();
        if (CollUtil.isNotEmpty(selectByMap)) {
            for (MemberSelectSymbolsEntity memberSelectSymbolsEntity : selectByMap) {
                MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
                memberSelectSymbolsVo.setSymbol(memberSelectSymbolsEntity.getSymbol());
                arrayList.add(memberSelectSymbolsVo);
            }
        }
        findCollectListVo.setMemberSelectSymbolsVo(arrayList);
        return Result.ok(findCollectListVo);
    }
    @Override
    public Result searchSymbolResultList() {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        FindCollectListVo findCollectListVo = new FindCollectListVo();
        List<MemberSelectSymbolsVo> list = new ArrayList<>();
        Map<String, Object> columnMap = new HashMap<>();
        List<PlatformSymbolsCoinEntity> selectByMap = platformSymbolsCoinDao.selectByMap(columnMap);
        List<MemberSelectSymbolsEntity> selectSymbolByMemIdAndSymbol = memberSelectSymbolsDao.selectSymbolByMemId(memberId);
        for (PlatformSymbolsCoinEntity platformSymbolsCoinEntity : selectByMap) {
            MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
            memberSelectSymbolsVo.setSymbol(platformSymbolsCoinEntity.getName());
            if (CollUtil.isNotEmpty(selectSymbolByMemIdAndSymbol)) {
                for (MemberSelectSymbolsEntity memberSelectSymbolsEntity : selectSymbolByMemIdAndSymbol) {
                    if (platformSymbolsCoinEntity.getName().equals(memberSelectSymbolsEntity.getSymbol())) {
                        memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_YES);
                    }
                }
            } else {
                memberSelectSymbolsVo.setIsCollect(MemberSelectSymbolsVo.ISCOLLECT_NO);
            }
            list.add(memberSelectSymbolsVo);
        }
        findCollectListVo.setMemberSelectSymbolsVo(list);
        return Result.ok(findCollectListVo);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void dealEntrustCoinOrder() {
        List<OrderCoinsEntity> list = orderCoinsDao.selectAllEntrustingCoinOrderList();
        if (CollUtil.isNotEmpty(list)) {
            for (OrderCoinsEntity orderCoinsEntity : list) {
                BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(orderCoinsEntity.getSymbol() + "/USDT")));
                // 下单时市场价
                BigDecimal markPrice = orderCoinsEntity.getMarkPrice();
                // 委托价
                BigDecimal entrustPrice = orderCoinsEntity.getEntrustPrice();
                //如果当时委托价小于市价
                if (entrustPrice.compareTo(markPrice) < 0) {
                    if (nowPrice.compareTo(entrustPrice) > 0) {
                        continue;
                    }
                } else {
                    //委托价大于市价
                    if (nowPrice.compareTo(entrustPrice) < 0) {
                        continue;
                    }
                }
                BigDecimal fee = entrustPrice.multiply(orderCoinsEntity.getEntrustCnt()).multiply(new BigDecimal("0.002")).setScale(8, BigDecimal.ROUND_HALF_UP);
                BigDecimal dealAmount = entrustPrice.multiply(orderCoinsEntity.getEntrustCnt());
                OrderCoinsDealEntity orderCoinsDealEntity = OrderCoinsDealMapper.INSTANCE.orderToOrderDeal(orderCoinsEntity);
                orderCoinsDealEntity.setDealAmount(dealAmount);
                orderCoinsDealEntity.setDealPrice(entrustPrice);
                orderCoinsDealEntity.setFeeAmount(fee);
                orderCoinsDealEntity.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
                orderCoinsDealEntity.setId(null);
                orderCoinDealDao.insert(orderCoinsDealEntity);
                orderCoinsDao.deleteById(orderCoinsEntity.getId());
                MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(orderCoinsEntity.getMemberId(), orderCoinsEntity.getSymbol());
                MemberWalletCoinEntity usdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(orderCoinsEntity.getMemberId(), "USDT");
                BigDecimal frozen = BigDecimal.ZERO;
                BigDecimal total = BigDecimal.ZERO;
                // 买入
                if (OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
                    BigDecimal newCoins = walletCoinEntity.getAvailableBalance().add(orderCoinsEntity.getEntrustCnt());
                    BigDecimal newCoinTotal = walletCoinEntity.getTotalBalance().add(orderCoinsEntity.getEntrustCnt());
                    walletCoinEntity.setAvailableBalance(newCoins);
                    walletCoinEntity.setTotalBalance(newCoinTotal);
                    memberWalletCoinDao.updateById(walletCoinEntity);
                    frozen = usdt.getFrozenBalance().subtract(dealAmount.add(fee));
                    total = usdt.getTotalBalance().subtract(dealAmount.add(fee));
                    usdt.setFrozenBalance(frozen);
                    usdt.setTotalBalance(total);
                    memberWalletCoinDao.updateById(usdt);
                } else {
                    walletCoinEntity.setFrozenBalance(walletCoinEntity.getFrozenBalance().subtract(orderCoinsEntity.getEntrustCnt()));
                    walletCoinEntity.setTotalBalance(walletCoinEntity.getTotalBalance().subtract(orderCoinsEntity.getEntrustCnt()));
                    memberWalletCoinDao.updateById(walletCoinEntity);
                    usdt.setAvailableBalance(usdt.getAvailableBalance().add(dealAmount.add(fee)));
                    usdt.setTotalBalance(usdt.getTotalBalance().add(dealAmount.add(fee)));
                    memberWalletCoinDao.updateById(usdt);
                }
            }
        }
    }
}
src/main/java/com/xcong/excoin/quartz/job/LoopExecutorJob.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.quartz.job;
import com.xcong.excoin.modules.coin.service.OrderCoinService;
import com.xcong.excoin.modules.contract.service.ContractHoldOrderService;
import com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao;
import lombok.extern.slf4j.Slf4j;
@@ -25,6 +26,9 @@
    @Resource
    private ContractHoldOrderService contractHoldOrderService;
    @Resource
    private OrderCoinService orderCoinService;
    /**
     * 更新快捷充值超时状态
     */
@@ -51,4 +55,16 @@
            log.error("#持仓费计算错误#", e);
        }
    }
    /**
     * 币币委托单成交
     */
    @Scheduled(cron = "0/5 * * * * ? ")
    public void coinEntrustToDeal() {
        try {
            orderCoinService.dealEntrustCoinOrder();
        } catch (Exception e) {
            log.error("#币币委托单成交错误#", e);
        }
    }
}
src/main/resources/application.yml
@@ -99,7 +99,7 @@
  newest-price-update-job: false
  #其他任务控制
  other-job: false
  loop-job: false
  loop-job: true
  rabbit-consumer: false
  block-job: false
src/main/resources/mapper/walletCoinOrder/OrderCoinsDao.xml
@@ -19,5 +19,11 @@
        
    SELECT *  FROM coins_order a where a.order_no= #{orderNo}  
    </select>
    <select id="selectAllEntrustingCoinOrderList" resultType="com.xcong.excoin.modules.coin.entity.OrderCoinsEntity">
        select *
        from coins_order
        where order_status=1
    </select>
</mapper>