Kaynağa Gözat

#MOD 附近设备

谭斌 2 yıl önce
ebeveyn
işleme
d4dd06a8ff

+ 39 - 0
device-api-service-member/pom.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>xy-device</artifactId>
+        <groupId>com.xy</groupId>
+        <version>1.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>device-api-service-member</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>device-api-service</artifactId>
+            <version>1.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>merc-api</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>merc-sdk</artifactId>
+            <version>1.0</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+</project>

+ 63 - 0
device-api-service-member/src/main/java/com/xy/controller/MemberDeviceController.java

@@ -0,0 +1,63 @@
+package com.xy.controller;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceInfoDto;
+import com.xy.dto.MemberDeviceDTO;
+import com.xy.error.CommRuntimeException;
+import com.xy.service.DeviceInfoServiceImpl;
+import com.xy.utils.Emptys;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import com.xy.utils.enums.DeviceBusySateType;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+
+/***
+ * 会员-设备
+ * @author 谭斌
+ * @date 2023/3/18 10:24
+ */
+@RestMappingController("member/device")
+@AllArgsConstructor
+@Api(tags = "会员-设备")
+public class MemberDeviceController {
+
+    private DeviceInfoServiceImpl deviceInfoService;
+
+    @PostMapping("nearbyPage")
+    @ApiOperation("附近设备列表")
+    public R<List<MemberDeviceDTO.NearlyDeviceVO>> nearbyPage(@RequestBody MemberDeviceDTO.QueryNearlyDevice dto) {
+        if (!Emptys.check(dto.getLon()) || !Emptys.check(dto.getLat())) {
+            throw new CommRuntimeException("经纬度不能为空");
+        }
+        MemberDeviceDTO.NearlyDeviceVO vo = new MemberDeviceDTO.NearlyDeviceVO();
+        DeviceInfoDto.Page page = new DeviceInfoDto.Page();
+        PageBean pageBean = new PageBean().setSize(-1L);
+        page.setPage(pageBean);
+        page.setLimitNum(dto.getLimitNum());
+        //冻结状态 1正常  2已冻结
+        page.setFreezeStatus(1);
+        page.setNearby(dto.getNearby());
+        page.setLat(dto.getLat());
+        page.setLon(dto.getLon());
+        PageBean<DeviceInfoDto.Vo2> pages = deviceInfoService.queryPage(page);
+        List<DeviceInfoDto.Vo2> records = pages.getRecords();
+        if (CollUtil.isEmpty(records)) {
+            return R.ok(CollUtil.newArrayList());
+        }
+        List<MemberDeviceDTO.NearlyDeviceVO> nearlyDeviceVOS = BeanUtil.copyToList(records, MemberDeviceDTO.NearlyDeviceVO.class);
+        nearlyDeviceVOS.forEach(v -> {
+            v.setBusyStateDesc(DeviceBusySateType.getEnumByCode(v.getBusyState()).getDescription());
+        });
+        return R.ok(nearlyDeviceVOS);
+    }
+
+
+}

+ 85 - 0
device-api-service-member/src/main/java/com/xy/dto/MemberDeviceDTO.java

@@ -0,0 +1,85 @@
+package com.xy.dto;
+
+import com.xy.annotate.DictFormat;
+import com.xy.consts.DictConsts;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+@Accessors(chain = true)
+public class MemberDeviceDTO {
+
+
+    @Data
+    @Accessors(chain = true)
+    public static class QueryNearlyDevice {
+
+        @NotBlank(message = "经度不能为空")
+        @ApiModelProperty(value = "经度", required = true)
+        private String lon;
+
+        @NotBlank(message = "维度不能为空")
+        @ApiModelProperty(value = "纬度", required = true)
+        private String lat;
+
+
+        @ApiModelProperty("附近最大距离,单位:米,默认500")
+        private Integer nearby = 500;
+
+        @ApiModelProperty(value = "限制查询数量(默认10)", required = false)
+        private Integer limitNum = 10;
+    }
+
+
+    @Data
+    @Accessors(chain = true)
+    public static class NearlyDeviceVO {
+
+        @ApiModelProperty("商户名称")
+        private String mercName;
+
+        @ApiModelProperty("距离")
+        private Integer m;
+
+        @ApiModelProperty("点位名称")
+        private String placeName;
+
+        @ApiModelProperty("线路名称")
+        private String placeLineName;
+
+        @ApiModelProperty("区域名称")
+        private String districtName;
+
+        @ApiModelProperty("设备id")
+        private Long deviceId;
+
+        @ApiModelProperty("设备名称")
+        private String deviceName;
+
+        @DictFormat(DictConsts.DEVICE_TYPE)
+        @ApiModelProperty("设备类型")
+        private Integer deviceType;
+
+        @ApiModelProperty("运营状态")
+        private Integer busyState;
+
+        @ApiModelProperty("运营状态描述")
+        private String busyStateDesc;
+
+        @ApiModelProperty("设备图片")
+        private String deviceImg;
+
+        @ApiModelProperty("经度")
+        private String lon;
+
+        @ApiModelProperty("纬度")
+        private String lat;
+
+
+    }
+
+
+}

