修正上传接口/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,15 +110,11 @@ 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是否为空,为空不进行添加操作
|
||||
currentRow.forEach(cell -> {
|
||||
if (!Objects.isNull(cell)){
|
||||
int columnIndex = cell.getColumnIndex();
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
|
@ -189,7 +181,7 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
String filename = multipartFile.getOriginalFilename();
|
||||
if (filename.contains(cell.getStringCellValue())) {
|
||||
BladeFile bladeFile = minioTemplate.putFile(multipartFile);
|
||||
bladeFile = this.format(bladeFile, imageUrl);
|
||||
bladeFile = format(bladeFile, imageUrl);
|
||||
entityDataAll.setLink(bladeFile.getLink());
|
||||
}
|
||||
});
|
||||
|
@ -200,6 +192,7 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
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