فهرست منبع

开发商户端订单相关接口

wangzhijun 1 هفته پیش
والد
کامیت
ff98283cdd

+ 4 - 2
nightFragrance-massage/src/main/java/com/ylx/massage/domain/dto/CoordinateDTO.java

@@ -4,14 +4,16 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.math.BigDecimal;
+
 @Data
 @ApiModel(description = "经纬度查询dto")
 public class CoordinateDTO {
 
     @ApiModelProperty(value = "经度", required = true)
-    private double longitude;
+    private BigDecimal longitude;
 
     @ApiModelProperty(value = "纬度", required = true)
-    private double latitude;
+    private BigDecimal latitude;
 
 }

+ 13 - 2
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/AreaServiceImpl.java

@@ -24,6 +24,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -166,10 +167,20 @@ public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements Ar
         if (dto == null) {
             throw new IllegalArgumentException("坐标信息不能为空");
         }
-        if (dto.getLongitude() < -180 || dto.getLongitude() > 180) {
+
+        // 1. 先判空
+        if (dto.getLongitude() == null || dto.getLatitude() == null) {
+            throw new IllegalArgumentException("经纬度数值不能为空");
+        }
+
+        // 2. 再比较(此时已经确定不为 null,可以安全拆箱)
+        double lon = dto.getLongitude().doubleValue();
+        double lat = dto.getLatitude().doubleValue();
+
+        if (lon < -180 || lon > 180) {
             throw new IllegalArgumentException("经度必须在-180到180之间");
         }
-        if (dto.getLatitude() < -90 || dto.getLatitude() > 90) {
+        if (lat < -90 || lat > 90) {
             throw new IllegalArgumentException("纬度必须在-90到90之间");
         }
     }