|
|
@@ -3,6 +3,7 @@ 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.math.MathUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import com.td.boss.common.service.*;
|
|
|
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
|
|
|
@@ -10,6 +11,7 @@ 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.CopyUtil;
|
|
|
import com.td.boss.util.DoubleUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.jdbc.metadata.OracleUcpDataSourcePoolMetadata;
|
|
|
@@ -48,6 +50,7 @@ public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, C
|
|
|
* @param userId 用户id
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void powerLoss(String userId) {
|
|
|
// 查询 [种植] [收取果实] [偷取果实] [卖出果实] 最后操作时间
|
|
|
ComPlayerLog comPlayerLog = comPlayerLogRepository.findFirstByUserIdOrderByCreateTimeDesc(userId).orElse(null);
|
|
|
@@ -69,8 +72,10 @@ public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, C
|
|
|
System.out.println("未到7天不损耗");
|
|
|
return;
|
|
|
}
|
|
|
- // 最多持续8天
|
|
|
- dayDiff = dayDiff > 8 ? 8 : dayDiff;
|
|
|
+ // 最多持续8天.
|
|
|
+ dayDiff = dayDiff > 14 ? 14 : dayDiff;
|
|
|
+ // 7 8 9 10 11 12 13 14
|
|
|
+ dayDiff = Math.abs(14 - 8 - dayDiff);
|
|
|
System.out.println("实际断电损耗:" + dayDiff + "天");
|
|
|
|
|
|
List<ComPlayerGoods> fruitList = comPlayerGoodsRepository.findAllByUserId(userId).stream().filter(a -> a.getGoodsType().equals(1)).collect(Collectors.toList());
|
|
|
@@ -78,17 +83,45 @@ public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, C
|
|
|
System.out.println("仓库无果实不损耗");
|
|
|
return;
|
|
|
}
|
|
|
- List<ComPlayerGoods> saveList = new ArrayList<>();
|
|
|
+ // 更新仓库果实量
|
|
|
+ List<ComPlayerGoods> playerGoodsList = new ArrayList<>();
|
|
|
+ // 写入明细
|
|
|
+ List<ComPlayerLog> playerLogList = new ArrayList<>();
|
|
|
+
|
|
|
for (ComPlayerGoods goods : fruitList) {
|
|
|
- double amount = goods.getAmount() + goods.getAmountPart();
|
|
|
- amount = amount * (1 - NumberUtil.div(dayDiff, 100));
|
|
|
+ // 操作仓库
|
|
|
+ int goodsBeforeAmount = goods.getAmount();
|
|
|
+ double goodsBeforePart = goods.getAmountPart();
|
|
|
+ //
|
|
|
+ double amount = (goodsBeforeAmount + goodsBeforePart) * (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);
|
|
|
+ playerGoodsList.add(goods);
|
|
|
+
|
|
|
+ // 写入明细
|
|
|
+ ComPlayerLog playerLog = new ComPlayerLog();
|
|
|
+ playerLog.setUserId(userId);
|
|
|
+ // 操作目标id,比如进入背包的是收获时候操作:水果
|
|
|
+ playerLog.setTId(goods.getGoodsIndex());
|
|
|
+ playerLog.setTName(goods.getName());
|
|
|
+ // 1=果实
|
|
|
+ playerLog.setTType(1);
|
|
|
+ playerLog.setBeforeAmount(goodsBeforeAmount);
|
|
|
+ playerLog.setBeforePart(goodsBeforePart);
|
|
|
+ // 交易后的数据
|
|
|
+ playerLog.setAfterAmount(goods.getAmount());
|
|
|
+ playerLog.setAfterPart(goods.getAmountPart());
|
|
|
+ // 收获时候,会有一个倍数
|
|
|
+ playerLog.setLMultiple(0);
|
|
|
+ // 损失
|
|
|
+ playerLog.setTLoss((goodsBeforeAmount + goodsBeforePart) * NumberUtil.div(dayDiff, 100));
|
|
|
+ playerLog.setCreateTime(serverDate);
|
|
|
+ playerLogList.add(playerLog);
|
|
|
}
|
|
|
- comPlayerGoodsRepository.saveAll(saveList);
|
|
|
+ comPlayerGoodsRepository.saveAll(playerGoodsList);
|
|
|
+ comPlayerLogRepository.saveAll(playerLogList);
|
|
|
+
|
|
|
System.out.println("损耗完成");
|
|
|
}
|
|
|
|