|
@@ -8,6 +8,7 @@ import com.zanxiang.erp.base.ErpServer;
|
|
|
import com.zanxiang.erp.base.rpc.ISysUserRpc;
|
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.GameVipAddBatchParam;
|
|
|
import com.zanxiang.game.module.manage.pojo.params.GameVipAddParam;
|
|
|
import com.zanxiang.game.module.manage.pojo.params.GameVipListParam;
|
|
|
import com.zanxiang.game.module.manage.pojo.vo.GameVipListVO;
|
|
@@ -18,13 +19,16 @@ import com.zanxiang.game.module.mybatis.entity.GameSupper;
|
|
|
import com.zanxiang.game.module.mybatis.entity.GameVip;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.GameVipMapper;
|
|
|
import com.zanxiang.module.util.exception.BaseException;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author tianhua
|
|
@@ -113,6 +117,58 @@ public class GameVipServiceImpl extends ServiceImpl<GameVipMapper, GameVip> impl
|
|
|
.convert(this::toVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean addBatch(GameVipAddBatchParam param) {
|
|
|
+ checkParam(param);
|
|
|
+ Long sysUserId = SecurityUtil.getUserId();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //得到需要添加的vip列表的所有vip等级
|
|
|
+ List<Integer> vipList = param.getList().stream()
|
|
|
+ .map(GameVipAddBatchParam.GameVipParam::getVipLevel).collect(Collectors.toList());
|
|
|
+
|
|
|
+ int count = count(new LambdaQueryWrapper<GameVip>()
|
|
|
+ .eq(GameVip::getSuperGameId, param.getSuperGameId())
|
|
|
+ .in(GameVip::getParentGameId, param.getParentGameId())
|
|
|
+ .in(GameVip::getVipLevel, vipList)
|
|
|
+ .eq(GameVip::getIsDelete, 0));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BaseException("已经存在需要添加的VIP等级,请勿重复设置。");
|
|
|
+ }
|
|
|
+ //总共需要建多少个GameVip实例
|
|
|
+ int size = param.getParentGameId().size() * param.getList().size();
|
|
|
+ List<GameVip> list = new ArrayList<>(size);
|
|
|
+ for (int i = 0; i < param.getParentGameId().size(); i++) {
|
|
|
+ //父游戏ID
|
|
|
+ Long parentGameId = param.getParentGameId().get(i);
|
|
|
+ for (GameVipAddBatchParam.GameVipParam gameVipParam : param.getList()) {
|
|
|
+ list.add(GameVip.builder()
|
|
|
+ .parentGameId(parentGameId)
|
|
|
+ .superGameId(param.getSuperGameId())
|
|
|
+ .rechargeMoneyMin(gameVipParam.getRechargeMoneyMin())
|
|
|
+ .rechargeMoneyMax(gameVipParam.getRechargeMoneyMax())
|
|
|
+ .vipLevel(gameVipParam.getVipLevel())
|
|
|
+ .createBy(sysUserId)
|
|
|
+ .createTime(now)
|
|
|
+ .updateTime(now)
|
|
|
+ .updateBy(sysUserId)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkParam(GameVipAddBatchParam param) {
|
|
|
+ if (CollectionUtils.isEmpty(param.getList())) {
|
|
|
+ throw new BaseException("至少创建一个VIP档位。");
|
|
|
+ }
|
|
|
+ List<Integer> collect = param.getList().stream()
|
|
|
+ .map(GameVipAddBatchParam.GameVipParam::getVipLevel).collect(Collectors.toList())
|
|
|
+ .stream().distinct().collect(Collectors.toList());
|
|
|
+ if (collect.size() != param.getList().size()) {
|
|
|
+ throw new BaseException("不能创建重复的VIP档位。");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private GameVipListVO toVO(GameVip vo) {
|
|
|
GameDTO game = gameService.getById(vo.getParentGameId());
|