|
@@ -1,9 +1,15 @@
|
|
|
package com.td.boss.game.complayersattri.service;
|
|
package com.td.boss.game.complayersattri.service;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.td.boss.common.pojo.Result;
|
|
import com.td.boss.common.pojo.Result;
|
|
|
import com.td.boss.common.service.CommonServiceImpl;
|
|
import com.td.boss.common.service.CommonServiceImpl;
|
|
|
|
|
+import com.td.boss.game.complayersattri.enums.ComPlayerLuckyLogEnum;
|
|
|
|
|
+import com.td.boss.game.complayersattri.pojo.ComPlayersAttri;
|
|
|
import com.td.boss.game.complayersattri.pojo.ComPlayersLuckyLog;
|
|
import com.td.boss.game.complayersattri.pojo.ComPlayersLuckyLog;
|
|
|
import com.td.boss.game.complayersattri.pojo.ComPlayersLuckyTools;
|
|
import com.td.boss.game.complayersattri.pojo.ComPlayersLuckyTools;
|
|
|
|
|
+import com.td.boss.game.complayersattri.repository.ComPlayersAttriRepository;
|
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersLuckyLogRepository;
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersLuckyLogRepository;
|
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersLuckyToolsRepository;
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersLuckyToolsRepository;
|
|
|
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyLogVo;
|
|
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyLogVo;
|
|
@@ -15,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
import javax.persistence.PersistenceContext;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -29,13 +36,27 @@ public class ComPlayersLuckyLogServiceImpl extends CommonServiceImpl<ComPlayersL
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ComPlayersLuckyToolsRepository luckyToolsRepository;
|
|
private ComPlayersLuckyToolsRepository luckyToolsRepository;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ComPlayersAttriRepository comPlayersAttriRepository;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public ComPlayersLuckyLogVo findByUserId(String userId) {
|
|
public ComPlayersLuckyLogVo findByUserId(String userId) {
|
|
|
ComPlayersLuckyLog comPlayersLuckyLog = repository.findByUserId(userId).orElse(null);
|
|
ComPlayersLuckyLog comPlayersLuckyLog = repository.findByUserId(userId).orElse(null);
|
|
|
return comPlayersLuckyLog == null ? null : CopyUtil.copy(comPlayersLuckyLog, ComPlayersLuckyLogVo.class);
|
|
return comPlayersLuckyLog == null ? null : CopyUtil.copy(comPlayersLuckyLog, ComPlayersLuckyLogVo.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Result useLuckyTools(Integer id) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用的工具 获得幸运值,12小时获取一次
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @param id
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result useLuckyTools(String userId, Integer id) {
|
|
|
|
|
+ //需要记录 对那块地使用了工具
|
|
|
|
|
+ //明细中应该记录当时工具名称
|
|
|
|
|
+ //工具应该加一个状态字段。标记是否启用该工具
|
|
|
if (id == null || id.equals(0)) {
|
|
if (id == null || id.equals(0)) {
|
|
|
Result.of(null, false, "无效工具");
|
|
Result.of(null, false, "无效工具");
|
|
|
}
|
|
}
|
|
@@ -43,8 +64,32 @@ public class ComPlayersLuckyLogServiceImpl extends CommonServiceImpl<ComPlayersL
|
|
|
if (tools == null) {
|
|
if (tools == null) {
|
|
|
Result.of(null, false, "无效工具");
|
|
Result.of(null, false, "无效工具");
|
|
|
}
|
|
}
|
|
|
- return Result.of(null);
|
|
|
|
|
|
|
+ ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
|
|
+ if (playersAttri == null) {
|
|
|
|
|
+ Result.of(null, false, "无效领取");
|
|
|
|
|
+ }
|
|
|
|
|
+ //验证工具是否可用:每隔一段时间才可使用
|
|
|
|
|
+ Optional<ComPlayersLuckyLog> lastComPlayersLuckyLog = repository.findByUserIdOrderByCreateTimeDesc(userId);
|
|
|
|
|
+ if (lastComPlayersLuckyLog.isPresent()) {
|
|
|
|
|
+ DateTime nextTime = DateUtil.offset(lastComPlayersLuckyLog.get().getCreateTime(), DateField.HOUR_OF_DAY, tools.getToolTime());
|
|
|
|
|
+ if (nextTime.isAfter(new Date())) {
|
|
|
|
|
+ Result.of(null, false, "请在" + nextTime.toDateStr() + "后使用工具");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //写入使用工具明细
|
|
|
|
|
+ ComPlayersLuckyLog comPlayersLuckyLog = new ComPlayersLuckyLog();
|
|
|
|
|
+ comPlayersLuckyLog.setAfterLucky(playersAttri.getLucky() + tools.getToolLucky());
|
|
|
|
|
+ comPlayersLuckyLog.setBeforeLucky(playersAttri.getLucky());
|
|
|
|
|
+ comPlayersLuckyLog.setAmount(tools.getToolLucky());
|
|
|
|
|
+ comPlayersLuckyLog.setLuckyType(ComPlayerLuckyLogEnum.tool.getCode());
|
|
|
|
|
+ comPlayersLuckyLog.setToolsId(id);
|
|
|
|
|
+ comPlayersLuckyLog.setUserId(userId);
|
|
|
|
|
+ repository.save(comPlayersLuckyLog);
|
|
|
|
|
|
|
|
|
|
+ //更新幸运值
|
|
|
|
|
+ playersAttri.setLucky(playersAttri.getLucky() + tools.getToolLucky());
|
|
|
|
|
+ comPlayersAttriRepository.save(playersAttri);
|
|
|
|
|
+ return Result.of(null, true, "使用工具成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|