From 36681e15e12aaa9135f69260472de65303cdcba3 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 26 四月 2022 19:10:45 +0800
Subject: [PATCH] 任务优化

---
 app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java |  129 ++++++++++++++++++++++++++++++++----------
 1 files changed, 98 insertions(+), 31 deletions(-)

diff --git a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
index 4d32bb9..75f01d2 100644
--- a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
+++ b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
@@ -24,6 +24,7 @@
 import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.TimeUtil;
 import org.yeshi.utils.annotation.RequestSerializableByKey;
 
@@ -32,6 +33,7 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author hxh
@@ -49,7 +51,7 @@
     private GoldCornGetRecordService goldCornGetRecordService;
 
     @Resource
-    private RedisTemplate<String, String> redisTemplate;
+    private RedisTemplate<String, Object> redisTemplate;
 
     @Resource
     private GoldCornGetPriceService goldCornGetPriceService;
@@ -121,7 +123,7 @@
 
     @RequestSerializableByKey(key = "'addgoldcorn-'+#uid+'-'+#type")
     @Override
-    public GoldCornGetRecord addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime, Integer price) throws UserInfoException, GoldCornGetPriceException, GoldCornGetFrequencyConfigException, GoldCornMakeException {
+    public GoldCornGetRecord addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime, Integer price) throws UserInfoException, GoldCornGetFrequencyConfigException, GoldCornMakeException {
         if (uid == null || type == null || currentTime == null) {
             throw new GoldCornMakeException(GoldCornMakeException.CODE_PARAMS_NOT_ENOUGH, "鍙傛暟涓嶅畬鏁�");
         }
@@ -131,20 +133,11 @@
         }
         //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒�
         frequencyVerify(user, type, currentTime);
-        //鑾峰彇浠锋牸
-        GoldCornGetPrice getPrice = goldCornGetPriceService.getPrice(user.getSystem(), type, currentTime);
-        if (price == null) {
-            throw new GoldCornGetPriceException(GoldCornGetPriceException.CODE_NOT_EXIST, "浠锋牸淇℃伅缂哄け");
-        }
+        GoldCornGetPrice getPrice = goldCornGetPriceService.getPrice(user.getSystem(), GoldCornGetType.watchVideo, currentTime);
 
-        //鍩虹浠锋牸,澶栭儴浼犲叆鐨勪环鏍间紭鍏�
-        int baseCornNum = (price != null ? price : getPrice.getCornNum());
 
-        //鏄惁鍔犲叆鍥㈤槦
-        Long bossUid = teamInviteRelationService.getBossUid(uid);
-        if (bossUid != null) {
-            baseCornNum = new BigDecimal(baseCornNum).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue();
-        }
+        //鍗曚环鐢卞闈紶鍏�
+        int baseCornNum = price;
 
         GoldCornGetRecord record = new GoldCornGetRecord();
         record.setCornNum(baseCornNum);
@@ -174,6 +167,7 @@
             }
             //鏄惁鏈変笂绾�
             if (getPrice.getTeamDivide() != null && getPrice.getTeamDivide()) {
+                Long bossUid = teamInviteRelationService.getBossUid(user.getId());
                 if (bossUid != null) {
                     BigDecimal rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamFirstDivideRate));
                     GoldCornGetRecord cRecord = new GoldCornGetRecord();
@@ -189,22 +183,22 @@
                         goldCornGetRecordService.add(cRecord);
                     }
                     //鏄惁鏈変笂涓婄骇
