Преглед изворни кода

游戏策略配置添加自定义条件

Letianhua пре 1 година
родитељ
комит
e81628b774

+ 12 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GamePolicyConfigAddOrUpdateParam.java

@@ -40,12 +40,24 @@ public class GamePolicyConfigAddOrUpdateParam {
     @ApiModelProperty("金额")
     private Long amount;
 
+    /**
+     * 金额条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    @ApiModelProperty("金额条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于")
+    private String amountCondition;
+
     /**
      * 时间(单位:小时)
      */
     @ApiModelProperty("时间(单位:小时)")
     private Long time;
 
+    /**
+     * 时间条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    @ApiModelProperty("时间条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于")
+    private String timeCondition;
+
     /**
      * 配置说明
      */

+ 10 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GamePolicyConfigInnerObjVO.java

@@ -22,9 +22,19 @@ public class GamePolicyConfigInnerObjVO {
      */
     private Long amount;
 
+    /**
+     * 金额条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    private String amountCondition;
+
     /**
      * 时间(单位:小时)
      */
     private Long time;
 
+    /**
+     * 时间条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    private String timeCondition;
+
 }

+ 12 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GamePolicyConfigListVO.java

@@ -54,12 +54,24 @@ public class GamePolicyConfigListVO {
     @ApiModelProperty("金额")
     private Long amount;
 
+    /**
+     * 金额条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    @ApiModelProperty("金额条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于")
+    private String amountCondition;
+
     /**
      * 时间(单位:小时)
      */
     @ApiModelProperty("时间(单位:小时)")
     private Long time;
 
+    /**
+     * 时间条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于
+     */
+    @ApiModelProperty("时间条件:eq -> 等于; lt -> 小于; gt -> 大于; le -> 小于等于; ge -> 大于等于")
+    private String timeCondition;
+
     /**
      * 配置说明
      */

+ 32 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GamePolicyConfigServiceImpl.java

@@ -21,6 +21,7 @@ import com.zanxiang.game.module.mybatis.mapper.GamePolicyConfigMapper;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -51,9 +52,8 @@ public class GamePolicyConfigServiceImpl extends ServiceImpl<GamePolicyConfigMap
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean addOrUpdate(GamePolicyConfigAddOrUpdateParam param) {
-        if (param.getAmount() == null && param.getTime() == null) {
-            throw new BaseException("策略配置的金额和时间不能同时为空,请重新输入。");
-        }
+        //检查输入的查询参数
+        checkParam(param);
         //当前操作人员
         Long sysUserId = SecurityUtil.getUserId();
         //当前操作时间
@@ -62,7 +62,9 @@ public class GamePolicyConfigServiceImpl extends ServiceImpl<GamePolicyConfigMap
         //生成配置json字符串
         String configParam = JsonUtil.toString(GamePolicyConfigInnerObjVO.builder()
                 .amount(param.getAmount())
+                .amountCondition(param.getAmountCondition())
                 .time(param.getTime())
+                .timeCondition(param.getTimeCondition())
                 .build());
 
         int count = this.count(new LambdaQueryWrapper<GamePolicyConfig>()
@@ -122,7 +124,9 @@ public class GamePolicyConfigServiceImpl extends ServiceImpl<GamePolicyConfigMap
         //得到配置参数map
         Map<String, String> configParam = JsonUtil.toMap(vo.getConfigParam(), Map.class, String.class);
         String amount = configParam.get("amount");
+        String amountCondition = configParam.get("amountCondition");
         String time = configParam.get("time");
+        String timeCondition = configParam.get("timeCondition");
         GameSupper gameSupper = gameSupperService.getById(vo.getSuperGameId());
         GameDTO game = gameService.getById(vo.getSuperGameId());
         String superGameName = null == gameSupper ? (null == game ? null : game.getName()) : gameSupper.getName();
@@ -131,8 +135,10 @@ public class GamePolicyConfigServiceImpl extends ServiceImpl<GamePolicyConfigMap
                 .superGameId(vo.getSuperGameId())
                 .superGameName(superGameName)
                 .type(vo.getType())
-                .amount(amount == null ? null : Long.valueOf(amount))
-                .time(time == null ? null : Long.valueOf(time))
+                .amount(StringUtils.isBlank(amount) ? null : Long.valueOf(amount))
+                .amountCondition(StringUtils.isBlank(amountCondition) ? null : amountCondition)
+                .time(StringUtils.isBlank(time) ? null : Long.valueOf(time))
+                .timeCondition(StringUtils.isBlank(timeCondition) ? null : timeCondition)
                 .configExplain(vo.getConfigExplain())
                 .createBy(vo.getCreateBy())
                 .createName(sysUserRpc.getById(vo.getCreateBy()).getData().getNickname())
@@ -143,6 +149,27 @@ public class GamePolicyConfigServiceImpl extends ServiceImpl<GamePolicyConfigMap
                 .build();
     }
 
+    /**
+     * 检查查询参数的合法性
+     * @param param GamePolicyConfigAddOrUpdateParam
+     */
+    private void checkParam(GamePolicyConfigAddOrUpdateParam param) {
+        if (param.getAmount() == null && param.getTime() == null) {
+            throw new BaseException("策略配置的金额和时间不能同时为空,请重新输入。");
+        }
+        if (param.getAmount() != null && StringUtils.isBlank(param.getAmountCondition())) {
+            throw new BaseException("输入金额后,对应的金额条件不能为空。");
+        }
+        if (param.getAmount() == null && StringUtils.isNotBlank(param.getAmountCondition())) {
+            throw new BaseException("金额为空时,不能单独设置金额条件。");
+        }
+        if (param.getTime() != null && StringUtils.isBlank(param.getTimeCondition())) {
+            throw new BaseException("输入时间后,对应的时间条件不能为空");
+        }
+        if (param.getTime() == null && StringUtils.isNotBlank(param.getTimeCondition())) {
+            throw new BaseException("时间为空时,不能单独设置时间条件");
+        }
 
+    }
 
 }