Bladeren bron

获取并设置今日喂养状态

xst 3 jaren geleden
bovenliggende
commit
ce517d5962

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

@@ -23,6 +23,7 @@ public interface ComPlayerCultivateSerivce {
 
     /**
      * 养殖 喂粮,一天不喂延迟2天
+     *
      * @param userId
      * @param configLandId
      * @return
@@ -38,4 +39,16 @@ public interface ComPlayerCultivateSerivce {
     Date getHarvestTime(String userId, Integer configLandId);
 
     Integer getHarvestDays(String userId, Integer configLandId);
+
+    /**
+     * 是否已经喂养
+     *
+     * @param userId       用户编号
+     * @param landType     土地类型 具体是养殖、渔场、放养
+     * @param configLandId
+     * @param begin
+     * @param end
+     * @return
+     */
+    boolean isAnimalEat(String userId, Integer landType, Integer configLandId, Date begin, Date end);
 }

+ 12 - 2
src/main/java/com/td/boss/game/complayercultivate/serivce/ComPlayerCultivateSerivceImpl.java

@@ -179,7 +179,7 @@ public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce
         //判断今天是否已经喂过
         Date begin = DateUtil.beginOfDay(new Date());
         Date end = DateUtil.endOfDay(new Date());
-        if (exists(userId, comPlayerLand.getMallType(), configLandId, begin, end)) {
+        if (isAnimalEat(userId, comPlayerLand.getMallType(), configLandId, begin, end)) {
             return Result.of(null, false, ResultEnum.FOOD_REPEAT_ERROR.getMessage(), ResultEnum.FOOD_REPEAT_ERROR.getCode());
         }
         long time = System.currentTimeMillis() + RedisData.getPlayerCultivateBuyFoodTimeout();
@@ -253,7 +253,17 @@ public class ComPlayerCultivateSerivceImpl implements ComPlayerCultivateSerivce
         return Convert.toInt(l, 0) + comPlayerLand.getPlantMature() - 1;
     }
 
-    private boolean exists(String userId, Integer landType, Integer configLandId, Date begin, Date end) {
+    /**
+     * 是否已经喂养
+     * @param userId 用户编号
+     * @param landType 土地类型 具体是养殖、渔场、放养
+     * @param configLandId
+     * @param begin
+     * @param end
+     * @return
+     */
+    @Override
+    public boolean isAnimalEat(String userId, Integer landType, Integer configLandId, Date begin, Date end) {
         Specification specification = new Specification<ComPlayerDisaster>() {
             @Override
             public Predicate toPredicate(Root<ComPlayerDisaster> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {

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

@@ -138,6 +138,12 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                     if (ArrayUtil.contains(CultivateKeys.mallType,e.getMallType())) {
                         Integer days = comPlayerCultivateSerivce.getHarvestDays(userId, e.getConfigLandId());
                         comMallSeedVo.setMaturity(days);
+
+                        //获取并设置今日喂养状态
+                        Date begin = cn.hutool.core.date.DateUtil.beginOfDay(new Date());
+                        Date end = cn.hutool.core.date.DateUtil.endOfDay(new Date());
+                        boolean animalEat = comPlayerCultivateSerivce.isAnimalEat(userId, e.getMallType(), e.getConfigLandId(), begin, end);
+                        comPlayerLandAndPlantVo.setAnimalEat(animalEat);
                     }
                     comPlayerLandAndPlantVo.setSeedInfo(comMallSeedVo);
                     //种子时间

+ 5 - 0
src/main/java/com/td/boss/game/complayerland/vo/ComPlayerLandAndPlantVo.java

@@ -72,4 +72,9 @@ public class ComPlayerLandAndPlantVo implements Serializable {
      * 新加是否枯萎
      */
     private boolean isWithered=false;
+
+    /**
+     * 当土地类型是放牧、养殖、渔场其中一种时,该字段表达是否已经喂养
+     */
+    private boolean animalEat;
 }