Browse Source

文件上传添加跳过逻辑

master
luogw 2 weeks ago
parent
commit
709192d0c6
  1. 2
      src/main/java/com/project/information/application/InformationApplicationService.java
  2. 4
      src/main/java/com/project/information/application/impl/InformationApplicationServiceImpl.java
  3. 3
      src/main/java/com/project/information/application/impl/KnowledgePointApplicationServiceImpl.java
  4. 4
      src/main/java/com/project/information/controller/InformationController.java
  5. 2
      src/main/java/com/project/information/domain/service/UploadInformationDomainService.java
  6. 15
      src/main/java/com/project/information/domain/service/impl/UploadInformationDomainServiceImpl.java

2
src/main/java/com/project/information/application/InformationApplicationService.java

@ -14,7 +14,7 @@ public interface InformationApplicationService {
Result<String> checkDuplicates(Long subLineId, List<FileCheckItem> files) throws Exception; Result<String> checkDuplicates(Long subLineId, List<FileCheckItem> files) throws Exception;
Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId) throws Exception; Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId,Boolean skipExisting) throws Exception;
/** /**
* 查询资料列表 * 查询资料列表

4
src/main/java/com/project/information/application/impl/InformationApplicationServiceImpl.java

@ -34,8 +34,8 @@ public class InformationApplicationServiceImpl implements InformationApplication
} }
@Override @Override
public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId) throws Exception { public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId, Boolean skipExisting) throws Exception {
return uploadInformationDomainService.batchUploadAndOverwrite(files , subLineId); return uploadInformationDomainService.batchUploadAndOverwrite(files , subLineId, skipExisting);
} }
@Override @Override

3
src/main/java/com/project/information/application/impl/KnowledgePointApplicationServiceImpl.java

@ -8,6 +8,7 @@ import com.project.information.application.KnowledgePointApplicationService;
import com.project.information.domain.dto.KnowledgePointStatisticsDTO; import com.project.information.domain.dto.KnowledgePointStatisticsDTO;
import com.project.information.domain.entity.InformationEntity; import com.project.information.domain.entity.InformationEntity;
import com.project.information.domain.entity.KnowledgePointEntity; import com.project.information.domain.entity.KnowledgePointEntity;
import com.project.information.domain.enums.InformationParseStatusEnum;
import com.project.information.domain.service.GetStatisticsKnowledgePointDomainService; import com.project.information.domain.service.GetStatisticsKnowledgePointDomainService;
import com.project.information.domain.service.InformationBaseService; import com.project.information.domain.service.InformationBaseService;
import com.project.information.domain.service.KnowledgePointBaseService; import com.project.information.domain.service.KnowledgePointBaseService;
@ -102,9 +103,9 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
//向资料中冗余pareName字段值 //向资料中冗余pareName字段值
InformationEntity informationEntity = new InformationEntity(); InformationEntity informationEntity = new InformationEntity();
informationEntity.setId(id); informationEntity.setId(id);
informationEntity.setParseStatus(InformationParseStatusEnum.Success.getValue());
informationEntity.setParseName(knowledgePointEntities.get(0).getParseName()); informationEntity.setParseName(knowledgePointEntities.get(0).getParseName());
informationBaseService.updateById(informationEntity); informationBaseService.updateById(informationEntity);
} }
} }

4
src/main/java/com/project/information/controller/InformationController.java

@ -32,8 +32,8 @@ public class InformationController {
} }
@PostMapping("/batchUploadAndOverwrite") @PostMapping("/batchUploadAndOverwrite")
public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId) throws Exception { public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId, @RequestParam(required = false, defaultValue = "false") Boolean skipExisting) throws Exception {
return informationApplicationService.batchUploadAndOverwrite(files , subLineId); return informationApplicationService.batchUploadAndOverwrite(files , subLineId, skipExisting);
} }
@GetMapping("/list") @GetMapping("/list")

2
src/main/java/com/project/information/domain/service/UploadInformationDomainService.java

@ -10,5 +10,5 @@ public interface UploadInformationDomainService {
Result<String> checkDuplicates(Long subLineId, List<FileCheckItem> files) throws Exception; Result<String> checkDuplicates(Long subLineId, List<FileCheckItem> files) throws Exception;
Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId) throws Exception; Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId, Boolean skipExisting) throws Exception;
} }

15
src/main/java/com/project/information/domain/service/impl/UploadInformationDomainServiceImpl.java

@ -83,7 +83,7 @@ public class UploadInformationDomainServiceImpl implements UploadInformationDoma
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId) throws Exception { public Result<String> batchUploadAndOverwrite(MultipartFile[] files, Long subLineId, Boolean skipExisting) throws Exception {
if (Objects.isNull(subLineId)) { if (Objects.isNull(subLineId)) {
throw new BusinessErrorException("所属子产品线id不能为空"); throw new BusinessErrorException("所属子产品线id不能为空");
} }
@ -98,10 +98,17 @@ public class UploadInformationDomainServiceImpl implements UploadInformationDoma
Map<Long, MultipartFile> fileMap = new HashMap<>(); Map<Long, MultipartFile> fileMap = new HashMap<>();
for (MultipartFile file : files) { for (MultipartFile file : files) {
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
// 删掉原来的
informationBaseService.remove(new LambdaQueryWrapper<InformationEntity>() LambdaQueryWrapper<InformationEntity> wrapper = new LambdaQueryWrapper<InformationEntity>()
.eq(InformationEntity::getSubLineId, subLineId) .eq(InformationEntity::getSubLineId, subLineId)
.eq(InformationEntity::getName, fileName)); .eq(InformationEntity::getName, fileName);
long count = informationBaseService.count(wrapper);
//如果存在重复的,并且是跳过则不做处理
if (count > 0 && skipExisting) {
continue;
}
// 删掉原来的
informationBaseService.remove(wrapper);
String filePath = String.format("%s/%s/%s.%s", String filePath = String.format("%s/%s/%s.%s",
subLineId, subLineId,
DateUtil.format(new Date(), "yyyyMMdd"), DateUtil.format(new Date(), "yyyyMMdd"),

Loading…
Cancel
Save