From 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 28 十月 2022 16:55:02 +0800
Subject: [PATCH] 批量添加结算消息

---
 app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java |  239 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 212 insertions(+), 27 deletions(-)

diff --git a/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java b/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java
index cfbe335..4a8d581 100644
--- a/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java
+++ b/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java
@@ -3,21 +3,20 @@
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
+import com.yeshi.makemoney.app.dto.goldcorn.GoldCornMakeResultDTO;
+import com.yeshi.makemoney.app.entity.goldcorn.*;
+import com.yeshi.makemoney.app.entity.user.UserInfo;
 import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetFrequencyConfigException;
 import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException;
 import com.yeshi.makemoney.app.exception.goldcorn.GoldCornMakeException;
 import com.yeshi.makemoney.app.exception.user.UserInfoException;
-import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornConsumeRecordService;
-import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetPriceService;
-import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService;
-import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMakeService;
+import com.yeshi.makemoney.app.service.inter.goldcorn.*;
 import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService;
+import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService;
+import com.yeshi.makemoney.app.service.inter.user.UserInfoService;
 import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornConsumeRecordQuery;
 import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery;
+import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornTaskTypeInfoQuery;
 import com.yeshi.makemoney.app.utils.Constant;
 import com.yeshi.makemoney.app.utils.annotation.UserLogin;
 import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil;
@@ -25,15 +24,25 @@
 import com.yeshi.makemoney.app.vo.goldcorn.*;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.StringUtil;
 import org.yeshi.utils.TimeUtil;
