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.PlayPersonnelWaiterInfoMapper;
import com.starry.admin.modules.personnel.module.entity.PlayPersonnelWaiterInfoEntity;
import com.starry.admin.modules.personnel.module.vo.PlayPersonnelWaiterInfoQueryVo;
import com.starry.admin.modules.personnel.module.vo.PlayPersonnelWaiterInfoReturnVo;
import com.starry.admin.modules.personnel.service.IPlayPersonnelWaiterInfoService;
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 PlayPersonnelWaiterInfoServiceImpl
        extends
            ServiceImpl<PlayPersonnelWaiterInfoMapper, PlayPersonnelWaiterInfoEntity>
        implements
            IPlayPersonnelWaiterInfoService {
    @Resource
    private PlayPersonnelWaiterInfoMapper playClerkWaiterInfoMapper;

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

    /**
     * 查询客服信息
     *
     * @param id
     *            客服信息主键
     * @return 客服信息
     */
    @Override
    public PlayPersonnelWaiterInfoEntity selectPlayClerkWaiterInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

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

    /**
     * 新增客服信息
     *
     * @param playClerkWaiterInfo
     *            客服信息
     * @return 结果
     */
    @Override
    public boolean create(PlayPersonnelWaiterInfoEntity playClerkWaiterInfo) {
        if (StrUtil.isBlankIfStr(playClerkWaiterInfo.getId())) {
            playClerkWaiterInfo.setId(IdUtils.getUuid());
        }
        return save(playClerkWaiterInfo);
    }

    /**
     * 修改客服信息
     *
     * @param playClerkWaiterInfo
     *            客服信息
     * @return 结果
     */
    @Override
    public boolean update(PlayPersonnelWaiterInfoEntity playClerkWaiterInfo) {
        return updateById(playClerkWaiterInfo);
    }

    /**
     * 批量删除客服信息
     *
     * @param ids
     *            需要删除的客服信息主键
     * @return 结果
     */
    @Override
    public int deletePlayClerkWaiterInfoByIds(String[] ids) {
        return playClerkWaiterInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除客服信息信息
     *
     * @param id
     *            客服信息主键
     */
    @Override
    public void deletePlayClerkWaiterInfoById(String id) {
        playClerkWaiterInfoMapper.deleteById(id);
    }
}
