forked from dyf/fys-Multi-tenant
在线状态任务3
This commit is contained in:
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|||||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
import com.fuyuanshen.equipment.domain.Device;
|
import com.fuyuanshen.equipment.domain.Device;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.OnlineStatusVo;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -24,21 +25,16 @@ public class OnlineStatusTask {
|
|||||||
// 使用cron表达式,每分钟的第0秒执行
|
// 使用cron表达式,每分钟的第0秒执行
|
||||||
@Scheduled(cron = "0 */3 * * * ?")
|
@Scheduled(cron = "0 */3 * * * ?")
|
||||||
public void cronTask() {
|
public void cronTask() {
|
||||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
List<OnlineStatusVo> onlineStatusVos = deviceMapper.queryOnlineStatusList();
|
||||||
queryWrapper.eq("online_status", 1);
|
onlineStatusVos.forEach(item -> {
|
||||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
|
||||||
devices.forEach(item -> {
|
|
||||||
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||||
String status = RedisUtils.getCacheObject(onlineStatusKey);
|
String status = RedisUtils.getCacheObject(onlineStatusKey);
|
||||||
String onlineStatus = item.getOnlineStatus()==null?"0" : item.getOnlineStatus().toString();
|
|
||||||
if("1".equals(onlineStatus) || "2".equals(onlineStatus)){
|
|
||||||
if(StringUtils.isBlank(status) || "0".equals(status)){
|
if(StringUtils.isBlank(status) || "0".equals(status)){
|
||||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq("id", item.getId());
|
updateWrapper.eq("id", item.getId());
|
||||||
updateWrapper.set("online_status", 0);
|
updateWrapper.set("online_status", 0);
|
||||||
deviceMapper.update(updateWrapper);
|
deviceMapper.update(updateWrapper);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.fuyuanshen.equipment.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OnlineStatusVo implements Serializable {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线状态(0离线,1在线)
|
||||||
|
*/
|
||||||
|
private Integer onlineStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备imei
|
||||||
|
*/
|
||||||
|
private String deviceImei;
|
||||||
|
}
|
||||||
@ -135,4 +135,6 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
|||||||
* @return 设备使用频次统计列表
|
* @return 设备使用频次统计列表
|
||||||
*/
|
*/
|
||||||
List<DeviceUsageFrequencyVo> getDeviceUsageFrequency(@Param("days") int days);
|
List<DeviceUsageFrequencyVo> getDeviceUsageFrequency(@Param("days") int days);
|
||||||
|
|
||||||
|
List<OnlineStatusVo> queryOnlineStatusList();
|
||||||
}
|
}
|
||||||
@ -490,5 +490,9 @@
|
|||||||
FROM device
|
FROM device
|
||||||
WHERE device_imei = #{deviceImei}
|
WHERE device_imei = #{deviceImei}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="queryOnlineStatusList" resultType="com.fuyuanshen.equipment.domain.vo.OnlineStatusVo">
|
||||||
|
SELECT a.id, a.online_status AS onlineStatus, a.device_imei AS deviceImei
|
||||||
|
FROM device a left join device_type b on a.device_type = b.id where b.communication_mode in (0, 2) and a.online_status in (1,2)
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user