Bläddra i källkod

模块7: 牧场养殖

呵呵哒 3 år sedan
förälder
incheckning
4177ebe195

+ 0 - 10
src/main/java/com/td/boss/common/pojo/ComConfigKeys.java

@@ -1,10 +0,0 @@
-package com.td.boss.common.pojo;
-
-/**
- * com_config配置表的key
- */
-public class ComConfigKeys {
-    public static final String cultivateSeed= "cultivate_seed";
-    public static final String cultivateFood= "cultivate_food";
-    public static final String cultivateLand= "cultivate_land";
-}

+ 2 - 0
src/main/java/com/td/boss/config/enums/ResultEnum.java

@@ -95,6 +95,8 @@ public enum ResultEnum {
     FOOD_DOT_NOT(811,"狗粮不足!"),
     FOOD_DOT_NOT(811,"狗粮不足!"),
 
 
     SEED_SALE_SAVE_LOCK(810,"操作繁忙,出售失败,稍后再试!"),
     SEED_SALE_SAVE_LOCK(810,"操作繁忙,出售失败,稍后再试!"),
+    SEED_NO_LAND_ERROR(812,"种子土地不匹配!"),
+    SEED_LAND_TIME_ERROR(813,"土地租赁时间不足!"),
     //装备相关
     //装备相关
     MALL_OTHER_IS_NULL(810,"商城装备不存在!"),
     MALL_OTHER_IS_NULL(810,"商城装备不存在!"),
     MALL_OTHER_IS_HAVE(811,"商城装备已经存在!"),
     MALL_OTHER_IS_HAVE(811,"商城装备已经存在!"),

+ 1 - 0
src/main/java/com/td/boss/game/comconfigland/pojo/ComConfigLand.java

@@ -51,4 +51,5 @@ public class ComConfigLand implements Serializable {
 
 
     private Date updateTime;//
     private Date updateTime;//
 
 
+    private Integer mallType;
 }
 }

+ 3 - 0
src/main/java/com/td/boss/game/commallseed/controller/ComMallSeedController.java

@@ -1,5 +1,6 @@
 package com.td.boss.game.commallseed.controller;
 package com.td.boss.game.commallseed.controller;
 
 
+import cn.hutool.core.convert.Convert;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.td.boss.common.controller.*;
 import com.td.boss.common.controller.*;
 import com.td.boss.common.pojo.Result;
 import com.td.boss.common.pojo.Result;
@@ -143,6 +144,8 @@ public class ComMallSeedController extends CommonController<ComMallSeedVo, ComMa
                 entityVo.setName(seedVo.getName());
                 entityVo.setName(seedVo.getName());
                 entityVo.setPictureName(seedVo.getPicture());
                 entityVo.setPictureName(seedVo.getPicture());
                 entityVo.setUserId(userId);
                 entityVo.setUserId(userId);
