package com.fs.qw.mapper;


import com.fs.qw.domain.QwMaterial;
import com.fs.qw.param.QwMaterialParam;
import com.fs.qw.vo.QwMaterialVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 素材库Mapper接口
 *
 * @author fs
 * @date 2024-06-20
 */
public interface QwMaterialMapper
{
    /**
     * 查询素材库
     *
     * @param materialId 素材库主键
     * @return 素材库
     */
    public QwMaterial selectQwMaterialByMaterialId(Long materialId);

    /**
     * 查询素材库列表
     *
     * @param qwMaterial 素材库
     * @return 素材库集合
     */
    public List<QwMaterial> selectQwMaterialList(QwMaterial qwMaterial);

    @Select("<script>" +
            "select q.*,mq.material_group_name,cu.nick_name as createName from  qw_material q " +
            "left join qw_material_group mq on q.material_group_id=mq.material_group_id " +
            "left join company_user cu on cu.user_id = mq.create_user_id " +
            "where 1=1 " +
            "<if test = 'map.corpId !=null  and map.corpId!=\"\" '> " +
            "and q.corp_id =#{map.corpId} " +
            "</if>  " +
            "<if test = 'map.materialType !=null  and map.materialType!=\"\" '> " +
            "and q.material_type =#{map.materialType} " +
            "</if>  " +
            "<if test ='map.createName !=null and map.createName !=\"\" '> " +
            "and cu.nick_name like concat(#{map.createName},'%') " +
            "</if> " +
            "<if test ='map.sendCount !=null and map.sendCount!= \"\" '> " +
            "and q.send_count = #{map.sendCount} " +
            "</if> " +
            "<if test ='map.materialGroupId !=null and map.materialGroupId!=\"\" '>" +
            "and q.material_group_id =#{map.materialGroupId} " +
            "</if> " +
            "<if test ='map.title !=null and map.title !=\"\" '>" +
            "and q.title like concat(#{map.title},'%') " +
            "</if> " +
            "<if test ='map.groupType !=null and map.groupType !=\"\" '>" +
            "and q.group_type = #{map.groupType}" +
            "</if> " +
            "<if test ='map.createUserId !=null and map.createUserId !=\"\" '>" +
            "and q.create_user_id = #{map.createUserId}" +
            "</if> " +
            "order by q.create_time desc" +
            "</script>  ")
    public List<QwMaterialVO> selectQwMaterialListVO(@Param("map") QwMaterialParam param);

    /**
     * 新增素材库
     *
     * @param qwMaterial 素材库
     * @return 结果
     */
    public int insertQwMaterial(QwMaterial qwMaterial);

    /**
     * 修改素材库
     *
     * @param qwMaterial 素材库
     * @return 结果
     */
    public int updateQwMaterial(QwMaterial qwMaterial);

    /**
     * 删除素材库
     *
     * @param materialId 素材库主键
     * @return 结果
     */
    public int deleteQwMaterialByMaterialId(Long materialId);

    public int deleteQwMaterialByGroupMaterialId(Long materialIds);

    /**
    * 批量删除素材
    */
    public int deleteQwMaterialByGroupMaterialIds(Long[] materialIds);




    /**
     * 批量删除素材库
     *
     * @param materialIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteQwMaterialByMaterialIds(Long[] materialIds);
}
