From 96e443a77b1d425d3e536c288fc271fe182f1496 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 18 Jul 2025 18:31:44 +0800
Subject: [PATCH] app股票列表修改

---
 src/main/resources/mapper/UserPositionMapper.xml |  244 ++++++++++++++++++++++++++----------------------
 1 files changed, 130 insertions(+), 114 deletions(-)

diff --git a/src/main/resources/mapper/UserPositionMapper.xml b/src/main/resources/mapper/UserPositionMapper.xml
index f96e1da..34c6e59 100644
--- a/src/main/resources/mapper/UserPositionMapper.xml
+++ b/src/main/resources/mapper/UserPositionMapper.xml
@@ -1,55 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.nq.dao.UserPositionMapper" >
-  <resultMap id="BaseResultMap" type="com.nq.pojo.UserPosition" >
-    <constructor >
-      <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="position_type" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="position_sn" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="user_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="nick_name" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="agent_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="stock_name" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="stock_code" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="stock_gid" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="stock_spell" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="buy_order_id" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="buy_order_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
-      <arg column="buy_order_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="sell_order_id" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="sell_order_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
-      <arg column="sell_order_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="profit_target_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="stop_target_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="order_direction" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="order_num" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="order_lever" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="order_total_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="order_fee" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="order_spread" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="order_stay_fee" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="order_stay_days" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="profit_and_lose" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="all_profit_and_lose" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
 
-      <arg column="is_lock" jdbcType="INTEGER" javaType="java.lang.Integer" />
-      <arg column="lock_msg" jdbcType="VARCHAR" javaType="java.lang.String" />
-
-      <arg column="stock_plate" jdbcType="VARCHAR" javaType="java.lang.String" />
-      <arg column="spread_rate_price" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-      <arg column="margin_add" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
-    </constructor>
-  </resultMap>
-  <sql id="Base_Column_List" >
-    id, position_type, position_sn, user_id, nick_name, agent_id, stock_name, stock_code, 
-    stock_gid, stock_spell, buy_order_id, buy_order_time, buy_order_price, sell_order_id, 
-    sell_order_time, sell_order_price, profit_target_price, stop_target_price, order_direction, 
-    order_num, order_lever, order_total_price, order_fee, order_spread, order_stay_fee, 
-    order_stay_days, profit_and_lose, all_profit_and_lose,is_lock,lock_msg,stock_plate,spread_rate_price,margin_add
-  </sql>
-  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
+  <select id="selectByPrimaryKey" resultType="com.nq.pojo.UserPosition" parameterType="java.lang.Integer" >
     select 
-    <include refid="Base_Column_List" />
+   *
     from user_position
     where id = #{id,jdbcType=INTEGER}
   </select>
@@ -57,31 +12,6 @@
     delete from user_position
     where id = #{id,jdbcType=INTEGER}
   </delete>
-  <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.nq.pojo.UserPosition" >
-    insert into user_position (id, position_type, position_sn, 
-      user_id, nick_name, agent_id, 
-      stock_name, stock_code, stock_gid, 
-      stock_spell, buy_order_id, buy_order_time, 
-      buy_order_price, sell_order_id, sell_order_time, 
-      sell_order_price, profit_target_price, stop_target_price, 
-      order_direction, order_num, order_lever, 
-      order_total_price, order_fee, order_spread, 
-      order_stay_fee, order_stay_days, profit_and_lose, 
-      all_profit_and_lose, is_lock, lock_msg,stock_plate,spread_rate_price)
-    values (#{id,jdbcType=INTEGER}, #{positionType,jdbcType=INTEGER}, #{positionSn,jdbcType=VARCHAR}, 
-      #{userId,jdbcType=INTEGER}, #{nickName,jdbcType=VARCHAR}, #{agentId,jdbcType=INTEGER}, 
-      #{stockName,jdbcType=VARCHAR}, #{stockCode,jdbcType=VARCHAR}, #{stockGid,jdbcType=VARCHAR}, 
-      #{stockSpell,jdbcType=VARCHAR}, #{buyOrderId,jdbcType=VARCHAR}, #{buyOrderTime,jdbcType=TIMESTAMP}, 
-      #{buyOrderPrice,jdbcType=DECIMAL}, #{sellOrderId,jdbcType=VARCHAR}, #{sellOrderTime,jdbcType=TIMESTAMP}, 
-      #{sellOrderPrice,jdbcType=DECIMAL}, #{profitTargetPrice,jdbcType=DECIMAL}, #{stopTargetPrice,jdbcType=DECIMAL}, 
-      #{orderDirection,jdbcType=VARCHAR}, #{orderNum,jdbcType=INTEGER}, #{orderLever,jdbcType=INTEGER}, 
-      #{orderTotalPrice,jdbcType=DECIMAL}, #{orderFee,jdbcType=DECIMAL}, #{orderSpread,jdbcType=DECIMAL}, 
-      #{orderStayFee,jdbcType=DECIMAL}, #{orderStayDays,jdbcType=INTEGER}, #{profitAndLose,jdbcType=DECIMAL}, 
-      #{allProfitAndLose,jdbcType=DECIMAL}, #{isLock,jdbcType=INTEGER}, #{lockMsg,jdbcType=VARCHAR},
-      #{stockPlate,jdbcType=VARCHAR},#{spreadRatePrice,jdbcType=DECIMAL}
-      )
-  </insert>
-
   <insert id="insertSelective" parameterType="com.nq.pojo.UserPosition" >
     insert into user_position
     <trim prefix="(" suffix=")" suffixOverrides="," >
@@ -427,16 +357,16 @@
   </update>
 
 
-  <select id="findPositionBySn" resultMap="BaseResultMap" parameterType="string">
+  <select id="findPositionBySn" resultType="com.nq.pojo.UserPosition" parameterType="string">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     WHERE position_sn = #{positionSn}
   </select>
 
