package com.ruoyi.frequency.worksshield.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.post.frequency.posshield.entity.PostShield;
import com.ruoyi.response.ResponseData;
import com.ruoyi.utils.SnowIdUtils;
import com.ruoyi.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.frequency.worksshield.mapper.WorksShieldMapper;
import com.ruoyi.frequency.worksshield.entity.WorksShield;
import com.ruoyi.frequency.worksshield.service.WorksShieldService;

/**
 * 作品屏蔽Service业务层处理
 *
 * @author liwenlong
 * @date 2023-11-30
 */
@Service
public class WorksShieldServiceImpl extends ServiceImpl<WorksShieldMapper, WorksShield>  implements WorksShieldService
{
    @Autowired
    private WorksShieldMapper worksShieldMapper;

    /**
     * 查询作品屏蔽
     *
     * @param id 作品屏蔽主键
     * @return 作品屏蔽
     */
    @Override
    public WorksShield selectWorksShieldById(Long id)
    {
        return worksShieldMapper.selectWorksShieldById(id);
    }

    /**
     * 查询作品屏蔽列表
     *
     * @param worksShield 作品屏蔽
     * @return 作品屏蔽
     */
    @Override
    public List<WorksShield> selectWorksShieldList(WorksShield worksShield)
    {
        return worksShieldMapper.selectWorksShieldList(worksShield);
    }

    /**
     * 新增作品屏蔽
     *
     * @param worksShield 作品屏蔽
     * @return 结果
     */
    @Override
    public int insertWorksShield(WorksShield worksShield)
    {
        return worksShieldMapper.insert(worksShield);
    }

    /**
     * 修改作品屏蔽
     *
     * @param worksShield 作品屏蔽
     * @return 结果
     */
    @Override
    public int updateWorksShield(WorksShield worksShield)
    {
        return worksShieldMapper.updateWorksShield(worksShield);
    }

    /**
     * 批量删除作品屏蔽
     *
     * @param ids 需要删除的作品屏蔽主键
     * @return 结果
     */
    @Override
    public int deleteWorksShieldByIds(Long[] ids,Integer delFlag)
    {
        this.lambdaUpdate().set(WorksShield::getDelFlag,delFlag).in(WorksShield::getId,ids).update();
        return ids.length;
    }

    @Override
    public ResponseData worksShield(Long id, UserVo userVo) {
        WorksShield worksShield = new WorksShield()
                .setId(SnowIdUtils.uniqueLong())
                .setWorksId(id)
                .setUserType(userVo.getUserType())
                .setUserId(userVo.getUserId());

        worksShield.setUpdateData();

        //作品屏蔽
        worksShieldMapper.worksShield(worksShield,userVo);

        return ResponseData.success();
    }

    @Override
    public List<Long> shieldWorksList(UserVo userVo) {
        //查询屏蔽帖子记录
        List<WorksShield> list = this.list(new QueryWrapper<WorksShield>().lambda()
                .eq(WorksShield::getDelFlag, PublicCommon.启用)
                .eq(WorksShield::getUserType, userVo.getUserType())
                .eq(WorksShield::getUserId, userVo.getUserId()));

        return list.stream().map(WorksShield::getWorksId).collect(Collectors.toList());
    }
}
