<?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" >
|
|
<select id="selectByPrimaryKey" resultType="com.nq.pojo.UserPosition" parameterType="java.lang.Integer" >
|
select
|
*
|
from user_position
|
where id = #{id,jdbcType=INTEGER}
|
</select>
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
delete from user_position
|
where id = #{id,jdbcType=INTEGER}
|
</delete>
|
<insert id="insertSelective" parameterType="com.nq.pojo.UserPosition" >
|
insert into user_position
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="id != null" >
|
id,
|
</if>
|
<if test="positionType != null" >
|
position_type,
|
</if>
|
<if test="positionSn != null" >
|
position_sn,
|
</if>
|
<if test="userId != null" >
|
user_id,
|
</if>
|
<if test="nickName != null" >
|
nick_name,
|
</if>
|
<if test="agentId != null" >
|
agent_id,
|
</if>
|
<if test="stockName != null" >
|
stock_name,
|
</if>
|
<if test="stockCode != null" >
|
stock_code,
|
</if>
|
<if test="stockGid != null" >
|
stock_gid,
|
</if>
|
<if test="stockSpell != null" >
|
stock_spell,
|
</if>
|
<if test="buyOrderId != null" >
|
buy_order_id,
|
</if>
|
<if test="buyOrderTime != null" >
|
buy_order_time,
|
</if>
|
<if test="buyOrderPrice != null" >
|
buy_order_price,
|
</if>
|
<if test="sellOrderId != null" >
|
sell_order_id,
|
</if>
|
<if test="sellOrderTime != null" >
|
sell_order_time,
|
</if>
|
<if test="sellOrderPrice != null" >
|
sell_order_price,
|
</if>
|
<if test="profitTargetPrice != null" >
|
profit_target_price,
|
</if>
|
<if test="stopTargetPrice != null" >
|
stop_target_price,
|
</if>
|
<if test="orderDirection != null" >
|
order_direction,
|
</if>
|
<if test="orderNum != null" >
|
order_num,
|
</if>
|
<if test="orderLever != null" >
|
order_lever,
|
</if>
|
<if test="orderTotalPrice != null" >
|
order_total_price,
|
</if>
|
<if test="orderFee != null" >
|
order_fee,
|
</if>
|
<if test="orderSpread != null" >
|
order_spread,
|
</if>
|
<if test="orderStayFee != null" >
|
order_stay_fee,
|
</if>
|
<if test="orderStayDays != null" >
|
order_stay_days,
|
</if>
|
<if test="profitAndLose != null" >
|
profit_and_lose,
|
</if>
|
<if test="allProfitAndLose != null" >
|
all_profit_and_lose,
|
</if>
|
|
<if test="isLock != null" >
|
is_lock,
|
</if>
|
<if test="lockMsg != null" >
|
lock_msg,
|
</if>
|
<if test="stockPlate != null" >
|
stock_plate,
|
</if>
|
<if test="spreadRatePrice != null" >
|
spread_rate_price,
|
</if>
|
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="id != null" >
|
#{id,jdbcType=INTEGER},
|
</if>
|
<if test="positionType != null" >
|
#{positionType,jdbcType=INTEGER},
|
</if>
|
<if test="positionSn != null" >
|
#{positionSn,jdbcType=VARCHAR},
|
</if>
|
<if test="userId != null" >
|
#{userId,jdbcType=INTEGER},
|
</if>
|
<if test="nickName != null" >
|
#{nickName,jdbcType=VARCHAR},
|
</if>
|
<if test="agentId != null" >
|
#{agentId,jdbcType=INTEGER},
|
</if>
|
<if test="stockName != null" >
|
#{stockName,jdbcType=VARCHAR},
|
</if>
|
<if test="stockCode != null" >
|
#{stockCode,jdbcType=VARCHAR},
|
</if>
|
<if test="stockGid != null" >
|
#{stockGid,jdbcType=VARCHAR},
|
</if>
|
<if test="stockSpell != null" >
|
#{stockSpell,jdbcType=VARCHAR},
|
</if>
|
<if test="buyOrderId != null" >
|
#{buyOrderId,jdbcType=VARCHAR},
|
</if>
|
<if test="buyOrderTime != null" >
|
#{buyOrderTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="buyOrderPrice != null" >
|
#{buyOrderPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="sellOrderId != null" >
|
#{sellOrderId,jdbcType=VARCHAR},
|
</if>
|
<if test="sellOrderTime != null" >
|
#{sellOrderTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="sellOrderPrice != null" >
|
#{sellOrderPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="profitTargetPrice != null" >
|
#{profitTargetPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="stopTargetPrice != null" >
|
#{stopTargetPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="orderDirection != null" >
|
#{orderDirection,jdbcType=VARCHAR},
|
</if>
|
<if test="orderNum != null" >
|
#{orderNum,jdbcType=INTEGER},
|
</if>
|
<if test="orderLever != null" >
|
#{orderLever,jdbcType=INTEGER},
|
</if>
|
<if test="orderTotalPrice != null" >
|
#{orderTotalPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="orderFee != null" >
|
#{orderFee,jdbcType=DECIMAL},
|
</if>
|
<if test="orderSpread != null" >
|
#{orderSpread,jdbcType=DECIMAL},
|
</if>
|
<if test="orderStayFee != null" >
|
#{orderStayFee,jdbcType=DECIMAL},
|
</if>
|
<if test="orderStayDays != null" >
|
#{orderStayDays,jdbcType=INTEGER},
|
</if>
|
<if test="profitAndLose != null" >
|
#{profitAndLose,jdbcType=DECIMAL},
|
</if>
|
<if test="allProfitAndLose != null" >
|
#{allProfitAndLose,jdbcType=DECIMAL},
|
</if>
|
|
<if test="isLock != null" >
|
#{isLock,jdbcType=INTEGER},
|
</if>
|
<if test="lockMsg != null" >
|
#{lockMsg,jdbcType=VARCHAR},
|
</if>
|
|
<if test="stockPlate != null" >
|
#{stockPlate,jdbcType=VARCHAR},
|
</if>
|
<if test="spreadRatePrice != null" >
|
#{spreadRatePrice,jdbcType=DECIMAL},
|
</if>
|
|
</trim>
|
</insert>
|
<update id="updateByPrimaryKeySelective" parameterType="com.nq.pojo.UserPosition" >
|
update user_position
|
<set >
|
<if test="positionType != null" >
|
position_type = #{positionType,jdbcType=INTEGER},
|
</if>
|
<if test="positionSn != null" >
|
position_sn = #{positionSn,jdbcType=VARCHAR},
|
</if>
|
<if test="userId != null" >
|
user_id = #{userId,jdbcType=INTEGER},
|
</if>
|
<if test="nickName != null" >
|
nick_name = #{nickName,jdbcType=VARCHAR},
|
</if>
|
<if test="agentId != null" >
|
agent_id = #{agentId,jdbcType=INTEGER},
|
</if>
|
<if test="stockName != null" >
|
stock_name = #{stockName,jdbcType=VARCHAR},
|
</if>
|
<if test="stockCode != null" >
|
stock_code = #{stockCode,jdbcType=VARCHAR},
|
</if>
|
<if test="stockGid != null" >
|
stock_gid = #{stockGid,jdbcType=VARCHAR},
|
</if>
|
<if test="stockSpell != null" >
|
stock_spell = #{stockSpell,jdbcType=VARCHAR},
|
</if>
|
<if test="buyOrderId != null" >
|
buy_order_id = #{buyOrderId,jdbcType=VARCHAR},
|
</if>
|
<if test="buyOrderTime != null" >
|
buy_order_time = #{buyOrderTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="buyOrderPrice != null" >
|
buy_order_price = #{buyOrderPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="sellOrderId != null" >
|
sell_order_id = #{sellOrderId,jdbcType=VARCHAR},
|
</if>
|
<if test="sellOrderTime != null" >
|
sell_order_time = #{sellOrderTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="sellOrderPrice != null" >
|
sell_order_price = #{sellOrderPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="profitTargetPrice != null" >
|
profit_target_price = #{profitTargetPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="stopTargetPrice != null" >
|
stop_target_price = #{stopTargetPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="orderDirection != null" >
|
order_direction = #{orderDirection,jdbcType=VARCHAR},
|
</if>
|
<if test="orderNum != null" >
|
order_num = #{orderNum,jdbcType=INTEGER},
|
</if>
|
<if test="orderLever != null" >
|
order_lever = #{orderLever,jdbcType=INTEGER},
|
</if>
|
<if test="orderTotalPrice != null" >
|
order_total_price = #{orderTotalPrice,jdbcType=DECIMAL},
|
</if>
|
<if test="orderFee != null" >
|
order_fee = #{orderFee,jdbcType=DECIMAL},
|
</if>
|
<if test="orderSpread != null" >
|
order_spread = #{orderSpread,jdbcType=DECIMAL},
|
</if>
|
<if test="orderStayFee != null" >
|
order_stay_fee = #{orderStayFee,jdbcType=DECIMAL},
|
</if>
|
<if test="orderStayDays != null" >
|
order_stay_days = #{orderStayDays,jdbcType=INTEGER},
|
</if>
|
<if test="profitAndLose != null" >
|
profit_and_lose = #{profitAndLose,jdbcType=DECIMAL},
|
</if>
|
<if test="allProfitAndLose != null" >
|
all_profit_and_lose = #{allProfitAndLose,jdbcType=DECIMAL},
|
</if>
|
|
<if test="isLock != null" >
|
is_lock = #{isLock,jdbcType=INTEGER},
|
</if>
|
<if test="lockMsg != null" >
|
lock_msg = #{lockMsg,jdbcType=VARCHAR},
|
</if>
|
<if test="stockPlate != null" >
|
stock_plate = #{stockPlate,jdbcType=VARCHAR},
|
</if>
|
<if test="spreadRatePrice != null" >
|
spread_rate_price = #{spreadRatePrice,jdbcType=DECIMAL},
|
</if>
|
<if test="marginAdd != null" >
|
margin_add = #{marginAdd,jdbcType=DECIMAL},
|
</if>
|
</set>
|
where id = #{id,jdbcType=INTEGER}
|
</update>
|
|
<update id="updateByPrimaryKey" parameterType="com.nq.pojo.UserPosition" >
|
update user_position
|
set position_type = #{positionType,jdbcType=INTEGER},
|
position_sn = #{positionSn,jdbcType=VARCHAR},
|
user_id = #{userId,jdbcType=INTEGER},
|
nick_name = #{nickName,jdbcType=VARCHAR},
|
agent_id = #{agentId,jdbcType=INTEGER},
|
stock_name = #{stockName,jdbcType=VARCHAR},
|
stock_code = #{stockCode,jdbcType=VARCHAR},
|
stock_gid = #{stockGid,jdbcType=VARCHAR},
|
stock_spell = #{stockSpell,jdbcType=VARCHAR},
|
buy_order_id = #{buyOrderId,jdbcType=VARCHAR},
|
buy_order_time = #{buyOrderTime,jdbcType=TIMESTAMP},
|
buy_order_price = #{buyOrderPrice,jdbcType=DECIMAL},
|
sell_order_id = #{sellOrderId,jdbcType=VARCHAR},
|
sell_order_time = #{sellOrderTime,jdbcType=TIMESTAMP},
|
sell_order_price = #{sellOrderPrice,jdbcType=DECIMAL},
|
profit_target_price = #{profitTargetPrice,jdbcType=DECIMAL},
|
stop_target_price = #{stopTargetPrice,jdbcType=DECIMAL},
|
order_direction = #{orderDirection,jdbcType=VARCHAR},
|
order_num = #{orderNum,jdbcType=INTEGER},
|
order_lever = #{orderLever,jdbcType=INTEGER},
|
order_total_price = #{orderTotalPrice,jdbcType=DECIMAL},
|
order_fee = #{orderFee,jdbcType=DECIMAL},
|
order_spread = #{orderSpread,jdbcType=DECIMAL},
|
order_stay_fee = #{orderStayFee,jdbcType=DECIMAL},
|
order_stay_days = #{orderStayDays,jdbcType=INTEGER},
|
profit_and_lose = #{profitAndLose,jdbcType=DECIMAL},
|
all_profit_and_lose = #{allProfitAndLose,jdbcType=DECIMAL},
|
is_lock = #{isLock,jdbcType=INTEGER},
|
lock_msg = #{lockMsg,jdbcType=VARCHAR},
|
stock_plate = #{stockPlate,jdbcType=VARCHAR},
|
spread_rate_price = #{spreadRatePrice,jdbcType=DECIMAL}
|
where id = #{id,jdbcType=INTEGER}
|
</update>
|
|
|
<select id="findPositionBySn" resultType="com.nq.pojo.UserPosition" parameterType="string">
|
SELECT
|
*
|
FROM user_position
|
WHERE position_sn = #{positionSn}
|
</select>
|
|
<select id="findMyPositionByCodeAndSpell" parameterType="map" resultType="com.nq.pojo.UserPosition">
|
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="state == 1">
|
and sell_order_id is not null
|
</if>
|
</if>
|
<if test="stockCode != null and stockCode != '' ">
|
and stock_code like CONCAT('%','${stockCode}','%')
|
</if>
|
<if test="stockSpell != null and stockSpell != '' ">
|
and stock_spell like CONCAT('%','${stockSpell}','%')
|
</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" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
FROM user_position
|
WHERE user_id = #{userId} and sell_order_id is null
|
order by id desc
|
</select>
|
|
<select id="findPositionByUserIdAndSellId" parameterType="map" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
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" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
FROM user_position
|
<where>
|
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">
|
<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>
|
<if test="positionSn != null and positionSn != ''">
|
AND position_sn LIKE CONCAT('%', #{positionSn}, '%')
|
</if>
|
<if test="positionType != null and positionType != ''">
|
AND position_type = #{positionType}
|
</if>
|
<if test="beginTime != null and beginTime != ''">
|
AND sell_order_time <![CDATA[>=]]> #{beginTime}
|
</if>
|
<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
|
</select>
|
|
|
|
<select id="findAllStayPosition" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
FROM user_position
|
WHERE sell_order_id is NULL
|
</select>
|
|
|
<select id="findDistinctUserIdList" resultType="integer" >
|
SELECT DISTINCT user_id FROM user_position WHERE sell_order_id is null
|
</select>
|
|
<select id="CountPositionNum" parameterType="map" resultType="integer">
|
SELECT COUNT(id) FROM user_position
|
<where>
|
position_type = #{accountType}
|
<if test="state == 1">
|
and sell_order_id is null
|
</if>
|
<if test="state == 2">
|
and sell_order_id is not null
|
</if>
|
</where>
|
</select>
|
|
|
|
<select id="CountPositionProfitAndLose" resultType="decimal" parameterType="integer">
|
SELECT sum(profit_and_lose) FROM user_position
|
WHERE sell_order_id is not null
|
</select>
|
|
<select id="CountPositionAllProfitAndLose" resultType="decimal" parameterType="integer">
|
SELECT sum(all_profit_and_lose) FROM user_position
|
WHERE sell_order_id is not null
|
</select>
|
|
|
<delete id="deleteByUserId" parameterType="integer">
|
DELETE FROM user_position WHERE user_id = #{userId}
|
</delete>
|
|
|
<select id="findPositionByStockCodeAndTimes" resultType="com.nq.pojo.UserPosition" parameterType="map">
|
SELECT
|
*
|
FROM user_position
|
WHERE stock_code = #{stockCode} and user_id = #{userId}
|
and buy_order_time <![CDATA[>=]]> #{minuteTimes}
|
</select>
|
|
|
|
<select id="findPositionNumByTimes" parameterType="map" resultType="integer">
|
SELECT COALESCE(SUM(order_num),0)
|
FROM user_position
|
WHERE user_id = #{userId}
|
and buy_order_time <![CDATA[>=]]> #{beginDate}
|
</select>
|
|
<!--股票入仓最新top列表-->
|
<select id="findPositionTopList" parameterType="map" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
FROM user_position
|
<where>
|
1=1
|
</where>
|
ORDER BY id DESC
|
limit #{pageSize}
|
</select>
|
|
<!--根据股票代码查询用户最早入仓股票-->
|
<select id="findUserPositionByCode" parameterType="integer" resultType="com.nq.pojo.UserPosition">
|
SELECT
|
*
|
FROM user_position
|
<where>
|
user_id = #{userId}
|
and stock_code = #{stockCode}
|
and sell_order_price is null
|
</where>
|
ORDER BY id ASC
|
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_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="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>
|