package com.ruoyi.cai.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cai.domain.UserBlacklist;
import com.ruoyi.cai.dto.app.vo.user.UserListVo;
import com.ruoyi.cai.mapper.UserBlacklistMapper;
import com.ruoyi.cai.service.UserBlacklistService;
import com.ruoyi.common.core.domain.PageQuery;
import org.springframework.stereotype.Service;

/**
 * 用户黑名单Service业务层处理
 *
 * @author 77
 * @date 2023-12-30
 */
@Service
public class UserBlacklistServiceImpl extends ServiceImpl<UserBlacklistMapper, UserBlacklist> implements UserBlacklistService {
    @Override
    public boolean black(Long userId, Long blackUserId,Integer actionType) {
        if(userId.equals(blackUserId)){
            throw new SecurityException("不能对自己操作哦");
        }
        if(actionType == 1){ // 拉黑
            UserBlacklist userBlacklist = new UserBlacklist();
            userBlacklist.setUserId(userId);
            userBlacklist.setBlackUid(blackUserId);
            this.save(userBlacklist);
        }else { // 取消拉黑
            this.remove(Wrappers.lambdaQuery(UserBlacklist.class)
                    .eq(UserBlacklist::getUserId,userId)
                    .eq(UserBlacklist::getBlackUid,blackUserId));
        }
        return true;
    }

    @Override
    public Page<UserListVo> pageApp(PageQuery pageQuery, Long userId) {
        return baseMapper.pageApp(pageQuery.build(),userId);
    }
}
