From 7f63cc81ceeb02d9fd760709cea7abbce98bd346 Mon Sep 17 00:00:00 2001
From: dd <gitluke@outlook.com>
Date: Tue, 04 Nov 2025 00:47:15 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java |   52 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java b/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
index e832c11..c26b761 100644
--- a/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
@@ -12,9 +12,11 @@
 import com.github.pagehelper.PageInfo;
 import com.nq.common.ServerResponse;
 import com.nq.dao.*;
+import com.nq.enums.EStockType;
+import com.nq.enums.EUserAssets;
 import com.nq.pojo.*;
 import com.nq.service.*;
-import com.nq.utils.DateTimeUtil;
+import com.nq.utils.timeutil.DateTimeUtil;
 import com.nq.utils.PropertiesUtil;
 import com.nq.utils.redis.JsonUtil;
 import com.nq.utils.redis.RedisShardedPoolUtils;
@@ -65,6 +67,12 @@
     private ISiteSettingService iSiteSettingService;
     @Autowired
     private UserPositionMapper userPositionMapper;
+    @Autowired
+    private UserAssetsServices userAssetsServices;
+    @Autowired
+    private MoneyLogMapper  moneyLogMapper;
+    @Autowired
+    private UserAssetsMapper userAssetsMapper;
 
     @Override
     public ServerResponse addOrder(String stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, BigDecimal targetPrice, HttpServletRequest request) {
@@ -118,7 +126,7 @@
             User user = (User) JsonUtil.string2Obj(userJson, User.class);
 //            log.info("user:{}",user);
             if (user != null) {
-                List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()));
+                List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()).orderByDesc("add_time"));
 
                 List UserPendingorderList = new ArrayList();
 
@@ -136,7 +144,8 @@
                         nowPrice = String.valueOf(0);
                     }
                     userPendingorderVO.setNowPrice(new BigDecimal(nowPrice));
-                    userPendingorderVO.setStockName(stock.getStockName());
+//                    userPendingorderVO.setStockName(stock.getStockName());
+                    userPendingorderVO.setStockName(stock.getStockSpell());
                     userPendingorderVO.setStockId(stock.getStockCode());
                     userPendingorderVO.setBuyNum(userPendingorder.getBuyNum());
                     userPendingorderVO.setBuyType(userPendingorder.getBuyType());
@@ -163,7 +172,7 @@
         log.info("当前有挂单的用户数量 为 {}", Integer.valueOf(userPendingorders.size()));
         for (int i = 0; i < userPendingorders.size(); i++) {
             Integer userId = (Integer) userPendingorders.get(i).getUserId();
-            User user = this.userMapper.selectByPrimaryKey(userId);
+            User user = this.userMapper.selectById(userId);
             if (user == null) {
                 continue;
             }
@@ -172,7 +181,6 @@
                 continue;
             }
             log.info("用户id = {} 姓名 = {} 已挂单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPendingorders.size())});
-            BigDecimal enable_user_amt = user.getEnableAmt();
             BigDecimal all_freez_amt = new BigDecimal("0");
             String nowPrice = "";
             String code = "";
@@ -234,8 +242,6 @@
                                 SiteTaskLog siteTaskLog = new SiteTaskLog();
                                 siteTaskLog.setTaskType("股票挂单转持仓");
                                 String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
-                                String taskcnt = accountType + "-" + user.getRealName() + "挂单[达到目标价格] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 目标价格 = " + userPendingorder.getTargetPrice() + ",现价" + nowPrice + ", 涨跌:" + (userPendingorder.getBuyType().intValue() == 0 ? "涨" : "跌");
-                                siteTaskLog.setTaskCnt(taskcnt);
                                 String tasktarget = "此次挂单买入id:" + userPendingorder.getId();
                                 siteTaskLog.setTaskTarget(tasktarget);
                                 siteTaskLog.setAddTime(new Date());
@@ -260,8 +266,6 @@
                                 SiteTaskLog siteTaskLog = new SiteTaskLog();
                                 siteTaskLog.setTaskType("指数挂单转持仓");
                                 String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
-                                String taskcnt = accountType + "-" + user.getRealName() + "挂单[达到目标价格] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 目标价格 = " + userPendingorder.getTargetPrice() + ",现价" + nowPrice + ", 涨跌:" + (userPendingorder.getBuyType().intValue() == 0 ? "涨" : "跌");
-                                siteTaskLog.setTaskCnt(taskcnt);
                                 String tasktarget = "此次挂单买入id:" + userPendingorder.getId();
                                 siteTaskLog.setTaskTarget(tasktarget);
                                 siteTaskLog.setAddTime(new Date());
@@ -316,6 +320,36 @@
         return ServerResponse.createByErrorMsg("Please log in");
     }
 
+    public void delUserPendingorderTask() {
+        log.info("===========删除挂单任务开始==========");
+        List<UserPendingorder> userPendingorderList = this.userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("status",0));
+        for (UserPendingorder userPendingorder : userPendingorderList) {
+            //修改状态
+            userPendingorder.setStatus(2);
+            userPendingorderMapper.updateById(userPendingorder);
+            //退款
+            QueryWrapper<UserAssets>  queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("accect_type","US");
+            queryWrapper.eq("user_id",userPendingorder.getUserId());
+            UserAssets userAssets =  userAssetsMapper.selectOne(queryWrapper);
+            String before = userAssets.getAvailableBalance().toString();
+            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(userPendingorder.getBuyAmt()));
+            userAssetsMapper.updateById(userAssets);
+            MoneyLog moneyLog = new MoneyLog();
+            moneyLog.setDescs(EUserAssets.BUY_REFUND.getDesc());
+            moneyLog.setBeFore(before);
+            moneyLog.setAfter(userAssets.getAvailableBalance().toString());
+            moneyLog.setAmount(userAssets.getAvailableBalance().toString());
+            moneyLog.setAccectType("US");
+            moneyLog.setType(EUserAssets.BUY_REFUND.getCode());
+            moneyLog.setUserId(userPendingorder.getUserId()+"");
+            moneyLog.setSymbol(EStockType.getEStockTypeByCode("US").getSymbol());
+            moneyLog.setCreateTime(new Date());
+            moneyLogMapper.insert(moneyLog);
+        }
+        log.info("===========删除挂单任务结束==========");
+    }
+
 
     @Override
     public ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request) {

--
Gitblit v1.9.3