From c054148b591113869b25c7c2f9b323fe1e5d132d Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Tue, 29 Jul 2025 18:32:41 +0800
Subject: [PATCH] 持仓列表修改

---
 src/main/resources/mapper/UserPositionMapper.xml |   92 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 78 insertions(+), 14 deletions(-)

diff --git a/src/main/resources/mapper/UserPositionMapper.xml b/src/main/resources/mapper/UserPositionMapper.xml
index 63c945d..dc41545 100644
--- a/src/main/resources/mapper/UserPositionMapper.xml
+++ b/src/main/resources/mapper/UserPositionMapper.xml
@@ -387,8 +387,7 @@
 <!--      <if test="stockType != null and stockType!= ''">-->
 <!--        and stock_gid = #{stockType}-->
 <!--      </if>-->
-
-
+      and position_type != 1
     </where>
     ORDER BY id DESC
   </select>
@@ -542,20 +541,85 @@
     limit 1
   </select>
 
-  <select id="getUserPositionDzList" resultType="com.nq.pojo.UserPosition">
-        SELECT u.*
-            FROM user_position u
-        LEFT JOIN user_position_check_dz dz ON dz.id = u.dz_id
-
-    <where>
-      <if test="userId != null ">
-        and u.user_id = #{userId}
+  <select id="findMyPositionByParam" parameterType="map" resultType="com.nq.vo.position.UserPositionVO">
+    SELECT a.* FROM (SELECT
+    *
+    FROM user_position
+    WHERE
+    user_id = #{uid}
+    <if test="state != null ">
+      <if test="state == 0">
+        and sell_order_id is null
       </if>
-      <if test="checkType != null ">
-        and dz.check_type = #{checkType}
+      <if test="state == 1">
+        and sell_order_id is not null
       </if>
-    </where>
-    ORDER BY u.buy_order_time DESC
+    </if>
+    UNION ALL
+    SELECT
+    p.id,
+    4 position_type,
+    null position_sn,
+    null user_id,
+    null nick_name,
+    null agent_id,
+    s.stock_name,
+    s.stock_code,
+    s.stock_type stock_gid,
+    s.stock_spell,
+    p.stock_ai_order_id buy_order_id,
+    p.creat_date buy_order_time,
+    p.stock_price buy_order_price,
+    null sell_order_id,
+    null sell_order_time,
+    p.cover_price sell_order_price,
+    null profit_target_price,
+    null stop_target_price,
+    null order_direction,
+    p.stock_num order_num,
+    null order_lever,
+    p.stock_num*p.stock_price order_total_price,
+    0 order_fee,
+    0 order_spread,
+    0 order_stay_fee,
+    null order_stay_days,
+    p.earnings profit_and_lose,
+    p.earnings all_profit_and_lose,
+    0 is_lock,
+    null lock_msg,
+    null stock_plate,
+    0 spread_rate_price,
+    0 margin_add,
+    null dz_id,
+    null new_id,
+    0 amount_to_be_covered
+    FROM stock_ai_order_position p
+    LEFT JOIN stock s ON s.id = p.stock_id
+    WHERE p.stock_ai_order_id IN (SELECT id FROM stock_ai_order WHERE
+    user_id = #{uid} and status='passed' )
+    <if test="state != null ">
+      <if test="state == 0">
+        and p.status = 0
+      </if>
+      <if test="state == 1">
+        and p.status = 1
+      </if>
+    </if>
+    ) a
+    WHERE a.position_type != 1
+    <if test="stockCode != null and stockCode != '' ">
+      and a.stock_code like CONCAT('%','${stockCode}','%')
+    </if>
+    <if test="stockSpell != null and stockSpell != '' ">
+      and a.stock_spell like CONCAT('%','${stockSpell}','%')
+    </if>
+    <if test="positionType != null">
+      and a.position_type = #{positionType}
+    </if>
+    <if test="stockType != null and stockType != '' ">
+      and a.stock_gid = #{stockType}
+    </if>
+    ORDER BY a.buy_order_time DESC
   </select>
 
 </mapper>

--
Gitblit v1.9.3