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/service/impl/goldcorn/GoldCornGetPriceServiceImpl.java |   98 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetPriceServiceImpl.java b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetPriceServiceImpl.java
index 95378cb..2478b0f 100644
--- a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetPriceServiceImpl.java
+++ b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetPriceServiceImpl.java
@@ -3,20 +3,26 @@
 import java.lang.Exception;
 import javax.annotation.Resource;
 
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.yeshi.makemoney.app.entity.SystemEnum;
+import com.yeshi.makemoney.app.entity.config.SystemConfigKey;
 import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
+import com.yeshi.makemoney.app.entity.goldcorn.GoldCornPriceCountType;
+import com.yeshi.makemoney.app.entity.user.UserInfo;
+import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException;
+import com.yeshi.makemoney.app.service.inter.config.SystemConfigService;
+import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
+import java.lang.reflect.Type;
 import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Date;
+import java.util.*;
 
 import org.yeshi.utils.StringUtil;
 import org.yeshi.utils.TimeUtil;
 import org.yeshi.utils.bean.BeanUtil;
-
-import java.util.List;
 
 import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetPriceDao;
 import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetPrice;
@@ -32,6 +38,12 @@
 
     @Resource
     private GoldCornGetPriceDao goldCornGetPriceDao;
+
+    @Resource
+    private SystemConfigService systemConfigService;
+
+    @Resource
+    private TeamInviteRelationService teamInviteRelationService;
 
     @Override
     public List<GoldCornGetPrice> list(GoldCornGetPriceQuery goldCornGetPriceQuery, int page, int pageSize) {
@@ -123,5 +135,83 @@
         return new BigDecimal(price.getCornNum()).multiply(new BigDecimal(1).add(price.getTeamGainRate())).intValue();
     }
 
+    @Override
+    public Integer getSingInPrice(SystemEnum system, int continueDay) {
+        List<Integer> list = getSingInPriceList(system);
+        if (list == null) {
+            return null;
+        }
+
+        if (continueDay >= list.size()) {
+            return list.get(list.size() - 1);
+        }
+
+        if (continueDay <= 0) {
+            return list.get(0);
+        }
+
+        return list.get(continueDay - 1);
+    }
+
+    @Override
+    public List<Integer> getSingInPriceList(SystemEnum system) {
+        String value = systemConfigService.getValueCache(system, SystemConfigKey.signInGoldCorn);
+        if (StringUtil.isNullOrEmpty(value)) {
+            return null;
+        }
+        Type type = new TypeToken<List<Integer>>() {
+        }.getType();
+        return new Gson().fromJson(value, type);
+    }
+
+    @Override
+    public Integer getCountPrice(GoldCornGetType type, UserInfo user, SystemEnum system, Date date, long eventCount) throws GoldCornGetPriceException {
+        GoldCornGetPrice getPrice = getPrice(system, type, date);
+        if (getPrice == null) {
+            throw new GoldCornGetPriceException(GoldCornGetPriceException.CODE_NOT_EXIST, "浠锋牸淇℃伅缂哄け");
+        }
+
+        int goldCorn;
+        if (getPrice.getCountType() == GoldCornPriceCountType.time) {
+            goldCorn = (int) (eventCount * getPrice.getCornNum() / 60.0f);
+
+        } else {
+            goldCorn = (int) (eventCount * getPrice.getCornNum());
+        }
+
+        //鍔犱笂鍥㈤槦澧炵泭姣斾緥
+        if (user != null && teamInviteRelationService.getBossUid(user.getId()) != null) {
+            goldCorn = new BigDecimal(goldCorn).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue();
+        }
+        return goldCorn;
+    }
+
+    @Override
+    public Map<GoldCornGetType, GoldCornGetPrice> getCountPrice(List<GoldCornGetType> typeList, UserInfo user, SystemEnum system, Date date) {
+        Map<GoldCornGetType, GoldCornGetPrice> map = new HashMap();
+        for (GoldCornGetType type : typeList) {
+            GoldCornGetPrice getPrice = getPrice(system, type, date);
+            if (getPrice == null) {
+                continue;
+            }
+            int goldCorn = getPrice.getCornNum();
+            //鍔犱笂鍥㈤槦澧炵泭姣斾緥
+            if (user != null && teamInviteRelationService.getBossUid(user.getId()) != null) {
+                goldCorn = new BigDecimal(goldCorn).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue();
+            }
+            getPrice.setCornNum(goldCorn);
+            map.put(type, getPrice);
+        }
+        return map;
+    }
+
+    @Override
+    public GoldCornGetPrice getCountPrice(GoldCornGetType type, UserInfo user, SystemEnum system, Date date) {
+
+        Map<GoldCornGetType, GoldCornGetPrice> map = getCountPrice(Arrays.asList(new GoldCornGetType[]{type}), user, system, date);
+
+        return map.get(type);
+    }
+
 
 }
\ No newline at end of file

--
Gitblit v1.8.0