package com.zanxiang.game.module.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.module.manage.service.IPushMsgTextStrategy;
import com.zanxiang.game.module.mybatis.entity.GameUserRole;
import com.zanxiang.game.module.mybatis.entity.PushMsgTextStrategy;
import com.zanxiang.game.module.mybatis.mapper.PushMsgTextStrategyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author : lingfeng
 * @time : 2024-05-24
 * @description : 消息推送文本策略
 */
@Slf4j
@Service
public class PushMsgTextStrategyImpl extends ServiceImpl<PushMsgTextStrategyMapper, PushMsgTextStrategy> implements IPushMsgTextStrategy {

    @Override
    public String getStrategyText(GameUserRole gameUserRole) {
        PushMsgTextStrategy pushMsgTextStrategy = super.getOne(new LambdaQueryWrapper<PushMsgTextStrategy>()
                .eq(PushMsgTextStrategy::getGameId, gameUserRole.getGameId())
                .le(PushMsgTextStrategy::getRoleLevelMin, gameUserRole.getRoleLevel())
                .ge(PushMsgTextStrategy::getRoleLevelMax, gameUserRole.getRoleLevel())
                .le(PushMsgTextStrategy::getRechargeMoneyMin, gameUserRole.getRechargeMoney())
                .ge(PushMsgTextStrategy::getRechargeMoneyMax, gameUserRole.getRechargeMoney())
                .orderByDesc(PushMsgTextStrategy::getCreateTime)
                .last("limit 1"));
        return pushMsgTextStrategy == null ? null : pushMsgTextStrategy.getText();
    }
}