+import org.yeshi.utils.annotation.RequestSerializableByKey;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
 
 import javax.annotation.Resource;
 import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -45,6 +54,9 @@
 @Controller
 @RequestMapping("api/v1/goldcorn")
 public class GoldCornController {
+
+    Logger logger = LoggerFactory.getLogger(GoldCornController.class);
+
     @Resource
     private GoldCornGetRecordService goldCornGetRecordService;
 
@@ -60,6 +72,24 @@
 
     @Resource
     private TeamInviteRelationService teamInviteRelationService;
+
+    @Resource
+    private UserExtraInfoService userExtraInfoService;
+
+    @Resource
+    private UserInfoService userInfoService;
+
+    @Resource
+    private RedisTemplate<String, Object> redisTemplate;
+
+    @Resource
+    private JedisPool jedisPool;
+
+    @Resource
+    private GoldCornTaskTypeInfoService goldCornTaskTypeInfoService;
+
+    @Resource
+    private GoldCornGetFrequencyConfigService goldCornGetFrequencyConfigService;
 
     private Gson gson = JsonUtil.getConvertBigDecimalToStringBuilder(new GsonBuilder()).create();
 
@@ -146,9 +176,13 @@
         List<GoldCornExchangeRecordVO> voList = new ArrayList<>();
         for (GoldCornConsumeRecord record : recordList) {
             GoldCornExchangeRecordVO vo = new GoldCornExchangeRecordVO();
-            vo.setDateTime(TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyy.MM.dd HH:mm"));
+            if (record.getEventTime() == null) {
+                vo.setDateTime(TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyy.MM.dd HH:mm"));
+            } else {
+                vo.setDateTime(TimeUtil.getGernalTime(record.getEventTime().getTime(), "yyyy.MM.dd"));
+            }
             vo.setNum(record.getCornNum());
-            vo.setMoney(record.getMoney().setScale(2).toString());
+            vo.setMoney(new BigDecimal(record.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR).toString());
             voList.add(vo);
         }
 
@@ -194,34 +228,165 @@
     @UserLogin(uid = "#uid")
     @RequestMapping("doTask")
     @ResponseBody
-    public String doTask(AcceptData acceptData, Long uid, String taskData) {
-        Type type = new TypeToken<List<GoldCornDoTaskVO>>() {
-        }.getType();
-        List<GoldCornDoTaskVO> list = null;
+    public String doTask(AcceptData acceptData, Long uid, GoldCornDoTaskVO vo) {
 
+        if (vo.getType() == null) {
+            return JsonUtil.loadFalseResult("鍙傛暟涓嶅畬鏁�");
+        }
+
+
+        String key = "dotask-" + acceptData.getSign();
+        Jedis jedis = jedisPool.getResource();
         try {
-            list = gson.fromJson(taskData, type);
-        } catch (Exception e) {
+            if (!StringUtil.isNullOrEmpty(jedis.get(key))) {
+                return JsonUtil.loadFalseResult("閲嶅鐨勮姹�");
+            }
+            jedis.set(key, "1");
+            //30鍒嗛挓鏈夋晥鏈�
+            jedis.expire(key, 60 * 30);
 
-        }
-        if (list == null) {
-            return JsonUtil.loadFalseResult("鏁版嵁涓虹┖");
-        }
-
-        for (GoldCornDoTaskVO vo : list) {
             try {
-                goldCornMakeService.addGoldCorn(uid, vo.getType(), vo.getDouble() == null ? false : vo.getDouble(), new Date(vo.getFinishTime() == null ? System.currentTimeMillis() : vo.getFinishTime()), null);
-            } catch (UserInfoException e) {
-                e.printStackTrace();
+                JSONObject data = new JSONObject();
+                GoldCornMakeResultDTO result = null;
+                if (vo.getType() == GoldCornGetType.watchVideo) {
+                    result = goldCornMakeService.watchVideo(uid, vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds());
+                } else if (vo.getType() == GoldCornGetType.readNovel) {
+                    result = goldCornMakeService.readNovel(uid, vo.getDoubles() == null ? false : vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds());
+                } else if (vo.getType() == GoldCornGetType.scanNews) {
+                    result = goldCornMakeService.scanNews(uid, vo.getDoubles() == null ? false : vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getNum());
+                } else {
+                    return JsonUtil.loadFalseResult("浠诲姟绫诲瀷鍑洪敊");
+                }
+                data.put("goldCorn", result.getGoldCorn());
+                data.put("leftCount", result.getLeftEventCount());
+                return JsonUtil.loadTrueResult(data);
+
             } catch (GoldCornGetPriceException e) {
                 e.printStackTrace();
+                return JsonUtil.loadFalseResult("涓氬姟閿欒");
+            } catch (UserInfoException e) {
+                e.printStackTrace();
+                return JsonUtil.loadFalseResult(e.getMessage());
+            } catch (GoldCornMakeException e) {
+                e.printStackTrace();
+                return JsonUtil.loadFalseResult(e.getMessage());
+            } catch (GoldCornGetFrequencyConfigException e) {
+                e.printStackTrace();
+                return JsonUtil.loadFalseResult(e.getMessage());
+            }
+        } finally {
+            jedis.close();
+        }
+    }
+
+
+    /**
+     * @return java.lang.String
+     * @author hxh
+     * @description 鑾峰彇浠诲姟淇℃伅
+     * @date 18:58 2022/4/28
+     * @param: acceptData
+     * @param: uid
+     * @param: vo
+     **/
+    @RequestMapping("getTaskInfo")
+    @ResponseBody
+    public String getTaskInfo(AcceptData acceptData, Long uid, String type) {
+
+        GoldCornGetType goldCornGetType = GoldCornGetType.valueOf(type);
+        if (goldCornGetType == null) {
+            return JsonUtil.loadFalseResult("绫诲瀷涓嶅瓨鍦�");
+        }
+
+        Date now = new Date();
+        UserInfo user = null;
+        if (uid != null) {
+            user = userInfoService.get(uid);
+        }
+        //鑾峰彇鍗曚环
+        GoldCornGetPrice price = goldCornGetPriceService.getCountPrice(goldCornGetType, user, acceptData.getSystem(), now);
+        boolean finish = true;
+        if (uid != null) {
+            try {
+                if (goldCornMakeService.frequencyVerify(user, goldCornGetType, now) > 0) {
+                    finish = false;
+                }
             } catch (GoldCornGetFrequencyConfigException e) {
                 e.printStackTrace();
             } catch (GoldCornMakeException e) {
                 e.printStackTrace();
+                finish = false;
+            }
+        } else {
+            finish = false;
+        }
+        JSONObject data = new JSONObject();
+        data.put("price", price.getCornNum());
+        data.put("finish", finish);
+        return JsonUtil.loadTrueResult(data);
+    }
+
+
+    /**
+     * @return java.lang.String
+     * @author hxh
+     * @description 鑾峰彇浠诲姟鍒楄〃
+     * @date 11:27 2022/4/28
+     * @param: acceptData
+     * @param: uid
+     **/
+    @RequestMapping("getTaskList")
+    @ResponseBody
+    public String getTaskList(AcceptData acceptData, Long uid) {
+        Date now = new Date();
+
+        GoldCornTaskTypeInfoQuery query = new GoldCornTaskTypeInfoQuery();
+        query.setSystem(acceptData.getSystem());
+        query.setShow(true);
+        query.setShowTime(now);
+
+        List<GoldCornTaskTypeInfo> list = goldCornTaskTypeInfoService.list(query, 1, 100);
+
+        List<GoldCornTaskVO> voList = new ArrayList<>();
+        if (list != null) {
+            UserInfo user = null;
+            if (uid != null) {
+                user = userInfoService.get(uid);
+            }
+            //鏌ヨ浠锋牸
+            List<GoldCornGetType> typeList = list.stream().map(item -> {
+                return item.getType();
+            }).collect(Collectors.toList());
+
+            Map<GoldCornGetType, GoldCornGetPrice> priceMap = goldCornGetPriceService.getCountPrice(typeList, user, acceptData.getSystem(), now);
+
+            Map<GoldCornGetType, Long> processMap = new HashMap<>();
+            if (uid != null) {
+                GoldCornGetRecordQuery goldCornGetRecordQuery = new GoldCornGetRecordQuery();
+                goldCornGetRecordQuery.setUid(uid);
+                goldCornGetRecordQuery.setDay(GoldCornUtil.getFormatDay(now));
+                //鑾峰彇浠婃棩鐨勮繘搴�
+                processMap = goldCornGetRecordService.sumEventCount(goldCornGetRecordQuery);
+            }
+            List<GoldCornGetFrequencyConfig> frequencyConfigs = goldCornGetFrequencyConfigService.listByTypes(typeList, acceptData.getSystem(), now);
+            Map<GoldCornGetType, GoldCornGetFrequencyConfig> frequencyConfigsMaps = frequencyConfigs.stream().collect(Collectors.toMap(GoldCornGetFrequencyConfig::getType, config -> config));
+
+
+            for (GoldCornTaskTypeInfo task : list) {
+                if (priceMap.get(task.getType()) == null) {
+                    continue;
+                }
+                if (frequencyConfigsMaps.get(task.getType()) == null) {
+                    continue;
+                }
+                GoldCornTaskVO vo = GoldCornTaskVO.create(task, priceMap.get(task.getType()), frequencyConfigsMaps.get(task.getType()), processMap.get(task.getType()));
+                voList.add(vo);
             }
         }
-        return JsonUtil.loadTrueResult("");
+        JSONObject data = new JSONObject();
+        data.put("list", JsonUtil.getSimpleGson().toJson(voList));
+        data.put("count", voList.size());
+        return JsonUtil.loadTrueResult(data);
     }
 
 
@@ -246,6 +411,7 @@
         if (uid != null) {
             vo.setSignIned(goldCornMakeService.isSignIn(uid, now));
             vo.setContinueSignInDay(goldCornMakeService.getContinueSignDay(uid));
+            vo.setNotify(userExtraInfoService.getSignInNotify(uid));
         }
         /*************绛惧埌鏃ユ湡鍒楄〃寮�濮�**************/
 
@@ -293,7 +459,7 @@
             } else {
                 dayDiff++;
                 //鏈潵鐨勬椂闂�
-                dayInfo.setGoldCorn(goldCornGetPriceService.getSingInPrice(acceptData.getSystem(), vo.getContinueSignInDay() + 1 + dayDiff));
+                dayInfo.setGoldCorn(goldCornGetPriceService.getSingInPrice(acceptData.getSystem(), vo.getContinueSignInDay() + (vo.isSignIned() ? 0 : 1) + dayDiff));
                 dayInfo.setState(SignInInfoVO.SignInDayInfo.STATE_NOT_GOT);
             }
             //娓呴櫎涓存椂鍙橀噺
@@ -354,4 +520,23 @@
 
     }
 
+
+    /**
+     * @return java.lang.String
+     * @author hxh
+     * @description 璁剧疆绛惧埌鎻愰啋
+     * @date 10:39 2022/4/22
+     * @param: acceptData
+     * @param: uid
+     * @param: notify 鏄惁鎻愰啋
+     **/
+    @UserLogin(uid = "#uid")
+    @RequestMapping("setSignInNotify")
+    @ResponseBody
+    public String setSignInNotify(AcceptData acceptData, Long uid, boolean notify) {
+        userExtraInfoService.setSignInNotify(uid, notify);
+        return JsonUtil.loadTrueResult("");
+    }
+
+
 }

--
Gitblit v1.8.0