+                //[xst]此处新增获取种子的类型
+                entityVo.setMallType(Convert.toInt(seedVo.getMallType(),0));
             } else {
             } else {
                 Integer _amount = entityVo.getAmount() + _paySeedAmount;
                 Integer _amount = entityVo.getAmount() + _paySeedAmount;
                 entityVo.setAmount(_amount);
                 entityVo.setAmount(_amount);

+ 199 - 11
src/main/java/com/td/boss/game/complayercultivate/controller/ComPlayerCultivateController.java

@@ -1,16 +1,38 @@
 package com.td.boss.game.complayercultivate.controller;
 package com.td.boss.game.complayercultivate.controller;
 
 
-import com.td.boss.common.controller.CommonController;
-import com.td.boss.common.pojo.ComConfigKeys;
+import cn.hutool.core.convert.Convert;
 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.game.complayercultivate.pojo.ComPlayerCultivate;
-import com.td.boss.game.complayercultivate.vo.ComPlayerCultivateLandVo;
-import com.td.boss.game.complayercultivate.vo.ComPlayerCultivateVo;
+import com.td.boss.config.enums.ResultEnum;
+import com.td.boss.game.comexplainland.service.ComExplainLandService;
+import com.td.boss.game.comexplainland.vo.ComExplainLandVo;
+import com.td.boss.game.commallseed.service.ComMallSeedService;
+import com.td.boss.game.commallseed.vo.ComMallSeedVo;
+import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
+import com.td.boss.game.complayergoods.service.ComPlayerGoodsService;
+import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
+import com.td.boss.game.complayerland.pojo.ComPlayerLand;
+import com.td.boss.game.complayerland.service.ComPlayerDisasterLogService;
+import com.td.boss.game.complayerland.service.ComPlayerDisasterProtectedService;
+import com.td.boss.game.complayerland.service.ComPlayerLandService;
+import com.td.boss.game.complayerland.vo.ComPlayerLandAndPlantVo;
+import com.td.boss.game.complayerland.vo.ComPlayerLandVo;
+import com.td.boss.game.complayerlog.service.ComPlayerLogService;
+import com.td.boss.game.complayerlog.vo.ComPlayerLogVo;
+import com.td.boss.game.complayerprofit.service.ComPlayerProfitService;
+import com.td.boss.util.CopyUtil;
+import com.td.boss.util.DateUtil;
+import com.td.boss.util.RedisLock;
+import com.td.boss.util.UUIDUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import java.util.Date;
+
 
 
 /**
 /**
  * 放牧\养殖\渔场
  * 放牧\养殖\渔场
@@ -19,11 +41,177 @@ import org.springframework.web.bind.annotation.RestController;
 @Slf4j
 @Slf4j
 @RequestMapping("/game/comPlayerCultivate/")
 @RequestMapping("/game/comPlayerCultivate/")
 public class ComPlayerCultivateController {
 public class ComPlayerCultivateController {
+    @Autowired
+    private ComPlayerLandService comPlayerLandService;
+
+    @Autowired
+    private ComMallSeedService comMallSeedService;
+
+    @Autowired
+    private ComPlayerGoodsService comPlayerGoodsService;
+
+    @Autowired
+    private ComPlayerLogService comPlayerLogService;
+
+    @Autowired
+    private ComExplainLandService comExplainLandService;
+
+    /**
+     * 种植土地,要先有土地才能种植
+     *
+     * @param userId
+     * @return
+     */
+    @GetMapping("plant")
+    @Transactional(rollbackFor = Exception.class)
+    public Result<ComPlayerLandAndPlantVo> plantFunction(
+            @RequestParam(value = "userId") String userId,
+            @RequestParam(value = "landId") Integer landId,
+            @RequestParam(value = "seedId") Integer seedId,
+            @RequestParam(value = "count") Integer count) {
+
+        try {
+            ComPlayerLand comPlayerLand = comPlayerLandService.findByUserIdAndLandId(userId, landId);
+            //土地数据不存在
+            if (comPlayerLand == null) {
+                return Result.of(null, false, ResultEnum.LAND_DATA_ERROR.getMessage(), ResultEnum.LAND_DATA_ERROR.getCode());
+            }
+            if (!comPlayerLand.getIsLease().equals(1)) {
+                return Result.of(null, false, ResultEnum.LAND_NOT_LEASE.getMessage(), ResultEnum.LAND_NOT_LEASE.getCode());
+            }
+            //土地已种植
+            if (comPlayerLand.getIsPlant().equals(1)) {
+                return Result.of(null, false, ResultEnum.LAND_IS_PLANT.getMessage(), ResultEnum.LAND_IS_PLANT.getCode());
+            }
+            //todo 用户没刷新时候,土地还存在。判定一下时间是否到期,到期不给收获
+            //租赁的剩余天数 。
+            Long leaseDaysMill = comPlayerLand.getLeaseTime().getTime() - DateUtil.getNowDate().getTime();
+            if (leaseDaysMill <= 0) {
+                //todo 清除记录的数据
+                //    1.土地租赁到期,删除土地租赁数据
+                comPlayerLandService.delete(comPlayerLand.getId());
+                //todo 2.把删除的这个土地的数据记录到com_explain_land中去
+                ComExplainLandVo comExplainLandVo = new ComExplainLandVo();
+                comExplainLandVo = CopyUtil.copy(comPlayerLand, ComExplainLandVo.class);
+                comExplainLandVo.setLandId(comPlayerLand.getConfigLandId());
+                comExplainLandVo.setLandCreate(comPlayerLand.getCreateTime());
+                comExplainLandVo.setExplainType(0);
+                comExplainLandVo.setExplainDescribe("播种种子时:土地租赁过期回收");
+                comExplainLandVo.setCreateTime(new Date());
+                comExplainLandVo.setUpdateTime(new Date());
+                comExplainLandService.save(comExplainLandVo);
+                return Result.of(null, false, ResultEnum.LAND_LEASE_EXPIRED.getMessage(), ResultEnum.LAND_LEASE_EXPIRED.getCode());
+            }
+
+            //获得种子信息
+            ComMallSeedVo comMallSeedVo = comMallSeedService.findById(seedId);
+            if (comMallSeedVo == null) {
+                return Result.of(null, false, ResultEnum.SEED_DATA_ERROR.getMessage(), ResultEnum.SEED_DATA_ERROR.getCode());
+            }
+            //[xst] 如果剩余时间<成熟时间 不允许种子
+            if (Convert.toInt(comMallSeedVo.getMallType()) > 0 && leaseDaysMill < comMallSeedVo.getMaturity()) {
+                return Result.of(null, false, ResultEnum.SEED_LAND_TIME_ERROR.getMessage(), ResultEnum.SEED_LAND_TIME_ERROR.getCode());
+            }
+            //[xst] 需要判断种子和土地类型是否匹配
+            if (comMallSeedVo.getMallType().equals(comPlayerLand.getMallType()) == false) {
+                return Result.of(null, false, ResultEnum.SEED_NO_LAND_ERROR.getMessage(), ResultEnum.SEED_NO_LAND_ERROR.getCode());
+            }
+
+            //todo 背包种子减去 土地当前的倍数,需要多倍播种,即消耗多个种子
+            ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 0);
+            //先拿到一个 before
+            Integer _beforeAmount = comPlayerGoodsSimpleVo.getAmount();
+            //操作一个种子的倍数
+            if (comPlayerGoodsSimpleVo.getAmount() < count || count > 500 || count < 0) {
+                return Result.of(null, false, ResultEnum.PLAYER_GOODS_SEEDS_AMOUNT_ERROR.getMessage(), ResultEnum.PLAYER_GOODS_SEEDS_AMOUNT_ERROR.getCode());
+
+            } else if (comPlayerGoodsSimpleVo.getAmount().equals(count)) {
+                //数量一样清除背包数据
+                comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
+            } else {
+                //_beforeAmount = comPlayerGoodsSimpleVo.getAmount();
+                //否则减去土地倍数
+                comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - count);
+                ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
+                comPlayerGoodsService.save(comPlayerGoodsVo);
+            }
+
+            //todo 种植
+            comPlayerLand.setIsPlant(1);
+            //记录一个植物的种植id
+            comPlayerLand.setPlantId(seedId);
+            comPlayerLand.setPlantStart(new Date());
+            //种植天数,成熟天数
+            comPlayerLand.setPlantMature(comMallSeedVo.getMaturity());
+
+            //生成一个标识,用来识别种植
+            comPlayerLand.setPlantFlag(UUIDUtil.getUUID());
+
+            //重新种植后,重新设置一个可以偷的标识
+            comPlayerLand.setPlantSteal(1);
+
+            //comPlayerLand.setLandDescribe();
+            ComPlayerLandVo comPlayerLandVo = CopyUtil.copy(comPlayerLand, ComPlayerLandVo.class);
+            comPlayerLandService.save(comPlayerLandVo);
+
+            //todo 记录一个种植 操作信息
+            ComPlayerLogVo _playerLogVo = new ComPlayerLogVo();
+            _playerLogVo.setUserId(userId);
+            _playerLogVo.setTId(comMallSeedVo.getId());
+            _playerLogVo.setTName(comMallSeedVo.getName());
+            _playerLogVo.setTType(1);//设置一个操作种子的id
+            _playerLogVo.setTAmount(comPlayerLand.getLeaseMultiple());
+            //交易后的数据
+            _playerLogVo.setBeforeAmount(_beforeAmount);
+            Integer _afterAmount = _beforeAmount - comPlayerLand.getLeaseMultiple();
+            _afterAmount = _afterAmount < 0 ? 0 : _afterAmount;
+            _playerLogVo.setAfterAmount(_afterAmount);
+            _playerLogVo.setLMultiple(comPlayerLand.getLeaseMultiple());
+
+            //收取时候信息记录
+            _playerLogVo.setTPart(0d);
+            _playerLogVo.setTLoss(0d); //损失的部分
+            _playerLogVo.setBeforePart(0d);
+            _playerLogVo.setAfterPart(0d);
+            comPlayerLogService.save(_playerLogVo);
+
+            ComPlayerLandAndPlantVo comPlayerLandAndPlantVo = CopyUtil.copy(comPlayerLand, ComPlayerLandAndPlantVo.class);
+            comPlayerLandAndPlantVo.setSeedInfo(comMallSeedVo);
+
+            //todo 返回一个计算的天数和小时,解决跨时区的问题
+            //土地时间
+            //租赁的总时间 = 租赁时间 - 土地数据的创建时间
+            Long leaseAllMill = comPlayerLandAndPlantVo.getLeaseTime().getTime() - comPlayerLandAndPlantVo.getCreateTime().getTime();
+            Integer allDays = DateUtil.getDays(leaseAllMill).intValue() <= 0 ? 0 : DateUtil.getDays(leaseAllMill).intValue();
+            comPlayerLandAndPlantVo.setLeaseDays(allDays);
+            //租赁的剩余天数
+            Integer leaseDays = DateUtil.getDays(leaseDaysMill).intValue() <= 0 ? 0 : DateUtil.getDays(leaseDaysMill).intValue();
+            comPlayerLandAndPlantVo.setLeaseDaysRemaining(leaseDays);
+
+            //返回一个租赁时间毫秒
+            comPlayerLandAndPlantVo.setLeaseDaysMill(leaseDaysMill);
+
+            //种子时间
+            //当前时间 > 种植时间+成熟期  = 说明可以收获了
+            //获取当前时间 - 植物的成熟期 = 收获时间,收获时间 >= 种植时间,即可以收获
+            Date _harvestTime = DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity());
+            // 两个时间差, 逻辑是_harvestTime 时间慢慢接近种植时间
+            long diff = comPlayerLandAndPlantVo.getPlantStart().getTime() - _harvestTime.getTime();
+            //种植的剩余时间毫秒
+            comPlayerLandAndPlantVo.setPlantDaysMill(diff);
 
 
+            if (diff <= 0) {
+                //说明可以收获了
+                comPlayerLandAndPlantVo.setPlantDaysRemaining(0);
+                comPlayerLandAndPlantVo.setPlantHoursRemaining(0);
+            } else {
+                comPlayerLandAndPlantVo.setPlantDaysRemaining(DateUtil.getDays(diff).intValue());
+                comPlayerLandAndPlantVo.setPlantHoursRemaining(DateUtil.getHours(diff).intValue());
+            }
+            return Result.of(comPlayerLandAndPlantVo);
 
 
-//    //获取所有土地
-//    @GetMapping("getLand")
-//    public Result<?> getLand() {
-//        return null;
-//    }
+        } catch (Exception e) {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
 }
 }

