| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.concurrent.CompletableFuture; |
| | | |
| | | |
| | | /** |
| | |
| | | return R.ok(tencentCosUtil.upLoadFile(file)); |
| | | } |
| | | |
| | | // @PostMapping(value = "/pic", produces = "application/json;charset=UTF-8") |
| | | // @ApiOperation(value = "文件上传加水印", tags = "师傅端-文件上传") |
| | | // @ApiImplicitParams({ |
| | | // @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | // }) |
| | | // public R<String> pic(@RequestParam("file") MultipartFile file,String longitude, |
| | | // String latitude) { |
| | | //// Result<String> address = GaoDeMapUtil.getAddress(longitude, latitude); |
| | | ////// return R.fail(); |
| | | //// |
| | | //// // 获取当前时间 |
| | | //// |
| | | //// LocalDateTime date = LocalDateTime.now(); |
| | | //// |
| | | //// // 设置日期格式 |
| | | //// |
| | | //// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | //// |
| | | //// // 通过format调用转换的方法 |
| | | //// |
| | | //// String dateWatermark = formatter.format(date); |
| | | ////// System.err.println("==========="+LocalDateTime.now()); |
| | | //// log.error("==========="+LocalDateTime.now()); |
| | | //// |
| | | //// MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file,dateWatermark,address.getDatas()); |
| | | ////// System.err.println("==========="+LocalDateTime.now()); |
| | | //// log.error("==========="+LocalDateTime.now()); |
| | | //// |
| | | //// |
| | | //// String url = tencentCosUtil.upLoadFile(watermarkFile); |
| | | ////// String url = tencentCosUtil.upLoadFile(file); |
| | | //// log.error("==========="+LocalDateTime.now()); |
| | | //// return R.ok(url); |
| | | // |
| | | // |
| | | // // 参数校验 |
| | | // if (file == null || file.isEmpty()) { |
| | | // return R.fail("文件不能为空"); |
| | | // } |
| | | // if (longitude == null || longitude.isEmpty() || latitude == null || latitude.isEmpty()) { |
| | | // return R.fail("经纬度参数不能为空"); |
| | | // } |
| | | // |
| | | // try { |
| | | // // 获取地址信息 |
| | | // Result<String> addressResult = GaoDeMapUtil.getAddress(longitude, latitude); |
| | | // if (addressResult == null || addressResult.getDatas() == null) { |
| | | // return R.fail("无法获取地址信息"); |
| | | // } |
| | | // |
| | | // // 获取当前时间 |
| | | // LocalDateTime date = LocalDateTime.now(); |
| | | // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // String dateWatermark = formatter.format(date); |
| | | // log.info("===========" + dateWatermark); |
| | | // |
| | | // // 给图片加水印 |
| | | // MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file, dateWatermark, addressResult.getDatas()); |
| | | // log.info("水印添加成功"); |
| | | // |
| | | // // 上传到腾讯云COS |
| | | // String url = tencentCosUtil.upLoadFile(watermarkFile); |
| | | // log.info("文件上传成功,URL: " + url); |
| | | // |
| | | // return R.ok(url); |
| | | // } catch (Exception e) { |
| | | // log.error("文件上传加水印失败: ", e); |
| | | // return R.fail("文件上传加水印失败: " + e.getMessage()); |
| | | // } |
| | | // } |
| | | |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | @PostMapping(value = "/pic", produces = "application/json;charset=UTF-8") |
| | | @ApiOperation(value = "文件上传加水印", tags = "师傅端-文件上传") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | }) |
| | | @Synchronized |
| | | public R<String> pic(@RequestParam("file") MultipartFile file,String longitude,String address, |
| | | String latitude) { |
| | | // Result<String> address = GaoDeMapUtil.getAddress(longitude, latitude); |
| | | // return R.fail(); |
| | | public CompletableFuture<R<String>> pic(@RequestParam("file") MultipartFile file, String longitude, String latitude) { |
| | | // 参数校验 |
| | | if (file == null || file.isEmpty()) { |
| | | return CompletableFuture.completedFuture(R.fail("文件不能为空")); |
| | | } |
| | | if (longitude == null || longitude.isEmpty() || latitude == null || latitude.isEmpty()) { |
| | | return CompletableFuture.completedFuture(R.fail("经纬度参数不能为空")); |
| | | } |
| | | |
| | | // 获取当前时间 |
| | | return CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | // 获取地址信息 |
| | | Result<String> addressResult = GaoDeMapUtil.getAddress(longitude, latitude); |
| | | if (addressResult == null || addressResult.getDatas() == null) { |
| | | return R.fail("无法获取地址信息"); |
| | | } |
| | | |
| | | LocalDateTime date = LocalDateTime.now(); |
| | | // 获取当前时间 |
| | | LocalDateTime date = LocalDateTime.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | String dateWatermark = formatter.format(date); |
| | | log.info("===========" + dateWatermark); |
| | | |
| | | // 设置日期格式 |
| | | // 给图片加水印 |
| | | MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file, dateWatermark, addressResult.getDatas()); |
| | | log.info("水印添加成功"); |
| | | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // 上传到腾讯云COS |
| | | String url = tencentCosUtil.upLoadFile(watermarkFile); |
| | | log.info("文件上传成功,URL: " + url); |
| | | |
| | | // 通过format调用转换的方法 |
| | | |
| | | String dateWatermark = formatter.format(date); |
| | | // System.err.println("==========="+LocalDateTime.now()); |
| | | log.error("==========="+LocalDateTime.now()); |
| | | |
| | | MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file,dateWatermark,address); |
| | | // System.err.println("==========="+LocalDateTime.now()); |
| | | log.error("==========="+LocalDateTime.now()); |
| | | |
| | | |
| | | String url = tencentCosUtil.upLoadFile(watermarkFile); |
| | | // String url = tencentCosUtil.upLoadFile(file); |
| | | log.error("==========="+LocalDateTime.now()); |
| | | return R.ok(url); |
| | | |
| | | return R.ok(url); |
| | | } catch (Exception e) { |
| | | log.error("文件上传加水印失败: ", e); |
| | | return R.fail("文件上传加水印失败: " + e.getMessage()); |
| | | } |
| | | }, taskExecutor); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |