ソースを参照

update:自选币种支持多用户v2

lvzhiqiang 1 年間 前
コミット
31b41915f6

+ 50 - 9
src/main/java/top/lvzhiqiang/controller/CoinController.java

@@ -17,6 +17,7 @@ import top.lvzhiqiang.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
 import java.util.List;
 
 /**
@@ -96,34 +97,58 @@ public class CoinController {
         return coinService.orderDetail2(orderId, symbol);
     }
 
-    @GetMapping("/watchlistDetail/{symbol}/{operationType}")
-    public Object watchlistDetail(@PathVariable String symbol, @PathVariable String operationType) {
+    @GetMapping("/watchlistDetail/{userName}/{symbol}/{operationType}")
+    public Object watchlistDetail(@PathVariable String userName, @PathVariable String symbol, @PathVariable String operationType) {
         if (StringUtils.isEmpty(symbol)) {
             throw new ParameterException("symbol不能为空!");
         }
+
+        Integer userId;
+        if (StringUtils.isEmpty(userName)) {
+            throw new ParameterException("userName为空!");
+        } else {
+            JSONObject coinUser = coinMapper.findUserByUsername(userName);
+            if (coinUser == null) {
+                throw new ParameterException("用户不存在!");
+            }
+            userId = coinUser.getInteger("id");
+        }
+
         if (StringUtils.isEmpty(operationType)) {
             throw new ParameterException("operationType不能为空!");
         }
 
-        return R.ok().data(coinService.watchlistDetail(symbol, operationType));
+        return R.ok().data(coinService.watchlistDetail(userId, symbol, operationType));
     }
 
     @PostMapping("/watchlistUpdate")
-    public Object watchlistUpdate(String symbol, String remark, String score) {
+    public Object watchlistUpdate(String symbol, String userName, String remark, String score) {
         if (StringUtils.isEmpty(symbol)) {
             throw new ParameterException("symbol不能为空!");
         }
+
+        Integer userId;
+        if (StringUtils.isEmpty(userName)) {
+            throw new ParameterException("userName为空!");
+        } else {
+            JSONObject coinUser = coinMapper.findUserByUsername(userName);
+            if (coinUser == null) {
+                throw new ParameterException("用户不存在!");
+            }
+            userId = coinUser.getInteger("id");
+        }
+
         if (StringUtils.isEmpty(remark) && StringUtils.isEmpty(score)) {
             throw new ParameterException("remark和score不能同时为空!");
         }
 
-        return R.ok().data(coinService.watchlistUpdate(symbol, remark, score));
+        return R.ok().data(coinService.watchlistUpdate(symbol, userId, remark, score));
     }
 
-    @GetMapping("/mainSearchDetail/{nameEn}/{id}")
-    public Object mainSearchDetail(@PathVariable String nameEn, @PathVariable String id) {
+    @GetMapping("/mainSearchDetail/{userName}/{nameEn}/{id}")
+    public Object mainSearchDetail(@PathVariable String userName, @PathVariable String nameEn, @PathVariable String id) {
 
-        return coinService.mainSearchDetail(nameEn, id);
+        return coinService.mainSearchDetail(userName, nameEn, id);
     }
 
     /**
@@ -139,6 +164,7 @@ public class CoinController {
             throw new ParameterException("crudType为空!");
         }
 
+        Integer userId;
         if (StringUtils.isEmpty(userName)) {
             throw new ParameterException("userName为空!");
         } else {
@@ -146,6 +172,7 @@ public class CoinController {
             if (coinUser == null) {
                 throw new ParameterException("用户不存在!");
             }
+            userId = coinUser.getInteger("id");
         }
 
         if (StringUtils.isEmpty(symbol)) {
@@ -163,19 +190,27 @@ public class CoinController {
             coinWatchlist.setTrackCategory(StringUtils.isEmpty(trackCategory) ? "" : trackCategory);
             coinWatchlist.setTrackCategory2(StringUtils.isEmpty(trackCategory2) ? "" : trackCategory2);
             coinWatchlist.setIssuingDate(LocalDate.parse(issuingDate, DateUtils.dateFormatter));
+
+            // 发行日期
+            // 发行天数
+            long totalDays = ChronoUnit.DAYS.between(coinWatchlist.getIssuingDate(), LocalDate.now());
+            coinWatchlist.setIssuingDays((int) totalDays);
+
             coinWatchlist.setCmcId(cmcId);
             coinWatchlist.setCoingeckoId(coingeckoId);
             coinWatchlist.setCoingeckoUrl(coingeckoUrl);
             coinWatchlist.setFeixiaohaoUrl(feixiaohaoUrl);
             coinWatchlist.setFilterFlag(filterFlag);
+            coinWatchlist.setUserId(userId);
 
             coinMapper.insertOrUpdateWatchlist(coinWatchlist);
+            coinMapper.insertOrUpdateWatchlistUser(coinWatchlist);
 
             // init data
             coinService.initWatchlist(coinWatchlist);
         } else if ("2".equals(crudType)) {
             // 修改
-            CoinWatchlist coinWatchlist = coinMapper.findWatchlistBySymbol(symbol);
+            CoinWatchlist coinWatchlist = coinMapper.findWatchlistUserBySymbolAndUserId(symbol, userId);
             if (coinWatchlist == null) {
                 throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "symbol 不存在!");
             }
@@ -188,6 +223,11 @@ public class CoinController {
             }
             if (StringUtils.isNotEmpty(issuingDate)) {
                 coinWatchlist.setIssuingDate(LocalDate.parse(issuingDate, DateUtils.dateFormatter));
+
+                // 发行日期
+                // 发行天数
+                long totalDays = ChronoUnit.DAYS.between(coinWatchlist.getIssuingDate(), LocalDate.now());
+                coinWatchlist.setIssuingDays((int) totalDays);
             }
             if (null != cmcId) {
                 coinWatchlist.setCmcId(cmcId);
@@ -207,6 +247,7 @@ public class CoinController {
                 coinWatchlist.setFilterFlag(filterFlag);
             }
             coinMapper.insertOrUpdateWatchlist(coinWatchlist);
+            coinMapper.insertOrUpdateWatchlistUser(coinWatchlist);
         }
 
         return R.ok().data("success");

+ 2 - 0
src/main/java/top/lvzhiqiang/entity/CoinWatchlist.java

@@ -140,4 +140,6 @@ public class CoinWatchlist implements Serializable {
     private Integer filterFlag;
 
     private String score;
+
+    private Integer userId;
 }

+ 18 - 8
src/main/java/top/lvzhiqiang/mapper/CoinMapper.java

@@ -184,7 +184,7 @@ public interface CoinMapper {
     @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}," +
-            "issuing_days=#{issuingDays},coingecko_url=#{coingeckoUrl},cmc_url=#{cmcUrl},feixiaohao_url=#{feixiaohaoUrl},modify_time=now() where id = #{id}")
+            "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) " +
@@ -213,7 +213,7 @@ public interface CoinMapper {
     int insertOrUpdateCoinWatchlistOtherList(Collection<CoinWatchlistOther> coinWatchlistOtherList);
 
     @Update({"<script>" +
-            "update coin_watchlist " +
+            "update coin_watchlist_user " +
             "<set>" +
             "<if test=\"score != null and score != ''\">" +
             "  score = #{score}," +
@@ -223,13 +223,17 @@ public interface CoinMapper {
             "</if>" +
             "modify_time=now()" +
             "</set>" +
-            "where symbol = #{symbol}" +
+            "where user_id = #{userId} and symbol = #{symbol}" +
             "</script>"})
-    int updateCoinWatchlistRemark(CoinWatchlist coinWatchlist);
+    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({"<script>" +
             "INSERT INTO coin_cmc_map(cmc_id,cmc_rank,name,symbol,slug,is_active,status," +
             "first_historical_data,last_historical_data,platform,modify_time)" +
@@ -259,12 +263,18 @@ public interface CoinMapper {
     @MapKey("job_name")
     Map<String, JSONObject> findMonitorJobConfig();
 
-    @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) " +
-            "VALUES (#{cmcId}, #{symbol}, #{trackCategory}, #{trackCategory2}, #{issuingDate}, #{coingeckoId}, #{coingeckoUrl}, #{cmcUrl}, #{feixiaohaoUrl}, #{filterFlag}, now(), now())" +
-            " 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)" +
-            ",coingecko_url=values(coingecko_url),cmc_url=values(cmc_url),feixiaohao_url=values(feixiaohao_url),filter_flag=values(filter_flag),modify_time=now()")
+    @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({"<script>" +
             "INSERT INTO coin_binance_symbol(symbol,status,baseAsset,marginAsset,baseAssetPrecision,contractType,underlyingSubType," +
             "filters,orderTypes,timeInForce,liquidationFee,marketTakeBound,deliveryDate,onboardDate,modify_time)" +

+ 3 - 3
src/main/java/top/lvzhiqiang/service/CoinService.java

@@ -44,15 +44,15 @@ public interface CoinService {
 
     void syncData4TraderListSub(JSONArray dataList);
 
-    String watchlistDetail(String symbol, String operationType);
+    String watchlistDetail(Integer userId, String symbol, String operationType);
 
-    Object watchlistUpdate(String symbol, String remark, String score);
+    Object watchlistUpdate(String symbol, Integer userId, String remark, String score);
 
     void syncCoinmarketcapCMap();
 
     Map<String, JSONObject> getMonitorJobConfig();
 
-    Object mainSearchDetail(String nameEn, String id);
+    Object mainSearchDetail(String userName, String nameEn, String id);
 
     void debugTest();
 

+ 18 - 14
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -46,7 +46,6 @@ import java.text.DecimalFormat;
 import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -311,8 +310,8 @@ public class CoinServiceImpl implements CoinService {
     }
 
     @Override
-    public String watchlistDetail(String symbol, String operationType) {
-        CoinWatchlist coinWatchlist = coinMapper.findWatchlistBySymbol(symbol);
+    public String watchlistDetail(Integer userId, String symbol, String operationType) {
+        CoinWatchlist coinWatchlist = coinMapper.findWatchlistUserBySymbolAndUserId(symbol, userId);
         if (coinWatchlist == null) {
             throw new BusinessException(1, "symbol不存在!");
         }
@@ -327,12 +326,13 @@ public class CoinServiceImpl implements CoinService {
     }
 
     @Override
-    public Object watchlistUpdate(String symbol, String remark, String score) {
+    public Object watchlistUpdate(String symbol, Integer userId, String remark, String score) {
         CoinWatchlist coinWatchlist = new CoinWatchlist();
         coinWatchlist.setSymbol(symbol);
+        coinWatchlist.setUserId(userId);
         coinWatchlist.setRemark(remark);
         coinWatchlist.setScore(score);
-        int num = coinMapper.updateCoinWatchlistRemark(coinWatchlist);
+        int num = coinMapper.updateCoinWatchlistRemarkAndScore(coinWatchlist);
         return num;
     }
 
@@ -1266,13 +1266,6 @@ public class CoinServiceImpl implements CoinService {
                         coinWatchlist.setIncreaseMultiple(increaseMultiple.intValue());
                     }
 
-                    // 发行日期
-                    // 发行天数
-                    if (coinWatchlist.getIssuingDate() != null) {
-                        long totalDays = ChronoUnit.DAYS.between(coinWatchlist.getIssuingDate(), LocalDate.now());
-                        coinWatchlist.setIssuingDays((int) totalDays);
-                    }
-
                     coinMapper.updateCoinWatchlist(coinWatchlist);
                 }
             }
@@ -2408,7 +2401,7 @@ public class CoinServiceImpl implements CoinService {
     }
 
     @Override
-    public Object mainSearchDetail(String nameEn, String id) {
+    public Object mainSearchDetail(String userName, String nameEn, String id) {
         if ("image".equals(nameEn)) {
             FileImage fileImage = pictureInfoMapper.findFileImageById(Long.valueOf(id));
 
@@ -2420,7 +2413,18 @@ public class CoinServiceImpl implements CoinService {
             fileImage.setThumbnailPath(ftpBaseurl + ftpThumbnailBasePath + path);
             return fileImage;
         } else if ("watchlist".equals(nameEn)) {
-            CoinWatchlist coinWatchlist = coinMapper.findWatchlistBySymbol(id);
+            Integer userId;
+            if (StringUtils.isEmpty(userName)) {
+                throw new ParameterException("userName为空!");
+            } else {
+                JSONObject coinUser = coinMapper.findUserByUsername(userName);
+                if (coinUser == null) {
+                    throw new ParameterException("用户不存在!");
+                }
+                userId = coinUser.getInteger("id");
+            }
+
+            CoinWatchlist coinWatchlist = coinMapper.findWatchlistUserBySymbolAndUserId(id, userId);
 
             String watchlistOtherStr = parseWatchlistOther(id);
 

+ 1 - 1
src/main/resources/static/js/my-av.js

@@ -105,7 +105,7 @@ function avmouseenter(e, nameEn) {
 function getInfo(e, nameEn) {
     var id = $(e).attr("avid");
     $.ajax({
-        url: "coin/mainSearchDetail/"+ nameEn + "/" + id, //请求的url地址
+        url: "coin/mainSearchDetail/" + getCookie('username') + "/" + nameEn + "/" + id, //请求的url地址
         dataType: "json", //返回格式为json
         type: "get", //请求方式
         async: false, //请求是否异步,默认为异步,这也是ajax重要特性

+ 7 - 2
src/main/resources/static/js/my-coin.js

@@ -683,6 +683,7 @@ function initContentEvent(nameEn) {
                 dataType: "json", //返回格式为json
                 data: {
                     "symbol": $(this).attr("id"),
+                    "userName": getCookie('username'),
                     "score": $(this).attr("val")
                 }, //参数值
                 type: "post", //请求方式
@@ -725,7 +726,11 @@ function initContentEvent(nameEn) {
                 $.ajax({
                     url: "coin/watchlistUpdate", //请求的url地址
                     dataType: "json", //返回格式为json
-                    data: {"symbol": $(".watchlistpreview-content").find(".watchlistpreview-symbol").val(), "remark": $(".watchlistpreview-content").find("textarea").val()}, //参数值
+                    data: {
+                        "symbol": $(".watchlistpreview-content").find(".watchlistpreview-symbol").val(),
+                        "userName": getCookie('username'),
+                        "remark": $(".watchlistpreview-content").find("textarea").val()
+                    }, //参数值
                     type: "post", //请求方式
                     async: false, //请求是否异步,默认为异步,这也是ajax重要特性
                     success: function (data) {
@@ -756,7 +761,7 @@ function initContentEvent(nameEn) {
 
             var symbol = $(this).attr("symbolName");
             $.ajax({
-                url: "coin/watchlistDetail/" + symbol + "/" + operationType, //请求的url地址
+                url: "coin/watchlistDetail/" + getCookie('username') + "/" + symbol + "/" + operationType, //请求的url地址
                 type: "get", //请求方式
                 async: true, //请求是否异步,默认为异步,这也是ajax重要特性
                 success: function (data) {