-  <select id="findMyPositionByCodeAndSpell" parameterType="map" resultMap="BaseResultMap">
+  <select id="findMyPositionByCodeAndSpell" parameterType="map" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     <where>
       user_id = #{uid}
@@ -454,62 +384,70 @@
       <if test="stockSpell != null and stockSpell != '' ">
         and stock_spell like CONCAT('%','${stockSpell}','%')
       </if>
-      <if test="stockType != null and stockType!= ''">
-        and stock_gid = #{stockType}
-      </if>
-
-
+<!--      <if test="stockType != null and stockType!= ''">-->
+<!--        and stock_gid = #{stockType}-->
+<!--      </if>-->
+      and position_type != 1
     </where>
     ORDER BY id DESC
   </select>
 
-  <select id="findPositionByUserIdAndSellIdIsNull" parameterType="integer" resultMap="BaseResultMap">
+  <select id="findPositionByUserIdAndSellIdIsNull" parameterType="integer" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     WHERE user_id = #{userId} and sell_order_id is null
     order by id desc
   </select>
 
-  <select id="findPositionByUserIdAndSellId" parameterType="map" resultMap="BaseResultMap">
+  <select id="findPositionByUserIdAndSellId" parameterType="map" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     WHERE user_id = #{userId} and sell_order_id is null and stock_gid = #{stockType}
     order by id desc
   </select>
 
 
-  <select id="listByAgent" parameterType="map" resultMap="BaseResultMap">
+  <select id="listByAgent" parameterType="map" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+   *
     FROM user_position
     <where>
-      <if test="searchId != null  ">
-        and agent_id = #{searchId}
+      1=1
+      <if test="ids != null and ids.size > 0">
+        AND agent_id IN
+        <foreach item="id" collection="ids" open="(" separator="," close=")">
+          #{id}
+        </foreach>
       </if>
-      <if test="state != null  ">
-        <if test="state == 0">
-          and sell_order_id is null
-        </if>
-        <if test="state == 1">
-          and sell_order_id is not null
-        </if>
+      <if test="state != null">
+        <choose>
+          <when test="state == 0">
+            AND sell_order_id IS NULL
+          </when>
+          <when test="state == 1">
+            AND sell_order_id IS NOT NULL
+          </when>
+        </choose>
       </if>
-      <if test="userId != null and userId != '' ">
-        and user_id = #{userId}
+      <if test="userId != null and userId != ''">
+        AND user_id = #{userId}
       </if>
-      <if test="positionSn != null and positionSn != '' ">
-        and position_sn like CONCAT('%','${positionSn}','%')
+      <if test="positionSn != null and positionSn != ''">
+        AND position_sn LIKE CONCAT('%', #{positionSn}, '%')
       </if>
-      <if test="positionType != null ">
-        and position_type = #{positionType}
+      <if test="positionType != null and positionType != ''">
+        AND position_type = #{positionType}
       </if>
-      <if test="beginTime != null ">
-        and sell_order_time <![CDATA[>=]]> #{beginTime}
+      <if test="beginTime != null and beginTime != ''">
+        AND sell_order_time <![CDATA[>=]]> #{beginTime}
       </if>
-      <if test="endTime != null ">
-        and sell_order_time <![CDATA[<=]]> #{endTime}
+      <if test="endTime != null and endTime != ''">
+        AND sell_order_time <![CDATA[<=]]> #{endTime}
+      </if>
+      <if test="phone != null and phone != ''">
+        AND user_id = (SELECT id FROM user WHERE phone = #{phone})
       </if>
     </where>
     ORDER BY id DESC
@@ -517,9 +455,9 @@
 
 
 
-  <select id="findAllStayPosition" resultMap="BaseResultMap">
+  <select id="findAllStayPosition" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+   *
     FROM user_position
     WHERE sell_order_id is NULL
   </select>
@@ -560,9 +498,9 @@
   </delete>
 
 
-  <select id="findPositionByStockCodeAndTimes" resultMap="BaseResultMap" parameterType="map">
+  <select id="findPositionByStockCodeAndTimes" resultType="com.nq.pojo.UserPosition" parameterType="map">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     WHERE stock_code = #{stockCode} and user_id = #{userId}
     and buy_order_time <![CDATA[>=]]> #{minuteTimes}
@@ -578,9 +516,9 @@
   </select>
 
   <!--股票入仓最新top列表-->
-  <select id="findPositionTopList" parameterType="map" resultMap="BaseResultMap">
+  <select id="findPositionTopList" parameterType="map" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+    *
     FROM user_position
     <where>
       1=1
@@ -590,9 +528,9 @@
   </select>
 
   <!--根据股票代码查询用户最早入仓股票-->
-  <select id="findUserPositionByCode" parameterType="integer" resultMap="BaseResultMap">
+  <select id="findUserPositionByCode" parameterType="integer" resultType="com.nq.pojo.UserPosition">
     SELECT
-    <include refid="Base_Column_List"/>
+   *
     FROM user_position
     <where>
       user_id = #{userId}
@@ -603,5 +541,83 @@
     limit 1
   </select>
 
+  <select id="findMyPositionByParam" parameterType="map" resultType="com.nq.vo.position.UserPositionVO">
+    SELECT a.* FROM (SELECT
+    *
+    FROM user_position
+    WHERE
+    user_id = #{uid}
+    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_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="state != null ">
+      <if test="state == 0">
+        and a.sell_order_id is null
+      </if>
+      <if test="state == 1">
+        and a.sell_order_id is not null
+      </if>
+    </if>
+    <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>
+    ORDER BY a.buy_order_time DESC
+  </select>
+
 </mapper>
 

--
Gitblit v1.9.3