Quellcode durchsuchen

1.修正数据,
2.添加接口

slambb vor 3 Jahren
Ursprung
Commit
f5aacd4063

+ 1 - 3
src/main/java/com/td/boss/config/enums/ResultEnum.java

@@ -86,7 +86,6 @@ public enum ResultEnum {
 
     LAND_MALL_TYPE_ERROR(717,"种植或养殖类型不对!"),
 
-
     //种子数据不能存在
     SEED_DATA_ERROR(801,"种子数据不存在!"),
     FRUIT_DATA_ERROR(802,"果实数据不存在!"),
@@ -117,8 +116,7 @@ public enum ResultEnum {
     PLAYER_OTHER_IS_NULL(812,"商城装备不存在!"),
     PLAYER_OTHER_IS_HAVE(813,"商城装备已经存在!"),
 
-
-    FRUIT_AMOUNT_IS_ZERO_AND_NOT_MULTIPLE(808,"请输入出售果实的数量!"),
+    FRUIT_AMOUNT_IS_ZERO_AND_NOT_MULTIPLE(814,"请输入出售果实的数量!"),
     ;
     private Integer code;
 

+ 16 - 0
src/main/java/com/td/boss/game/complayercultivate/controller/ComPlayerCultivateController.java

@@ -62,4 +62,20 @@ public class ComPlayerCultivateController {
     public Result<?> getTimes(@RequestParam(value = "userId") String userId) {
         return Result.of(comPlayerCultivateSerivce.getTimes(userId));
     }
+
+
+
+    /**
+     * 喂养养殖场动物
+     *
+     * @param userId
+     * @param configLandId
+     * @return
+     */
+    @PostMapping("buyAnimalFood")
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> buyAnimalFood(@RequestParam(value = "userId") String userId,
+                             @RequestParam(value = "configLandId") Integer configLandId) {
+        return comPlayerCultivateSerivce.buyFood(userId, configLandId);
+    }
 }

+ 29 - 5
src/main/java/com/td/boss/game/complayerscore/controller/ComPlayerScoreController.java

@@ -2,6 +2,7 @@ package com.td.boss.game.complayerscore.controller;
 
 import com.td.boss.common.controller.*;
 import com.td.boss.common.pojo.Result;
+import com.td.boss.config.enums.ResultEnum;
 import com.td.boss.game.commallseed.pojo.ComMallSeed;
 import com.td.boss.game.commallseed.service.ComMallSeedService;
 import com.td.boss.game.commallseed.vo.ComMallSeedVo;
@@ -9,10 +10,13 @@ import com.td.boss.game.complayerscore.pojo.ComPlayerScore;
 import com.td.boss.game.complayerscore.vo.ComPlayerScoreVo;
 import com.td.boss.game.complayerscore.service.ComPlayerScoreService;
 import com.td.boss.util.CopyUtil;
+import com.td.boss.util.RedisData;
+import com.td.boss.util.RedisLock;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -26,6 +30,9 @@ public class ComPlayerScoreController extends CommonController<ComPlayerScoreVo,
     @Autowired
     private ComMallSeedService comMallSeedService;
 
+    @Autowired
+    private RedisLock redisLock;
+
     /**
      * 积分兑换种子
      *
@@ -36,30 +43,47 @@ public class ComPlayerScoreController extends CommonController<ComPlayerScoreVo,
      */
     @PostMapping("exchange")
     @ResponseBody
-    public Result<String> exchange(
+    public Result<Map> exchange(
             @RequestParam(value = "userId") String userId,
             @RequestParam(value = "amount") Integer amount,
             @RequestParam(value = "seedId") Integer seedId
     ) {
-        return comPlayerScoreService.exchange(userId, amount, seedId);
+        long time = System.currentTimeMillis() + RedisData.getPlayerScoreTimeout();
+        String _redisKey = "LOCK:PLAYER_SCORE_TIMEOUT:" + userId;
+        try {
+            if (!redisLock.lock(_redisKey, String.valueOf(time))) {
+                return Result.of(null, false, ResultEnum.REDIS_IS_LOCK.getMessage(), ResultEnum.REDIS_IS_LOCK.getCode());
+            }
+            Result result = comPlayerScoreService.exchange(userId, amount, seedId);
+            redisLock.unlock(_redisKey, String.valueOf(time));
+            return result;
+        } catch (Exception e) {
+            redisLock.unlock(_redisKey, String.valueOf(time));
+            return Result.of(null, false, ResultEnum.REDIS_IS_LOCK_ERROR.getMessage(), ResultEnum.REDIS_IS_LOCK_ERROR.getCode());
+        }
     }
 
 
     /**
      * 返回十天期的当前种子
+     *
      * @param userId
      * @return
      */
     @GetMapping("getSeeds")
     @ResponseBody
-    public Result<List<ComMallSeedVo>> getSeeds(
+    public Result<Map> getSeeds(
             @RequestParam(value = "userId") String userId
     ) {
 
         Integer _limitDay = 10;
         List<ComMallSeed> comMallSeedList = comMallSeedService.findMallSeedAll().stream().
-                filter(e->e.getMaturity().equals(_limitDay)).collect(Collectors.toList());
+                filter(e -> e.getMaturity().equals(_limitDay) && e.getMallType().equals(0) && !e.getAmount().equals(0)).collect(Collectors.toList());
+        //返回当前积分
+        Map map = new HashMap();
+        map.put("seeds", CopyUtil.copyList(comMallSeedList, ComMallSeedVo.class));
+        map.put("score", comPlayerScoreService.getScore(userId));
+        return Result.of(map);
 
-        return Result.of( CopyUtil.copyList(comMallSeedList,ComMallSeedVo.class));
     }
 }

+ 5 - 1
src/main/java/com/td/boss/game/complayerscore/service/ComPlayerScoreService.java

@@ -5,6 +5,8 @@ import com.td.boss.common.service.*;
 import com.td.boss.game.complayerscore.pojo.ComPlayerScore;
 import com.td.boss.game.complayerscore.vo.ComPlayerScoreVo;
 
+import java.util.Map;
+
 public interface ComPlayerScoreService extends CommonService<ComPlayerScoreVo, ComPlayerScore, Integer> {
 
     /**
@@ -15,6 +17,8 @@ public interface ComPlayerScoreService extends CommonService<ComPlayerScoreVo, C
      * @param seedId 种子id
      * @return {@link Result}<{@link String}>
      */
-    Result<String> exchange(String userId, Integer amount, Integer seedId);
+    Result<Map> exchange(String userId, Integer amount, Integer seedId);
+
 
+    Map getScore(String userId);
 }

+ 43 - 17
src/main/java/com/td/boss/game/complayerscore/service/ComPlayerScoreServiceImpl.java

@@ -4,6 +4,7 @@ import com.td.boss.common.pojo.Result;
 import com.td.boss.common.service.CommonServiceImpl;
 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.complayerscore.pojo.ComPlayerScore;
@@ -11,6 +12,7 @@ import com.td.boss.game.complayerscore.repository.ComPlayerScoreRepository;
 import com.td.boss.game.complayerscore.vo.ComPlayerScoreVo;
 import com.td.boss.game.comusers.service.ComUsersService;
 import com.td.boss.game.comusers.vo.ComUsersVo;
+import com.td.boss.util.CopyUtil;
 import com.td.boss.util.DappUtil;
 import com.td.boss.util.UUIDUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 @Service
 public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreVo, ComPlayerScore, Integer> implements ComPlayerScoreService {
@@ -45,7 +49,7 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Result<String> exchange(String userId,
+    public Result<Map> exchange(String userId,
                                    Integer amount,
                                    Integer seedId) {
         ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
@@ -58,8 +62,8 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
             return Result.of(null, false, "消费土地的总cnt不足");
         }
         ComMallSeedVo mallSeed = comMallSeedService.findById(seedId);
-        // 5 = 固定积分兑换种子
-        if (mallSeed == null || mallSeed.getAmount().equals(0) || !"5".equals(mallSeed.getMallType())) {
+        // 固定积分兑换种子,使用的是已存在的种子
+        if (mallSeed == null || mallSeed.getAmount().equals(0) || !mallSeed.getMallType().equals(0)) {
             return Result.of(null, false, "种子不存在或已被下架");
         }
         // 本次总消费
@@ -85,20 +89,42 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
         comPlayerScore.setPriceCnt(mallSeed.getPriceCnt());
         comPlayerScore.setCreateTime(new Date());
         comPlayerScoreRepository.save(comPlayerScore);
-        // 保存进仓库
-        ComPlayerGoodsVo comPlayerGoods = new ComPlayerGoodsVo();
-        comPlayerGoods.setGoodsId(UUIDUtil.getUUID());
-        comPlayerGoods.setGoodsIndex(seedId);
-        comPlayerGoods.setGoodsType(0);
-        comPlayerGoods.setUserId(userId);
-        comPlayerGoods.setName(mallSeed.getName());
-        comPlayerGoods.setPictureName(mallSeed.getPicture());
-        comPlayerGoods.setAmount(amount);
-        comPlayerGoods.setAmountPart(0d);
-        comPlayerGoods.setCreateTime(new Date());
-        comPlayerGoods.setMallType(0);
-        comPlayerGoodsService.save(comPlayerGoods);
+        // 保存进仓库,处理种子
 
-        return Result.of(null, true, "兑换成功");
+        ComPlayerGoods  comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, seedId, 0);
+        if(comPlayerGoods == null){
+            comPlayerGoods = new ComPlayerGoods();
+            comPlayerGoods.setGoodsIndex(seedId);
+            comPlayerGoods.setGoodsType(0);
+            comPlayerGoods.setUserId(userId);
+            comPlayerGoods.setName(mallSeed.getName());
+            comPlayerGoods.setPictureName(mallSeed.getPicture());
+            comPlayerGoods.setAmount(amount);
+            comPlayerGoods.setAmountPart(0d);
+            comPlayerGoods.setMallType(0);
+        }else{
+            Integer _amount = comPlayerGoods.getAmount() + amount;
+            comPlayerGoods.setAmount(_amount);
+        }
+        comPlayerGoodsService.save(CopyUtil.copy(comPlayerGoods,ComPlayerGoodsVo.class));
+
+        Map map = new HashMap();
+        map.put("score", getScore(userId));
+        return Result.of( map,true, "兑换成功");
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Map getScore(String userId) {
+        // 链端获取cnt总数
+        Integer totalCount = DappUtil.getChildrenBuyLandAmount(userId);
+        Integer oldTotalCnt = comPlayerScoreRepository.findAllByUserId(userId).stream()
+                .map(ComPlayerScore::getTotalCnt).reduce(0, Integer::sum);
+
+        Map map = new HashMap();
+        map.put("totalCount",totalCount);
+        map.put("oldTotalCnt",oldTotalCnt);
+        return map;
     }
 }

+ 1 - 0
src/main/java/com/td/boss/game/comsnbfreeze/controller/ComSnbFreezeController.java

@@ -629,6 +629,7 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
                     entityVo.setName(seedVo.getName());
                     entityVo.setAmountPart(0d);
                     entityVo.setPictureName(seedVo.getPicture());
+                    entityVo.setMallType(0);
                 } else {
                     Integer _amount = entityVo.getAmount() + _paySeedAmount;
                     entityVo.setAmount(_amount);

+ 9 - 0
src/main/java/com/td/boss/util/RedisData.java

@@ -107,4 +107,13 @@ public class RedisData {
     public static int getPlayerCultivateBuyFoodTimeout() {
         return PLAYER_CULTIVATE_BUYFOOD_TIMEOUT;
     }
+
+
+    /**
+     * 10s 兑换种子模块
+     */
+    private static final int PLAYER_SCORE_TIMEOUT = 10 * 1000;
+    public static int getPlayerScoreTimeout() {
+        return PLAYER_SCORE_TIMEOUT;
+    }
 }