+ 9 - 2
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -27,6 +27,7 @@ import com.xy.mapper.entity.DeviceInfoQueryPage;
 import com.xy.util.ExcelUtils;
 import com.xy.util.FileUtils;
 import com.xy.utils.*;
+import com.xy.utils.enums.DeviceNetSateType;
 import com.xy.utils.enums.DictEnum;
 import com.xy.utils.enums.DictSonEnum;
 import io.swagger.annotations.Api;
@@ -141,7 +142,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 .in(DeviceInfo::getDeviceId, dto.getDeviceId())
                 .select(DeviceInfo::getDeviceId, DeviceInfo::getDeviceName);
         List<DeviceInfo> deviceInfoList = list(lqw);
-        return R.ok(deviceInfoList.stream().collect(Collectors.toMap(DeviceInfo::getDeviceId, i->Optional.ofNullable(i.getDeviceName()).orElse(""))));
+        return R.ok(deviceInfoList.stream().collect(Collectors.toMap(DeviceInfo::getDeviceId, i -> Optional.ofNullable(i.getDeviceName()).orElse(""))));
     }
 
     @Override
@@ -594,12 +595,18 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
                 device.setBusyStateName(dictBusyState.getMsg());
                 DeviceDataDto.Vo deviceData = finalDataMap.get(dId);
+
+
                 //今日销售、库存情况 反显
                 device.setDayOrderNum(deviceData != null ? deviceData.getSalesCount() : 0);
                 device.setDaySalesPrice(deviceData != null ? deviceData.getSalesMoney() : 0);
                 DeviceStatusDto.Vo deviceStatus = finalDatdeviceStatusMap.get(deviceId);
                 device.setOnSaleNum(deviceStatus != null ? deviceStatus.getStock() : 0);
                 device.setFillNum(deviceStatus != null ? deviceStatus.getAfterFillStock() : 0);
+                //联网状态
+                Integer netState = deviceStatus.getNetState();
+                device.setNetState(netState);
+                device.setNetStateName(netState == null ? StrUtil.EMPTY : DeviceNetSateType.getEnumByCode(deviceStatus.getNetState()).getDescription());
 
             });
             vo.setDeviceInfos(deviceInfos);
@@ -950,7 +957,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
     }
 
 
-    private PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
+    public PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
         IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
         return toPageBean(DeviceInfoDto.Vo2.class, iPage);
     }

+ 17 - 8
device-api-service/src/main/resources/mapper/DeviceInfoMapper.xml

@@ -4,6 +4,9 @@
     <resultMap id="queryPageMap" type="com.xy.mapper.entity.DeviceInfoQueryPage">
         <id column="device_id" property="deviceId"/>
         <result column="device_name" property="deviceName"/>
+        <result column="m" property="m"/>
+        <result column="lon" property="lon"/>
+        <result column="lat" property="lat"/>
         <result column="device_type" property="deviceType"/>
         <result column="merc_device_code" property="mercDeviceCode"/>
         <result column="merc_id" property="mercId"/>
