CoinMapper.java 24 KB

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