修正上传接口/importTemplate
This commit is contained in:
parent
d5f552784d
commit
6dc9085d53
|
@ -6,18 +6,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.kening.vordm.entity.EntityDataAll;
|
||||
import com.kening.vordm.entity.GuestInfo;
|
||||
import com.kening.vordm.entity.RemoteSensingSourceData;
|
||||
import com.kening.vordm.mapper.GuestInfoMapper;
|
||||
import com.kening.vordm.service.EntityDataAllService;
|
||||
import com.kening.vordm.mapper.EntityDataAllMapper;
|
||||
import com.kening.vordm.vo.UserTenantVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.springblade.core.oss.MinioTemplate;
|
||||
import org.springblade.core.oss.model.BladeFile;
|
||||
import org.springblade.core.oss.props.OssProperties;
|
||||
|
@ -29,8 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author G
|
||||
|
@ -39,6 +34,7 @@ import java.util.stream.Stream;
|
|||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, EntityDataAll>
|
||||
implements EntityDataAllService {
|
||||
|
||||
|
@ -114,92 +110,89 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
InputStream inputStream = fileDataOne.getInputStream();
|
||||
Workbook workbook = new HSSFWorkbook(inputStream);
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
Iterator<Row> iterator = sheet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Row currentRow = iterator.next();
|
||||
if (currentRow.getRowNum() != 0) {
|
||||
Iterator<Cell> cellIterator = currentRow.iterator();
|
||||
sheet.forEach(currentRow -> {
|
||||
if (currentRow.getRowNum()!= 0&¤tRow!=null&&!isBlankRow(currentRow)) {
|
||||
EntityDataAll entityDataAll = new EntityDataAll();
|
||||
while (cellIterator.hasNext()) {
|
||||
Cell cell = cellIterator.next();
|
||||
//判断cell是否为空,为空不进行添加操作
|
||||
int columnIndex = cell.getColumnIndex();
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
entityDataAll.setLink(cell.getStringCellValue());
|
||||
break;
|
||||
case 1:
|
||||
entityDataAll.setProductLevel(cell.getStringCellValue());
|
||||
break;
|
||||
case 2:
|
||||
entityDataAll.setProductSerialNum(cell.getStringCellValue());
|
||||
break;
|
||||
case 3:
|
||||
entityDataAll.setProductTime(cell.getDateCellValue());
|
||||
break;
|
||||
case 4:
|
||||
entityDataAll.setProductResolution(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 5:
|
||||
String s = Double.toString(cell.getNumericCellValue());
|
||||
entityDataAll.setCloudCover(Integer.parseInt(s.substring(0,s.lastIndexOf("."))));
|
||||
break;
|
||||
case 6:
|
||||
entityDataAll.setSatelliteCode(cell.getStringCellValue());
|
||||
break;
|
||||
case 7:
|
||||
entityDataAll.setUpperLeftLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 8:
|
||||
entityDataAll.setUpperLeftLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 9:
|
||||
entityDataAll.setUpperRightLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 10:
|
||||
entityDataAll.setUpperRightLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 11:
|
||||
entityDataAll.setViewCenterLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 12:
|
||||
entityDataAll.setViewCenterLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 13:
|
||||
entityDataAll.setLowerRightLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 14:
|
||||
entityDataAll.setLowerRightLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 15:
|
||||
entityDataAll.setLowerLeftLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 16:
|
||||
entityDataAll.setLowerLeftLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 17:
|
||||
entityDataAll.setSourceOrganization(cell.getStringCellValue());
|
||||
break;
|
||||
case 18:
|
||||
entityDataAll.setPictureName(cell.getStringCellValue());
|
||||
if (StrUtil.isNotBlank(cell.getStringCellValue())){
|
||||
boolean flag = pictureNames.add(cell.getStringCellValue());
|
||||
if (!flag) {
|
||||
fileDataTwo.stream().forEach(multipartFile -> {
|
||||
String filename = multipartFile.getOriginalFilename();
|
||||
if (filename.contains(cell.getStringCellValue())) {
|
||||
BladeFile bladeFile = minioTemplate.putFile(multipartFile);
|
||||
bladeFile = this.format(bladeFile, imageUrl);
|
||||
entityDataAll.setLink(bladeFile.getLink());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
pictureNames.remove(cell.getStringCellValue());
|
||||
currentRow.forEach(cell -> {
|
||||
if (!Objects.isNull(cell)){
|
||||
int columnIndex = cell.getColumnIndex();
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
entityDataAll.setLink(cell.getStringCellValue());
|
||||
break;
|
||||
case 1:
|
||||
entityDataAll.setProductLevel(cell.getStringCellValue());
|
||||
break;
|
||||
case 2:
|
||||
entityDataAll.setProductSerialNum(cell.getStringCellValue());
|
||||
break;
|
||||
case 3:
|
||||
entityDataAll.setProductTime(cell.getDateCellValue());
|
||||
break;
|
||||
case 4:
|
||||
entityDataAll.setProductResolution(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 5:
|
||||
String s = Double.toString(cell.getNumericCellValue());
|
||||
entityDataAll.setCloudCover(Integer.parseInt(s.substring(0,s.lastIndexOf("."))));
|
||||
break;
|
||||
case 6:
|
||||
entityDataAll.setSatelliteCode(cell.getStringCellValue());
|
||||
break;
|
||||
case 7:
|
||||
entityDataAll.setUpperLeftLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 8:
|
||||
entityDataAll.setUpperLeftLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 9:
|
||||
entityDataAll.setUpperRightLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 10:
|
||||
entityDataAll.setUpperRightLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 11:
|
||||
entityDataAll.setViewCenterLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 12:
|
||||
entityDataAll.setViewCenterLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 13:
|
||||
entityDataAll.setLowerRightLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 14:
|
||||
entityDataAll.setLowerRightLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 15:
|
||||
entityDataAll.setLowerLeftLat(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 16:
|
||||
entityDataAll.setLowerLeftLon(Double.toString(cell.getNumericCellValue()));
|
||||
break;
|
||||
case 17:
|
||||
entityDataAll.setSourceOrganization(cell.getStringCellValue());
|
||||
break;
|
||||
case 18:
|
||||
entityDataAll.setPictureName(cell.getStringCellValue());
|
||||
if (StrUtil.isNotBlank(cell.getStringCellValue())){
|
||||
boolean flag = pictureNames.add(cell.getStringCellValue());
|
||||
if (!flag) {
|
||||
fileDataTwo.stream().forEach(multipartFile -> {
|
||||
String filename = multipartFile.getOriginalFilename();
|
||||
if (filename.contains(cell.getStringCellValue())) {
|
||||
BladeFile bladeFile = minioTemplate.putFile(multipartFile);
|
||||
bladeFile = format(bladeFile, imageUrl);
|
||||
entityDataAll.setLink(bladeFile.getLink());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
pictureNames.remove(cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
entityDataAll.setType("4");
|
||||
entityDataAll.setSource("Other");
|
||||
entityDataAll.setDisasterId(disasterId);
|
||||
|
@ -208,7 +201,7 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
entityDataAll.setIsAdministration(1);
|
||||
baseMapper.insert(entityDataAll);
|
||||
}
|
||||
}
|
||||
});
|
||||
workbook.close();
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -235,6 +228,25 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
}
|
||||
return bladeFile;
|
||||
}
|
||||
|
||||
public static boolean isBlankRow(Row row){
|
||||
boolean isEmptyRow = true;
|
||||
for (int i=0; i<row.getLastCellNum(); i++){
|
||||
if (row.getCell(i) != null){
|
||||
if (row.getCell(i).getCellType()== CellType.STRING && !row.getCell(i).getRichStringCellValue().equals("")){
|
||||
isEmptyRow = false;
|
||||
break;
|
||||
}else if (row.getCell(i).getCellType()!=CellType.BLANK){
|
||||
isEmptyRow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isEmptyRow)
|
||||
break;
|
||||
}
|
||||
return isEmptyRow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue