package org.jeecg.modules.adweb.enquiry.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import jakarta.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.adweb.enquiry.entity.AdwebPublicEnquiryRule;
import org.jeecg.modules.adweb.enquiry.mapper.AdwebPublicEnquiryRuleMapper;
import org.jeecg.modules.adweb.enquiry.service.IAdwebPublicEnquiryRuleService;
import org.springframework.stereotype.Service;

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

/**
 * @Description: 用于询盘规则过滤
 * @Author: cpq
 * @Date:   2024-10-17
 * @Version: V1.0
 */
@Service
public class AdwebPublicEnquiryRuleServiceImpl extends ServiceImpl<AdwebPublicEnquiryRuleMapper, AdwebPublicEnquiryRule> implements IAdwebPublicEnquiryRuleService {

    @Resource
    private AdwebPublicEnquiryRuleMapper adwebPublicEnquiryRuleMapper;

    @Override
    public IPage<AdwebPublicEnquiryRule> pageList(Page<AdwebPublicEnquiryRule> page, String word, Integer blackOrWhiteList, Integer isEnable, Integer useStatus,String column,String order) {
        return adwebPublicEnquiryRuleMapper.pageList(page, word, blackOrWhiteList, isEnable, useStatus,column,order);
    }

    @Override
    public List<String> getOpenAiBlackList() {
        List<AdwebPublicEnquiryRule> list = this.list(new QueryWrapper<AdwebPublicEnquiryRule>()
                .eq("status", 1)
                .eq("use_status", 1)
                .eq("is_enable", 1)
                .eq("black_or_white_list", 0));
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.stream().map(AdwebPublicEnquiryRule::getWord).collect(Collectors.toList());
    }

    @Override
    public List<String> getEnquiryBlackList() {
        List<AdwebPublicEnquiryRule> list = this.list(new QueryWrapper<AdwebPublicEnquiryRule>()
                .eq("status", 1)
                .eq("use_status", 0)
                .eq("is_enable", 1)
                .eq("black_or_white_list", 0));
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.stream().map(AdwebPublicEnquiryRule::getWord).collect(Collectors.toList());
    }

}
