| | |
| | | package com.ruoyi.worker.controller; |
| | | |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.utils.GaoDeMapUtil; |
| | | import com.ruoyi.common.core.utils.ObsUploadUtil; |
| | | import com.ruoyi.worker.entity.Order; |
| | | import com.ruoyi.worker.service.OrderService; |
| | | import com.ruoyi.order.api.feignClient.OrderClient; |
| | | import com.ruoyi.worker.utils.FileImageWatermarkUtils; |
| | | import com.ruoyi.worker.utils.TencentCosUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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 org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | |
| | | /** |
| | | * @author HJL |
| | |
| | | @RestController |
| | | @RequestMapping("/oss") |
| | | @Api(tags = "师傅端-文件上传") |
| | | @Slf4j |
| | | public class OssController { |
| | | |
| | | @Resource |
| | | private OrderService orderService; |
| | | private OrderClient orderClient; |
| | | @Resource |
| | | private TencentCosUtil tencentCosUtil; |
| | | |
| | | |
| | | @PostMapping("/upload") |
| | | @ApiOperation(value = "文件上传", tags = "师傅端-文件上传") |
| | |
| | | @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | }) |
| | | public R<String> upload(@RequestParam("file") MultipartFile file) { |
| | | try { |
| | | return R.ok(ObsUploadUtil.obsUpload(file), ""); |
| | | } catch (IOException e) { |
| | | return R.fail("文件上传失败!"); |
| | | } |
| | | return R.ok(tencentCosUtil.upLoadFile(file)); |
| | | } |
| | | |
| | | @PostMapping("/uploadPhoto") |
| | |
| | | @ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true) |
| | | }) |
| | | public R<String> uploadPhoto(@RequestParam("file") MultipartFile file, @RequestParam String orderId, |
| | | @RequestParam String longitude, @RequestParam String latitude) { |
| | | // 校验经纬度 |
| | | Order order = orderService.lambdaQuery().eq(Order::getIsDelete, orderId).eq(Order::getIsDelete, 0).one(); |
| | | // 用户下单位置经纬度 |
| | | String orderPosition = order.getLongitude() + "," + order.getLatitude(); |
| | | // 师傅经纬度 |
| | | String workerPosition = longitude + "," + latitude; |
| | | // 师傅当前位置离用户下单位置具体距离 |
| | | Long distance = GaoDeMapUtil.getDistance(orderPosition, workerPosition).getDatas(); |
| | | // 上传时判断是否在下单位置附件,距离大于某个值则 不允许上传 |
| | | if (distance > Constants.THREE_THOUSAND) { |
| | | throw new GlobalException("您当前手机定位超出当前订单预约地址范围 3km,无法提供回收服务!"); |
| | | } |
| | | try { |
| | | return R.ok(ObsUploadUtil.obsUpload(file)); |
| | | } catch (IOException e) { |
| | | return R.fail("文件上传失败!"); |
| | | } |
| | | public R<Boolean> uploadPhoto(@RequestParam("file") MultipartFile file, @RequestParam String orderId, |
| | | @RequestParam String longitude, @RequestParam String latitude) { |
| | | 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) |
| | | }) |
| | | public CompletableFuture<R<String>> pic(@RequestParam("file") MultipartFile file, String longitude, String latitude) { |
| | | System.out.println("文件上传加水印=====>"+longitude+"====>"+latitude); |
| | | // 参数校验 |
| | | if (file == null || file.isEmpty()) { |
| | | return CompletableFuture.completedFuture(R.fail("文件不能为空")); |
| | | } |
| | | |
| | | Result<String> datas = new Result<>(); |
| | | |
| | | if (longitude == null || longitude.isEmpty() || latitude == null || latitude.isEmpty()) { |
| | | datas.setDatas("地址获取失败"); |
| | | } |
| | | |
| | | return CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | // 获取地址信息 |
| | | Result<String> addressResult = GaoDeMapUtil.getAddress(longitude, latitude); |
| | | if (addressResult == null || addressResult.getDatas() == null) { |
| | | datas.setDatas("地址获取失败"); |
| | | }else { |
| | | datas.setDatas(addressResult.getDatas()); |
| | | } |
| | | |
| | | // 获取当前时间 |
| | | 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, datas.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()); |
| | | } |
| | | }, taskExecutor); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |