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

import com.starry.common.utils.IdUtils;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.starry.admin.modules.play.mapper.PlayUserInfoMapper;
import com.starry.admin.modules.play.module.entity.PlayUserInfoEntity;
import com.starry.admin.modules.play.module.vo.PlayUserInfoQueryVo;
import com.starry.admin.modules.play.service.IPlayUserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 账号Service业务层处理
 *
 * @author admin
 * @since 2024-03-30
 */
@Service
public class PlayUserInfoServiceImpl extends ServiceImpl<PlayUserInfoMapper, PlayUserInfoEntity> implements IPlayUserInfoService {
    @Resource
    private PlayUserInfoMapper playUserInfoMapper;



    /**
     * 查询账号
     *
     * @param id 账号主键
     * @return 账号
     */
    @Override
    public PlayUserInfoEntity selectPlayUserInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

    /**
     * 查询账号列表
     *
     * @param vo 账号查询实体
     * @return 账号
     */
    @Override
    public IPage<PlayUserInfoEntity> selectPlayUserInfoByPage(PlayUserInfoQueryVo vo) {
        LambdaQueryWrapper<PlayUserInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(vo.getId())) {
            lambdaQueryWrapper.eq(PlayUserInfoEntity::getId, vo.getId());
        }
        if (StrUtil.isNotBlank(vo.getUserCode())) {
            lambdaQueryWrapper.eq(PlayUserInfoEntity::getAreaCode, vo.getUserCode());
        }
        Page<PlayUserInfoEntity> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        return this.baseMapper.selectPage(page, lambdaQueryWrapper);
    }

    /**
     * 新增账号
     *
     * @param playUserInfo 账号
     * @return 结果
     */
    @Override
    public boolean create(PlayUserInfoEntity playUserInfo) {
        if (StrUtil.isBlankIfStr(playUserInfo.getId())) {
            playUserInfo.setId(IdUtils.getUuid());
        }
        return save(playUserInfo);
    }

    /**
     * 修改账号
     *
     * @param playUserInfo 账号
     * @return 结果
     */
    @Override
    public boolean update(PlayUserInfoEntity playUserInfo) {
        return updateById(playUserInfo);
    }

    /**
     * 批量删除账号
     *
     * @param ids 需要删除的账号主键
     * @return 结果
     */
    @Override
    public int deletePlayUserInfoByIds(String[] ids) {
        return playUserInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除账号信息
     *
     * @param id 账号主键
     * @return 结果
     */
    @Override
    public int deletePlayUserInfoById(String id) {
        return playUserInfoMapper.deleteById(id);
    }
}
