package cn.com.ty.lift.enterprise.oa.service;

import cn.com.ty.lift.enterprise.oa.entity.AnnouncementImg;
import cn.com.ty.lift.enterprise.oa.mapper.AnnouncementImgMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 公告图片 服务实现类
 * </p>
 *
 * @author wcz
 * @since 2019-12-12
 */
@Service
public class AnnouncementImgService extends ServiceImpl<AnnouncementImgMapper, AnnouncementImg> {

    /**
     * 根据公告id查询公告图片
     * @param announcementId 公告id
     * @return List<AnnouncementImg>公告图片列表
     */
    public List<AnnouncementImg> listByAnnouncement(Long announcementId){
        LambdaQueryWrapper<AnnouncementImg> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(AnnouncementImg::getAnnouncementId, announcementId);
        lambdaQueryWrapper.orderByAsc(AnnouncementImg::getSort);
        return list(lambdaQueryWrapper);
    }

    public List<AnnouncementImg> listByAnnouncementIds(List<Long> announcementIds){
        LambdaQueryWrapper<AnnouncementImg> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(AnnouncementImg::getAnnouncementId, announcementIds);
        return list(lambdaQueryWrapper);
    }

    public boolean removeByAnnouncement(Long announcement){
        LambdaQueryWrapper<AnnouncementImg> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(AnnouncementImg::getAnnouncementId, announcement);
        return remove(lambdaQueryWrapper);
    }
}
