ソースを参照

附近设备分页查询

李进 2 年 前
コミット
52e92a8356

+ 10 - 0
device-api-service/src/main/java/com/xy/entity/DeviceInfo.java

@@ -81,6 +81,16 @@ public class DeviceInfo {
      */
     private String deviceImg;
 
+    /**
+     * 经度
+     */
+    private String lon;
+
+    /**
+     * 纬度
+     */
+    private String lat;
+
     /**
      * 创建时间
      */

+ 5 - 0
device-api-service/src/main/java/com/xy/mapper/entity/DeviceInfoQueryPage.java

@@ -42,4 +42,9 @@ public class DeviceInfoQueryPage extends DeviceInfo {
      * 锁机状态
      */
     private Integer deviceState;
+
+    /**
+     * 距离
+     */
+    private Integer m;
 }

+ 11 - 1
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -12,6 +12,7 @@ import com.xy.dto.DeviceStatusDto;
 import com.xy.dto.DeviceSysinfoDto;
 import com.xy.entity.DeviceInfo;
 import com.xy.entity.SysDictRedis;
+import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceInfoMapper;
 import com.xy.mapper.entity.DeviceInfoQueryPage;
 import com.xy.utils.*;
@@ -129,8 +130,8 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         return R.ok();
     }
 
-    @ApiOperation("分页查询")
     @PostMapping("page")
+    @ApiOperation("分页查询")
     public R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page) {
         //数据鉴权
         boolean authByData = AuthorizeUtils.authByData(AuthorizeUtils.getSysId(), AuthorizeUtils.getUri());
@@ -142,6 +143,15 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             }
         }
         //查询数据
+        return nearbyPage(page);
+    }
+
+    @PostMapping("nearbyPage")
+    @ApiOperation("附近设备分页查询")
+    public R<PageBean<DeviceInfoDto.Vo2>> nearbyPage(@RequestBody DeviceInfoDto.Page page) {
+        if (!Emptys.check(page.getLon()) || !Emptys.check(page.getLat())) {
+            throw new CommRuntimeException("经纬度不能为空");
+        }
         IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
         return R.ok(toPageBean(DeviceInfoDto.Vo2.class, iPage));
     }

+ 37 - 1
device-api-service/src/main/resources/mapper/DeviceInfoMapper.xml

@@ -9,6 +9,29 @@
         sysinfo.android_version, sysinfo.device_sn,
         status.net_state, status.net_type, status.net_dbm, status.device_state,
         mr.merc_name
+        <if test="queryPage.lon != null and queryPage.lon != ''">
+            ,ROUND(
+                6378.138 * 2 * ASIN(
+                    SQRT(
+                        POW(
+                            SIN(
+                                (
+                                    #{queryPage.lat} * PI() / 180 - lat * PI() / 180
+                                ) / 2
+                            ),
+                            2
+                        ) + COS(#{queryPage.lat} * PI() / 180) * COS(lat * PI() / 180) * POW(
+                            SIN(
+                                (
+                                    #{queryPage.lon} * PI() / 180 - lon * PI() / 180
+                                ) / 2
+                            ),
+                            2
+                        )
+                    )
+                ) * 1000
+            ) AS m
+        </if>
         from device_info info
         join device_sysinfo sysinfo on(info.device_id = sysinfo.device_id)
         join device_status status on(info.device_id = status.device_id)
@@ -49,7 +72,20 @@
         <if test="queryPage.endActiveTime != null and queryPage.endActiveTime != ''">
             and info.active_time &lt;= #{queryPage.endActiveTime}
         </if>
-        order by create_time desc
+        <if test="queryPage.lon != null and queryPage.lon != ''">
+            <if test="queryPage.nearby != null and queryPage.nearby != ''">
+                HAVING `m` &lt;= #{queryPage.nearby}
+            </if>
+        </if>
+
+        <choose>
+            <when test="queryPage.lon != null and queryPage.lon != ''">
+                order by `m` asc
+            </when>
+            <otherwise>
+                order by create_time desc
+            </otherwise>
+        </choose>
     </select>
 
 </mapper>

+ 12 - 0
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -71,6 +71,9 @@ public class DeviceInfoDto {
         @ApiModelProperty(value = "激活时间-始")
         private LocalDate endActiveTime;
 
+        @ApiModelProperty("附近最大距离,单位:米")
+        private Integer nearby;
+
         public String getBeginActiveTime() {
             return beginActiveTime == null ? null : DataTime.toString(beginActiveTime.atTime(0, 0, 0));
         }
@@ -133,6 +136,12 @@ public class DeviceInfoDto {
         @ApiModelProperty("设备图片")
         private String deviceImg;
 
+        @ApiModelProperty("经度")
+        private String lon;
+
+        @ApiModelProperty("纬度")
+        private String lat;
+
         @ApiModelProperty("创建时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;
@@ -175,5 +184,8 @@ public class DeviceInfoDto {
 
         @ApiModelProperty("锁机状态")
         private Integer deviceState;
+
+        @ApiModelProperty("距离")
+        private Integer m;
     }
 }