宿州新版位置汇聚

ds-bozhou
luyya 2025-04-27 09:32:57 +08:00
parent 86666b8a04
commit a2115294cb
30 changed files with 787 additions and 42 deletions

View File

@ -89,12 +89,12 @@
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
<nacos.server>53.16.17.13:8848</nacos.server>
<nacos.server>10.129.128.114:8848</nacos.server>
<nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
<nacos.config.group>DEFAULT_GROUP</nacos.config.group>
<nacos.username>nacos</nacos.username>
<nacos.password>nacos</nacos.password>
<logstash.address>53.16.17.13:4560</logstash.address>
<logstash.address>10.129.128.114:4560</logstash.address>
</properties>
</profile>
</profiles>

View File

@ -40,6 +40,10 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
@ -51,6 +55,11 @@
<artifactId>jedis</artifactId>
<version>5.1.0</version>
</dependency>
<!-- Lettuce -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -49,10 +49,15 @@ import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADAT
public class RedisMetadataReport extends AbstractMetadataReport {
private static final String REDIS_DATABASE_KEY = "database";
private static final String SENTINEL_KEY = "sentinel";
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(RedisMetadataReport.class);
// protected , for test
protected JedisPool pool;
protected JedisSentinelPool sentinelPool;
private Set<HostAndPort> jedisClusterNodes;
private int timeout;
private String password;
@ -75,6 +80,14 @@ public class RedisMetadataReport extends AbstractMetadataReport {
for (URL tmpUrl : urls) {
jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
}
} else if (url.getParameter(SENTINEL_KEY,false)) {
Set<String> sentinels = new HashSet<>();
List<URL> urls = url.getBackupUrls();
for (URL tmpUrl : urls) {
sentinels.add(tmpUrl.getHost()+":"+ tmpUrl.getPort());
}
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
sentinelPool = new JedisSentinelPool("mymaster",sentinels ,new GenericObjectPoolConfig<>(), timeout, password, database);
} else {
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, password, database);
@ -128,11 +141,25 @@ public class RedisMetadataReport extends AbstractMetadataReport {
private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, String v) {
if (pool != null) {
storeMetadataStandalone(metadataIdentifier, v);
}else if(sentinelPool != null) {
storeMetadataInSentinel(metadataIdentifier, v);
} else {
storeMetadataInCluster(metadataIdentifier, v);
}
}
private void storeMetadataInSentinel(BaseMetadataIdentifier metadataIdentifier, String v) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
jedisSentinel.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), v, jedisParams);
} catch (Throwable e) {
String msg =
"Failed to put " + metadataIdentifier + " to redis cluster " + v + ", cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
}
private void storeMetadataInCluster(BaseMetadataIdentifier metadataIdentifier, String v) {
try (JedisCluster jedisCluster =
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
@ -158,11 +185,24 @@ public class RedisMetadataReport extends AbstractMetadataReport {
private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) {
if (pool != null) {
deleteMetadataStandalone(metadataIdentifier);
}else if(sentinelPool != null) {
deleteMetadataSentinel(metadataIdentifier);
} else {
deleteMetadataInCluster(metadataIdentifier);
}
}
private void deleteMetadataSentinel(BaseMetadataIdentifier metadataIdentifier) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
jedisSentinel.del(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
} catch (Throwable e) {
String msg = "Failed to delete " + metadataIdentifier + " from redis , cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
}
private void deleteMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
try (JedisCluster jedisCluster =
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
@ -187,11 +227,24 @@ public class RedisMetadataReport extends AbstractMetadataReport {
private String getMetadata(BaseMetadataIdentifier metadataIdentifier) {
if (pool != null) {
return getMetadataStandalone(metadataIdentifier);
}else if(sentinelPool != null) {
return getMetadataSentinel(metadataIdentifier);
} else {
return getMetadataInCluster(metadataIdentifier);
}
}
private String getMetadataSentinel(BaseMetadataIdentifier metadataIdentifier) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
return jedisSentinel.get(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
} catch (Throwable e) {
String msg = "Failed to get " + metadataIdentifier + " from redis , cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
}
private String getMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
try (JedisCluster jedisCluster =
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
@ -243,6 +296,8 @@ public class RedisMetadataReport extends AbstractMetadataReport {
private boolean storeMapping(String key, String field, String value, String ticket) {
if (pool != null) {
return storeMappingStandalone(key, field, value, ticket);
}else if(sentinelPool != null) {
return storeMappingSentinel(key, field, value, ticket);
} else {
return storeMappingInCluster(key, field, value, ticket);
}
@ -278,6 +333,33 @@ public class RedisMetadataReport extends AbstractMetadataReport {
return false;
}
/**
* use 'watch' to implement cas.
* Find information about slot distribution by key.
*/
private boolean storeMappingSentinel(String key, String field, String value, String ticket) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
jedisSentinel.watch(key);
String oldValue = jedisSentinel.hget(key, field);
if (null == oldValue || null == ticket || oldValue.equals(ticket)) {
Transaction transaction = jedisSentinel.multi();
transaction.hset(key, field, value);
List<Object> result = transaction.exec();
if (null != result) {
jedisSentinel.publish(buildPubSubKey(), field);
return true;
}
}
jedisSentinel.unwatch();
} catch (Throwable e) {
String msg = "Failed to put " + key + ":" + field + " to redis " + value + ", cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
return false;
}
/**
* use 'watch' to implement cas.
* Find information about slot distribution by key.
@ -339,6 +421,8 @@ public class RedisMetadataReport extends AbstractMetadataReport {
private String getMappingData(String key, String field) {
if (pool != null) {
return getMappingDataStandalone(key, field);
}else if(sentinelPool != null) {
return getMappingDataSentinel(key, field);
} else {
return getMappingDataInCluster(key, field);
}
@ -355,6 +439,17 @@ public class RedisMetadataReport extends AbstractMetadataReport {
}
}
private String getMappingDataSentinel(String key, String field) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
return jedisSentinel.hget(key, field);
} catch (Throwable e) {
String msg = "Failed to get " + key + ":" + field + " from redis , cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
}
private String getMappingDataStandalone(String key, String field) {
try (Jedis jedis = pool.getResource()) {
return jedis.hget(key, field);
@ -502,6 +597,14 @@ public class RedisMetadataReport extends AbstractMetadataReport {
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
} else if (sentinelPool != null) {
try (Jedis jedisSentinel = sentinelPool.getResource()) {
jedisSentinel.subscribe(notifySub, path);
} catch (Throwable e) {
String msg = "Failed to subscribe " + path + ", cause: " + e.getMessage();
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
throw new RpcException(msg, e);
}
} else {
try (JedisCluster jedisCluster = new JedisCluster(
jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {

View File

@ -23,15 +23,27 @@ dubbo:
address: redis://${spring.data.redis.host}:${spring.data.redis.port}
group: DUBBO_GROUP
username: dubbo
password: ${spring.data.redis.password}
password: ruoyi123
# 集群开关
cluster: false
sentinel: false
parameters:
namespace: ${spring.profiles.active}
database: ${spring.data.redis.database}
timeout: ${spring.data.redis.timeout}
# 集群地址 cluster 为 true 生效
backup: 127.0.0.1:6379,127.0.0.1:6381
backup: 10.129.128.116:26380,10.129.128.115:26380,10.129.128.114:26380
# metadata-report:
# address: redis://${spring.data.redis.host}:${spring.data.redis.port}
# group: DUBBO_GROUP
# username: dubbo
# password: ${spring.data.redis.password}
# # 集群开关
# cluster: false
# parameters:
# namespace: ${spring.profiles.active}
# database: ${spring.data.redis.database}
# timeout: ${spring.data.redis.timeout}
# # 集群地址 cluster 为 true 生效
# backup: 127.0.0.1:6379,127.0.0.1:6381
# 消费者相关配置
consumer:
# 结果缓存(LRU算法)
@ -43,3 +55,12 @@ dubbo:
retries: 0
# 初始化检查
check: false
logging:
level:
# 设置 Dubbo 核心包的日志级别为 DEBUG
org.apache.dubbo: DEBUG
# 如果需要更细粒度的调试,可指定元数据报告模块
org.apache.dubbo.metadata: DEBUG
# Redis 客户端日志(可选)
io.lettuce.core: WARN # 避免 Redis 连接日志过多

View File

@ -25,6 +25,7 @@ import org.springframework.core.task.VirtualThreadTaskExecutor;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.TimeZone;
/**
@ -94,6 +95,22 @@ public class RedisConfiguration {
.setReadMode(clusterServersConfig.getReadMode())
.setSubscriptionMode(clusterServersConfig.getSubscriptionMode());
}
// 哨兵模式
RedissonProperties.Sentinel sentinel = redissonProperties.getSentinel();
if (Objects.nonNull(sentinel)) {
config.useSentinelServers()
.setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix()))
.setTimeout(sentinel.getTimeout())
.setClientName(sentinel.getClientName())
.setIdleConnectionTimeout(sentinel.getIdleConnectionTimeout())
.setSubscriptionConnectionPoolSize(sentinel.getSubscriptionConnectionPoolSize())
.setMasterConnectionMinimumIdleSize(sentinel.getMasterConnectionMinimumIdleSize())
.setMasterConnectionPoolSize(sentinel.getMasterConnectionPoolSize())
.setSlaveConnectionMinimumIdleSize(sentinel.getSlaveConnectionMinimumIdleSize())
.setSlaveConnectionPoolSize(sentinel.getSlaveConnectionPoolSize())
.setReadMode(sentinel.getReadMode())
.setSubscriptionMode(sentinel.getSubscriptionMode());
}
log.info("初始化 redis 配置");
};
}

View File

@ -40,6 +40,8 @@ public class RedissonProperties {
*/
private ClusterServersConfig clusterServersConfig;
private Sentinel sentinel;
@Data
@NoArgsConstructor
public static class SingleServerConfig {
@ -132,4 +134,60 @@ public class RedissonProperties {
}
@Data
@NoArgsConstructor
public static class Sentinel {
/**
*
*/
private String clientName;
/**
* master
*/
private int masterConnectionMinimumIdleSize;
/**
* master
*/
private int masterConnectionPoolSize;
/**
* slave
*/
private int slaveConnectionMinimumIdleSize;
/**
* slave
*/
private int slaveConnectionPoolSize;
/**
*
*/
private int idleConnectionTimeout;
/**
*
*/
private int timeout;
/**
*
*/
private int subscriptionConnectionPoolSize;
/**
*
*/
private ReadMode readMode;
/**
*
*/
private SubscriptionMode subscriptionMode;
}
}

View File

@ -49,7 +49,7 @@ public class DataInsertBatchHandler implements CommandLineRunner {
log.info("batch size={}", list.size());
if(CollectionUtil.isNotEmpty(list)) {
gpsService.saveDataBatch(list);
storeDataService.saveDataByPersonTypeBatch(list);
// storeDataService.saveDataByPersonTypeBatch(list);
}
} catch (Exception e) {
log.error("缓存队列批量消费异常:{}", e.getMessage());

View File

@ -153,7 +153,7 @@ public class GpsServiceImpl implements IGpsService {
//地市版本没用批量插入
requestHandler.redisOnlineUser(info);
//发送到勤务
storeDataService.saveDataByPersonType(info);
// storeDataService.saveDataByPersonType(info);
CompletableFuture.allOf(esFuture);
EsGpsInfo esGpsInfo1 = esFuture.get();

View File

@ -1,25 +1,20 @@
package org.dromara.system.controller.system;
import cn.hutool.core.date.DateUtil;
import jdk.dynalink.linker.LinkerServices;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.DeviceRedis;
import org.dromara.system.domain.bo.SysDeptBo;
import org.dromara.system.domain.bo.TDeviceBo;
import org.dromara.system.domain.vo.DeviceStaticsVo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.domain.vo.SysDictDataVo;
import org.dromara.system.domain.vo.*;
import org.dromara.system.service.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@RequiredArgsConstructor
@RestController
@ -34,14 +29,50 @@ public class IndexStaticsController extends BaseController {
private final IDeviceRedisService redisService;
/*
* 线
* 线
* */
@PostMapping("/onlineCount")
public R onlineCount(TDeviceBo deviceInfo){
List<TDeviceVo> list = deviceService.queryList(deviceInfo);
String keys = "online_users:";
//List<String> strs = redisUtil.match(keys);
Date date = new Date();
Integer count = 0;
return R.ok(count);
}
/*
* 线
* */
@GetMapping("/topPan")
public R topPan(String zzjgdm){
public R topPan(){
DeviceRedis redis = new DeviceRedis();
redis.setZzjgdm(zzjgdm);
return R.ok(redisService.countByCondition(redis));
List<DeviceRedisVo> list = redisService.countByCondition(redis);
return R.ok(list);
}
/*
* Redis
* */
@RequestMapping("/serviceStatus")
public R serviceStatus(){
DeviceRedis redis = new DeviceRedis();
List<DeviceRedisVo> list = redisService.countByCondition(redis);
List<HashMap> maps = new ArrayList<>();
for (DeviceRedisVo redisVo : list) {
HashMap map = new HashMap();
Integer status = 1;
map.put("deviceType",redisVo.getDeviceType());
if (0 == redisVo.getOnline()){
status = 0;
}
map.put("status",status);
maps.add(map);
}
return R.ok(maps);
}
/*
@ -142,7 +173,47 @@ public class IndexStaticsController extends BaseController {
}
/*
*
* */
@PostMapping("/deviceTypePen")
public R deviceTypePen(TDeviceBo deviceInfo){
List<SysDictDataVo> dataList = dictTypeService.selectDictDataByType("zd_device_type");
List<HashMap> list = new ArrayList<>();
for (SysDictDataVo data : dataList) {
HashMap map = new HashMap();
deviceInfo.setDeviceType(data.getDictValue());
Long count = deviceService.countByCondition(deviceInfo);
map.put("name",data.getDictLabel());
map.put("value",count);
list.add(map);
}
return R.ok(list);
}
/*
*
* */
@PostMapping("/deviceBar")
public R deviceBar(TDeviceBo deviceInfo){
SysDeptBo dept = new SysDeptBo();
dept.setParentId(deviceInfo.getZzjgdm());
//dept.setIsStuck("1");
List<SysDeptVo> depts = deptService.selectDeptList(dept);
HashMap map = new HashMap();
List<String> names = new ArrayList<>();
List<Long> datas = new ArrayList<>();
for (SysDeptVo sysDept : depts) {
names.add(sysDept.getDeptName());
deviceInfo.setZzjgdm(sysDept.getDeptId());
Long count = deviceService.countByCondition(deviceInfo);
datas.add(count);
}
map.put("name",names);
map.put("data",datas);
return R.ok(map);
}
}

View File

@ -124,6 +124,12 @@ public class TDeviceController extends BaseController {
return toAjax(tDeviceService.updateByBo(bo));
}
@RequestMapping("/updateBatch")
public R<Void> updateBatch(@RequestBody TDeviceBo deviceInfo){
int num = tDeviceService.updateBatch(deviceInfo.getDeviceCode(),deviceInfo.getZzjgdm(),deviceInfo.getZzjgmc());
return toAjax(num);
}
/**
* device
*

View File

@ -14,7 +14,7 @@ public class DeviceRedisVo {
private String deviceType;
private String online;
// private String online;
private String zzjgdm;
@ -22,6 +22,6 @@ public class DeviceRedisVo {
private Integer co;
private Integer onlien;
private Integer online;
}

View File

@ -13,6 +13,7 @@ import org.dromara.system.domain.vo.TDeviceExportVo;
import org.dromara.system.domain.vo.TDeviceVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import java.util.HashMap;
import java.util.List;
/**
@ -35,4 +36,6 @@ public interface TDeviceMapper extends BaseMapperPlus<TDevice, TDeviceVo> {
})
Page<TDeviceVo> selectPageDevicetList(@Param("page") Page<TDevice> page, @Param(Constants.WRAPPER) Wrapper<TDevice> queryWrapper);
int updateBatch(HashMap<String,Object> map);
}

View File

@ -63,6 +63,8 @@ public interface ITDeviceService {
*/
Boolean updateByBo(TDeviceBo bo);
int updateBatch(String deviceCodes,String zzjgdm,String zzjgmc);
/**
* device
*

View File

@ -351,7 +351,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override
public List<SysDeptVo> deviceStatics(String deviceType,String manageDeptId) {
if(!manageDeptId.equals("341800000000")){
if(!manageDeptId.equals("341300000000")){
String subManageId = manageDeptId.substring(0,findLastNonZeroIndex(manageDeptId) + 1);
return baseMapper.deviceStaticsByDeptId(deviceType,subManageId);

View File

@ -1,5 +1,6 @@
package org.dromara.system.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -190,6 +191,16 @@ public class TDeviceServiceImpl implements ITDeviceService {
return baseMapper.updateById(update) > 0;
}
@Override
public int updateBatch(String deviceCodes, String zzjgdm, String zzjgmc) {
String[] ids = Convert.toStrArray(deviceCodes);
HashMap<String,Object> map = new HashMap<>();
map.put("zzjgdm",zzjgdm);
map.put("deviceCode",ids);
map.put("zzjgmc",zzjgmc);
return baseMapper.updateBatch(map);
}
/**
*
*/

View File

@ -24,7 +24,7 @@
<!-- 全省各类设备总数、在线数 -->
<select id="countByCondition" resultMap="deviceRedisResult">
SELECT d.dict_label type_name,dict_value,COALESCE(r.co,0) online,COALESCE(td.co,0) co from sys_dict_data d
SELECT d.dict_label type_name,dict_value device_type,COALESCE(r.co,0) online,COALESCE(td.co,0) co from sys_dict_data d
LEFT JOIN (
SELECT device_type,count(*) co FROM (
SELECT * FROM t_device_redis

View File

@ -34,4 +34,12 @@
${ew.getCustomSqlSegment}
</select>
<update id="updateBatch" parameterType="map">
update t_device set zzjgdm = #{zzjgdm},zzjgmc = #{zzjgmc}
where device_code in
<foreach item="deviceCode" collection="deviceCode" open="(" separator="," close=")">
#{deviceCode}
</foreach>
</update>
</mapper>

View File

@ -15,6 +15,7 @@ import org.dromara.extract.util.PathUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
@ -38,9 +39,13 @@ public class DeviceGPSController {
@DubboReference
RemoteDataToEsService dataToEsService;
@Value("${ruansi.start_update_time}")
private String startUpdateTime;
private String jlyUpdateTime;
private String lastUpdateTime = "2024-06-05 11:40:00";
@Value("${ruansi.last_update_time}")
private String lastUpdateTime;
@RequestMapping("/maxId")
public String getMaxId(){
@ -55,7 +60,7 @@ public class DeviceGPSController {
return DateUtil.formatDateTime(info.getGpsTime());
}
@Scheduled(cron = "0/30 * * * * ?")
@Scheduled(cron = "0/10 * * * * ?")
@Async
public void bdgcGps(){
if(StringUtils.isBlank(lastUpdateTime)){
@ -73,8 +78,8 @@ public class DeviceGPSController {
List<EsGpsInfo> list = deviceGpsService.selectBDGCGPS(gpsInfo);
Instant finish = Instant.now();
long timeElapsed = Duration.between(start, finish).toMillis();
logger.info("查询耗时:"+timeElapsed);
logger.info("数据大小size"+list.size());
logger.info("公车查询耗时:"+timeElapsed);
logger.info("公车数据大小size"+list.size());
Date nowDate = new Date();
for (int i = 0; i < list.size(); i++) {
@ -83,7 +88,7 @@ public class DeviceGPSController {
lastUpdateTime = DateUtil.formatDateTime(info.getGpsTime());
// resetUpdateTime(info.getId()+"");
}
if (DateUtil.between(nowDate,info.getGpsTime(),DateUnit.MINUTE) > 30){
if (DateUtil.between(new Date(),info.getGpsTime(),DateUnit.MINUTE) > 10){
info.setOnline("0");
}else {
info.setOnline("1");
@ -93,9 +98,7 @@ public class DeviceGPSController {
}
ArrayList<EsGpsInfo> collect = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(EsGpsInfo::getDeviceCode))), ArrayList::new));
logger.info("去重前size={},去重后size={}",list.size(),collect.size());
// List<RemoteGpsInfo> remoteGpsInfos = new ArrayList<>();
// remoteGpsInfos.add()
logger.info("公车去重前size={},公车去重后size={}",list.size(),collect.size());
dataToEsService.saveDataBatch(BeanUtil.copyToList(collect,RemoteGpsInfo.class));
Instant end = Instant.now();
long timeEnd = Duration.between(finish, end).toMillis();
@ -103,6 +106,60 @@ public class DeviceGPSController {
}
@Scheduled(cron = "0/8 * * * * ?")
@Async
public void jlyGps(){
if(StringUtils.isBlank(jlyUpdateTime)){
jlyUpdateTime = startUpdateTime;
}
EsGpsInfo gpsInfo = new EsGpsInfo();
gpsInfo.setGpsTime(DateUtil.parse(jlyUpdateTime));
logger.info("更新时间:"+jlyUpdateTime);
Instant start = Instant.now();
List<EsGpsInfo> list = deviceGpsService.selectJlyGPS(gpsInfo);
Instant finish = Instant.now();
long timeElapsed = Duration.between(start, finish).toMillis();
logger.info("查询耗时:"+timeElapsed);
logger.info("数据大小size"+list.size());
for (int i = 0; i < list.size(); i++) {
EsGpsInfo info = list.get(i);
if(i == 0){
jlyUpdateTime = DateUtil.format(info.getGpsTime(),"yyyy-MM-dd HH:mm:ss") ;
}
if (DateUtil.between(new Date(),info.getGpsTime(),DateUnit.MINUTE) > 5){
info.setOnline("0");
}else {
info.setOnline("1");
}
}
ArrayList<EsGpsInfo> collect = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(EsGpsInfo::getDeviceCode))), ArrayList::new));
dataToEsService.saveDataBatch(BeanUtil.copyToList(collect,RemoteGpsInfo.class));
Instant end = Instant.now();
long timeEnd = Duration.between(finish, end).toMillis();
logger.info("方法执行逻辑耗时:"+timeEnd);
}
@Scheduled(cron = "0/30 * * * * ?")
public void jlyGpsStatus(){
if(StringUtils.isBlank(jlyUpdateTime)){
jlyUpdateTime = startUpdateTime;
}
EsGpsInfo gpsInfo = new EsGpsInfo();
gpsInfo.setGpsTime(DateUtil.parse(jlyUpdateTime));
List<EsGpsInfo> list = deviceGpsService.selectJlyStatus(gpsInfo);
for (int i = 0; i < list.size(); i++) {
EsGpsInfo info = list.get(i);
if(i == 0){
jlyUpdateTime = DateUtil.format(info.getGpsTime(),"yyyy-MM-dd HH:mm:ss") ;
}
info.setGpsTime(null);
}
dataToEsService.updateOnlineStatusBatch(BeanUtil.copyToList(list,RemoteGpsInfo.class));
}
private void resetUpdateTime(String lastUpdateTime) {
try {

View File

@ -0,0 +1,144 @@
package org.dromara.extract.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
import java.util.Date;
/**
* <p>description: </p>
*
* @author luya
* @date 2021-10-12 16:10
*/
public class Device implements Serializable {
private static final long serialVersionUID = -25321078267627110L;
private Long id;
private String deviceCode;
private int deviceType;
private String zzjgdm;
private String zzjgmc;
private String policeNo;
private String policeName;
private String phoneNum;
private String carNum;
private String remark1;
private String remark2;
private int valid;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public int getDeviceType() {
return deviceType;
}
public void setDeviceType(int deviceType) {
this.deviceType = deviceType;
}
public String getZzjgdm() {
return zzjgdm;
}
public void setZzjgdm(String zzjgdm) {
this.zzjgdm = zzjgdm;
}
public String getZzjgmc() {
return zzjgmc;
}
public void setZzjgmc(String zzjgmc) {
this.zzjgmc = zzjgmc;
}
public String getPoliceNo() {
return policeNo;
}
public void setPoliceNo(String policeNo) {
this.policeNo = policeNo;
}
public String getPoliceName() {
return policeName;
}
public void setPoliceName(String policeName) {
this.policeName = policeName;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public String getCarNum() {
return carNum;
}
public void setCarNum(String carNum) {
this.carNum = carNum;
}
public String getRemark1() {
return remark1;
}
public void setRemark1(String remark1) {
this.remark1 = remark1;
}
public String getRemark2() {
return remark2;
}
public void setRemark2(String remark2) {
this.remark2 = remark2;
}
public int getValid() {
return valid;
}
public void setValid(int valid) {
this.valid = valid;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

View File

@ -14,6 +14,11 @@ public interface DeviceGpsMapper {
List<EsGpsInfo> selectBDGCGPS(EsGpsInfo esGpsInfo);
List<EsGpsInfo> selectJlyGPS(EsGpsInfo esGpsInfo);
List<EsGpsInfo> selectJlyStatus(EsGpsInfo esGpsInfo);
EsGpsInfo selectBDGCMaxTime();
}

View File

@ -0,0 +1,22 @@
package org.dromara.extract.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.extract.domain.Device;
import java.util.List;
@Mapper
public interface DeviceMapper {
List<Device> selectPDT(Device tDevice);
List<Device> selectYDJW(Device tDevice);
List<Device> selectBDGC(Device tDevice);
List<Device> selectJly(Device tDevice);
Device deviceByCode(String deviceCode);
}

View File

@ -0,0 +1,52 @@
package org.dromara.extract.schedule;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.extract.domain.Device;
import org.dromara.extract.service.IDeviceService;
import org.dromara.system.api.RemoteDeviceService;
import org.dromara.system.api.domain.bo.RemoteDeviceBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.List;
@Configuration
@Slf4j
/*
*
* */
public class JJDeviceSchedule {
@Autowired
IDeviceService deviceService;
@DubboReference
RemoteDeviceService remoteDeviceService;
@Value("${ruansi.start_jlyupdate_time}")
private String startUpdateTime;
private String lastUpdateTime = "";
@Scheduled(cron = "0 0/10 * * * ?")
public void saveORUpdateJly(){
if(StringUtils.isBlank(lastUpdateTime)){
lastUpdateTime = startUpdateTime;
}
Device device = new Device();
device.setUpdateTime(DateUtil.parse(lastUpdateTime));
List<Device> list = deviceService.selectJly(device);
remoteDeviceService.batchSaveDevice(BeanUtil.copyToList(list, RemoteDeviceBo.class));
if (list.size() != 0){
lastUpdateTime = DateUtil.format(list.get(0).getUpdateTime(),"yyyy-MM-dd HH:mm:ss") ;
}
}
}

View File

@ -0,0 +1,23 @@
package org.dromara.extract.service;
import org.dromara.extract.domain.Device;
import java.util.List;
public interface IDeviceService {
public List<Device> selectPDT(Device device);
List<Device> selectYDJW(Device tDevice);
List<Device> selectBDGC(Device tDevice);
List<Device> selectJly(Device tDevice);
Device deviceByCode(String deviceCode);
}

View File

@ -10,6 +10,10 @@ public interface ITDeviceGpsService {
List<EsGpsInfo> selectBDGCGPS(EsGpsInfo esGpsInfo);
List<EsGpsInfo> selectJlyGPS(EsGpsInfo esGpsInfo);
List<EsGpsInfo> selectJlyStatus(EsGpsInfo esGpsInfo);
EsGpsInfo selectBDGCMaxTime();
}

View File

@ -0,0 +1,44 @@
package org.dromara.extract.service.impl;
import org.dromara.extract.domain.Device;
import org.dromara.extract.mapper.DeviceMapper;
import org.dromara.extract.service.IDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DeviceServiceImpl implements IDeviceService {
@Autowired
DeviceMapper deviceMapper;
@Override
public List<Device> selectPDT(Device device) {
List<Device> list = deviceMapper.selectPDT(device);
return list;
}
@Override
public List<Device> selectYDJW(Device tDevice) {
return deviceMapper.selectYDJW(tDevice);
}
@Override
public List<Device> selectBDGC(Device tDevice) {
return deviceMapper.selectBDGC(tDevice);
}
@Override
public List<Device> selectJly(Device tDevice) {
return deviceMapper.selectJly(tDevice);
}
@Override
public Device deviceByCode(String deviceCode) {
return deviceMapper.deviceByCode(deviceCode);
}
}

View File

@ -2,6 +2,7 @@ package org.dromara.extract.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.dromara.extract.domain.EsGpsInfo;
import org.dromara.extract.mapper.DeviceGpsMapper;
import org.dromara.extract.service.ITDeviceGpsService;
@ -17,11 +18,22 @@ public class TDeviceGpsServiceImpl implements ITDeviceGpsService {
DeviceGpsMapper deviceMapper;
@DS("bdgc")
@Override
public List<EsGpsInfo> selectBDGCGPS(EsGpsInfo esGpsInfo) {
return deviceMapper.selectBDGCGPS(esGpsInfo);
}
@Override
public List<EsGpsInfo> selectJlyGPS(EsGpsInfo esGpsInfo) {
return deviceMapper.selectJlyGPS(esGpsInfo);
}
@Override
public List<EsGpsInfo> selectJlyStatus(EsGpsInfo esGpsInfo) {
return deviceMapper.selectJlyStatus(esGpsInfo);
}
@Override
public EsGpsInfo selectBDGCMaxTime() {
return deviceMapper.selectBDGCMaxTime();

View File

@ -36,13 +36,11 @@
</select>
<select id="selectBDGCGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult">
select id, deviceCode,deviceType,lng,lat, gpsTime, speed from (
select id, gpsid deviceCode,'2' deviceType, longitude lng, latitude lat, DATE_FORMAT(time,'%Y-%m-%d %H:%i:%s') gpsTime, speed speed from vehicle_trajectory
select terminalid deviceCode,'2' deviceType, lon lng, lat lat, gpstime gpsTime from car_gps_info
<where>
<if test="gpsTime != null "> and time > #{gpsTime}</if>
<if test="gpsTime != null "> and gpstime >= #{gpsTime}</if>
</where>
) a group by deviceCode
order by gpsTime desc limit 100
order by gpstime desc
</select>
<select id="selectBDGCMaxTime" resultMap="DeviceResult">
@ -50,6 +48,20 @@
order by time desc limit 1
</select>
<select id="selectJlyGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult">
select zdbh deviceCode,'5' deviceType, longitude lng, latitude lat,gpstime gpsTime,speed from bas_police_gps
<where>
<if test="gpsTime != null "> and gpstime >= #{gpsTime}</if>
</where>
order by gpstime desc
</select>
<select id="selectJlyStatus" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult">
select zdbh deviceCode,'5' deviceType,ifnull(zt,0) is_online,ztgxsj gpsTime from bas_device
<where>
<if test="gpsTime != null "> and ztgxsj >= #{gpsTime}</if>
</where>
order by ztgxsj desc
</select>
</mapper>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.extract.mapper.DeviceMapper">
<resultMap type="org.dromara.extract.domain.Device" id="DeviceRes">
<result property="id" column="id" />
<result property="deviceCode" column="device_code" />
<result property="deviceType" column="device_type" />
<result property="policeNo" column="policeNo" />
<result property="policeName" column="policeName" />
<result property="phoneNum" column="phoneNum" />
<result property="carNum" column="car_num" />
<result property="zzjgdm" column="zzjgdm" />
<result property="zzjgmc" column="zzjgmc" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="valid" column="valid" />
<result property="remark1" column="remark1" />
<result property="remark2" column="remark2" />
</resultMap>
<select id="selectPDT" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
select hh device_code,'3' device_type, zzjgdm, sjjg zzjgmc, creatime create_time, syr policeName, username policeNo, lxfs phoneNum from T_PDT_MESSAGE
<where>
yxx = '1'
<if test="createTime != null "> and creatime >= #{createTime}</if>
</where>
</select>
<select id="selectYDJW" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
select pnum device_code,'4' device_type, dept_code zzjgdm, department_detail zzjgmc, zhgxsj create_time, pname policeName,
pnum policeNo, phonenum phoneNum from v_user
<where>
<if test="createTime != null "> and zhgxsj >= #{createTime}</if>
</where>
</select>
<select id="selectBDGC" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
select gpsid device_code,'2' device_type, zzjgdm, remark2 zzjgmc,updatetime update_time, carno car_num from v_t_gc_sbxx
<where>
valid = '1'
<if test="updateTime != null "> and updatetime >= #{updateTime}</if>
</where>
</select>
<select id="selectJly" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
select zdbh device_code,'5' device_type,'341300250000' zzjgdm, '交通警察支队' zzjgmc,gxsj update_time, sbmc policeName,byzd4 policeNo from bas_device
<where>
<if test="updateTime != null "> and gxsj >= #{updateTime}</if>
</where>
order by gxsj desc
</select>
<select id="deviceByCode" parameterType="String" resultMap="DeviceRes">
select * from t_device where device_code = #{deviceCode}
</select>
</mapper>

View File

@ -12,7 +12,7 @@
<artifactId>wzhj-udp</artifactId>
<description>
wzhj-udp UDP数据接收服务
wzhj-udp 数据抽取服务
</description>
<dependencies>

View File

@ -132,8 +132,8 @@ public class DeviceSchedule {
}
if(Objects.isNull(one)){
// log.info("未找到该组织机构,civilCode={},civilCode + eqValue={}",civilCode,civilCode + eqValue);
newDevice.setZzjgdm("341800000000");
newDevice.setZzjgmc("宣城市公安局");
newDevice.setZzjgdm("341300000000");
newDevice.setZzjgmc("宿州市公安局");
return;
}