|
|
|
@ -2,12 +2,11 @@ package com.baiye.modules.platform.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
import cn.hutool.core.text.csv.CsvData;
|
|
|
|
|
import cn.hutool.core.text.csv.CsvReader;
|
|
|
|
|
import cn.hutool.core.text.csv.CsvRow;
|
|
|
|
|
import cn.hutool.core.text.csv.CsvUtil;
|
|
|
|
|
import cn.hutool.core.text.StrPool;
|
|
|
|
|
import cn.hutool.core.text.csv.*;
|
|
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.baiye.config.properties.DeliveryProperties;
|
|
|
|
@ -38,9 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -94,9 +91,12 @@ public class ModelRecordServiceImpl implements ModeRecordService {
|
|
|
|
|
}
|
|
|
|
|
// 去除重复数据
|
|
|
|
|
List<ImeiDTO> dtoArrayList = Lists.newArrayList(Sets.newHashSet(stringList));
|
|
|
|
|
// 保存文件
|
|
|
|
|
String downUrl = getDownUrl(stringList);
|
|
|
|
|
|
|
|
|
|
// 保存父类数据
|
|
|
|
|
Long recordId = saveRecord(taskName, uploadType, userId, (long) DefaultNumberConstants.ZERO_NUMBER,
|
|
|
|
|
DefaultNumberConstants.ONE_NUMBER, CharSequenceUtil.EMPTY, dtoArrayList);
|
|
|
|
|
DefaultNumberConstants.ONE_NUMBER, CharSequenceUtil.EMPTY, downUrl, dtoArrayList);
|
|
|
|
|
// tag分组
|
|
|
|
|
Map<String, List<ImeiDTO>> collect = dtoArrayList.stream().
|
|
|
|
|
collect(Collectors.groupingBy(ImeiDTO::getTag));
|
|
|
|
@ -105,7 +105,7 @@ public class ModelRecordServiceImpl implements ModeRecordService {
|
|
|
|
|
List<ImeiDTO> imeiDTOList = entry.getValue();
|
|
|
|
|
// 保存子类数据
|
|
|
|
|
Long childrenId = saveRecord(taskName, uploadType, userId, recordId,
|
|
|
|
|
DefaultNumberConstants.TWO_NUMBER, tag, imeiDTOList);
|
|
|
|
|
DefaultNumberConstants.TWO_NUMBER, tag, null, imeiDTOList);
|
|
|
|
|
if (uploadType < DefaultNumberConstants.TWO_NUMBER) {
|
|
|
|
|
// 每次100000 数据
|
|
|
|
|
List<List<ImeiDTO>> partition = Lists.partition
|
|
|
|
@ -128,6 +128,22 @@ public class ModelRecordServiceImpl implements ModeRecordService {
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getDownUrl(List<ImeiDTO> stringList) {
|
|
|
|
|
String uuid = IdUtil.fastSimpleUUID();
|
|
|
|
|
String fileName = deliveryProperties.getModelUrl().concat(StrPool.SLASH).concat(uuid);
|
|
|
|
|
String csvPath = fileName.concat(StrPool.DOT).concat(FileConstant.CSV_FILE_SUB_NAME);
|
|
|
|
|
CsvWriter writer = CsvUtil.getWriter(csvPath, CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
String zipPath = fileName.concat(FileConstant.ZIP_FILE_SUB_NAME);
|
|
|
|
|
writer.writeBeans(stringList);
|
|
|
|
|
writer.close();
|
|
|
|
|
// 设置压缩文件
|
|
|
|
|
CompressUtil.decryptionCompression(zipPath, csvPath, null);
|
|
|
|
|
String filePath = zipPath.substring
|
|
|
|
|
(zipPath.lastIndexOf(StrPool.SLASH) + DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
cn.hutool.core.io.FileUtil.del(csvPath);
|
|
|
|
|
return deliveryProperties.getModelPath().concat(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String findPath(Long downId) {
|
|
|
|
|
ModeRecord downRecord = modeRecordRepository.findById(downId).orElseGet(ModeRecord::new);
|
|
|
|
@ -150,38 +166,41 @@ public class ModelRecordServiceImpl implements ModeRecordService {
|
|
|
|
|
@Override
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean sendDataByActNameAndActId(Long id, String actName, String actId) {
|
|
|
|
|
public Boolean sendDataByActNameAndActId(List<Long> ids, String actName, String actId) {
|
|
|
|
|
List<String> stringList = Lists.newArrayList();
|
|
|
|
|
ModeRecord downRecord = modeRecordRepository.findById(id).orElseGet(ModeRecord::new);
|
|
|
|
|
if (ObjectUtil.isNull(downRecord) ||
|
|
|
|
|
downRecord.getRecordStatus() != DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
throw new BadRequestException("该批次暂不能建模!");
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
ModeRecord downRecord = modeRecordRepository.findById(id).orElseGet(ModeRecord::new);
|
|
|
|
|
if (ObjectUtil.isNull(downRecord) ||
|
|
|
|
|
downRecord.getRecordStatus() != DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
throw new BadRequestException("该批次暂不能建模!");
|
|
|
|
|
}
|
|
|
|
|
// 解压文件
|
|
|
|
|
String unzipPath = CompressUtil.unzipFiles
|
|
|
|
|
(deliveryProperties.getFileUrl(), downRecord.getUploadPath(), deliveryProperties.getZipPassword());
|
|
|
|
|
File unzipFile = new File(unzipPath);
|
|
|
|
|
File parseFile = Objects.requireNonNull
|
|
|
|
|
(unzipFile.listFiles())[DefaultNumberConstants.ZERO_NUMBER];
|
|
|
|
|
CsvReader reader = CsvUtil.getReader();
|
|
|
|
|
CsvData data = reader.read(parseFile);
|
|
|
|
|
// csv通配
|
|
|
|
|
data.getRows().forEach(str -> stringList.add(str.size() >
|
|
|
|
|
DefaultNumberConstants.THREE_NUMBER ? str.get(DefaultNumberConstants.TWO_NUMBER)
|
|
|
|
|
: str.get(DefaultNumberConstants.ZERO_NUMBER)));
|
|
|
|
|
cn.hutool.core.io.FileUtil.del(unzipPath);
|
|
|
|
|
// 修改状态
|
|
|
|
|
modeRecordRepository.updateStatusById(DefaultNumberConstants.TWO_NUMBER, id);
|
|
|
|
|
}
|
|
|
|
|
// 解压文件
|
|
|
|
|
String unzipPath = CompressUtil.unzipFiles
|
|
|
|
|
(deliveryProperties.getFileUrl(), downRecord.getUploadPath(), deliveryProperties.getZipPassword());
|
|
|
|
|
File unzipFile = new File(unzipPath);
|
|
|
|
|
File parseFile = Objects.requireNonNull
|
|
|
|
|
(unzipFile.listFiles())[DefaultNumberConstants.ZERO_NUMBER];
|
|
|
|
|
CsvReader reader = CsvUtil.getReader();
|
|
|
|
|
CsvData data = reader.read(parseFile);
|
|
|
|
|
// csv通配
|
|
|
|
|
data.getRows().forEach(str -> stringList.add(str.size() >
|
|
|
|
|
DefaultNumberConstants.THREE_NUMBER ? str.get(DefaultNumberConstants.TWO_NUMBER)
|
|
|
|
|
: str.get(DefaultNumberConstants.ZERO_NUMBER)));
|
|
|
|
|
cn.hutool.core.io.FileUtil.del(unzipPath);
|
|
|
|
|
// 修改状态
|
|
|
|
|
modeRecordRepository.updateStatusById(DefaultNumberConstants.TWO_NUMBER, id);
|
|
|
|
|
decryptTask.doRunSendTask(stringList, ids, actId, actName);
|
|
|
|
|
// 调用异步任务
|
|
|
|
|
decryptTask.doRunSendTask(stringList, id, actId, actName);
|
|
|
|
|
log.info("============= the request str list {} =============", stringList.size());
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long saveRecord(String taskName, Integer uploadType, Long userId, Long parentId, Integer levelNum, String tagStr, List<ImeiDTO> dtoArrayList) {
|
|
|
|
|
private Long saveRecord(String taskName, Integer uploadType, Long userId, Long parentId, Integer levelNum, String tagStr, String downUrl, List<ImeiDTO> dtoArrayList) {
|
|
|
|
|
ModeRecord modeRecord = new ModeRecord();
|
|
|
|
|
modeRecord.setUserId(userId);
|
|
|
|
|
modeRecord.setTagStr(tagStr);
|
|
|
|
|
modeRecord.setDownUrl(downUrl);
|
|
|
|
|
modeRecord.setParentId(parentId);
|
|
|
|
|
modeRecord.setTaskName(taskName);
|
|
|
|
|
modeRecord.setTreeLevel(levelNum);
|
|
|
|
@ -201,24 +220,30 @@ public class ModelRecordServiceImpl implements ModeRecordService {
|
|
|
|
|
|| originalFilename.endsWith(FileConstant.XLSX_FILE_SUB_NAME)) {
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(upload);
|
|
|
|
|
for (List<Object> objects : reader.read()) {
|
|
|
|
|
ImeiDTO dto = new ImeiDTO();
|
|
|
|
|
if (objects.size() > DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
ImeiDTO dto = new ImeiDTO();
|
|
|
|
|
dto.setTag(objects.get(DefaultNumberConstants.ONE_NUMBER).toString());
|
|
|
|
|
dto.setImei(objects.get(DefaultNumberConstants.ZERO_NUMBER).toString());
|
|
|
|
|
dtoList.add(dto);
|
|
|
|
|
}
|
|
|
|
|
if (objects.size() > DefaultNumberConstants.TWO_NUMBER) {
|
|
|
|
|
dto.setTime(objects.get(DefaultNumberConstants.TWO_NUMBER).toString());
|
|
|
|
|
}
|
|
|
|
|
dtoList.add(dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (originalFilename.endsWith(FileConstant.CSV_FILE_SUB_NAME)) {
|
|
|
|
|
CsvReader reader = CsvUtil.getReader();
|
|
|
|
|
CsvData read = reader.read(upload);
|
|
|
|
|
for (CsvRow row : read.getRows()) {
|
|
|
|
|
ImeiDTO dto = new ImeiDTO();
|
|
|
|
|
if (row.size() > DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
ImeiDTO dto = new ImeiDTO();
|
|
|
|
|
dto.setTag(row.get(DefaultNumberConstants.ONE_NUMBER));
|
|
|
|
|
dto.setImei(row.get(DefaultNumberConstants.ZERO_NUMBER));
|
|
|
|
|
dtoList.add(dto);
|
|
|
|
|
}
|
|
|
|
|
if (row.size() > DefaultNumberConstants.TWO_NUMBER) {
|
|
|
|
|
dto.setTime(row.get(DefaultNumberConstants.TWO_NUMBER));
|
|
|
|
|
}
|
|
|
|
|
dtoList.add(dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|