package top.lvzhiqiang.mapper;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.*;
import top.lvzhiqiang.entity.*;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* coin-Mapper
*
* @author lvzhiqiang
* 2023/9/9 17:37
*/
public interface CoinMapper {
@Insert({""})
int insertHistoryOrderList(List historyOrderList);
@Select({""})
List findHistoryOrderList(Map params);
@Select("select symbol,type,category,sort from coin_monitor_currency where delete_flag = 1 order by sort")
List findMonitorCurrencyList();
@Select("select * from coin_public_params where 1=1")
@MapKey("codeKey")
List findPublicParams();
@Insert({""})
void insertMixTradeList(List parseMixTradeList);
@Select({""})
List findMixTraderList(Map params);
@Select("select concat(traderUid, '|', traderNickName) from coin_monitor_trader where delete_flag = '1'")
List findMonitorTraderList();
@Select({""})
List findWatchlistList(Map params);
@Select({""})
List findWatchlistList2(Map params);
@Select({""})
List findWatchlistList2ByUserId(Map params);
@Update("update coin_watchlist set cmc_id=#{cmcId},total_market_ranking=#{totalMarketRanking},total_market_value=#{totalMarketValue}," +
"mark_price=#{markPrice},price_change_percentage_24h=#{priceChangePercentage24h},highest_historical_price=#{highestHistoricalPrice},ath_change_percentage=#{athChangePercentage},atl_change_percentage=#{atlChangePercentage},lowest_historical_price=#{lowestHistoricalPrice}," +
"highest_historical_date=#{highestHistoricalDate},lowest_historical_date=#{lowestHistoricalDate},increase_multiple=#{increaseMultiple}," +
"coingecko_url=#{coingeckoUrl},cmc_url=#{cmcUrl},feixiaohao_url=#{feixiaohaoUrl},modify_time=now() where id = #{id}")
int updateCoinWatchlist(CoinWatchlist coinWatchlist);
@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) " +
"VALUES (#{symbol}, #{maxSupply}, #{circulatingSupply}, #{circulatingRate}, #{totalSupply}, #{marketCap}, #{fullyDilutedMarketCap}, now(), now())" +
" ON DUPLICATE KEY UPDATE max_supply=values(max_supply),circulating_supply=values(circulating_supply),circulating_rate=values(circulating_rate),total_supply=values(total_supply)" +
",market_cap=values(market_cap),fully_diluted_market_cap=values(fully_diluted_market_cap),modify_time=now()")
int insertOrUpdateCoinWatchlistOther(CoinWatchlistOther coinWatchlistOther);
@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')")
List findAllCoinWatchlistOther();
@Select("select * from coin_watchlist_other where symbol = #{symbol} and delete_flag = 1")
CoinWatchlistOther findWatchlistOtherBySymbol(String symbol);
@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")
CoinWatchlistOther findWatchlistOtherBySymbol2(String symbol);
@Insert({""})
int insertOrUpdateCoinWatchlistOtherList(Collection coinWatchlistOtherList);
@Update({""})
int updateCoinWatchlistRemarkAndScore(CoinWatchlist coinWatchlist);
@Select("select * from coin_watchlist where symbol = #{symbol} and delete_flag = 1")
CoinWatchlist findWatchlistBySymbol(String symbol);
@Select("select cwu.*,cw.cmc_id,cw.cmc_url,cw.coingecko_id,cw.coingecko_url,cw.feixiaohao_url" +
" 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")
CoinWatchlist findWatchlistUserBySymbolAndUserId(String symbol, Integer userId);
@Insert({""})
void insertCmcMapList(List cmcMapList);
@Select({""})
List findCmcMapList(Map params);
@Select("select 1 from coin_cmc_map where symbol = #{symbol} and status='active' limit 1")
Integer existCmcMapBySymbol(String symbol);
@Select("SELECT * FROM coin_monitor_job WHERE delete_flag = 1")
@MapKey("job_name")
Map findMonitorJobConfig();
@Insert("INSERT INTO coin_watchlist(cmc_id, symbol, coingecko_id, coingecko_url, cmc_url, feixiaohao_url, create_time, modify_time, delete_flag) " +
"VALUES (#{cmcId}, #{symbol}, #{coingeckoId}, #{coingeckoUrl}, #{cmcUrl}, #{feixiaohaoUrl}, now(), now(), 1)" +
" ON DUPLICATE KEY UPDATE cmc_id=values(cmc_id),coingecko_id=values(coingecko_id)" +
",coingecko_url=values(coingecko_url),cmc_url=values(cmc_url),feixiaohao_url=values(feixiaohao_url),modify_time=now(),delete_flag=1")
int insertOrUpdateWatchlist(CoinWatchlist coinWatchlist);
@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) " +
"VALUES (#{symbol}, #{userId}, #{trackCategory}, #{trackCategory2}, #{issuingDate}, #{issuingDays}, #{filterFlag}, now(), now(), 1)" +
" ON DUPLICATE KEY UPDATE track_category=values(track_category),track_category2=values(track_category2),issuing_date=values(issuing_date)," +
"issuing_days=values(issuing_days),filter_flag=values(filter_flag),modify_time=now(),delete_flag=1")
int insertOrUpdateWatchlistUser(CoinWatchlist coinWatchlist);
@Insert({""})
void insertCoinBinanceSymbolList(List coinBinanceSymbolList);
@Select({""})
List findCoinBinanceSymbolListByParams(Map params);
@Select("select orderId from coin_binance_order_history")
List findAllCoinBinanceOrderIdList();
@Insert({""})
void insertOrUpdateBinanceOrderHistoryList(List coinBinanceOrderHistoryList);
@Select({""})
List findCurrentHoldingList(Map params);
@Update("update coin_currency_holding set symbol=#{symbol},buy_price=#{buyPrice},current_price=#{currentPrice},change_percentage=#{changePercentage},buy_quantity=#{buyQuantity}," +
"current_quantity=#{currentQuantity},buy_amount=#{buyAmount},current_amount=#{currentAmount},exchange_category_id=#{exchangeCategoryId},coingecko_id=#{coingeckoId},status=#{status}," +
"remark=#{remark},buy_time=#{buyTime},modify_time=now(),sell_time=#{sellTime},sell_price=#{sellPrice},sell_amount=#{sellAmount} where id = #{id}")
int updateCurrentHolding(CoinCurrencyHolding coinCurrencyHolding);
@Select({""})
BigDecimal getCurrentHoldingTotalAmout(Map params);
@Select("select 1 from coin_users where username = #{username} and password = #{password} and delete_flag = 1")
Integer existUserByUsernameAndPassword(String username, String password);
@Select("select 1 from coin_users where username = #{userName} and delete_flag = 1")
Integer existUserByUsername(String userName);
@Select("select * from coin_users where username = #{userName} and delete_flag = 1")
JSONObject findUserByUsername(String userName);
@Select("select coingecko_id from coin_watchlist where symbol = #{symbol} limit 1")
String findCoingeckoIdBySymbol(String symbol);
@Insert("INSERT INTO coin_currency_holding(symbol, buy_price, buy_quantity, current_quantity, exchange_category_id, coingecko_id, status, buy_time, remark, modify_time) " +
"VALUES (#{symbol}, #{buyPrice}, #{buyQuantity}, #{currentQuantity}, #{exchangeCategoryId}, #{coingeckoId}, #{status}, #{buyTime}, #{remark}, now())")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int buyCurrentHolding(CoinCurrencyHolding currencyHolding);
@Select("select * from coin_currency_holding where id = #{id}")
CoinCurrencyHolding findCurrencyHoldingById(String id);
@Select("select * from coin_currency_holding where symbol = #{symbol} and exchange_category_id = #{exchangeCategoryId}")
CoinCurrencyHolding findCurrentHoldingBySymbolAndExchangeCategoryId(String symbol, Integer exchangeCategoryId);
}