From 030c2e542bbe4053c279cc35fc09c1733729a574 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 22 Oct 2023 18:54:31 +0800 Subject: [PATCH] init --- .../auth/service/ClientLoginService.java | 1 + .../common/core/constant/ClientConstant.java | 8 +++- .../biz/impl/TradeTransactionServiceImpl.java | 4 -- .../ClientUserWalletController.java | 12 ++++++ .../controller/TradeOrderController.java | 5 +++ .../ruoyi/client/domain/ClientUserWallet.java | 11 ++++++ .../client/service/ITradeOrderService.java | 7 ++++ .../service/impl/TradeOrderServiceImpl.java | 39 ++++++++++++++++++- .../mapper/client/ClientUserAuthMapper.xml | 3 +- ruoyi-ui/src/views/client/auth/index.vue | 26 ++++++++----- .../src/views/client/wallet-flow/index.vue | 2 +- ruoyi-ui/src/views/client/wallet/index.vue | 3 +- .../src/views/fund/account/recharge/index.vue | 3 +- .../src/views/fund/account/withdraw/index.vue | 3 +- ruoyi-ui/src/views/fund/config/index.vue | 4 +- ruoyi-ui/src/views/fund/entrust/index.vue | 2 +- ruoyi-ui/src/views/fund/trade/index.vue | 2 +- ruoyi-ui/src/views/fund/withdraw/index.vue | 4 +- ruoyi-ui/src/views/market/config/index.vue | 2 +- ruoyi-ui/src/views/market/financial/index.vue | 2 +- ruoyi-ui/src/views/market/product/index.vue | 2 +- 21 files changed, 116 insertions(+), 29 deletions(-) diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/ClientLoginService.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/ClientLoginService.java index 57d2e2483..4f22aaea8 100644 --- a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/ClientLoginService.java +++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/ClientLoginService.java @@ -72,6 +72,7 @@ public void register(String username, String password, String phonenumber, Long clientUser.setPhonenumber(phonenumber); clientUser.setInviteCode(inviteCode); clientUser.setPassword(SecurityUtils.encryptPassword(password)); + logger.info("注册用户信息:{}", clientUser); R registerResult = remoteClientUserService.registerUserInfo(clientUser, SecurityConstants.INNER); if (R.FAIL == registerResult.getCode()) { diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ClientConstant.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ClientConstant.java index 37792c670..e87ee7ffc 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ClientConstant.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ClientConstant.java @@ -28,6 +28,12 @@ public class ClientConstant { public static final Long ENTRUST_SUCCESS = 1L; - public static final Long ENTRUST_CANCLE = 2L; + public static final Long ENTRUST_CANCEL = 2L; + + public static final Long POSITION_PENDING = 0L; + + public static final Long POSITION_CLOSED = 1L; + + public static final Long LIQUIDATION = 2L; } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/biz/impl/TradeTransactionServiceImpl.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/biz/impl/TradeTransactionServiceImpl.java index 6f6ca5175..9a1f8c306 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/biz/impl/TradeTransactionServiceImpl.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/biz/impl/TradeTransactionServiceImpl.java @@ -43,7 +43,6 @@ public class TradeTransactionServiceImpl implements TradeTransactionService { @Override public void tradeOrderPriceChange(String productCode) { - log.info("产品{}价格发生波动,开始检查订单", productCode); String productPriceCacheKey = String.format(PRODUCT_PRICE_INFO_KEY, productCode, DateUtils.dateTime()); JSONObject price = redisService.getCacheObject(productPriceCacheKey); TradeOrder tradeOrder = new TradeOrder(); @@ -114,7 +113,6 @@ private void tradeOrderDelivery(TradeOrder tradeOrder) { @Override public void entrustOrderPriceChange(String productCode) { - log.info("产品{}价格发生波动,开始检查订单", productCode); String productPriceCacheKey = String.format(PRODUCT_PRICE_INFO_KEY, productCode, DateUtils.dateTime()); JSONObject price = redisService.getCacheObject(productPriceCacheKey); EntrustOrder entrustOrder = new EntrustOrder(); @@ -140,7 +138,6 @@ protected void processIfBuy(EntrustOrder entrustOrder, BigDecimal currentPrice) if (entrustOrder.getTradePrice().compareTo(currentPrice) < 0) { return; } - log.info("委托买入订单{}即将交割", entrustOrder.getOrderId()); EntrustOrder updateOrder = new EntrustOrder(); updateOrder.setId(entrustOrder.getId()); updateOrder.setStatus(1L); @@ -154,7 +151,6 @@ protected void processIfSell(EntrustOrder entrustOrder, BigDecimal currentPrice) if (entrustOrder.getTradePrice().compareTo(currentPrice) > 0) { return; } - log.info("委托卖出订单{}即将交割", entrustOrder.getOrderId()); EntrustOrder updateOrder = new EntrustOrder(); updateOrder.setId(entrustOrder.getId()); updateOrder.setStatus(1L); diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserWalletController.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserWalletController.java index f5faae460..d1ad3499f 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserWalletController.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserWalletController.java @@ -4,6 +4,8 @@ import java.io.IOException; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.client.domain.ClientUser; +import com.ruoyi.client.service.IClientUserService; import com.ruoyi.common.core.domain.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -37,6 +39,9 @@ public class ClientUserWalletController extends BaseController @Autowired private IClientUserWalletService clientUserWalletService; + @Autowired + private IClientUserService clientUserService; + /** * 查询用户资产列表 */ @@ -46,6 +51,13 @@ public TableDataInfo list(ClientUserWallet clientUserWallet) { startPage(); List list = clientUserWalletService.selectClientUserWalletList(clientUserWallet); + for (ClientUserWallet wallet: list) { + ClientUser clientUser = clientUserService.selectClientUserByUserId(wallet.getUserId()); + if (clientUser == null) { + continue; + } + wallet.setUserName(clientUser.getUserName()); + } return getDataTable(list); } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/TradeOrderController.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/TradeOrderController.java index 72734171b..2da77bd22 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/TradeOrderController.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/TradeOrderController.java @@ -120,4 +120,9 @@ public AjaxResult orderPriceChange(@RequestParam("productCode") String productCo return AjaxResult.success(); } + @PostMapping("/sellOut") + public AjaxResult sellOut(@RequestBody TradeOrder tradeOrder) { + return AjaxResult.success(tradeOrderService.sellOut(tradeOrder)); + } + } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/domain/ClientUserWallet.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/domain/ClientUserWallet.java index 084146ba9..fcbaa0c44 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/domain/ClientUserWallet.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/domain/ClientUserWallet.java @@ -24,6 +24,9 @@ public class ClientUserWallet extends BaseEntity @Excel(name = "用户id") private Long userId; + @Excel(name = "用户名") + private String userName; + /** 总金额 */ @Excel(name = "总金额") private BigDecimal totalAmount; @@ -94,6 +97,14 @@ public Long getDelFlag() return delFlag; } + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/ITradeOrderService.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/ITradeOrderService.java index 72874abfc..c47f57f6e 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/ITradeOrderService.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/ITradeOrderService.java @@ -64,4 +64,11 @@ public interface ITradeOrderService * @param tradeOrder */ public boolean submit(TradeOrder tradeOrder); + + /** + * 平仓 + * @param tradeOrder + * @return + */ + public boolean sellOut(TradeOrder tradeOrder); } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/TradeOrderServiceImpl.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/TradeOrderServiceImpl.java index d67834ca2..7fad46a3b 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/TradeOrderServiceImpl.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/TradeOrderServiceImpl.java @@ -1,5 +1,7 @@ package com.ruoyi.client.service.impl; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import java.util.List; @@ -10,6 +12,7 @@ import com.ruoyi.common.core.context.SecurityContextHolder; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.uuid.UUID; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.market.api.RemoteProductInfoService; @@ -25,7 +28,7 @@ import javax.annotation.Resource; -import static com.ruoyi.common.core.constant.MarketConstant.PRODUCT_PRICE_INFO_KEY; +import static com.ruoyi.common.core.constant.MarketConstant.*; /** * 交易订单Service业务层处理 @@ -151,6 +154,40 @@ public boolean submit(TradeOrder tradeOrder) { return true; } + @Override + public boolean sellOut(TradeOrder tradeOrder) { + TradeOrder existOrder = tradeOrderMapper.selectTradeOrderById(tradeOrder.getId()); + if (existOrder == null) { + throw new IllegalArgumentException("Order is not exist"); + } + if (!ClientConstant.POSITION_PENDING.equals(existOrder.getStatus())) { + throw new IllegalArgumentException("Order status is not correct"); + } + String productPriceCacheKey = String.format(PRODUCT_PRICE_INFO_KEY, existOrder.getProductCode(), DateUtils.dateTime()); + JSONObject price = redisService.getCacheObject(productPriceCacheKey); + BigDecimal currentPrice = price.getBigDecimal("currentPrice"); + TradeOrder updateOrder = new TradeOrder(); + if (StringUtils.equals(BUY, tradeOrder.getTradeDirect())) { + updateOrder.setIncome(currentPrice.subtract(existOrder.getTradePrice()).multiply(existOrder.getSheetNum()).setScale(6, RoundingMode.HALF_UP)); + } else { + updateOrder.setIncome(existOrder.getTradePrice().subtract(currentPrice).multiply(existOrder.getSheetNum()).setScale(6, RoundingMode.HALF_UP)); + } + updateOrder.setStatus(1L); + updateOrder.setDeliveryAmount(currentPrice.multiply(existOrder.getSheetNum()).setScale(6, RoundingMode.HALF_UP)); + updateOrder.setDeliveryPrice(currentPrice); + updateOrder.setRemark("止盈平仓"); + updateTradeOrder(updateOrder); + clientUserWalletService.balanceChange( + existOrder.getUserId(), + "system", + updateOrder.getId(), + "USD", + updateOrder.getIncome(), + ClientConstant.INCREASE + ); + return true; + } + @Transactional(rollbackFor = Exception.class) public void generateOrder(TradeOrder tradeOrder) { tradeOrder.setStatus(0L); diff --git a/ruoyi-modules/ruoyi-client/src/main/resources/mapper/client/ClientUserAuthMapper.xml b/ruoyi-modules/ruoyi-client/src/main/resources/mapper/client/ClientUserAuthMapper.xml index c6d5b718e..9a881c1d0 100644 --- a/ruoyi-modules/ruoyi-client/src/main/resources/mapper/client/ClientUserAuthMapper.xml +++ b/ruoyi-modules/ruoyi-client/src/main/resources/mapper/client/ClientUserAuthMapper.xml @@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"