更新上传接口/importTemplate
This commit is contained in:
parent
74ae7dad49
commit
5a281ac912
|
@ -116,8 +116,8 @@ public class EntityDataAllController {
|
|||
* @return
|
||||
*/
|
||||
//4遥感数据(Remote sensing data) type
|
||||
@PostMapping({"/importTemplate"})
|
||||
@PostMapping("/importTemplate")
|
||||
public R fileExcelUpload(@RequestParam("fileDataOne") MultipartFile fileDataOne, @RequestParam("fileDataTwo") List<MultipartFile> fileDataTwo, @RequestParam("type") Integer type, @RequestParam("disasterId") Long disasterId) {
|
||||
return R.data(null);
|
||||
return entityDataAllService.fileExcelUpload(fileDataOne,fileDataTwo,type,disasterId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.kening.vordm.entity.EntityDataAll;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.kening.vordm.vo.UserTenantVo;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,4 +23,5 @@ public interface EntityDataAllService extends IService<EntityDataAll> {
|
|||
|
||||
R saveEntityData(EntityDataAll entityData);
|
||||
|
||||
R fileExcelUpload(MultipartFile fileDataOne, List<MultipartFile> fileDataTwo, Integer type, Long disasterId);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,36 @@
|
|||
package com.kening.vordm.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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 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.springblade.core.oss.MinioTemplate;
|
||||
import org.springblade.core.oss.model.BladeFile;
|
||||
import org.springblade.core.oss.props.OssProperties;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author G
|
||||
|
@ -29,6 +44,12 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
|
||||
private final GuestInfoMapper guestInfoMapper;
|
||||
|
||||
private final OssProperties ossProperties;
|
||||
private final MinioTemplate minioTemplate;
|
||||
|
||||
@Value("${oss.minio.image-url:}")
|
||||
private String imageUrl;
|
||||
|
||||
@Override
|
||||
public IPage<EntityDataAll> getEntityDataList(IPage<Object> page, EntityDataAll entityData) {
|
||||
if (entityData.getType() != null && !entityData.getType().isEmpty()) {
|
||||
|
@ -80,6 +101,135 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
|
|||
}
|
||||
return R.status(this.baseMapper.insert(entityData) > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R fileExcelUpload(MultipartFile fileDataOne, List<MultipartFile> fileDataTwo, Integer type, Long disasterId) {
|
||||
HashSet<String> pictureNames = new HashSet<>();
|
||||
fileDataTwo.stream().forEach(multipartFile -> {
|
||||
String filename = multipartFile.getOriginalFilename();
|
||||
String firstname = filename.substring(0, filename.lastIndexOf("."));
|
||||
pictureNames.add(firstname);
|
||||
});
|
||||
try {
|
||||
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();
|
||||
EntityDataAll entityDataAll = new EntityDataAll();
|
||||
while (cellIterator.hasNext()) {
|
||||
Cell cell = cellIterator.next();
|
||||
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());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
entityDataAll.setType("4");
|
||||
entityDataAll.setDisasterId(disasterId);
|
||||
baseMapper.insert(entityDataAll);
|
||||
}
|
||||
}
|
||||
workbook.close();
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return R.data(false);
|
||||
}
|
||||
return R.data(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化上传文件返回路径
|
||||
*
|
||||
* @param bladeFile 上传成功后返回的值
|
||||
* @param showUrl 回显地址
|
||||
* @return 上传后的文件内容
|
||||
*/
|
||||
private BladeFile format(BladeFile bladeFile, String showUrl) {
|
||||
if (StringUtil.isNotBlank(showUrl)) {
|
||||
String link = bladeFile.getLink();
|
||||
String subUrl = link.replace(ossProperties.getEndpoint(), showUrl);
|
||||
bladeFile.setLink(subUrl);
|
||||
bladeFile.setDomain(showUrl);
|
||||
}
|
||||
return bladeFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue