package com.supervision.pdfqaserver.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.supervision.pdfqaserver.domain.Intention; import com.supervision.pdfqaserver.service.IntentionService; import com.supervision.pdfqaserver.mapper.IntentionMapper; import com.supervision.pdfqaserver.service.IntentionTruncationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * @author Administrator * @description 针对表【intention】的数据库操作Service实现 * @createDate 2025-05-14 15:23:54 */ @Slf4j @Service @RequiredArgsConstructor public class IntentionServiceImpl extends ServiceImpl implements IntentionService{ private final IntentionTruncationService intentionTruncationService; @Override public List batchSaveIfAbsent(List intents, String domainCategoryId,String truncateId) { Assert.notEmpty(domainCategoryId, "行业分类ID不能为空"); if (CollUtil.isEmpty(intents)){ return new ArrayList<>(); } List intentions = this.lambdaQuery().in(Intention::getDigest, intents) .eq(Intention::getDomainCategoryId, domainCategoryId).list(); List result = new ArrayList<>(); for (String intent : intents) { Intention one = intentions.stream().filter(i -> i.getDigest().equals(intent)).findFirst().orElse(null); if (null == one){ Intention intention = new Intention(); intention.setDigest(intent); intention.setDomainCategoryId(domainCategoryId); intention.setGenerationType("1");// 1:系统录入 this.save(intention); result.add(intention); // 保存关联关系 intentionTruncationService.saveIfAbsent(intention.getId(), truncateId); }else { result.add(one); intentionTruncationService.saveIfAbsent(one.getId(), truncateId); } } return result; } @Override public Intention queryByDigestAndDomainCategoryId(String digest, String domainCategoryId) { return this.lambdaQuery().eq(Intention::getDigest, digest) .eq(Intention::getDomainCategoryId, domainCategoryId).one(); } @Override public List queryByDomainCategoryId(String domainCategoryId) { return super.lambdaQuery().eq(Intention::getDomainCategoryId, domainCategoryId).list(); } @Override public List listAllPassed() { return super.lambdaQuery().eq(Intention::getGenerationType, "0").list(); } }