+ 1 - 13
src/main/java/com/td/boss/game/complayercultivate/serivce/ComPlayerCultivateSerivce.java

@@ -1,18 +1,13 @@
 package com.td.boss.game.complayercultivate.serivce;
 package com.td.boss.game.complayercultivate.serivce;
 
 
 import com.td.boss.common.pojo.Result;
 import com.td.boss.common.pojo.Result;
-import com.td.boss.game.complayercultivate.vo.ComPlayerCultivateFoodVo;
-import com.td.boss.game.complayercultivate.vo.ComPlayerCultivateLandVo;
-import com.td.boss.game.complayercultivate.vo.ComPlayerCultivateSeedVo;
 
 
 import java.util.List;
 import java.util.List;
 
 
 public interface ComPlayerCultivateSerivce {
 public interface ComPlayerCultivateSerivce {
 
 
-    Result<?> zulin(String userId, String landId);
-
-    Result<?> toufang(String userId, String landId, String seedId, Integer seedNum);
 
 
+    Result<?> zulin(String userId, Integer configLandId);
     /**
     /**
      * 获取租赁机会
      * 获取租赁机会
      *
      *
@@ -20,11 +15,4 @@ public interface ComPlayerCultivateSerivce {
      * @return
      * @return
      */
      */
     Integer getTimes(String userId);
     Integer getTimes(String userId);
-
-    //获取所有土地
-    List<ComPlayerCultivateLandVo> getLand();
-
-    List<ComPlayerCultivateFoodVo> getFood();
-
-    List<ComPlayerCultivateSeedVo> getSeed();
 }
 }

