CoinMapper.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package top.lvzhiqiang.mapper;
  2. import com.alibaba.fastjson.JSONObject;
  3. import org.apache.ibatis.annotations.Insert;
  4. import org.apache.ibatis.annotations.MapKey;
  5. import org.apache.ibatis.annotations.Select;
  6. import org.apache.ibatis.annotations.Update;
  7. import top.lvzhiqiang.entity.*;
  8. import java.math.BigDecimal;
  9. import java.util.Collection;
  10. import java.util.List;
  11. import java.util.Map;
  12. /**
  13. * coin-Mapper
  14. *
  15. * @author lvzhiqiang
  16. * 2023/9/9 17:37
  17. */
  18. public interface CoinMapper {
  19. @Insert({"<script>" +
  20. "INSERT ignore INTO coin_order_history(symbol,size,orderId,clientOid,filledQty,fee,price,priceAvg,state,side" +
  21. ",timeInForce,totalProfits,posSide,marginCoin,leverage,marginMode,orderType,reduceOnly,enterPointSource,tradeSide" +
  22. ",holdMode,orderSource,cTime,uTime)" +
  23. " VALUES " +
  24. "<foreach collection='list' item='p' index=\"index\" separator=\",\">" +
  25. " ( #{p.symbol}, #{p.size}, #{p.orderId}, #{p.clientOid}, #{p.filledQty}, #{p.fee}, #{p.price}, #{p.priceAvg}, #{p.state}" +
  26. ", #{p.side}, #{p.timeInForce}, #{p.totalProfits}, #{p.posSide}, #{p.marginCoin}, #{p.leverage}, #{p.marginMode}, #{p.orderType}" +
  27. ", #{p.reduceOnly}, #{p.enterPointSource}, #{p.tradeSide}, #{p.holdMode}, #{p.orderSource}, #{p.cTime}, #{p.uTime})" +
  28. "</foreach>" +
  29. "</script>"})
  30. int insertHistoryOrderList(List<CoinHistoryOrder> historyOrderList);
  31. @Select({"<script>" +
  32. "select * from coin_order_history WHERE 1 = 1" +
  33. "<if test=\"keyword != null and keyword != ''\">" +
  34. " and symbol like concat('%',#{keyword},'%')" +
  35. "</if>" +
  36. "<if test=\"side != null and side != ''\">" +
  37. " and side = #{side}" +
  38. "</if>" +
  39. " order by ${sortField} ${sort}" +
  40. "</script>"})
  41. List<CoinHistoryOrder> findHistoryOrderList(Map<String, Object> params);
  42. @Select("select symbol,type,category,sort from coin_monitor_currency where delete_flag = 1 order by sort")
  43. List<CoinMonitorCurrency> findMonitorCurrencyList();
  44. @Select("select * from coin_public_params where 1=1")
  45. @MapKey("codeKey")
  46. List<CoinPubilcParams> findPublicParams();
  47. @Insert({"<script>" +
  48. "INSERT INTO coin_trader(traderUid,traderNickName,maxFollowCount,followCount,totalFollowers,profitOrderCount,lossOrderCount," +
  49. "totalTradeCount,dailyProfitRate,dailyProfit,copyTradeDays,roi,totalProfit,totalFollowersProfit,aum,maxCallbackRate,last3wWinRate," +
  50. "averageWinRate,traderHeadPic,canTrace,tradingPairsAvailable,profile,lastTradeTime,modify_time)" +
  51. " VALUES " +
  52. "<foreach collection='list' item='mt' index=\"index\" separator=\",\">" +
  53. " (#{mt.traderUid},#{mt.traderNickName},#{mt.maxFollowCount},#{mt.followCount},#{mt.totalFollowers},#{mt.profitOrderCount},#{mt.lossOrderCount}," +
  54. "#{mt.totalTradeCount},#{mt.dailyProfitRate},#{mt.dailyProfit},#{mt.copyTradeDays},#{mt.roi},#{mt.totalProfit},#{mt.totalFollowersProfit},#{mt.aum}," +
  55. "#{mt.maxCallbackRate},#{mt.last3wWinRate},#{mt.averageWinRate},#{mt.traderHeadPic},#{mt.canTrace},#{mt.tradingPairsAvailable},#{mt.profile},#{mt.lastTradeTime}, now())" +
  56. " </foreach>" +
  57. " ON DUPLICATE KEY UPDATE traderNickName=values(traderNickName),maxFollowCount=values(maxFollowCount),followCount=values(followCount),totalFollowers=values(totalFollowers)," +
  58. "profitOrderCount=values(profitOrderCount),lossOrderCount=values(lossOrderCount),totalTradeCount=values(totalTradeCount),dailyProfitRate=values(dailyProfitRate)," +
  59. "dailyProfit=values(dailyProfit),copyTradeDays=values(copyTradeDays),roi=values(roi),totalProfit=values(totalProfit),totalFollowersProfit=values(totalFollowersProfit)," +
  60. "aum=values(aum),maxCallbackRate=values(maxCallbackRate),last3wWinRate=values(last3wWinRate),averageWinRate=values(averageWinRate),traderHeadPic=values(traderHeadPic)," +
  61. "canTrace=values(canTrace),tradingPairsAvailable=values(tradingPairsAvailable),profile=values(profile),lastTradeTime=values(lastTradeTime),modify_time=now()" +
  62. "</script>"})
  63. void insertMixTradeList(List<CoinTrader> parseMixTradeList);
  64. @Select({"<script>" +
  65. "select * from coin_trader WHERE 1 = 1" +
  66. "<if test=\"keyword != null and keyword != ''\">" +
  67. " and traderNickName like concat('%',#{keyword},'%')" +
  68. "</if>" +
  69. "<if test=\"canTrace != null and canTrace != ''\">" +
  70. " and canTrace = #{canTrace}" +
  71. "</if>" +
  72. " order by ${sortField} ${sort}" +
  73. "</script>"})
  74. List<CoinTrader> findMixTraderList(Map<String, Object> params);
  75. @Select("select concat(traderUid, '|', traderNickName) from coin_monitor_trader where delete_flag = '1'")
  76. List<String> findMonitorTraderList();
  77. @Select({"<script>" +
  78. "select * from coin_watchlist WHERE delete_flag = 1" +
  79. "<if test=\"keyword != null and keyword != ''\">" +
  80. " and symbol like concat('%',#{keyword},'%')" +
  81. "</if>" +
  82. "<if test=\"symbol != null and symbol != ''\">" +
  83. " and symbol = #{symbol}" +
  84. "</if>" +
  85. "<if test=\"filterField != null and filterField != ''\">" +
  86. " and filter_flag = #{filterField}" +
  87. "</if>" +
  88. "<if test=\"trackCategoryField != null and trackCategoryField != ''\">" +
  89. " and track_category like concat('%',#{trackCategoryField},'%')" +
  90. "</if>" +
  91. " order by " +
  92. "<foreach collection='sortField' item='sf' index=\"index\" separator=\",\">" +
  93. " ${sf} ${sort}" +
  94. " </foreach>" +
  95. "</script>"})
  96. List<CoinWatchlist> findWatchlistList(Map<String, Object> params);
  97. @Select({"<script>" +
  98. "select cw.* from coin_watchlist cw left join coin_watchlist_other cwo on cw.symbol=cwo.symbol WHERE cw.delete_flag = 1" +
  99. "<if test=\"keyword != null and keyword != ''\">" +
  100. " and cw.symbol like concat('%',#{keyword},'%')" +
  101. "</if>" +
  102. "<if test=\"symbol != null and symbol != ''\">" +
  103. " and cw.symbol = #{symbol}" +
  104. "</if>" +
  105. "<if test=\"filterField != null and filterField != ''\">" +
  106. " and cw.filter_flag = #{filterField}" +
  107. "</if>" +
  108. "<if test=\"trackCategoryField != null and trackCategoryField != ''\">" +
  109. " and cw.track_category like concat('%',#{trackCategoryField},'%')" +
  110. "</if>" +
  111. "<if test=\"trackCategory2Field != null and trackCategory2Field != ''\">" +
  112. " and cw.track_category2 like concat('%',#{trackCategory2Field},'%')" +
  113. "</if>" +
  114. "<if test=\"cexFilterField != null and cexFilterField != ''\">" +
  115. " <choose>" +
  116. " <when test=\" cexFilterName == 'cwo.cex_spot' \">" +
  117. " and substring(cwo.cex_spot,#{cexFilterIndex},1) = '1'" +
  118. " </when>" +
  119. " <otherwise>" +
  120. " and substring(cwo.cex_perpetual,#{cexFilterIndex},1) = '1'" +
  121. " </otherwise>" +
  122. " </choose>" +
  123. "</if>" +
  124. " order by " +
  125. "<foreach collection='sortField' item='sf' index=\"index\" separator=\",\">" +
  126. " ${sf} ${sort}" +
  127. " </foreach>" +
  128. "</script>"})
  129. List<CoinWatchlist> findWatchlistList2(Map<String, Object> params);
  130. @Update("update coin_watchlist set cmc_id=#{cmcId},total_market_ranking=#{totalMarketRanking},total_market_value=#{totalMarketValue}," +
  131. "mark_price=#{markPrice},price_change_percentage_24h=#{priceChangePercentage24h},highest_historical_price=#{highestHistoricalPrice},ath_change_percentage=#{athChangePercentage},atl_change_percentage=#{atlChangePercentage},lowest_historical_price=#{lowestHistoricalPrice}," +
  132. "highest_historical_date=#{highestHistoricalDate},lowest_historical_date=#{lowestHistoricalDate},increase_multiple=#{increaseMultiple}," +
  133. "issuing_days=#{issuingDays},coingecko_url=#{coingeckoUrl},cmc_url=#{cmcUrl},feixiaohao_url=#{feixiaohaoUrl},modify_time=now() where id = #{id}")
  134. int updateCoinWatchlist(CoinWatchlist coinWatchlist);
  135. @Insert("INSERT INTO coin_watchlist_other(symbol, max_supply, circulating_supply, circulating_rate, total_supply, market_cap, fully_diluted_market_cap, create_time, modify_time) " +
  136. "VALUES (#{symbol}, #{maxSupply}, #{circulatingSupply}, #{circulatingRate}, #{totalSupply}, #{marketCap}, #{fullyDilutedMarketCap}, now(), now())" +
  137. " ON DUPLICATE KEY UPDATE max_supply=values(max_supply),circulating_supply=values(circulating_supply),circulating_rate=values(circulating_rate),total_supply=values(total_supply)" +
  138. ",market_cap=values(market_cap),fully_diluted_market_cap=values(fully_diluted_market_cap),modify_time=now()")
  139. int insertOrUpdateCoinWatchlistOther(CoinWatchlistOther coinWatchlistOther);
  140. @Select("select a.*,b.coingecko_id from coin_watchlist_other a left join coin_watchlist b on a.symbol=b.symbol where a.delete_flag = 1 and a.symbol not in ('BTC','ETH')")
  141. List<CoinWatchlistOther> findAllCoinWatchlistOther();
  142. @Select("select * from coin_watchlist_other where symbol = #{symbol} and delete_flag = 1")
  143. CoinWatchlistOther findWatchlistOtherBySymbol(String symbol);
  144. @Select("select a.*,b.coingecko_id from coin_watchlist_other a left join coin_watchlist b on a.symbol=b.symbol where a.symbol = #{symbol} and a.delete_flag = 1")
  145. CoinWatchlistOther findWatchlistOtherBySymbol2(String symbol);
  146. @Insert({"<script>" +
  147. "INSERT INTO coin_watchlist_other(symbol,cex_spot,cex_perpetual,create_time,modify_time)" +
  148. " VALUES " +
  149. "<foreach collection='collection' item='cwo' index=\"index\" separator=\",\">" +
  150. " (#{cwo.symbol},#{cwo.cexSpot},#{cwo.cexPerpetual},now(),now())" +
  151. " </foreach>" +
  152. " ON DUPLICATE KEY UPDATE cex_spot=values(cex_spot),cex_perpetual=values(cex_perpetual),modify_time=now()" +
  153. "</script>"})
  154. int insertOrUpdateCoinWatchlistOtherList(Collection<CoinWatchlistOther> coinWatchlistOtherList);
  155. @Update({"<script>" +
  156. "update coin_watchlist " +
  157. "<set>" +
  158. "<if test=\"score != null and score != ''\">" +
  159. " score = #{score}," +
  160. "</if>" +
  161. "<if test=\"remark != null and remark != ''\">" +
  162. " remark = #{remark}," +
  163. "</if>" +
  164. "modify_time=now()" +
  165. "</set>" +
  166. "where symbol = #{symbol}" +
  167. "</script>"})
  168. int updateCoinWatchlistRemark(CoinWatchlist coinWatchlist);
  169. @Select("select * from coin_watchlist where symbol = #{symbol} and delete_flag = 1")
  170. CoinWatchlist findWatchlistBySymbol(String symbol);
  171. @Insert({"<script>" +
  172. "INSERT INTO coin_cmc_map(cmc_id,cmc_rank,name,symbol,slug,is_active,status," +
  173. "first_historical_data,last_historical_data,platform,modify_time)" +
  174. " VALUES " +
  175. "<foreach collection='list' item='mt' index=\"index\" separator=\",\">" +
  176. " (#{mt.cmcId},#{mt.cmcRank},#{mt.name},#{mt.symbol},#{mt.slug},#{mt.isActive},#{mt.status}," +
  177. "#{mt.firstHistoricalData},#{mt.lastHistoricalData},#{mt.platform},now())" +
  178. " </foreach>" +
  179. " ON DUPLICATE KEY UPDATE cmc_rank=values(cmc_rank),name=values(name),symbol=values(symbol),slug=values(slug)," +
  180. "is_active=values(is_active),status=values(status),first_historical_data=values(first_historical_data),last_historical_data=values(last_historical_data),modify_time=now()" +
  181. "</script>"})
  182. void insertCmcMapList(List<CoinCmcMap> cmcMapList);
  183. @Select({"<script>" +
  184. "select * from coin_cmc_map WHERE 1 = 1" +
  185. "<if test=\"keyword != null and keyword != ''\">" +
  186. " and (name like concat('%',#{keyword},'%') or symbol like concat('%',#{keyword},'%') or slug like concat('%',#{keyword},'%'))" +
  187. "</if>" +
  188. "<if test=\"filterField != null and filterField != ''\">" +
  189. " and status = #{filterField}" +
  190. "</if>" +
  191. " order by ${sortField} ${sort}" +
  192. "</script>"})
  193. List<CoinCmcMap> findCmcMapList(Map<String, Object> params);
  194. @Select("SELECT * FROM coin_monitor_job WHERE delete_flag = 1")
  195. @MapKey("job_name")
  196. Map<String, JSONObject> findMonitorJobConfig();
  197. @Insert("INSERT INTO coin_watchlist(cmc_id, symbol, track_category, track_category2, issuing_date, coingecko_id, coingecko_url, cmc_url, feixiaohao_url, filter_flag, create_time, modify_time) " +
  198. "VALUES (#{cmcId}, #{symbol}, #{trackCategory}, #{trackCategory2}, #{issuingDate}, #{coingeckoId}, #{coingeckoUrl}, #{cmcUrl}, #{feixiaohaoUrl}, #{filterFlag}, now(), now())" +
  199. " ON DUPLICATE KEY UPDATE cmc_id=values(cmc_id),track_category=values(track_category),track_category2=values(track_category2),issuing_date=values(issuing_date),coingecko_id=values(coingecko_id)" +
  200. ",coingecko_url=values(coingecko_url),cmc_url=values(cmc_url),feixiaohao_url=values(feixiaohao_url),filter_flag=values(filter_flag),modify_time=now()")
  201. int insertOrUpdateWatchlist(CoinWatchlist coinWatchlist);
  202. @Insert({"<script>" +
  203. "INSERT INTO coin_binance_symbol(symbol,status,baseAsset,marginAsset,baseAssetPrecision,contractType,underlyingSubType," +
  204. "filters,orderTypes,timeInForce,liquidationFee,marketTakeBound,deliveryDate,onboardDate,modify_time)" +
  205. " VALUES " +
  206. "<foreach collection='list' item='cbs' index=\"index\" separator=\",\">" +
  207. " (#{cbs.symbol},#{cbs.status},#{cbs.baseAsset},#{cbs.marginAsset},#{cbs.baseAssetPrecision},#{cbs.contractType},#{cbs.underlyingSubType}," +
  208. "#{cbs.filters},#{cbs.orderTypes},#{cbs.timeInForce},#{cbs.liquidationFee},#{cbs.marketTakeBound},#{cbs.deliveryDate},#{cbs.onboardDate},now())" +
  209. " </foreach>" +
  210. " ON DUPLICATE KEY UPDATE status=values(status),baseAsset=values(baseAsset),marginAsset=values(marginAsset),baseAssetPrecision=values(baseAssetPrecision)," +
  211. "contractType=values(contractType),underlyingSubType=values(underlyingSubType),filters=values(filters),orderTypes=values(orderTypes)," +
  212. "timeInForce=values(timeInForce),liquidationFee=values(liquidationFee),marketTakeBound=values(marketTakeBound),deliveryDate=values(deliveryDate),onboardDate=values(onboardDate),modify_time=now()" +
  213. "</script>"})
  214. void insertCoinBinanceSymbolList(List<CoinBinanceSymbol> coinBinanceSymbolList);
  215. @Select({"<script>" +
  216. "select * from coin_binance_symbol WHERE 1 = 1" +
  217. "<if test=\"keyword != null and keyword != ''\">" +
  218. " and symbol like concat('%',#{keyword},'%')" +
  219. "</if>" +
  220. "<if test=\"status != null and status != ''\">" +
  221. " and status = #{status}" +
  222. "</if>" +
  223. "<if test=\"marginAsset != null and marginAsset != ''\">" +
  224. " and marginAsset = #{marginAsset}" +
  225. "</if>" +
  226. "<if test=\"contractType != null and contractType != ''\">" +
  227. " and contractType = #{contractType}" +
  228. "</if>" +
  229. " order by ${sortField} ${sort}" +
  230. "</script>"})
  231. List<CoinBinanceSymbol> findCoinBinanceSymbolListByParams(Map<String, Object> params);
  232. @Select("select orderId from coin_binance_order_history")
  233. List<String> findAllCoinBinanceOrderIdList();
  234. @Insert({"<script>" +
  235. "INSERT ignore INTO coin_binance_order_history(orderId,symbol,status,price,avgPrice,origQty,executedQty,cumQuote,timeInForce,type" +
  236. ",side,positionSide,stopPrice,workingType,origType,time,updateTime,commission,realizedPnl,modify_time)" +
  237. " VALUES " +
  238. "<foreach collection='list' item='p' index=\"index\" separator=\",\">" +
  239. " ( #{p.orderId}, #{p.symbol}, #{p.status}, #{p.price}, #{p.avgPrice}, #{p.origQty}, #{p.executedQty}, #{p.cumQuote}, #{p.timeInForce}, #{p.type}" +
  240. ", #{p.side}, #{p.positionSide}, #{p.stopPrice}, #{p.workingType}, #{p.origType}, #{p.time}, #{p.updateTime}, #{p.commission}, #{p.realizedPnl}, now())" +
  241. "</foreach>" +
  242. "</script>"})
  243. void insertOrUpdateBinanceOrderHistoryList(List<CoinBinanceOrderHistory> coinBinanceOrderHistoryList);
  244. @Select({"<script>" +
  245. "select cch.*,cec.category_name exchangeCategory from coin_currency_holding cch left join coin_exchange_category cec on cch.exchange_category_id=cec.id WHERE cch.delete_flag = 1" +
  246. "<if test=\"keyword != null and keyword != ''\">" +
  247. " and cch.symbol like concat('%',#{keyword},'%')" +
  248. "</if>" +
  249. "<if test=\"symbol != null and symbol != ''\">" +
  250. " and cch.symbol = #{symbol}" +
  251. "</if>" +
  252. "<if test=\"status != null and status != ''\">" +
  253. " and cch.status = #{status}" +
  254. "</if>" +
  255. "<if test=\"categoryField != null and categoryField != ''\">" +
  256. " and cch.exchange_category_id = #{categoryField}" +
  257. "</if>" +
  258. " order by " +
  259. "<foreach collection='sortField' item='sf' index=\"index\" separator=\",\">" +
  260. " ${sf} ${sort}" +
  261. " </foreach>" +
  262. "</script>"})
  263. List<CoinCurrencyHolding> findCurrentHoldingList(Map<String, Object> params);
  264. @Update("update coin_currency_holding set symbol=#{symbol},buy_price=#{buyPrice},current_price=#{currentPrice},change_percentage=#{changePercentage},buy_quantity=#{buyQuantity}," +
  265. "current_quantity=#{currentQuantity},buy_amount=#{buyAmount},current_amount=#{currentAmount},exchange_category_id=#{exchangeCategoryId},coingecko_id=#{coingeckoId},status=#{status}," +
  266. "remark=#{remark},buy_time=#{buyTime},modify_time=now() where id = #{id}")
  267. int updateCurrentHolding(CoinCurrencyHolding coinCurrencyHolding);
  268. @Select({"<script>" +
  269. "select sum(current_amount) from coin_currency_holding cch WHERE cch.delete_flag = 1" +
  270. "<if test=\"keyword != null and keyword != ''\">" +
  271. " and cch.symbol like concat('%',#{keyword},'%')" +
  272. "</if>" +
  273. "<if test=\"symbol != null and symbol != ''\">" +
  274. " and cch.symbol = #{symbol}" +
  275. "</if>" +
  276. "<if test=\"status != null and status != ''\">" +
  277. " and cch.status = #{status}" +
  278. "</if>" +
  279. "<if test=\"categoryField != null and categoryField != ''\">" +
  280. " and cch.exchange_category_id = #{categoryField}" +
  281. "</if>" +
  282. "</script>"})
  283. BigDecimal getCurrentHoldingTotalAmout(Map<String, Object> params);
  284. @Select({"<script>" +
  285. "select bi.*,bc.name categoryName from bookmark_info bi left join bookmark_category bc on bi.category_id=bc.id WHERE bi.delete_flag = 1 and bc.delete_flag = 1" +
  286. "<if test=\"keyword != null and keyword != ''\">" +
  287. " and (bi.title like concat('%',#{keyword},'%') or bi.remark like concat('%',#{keyword},'%') or bi.tags like concat('%',#{keyword},'%'))" +
  288. "</if>" +
  289. "<if test=\"categoryField != null and categoryField != ''\">" +
  290. " and bi.category_id = #{categoryField}" +
  291. "</if>" +
  292. "<if test=\"accountId != null and accountId != ''\">" +
  293. " and bi.account_id = #{accountId}" +
  294. "</if>" +
  295. "<if test=\"isFavorite != null and isFavorite != ''\">" +
  296. " and bi.is_favorite = #{isFavorite}" +
  297. "</if>" +
  298. "<if test=\"status != null and status != ''\">" +
  299. " and bi.status = #{status}" +
  300. "</if>" +
  301. " order by " +
  302. "<foreach collection='sortField' item='sf' index=\"index\" separator=\",\">" +
  303. " ${sf} ${sort}" +
  304. " </foreach>" +
  305. "</script>"})
  306. List<BookmarkInfo> findBookmarkList(Map<String, Object> params);
  307. }