修正上传接口/importTemplate

This commit is contained in:
遥望-何玉明 2024-07-11 09:50:54 +08:00
parent d5f552784d
commit 6dc9085d53
1 changed files with 104 additions and 92 deletions

View File

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