|
|
@ -5,16 +5,13 @@ import cn.hutool.core.date.DateUtil; |
|
|
import cn.hutool.core.io.FileUtil; |
|
|
import cn.hutool.core.io.FileUtil; |
|
|
import cn.hutool.core.io.file.FileNameUtil; |
|
|
import cn.hutool.core.io.file.FileNameUtil; |
|
|
import cn.hutool.core.util.IdUtil; |
|
|
import cn.hutool.core.util.IdUtil; |
|
|
import cn.hutool.db.handler.StringHandler; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.project.base.config.CustomIdGenerator; |
|
|
import com.project.base.config.CustomIdGenerator; |
|
|
import com.project.base.domain.exception.BusinessErrorException; |
|
|
import com.project.base.domain.exception.BusinessErrorException; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.information.application.KnowledgePointApplicationService; |
|
|
import com.project.information.application.KnowledgePointApplicationService; |
|
|
import com.project.information.domain.dto.InformationDTO; |
|
|
import com.project.information.domain.dto.InformationDTO; |
|
|
import com.project.information.domain.dto.KnowledgePointDTO; |
|
|
|
|
|
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.ProductLineEntity; |
|
|
import com.project.information.domain.entity.ProductLineEntity; |
|
|
import com.project.information.domain.enums.InformationParseStatusEnum; |
|
|
import com.project.information.domain.enums.InformationParseStatusEnum; |
|
|
import com.project.information.domain.param.FileCheckItem; |
|
|
import com.project.information.domain.param.FileCheckItem; |
|
|
@ -29,12 +26,14 @@ import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class UploadInformationDomainServiceImpl implements UploadInformationDomainService { |
|
|
public class UploadInformationDomainServiceImpl implements UploadInformationDomainService { |
|
|
|
|
|
private final ConcurrentHashMap<Long, ReentrantLock> subLineUploadLocks = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private InformationBaseService informationBaseService; |
|
|
private InformationBaseService informationBaseService; |
|
|
@ -108,21 +107,43 @@ public class UploadInformationDomainServiceImpl implements UploadInformationDoma |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReentrantLock lock = subLineUploadLocks.computeIfAbsent(subLineId, key -> new ReentrantLock()); |
|
|
|
|
|
lock.lock(); |
|
|
|
|
|
try { |
|
|
|
|
|
List<MultipartFile> sortedFiles = Arrays.stream(files) |
|
|
|
|
|
.sorted(Comparator.comparing(file -> Optional.ofNullable(file.getOriginalFilename()).orElse(""))) |
|
|
|
|
|
.toList(); |
|
|
|
|
|
|
|
|
|
|
|
List<String> inputFileNames = sortedFiles.stream() |
|
|
|
|
|
.map(MultipartFile::getOriginalFilename) |
|
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
|
.toList(); |
|
|
|
|
|
Set<String> existNameSet = new HashSet<>(); |
|
|
|
|
|
if (CollUtil.isNotEmpty(inputFileNames)) { |
|
|
|
|
|
existNameSet = informationBaseService.list(new LambdaQueryWrapper<InformationEntity>() |
|
|
|
|
|
.select(InformationEntity::getName) |
|
|
|
|
|
.eq(InformationEntity::getSubLineId, subLineId) |
|
|
|
|
|
.in(InformationEntity::getName, inputFileNames)) |
|
|
|
|
|
.stream() |
|
|
|
|
|
.map(InformationEntity::getName) |
|
|
|
|
|
.collect(java.util.stream.Collectors.toSet()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
List<String> successFiles = new ArrayList<>(); |
|
|
List<String> successFiles = new ArrayList<>(); |
|
|
Map<Long, String> fileMap = new HashMap<>(); |
|
|
Map<Long, String> fileMap = new HashMap<>(); |
|
|
Map<Long, String> fileNameMap = new HashMap<>(); |
|
|
Map<Long, String> fileNameMap = new HashMap<>(); |
|
|
for (MultipartFile file : files) { |
|
|
for (MultipartFile file : sortedFiles) { |
|
|
String fileName = file.getOriginalFilename(); |
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
|
|
if (Objects.isNull(fileName)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (existNameSet.contains(fileName) && skipExisting) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
LambdaQueryWrapper<InformationEntity> wrapper = 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); |
|
|
informationBaseService.remove(wrapper); |
|
|
String filePath = String.format("%s/%s/%s.%s", |
|
|
String filePath = String.format("%s/%s/%s.%s", |
|
|
subLineId, |
|
|
subLineId, |
|
|
@ -152,5 +173,8 @@ public class UploadInformationDomainServiceImpl implements UploadInformationDoma |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(String.format("上传成功:【%s】" , String.join("," , successFiles))); |
|
|
return Result.success(String.format("上传成功:【%s】" , String.join("," , successFiles))); |
|
|
|
|
|
} finally { |
|
|
|
|
|
lock.unlock(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|