Jelajahi Sumber

接口去掉经纬度必填

zhangchen 1 Minggu lalu
induk
melakukan
5988bfc1cf

+ 13 - 6
alien-entity/src/main/java/shop/alien/mapper/second/SecondGoodsMapper.java

@@ -194,17 +194,24 @@ public interface SecondGoodsMapper extends BaseMapper<SecondGoods> {
      * @param queryWrapper 查询条件
      * @return 商品列表
      */
-    @Select("SELECT " +
+    @Select("<script>" +
+            "SELECT " +
             "sg.*, " +
             "sgc1.category_name as categoryOneName, " +
-            "sgc2.category_name as categoryTwoName, "+
-            "ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(',#{currentLongitude},' ',#{currentLatitude} , ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(sg.position, ',', ' '), ')' ))) / 1000, 2) AS distance "+
-            " FROM second_goods sg " +
+            "sgc2.category_name as categoryTwoName, " +
+            "<if test=\"currentLatitude != null and currentLongitude != null\">" +
+            "ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(',#{currentLongitude},' ',#{currentLatitude},')')), ST_GeomFromText(CONCAT('POINT(', REPLACE(sg.position, ',', ' '), ')' ))) / 1000, 2) AS distance " +
+            "</if>" +
+            "<if test=\"currentLatitude == null or currentLongitude == null\">" +
+            "NULL AS distance " +
+            "</if>" +
+            "FROM second_goods sg " +
             "left JOIN second_goods_category sgc1 " +
             "on sg.category_one_id = sgc1.id " +
             "left JOIN second_goods_category sgc2 " +
-            "on sg.category_two_id = sgc2.id "+
-            "${ew.customSqlSegment}")
+            "on sg.category_two_id = sgc2.id " +
+            "${ew.customSqlSegment}" +
+            "</script>")
     IPage<SecondGoodsVo> getUserGoodsPage(IPage<SecondGoodsVo> page,@Param("currentLatitude") Double currentLatitude , @Param("currentLongitude") Double currentLongitude,  @Param(Constants.WRAPPER) QueryWrapper<SecondGoodsVo> queryWrapper);
 
     /**

+ 4 - 4
alien-second/src/main/java/shop/alien/second/controller/UserGoodsController.java

@@ -162,14 +162,14 @@ public class UserGoodsController {
     @ApiOperation("他的商品-个人主页用户发布的商品")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "userId", value = "主页用户id", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "currentLongitude", value = "经度", dataType = "Double", paramType = "query", required = true),
-            @ApiImplicitParam(name = "currentLatitude", value = "纬度", dataType = "Double", paramType = "query", required = true),
+            @ApiImplicitParam(name = "currentLongitude", value = "经度", dataType = "Double", paramType = "query", required = false),
+            @ApiImplicitParam(name = "currentLatitude", value = "纬度", dataType = "Double", paramType = "query", required = false),
             @ApiImplicitParam(name = "pageNum", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
             @ApiImplicitParam(name = "pageSize", value = "分页条数", dataType = "Integer", paramType = "query", required = true)})
     public R<IPage<SecondGoodsVo>> getUserGoodsPage(
             @RequestParam Integer userId,
-            @RequestParam Double currentLongitude,
-            @RequestParam Double currentLatitude,
+            @RequestParam(required = false) Double currentLongitude,
+            @RequestParam(required = false) Double currentLatitude,
             @RequestParam(defaultValue = "1") Integer pageNum,
             @RequestParam(defaultValue = "10") Integer pageSize) {
         log.info("SecondGoodsController.getDraftList?userId={},currentLongitude={},currentLatitude={},page={},size={},",userId,currentLongitude,currentLatitude, pageNum,pageSize);

+ 1 - 1
alien-second/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: dev
+    active: test