1.更新设备的在线状态

This commit is contained in:
邱贞招 2024-09-27 17:28:47 +08:00
parent c1dcf956e2
commit 8cf4a61856
7 changed files with 116 additions and 6 deletions

View File

@ -232,7 +232,7 @@ iot:
# 推送消息token
token: JZWgouXXNcgTbxCyRCLKbQkKQMhyUrfL
# 创建设备地址
deviceUrl: https://iot-api.heclouds.com/device/create
deviceUrl: https://iot-api.heclouds.com/device
geo:
# 高德地图key web服务 手续费
key: 834f1f029671d84272554528311ff0f1

View File

@ -0,0 +1,47 @@
package com.ruoyi.common.utils.onenet;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class DeviceInfo {
private int code;
private Data data;
private String msg;
private String requestId;
@lombok.Data
public static class Data {
private long did;
private String pid;
private int accessPt;
private String authInfo;
private int dataPt;
private String name;
private String desc;
private int status; // 设备状态0-离线1-在线2-未激活
private LocalDateTime createTime;
private LocalDateTime activateTime;
private LocalDateTime lastTime;
private String imsi;
private String imei;
private String psk;
private String groupId;
private boolean enableStatus;
private List<String> tags;
private String lat;
private String lon;
private String authCode;
private String secKey;
private int chip;
private boolean obsv;
private boolean obsvSt;
private List<String> imsiOld;
private LocalDateTime imsiMt;
private int intelligentWay;
}
}

View File

@ -19,4 +19,7 @@ public class AsDeviceVO {
/** 是否绑定 */
@Excel(name = "是否绑定")
private Boolean isBand;
@Excel(name = "在线状态")
private String onlineStatus;
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AsDevice;
import com.ruoyi.system.domain.vo.AsDeviceVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -149,7 +150,7 @@ public interface AsDeviceMapper extends BaseMapper<AsDevice>
*/
String getNoOrderDevice(@Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("areaId") String areaId);
public int batchDisable(String[] sns);
// public int batchDisable(String[] sns);
AsDevice checkSNUnique(String sn);
@ -165,4 +166,9 @@ public interface AsDeviceMapper extends BaseMapper<AsDevice>
* 未绑定版本数
*/
int countUnBoundNum(Long id);
/**
* 未绑定版本数
*/
List<AsDeviceVO> selectAllDevice();
}

View File

@ -2744,7 +2744,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
createDeviceVo.setDevice_name(asDevice.getMac());
createDeviceVo.setProduct_id(productId);
String result = HttpUtils.sendPostWithToken(deviceUrl,JSON.toJSONString(createDeviceVo), Token.getToken());
String result = HttpUtils.sendPostWithToken(deviceUrl+"/create",JSON.toJSONString(createDeviceVo), Token.getToken());
log.info("【sn和mac号绑定】===>IOT请求调用结果:【{}】",result);
JSONObject paramsObj = JSON.parseObject(result);
String code = paramsObj.getString("code");

View File

@ -7,6 +7,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.IotConstants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.AsUser;
import com.ruoyi.common.core.domain.entity.SysUser;
@ -14,24 +15,34 @@ import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.map.GeoUtils;
import com.ruoyi.common.utils.map.GpsCoordinateUtils;
import com.ruoyi.common.utils.onenet.CreateDeviceVo;
import com.ruoyi.common.utils.onenet.DeviceInfo;
import com.ruoyi.common.utils.onenet.LogEntry;
import com.ruoyi.common.utils.onenet.Token;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.AsDeviceVO;
import com.ruoyi.system.domain.vo.OperatingDataVo;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.*;
import com.wechat.pay.java.service.refund.model.Refund;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -94,6 +105,12 @@ public class EtTask {
@Resource
private EtCouponClaimLogMapper etCouponClaimLogMapper;
@Value(value = "${iot.deviceUrl}")
private String deviceUrl;
@Value(value = "${iot.productId}")
private String productId;
/**
* 1.启动时判断是否有未取消预约的订单
@ -740,10 +757,42 @@ public class EtTask {
}
/**
* 五分钟更新电动车的状态
* 更新设备的在线状态
*
*/
public void updateDeviceStatus(){
log.info("-------------------【定时任务】五分钟更新电动车的状态---开始----------------");
public void updateDeviceOnlineStatus(){
log.info("-------------------【定时任务】更新设备的在线状态---开始----------------");
List<AsDeviceVO> deviceVOS = asDeviceMapper.selectAllDevice();
for(AsDeviceVO deviceVO : deviceVOS){
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
createDeviceVo.setDevice_name(deviceVO.getMac());
createDeviceVo.setProduct_id(productId);
try {
String param = "device_name=" + deviceVO.getMac() + "&product_id=" + productId;
String sendUrl = deviceUrl+"/detail" + "?"+param;
String result = HttpUtils.sendGetWithToken(sendUrl,null, Token.getToken());
log.info("【定时--更新设备的在线状态】===>IOT请求调用结果:【{}】",result);
DeviceInfo deviceInfo = JSON.parseObject(result, DeviceInfo.class);
int onlineStatus = Integer.parseInt(deviceVO.getOnlineStatus());
if(deviceInfo.getCode() != 0){
log.info("【定时--更新设备的在线状态】===>IOT请求调用失败");
continue;
}
int onenetStatus = deviceInfo.getData().getStatus();
if(onenetStatus != onlineStatus ){
AsDevice device = new AsDevice();
device.setMac(deviceVO.getMac());
device.setOnlineStatus(onenetStatus+"");
int i = asDeviceMapper.updateAsDeviceByMac(device);
log.info("【定时--更新设备的在线状态】===>更新设备状态结果:【{}】",i);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
}
}
}

View File

@ -171,6 +171,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1) from et_device where hardware_version_id = #{hardwareVersionId} and area_id is null
</select>
<select id="selectAllDevice" resultType="com.ruoyi.system.domain.vo.AsDeviceVO" >
select mac, sn, online_status onlineStatus from et_device
</select>
<insert id="insertAsDevice" parameterType="AsDevice" useGeneratedKeys="true" keyProperty="deviceId">
insert into et_device
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -362,6 +366,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="sn != null">sn = #{sn},</if>
<if test="hardwareVersionId != null">hardware_version_id = #{hardwareVersionId},</if>
<if test="onlineStatus != null">online_status = #{onlineStatus},</if>
</trim>
where mac = #{mac}
</update>