|
|
@@ -1,12 +1,16 @@
|
|
|
package com.td.boss.game.complayerlog.service;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.format.AbstractDateBasic;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import com.td.boss.common.service.*;
|
|
|
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
|
|
|
import com.td.boss.game.complayergoods.repository.ComPlayerGoodsRepository;
|
|
|
import com.td.boss.game.complayerlog.pojo.ComPlayerLog;
|
|
|
import com.td.boss.game.complayerlog.vo.ComPlayerLogVo;
|
|
|
import com.td.boss.game.complayerlog.repository.ComPlayerLogRepository;
|
|
|
+import com.td.boss.util.DoubleUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.jdbc.metadata.OracleUcpDataSourcePoolMetadata;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -14,7 +18,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
@@ -53,16 +61,35 @@ public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, C
|
|
|
Date lastOperationTime = lastOperationTime(comPlayerLog, comPlayerGoods);
|
|
|
System.out.println("最后操作时间:" + dateFormat(lastOperationTime));
|
|
|
// 计算服务器时间与最后操作时间差
|
|
|
- long dayDiff = DateUtil.betweenDay(new Date(), lastOperationTime, false);
|
|
|
+ Date serverDate = new Date();
|
|
|
+ long dayDiff = DateUtil.betweenDay(serverDate, lastOperationTime, false);
|
|
|
System.out.println("与服务器时间相差:" + dayDiff + "天");
|
|
|
- // 7天未操作 + 最多持续8天.
|
|
|
- if (dayDiff >= 7 && dayDiff <= 15) {
|
|
|
- System.out.println("进入断电损耗");
|
|
|
- // 开始计算断电损耗。不影响种子(如:果实成熟总收益为120,种子保底收益为100,那么每天损耗部分为20的1%)
|
|
|
+ // 7天未操作
|
|
|
+ if (dayDiff < 7) {
|
|
|
+ System.out.println("未到7天不损耗");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 最多持续8天
|
|
|
+ dayDiff = dayDiff > 8 ? 8 : dayDiff;
|
|
|
+ System.out.println("实际断电损耗:" + dayDiff + "天");
|
|
|
|
|
|
- } else {
|
|
|
- System.out.println("不损耗");
|
|
|
+ List<ComPlayerGoods> fruitList = comPlayerGoodsRepository.findAllByUserId(userId).stream().filter(a -> a.getGoodsType().equals(1)).collect(Collectors.toList());
|
|
|
+ if (fruitList.size() == 0) {
|
|
|
+ System.out.println("仓库无果实不损耗");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ComPlayerGoods> saveList = new ArrayList<>();
|
|
|
+ for (ComPlayerGoods goods : fruitList) {
|
|
|
+ double amount = goods.getAmount() + goods.getAmountPart();
|
|
|
+ amount = amount * (1 - NumberUtil.div(dayDiff, 100));
|
|
|
+ goods.setAmount((int) Math.floor(amount));
|
|
|
+ goods.setAmountPart(DoubleUtil.sub(amount, Math.floor(amount)));
|
|
|
+ // 重要! 重置最后操作时间
|
|
|
+ goods.setCreateTime(serverDate);
|
|
|
+ saveList.add(goods);
|
|
|
}
|
|
|
+ comPlayerGoodsRepository.saveAll(saveList);
|
|
|
+ System.out.println("损耗完成");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -76,7 +103,8 @@ public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, C
|
|
|
if (comPlayerLog == null) {
|
|
|
System.out.println("[comPlayerLog]表无记录. 最后操作时间:" + dateFormat(comPlayerGoods.getCreateTime()));
|
|
|
return comPlayerGoods.getCreateTime();
|
|
|
- } else if (comPlayerGoods == null) {
|
|
|
+ }
|
|
|
+ if (comPlayerGoods == null) {
|
|
|
System.out.println("[comPlayerGoods]表无记录. 最后操作时间:" + dateFormat(comPlayerLog.getCreateTime()));
|
|
|
return comPlayerLog.getCreateTime();
|
|
|
}
|