设备在线状态推送
This commit is contained in:
parent
53e2a00a62
commit
1e22037196
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.iot.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
@ -134,5 +135,10 @@ public class IotDeviceDetail {
|
|||
NO_ACTIVE(2); // 未激活
|
||||
|
||||
private final Integer status;
|
||||
|
||||
// 转换为设备在线状态
|
||||
public static DeviceOnlineStatus toDeviceOnlineStatus(Integer iotStatus) {
|
||||
return ONLINE.getStatus().equals(iotStatus) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ import com.ruoyi.common.constant.IotConstants;
|
|||
import com.ruoyi.common.utils.NumberUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.iot.constants.ReceiveConstants;
|
||||
import com.ruoyi.iot.domain.IotDeviceDetail;
|
||||
import com.ruoyi.iot.domain.ReceiveMsg;
|
||||
import com.ruoyi.iot.enums.ReceiveType;
|
||||
import com.ruoyi.ss.device.domain.SmDevice;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOutageWay;
|
||||
import com.ruoyi.ss.device.service.ISmDeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -29,6 +31,7 @@ public class IotReceiveServiceImpl implements IotReceiveService{
|
|||
@Override
|
||||
public void handleReceive(ReceiveMsg msg) {
|
||||
log.info("handleReceive {}", msg.toString());
|
||||
// 数据点推送
|
||||
if (ReceiveType.DATA_POINT.getType().equals(msg.getType())) {
|
||||
if (ReceiveConstants.DS_SSID.equals(msg.getDsId())
|
||||
&& ReceiveConstants.DSV_SSID_CT.equals((String) msg.getValue())) {
|
||||
|
@ -41,8 +44,21 @@ public class IotReceiveServiceImpl implements IotReceiveService{
|
|||
deviceService.updateByIot(this.parseToDevice(msg));
|
||||
}
|
||||
}
|
||||
// 生命周期
|
||||
else if (ReceiveType.DEVICE_STATUS.getType().equals(msg.getType())) {
|
||||
deviceService.updateByIot(this.parseToDeviceByLife(msg));
|
||||
}
|
||||
}
|
||||
|
||||
// 生命周期转设备信息
|
||||
private SmDevice parseToDeviceByLife(ReceiveMsg msg) {
|
||||
SmDevice device = new SmDevice();
|
||||
device.setMac(msg.getDevName());
|
||||
device.setOnlineStatus(IotDeviceDetail.Status.toDeviceOnlineStatus(msg.getStatus()).getStatus());
|
||||
return device;
|
||||
}
|
||||
|
||||
// 数据点数据转设备信息
|
||||
private SmDevice parseToDevice(ReceiveMsg msg) {
|
||||
SmDevice device = new SmDevice();
|
||||
device.setMac(msg.getDevName());
|
||||
|
|
|
@ -77,7 +77,7 @@ public class IotServiceImpl implements IotService {
|
|||
return DeviceOnlineStatus.OFFLINE;
|
||||
}
|
||||
|
||||
return IotDeviceDetail.Status.ONLINE.getStatus().equals(detail.getStatus()) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
||||
return IotDeviceDetail.Status.toDeviceOnlineStatus(detail.getStatus());
|
||||
}
|
||||
|
||||
// 通电
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.ruoyi.ss.ad.domain;
|
||||
|
||||
import com.ruoyi.common.valid.EnumValid;
|
||||
import com.ruoyi.ss.ad.domain.enums.AdUrlType;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
@ -7,6 +9,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 广告对象 ss_ad
|
||||
*
|
||||
|
@ -22,7 +26,7 @@ public class Ad extends BaseEntity
|
|||
private Long adId;
|
||||
|
||||
@Excel(name = "广告类型 1:活动推广")
|
||||
@ApiModelProperty("广告类型 1:活动推广 ")
|
||||
@ApiModelProperty("广告类型 1:活动推广")
|
||||
private String type;
|
||||
|
||||
@Excel(name = "广告图片")
|
||||
|
@ -32,4 +36,13 @@ public class Ad extends BaseEntity
|
|||
@Excel(name = "跳转链接")
|
||||
@ApiModelProperty("跳转链接")
|
||||
private String url;
|
||||
|
||||
@Excel(name = "跳转链接类型")
|
||||
@ApiModelProperty("跳转链接类型,1外链跳转,2站内跳转")
|
||||
@EnumValid(
|
||||
clazz = AdUrlType.class,
|
||||
method = "getType",
|
||||
message = "非法的跳转链接类型"
|
||||
)
|
||||
private String urlType;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.ruoyi.ss.ad.domain.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/5/27
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AdUrlType {
|
||||
|
||||
OUTER("1"), // 外链
|
||||
INNER("2"); // 站内
|
||||
|
||||
private final String type;
|
||||
|
||||
}
|
|
@ -4,18 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.ss.ad.mapper.AdMapper">
|
||||
|
||||
<resultMap type="AdVO" id="AdResult">
|
||||
<result property="adId" column="ad_id" />
|
||||
<result property="type" column="type" />
|
||||
<result property="picture" column="picture" />
|
||||
<result property="url" column="url" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="deleted" column="deleted" />
|
||||
</resultMap>
|
||||
<resultMap type="AdVO" id="AdResult" autoMapping="true"/>
|
||||
|
||||
<sql id="selectAdVo">
|
||||
select
|
||||
|
@ -28,13 +17,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sa.update_by,
|
||||
sa.update_time,
|
||||
sa.remark,
|
||||
sa.deleted
|
||||
sa.deleted,
|
||||
sa.url_type
|
||||
from ss_ad sa
|
||||
</sql>
|
||||
|
||||
<sql id="searchCondition">
|
||||
<if test="adId != null "> and sa.ad_id = #{adId}</if>
|
||||
<if test="type != null and type != ''"> and sa.type = #{type}</if>
|
||||
<if test="urlType != null and urlType != ''"> and sa.url_type = #{urlType}</if>
|
||||
<if test="url != null and url != ''"> and sa.url like concat('%', #{url}, '%')</if>
|
||||
<if test="deleted != null "> and sa.deleted = #{deleted}</if>
|
||||
<if test="deleted == null "> and sa.deleted = false</if>
|
||||
|
@ -72,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="deleted != null">deleted,</if>
|
||||
<if test="urlType != null">url_type,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="type != null">#{type},</if>
|
||||
|
@ -83,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="deleted != null">#{deleted},</if>
|
||||
<if test="urlType != null">#{urlType},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -97,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="urlType != null">url_type = #{urlType},</if>
|
||||
</trim>
|
||||
where ad_id = #{adId}
|
||||
</update>
|
||||
|
|
|
@ -156,4 +156,9 @@ public interface SmDeviceMapper
|
|||
* 设备超时修改状态
|
||||
*/
|
||||
int changeTimeoutStatus(@Param("deviceId") Long deviceId);
|
||||
|
||||
/**
|
||||
* 批量更新在线状态
|
||||
*/
|
||||
int batchUpdateOnlineStatus(@Param("list") List<SmDeviceVo> list);
|
||||
}
|
||||
|
|
|
@ -364,6 +364,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</if>
|
||||
</update>
|
||||
|
||||
<!--批量更新在线状态-->
|
||||
<update id="batchUpdateOnlineStatus">
|
||||
update sm_device
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<foreach open="online_status = CASE device_id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.onlineStatus != null">
|
||||
WHEN #{item.deviceId} THEN #{item.onlineStatus}
|
||||
</when>
|
||||
<otherwise>
|
||||
WHEN #{item.deviceId} THEN `online_status`
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
where device_id in
|
||||
<foreach item="item" collection="list" open="(" separator="," close=")">
|
||||
#{item.deviceId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<delete id="deleteSmDeviceByDeviceId" parameterType="Long">
|
||||
delete from sm_device where device_id = #{deviceId}
|
||||
</delete>
|
||||
|
|
|
@ -205,4 +205,9 @@ public interface ISmDeviceService
|
|||
* 刷新设备状态,如果过期,则修改为正常
|
||||
*/
|
||||
void freshStatus(SmDeviceVo device);
|
||||
|
||||
/**
|
||||
* 设备心跳,用于检测是否在线
|
||||
*/
|
||||
void deviceHeartBeat();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.springframework.transaction.support.TransactionTemplate;
|
|||
import java.math.BigDecimal;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -239,7 +238,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
long seconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
|
||||
if (seconds > 0) {
|
||||
boolean rechargeResult = iotService.setTime(device.getMac(), new BigDecimal(seconds));
|
||||
ServiceUtil.assertion(!rechargeResult, "设备充值失败");
|
||||
ServiceUtil.assertion(!rechargeResult, "设备充值失败,请检查设备是否在线或联系管理员");
|
||||
}
|
||||
|
||||
// 拉取设备信息
|
||||
|
@ -281,6 +280,31 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
}, between.getSeconds() , TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备心跳,用于检测是否在线
|
||||
*/
|
||||
@Override
|
||||
public void deviceHeartBeat() {
|
||||
log.info("device heart beat running...");
|
||||
List<SmDeviceVo> list = smDeviceMapper.selectSimpleList(new SmDeviceQuery());
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
log.info("device list is empty");
|
||||
return;
|
||||
}
|
||||
for (SmDeviceVo device : list) {
|
||||
if (StringUtils.hasText(device.getMac())) {
|
||||
String status = iotService.getOnlineStatus(device.getMac()).getStatus();
|
||||
log.info("device: {} {} online status is {}", device.getDeviceId(), device.getMac(), status);
|
||||
device.setOnlineStatus(status);
|
||||
} else {
|
||||
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
||||
log.info("device {} mac is empty", device.getDeviceId());
|
||||
}
|
||||
}
|
||||
int i = smDeviceMapper.batchUpdateOnlineStatus(list);
|
||||
log.info("update count: {}", i);
|
||||
}
|
||||
|
||||
private int changeStatus(Long deviceId, DeviceStatus status) {
|
||||
SmDevice device = new SmDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.domain.JsonViewProfile;
|
|||
import com.ruoyi.common.core.domain.ValidGroup;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.ss.device.service.ISmDeviceService;
|
||||
import com.ruoyi.ss.store.domain.*;
|
||||
import com.ruoyi.ss.store.service.IStoreService;
|
||||
import com.ruoyi.ss.store.service.StoreAssembler;
|
||||
|
@ -43,6 +44,9 @@ public class AppStoreController extends BaseController {
|
|||
@Autowired
|
||||
private StoreAssembler storeAssembler;
|
||||
|
||||
@Autowired
|
||||
private ISmDeviceService deviceService;
|
||||
|
||||
/**
|
||||
* 查询本人店铺列表
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user