|
|
@@ -1,21 +1,102 @@
|
|
|
package com.td.boss.game.complayerlog.service;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.jdbc.metadata.OracleUcpDataSourcePoolMetadata;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, ComPlayerLog, Integer> implements ComPlayerLogService{
|
|
|
+public class ComPlayerLogServiceImpl extends CommonServiceImpl<ComPlayerLogVo, ComPlayerLog, Integer> implements ComPlayerLogService {
|
|
|
|
|
|
@PersistenceContext
|
|
|
private EntityManager em;
|
|
|
@Autowired
|
|
|
private ComPlayerLogRepository comPlayerLogRepository;
|
|
|
+ @Autowired
|
|
|
+ private ComPlayerGoodsRepository comPlayerGoodsRepository;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 7天没有操作仓库进入断电损耗期,最多持续8天
|
|
|
+ * 1.查询5种操作最后一次操作时间
|
|
|
+ * - 购买种子
|
|
|
+ * - 种植
|
|
|
+ * - 收取果实
|
|
|
+ * - 偷取果实
|
|
|
+ * - 卖出果实
|
|
|
+ * 2.计算并执行本次损耗
|
|
|
+ *
|
|
|
+ * @param userId 用户id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void powerLoss(String userId) {
|
|
|
+ // 查询 [种植] [收取果实] [偷取果实] [卖出果实] 最后操作时间
|
|
|
+ ComPlayerLog comPlayerLog = comPlayerLogRepository.findFirstByUserIdOrderByCreateTimeDesc(userId).orElse(null);
|
|
|
+ // 查询 [购买种子] 最后操作时间,这里查询这张表是因为购买种子不会往 [com_player_log] 表写数据
|
|
|
+ ComPlayerGoods comPlayerGoods = comPlayerGoodsRepository.findFirstByUserIdOrderByCreateTimeDesc(userId).orElse(null);
|
|
|
+ // 这是个空号.
|
|
|
+ if (comPlayerLog == null && comPlayerGoods == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 计算最后操作时间
|
|
|
+ Date lastOperationTime = lastOperationTime(comPlayerLog, comPlayerGoods);
|
|
|
+ System.out.println("最后操作时间:" + dateFormat(lastOperationTime));
|
|
|
+ // 计算服务器时间与最后操作时间差
|
|
|
+ long dayDiff = DateUtil.betweenDay(new Date(), lastOperationTime, false);
|
|
|
+ System.out.println("与服务器时间相差:" + dayDiff + "天");
|
|
|
+ // 7天未操作 + 最多持续8天.
|
|
|
+ if (dayDiff >= 7 && dayDiff <= 15) {
|
|
|
+ System.out.println("进入断电损耗");
|
|
|
+ // 开始计算断电损耗。不影响种子(如:果实成熟总收益为120,种子保底收益为100,那么每天损耗部分为20的1%)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.out.println("不损耗");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最后一次操作时间
|
|
|
+ *
|
|
|
+ * @param comPlayerLog 交易日志
|
|
|
+ * @param comPlayerGoods 最后购买种子时间
|
|
|
+ * @return {@link Date}
|
|
|
+ */
|
|
|
+ private Date lastOperationTime(ComPlayerLog comPlayerLog, ComPlayerGoods comPlayerGoods) {
|
|
|
+ if (comPlayerLog == null) {
|
|
|
+ System.out.println("[comPlayerLog]表无记录. 最后操作时间:" + dateFormat(comPlayerGoods.getCreateTime()));
|
|
|
+ return comPlayerGoods.getCreateTime();
|
|
|
+ } else if (comPlayerGoods == null) {
|
|
|
+ System.out.println("[comPlayerGoods]表无记录. 最后操作时间:" + dateFormat(comPlayerLog.getCreateTime()));
|
|
|
+ return comPlayerLog.getCreateTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("[comPlayerLog]表最后操作日期:" + dateFormat(comPlayerLog.getCreateTime()));
|
|
|
+ System.out.println("[comPlayerGoods]表最后操作日期:" + dateFormat(comPlayerGoods.getCreateTime()));
|
|
|
+ if (comPlayerGoods.getCreateTime().before(comPlayerLog.getCreateTime())) {
|
|
|
+ return comPlayerLog.getCreateTime();
|
|
|
+ } else {
|
|
|
+ return comPlayerGoods.getCreateTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期格式化
|
|
|
+ *
|
|
|
+ * @param date 日期
|
|
|
+ * @return {@link String}
|
|
|
+ */
|
|
|
+ private String dateFormat(Date date) {
|
|
|
+ return DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ }
|
|
|
}
|