更新上传接口/importTemplate

This commit is contained in:
遥望-何玉明 2024-07-10 16:59:59 +08:00
parent 74ae7dad49
commit 5a281ac912
3 changed files with 166 additions and 14 deletions

View File

@ -116,8 +116,8 @@ public class EntityDataAllController {
* @return * @return
*/ */
//4遥感数据(Remote sensing data) type //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) { 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);
} }
} }

View File

@ -6,6 +6,7 @@ import com.kening.vordm.entity.EntityDataAll;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.kening.vordm.vo.UserTenantVo; import com.kening.vordm.vo.UserTenantVo;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@ -22,4 +23,5 @@ public interface EntityDataAllService extends IService<EntityDataAll> {
R saveEntityData(EntityDataAll entityData); R saveEntityData(EntityDataAll entityData);
R fileExcelUpload(MultipartFile fileDataOne, List<MultipartFile> fileDataTwo, Integer type, Long disasterId);
} }

View File

@ -1,40 +1,61 @@
package com.kening.vordm.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; 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 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.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays; import java.io.*;
import java.util.Date; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author G * @author G
* @description 针对表entity_data_all(其他上传的实体数据)的数据库操作Service实现 * @description 针对表entity_data_all(其他上传的实体数据)的数据库操作Service实现
* @createDate 2024-07-09 15:13:50 * @createDate 2024-07-09 15:13:50
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, EntityDataAll> public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, EntityDataAll>
implements EntityDataAllService{ implements EntityDataAllService {
private final GuestInfoMapper guestInfoMapper; private final GuestInfoMapper guestInfoMapper;
private final OssProperties ossProperties;
private final MinioTemplate minioTemplate;
@Value("${oss.minio.image-url:}")
private String imageUrl;
@Override @Override
public IPage<EntityDataAll> getEntityDataList(IPage<Object> page, EntityDataAll entityData) { public IPage<EntityDataAll> getEntityDataList(IPage<Object> page, EntityDataAll entityData) {
if (entityData.getType() !=null && !entityData.getType().isEmpty()){ if (entityData.getType() != null && !entityData.getType().isEmpty()) {
entityData.setTypeList(Arrays.asList(entityData.getType().split(","))); entityData.setTypeList(Arrays.asList(entityData.getType().split(",")));
} }
if (entityData.getStateListNew() !=null && !entityData.getStateListNew().isEmpty()){ if (entityData.getStateListNew() != null && !entityData.getStateListNew().isEmpty()) {
entityData.setStateList(Arrays.asList(entityData.getStateListNew().split(","))); entityData.setStateList(Arrays.asList(entityData.getStateListNew().split(",")));
} }
return this.baseMapper.getEntityDataList(entityData, page); return this.baseMapper.getEntityDataList(entityData, page);
@ -48,7 +69,7 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
@Override @Override
public R saveEntityData(EntityDataAll entityData) { public R saveEntityData(EntityDataAll entityData) {
if(entityData.getIsAdministration() == 0){ if (entityData.getIsAdministration() == 0) {
//判断上传用户是否存在 //判断上传用户是否存在
LambdaQueryWrapper<GuestInfo> qw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GuestInfo> qw = new LambdaQueryWrapper<>();
qw.eq(GuestInfo::getEmail, entityData.getEmail()); qw.eq(GuestInfo::getEmail, entityData.getEmail());
@ -75,11 +96,140 @@ public class EntityDataAllServiceImpl extends ServiceImpl<EntityDataAllMapper, E
entityData.setUploadTime(new Date()); entityData.setUploadTime(new Date());
entityData.setStatus(0); entityData.setStatus(0);
if (entityData.getId()!=null){ if (entityData.getId() != null) {
return R.status(this.baseMapper.updateById(entityData) > 0); return R.status(this.baseMapper.updateById(entityData) > 0);
} }
return R.status(this.baseMapper.insert(entityData) > 0); 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;
}
} }