package com.starry.admin.modules.clerk.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.starry.admin.modules.clerk.mapper.PlayCustomArticleInfoMapper;
import com.starry.admin.modules.clerk.module.entity.PlayCustomArticleInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayCustomArticleInfoService;
import com.starry.common.utils.IdUtils;
import java.util.Arrays;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 陪聊点赞动态信息Service业务层处理
 *
 * @author admin
 * @since 2024-05-04
 */
@Service
public class PlayCustomArticleInfoServiceImpl
        extends
            ServiceImpl<PlayCustomArticleInfoMapper, PlayCustomArticleInfoEntity>
        implements
            IPlayCustomArticleInfoService {
    @Resource
    private PlayCustomArticleInfoMapper playCustomArticleInfoMapper;

    @Override
    public PlayCustomArticleInfoEntity selectByArticleId(String articleId, String customId, String endorseType) {
        LambdaQueryWrapper<PlayCustomArticleInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(PlayCustomArticleInfoEntity::getArticleId, articleId);
        lambdaQueryWrapper.eq(PlayCustomArticleInfoEntity::getCustomId, customId);
        lambdaQueryWrapper.eq(PlayCustomArticleInfoEntity::getEndorseType, endorseType);
        return this.baseMapper.selectOne(lambdaQueryWrapper);
    }

    /**
     * 查询陪聊点赞动态信息
     *
     * @param id
     *            陪聊点赞动态信息主键
     * @return 陪聊点赞动态信息
     */
    @Override
    public PlayCustomArticleInfoEntity selectPlayCustomArticleInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

    /**
     * 查询陪聊点赞动态信息列表
     *
     * @param playCustomArticleInfo
     *            陪聊点赞动态信息
     * @return 陪聊点赞动态信息
     */
    @Override
    public IPage<PlayCustomArticleInfoEntity> selectPlayCustomArticleInfoByPage(
            PlayCustomArticleInfoEntity playCustomArticleInfo) {
        Page<PlayCustomArticleInfoEntity> page = new Page<>(1, 10);
        return this.baseMapper.selectPage(page, new LambdaQueryWrapper<>());
    }

    /**
     * 新增陪聊点赞动态信息
     *
     * @param playCustomArticleInfo
     *            陪聊点赞动态信息
     * @return 结果
     */
    @Override
    public boolean create(PlayCustomArticleInfoEntity playCustomArticleInfo) {
        if (StrUtil.isBlankIfStr(playCustomArticleInfo.getId())) {
            playCustomArticleInfo.setId(IdUtils.getUuid());
        }
        return save(playCustomArticleInfo);
    }

    /**
     * 修改陪聊点赞动态信息
     *
     * @param playCustomArticleInfo
     *            陪聊点赞动态信息
     * @return 结果
     */
    @Override
    public boolean update(PlayCustomArticleInfoEntity playCustomArticleInfo) {
        return updateById(playCustomArticleInfo);
    }

    /**
     * 批量删除陪聊点赞动态信息
     *
     * @param ids
     *            需要删除的陪聊点赞动态信息主键
     * @return 结果
     */
    @Override
    public int deletePlayCustomArticleInfoByIds(String[] ids) {
        return playCustomArticleInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除陪聊点赞动态信息信息
     *
     * @param id
     *            陪聊点赞动态信息主键
     * @return 结果
     */
    @Override
    public int deletePlayCustomArticleInfoById(String id) {
        return playCustomArticleInfoMapper.deleteById(id);
    }

    @Override
    public void deleteByArticleId(String articleId) {
        LambdaQueryWrapper<PlayCustomArticleInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(PlayCustomArticleInfoEntity::getArticleId, articleId);
        this.baseMapper.delete(lambdaQueryWrapper);
    }
}