+ 98 - 99
src/main/java/com/td/boss/game/complayercultivate/serivce/ComPlayerCultivateSerivceImpl.java

@@ -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);
-    }
 }
 }

+ 0 - 12
src/main/java/com/td/boss/game/complayercultivate/vo/ComPlayerCultivateFoodVo.java

@@ -1,12 +0,0 @@
-package com.td.boss.game.complayercultivate.vo;
-
-import lombok.Data;
-
-@Data
-public class ComPlayerCultivateFoodVo {
-    private Integer foodId;
-    private String foodName;
-    private double foodSNB;
-    private int foodType;
-    private String foodImage;
-}

+ 0 - 13
src/main/java/com/td/boss/game/complayercultivate/vo/ComPlayerCultivateLandVo.java

@@ -1,13 +0,0 @@
-package com.td.boss.game.complayercultivate.vo;
-
-import lombok.Data;
-
-@Data
-public class ComPlayerCultivateLandVo {
-    private Integer landId;
-    private String landName;
-    private int landLimit;
-    private int landType;
-
-    private boolean isActivty;
-}

+ 0 - 16
src/main/java/com/td/boss/game/complayercultivate/vo/ComPlayerCultivateSeedVo.java

@@ -1,16 +0,0 @@
-package com.td.boss.game.complayercultivate.vo;
-
-import lombok.Data;
-
-@Data
-public class ComPlayerCultivateSeedVo {
-    private Integer seedId;
-    private String seedName;
-    private int seedSNB;
-    private int delayDays;
-    private String fruitname;
-    private int maturity;
-    private int harvest;
-    private Integer foodId;
-    private String image;
-}

+ 1 - 0
src/main/java/com/td/boss/game/complayergoods/pojo/ComPlayerGoods.java

@@ -28,4 +28,5 @@ public class ComPlayerGoods implements Serializable {
 
 
     private Date createTime;
     private Date createTime;
 
 
+    private Integer mallType;//新加类型。0代表原有,其他代表放牧养殖渔场
 }
 }

+ 1 - 0
src/main/java/com/td/boss/game/complayerland/controller/ComPlayerLandController.java

@@ -1,5 +1,6 @@
 package com.td.boss.game.complayerland.controller;
 package com.td.boss.game.complayerland.controller;
 
 
+import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
 import com.td.boss.common.controller.*;
 import com.td.boss.common.controller.*;

+ 2 - 0
src/main/java/com/td/boss/game/complayerland/pojo/ComPlayerLand.java

@@ -49,4 +49,6 @@ public class ComPlayerLand implements Serializable {
     private Date updateTime;
     private Date updateTime;
 
 
     private Integer landLevel;//土地级别
     private Integer landLevel;//土地级别
+
+    private Integer mallType;
 }
 }