package cn.cslg.pas.service;

import cn.cslg.pas.domain.ReportTemplateLabel;
import cn.cslg.pas.mapper.ReportTemplateLabelMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 模板表 服务类
 * </p>
 *
 * @author 王岩
 * @since 2022-03-31
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ReportTemplateLabelService extends ServiceImpl<ReportTemplateLabelMapper, ReportTemplateLabel> {

    public List<ReportTemplateLabel> getTemplateLabelByTemplateIds(List<Integer> templatesIds) {
        if (templatesIds == null || templatesIds.size() == 0) {
            return new ArrayList<>();
        }
        LambdaQueryWrapper<ReportTemplateLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(ReportTemplateLabel::getTemplateId, templatesIds);
        return this.list(queryWrapper);
    }

    public void deleteTemplateLabelByTemplateId(Integer templateId) {
        this.remove(Wrappers.<ReportTemplateLabel>lambdaQuery().eq(ReportTemplateLabel::getTemplateId, templateId));
    }
}
