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 |  217 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 183 insertions(+), 34 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 ca43199..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,22 +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;
@@ -26,15 +24,23 @@
 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;
@@ -48,6 +54,9 @@
 @Controller
 @RequestMapping("api/v1/goldcorn")
 public class GoldCornController {
+
+    Logger logger = LoggerFactory.getLogger(GoldCornController.class);
+
     @Resource
     private GoldCornGetRecordService goldCornGetRecordService;
 
@@ -68,7 +77,19 @@
     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();
 
@@ -155,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);
         }
 
@@ -209,34 +234,48 @@
             return JsonUtil.loadFalseResult("鍙傛暟涓嶅畬鏁�");
         }
 
+
+        String key = "dotask-" + acceptData.getSign();
+        Jedis jedis = jedisPool.getResource();
         try {
-            JSONObject data = new JSONObject();
-            Integer result = null;
-            if (vo.getType() == GoldCornGetType.watchVideo) {
-                result = goldCornMakeService.watchVideo(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds());
-            } else if (vo.getType() == GoldCornGetType.readNovel) {
-                result = goldCornMakeService.readNovel(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds());
-            } else if (vo.getType() == GoldCornGetType.scanNews) {
-                result = goldCornMakeService.scanNews(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getNum());
-            } else {
-                return JsonUtil.loadFalseResult("浠诲姟绫诲瀷鍑洪敊");
+            if (!StringUtil.isNullOrEmpty(jedis.get(key))) {
+                return JsonUtil.loadFalseResult("閲嶅鐨勮姹�");
             }
-            data.put("goldCorn", result);
+            jedis.set(key, "1");
+            //30鍒嗛挓鏈夋晥鏈�
+            jedis.expire(key, 60 * 30);
 
-            return JsonUtil.loadTrueResult(data);
+            try {
+                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());
+            } 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();
         }
     }
 
@@ -244,6 +283,116 @@
     /**
      * @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);
+            }
+        }
+        JSONObject data = new JSONObject();
+        data.put("list", JsonUtil.getSimpleGson().toJson(voList));
+        data.put("count", voList.size());
+        return JsonUtil.loadTrueResult(data);
+    }
+
+
+    /**
+     * @return java.lang.String
+     * @author hxh
      * @description 鑾峰彇绛惧埌淇℃伅
      * @date 17:12 2022/4/21
      * @param: acceptData

--
Gitblit v1.8.0