|
|
|
@ -2,9 +2,12 @@ package com.project.information.application.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.project.base.domain.exception.BusinessErrorException; |
|
|
|
import com.project.base.config.CustomIdGenerator; |
|
|
|
import com.project.base.domain.result.PageResult; |
|
|
|
import com.project.base.domain.result.Result; |
|
|
|
import com.project.base.config.CustomIdGenerator; |
|
|
|
import com.project.information.application.DraftReviewApplicationService; |
|
|
|
import com.project.information.domain.dto.DraftSaveDTO; |
|
|
|
import com.project.information.domain.dto.KnowledgePointDTO; |
|
|
|
@ -15,6 +18,7 @@ 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.param.InformationParam; |
|
|
|
import com.project.information.domain.service.ConfirmKnowledgePointDraftDomainService; |
|
|
|
import com.project.information.domain.service.InformationBaseService; |
|
|
|
import com.project.information.domain.service.KnowledgeClusterBaseService; |
|
|
|
@ -66,27 +70,32 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<List<KnowledgePointDraftDTO>> listDrafts(Long informationId) { |
|
|
|
if (informationId == null) { |
|
|
|
public Result<PageResult<KnowledgePointDraftDTO>> listDrafts(InformationParam param) { |
|
|
|
if (param.getInformationId() == null) { |
|
|
|
throw new BusinessErrorException("资料ID不能为空"); |
|
|
|
} |
|
|
|
List<KnowledgePointDraftEntity> drafts = knowledgePointDraftBaseService.list( |
|
|
|
|
|
|
|
Page<KnowledgePointDraftEntity> page = new Page<>(param.getCurrent(), param.getSize()); |
|
|
|
IPage<KnowledgePointDraftEntity> pageResult = knowledgePointDraftBaseService.page(page, |
|
|
|
new LambdaQueryWrapper<KnowledgePointDraftEntity>() |
|
|
|
.eq(KnowledgePointDraftEntity::getInformationId, informationId) |
|
|
|
.eq(KnowledgePointDraftEntity::getInformationId, param.getInformationId()) |
|
|
|
.orderByAsc(KnowledgePointDraftEntity::getId)); |
|
|
|
List<KnowledgePointDraftDTO> res = drafts.stream() |
|
|
|
|
|
|
|
List<KnowledgePointDraftDTO> res = pageResult.getRecords().stream() |
|
|
|
.map(entity -> entity.toDTO(KnowledgePointDraftDTO::new)) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
Long infoId = drafts.stream() |
|
|
|
.findAny() |
|
|
|
.map(KnowledgePointDraftEntity::getInformationId) |
|
|
|
.orElse(null); // 或者 .orElse(0L) 给个默认值
|
|
|
|
if (Objects.nonNull(infoId)) { |
|
|
|
InformationEntity one = informationBaseService.getById(infoId); |
|
|
|
res.forEach(dto -> dto.setInformationName(one.getName())); |
|
|
|
// 填充资料名称
|
|
|
|
InformationEntity information = informationBaseService.getById(param.getInformationId()); |
|
|
|
if (information != null) { |
|
|
|
String name = information.getName(); |
|
|
|
res.forEach(dto -> dto.setInformationName(name)); |
|
|
|
} |
|
|
|
return Result.success(res); |
|
|
|
|
|
|
|
// 构造 DTO 分页结果
|
|
|
|
Page<KnowledgePointDraftDTO> dtoPage = new Page<>(pageResult.getCurrent(), pageResult.getSize(), pageResult.getTotal()); |
|
|
|
dtoPage.setRecords(res); |
|
|
|
return Result.success(new PageResult<>(dtoPage)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -145,46 +154,21 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<String> confirm(Long informationId) { |
|
|
|
public Result<String> confirm(Long informationId, String name) { |
|
|
|
validateInformation(informationId, name); |
|
|
|
return confirmKnowledgePointDraftDomainService.confirm(informationId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<String> batchSaveAndConfirm(Long informationId, List<DraftSaveDTO> draftList, String name) { |
|
|
|
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("该资料不在待审核状态"); |
|
|
|
} |
|
|
|
// 1. 校验资料状态并更新名称
|
|
|
|
validateInformation(informationId, name); |
|
|
|
|
|
|
|
// 2. 如果传了名称且与原名不同,查重并更新
|
|
|
|
if (StrUtil.isNotBlank(name) && !StrUtil.equals(name, information.getName())) { |
|
|
|
boolean exists = informationBaseService.lambdaQuery() |
|
|
|
.eq(InformationEntity::getSubLineId, information.getSubLineId()) |
|
|
|
.eq(InformationEntity::getName, name) |
|
|
|
.ne(InformationEntity::getId, informationId) |
|
|
|
.exists(); |
|
|
|
if (exists) { |
|
|
|
throw new BusinessErrorException("该子产品线下已存在同名资料「" + name + "」,请修改文件名"); |
|
|
|
} |
|
|
|
information.setName(name); |
|
|
|
informationBaseService.updateById(information); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 获取该资料下所有待审核草稿ID(仅查ID,减少数据传输)
|
|
|
|
// 2. 获取该资料下所有待审核草稿ID(仅查ID,减少数据传输)
|
|
|
|
List<Long> existingIds = knowledgePointDraftBaseService.lambdaQuery() |
|
|
|
.select(KnowledgePointDraftEntity::getId) |
|
|
|
.eq(KnowledgePointDraftEntity::getInformationId, informationId) |
|
|
|
@ -194,7 +178,7 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
.map(KnowledgePointDraftEntity::getId) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
// 3. 用户传来的草稿ID集合(用Set,O(1)查找)
|
|
|
|
// 2. 用户传来的草稿ID集合(用Set,O(1)查找)
|
|
|
|
Set<Long> incomingIdSet = draftList.stream() |
|
|
|
.map(DraftSaveDTO::getId) |
|
|
|
.filter(Objects::nonNull) |
|
|
|
@ -268,6 +252,39 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验资料存在性及状态,并更新名称(如有变更) |
|
|
|
*/ |
|
|
|
private void validateInformation(Long informationId, String name) { |
|
|
|
if (informationId == null) { |
|
|
|
throw new BusinessErrorException("资料ID不能为空"); |
|
|
|
} |
|
|
|
InformationEntity information = informationBaseService.getById(informationId); |
|
|
|
if (information == null) { |
|
|
|
throw new BusinessErrorException("资料不存在"); |
|
|
|
} |
|
|
|
if (DraftStatusEnum.APPROVED.getValue().equals(information.getDraftStatus())) { |
|
|
|
throw new BusinessErrorException("该资料已审核通过,不可重复操作"); |
|
|
|
} |
|
|
|
if (!DraftStatusEnum.PENDING.getValue().equals(information.getDraftStatus())) { |
|
|
|
throw new BusinessErrorException("该资料不在待审核状态"); |
|
|
|
} |
|
|
|
// 如果传了名称且与原名不同,查重并更新
|
|
|
|
if (StrUtil.isNotBlank(name) && !StrUtil.equals(name, information.getName())) { |
|
|
|
boolean exists = informationBaseService.lambdaQuery() |
|
|
|
.eq(InformationEntity::getSubLineId, information.getSubLineId()) |
|
|
|
.eq(InformationEntity::getName, name) |
|
|
|
.ne(InformationEntity::getId, informationId) |
|
|
|
.exists(); |
|
|
|
if (exists) { |
|
|
|
throw new BusinessErrorException("该子产品线下已存在同名资料「" + name + "」,请修改文件名"); |
|
|
|
} |
|
|
|
information.setName(name); |
|
|
|
informationBaseService.updateById(information); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 触发语义聚类 |
|
|
|
* 触发语义聚类 |
|
|
|
* 调用算法服务进行真实聚类,回调结果由 saveClusterByInformationId 处理 |
|
|
|
*/ |
|
|
|
|