forked from dyf/fys-Multi-tenant
Compare commits
4 Commits
7b8c626cb6
...
62af38cbf0
| Author | SHA1 | Date | |
|---|---|---|---|
| 62af38cbf0 | |||
| 04a21567aa | |||
| 5b4fa38dbd | |||
| 2c3effa683 |
@ -3,6 +3,7 @@ package com.fuyuanshen;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
@ -10,6 +11,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DromaraApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@ -57,13 +57,12 @@ public class BjqAlarmRule implements MqttMessageRule {
|
||||
if (StringUtils.isNotBlank(convertValue)) {
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue);
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
if ("1".equals(convertValue)) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, "1");
|
||||
}else if ("0".equals(convertValue)){
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
RedisUtils.deleteObject(sendMessageIng);
|
||||
RedisUtils.deleteObject(deviceRedisKey);
|
||||
}
|
||||
|
||||
@ -56,7 +56,11 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
// Latitude, longitude
|
||||
String latitude = convertArr[1].toString();
|
||||
String longitude = convertArr[2].toString();
|
||||
|
||||
// 判断 latitude 和 longitude 是否都为 0
|
||||
if ("0".equals(latitude) && "0".equals(longitude)) {
|
||||
log.info("位置信息为0,不存储到Redis: device={}, lat={}, lon={}", context.getDeviceImei(), latitude, longitude);
|
||||
return;
|
||||
}
|
||||
// 异步发送经纬度到Redis
|
||||
asyncSendLocationToRedisWithFuture(context.getDeviceImei(), latitude, longitude);
|
||||
// 异步保存数据
|
||||
@ -122,6 +126,7 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// String[] latArr = latitude.split("\\.");
|
||||
// String[] lonArr = longitude.split("\\.");
|
||||
// // 将位置信息存储到Redis中
|
||||
|
||||
@ -17,10 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
@ -42,6 +39,12 @@ public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
|
||||
|
||||
// 三种等价的写法
|
||||
Integer[] array1 = list.toArray(new Integer[0]);
|
||||
Integer[] array2 = list.toArray(size -> new Integer[size]);
|
||||
|
||||
return XingHanCommandTypeConstants.XingHan_ESEND_MSG;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package com.fuyuanshen.global.queue;// ScheduledTasks.java
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
@Component
|
||||
public class OnlineStatusTask {
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
// 使用cron表达式,每分钟的第0秒执行
|
||||
@Scheduled(cron = "0 */3 * * * ?")
|
||||
public void cronTask() {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
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 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)){
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", item.getId());
|
||||
updateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -395,6 +395,10 @@ public class DeviceBizService {
|
||||
JSONObject jsonObject = JSONObject.parseObject(obj);
|
||||
Long timestamp = jsonObject.getLong("timestamp");
|
||||
LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate();
|
||||
String address = jsonObject.getString("address");
|
||||
if(StringUtils.isBlank( address) || "[]".equals(address)){
|
||||
continue;
|
||||
}
|
||||
if (map.containsKey(date.toString())) {
|
||||
map.get(date.toString()).add(jsonObject);
|
||||
} else {
|
||||
|
||||
@ -105,6 +105,7 @@ public class DeviceQueryCriteria extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 设备所属分组
|
||||
* group_id
|
||||
*/
|
||||
private Long groupId;
|
||||
|
||||
|
||||
@ -140,6 +140,9 @@
|
||||
<if test="criteria.deviceStatus != null">
|
||||
and d.device_status = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.groupId != null">
|
||||
and d.group_id = #{criteria.groupId}
|
||||
</if>
|
||||
<if test="criteria.currentOwnerId != null">
|
||||
and d.current_owner_id = #{criteria.currentOwnerId}
|
||||
</if>
|
||||
@ -274,6 +277,9 @@
|
||||
<if test="criteria.deviceImei != null and criteria.deviceImei != ''">
|
||||
and a.device_imei like concat('%',#{criteria.deviceImei}, '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null and criteria.deviceMac != ''">
|
||||
and a.device_mac like concat('%',#{criteria.deviceMac}, '%')
|
||||
</if>
|
||||
<if test="criteria.content != null and criteria.content != ''">
|
||||
AND (a.device_imei like concat('%',#{criteria.content}, '%') or a.device_mac like concat('%',#{criteria.content}, '%') )
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user