|
|
@@ -45,8 +45,6 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
|
|
|
private String toolskey = "land_tools";
|
|
|
private String levelUp = "land_level";
|
|
|
- @PersistenceContext
|
|
|
- private EntityManager em;
|
|
|
|
|
|
@Autowired
|
|
|
private ComConfigService comConfigService;
|
|
|
@@ -63,28 +61,6 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
@Autowired
|
|
|
private RedisLock redisLock;
|
|
|
|
|
|
- /**
|
|
|
- * 获取所有工具列表,方便用户选择使用哪种工具来获取幸运值
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<ComPlayersLuckyToolsVo> getLandTools() {
|
|
|
- String land_tools = comConfigService.selectByKey(toolskey);
|
|
|
- return JSONUtil.toList(land_tools, ComPlayersLuckyToolsVo.class);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取土地升级列表
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<ComPlayersLuckyLandLevelUpVo> getLandLevelUp() {
|
|
|
- String land_tools = comConfigService.selectByKey(levelUp);
|
|
|
- return JSONUtil.toList(land_tools, ComPlayersLuckyLandLevelUpVo.class);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 使用的工具 获得幸运值,12小时获取一次
|
|
|
*
|
|
|
@@ -93,25 +69,33 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result useLuckyTools(String userId, Integer toolId, Integer landId) {
|
|
|
- if (toolId == null || toolId.equals(0)) {
|
|
|
- return Result.of(null, false, "无效工具");
|
|
|
- }
|
|
|
+ //验证工具是否存在
|
|
|
ComPlayersLuckyToolsVo tools = getLandTools().stream().filter(a -> a.getId().equals(toolId)).findFirst().orElse(null);
|
|
|
if (tools == null || tools.isEnable() == false) {
|
|
|
return Result.of(null, false, "无效工具");
|
|
|
}
|
|
|
+ //验证土地是否存在
|
|
|
+ ComPlayerLand comPlayerLand = comPlayerLandRepository.findById(landId).orElse(null);
|
|
|
+ if (comPlayerLand == null || comPlayerLand.getUserId().equals(userId) == false) {
|
|
|
+ return Result.of(null, false, "升级失败,无效土地!");
|
|
|
+ }
|
|
|
+ //土地租赁到期了,不能使用工具
|
|
|
+ if (comPlayerLand.getLeaseTime().before(new Date())) {
|
|
|
+ return Result.of(null, false, "升级失败,土地已到期!");
|
|
|
+ }
|
|
|
+ //验证用户是否存在
|
|
|
+ ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
+ if (playersAttri == null) {
|
|
|
+ return Result.of(null, false, "无效用户");
|
|
|
+ }
|
|
|
|
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerLandToolTimeout();
|
|
|
String _redisKey = "LOCK:COM_PLAYER_LAND_TOOL:" + userId;
|
|
|
if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
return Result.of(null, false, ResultEnum.LAND_USE_TOOL.getMessage(), ResultEnum.LAND_USE_TOOL.getCode());
|
|
|
}
|
|
|
-
|
|
|
- ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
- if (playersAttri == null) {
|
|
|
- return Result.of(null, false, "无效用户");
|
|
|
- }
|
|
|
//验证工具是否可用:每隔一段时间才可使用
|
|
|
Optional<ComPlayersLucky> lastComPlayersLuckyLog = repository.findFirstByUserIdOrderByCreateTimeDesc(userId);
|
|
|
if (lastComPlayersLuckyLog.isPresent()) {
|
|
|
@@ -120,9 +104,10 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
return Result.of(null, false, "请在" + nextTime.toDateStr() + "后使用工具");
|
|
|
}
|
|
|
}
|
|
|
+ int afterLucky = playersAttri.getLucky() + tools.getToolLucky();
|
|
|
//写入使用工具明细
|
|
|
ComPlayersLucky comPlayersLucky = new ComPlayersLucky();
|
|
|
- comPlayersLucky.setAfterLucky(playersAttri.getLucky() + tools.getToolLucky());
|
|
|
+ comPlayersLucky.setAfterLucky(afterLucky);
|
|
|
comPlayersLucky.setBeforeLucky(playersAttri.getLucky());
|
|
|
comPlayersLucky.setAmount(tools.getToolLucky());
|
|
|
comPlayersLucky.setLuckyType(ComPlayerLuckyLogEnum.tool.getCode());
|
|
|
@@ -135,7 +120,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
repository.save(comPlayersLucky);
|
|
|
|
|
|
//更新幸运值
|
|
|
- playersAttri.setLucky(playersAttri.getLucky() + tools.getToolLucky());
|
|
|
+ playersAttri.setLucky(afterLucky);
|
|
|
comPlayersAttriRepository.save(playersAttri);
|
|
|
return Result.of(null, true, "使用工具成功");
|
|
|
}
|
|
|
@@ -149,45 +134,49 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result<?> landLevelUp(String userId, Integer levelId, Integer landId) {
|
|
|
-
|
|
|
- ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
- if (playersAttri == null) {
|
|
|
- return Result.of(null, false, "无效领取");
|
|
|
- }
|
|
|
- Optional<ComPlayersLuckyLandLevelUpVo> levelLand = getLandLevelUp().stream().filter(a -> a.getId().equals(levelId)).findFirst();
|
|
|
- if (levelLand.isPresent() == false) {
|
|
|
+ //验证土地级别是否存在
|
|
|
+ ComPlayersLuckyLandLevelUpVo landLevelUpVo = getLandLevelUp().stream().filter(a -> a.getId().equals(levelId)).findFirst().orElse(null);
|
|
|
+ if (landLevelUpVo == null) {
|
|
|
return Result.of(null, false, "升级失败,无效升级!");
|
|
|
}
|
|
|
- ComPlayerLand land = comPlayerLandRepository.findByUserIdAndConfigLandId(userId, landId).orElse(null);
|
|
|
- if (land == null) {
|
|
|
+ //验证土地是否存在
|
|
|
+ ComPlayerLand comPlayerLand = comPlayerLandRepository.findById(landId).orElse(null);
|
|
|
+ if (comPlayerLand == null || comPlayerLand.getUserId().equals(userId) == false) {
|
|
|
return Result.of(null, false, "升级失败,无效土地!");
|
|
|
}
|
|
|
- if (land.getLandLevel() >= levelId) {
|
|
|
+ //验证 将要升级的土地级别是否大于当前土地级别
|
|
|
+ if (comPlayerLand.getLandLevel() >= levelId) {
|
|
|
return Result.of(null, false, "升级失败,无效级别!");
|
|
|
}
|
|
|
//土地租赁到期了,不能升级
|
|
|
- if (getEndTime(land.getLeaseTime(), land.getLeaseDate()).before(new Date())) {
|
|
|
+ if (comPlayerLand.getLeaseTime().before(new Date())) {
|
|
|
return Result.of(null, false, "升级失败,土地已到期!");
|
|
|
}
|
|
|
- //剩余幸运值
|
|
|
- int sub = Convert.toInt(NumberUtil.sub(playersAttri.getLucky(), levelLand.get().getCostLucky()));
|
|
|
- if (sub < 0) {
|
|
|
- return Result.of(null, false, "升级失败,幸运值不足!");
|
|
|
- }
|
|
|
+
|
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerLandLevelupTimeout();
|
|
|
String _redisKey = "LOCK:COM_PLAYER_LAND_LEVELUP:" + userId;
|
|
|
-
|
|
|
if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
return Result.of(null, false, ResultEnum.LAND_LAND_LEVELUPPING.getMessage(), ResultEnum.LAND_LAND_LEVELUPPING.getCode());
|
|
|
}
|
|
|
+ //验证用户是否存在
|
|
|
+ ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
+ if (playersAttri == null) {
|
|
|
+ return Result.of(null, false, "升级失败");
|
|
|
+ }
|
|
|
+ //验证幸运值是否够用
|
|
|
+ int sub = Convert.toInt(NumberUtil.sub(playersAttri.getLucky(), landLevelUpVo.getCostLucky()));
|
|
|
+ if (sub < 0) {
|
|
|
+ return Result.of(null, false, "升级失败,幸运值不足!");
|
|
|
+ }
|
|
|
//写入使用工具明细
|
|
|
ComPlayersLucky comPlayersLucky = new ComPlayersLucky();
|
|
|
comPlayersLucky.setAfterLucky(sub);
|
|
|
comPlayersLucky.setBeforeLucky(playersAttri.getLucky());
|
|
|
- comPlayersLucky.setAmount(levelLand.get().getCostLucky());
|
|
|
+ comPlayersLucky.setAmount(landLevelUpVo.getCostLucky());
|
|
|
comPlayersLucky.setLuckyType(ComPlayerLuckyLogEnum.level.getCode());
|
|
|
- comPlayersLucky.setLuckyName(levelLand.get().getName());
|
|
|
+ comPlayersLucky.setLuckyName(landLevelUpVo.getName());
|
|
|
comPlayersLucky.setLevelId(levelId);
|
|
|
comPlayersLucky.setLandId(landId);
|
|
|
comPlayersLucky.setUserId(userId);
|
|
|
@@ -199,8 +188,8 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
comPlayersAttriRepository.save(playersAttri);
|
|
|
|
|
|
//更新土地级别
|
|
|
- land.setLandLevel(levelId);
|
|
|
- comPlayerLandRepository.save(land);
|
|
|
+ comPlayerLand.setLandLevel(levelId);
|
|
|
+ comPlayerLandRepository.save(comPlayerLand);
|
|
|
return Result.of(null, true, "升级成功");
|
|
|
}
|
|
|
|
|
|
@@ -212,6 +201,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result<?> toSNB(String userId, Integer luckNum) {
|
|
|
//兑换snb倍数
|
|
|
int snb = Convert.toInt(comConfigService.selectByKey("land_luck_tosnb"), 0);
|
|
|
@@ -307,21 +297,24 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取土地到期时间
|
|
|
+ * 获取所有工具列表,方便用户选择使用哪种工具来获取幸运值
|
|
|
*
|
|
|
- * @param beginTime 租赁时间
|
|
|
- * @param type //租赁的日期,1是3个月,2是1年,3是5年
|
|
|
* @return
|
|
|
*/
|
|
|
- private Date getEndTime(Date beginTime, int type) {
|
|
|
- if (type == 1) {
|
|
|
- return DateUtil.date(beginTime).offset(DateField.MONTH, 3);
|
|
|
- } else if (type == 2) {
|
|
|
- return DateUtil.date(beginTime).offset(DateField.YEAR, 1);
|
|
|
- } else if (type == 3) {
|
|
|
- return DateUtil.date(beginTime).offset(DateField.YEAR, 5);
|
|
|
- } else {
|
|
|
- return beginTime;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<ComPlayersLuckyToolsVo> getLandTools() {
|
|
|
+ String land_tools = comConfigService.selectByKey(toolskey);
|
|
|
+ return JSONUtil.toList(land_tools, ComPlayersLuckyToolsVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取土地升级列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ComPlayersLuckyLandLevelUpVo> getLandLevelUp() {
|
|
|
+ String land_tools = comConfigService.selectByKey(levelUp);
|
|
|
+ return JSONUtil.toList(land_tools, ComPlayersLuckyLandLevelUpVo.class);
|
|
|
}
|
|
|
}
|