|
|
|
@ -2,25 +2,35 @@ package com.project.information.application.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.project.base.domain.exception.BusinessErrorException; |
|
|
|
import com.project.base.config.CustomIdGenerator; |
|
|
|
import com.project.base.domain.result.Result; |
|
|
|
import com.project.information.application.DraftReviewApplicationService; |
|
|
|
import com.project.information.domain.dto.DraftSaveDTO; |
|
|
|
import com.project.information.domain.entity.InformationEntity; |
|
|
|
import com.project.information.domain.entity.KnowledgePointDraftEntity; |
|
|
|
import com.project.information.domain.entity.KnowledgePointEntity; |
|
|
|
import com.project.information.domain.enums.AuditStatusEnum; |
|
|
|
import com.project.information.domain.enums.DraftStatusEnum; |
|
|
|
import com.project.information.domain.service.ConfirmKnowledgePointDraftDomainService; |
|
|
|
import com.project.information.domain.service.InformationBaseService; |
|
|
|
import com.project.information.domain.service.KnowledgePointBaseService; |
|
|
|
import com.project.information.domain.service.KnowledgePointDraftBaseService; |
|
|
|
import com.project.interaction.application.AlgorithmApplicationService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
/** |
|
|
|
* 知识点草稿审核应用服务实现 |
|
|
|
* 简单 CRUD 直接调 BaseService,确认固化调 DomainService |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class DraftReviewApplicationServiceImpl implements DraftReviewApplicationService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@ -32,6 +42,15 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
@Autowired |
|
|
|
private ConfirmKnowledgePointDraftDomainService confirmKnowledgePointDraftDomainService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private KnowledgePointBaseService knowledgePointBaseService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AlgorithmApplicationService algorithmApplicationService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomIdGenerator customIdGenerator; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<List<KnowledgePointDraftEntity>> listDrafts(Long informationId) { |
|
|
|
if (informationId == null) { |
|
|
|
@ -103,4 +122,102 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
public Result<String> confirm(Long informationId) { |
|
|
|
return confirmKnowledgePointDraftDomainService.confirm(informationId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量保存草稿并确认(替代逐条编辑+单独确认) |
|
|
|
* 前端编辑完所有草稿后一次性提交,提交后自动固化 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Result<String> batchSaveAndConfirm(Long informationId, List<DraftSaveDTO> draftList) { |
|
|
|
if (informationId == null) { |
|
|
|
throw new BusinessErrorException("资料ID不能为空"); |
|
|
|
} |
|
|
|
if (draftList == null || draftList.isEmpty()) { |
|
|
|
throw new BusinessErrorException("草稿数据不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 校验资料状态
|
|
|
|
InformationEntity information = informationBaseService.getById(informationId); |
|
|
|
if (information == null) { |
|
|
|
throw new BusinessErrorException("资料不存在"); |
|
|
|
} |
|
|
|
if (DraftStatusEnum.APPROVED.getValue().equals(information.getDraftStatus())) { |
|
|
|
return Result.success("该资料已审核通过,无需重复操作"); |
|
|
|
} |
|
|
|
if (!DraftStatusEnum.PENDING.getValue().equals(information.getDraftStatus())) { |
|
|
|
throw new BusinessErrorException("该资料不在待审核状态"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 获取该资料下所有待审核草稿
|
|
|
|
List<KnowledgePointDraftEntity> existingDrafts = knowledgePointDraftBaseService.list( |
|
|
|
new LambdaQueryWrapper<KnowledgePointDraftEntity>() |
|
|
|
.eq(KnowledgePointDraftEntity::getInformationId, informationId) |
|
|
|
.eq(KnowledgePointDraftEntity::getAuditStatus, AuditStatusEnum.PENDING.getValue())); |
|
|
|
List<Long> existingIds = existingDrafts.stream() |
|
|
|
.map(KnowledgePointDraftEntity::getId).toList(); |
|
|
|
|
|
|
|
// 3. 用户传来的草稿ID集合
|
|
|
|
List<Long> incomingIds = draftList.stream() |
|
|
|
.map(DraftSaveDTO::getId) |
|
|
|
.filter(Objects::nonNull) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
// 4. 计算用户删除的草稿ID
|
|
|
|
List<Long> deletedIds = existingIds.stream() |
|
|
|
.filter(id -> !incomingIds.contains(id)) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
// 5. 逻辑删除(deleted=1),保留审计记录
|
|
|
|
if (!deletedIds.isEmpty()) { |
|
|
|
knowledgePointDraftBaseService.lambdaUpdate() |
|
|
|
.set(KnowledgePointDraftEntity::getDeleted, true) |
|
|
|
.in(KnowledgePointDraftEntity::getId, deletedIds) |
|
|
|
.update(); |
|
|
|
} |
|
|
|
|
|
|
|
// 6. 更新/编辑草稿
|
|
|
|
List<KnowledgePointDraftEntity> confirmedDrafts = new ArrayList<>(); |
|
|
|
for (DraftSaveDTO dto : draftList) { |
|
|
|
if (dto.getId() != null) { |
|
|
|
// 编辑现有草稿
|
|
|
|
KnowledgePointDraftEntity oldDraft = knowledgePointDraftBaseService.getById(dto.getId()); |
|
|
|
if (oldDraft != null && AuditStatusEnum.PENDING.getValue().equals(oldDraft.getAuditStatus())) { |
|
|
|
oldDraft.setContent(dto.getContent()); |
|
|
|
oldDraft.setKnowledgeType(dto.getKnowledgeType() != null ? dto.getKnowledgeType() : oldDraft.getKnowledgeType()); |
|
|
|
// aiContent 保留不动(AI原始返回用于审计对比)
|
|
|
|
oldDraft.setAuditStatus(AuditStatusEnum.APPROVED.getValue()); |
|
|
|
knowledgePointDraftBaseService.updateById(oldDraft); |
|
|
|
confirmedDrafts.add(oldDraft); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 7. 复制草稿content到正式知识点表
|
|
|
|
List<KnowledgePointEntity> knowledgePoints = new ArrayList<>(); |
|
|
|
for (KnowledgePointDraftEntity draft : confirmedDrafts) { |
|
|
|
KnowledgePointEntity kp = new KnowledgePointEntity(); |
|
|
|
kp.setId(customIdGenerator.nextId(kp)); |
|
|
|
kp.setContent(draft.getContent()); |
|
|
|
kp.setKnowledgeType(draft.getKnowledgeType()); |
|
|
|
kp.setInformationId(informationId); |
|
|
|
kp.setParseName(draft.getParseName()); |
|
|
|
knowledgePoints.add(kp); |
|
|
|
} |
|
|
|
knowledgePointBaseService.saveBatch(knowledgePoints); |
|
|
|
|
|
|
|
// 8. 更新资料状态为已审核通过(终态)
|
|
|
|
informationBaseService.lambdaUpdate() |
|
|
|
.eq(InformationEntity::getId, informationId) |
|
|
|
.set(InformationEntity::getDraftStatus, DraftStatusEnum.APPROVED.getValue()) |
|
|
|
.update(); |
|
|
|
|
|
|
|
// 9. 触发聚类
|
|
|
|
List<com.project.information.domain.dto.KnowledgePointDTO> kpList = knowledgePoints.stream() |
|
|
|
.map(entity -> entity.toDTO(com.project.information.domain.dto.KnowledgePointDTO::new)) |
|
|
|
.toList(); |
|
|
|
algorithmApplicationService.postToClusteringByInformationId(informationId, kpList); |
|
|
|
|
|
|
|
log.info(">>> [草稿审核] 批量保存并确认完成, informationId={}, 草稿数={}", informationId, confirmedDrafts.size()); |
|
|
|
return Result.success("保存成功,已审核通过"); |
|
|
|
} |
|
|
|
} |
|
|
|
|