<?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.ruoyi.stocksystem.mapper.StocksMapper" >
<resultMap type= "Stocks" id= "StocksResult" >
<result property= "id" column= "id" />
<result property= "code" column= "code" />
<result property= "name" column= "name" />
<result property= "blemind2" column= "blemind2" />
<result property= "blemind3" column= "blemind3" />
<result property= "listdate" column= "listdate" />
<result property= "tradeDay" column= "trade_day" />
<result property= "stradeDay" column= "strade_day" />
<result property= "open" column= "open" />
<result property= "close" column= "close" />
<result property= "high" column= "high" />
<result property= "low" column= "low" />
<result property= "islimit" column= "islimit" />
<result property= "isdrop" column= "isdrop" />
<result property= "differrange" column= "differrange" />
<result property= "tradeDays" column= "trade_days" />
<result property= "volumn" column= "volumn" />
<result property= "amount" column= "amount" />
<result property= "differrange10" column= "differrange10" />
<result property= "differrange20" column= "differrange20" />
<result property= "differrange60" column= "differrange60" />
<result property= "differrange3" column= "differrange3" />
<result property= "differrange5" column= "differrange5" />
<result property= "differrange15" column= "differrange15" />
<result property= "differrange30" column= "differrange30" />
<result property= "avgVolume20" column= "avg_volume20" />
<result property= "freefloatMarketValue" column= "freefloat_market_value" />
<result property= "totalMarketValue" column= "total_market_value" />
<result property= "agenciesHold" column= "agencies_hold" />
<result property= "blemindCount" column= "blemind_count" />
<result property= "listdate" column= "listdate" />
<result property= "blemindsCount" column= "blemindsCount" />
<result property= "orderParam" column= "orderParam" />
</resultMap>
<resultMap id= "StocksStockBasicResult" type= "Stocks" extends= "StocksResult" >
<collection property= "stockBasicList" notNullColumn= "sub_id" javaType= "java.util.List" resultMap= "StockBasicResult" />
</resultMap>
<sql id= "selectStocksVo" >
select id, code, trade_day, open, close, differrange, trade_days, volumn, amount, differrange10, differrange20, differrange60, avg_volume20, freefloat_market_value, total_market_value, agencies_hold from stocks
</sql>
<select id= "selectStocksList" parameterType= "Stocks" resultMap= "StocksResult" >
<include refid= "selectStocksVo" />
<where >
<if test= "code != null and code != ''" > and code = #{code}</if>
<if test= "tradeDay != null " > and trade_day = #{tradeDay}</if>
<if test= "open != null " > and open = #{open}</if>
<if test= "close != null " > and close = #{close}</if>
<if test= "differrange != null " > and differrange = #{differrange}</if>
<if test= "tradeDays != null " > and trade_days = #{tradeDays}</if>
<if test= "volumn != null " > and volumn = #{volumn}</if>
<if test= "amount != null " > and amount = #{amount}</if>
<if test= "differrange10 != null " > and differrange10 = #{differrange10}</if>
<if test= "differrange20 != null " > and differrange20 = #{differrange20}</if>
<if test= "differrange60 != null " > and differrange60 = #{differrange60}</if>
<if test= "avgVolume20 != null " > and avg_volume20 = #{avgVolume20}</if>
<if test= "freefloatMarketValue != null " > and freefloat_market_value = #{freefloatMarketValue}</if>
<if test= "totalMarketValue != null " > and total_market_value = #{totalMarketValue}</if>
<if test= "agenciesHold != null " > and agencies_hold = #{agenciesHold}</if>
</where>
</select>
<!--
<select id= "selectStocksListB" parameterType= "Stocks" resultMap= "StocksResult" >
select a.code , a.trade_day , a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,
b.name as name, b.blemind2 as blemind2, b.blemind3 as blemind3, b.listdate as listdate
from stocks a
left join stock_basis b on b.code = a.code
where a.trade_day = #{tradeDay}
</select>
-->
<select id= "selectStocksListB" parameterType= "Stocks" resultMap= "StocksResult" >
select a.code , a.trade_day , a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.differrange3, a.differrange5, a.differrange15, a.differrange30, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,b.name as name, b.blemind2 as blemind2, b.blemind3 as blemind3, b.listdate as listdate from
(select s.code , s.trade_day , s.open, s.close, s.differrange, s.trade_days, s.volumn, s.amount, s.differrange10, s.differrange20, s.differrange60, st.differrange3, st.differrange5, st.differrange15, st.differrange30, s.avg_volume20, s.freefloat_market_value, s.total_market_value, s.agencies_hold
from stocks s,stocks_tmp st where s.`code` = st.`code` and s.trade_day = st.trade_day) a
left join stock_basis b on b.code = a.code
where a.trade_day = #{tradeDay}
</select>
<select id= "selectStrongStocksList" parameterType= "Stocks" resultMap= "StocksResult" >
select trade_day , code,islimit, isdrop from stocks where trade_day BETWEEN #{stradeDay} and #{tradeDay} and islimit = #{islimit} and isdrop = #{isdrop} and trade_days > 30 ORDER BY code ,trade_day DESC;
</select>
<select id= "selectLimitStocksList" parameterType= "Stocks" resultMap= "StocksResult" >
select trade_day , code,islimit, isdrop from stocks where trade_day = #{tradeDay} and islimit = #{islimit} and isdrop = #{isdrop} ORDER BY code DESC;
</select>
<select id= "selectStocksListSortA" parameterType= "Stocks" resultMap= "StocksResult" >
select a.code , a.trade_day , a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,
b.name as name, b.blemind2 as blemind2, b.blemind3 as blemind3, b.listdate as listdate
from stocks a
left join stock_basis b on b.code = a.code
<where >
<if test= "tradeDay != null " > and a.trade_day = #{tradeDay}</if>
<if test= "tradeDays != null " > and a.trade_days >= #{tradeDays}</if>
<if test= "differrange10 != null " > and a.differrange10 = #{differrange10}</if>
<if test= "differrange20 != null " > and a.differrange20 = #{differrange20}</if>
<if test= "differrange60 != null " > and a.differrange60 = #{differrange60}</if>
<if test= "agenciesHold != null " > and a.agencies_hold >= #{agenciesHold}</if>
</where>
</select>
<select id= "selectStocksListSort" parameterType= "Stocks" resultMap= "StocksResult" >
select a.code , a.trade_day , a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.differrange3, a.differrange5, a.differrange15, a.differrange30, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,b.name as name, b.blemind2 as blemind2, b.blemind3 as blemind3, b.listdate as listdate from
(select s.code , s.trade_day , s.open, s.close, s.differrange, s.trade_days, s.volumn, s.amount, s.differrange10, s.differrange20, s.differrange60, st.differrange3, st.differrange5, st.differrange15, st.differrange30, s.avg_volume20, s.freefloat_market_value, s.total_market_value, s.agencies_hold
from stocks s,stocks_tmp st where s.`code` = st.`code` and s.trade_day = st.trade_day) a
left join stock_basis b on b.code = a.code
<where >
<if test= "tradeDay != null " > and a.trade_day = #{tradeDay}</if>
<if test= "tradeDays != null " > and a.trade_days >= #{tradeDays}</if>
<if test= "differrange10 != null " > and a.differrange10 = #{differrange10}</if>
<if test= "differrange20 != null " > and a.differrange20 = #{differrange20}</if>
<if test= "differrange60 != null " > and a.differrange60 = #{differrange60}</if>
<if test= "agenciesHold != null " > and a.agencies_hold >= #{agenciesHold}</if>
</where>
order by ${orderParam} desc
</select>
<select id= "selectGroupStocksList" parameterType= "Stocks" resultMap= "StocksResult" >
select blemind2 ,COUNT(blemind2) as blemind_count from (select s.code, sb.blemind2 as blemind2 from stocks s, stock_basis sb WHERE s.`code` = sb.`code` and s.trade_day = #{tradeDay}) temp GROUP BY blemind2 ORDER BY blemind_count DESC
</select>
<!--
<select id= "selectStocksById" parameterType= "Long" resultMap= "StocksStockBasicResult" >
select a.id, a.code, a.trade_day, a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,
b.id as sub_id, b.code as sub_code, b.name as sub_name, b.blemind2 as sub_blemind2, b.blemind3 as sub_blemind3, b.listdate as sub_listdate
from stocks a
left join stock_basis b on b.code = a.id
where a.id = #{id}
</select>
-->
<select id= "selectStocksById" parameterType= "Long" resultMap= "StocksStockBasicResult" >
select a.code , a.trade_day , a.open, a.close, a.differrange, a.trade_days, a.volumn, a.amount, a.differrange10, a.differrange20, a.differrange60, a.differrange3, a.differrange5, a.differrange15, a.differrange30, a.avg_volume20, a.freefloat_market_value, a.total_market_value, a.agencies_hold,b.name as name, b.blemind2 as blemind2, b.blemind3 as blemind3, b.listdate as listdate from
(select s.code , s.trade_day , s.open, s.close, s.differrange, s.trade_days, s.volumn, s.amount, s.differrange10, s.differrange20, s.differrange60, st.differrange3, st.differrange5, st.differrange15, st.differrange30, s.avg_volume20, s.freefloat_market_value, s.total_market_value, s.agencies_hold
from stocks s,stocks_tmp st where s.`code` = st.`code` and s.trade_day = st.trade_day) a
left join stock_basis b on b.code = a.id
where a.id = #{id}
</select>
<select id= "selectStocksByCode" parameterType= "Stocks" resultMap= "StocksResult" >
select id, code, trade_day, open, close, differrange, trade_days, volumn, amount, differrange10, differrange20, differrange60, avg_volume20, freefloat_market_value, total_market_value, agencies_hold from stocks where code = #{code} and trade_day = #{tradeDay}
</select>
<insert id= "insertStocks" parameterType= "Stocks" useGeneratedKeys= "true" keyProperty= "id" >
insert into stocks
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "code != null and code != ''" > code,</if>
<if test= "tradeDay != null" > trade_day,</if>
<if test= "open != null" > open,</if>
<if test= "close != null" > close,</if>
<if test= "high != null" > high,</if>
<if test= "low != null" > low,</if>
<if test= "islimit != null" > islimit,</if>
<if test= "isdrop != null" > isdrop,</if>
<if test= "differrange != null" > differrange,</if>
<if test= "tradeDays != null" > trade_days,</if>
<if test= "volumn != null" > volumn,</if>
<if test= "amount != null" > amount,</if>
<if test= "differrange10 != null" > differrange10,</if>
<if test= "differrange20 != null" > differrange20,</if>
<if test= "differrange60 != null" > differrange60,</if>
<if test= "avgVolume20 != null" > avg_volume20,</if>
<if test= "freefloatMarketValue != null" > freefloat_market_value,</if>
<if test= "totalMarketValue != null" > total_market_value,</if>
<if test= "agenciesHold != null" > agencies_hold,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "code != null and code != ''" > #{code},</if>
<if test= "tradeDay != null" > #{tradeDay},</if>
<if test= "open != null" > #{open},</if>
<if test= "close != null" > #{close},</if>
<if test= "high != null" > #{high},</if>
<if test= "low != null" > #{low},</if>
<if test= "islimit != null" > #{islimit},</if>
<if test= "isdrop != null" > #{isdrop},</if>
<if test= "differrange != null" > #{differrange},</if>
<if test= "tradeDays != null" > #{tradeDays},</if>
<if test= "volumn != null" > #{volumn},</if>
<if test= "amount != null" > #{amount},</if>
<if test= "differrange10 != null" > #{differrange10},</if>
<if test= "differrange20 != null" > #{differrange20},</if>
<if test= "differrange60 != null" > #{differrange60},</if>
<if test= "avgVolume20 != null" > #{avgVolume20},</if>
<if test= "freefloatMarketValue != null" > #{freefloatMarketValue},</if>
<if test= "totalMarketValue != null" > #{totalMarketValue},</if>
<if test= "agenciesHold != null" > #{agenciesHold},</if>
</trim>
</insert>
<update id= "updateStocks" parameterType= "Stocks" >
update stocks
<trim prefix= "SET" suffixOverrides= "," >
<if test= "code != null and code != ''" > code = #{code},</if>
<if test= "tradeDay != null" > trade_day = #{tradeDay},</if>
<if test= "open != null" > open = #{open},</if>
<if test= "close != null" > close = #{close},</if>
<if test= "high != null" > high = #{high},</if>
<if test= "low != null" > low = #{low},</if>
<if test= "islimit != null" > islimit = #{islimit},</if>
<if test= "isdrop != null" > isdrop = #{isdrop},</if>
<if test= "differrange != null" > differrange = #{differrange},</if>
<if test= "tradeDays != null" > trade_days = #{tradeDays},</if>
<if test= "volumn != null" > volumn = #{volumn},</if>
<if test= "amount != null" > amount = #{amount},</if>
<if test= "differrange10 != null" > differrange10 = #{differrange10},</if>
<if test= "differrange20 != null" > differrange20 = #{differrange20},</if>
<if test= "differrange60 != null" > differrange60 = #{differrange60},</if>
<if test= "avgVolume20 != null" > avg_volume20 = #{avgVolume20},</if>
<if test= "freefloatMarketValue != null" > freefloat_market_value = #{freefloatMarketValue},</if>
<if test= "totalMarketValue != null" > total_market_value = #{totalMarketValue},</if>
<if test= "agenciesHold != null" > agencies_hold = #{agenciesHold},</if>
</trim>
where trade_day = #{tradeDay} and code = #{code}
</update>
<delete id= "deleteStocksById" parameterType= "Long" >
delete from stocks where id = #{id}
</delete>
<delete id= "deleteStocksByIds" parameterType= "String" >
delete from stocks where id in
<foreach item= "id" collection= "array" open= "(" separator= "," close= ")" >
#{id}
</foreach>
</delete>
<delete id= "deleteStockBasicByCodes" parameterType= "String" >
delete from stock_basis where code in
<foreach item= "code" collection= "array" open= "(" separator= "," close= ")" >
#{code}
</foreach>
</delete>
<delete id= "deleteStockBasicByCode" parameterType= "Long" >
delete from stock_basis where code = #{code}
</delete>
<insert id= "batchStockBasic" >
insert into stock_basis( id, code, name, blemind2, blemind3, listdate) values
<foreach item= "item" index= "index" collection= "list" separator= "," >
( #{item.id}, #{item.code}, #{item.name}, #{item.blemind2}, #{item.blemind3}, #{item.listdate})
</foreach>
</insert>
<select id= "selectStockBasicByCode" parameterType= "String" resultMap= "StocksResult" >
select name, code, blemind2, blemind3 from stock_basis where code = #{code}
</select>
<select id= "selectStockBasicList" parameterType= "Stocks" resultMap= "StocksResult" >
select name, code, blemind2, blemind3 from stock_basis
</select>
<insert id= "insertStockBasic" parameterType= "Stocks" useGeneratedKeys= "true" keyProperty= "id" >
insert into stock_basis
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "code != null" > code,</if>
<if test= "name != null" > name,</if>
<if test= "blemind2 != null" > blemind2,</if>
<if test= "blemind3 != null" > blemind3,</if>
<if test= "listdate != null" > listdate,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "code != null" > #{code},</if>
<if test= "name != null" > #{name},</if>
<if test= "blemind2 != null" > #{blemind2},</if>
<if test= "blemind3 != null" > #{blemind3},</if>
<if test= "listdate != null" > #{listdate},</if>
</trim>
</insert>
<update id= "updateStockBasic" parameterType= "Stocks" >
update stock_basis
<trim prefix= "SET" suffixOverrides= "," >
<if test= "code != null" > code = #{code},</if>
<if test= "name != null" > name = #{name},</if>
<if test= "blemind2 != null" > blemind2 = #{blemind2},</if>
<if test= "blemind3 != null" > blemind3 = #{blemind3},</if>
<if test= "listdate != null" > listdate = #{listdate},</if>
</trim>
where code = #{code}
</update>
<select id= "selectStocksDistributionSubtract" parameterType= "Stocks" resultType= "int" >
select count(code) as dcount from stocks
<where >
<if test= "tradeDay != null " > and trade_day = #{tradeDay}</if>
<if test= "differrange != null " > and differrange > #{differrange}</if>
</where>
</select>
<select id= "selectStocksDistributionEqual" parameterType= "Stocks" resultType= "int" >
select count(code) as dcount from stocks
<where >
<if test= "tradeDay != null " > and trade_day = #{tradeDay}</if>
<if test= "differrange != null " > and differrange = #{differrange}</if>
</where>
</select>
<select id= "selectGroupStocksLimit" parameterType= "Stocks" resultMap= "StocksResult" >
select sb.blemind2 as blemind2 ,COUNT(blemind2) as blemindsCount from stocks sl,stock_basis sb
where sl.`code` = sb.`code` and sl.trade_day = #{tradeDay} and sl.isdrop=#{isdrop} and sl.islimit=#{islimit} GROUP BY blemind2 ORDER BY blemindsCount DESC limit 10;
</select>
<!-- <select id="selectStockHistory" parameterType="Stocks" resultMap="StocksResult"> -->
<!-- select trade_day,code,open,close,high,low, volumn,differrange from stocks where trade_day BETWEEN '2021 - 01 - 01' and #{tradeDay} and `code`=#{code} ORDER BY trade_day desc; -->
<!-- </select> -->
<select id= "selectStockHistory" parameterType= "Stocks" resultMap= "StocksResult" >
select s.trade_day as trade_day,s.code as code,s.open as open,s.close as close,s.high as high,s.low as low, s.volumn as volumn,s.differrange as differrange,sb.blemind2 as blemind2,sb.blemind3 as blemind3 from stocks s,stock_basis sb where s.code = sb.`code` and s.trade_day BETWEEN '2021-01-01' and #{tradeDay} and s.code=#{code} ORDER BY s.trade_day desc;
</select>
<!-- 获取指数历史数据 -->
<select id= "selectStockIndexHistory" parameterType= "Stocks" resultMap= "StocksResult" >
SELECT
s.trade_day AS trade_day,
s.CODE AS CODE,
s.OPEN AS OPEN,
s.CLOSE AS CLOSE,
s.high AS high,
s.low AS low,
s.volume AS volumn,
s.differrange AS differrange
FROM
stock_index s
WHERE
s.trade_day BETWEEN '2021-01-01' and #{tradeDay} and s.name=#{blemind2} ORDER BY s.trade_day desc;
</select>
<select id= "selectStocksForHigh" parameterType= "Stocks" resultMap= "StocksResult" >
select trade_day,code,open,MAX(close) as close,high,low,differrange20 from stocks where trade_day BETWEEN #{stradeDay} and #{tradeDay} GROUP BY code ORDER BY differrange20 desc;
</select>
<!-- 插入到stocks_tmp表中的数据 -->
<insert id= "insertStocksTmp" parameterType= "Stocks" useGeneratedKeys= "true" keyProperty= "id" >
insert into stocks_tmp
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "code != null and code != ''" > code,</if>
<if test= "tradeDay != null" > trade_day,</if>
<if test= "differrange3 != null" > differrange3,</if>
<if test= "differrange5 != null" > differrange5,</if>
<if test= "differrange15 != null" > differrange15,</if>
<if test= "differrange30 != null" > differrange30,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "code != null and code != ''" > #{code},</if>
<if test= "tradeDay != null" > #{tradeDay},</if>
<if test= "differrange3 != null" > #{differrange3},</if>
<if test= "differrange5 != null" > #{differrange5},</if>
<if test= "differrange15 != null" > #{differrange15},</if>
<if test= "differrange30 != null" > #{differrange30},</if>
</trim>
</insert>
<select id= "selectStocksDataForQuery" parameterType= "Stocks" resultMap= "StocksResult" >
select code,name from stock_basis;
</select>
<select id= "selectStockIndexsDataForQuery" parameterType= "Stocks" resultMap= "StocksResult" >
select DISTINCT code,name from stock_index;
</select>
</mapper>