| | |
| | | package com.ruoyi.admin.controller; |
| | | |
| | | import com.ruoyi.admin.entity.Order; |
| | | import com.ruoyi.admin.service.OrderService; |
| | | import com.ruoyi.admin.utils.ObsUploadUtil; |
| | | 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.utils.GaoDeMapUtil; |
| | | import com.ruoyi.common.core.utils.ObsUploadUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | |
| | | @Api(tags = "公共-文件上传") |
| | | public class OssController { |
| | | |
| | | @Resource |
| | | private OrderService orderService; |
| | | |
| | | @PostMapping("/upload") |
| | | @ApiOperation(value = "文件上传", tags = "公共-文件上传") |
| | | @ApiImplicitParams({ |
| | |
| | | public R<String> upload(@RequestParam("file") MultipartFile file) { |
| | | try { |
| | | return R.ok(ObsUploadUtil.obsUpload(file), ""); |
| | | } catch (IOException e) { |
| | | return R.fail("文件上传失败!"); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/uploadPhoto") |
| | | @ApiOperation(value = "师傅端-上传完工照片", tags = "公共-文件上传") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "照片", name = "file", dataType = "MultipartFile", required = true), |
| | | @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true), |
| | | @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("文件上传失败!"); |
| | | } |