-                    bossUid = teamInviteRelationService.getBossUid(bossUid);
-                    if (bossUid != null) {
-                        rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamSecondDivideRate));
-                        GoldCornGetRecord ccRecord = new GoldCornGetRecord();
-                        ccRecord.setDay(record.getDay());
-                        ccRecord.setType(type);
-                        ccRecord.setUid(bossUid);
-                        ccRecord.setFromId(record.getId());
-                        ccRecord.setFromUid(record.getUid());
-                        ccRecord.setCornNum(new BigDecimal(baseCornNum).multiply(rate).intValue());
-                        ccRecord.setLevel(GoldCornGetRecord.LEVEL_SECOND);
-                        ccRecord.setCreateTime(currentTime);
-                        if (ccRecord.getCornNum() > 0) {
-                            goldCornGetRecordService.add(ccRecord);
-                        }
-                    }
+//                    bossUid = teamInviteRelationService.getBossUid(bossUid);
+//                    if (bossUid != null) {
+//                        rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamSecondDivideRate));
+//                        GoldCornGetRecord ccRecord = new GoldCornGetRecord();
+//                        ccRecord.setDay(record.getDay());
+//                        ccRecord.setType(type);
+//                        ccRecord.setUid(bossUid);
+//                        ccRecord.setFromId(record.getId());
+//                        ccRecord.setFromUid(record.getUid());
+//                        ccRecord.setCornNum(new BigDecimal(baseCornNum).multiply(rate).intValue());
+//                        ccRecord.setLevel(GoldCornGetRecord.LEVEL_SECOND);
+//                        ccRecord.setCreateTime(currentTime);
+//                        if (ccRecord.getCornNum() > 0) {
+//                            goldCornGetRecordService.add(ccRecord);
+//                        }
+//                    }
                 }
             }
         } catch (GoldCornGetRecordException e) {
@@ -256,8 +250,13 @@
         Date now = new Date();
         //鏌ヨ浠婃棩鏄惁宸茬粡绛惧埌
         boolean isSignIn = isSignIn(uid, now);
+        Date deadDate = now;
+        if (!isSignIn) {
+            deadDate = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now.getTime(), "yyyyMMdd"), "yyyyMMdd"));
+        }
+
         //浠婃棩鏈鍒扮殑锛屾煡璇㈣繛缁鍒版鏁板簲璇ヤ粠鍓嶄竴澶╁紑濮嬭绠�
-        int continueDay = goldCornGetRecordService.getContinueDay(uid, GoldCornGetType.signIn, !isSignIn ? new Date(now.getTime() - 1000 * 60 * 60 * 24L) : now);
+        int continueDay = goldCornGetRecordService.getContinueDay(uid, GoldCornGetType.signIn, deadDate);
         return continueDay;
     }
 
@@ -282,5 +281,73 @@
         return addGoldCorn(uid, GoldCornGetType.signIn, false, new Date(), price);
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public Integer watchVideo(Long uid, boolean isDouble, Date time, int timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException {
+        UserInfo user = userInfoService.get(uid);
+        if (user == null) {
+            throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�");
+        }
+
+        Integer price = goldCornGetPriceService.getWatchVideoPrice(user, time, timeSeconds);
+        //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍
+        if (price == 0) {
+            return 0;
+        }
+
+        GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.watchVideo, isDouble, time, price);
+        return record.getCornNum() * (isDouble ? 2 : 1);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public Integer readNovel(Long uid, boolean isDouble, Date time, int timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException {
+
+        String readNovelCacheKey = "task-n-" + uid + "-" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd");
+        Integer readNovelNowSeconds = timeSeconds;
+
+        Integer start = (Integer) redisTemplate.opsForValue().get(readNovelCacheKey);
+        if (start == null) {
+            start = 0;
+        }
+
+        timeSeconds = timeSeconds - start;
+
+        UserInfo user = userInfoService.get(uid);
+        if (user == null) {
+            throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�");
+        }
+
+        Integer price = goldCornGetPriceService.getReadNovelPrice(user, time, timeSeconds);
+        //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍
+        if (price == 0) {
+            return 0;
+        }
+
+        GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.readNovel, isDouble, time, price);
+
+        //璁板綍褰撳ぉ鐨勫疄鏃堕槄璇诲垎閽熸暟
+        redisTemplate.opsForValue().set(readNovelCacheKey, readNovelNowSeconds, 60 * 60 * 24, TimeUnit.SECONDS);
+        return record.getCornNum() * (isDouble ? 2 : 1);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public Integer scanNews(Long uid, boolean isDouble, Date time, int num) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException {
+        UserInfo user = userInfoService.get(uid);
+        if (user == null) {
+            throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�");
+        }
+
+        Integer price = goldCornGetPriceService.getScanNewsPrice(user, time, num);
+        //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍
+        if (price == 0) {
+            return 0;
+        }
+
+        GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.scanNews, isDouble, time, price);
+        return record.getCornNum() * (isDouble ? 2 : 1);
+    }
+
 
 }

--
Gitblit v1.8.0