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

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.github.yulichang.wrapper.MPJLambdaWrapper;
import com.starry.admin.modules.personnel.mapper.PlayPersonnelAdminInfoMapper;
import com.starry.admin.modules.personnel.module.entity.PlayPersonnelAdminInfoEntity;
import com.starry.admin.modules.personnel.module.vo.PlayPersonnelAdminInfoQueryVo;
import com.starry.admin.modules.personnel.module.vo.PlayPersonnelAdminInfoReturnVo;
import com.starry.admin.modules.personnel.service.IPlayPersonnelAdminInfoService;
import com.starry.common.utils.IdUtils;
import java.util.Arrays;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 管理员管理Service业务层处理
 *
 * @author admin
 * @since 2024-06-14
 */
@Service
public class PlayPersonnelAdminInfoServiceImpl
        extends
            ServiceImpl<PlayPersonnelAdminInfoMapper, PlayPersonnelAdminInfoEntity>
        implements
            IPlayPersonnelAdminInfoService {
    @Resource
    private PlayPersonnelAdminInfoMapper playPersonnelAdminInfoMapper;

    @Override
    public PlayPersonnelAdminInfoEntity selectByUserId(String userId) {
        LambdaQueryWrapper<PlayPersonnelAdminInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PlayPersonnelAdminInfoEntity::getSysUserId, userId);
        return this.baseMapper.selectOne(queryWrapper);
    }

    /**
     * 查询管理员管理
     *
     * @param id
     *            管理员管理主键
     * @return 管理员管理
     */
    @Override
    public PlayPersonnelAdminInfoEntity selectPlayPersonnelAdminInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public IPage<PlayPersonnelAdminInfoReturnVo> selectByPage(PlayPersonnelAdminInfoQueryVo vo) {
        MPJLambdaWrapper<PlayPersonnelAdminInfoEntity> lambdaWrapper = new MPJLambdaWrapper<>();
        if (StrUtil.isNotBlank(vo.getAdminName())) {
            lambdaWrapper.eq(PlayPersonnelAdminInfoEntity::getAdminName, vo.getAdminName());
        }
        return this.baseMapper.selectJoinPage(new Page<>(vo.getPageNum(), vo.getPageSize()),
                PlayPersonnelAdminInfoReturnVo.class, lambdaWrapper);
    }

    /**
     * 新增管理员管理
     *
     * @param playPersonnelAdminInfo
     *            管理员管理
     * @return 结果
     */
    @Override
    public boolean create(PlayPersonnelAdminInfoEntity playPersonnelAdminInfo) {
        if (StrUtil.isBlankIfStr(playPersonnelAdminInfo.getId())) {
            playPersonnelAdminInfo.setId(IdUtils.getUuid());
        }
        return save(playPersonnelAdminInfo);
    }

    /**
     * 修改管理员管理
     *
     * @param playPersonnelAdminInfo
     *            管理员管理
     * @return 结果
     */
    @Override
    public boolean update(PlayPersonnelAdminInfoEntity playPersonnelAdminInfo) {
        return updateById(playPersonnelAdminInfo);
    }

    /**
     * 批量删除管理员管理
     *
     * @param ids
     *            需要删除的管理员管理主键
     * @return 结果
     */
    @Override
    public int deletePlayPersonnelAdminInfoByIds(String[] ids) {
        return playPersonnelAdminInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除管理员管理信息
     *
     * @param id
     *            管理员管理主键
     */
    @Override
    public void deletePlayPersonnelAdminInfoById(String id) {
        playPersonnelAdminInfoMapper.deleteById(id);
    }
}
