|
@@ -1,17 +1,20 @@
|
|
|
package com.td.boss.game.complayercultivate.serivce;
|
|
package com.td.boss.game.complayercultivate.serivce;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateField;
|
|
import cn.hutool.core.date.DateField;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
|
-import com.td.boss.common.pojo.ComConfigKeys;
|
|
|
|
|
import com.td.boss.common.pojo.Result;
|
|
import com.td.boss.common.pojo.Result;
|
|
|
import com.td.boss.common.service.ComConfigService;
|
|
import com.td.boss.common.service.ComConfigService;
|
|
|
|
|
+import com.td.boss.config.enums.ResultEnum;
|
|
|
|
|
+import com.td.boss.game.comconfigland.pojo.ComConfigLand;
|
|
|
|
|
+import com.td.boss.game.comconfigland.service.ComConfigLandService;
|
|
|
import com.td.boss.game.complayercultivate.pojo.ComPlayerCultivate;
|
|
import com.td.boss.game.complayercultivate.pojo.ComPlayerCultivate;
|
|
|
import com.td.boss.game.complayercultivate.pojo.ComPlayerCultivateDetail;
|
|
import com.td.boss.game.complayercultivate.pojo.ComPlayerCultivateDetail;
|
|
|
import com.td.boss.game.complayercultivate.repository.ComPlayerCultivateDetailRepository;
|
|
import com.td.boss.game.complayercultivate.repository.ComPlayerCultivateDetailRepository;
|
|
|
import com.td.boss.game.complayercultivate.repository.ComPlayerCultivateRepository;
|
|
import com.td.boss.game.complayercultivate.repository.ComPlayerCultivateRepository;
|
|
|
import com.td.boss.game.complayercultivate.vo.*;
|
|
import com.td.boss.game.complayercultivate.vo.*;
|
|
|
|
|
+import com.td.boss.game.complayerland.pojo.ComPlayerLand;
|
|
|
|
|
+import com.td.boss.game.complayerland.service.ComPlayerLandService;
|
|
|
import com.td.boss.util.DappUtil;
|
|
import com.td.boss.util.DappUtil;
|
|
|
import com.td.boss.util.RedisData;
|
|
import com.td.boss.util.RedisData;
|
|
|
import com.td.boss.util.RedisLock;
|
|
import com.td.boss.util.RedisLock;
|
|
@@ -29,7 +32,9 @@ import java.util.List;
|
|
|
public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce {
|
|
public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private ComConfigService comConfigService;
|
|
|
|
|
|
|
+ private ComPlayerLandService comPlayerLandService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ComConfigLandService comConfigLandService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ComPlayerCultivateRepository cultivateRepository;
|
|
private ComPlayerCultivateRepository cultivateRepository;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -40,7 +45,7 @@ public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@Override
|
|
@Override
|
|
|
- public Result<?> zulin(String userId, String landId) {
|
|
|
|
|
|
|
+ public Result<?> zulin(String userId, Integer configLandId) {
|
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerCultivateZuLinTimeout();
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerCultivateZuLinTimeout();
|
|
|
String _redisKey = "LOCK:COM_PLAYER_CULTIVATE_ZULIN:" + userId;
|
|
String _redisKey = "LOCK:COM_PLAYER_CULTIVATE_ZULIN:" + userId;
|
|
|
if (redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
if (redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
@@ -48,124 +53,118 @@ public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce
|
|
|
return ErrorResult("操作频繁!");
|
|
return ErrorResult("操作频繁!");
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- ComPlayerCultivateLandVo comPlayerCultivateLandVo = getLandById(landId);
|
|
|
|
|
- if (comPlayerCultivateLandVo != null) {
|
|
|
|
|
- return ErrorResult("土地不存在!");
|
|
|
|
|
- }
|
|
|
|
|
- if (cultivateRepository.findByUserId(userId) != null) {
|
|
|
|
|
- return ErrorResult("该土地已被租赁!");
|
|
|
|
|
|
|
+ //根据土地config id查找,对应ConfigLandId ,
|
|
|
|
|
+ ComConfigLand comConfigLand = comConfigLandService.findById(configLandId);
|
|
|
|
|
+ //如果土地等于不能初始化,或者已经种植,不能进行购买
|
|
|
|
|
+ if (comConfigLand == null || comConfigLand.getIsInit().equals(0) || comConfigLand.getIsPlant().equals(1)) {
|
|
|
|
|
+ return Result.of(null, false, ResultEnum.LAND_DATA_ERROR.getMessage(), ResultEnum.LAND_DATA_ERROR.getCode());
|
|
|
}
|
|
}
|
|
|
if (getTimes(userId) <= 0) {
|
|
if (getTimes(userId) <= 0) {
|
|
|
return ErrorResult("次数不足!");
|
|
return ErrorResult("次数不足!");
|
|
|
}
|
|
}
|
|
|
- ComPlayerCultivate comPlayerCultivate = new ComPlayerCultivate();
|
|
|
|
|
- comPlayerCultivate.setCreateTime(new Date());
|
|
|
|
|
- comPlayerCultivate.setEndTime(DateUtil.offset(comPlayerCultivate.getCreateTime(),DateField.MONTH,1));
|
|
|
|
|
- comPlayerCultivate.setLandId(comPlayerCultivateLandVo.getLandId());
|
|
|
|
|
- comPlayerCultivate.setLandType(comPlayerCultivateLandVo.getLandType());
|
|
|
|
|
- comPlayerCultivate.setLandName(comPlayerCultivateLandVo.getLandName());
|
|
|
|
|
- comPlayerCultivate.setLandLimit(comPlayerCultivateLandVo.getLandLimit());
|
|
|
|
|
- comPlayerCultivate.setIsActivity(0);
|
|
|
|
|
- comPlayerCultivate.setUserId(userId);
|
|
|
|
|
- cultivateRepository.save(comPlayerCultivate);
|
|
|
|
|
- return Result.of(comPlayerCultivate, true, "租赁成功");
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- } finally {
|
|
|
|
|
- redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
- }
|
|
|
|
|
- return ErrorResult("租赁失败!");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Transactional
|
|
|
|
|
- @Override
|
|
|
|
|
- public Result<?> toufang(String userId, String landId, String seedId, Integer seedNum) {
|
|
|
|
|
- long time = System.currentTimeMillis() + RedisData.getPlayerCultivateTouFangTimeout();
|
|
|
|
|
- String _redisKey = "LOCK:COM_PLAYER_CULTIVATE_TOUFANG:" + userId;
|
|
|
|
|
- if (redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
|
|
- return ErrorResult("操作频繁!");
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- ComPlayerCultivate comPlayerCultivate = cultivateRepository.findByUserId(userId);
|
|
|
|
|
- if (comPlayerCultivate == null) {
|
|
|
|
|
- return ErrorResult("该土地未被租赁!");
|
|
|
|
|
- }
|
|
|
|
|
- ComPlayerCultivateSeedVo seedVo = getSeedById(seedId);
|
|
|
|
|
- if (seedVo == null) {
|
|
|
|
|
- return ErrorResult("幼崽不存在!");
|
|
|
|
|
- }
|
|
|
|
|
- if (comPlayerCultivate != null && Integer.getInteger("1").equals(comPlayerCultivate.getIsActivity())) {
|
|
|
|
|
- return ErrorResult("该土地正在使用中!");
|
|
|
|
|
- }
|
|
|
|
|
- //计算一下成熟的时间
|
|
|
|
|
- DateTime maturityTime = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, seedVo.getMaturity());
|
|
|
|
|
- if (maturityTime.after(comPlayerCultivate.getEndTime())) {
|
|
|
|
|
- return ErrorResult("土地租赁时间不足!");
|
|
|
|
|
- }
|
|
|
|
|
- //判断一下种植最大数量
|
|
|
|
|
- if (comPlayerCultivate.getLandLimit() > seedNum) {
|
|
|
|
|
- return ErrorResult("最多可投放" + comPlayerCultivate.getLandLimit() + "!");
|
|
|
|
|
- }
|
|
|
|
|
- comPlayerCultivate.setIsActivity(1);
|
|
|
|
|
- cultivateRepository.save(comPlayerCultivate);
|
|
|
|
|
|
|
+ ComPlayerLand comPlayerLand = comPlayerLandService.findByUserIdAndLandId(userId, configLandId);
|
|
|
|
|
|
|
|
- ComPlayerCultivateDetail comPlayerCultivateDetailVo = new ComPlayerCultivateDetail();
|
|
|
|
|
- comPlayerCultivateDetailVo.setCreateTime(new Date());
|
|
|
|
|
- comPlayerCultivateDetailVo.setSeed(JSONUtil.toJsonStr(seedVo));
|
|
|
|
|
- comPlayerCultivateDetailVo.setSeedId(seedVo.getSeedId());
|
|
|
|
|
- comPlayerCultivateDetailVo.setSeedNum(seedNum);
|
|
|
|
|
- comPlayerCultivateDetailVo.setIsMaturity(0);
|
|
|
|
|
- comPlayerCultivateDetailVo.setMaturityTime(maturityTime);
|
|
|
|
|
- comPlayerCultivateDetailVo.setIncomeNum(seedVo.getHarvest() * seedNum);
|
|
|
|
|
- cultivateDetailRepository.save(comPlayerCultivateDetailVo);
|
|
|
|
|
- return Result.of(null, true, "投放成功!");
|
|
|
|
|
|
|
+ if (comPlayerLand == null) {
|
|
|
|
|
+ //创建新土地
|
|
|
|
|
+ comPlayerLand = new ComPlayerLand();
|
|
|
|
|
+ comPlayerLand.setConfigLandId(comConfigLand.getId());
|
|
|
|
|
+ comPlayerLand.setUserId(userId);
|
|
|
|
|
+ comPlayerLand.setName(comConfigLand.getName());
|
|
|
|
|
+ //todo 续租问题,如果用户续租,保留之前的状态
|
|
|
|
|
+ //初始化一下未种植参数
|
|
|
|
|
+ comPlayerLand.setIsPlant(0);
|
|
|
|
|
+ comPlayerLand.setCreateTime(new Date());
|
|
|
|
|
+ comPlayerLand.setPlantSteal(1);
|
|
|
|
|
+ comPlayerLand.setMallType(comConfigLand.getMallType());
|
|
|
|
|
|
|
|
|
|
+ comPlayerLand.setLandDescribe("每次租赁1个月");
|
|
|
|
|
+ comPlayerLand.setLeaseMultiple(1);
|
|
|
|
|
+ comPlayerLand.setLeaseDate(1);
|
|
|
|
|
+ //设置租赁日期
|
|
|
|
|
+ comPlayerLand.setLeaseTime(DateUtil.offset(new Date(), DateField.MONTH, 1));
|
|
|
|
|
+ //租赁土地
|
|
|
|
|
+ comPlayerLand.setIsLease(1);
|
|
|
|
|
+ comPlayerLand.setUpdateTime(new Date());
|
|
|
|
|
+ //记录一下租赁费用
|
|
|
|
|
+ comPlayerLand.setRentalExpenses(1.0d);
|
|
|
|
|
+ comPlayerLandService.AddComPlayerLand(comPlayerLand);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.of(null, true, "租赁成功");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
} finally {
|
|
} finally {
|
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
}
|
|
}
|
|
|
- return ErrorResult("投放失败!");
|
|
|
|
|
|
|
+ return ErrorResult("租赁失败!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// @Transactional
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public Result<?> toufang(String userId, String landId, String seedId, Integer seedNum) {
|
|
|
|
|
+// long time = System.currentTimeMillis() + RedisData.getPlayerCultivateTouFangTimeout();
|
|
|
|
|
+// String _redisKey = "LOCK:COM_PLAYER_CULTIVATE_TOUFANG:" + userId;
|
|
|
|
|
+// if (redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
|
|
+// return ErrorResult("操作频繁!");
|
|
|
|
|
+// }
|
|
|
|
|
+// try {
|
|
|
|
|
+// ComPlayerCultivate comPlayerCultivate = cultivateRepository.findByUserId(userId);
|
|
|
|
|
+// if (comPlayerCultivate == null) {
|
|
|
|
|
+// return ErrorResult("该土地未被租赁!");
|
|
|
|
|
+// }
|
|
|
|
|
+// ComPlayerCultivateSeedVo seedVo = getSeedById(seedId);
|
|
|
|
|
+// if (seedVo == null) {
|
|
|
|
|
+// return ErrorResult("幼崽不存在!");
|
|
|
|
|
+// }
|
|
|
|
|
+// if (comPlayerCultivate != null && Integer.getInteger("1").equals(comPlayerCultivate.getIsActivity())) {
|
|
|
|
|
+// return ErrorResult("该土地正在使用中!");
|
|
|
|
|
+// }
|
|
|
|
|
+// //计算一下成熟的时间
|
|
|
|
|
+// DateTime maturityTime = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, seedVo.getMaturity());
|
|
|
|
|
+// if (maturityTime.after(comPlayerCultivate.getEndTime())) {
|
|
|
|
|
+// return ErrorResult("土地租赁时间不足!");
|
|
|
|
|
+// }
|
|
|
|
|
+// //判断一下种植最大数量
|
|
|
|
|
+// if (comPlayerCultivate.getLandLimit() > seedNum) {
|
|
|
|
|
+// return ErrorResult("最多可投放" + comPlayerCultivate.getLandLimit() + "!");
|
|
|
|
|
+// }
|
|
|
|
|
+// comPlayerCultivate.setIsActivity(1);
|
|
|
|
|
+// cultivateRepository.save(comPlayerCultivate);
|
|
|
|
|
+//
|
|
|
|
|
+// ComPlayerCultivateDetail comPlayerCultivateDetailVo = new ComPlayerCultivateDetail();
|
|
|
|
|
+// comPlayerCultivateDetailVo.setCreateTime(new Date());
|
|
|
|
|
+// comPlayerCultivateDetailVo.setSeed(JSONUtil.toJsonStr(seedVo));
|
|
|
|
|
+// comPlayerCultivateDetailVo.setSeedId(seedVo.getSeedId());
|
|
|
|
|
+// comPlayerCultivateDetailVo.setSeedNum(seedNum);
|
|
|
|
|
+// comPlayerCultivateDetailVo.setIsMaturity(0);
|
|
|
|
|
+// comPlayerCultivateDetailVo.setMaturityTime(maturityTime);
|
|
|
|
|
+// comPlayerCultivateDetailVo.setIncomeNum(seedVo.getHarvest() * seedNum);
|
|
|
|
|
+// cultivateDetailRepository.save(comPlayerCultivateDetailVo);
|
|
|
|
|
+// return Result.of(null, true, "投放成功!");
|
|
|
|
|
+//
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// } finally {
|
|
|
|
|
+// redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
+// }
|
|
|
|
|
+// return ErrorResult("投放失败!");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取租赁机会
|
|
* 获取租赁机会
|
|
|
|
|
+ *
|
|
|
* @param userId
|
|
* @param userId
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Integer getTimes(String userId) {
|
|
public Integer getTimes(String userId) {
|
|
|
Integer totalcount = DappUtil.getChildrenBuyLandAmount(userId);
|
|
Integer totalcount = DappUtil.getChildrenBuyLandAmount(userId);
|
|
|
- Integer hascount = cultivateDetailRepository.findByUserId(userId).size();
|
|
|
|
|
- return totalcount - hascount;
|
|
|
|
|
- }
|
|
|
|
|
- //todo 少一个购买饲料、幼崽到仓库的逻辑,从仓库到放养的逻辑,参考原有逻辑
|
|
|
|
|
- //todo 少一个喂养的逻辑,并且写入明细,重新计算天,可以使用延迟队列
|
|
|
|
|
- //todo 少一个被偷的逻辑,需要问问怎么做
|
|
|
|
|
- //todo 少一个成熟的逻辑,可以使用延迟队列
|
|
|
|
|
- //todo 将7 8模块都加入到config中
|
|
|
|
|
- @Override
|
|
|
|
|
- public List<ComPlayerCultivateLandVo> getLand() {
|
|
|
|
|
- return comConfigService.selectByKey(ComConfigKeys.cultivateLand, ComPlayerCultivateLandVo.class);
|
|
|
|
|
|
|
+ long hascount = comPlayerLandService.findAllByUserId(userId).stream()
|
|
|
|
|
+ .filter(a -> a.getMallType() > 0)
|
|
|
|
|
+ .map(a -> a.getLeaseDate())
|
|
|
|
|
+ .reduce(0, Integer::sum);
|
|
|
|
|
+ return totalcount - Convert.toInt(hascount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public List<ComPlayerCultivateFoodVo> getFood() {
|
|
|
|
|
- return comConfigService.selectByKey(ComConfigKeys.cultivateFood, ComPlayerCultivateFoodVo.class);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public List<ComPlayerCultivateSeedVo> getSeed() {
|
|
|
|
|
- return comConfigService.selectByKey(ComConfigKeys.cultivateSeed, ComPlayerCultivateSeedVo.class);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
private Result<?> ErrorResult(String msg) {
|
|
private Result<?> ErrorResult(String msg) {
|
|
|
return Result.of(null, false, msg);
|
|
return Result.of(null, false, msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private ComPlayerCultivateLandVo getLandById(String landId) {
|
|
|
|
|
- return getLand().stream().filter(a -> a.getLandId().toString().equals(landId)).findFirst().orElse(null);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private ComPlayerCultivateSeedVo getSeedById(String seedId) {
|
|
|
|
|
- return getSeed().stream().filter(a -> a.getSeedId().toString().equals(seedId)).findFirst().orElse(null);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|