src/main/java/com/xcong/excoin/common/contants/AppContants.java
@@ -95,5 +95,5 @@ public static final String BASE_URL_L2 = "http://123.60.45.251"; public static final BigDecimal BASE_MIN_AMOUNT = new BigDecimal(100); public static final String OTC_ORDER_CANCEL_TIMES = "OTC_ORDER_CANCEL_TIMES_"; } src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java
@@ -11,6 +11,7 @@ import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo; import com.xcong.excoin.modules.otc.vo.OrderListVo; import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo; import com.xcong.excoin.utils.RedisUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcMarketBussinessServiceImpl.java
@@ -53,10 +53,16 @@ List<OtcOrder> unFinishOrders = otcOrderDao.selectOrderListForUser(member.getId(), 4); if (CollUtil.isNotEmpty(unFinishOrders)) { BigDecimal.valueOf(finishOrders.size() - unFinishOrders.size()).divide(BigDecimal.valueOf(finishOrders.size()), 2, BigDecimal.ROUND_DOWN); BigDecimal finishRatio = BigDecimal.valueOf(finishOrders.size() - unFinishOrders.size()).divide(BigDecimal.valueOf(finishOrders.size()), 4, BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)); if (setting.getCompletionRate().compareTo(finishRatio) > 0) { throw new GlobalException("条件未达标"); } } BigDecimal totalAmount = otcOrderDao.selectOrderTotalAmount(member.getId()); if (setting.getTotalAmount().compareTo(totalAmount) > 0) { throw new GlobalException("条件未达标"); } OtcMarketBussiness mb = this.baseMapper.selectMarketBussinessByMemberId(member.getId()); OtcMarketBussiness otcMb = new OtcMarketBussiness(); src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.excoin.common.LoginUserUtils; import com.xcong.excoin.common.contants.AppContants; import com.xcong.excoin.common.exception.GlobalException; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.common.system.service.CommonService; @@ -29,6 +30,7 @@ import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo; import com.xcong.excoin.modules.otc.vo.OrderListVo; import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo; import com.xcong.excoin.utils.RedisUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; @@ -43,7 +45,6 @@ @Service @RequiredArgsConstructor public class OtcOrderServiceImpl extends ServiceImpl<OtcOrderDao, OtcOrder> implements OtcOrderService { private final OtcMarketBussinessDao otcMarketBussinessDao; private final OtcEntrustOrderDao otcEntrustOrderDao; private final OtcOrderAppealDao otcOrderAppealDao; @@ -52,6 +53,8 @@ private final MemberDao memberDao; private final MemberPaymentMethodDao memberPaymentMethodDao; private final OtcBlackListDao otcBlackListDao; private final OtcSettingDao otcSettingDao; private final RedisUtils redisUtils; @Override @@ -69,6 +72,12 @@ if (!OtcEntrustOrder.ORDER_TYPE_S.equals(entrustOrder.getOrderType())) { throw new GlobalException("无法购买"); } OtcSetting setting = otcSettingDao.selectById(1L); String times = redisUtils.getString(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId()); if (setting.getCancellNum() <= Integer.parseInt(times)) { throw new GlobalException("订单取消次数过多, 限制交易24小时"); } if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) { @@ -142,6 +151,12 @@ if (!OtcEntrustOrder.ORDER_TYPE_B.equals(entrustOrder.getOrderType())) { throw new GlobalException("无法出售"); } OtcSetting setting = otcSettingDao.selectById(1L); String times = redisUtils.getString(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId()); if (setting.getCancellNum() <= Integer.parseInt(times)) { throw new GlobalException("订单取消次数过多, 限制交易24小时"); } if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) { @@ -392,6 +407,7 @@ @Override public void cancelOrder(Long id) { MemberEntity member = LoginUserUtils.getAppLoginUser(); OtcOrder otcOrder = this.baseMapper.selectById(id); if (otcOrder == null) { throw new GlobalException("订单不存在"); @@ -407,6 +423,20 @@ memberWalletCoinDao.subFrozenBalance(saleOrder.getMemberId(), wallet.getId(), saleOrder.getCoinAmount()); } OtcSetting setting = otcSettingDao.selectById(1L); String times = redisUtils.getString(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId()); if (StrUtil.isNotBlank(times)) { int i = Integer.parseInt(times); i++; if (i >= setting.getCancellNum()) { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId(), i, 86400); } else { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId(), i); } } else { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + member.getId(), 1, 86400); } otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount()); this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo()); } src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
@@ -4,15 +4,20 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.xcong.excoin.common.contants.AppContants; import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao; import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao; import com.xcong.excoin.modules.otc.dao.OtcOrderDao; import com.xcong.excoin.modules.otc.dao.OtcSettingDao; import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder; import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness; import com.xcong.excoin.modules.otc.entity.OtcOrder; import com.xcong.excoin.modules.otc.entity.OtcSetting; import com.xcong.excoin.modules.otc.service.OtcOrderService; import com.xcong.excoin.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -36,14 +41,17 @@ private OtcMarketBussinessDao otcMarketBussinessDao; @Autowired private MemberWalletCoinDao memberWalletCoinDao; @Autowired private OtcSettingDao otcSettingDao; @Autowired private RedisUtils redisUtils; @Scheduled(cron = "0/1 * * * * ? ") public void autoCancelOrder() { List<OtcOrder> otcOrders = otcOrderDao.selectOrderListWithStatusAndType(OtcEntrustOrder.ORDER_TYPE_B, OtcOrder.STATUS_SUBMIT); if (CollUtil.isNotEmpty(otcOrders)) { for (OtcOrder otcOrder : otcOrders) { long between = DateUtil.between(new Date(), DateUtil.offsetMinute(otcOrder.getCreateTime(), 30), DateUnit.SECOND, false); long between = DateUtil.between(new Date(), DateUtil.offsetMinute(otcOrder.getCreateTime(), 3), DateUnit.SECOND, false); if (between <= 0) { OtcOrder saleOrder = otcOrderDao.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S); @@ -54,6 +62,27 @@ otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount()); otcOrderDao.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo()); Long memberId; if (otcOrder.getMemberId().equals(otcOrder.getEntrustMemberId())) { memberId = otcOrder.getOppositeMemberId(); } else { memberId = otcOrder.getMemberId(); } OtcSetting setting = otcSettingDao.selectById(1L); String times = redisUtils.getString(AppContants.OTC_ORDER_CANCEL_TIMES + memberId); if (StrUtil.isNotBlank(times)) { int i = Integer.parseInt(times); i++; if (i >= setting.getCancellNum()) { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, i, 86400); } else { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, i); } } else { redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, 1, 86400); } } } }