package com.starry.admin.modules.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.starry.admin.modules.system.mapper.SysTenantRechargeInfoMapper;
import com.starry.admin.modules.system.module.entity.SysTenantEntity;
import com.starry.admin.modules.system.module.entity.SysTenantRechargeInfoEntity;
import com.starry.admin.modules.system.module.vo.SysTenantRechargeInfoQueryVo;
import com.starry.admin.modules.system.module.vo.SysTenantRechargeInfoReturnVo;
import com.starry.admin.modules.system.service.ISysTenantRechargeInfoService;
import com.starry.common.utils.IdUtils;
import java.util.Arrays;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 租户充值信息Service业务层处理
 *
 * @author admin
 * @since 2024-09-05
 */
@Service
public class SysTenantRechargeInfoServiceImpl
        extends
            ServiceImpl<SysTenantRechargeInfoMapper, SysTenantRechargeInfoEntity>
        implements
            ISysTenantRechargeInfoService {
    @Resource
    private SysTenantRechargeInfoMapper sysTenantRechargeInfoMapper;

    /**
     * 查询租户充值信息
     *
     * @param id
     *            租户充值信息主键
     * @return 租户充值信息
     */
    @Override
    public SysTenantRechargeInfoEntity selectSysTenantRechargeInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

    /**
     * 查询租户充值信息列表
     *
     * @param queryVo
     *            租户充值信息
     * @return 租户充值信息
     */
    @Override
    public IPage<SysTenantRechargeInfoReturnVo> selectByPage(SysTenantRechargeInfoQueryVo queryVo) {
        MPJLambdaWrapper<SysTenantRechargeInfoEntity> lambdaQueryWrapper = new MPJLambdaWrapper<>();
        lambdaQueryWrapper.selectAll(SysTenantRechargeInfoEntity.class);
        lambdaQueryWrapper.selectAs(SysTenantEntity::getTenantName, "rechargeName");
        lambdaQueryWrapper.leftJoin(SysTenantEntity.class, SysTenantEntity::getTenantId,
                SysTenantRechargeInfoEntity::getRechargeUser);
        return this.baseMapper.selectJoinPage(new Page<>(queryVo.getPageNum(), queryVo.getPageSize()),
                SysTenantRechargeInfoReturnVo.class, lambdaQueryWrapper);
    }

    /**
     * 新增租户充值信息
     *
     * @param sysTenantRechargeInfo
     *            租户充值信息
     * @return 结果
     */
    @Override
    public boolean create(SysTenantRechargeInfoEntity sysTenantRechargeInfo) {
        if (StrUtil.isBlankIfStr(sysTenantRechargeInfo.getId())) {
            sysTenantRechargeInfo.setId(IdUtils.getUuid());
        }
        return save(sysTenantRechargeInfo);
    }

    /**
     * 修改租户充值信息
     *
     * @param sysTenantRechargeInfo
     *            租户充值信息
     * @return 结果
     */
    @Override
    public boolean update(SysTenantRechargeInfoEntity sysTenantRechargeInfo) {
        return updateById(sysTenantRechargeInfo);
    }

    /**
     * 批量删除租户充值信息
     *
     * @param ids
     *            需要删除的租户充值信息主键
     * @return 结果
     */
    @Override
    public int deleteSysTenantRechargeInfoByIds(String[] ids) {
        return sysTenantRechargeInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除租户充值信息信息
     *
     * @param id
     *            租户充值信息主键
     * @return 结果
     */
    @Override
    public int deleteSysTenantRechargeInfoById(String id) {
        return sysTenantRechargeInfoMapper.deleteById(id);
    }
}