@@ -111,14 +114,14 @@
             POW(
             SIN(
             (
-            #{queryPage.lat} * PI() / 180 - lat * PI() / 180
+            #{queryPage.lat} * PI() / 180 - info.lat * PI() / 180
             ) / 2
             ),
             2
-            ) + COS(#{queryPage.lat} * PI() / 180) * COS(lat * PI() / 180) * POW(
+            ) + COS(#{queryPage.lat} * PI() / 180) * COS(info.lat * PI() / 180) * POW(
             SIN(
             (
-            #{queryPage.lon} * PI() / 180 - lon * PI() / 180
+            #{queryPage.lon} * PI() / 180 - info.lon * PI() / 180
             ) / 2
             ),
             2
@@ -153,7 +156,8 @@
         </if>
         <if test="queryPage.deviceIdName != null and queryPage.deviceIdName != ''">
             and (
-            LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or LOCATE(#{queryPage.deviceIdName}, info.device_name) > 0
+            LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or LOCATE(#{queryPage.deviceIdName}, info.device_name)
+            > 0
             )
         </if>
         <if test="queryPage.deviceId != null">
@@ -171,7 +175,8 @@
         </if>
         <if test="queryPage.no != null and queryPage.no != ''">
             and (
-            LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
+            LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or
+            LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
             )
         </if>
         <if test="queryPage.activeState != null">
@@ -203,7 +208,8 @@
         </if>
         <if test="queryPage.merc != null and queryPage.merc != ''">
             and (
-            info.merc_id = #{queryPage.merc} or info.merc_code = #{queryPage.merc} or LOCATE(#{queryPage.merc}, mr.name) > 0
+            info.merc_id = #{queryPage.merc} or info.merc_code = #{queryPage.merc} or LOCATE(#{queryPage.merc}, mr.name)
+            > 0
             )
         </if>
         <if test="queryPage.placeId != null">
@@ -222,7 +228,7 @@
             and info.busy_state = #{queryPage.busyState}
         </if>
         <if test="queryPage.appUpmVersion != null and queryPage.appUpmVersion != ''">
-            and sysinfo.app_upm_version = #{appUpmVersion}
+            and sysinfo.app_upm_version = #{queryPage.appUpmVersion}
         </if>
         <if test="queryPage.appDownmVersion != null and queryPage.appDownmVersion != ''">
             and sysinfo.app_downm_version = #{queryPage.appDownmVersion}
@@ -234,7 +240,7 @@
             and info.active_time &lt;= #{queryPage.endActiveTime}
         </if>
         <if test="queryPage.lon != null and queryPage.lon != ''">
-            <if test="queryPage.nearby != null and queryPage.nearby != ''">
+            <if test="queryPage.nearby != null">
                 HAVING `m` &lt;= #{queryPage.nearby}
             </if>
         </if>
@@ -246,6 +252,9 @@
                 order by info.create_time desc
             </otherwise>
         </choose>
+        <if test="queryPage.limitNum != null">
+            limit #{queryPage.limitNum }
+        </if>
     </select>
 
     <!--  小程序首页设备列表线路分组  -->

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

@@ -217,6 +217,9 @@ public class DeviceInfoDto {
         @ApiModelProperty(value = "注册信息", hidden = true)
         private DeviceRegisterDto.Vo deviceRegister;
 
+        @ApiModelProperty(value = "限制查询数量", required = false)
+        private Integer limitNum;
+
         public String getBeginActiveTime() {
             return beginActiveTime == null ? null : DataTime.toString(beginActiveTime.atTime(0, 0, 0));
         }
@@ -618,6 +621,12 @@ public class DeviceInfoDto {
         @ApiModelProperty("运营状态")
         private Integer busyState;
 
+        @ApiModelProperty("联网状态")
+        private Integer netState;
+
+        @ApiModelProperty("联网状态名称")
+        private String netStateName;
+
         @ApiModelProperty("运营状态名称")
         private String busyStateName;
 

+ 48 - 0
device-api/src/main/java/com/xy/utils/enums/DeviceNetSateType.java

@@ -0,0 +1,48 @@
+package com.xy.utils.enums;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.ToString;
+
+/**
+ * 设备联网状态 1 在线 2 离线
+ *
+ * @author 谭斌
+ */
+@Getter
+@ToString
+@AllArgsConstructor
+public enum DeviceNetSateType {
+
+
+    CONNECTED(1, "在线"),
+    DISCONNECT(2, "离线");
+
+    /**
+     * 编码值
+     */
+    private Integer code;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+
+    /**
+     * 通过code获取enum
+     *
+     * @param code
+     * @return
+     */
+    public static DeviceNetSateType getEnumByCode(Integer code) {
+        DeviceNetSateType[] values = values();
+        for (DeviceNetSateType value : values) {
+            if (value.getCode().equals(code)) {
+                return value;
+            }
+        }
+        return null;
+    }
+}

+ 7 - 0
device-start/pom.xml

@@ -29,6 +29,13 @@
             <artifactId>device-api-service-merc-mini</artifactId>
             <version>1.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>device-api-service-member</artifactId>
+            <version>1.0</version>
+        </dependency>
+
         <dependency>
             <groupId>com.xy</groupId>
             <artifactId>authorize-api-cloud</artifactId>

+ 2 - 1
pom.xml

@@ -13,6 +13,7 @@
         <module>device-api-service</module>
         <module>device-start</module>
         <module>device-api-service-merc-mini</module>
+        <module>device-api-service-member</module>
     </modules>
     <packaging>pom</packaging>
 
@@ -56,4 +57,4 @@
             <url>http://119.96.213.127:9013/maven/release</url>
         </repository>
     </distributionManagement>
-</project>
+</project>