diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/EntityDataAllController.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/EntityDataAllController.java index dabc127..5c4606e 100644 --- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/EntityDataAllController.java +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/EntityDataAllController.java @@ -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 fileDataTwo, @RequestParam("type") Integer type, @RequestParam("disasterId") Long disasterId) { - return R.data(null); + return entityDataAllService.fileExcelUpload(fileDataOne,fileDataTwo,type,disasterId); } } diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/EntityDataAllService.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/EntityDataAllService.java index 076b265..63e5361 100644 --- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/EntityDataAllService.java +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/EntityDataAllService.java @@ -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 { R saveEntityData(EntityDataAll entityData); + R fileExcelUpload(MultipartFile fileDataOne, List fileDataTwo, Integer type, Long disasterId); } diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/EntityDataAllServiceImpl.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/EntityDataAllServiceImpl.java index 4ea73aa..e04d7bb 100644 --- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/EntityDataAllServiceImpl.java +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/EntityDataAllServiceImpl.java @@ -1,40 +1,61 @@ 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 -* @description 针对表【entity_data_all(其他上传的实体数据)】的数据库操作Service实现 -* @createDate 2024-07-09 15:13:50 -*/ + * @author G + * @description 针对表【entity_data_all(其他上传的实体数据)】的数据库操作Service实现 + * @createDate 2024-07-09 15:13:50 + */ @Service @RequiredArgsConstructor public class EntityDataAllServiceImpl extends ServiceImpl - implements EntityDataAllService{ + implements EntityDataAllService { private final GuestInfoMapper guestInfoMapper; + private final OssProperties ossProperties; + private final MinioTemplate minioTemplate; + + @Value("${oss.minio.image-url:}") + private String imageUrl; + @Override public IPage getEntityDataList(IPage page, EntityDataAll entityData) { - if (entityData.getType() !=null && !entityData.getType().isEmpty()){ + if (entityData.getType() != null && !entityData.getType().isEmpty()) { 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(","))); } return this.baseMapper.getEntityDataList(entityData, page); @@ -48,7 +69,7 @@ public class EntityDataAllServiceImpl extends ServiceImpl qw = new LambdaQueryWrapper<>(); qw.eq(GuestInfo::getEmail, entityData.getEmail()); @@ -75,11 +96,140 @@ public class EntityDataAllServiceImpl extends ServiceImpl 0); } return R.status(this.baseMapper.insert(entityData) > 0); } + + @Override + public R fileExcelUpload(MultipartFile fileDataOne, List fileDataTwo, Integer type, Long disasterId) { + HashSet 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 iterator = sheet.iterator(); + while (iterator.hasNext()) { + Row currentRow = iterator.next(); + if (currentRow.getRowNum() != 0) { + Iterator 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; + } }