package com.ruoyi.busi.service.impl;

import java.util.List;

import com.ruoyi.busi.query.BusiReportQuery;
import com.ruoyi.busi.service.IBusiUserLoveService;
import com.ruoyi.busi.vo.BusiReportVo;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.member.domain.MemberBlacklist;
import com.ruoyi.member.service.IMemberBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.busi.mapper.BusiReportMapper;
import com.ruoyi.busi.domain.BusiReport;
import com.ruoyi.busi.service.IBusiReportService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 举报记录Service业务层处理
 *
 * @author 朱春云
 * @date 2025-03-17
 */
@Service
public class BusiReportServiceImpl extends ServiceImpl<BusiReportMapper,BusiReport>  implements IBusiReportService
{
    @Autowired
    private BusiReportMapper busiReportMapper;
    @Resource
    private IMemberBlacklistService blacklistService;
    @Resource
    private IBusiUserLoveService userLoveService;

    @Override
    public IPage<BusiReportVo> queryListPage(BusiReportQuery pageReqVO, Page<BusiReportVo> page) {
        return busiReportMapper.queryListPage(pageReqVO, page);
    }

    /**
     * 处理举报
     * @param busiReport 请求参数
     */
    @Override
    public void dealReport(BusiReport busiReport) {
        busiReport.setDealTime(DateUtils.getNowDate());
        busiReport.setDealUserId(SecurityUtils.getUserId());
        busiReportMapper.updateById(busiReport);
    }

    /**
     * 博主举报通告主
     *
     * @param report {@link BusiReport}
     * @author PQZ
     * @date 14:00 2025/4/14
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveReport(BusiReport report) {
        //获取当前登录用户
        Long userId = SecurityUtils.getUserId();
        report.setUserId(userId);
        //加入拉黑
        MemberBlacklist blacklist = new MemberBlacklist();
        blacklist.setUserId(userId);
        blacklist.setBlackUserId(report.getReportUserId());
        blacklist.setBlackUserType(report.getReportUserType());
        blacklistService.save(blacklist);
        //取消关注
        userLoveService.userLoveIs(report.getReportUserId(), "0");
        save(report);
    }
}
