| | |
| | | package com.se.simu.controller; |
| | | |
| | | import com.se.simu.domain.vo.R; |
| | | import com.se.simu.utils.FileUtil; |
| | | import com.se.simu.utils.ZipUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("1-上传单个shp文件") |
| | | @PostMapping("/uploadShp") |
| | | public R<Object> uploadShp(@RequestParam("file") MultipartFile file) throws IOException { |
| | | if (file.isEmpty()) { |
| | | return success("文件不能为空"); |
| | | } |
| | | // 获取当前年月日 |
| | | String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
| | | String targetDir = Paths.get(uploadedFolder, date).toString(); |
| | | log.info("目标目录: {}", targetDir); |
| | | createDirectoriesIfNotExists(targetDir); |
| | | try { |
| | | // 文件地址全称 |
| | | Path filePath = Paths.get(targetDir, file.getOriginalFilename()); |
| | | // 文件名 |
| | | file.transferTo(filePath); |
| | | ZipUtils.unzip(targetDir + "\\" + file.getOriginalFilename(),targetDir); |
| | | File zipfile=new File(targetDir + "\\" + file.getOriginalFilename()); |
| | | zipfile.delete(); |
| | | return success(FileUtil.getShpPath(targetDir), "文件上传成功"); |
| | | } catch (IOException e) { |
| | | log.error("文件上传失败", e); |
| | | return fail("文件上传失败"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("1-上传单个文件") |
| | | @PostMapping("/uploads") |