Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
91d4643d
提交
91d4643d
authored
5月 14, 2022
作者:
涂茂林
浏览文件
操作
浏览文件
下载
差异文件
合并分支 'merge_dev' 到 'dev_tml'
Merge dev 查看合并请求 chemical-kesai/kshg-api!23
上级
75be7cd2
d5618dce
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
30 个修改的文件
包含
418 行增加
和
132 行删除
+418
-132
Broadcast.java
.../main/java/com/yiring/app/domain/broadcast/Broadcast.java
+2
-4
District.java
...rc/main/java/com/yiring/app/domain/district/District.java
+1
-1
DistrictRepository.java
...va/com/yiring/app/domain/district/DistrictRepository.java
+9
-0
LocationBeacon.java
...n/java/com/yiring/app/domain/location/LocationBeacon.java
+1
-0
LocationFence.java
...in/java/com/yiring/app/domain/location/LocationFence.java
+8
-2
LocationFenceAlarm.java
...va/com/yiring/app/domain/location/LocationFenceAlarm.java
+92
-0
LocationFenceAlarmRepository.java
...ing/app/domain/location/LocationFenceAlarmRepository.java
+17
-0
LocationFenceRepository.java
...m/yiring/app/domain/location/LocationFenceRepository.java
+9
-0
LocationFenceRuleRepository.java
...ring/app/domain/location/LocationFenceRuleRepository.java
+1
-1
LocationLog.java
...main/java/com/yiring/app/domain/location/LocationLog.java
+6
-0
LocationTag.java
...main/java/com/yiring/app/domain/location/LocationTag.java
+1
-0
LocationTagRepository.java
...com/yiring/app/domain/location/LocationTagRepository.java
+1
-1
LocationTurnover.java
...java/com/yiring/app/domain/location/LocationTurnover.java
+76
-0
LocationTurnoverRepository.java
...iring/app/domain/location/LocationTurnoverRepository.java
+17
-0
AccidentSpot.java
...in/java/com/yiring/app/domain/rehearsal/AccidentSpot.java
+1
-1
EvacuationZone.java
.../java/com/yiring/app/domain/rehearsal/EvacuationZone.java
+1
-1
Video.java
app/src/main/java/com/yiring/app/domain/video/Video.java
+1
-0
MockPositionMessageJob.java
.../main/java/com/yiring/app/job/MockPositionMessageJob.java
+53
-16
MockZyRabbitConfig.java
...java/com/yiring/app/rabbit/config/MockZyRabbitConfig.java
+21
-11
RabbitConfig.java
.../main/java/com/yiring/app/rabbit/config/RabbitConfig.java
+0
-17
ZyConfigProperties.java
...java/com/yiring/app/rabbit/config/ZyConfigProperties.java
+1
-0
ZyRabbitConfig.java
...ain/java/com/yiring/app/rabbit/config/ZyRabbitConfig.java
+30
-34
PositionMessageHandler.java
...om/yiring/app/rabbit/receiver/PositionMessageHandler.java
+15
-28
PositionMessageService.java
...om/yiring/app/service/message/PositionMessageService.java
+1
-1
PositionMessageServiceImpl.java
.../app/service/message/impl/PositionMessageServiceImpl.java
+0
-0
GeoUtils.java
app/src/main/java/com/yiring/app/util/GeoUtils.java
+10
-7
LonLatUtil.java
app/src/main/java/com/yiring/app/util/zy/LonLatUtil.java
+3
-2
application-dev.yml
app/src/main/resources/application-dev.yml
+3
-3
TimesAspect.java
...l/src/main/java/com/yiring/common/aspect/TimesAspect.java
+2
-2
XxlJobAspect.java
.../src/main/java/com/yiring/common/aspect/XxlJobAspect.java
+35
-0
没有找到文件。
app/src/main/java/com/yiring/app/domain/broadcast/Broadcast.java
浏览文件 @
91d4643d
...
@@ -4,10 +4,7 @@ package com.yiring.app.domain.broadcast;
...
@@ -4,10 +4,7 @@ package com.yiring.app.domain.broadcast;
import
java.io.Serial
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
javax.persistence.Entity
;
import
javax.persistence.*
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
lombok.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.FieldNameConstants
;
...
@@ -52,6 +49,7 @@ public class Broadcast implements Serializable {
...
@@ -52,6 +49,7 @@ public class Broadcast implements Serializable {
String
broadcastName
;
String
broadcastName
;
@Comment
(
"坐标点信息"
)
@Comment
(
"坐标点信息"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
Point
point
;
@Comment
(
"播报设备地址"
)
@Comment
(
"播报设备地址"
)
...
...
app/src/main/java/com/yiring/app/domain/district/District.java
浏览文件 @
91d4643d
...
@@ -59,7 +59,7 @@ public class District implements Serializable {
...
@@ -59,7 +59,7 @@ public class District implements Serializable {
@Comment
(
"区域信息"
)
@Comment
(
"区域信息"
)
@Type
(
type
=
"jts_geometry"
)
@Type
(
type
=
"jts_geometry"
)
@Column
(
columnDefinition
=
"geometry"
)
@Column
(
columnDefinition
=
"geometry
(Geometry,4326)
"
)
private
Geometry
geometry
;
private
Geometry
geometry
;
@Comment
(
"创建时间"
)
@Comment
(
"创建时间"
)
...
...
app/src/main/java/com/yiring/app/domain/district/DistrictRepository.java
浏览文件 @
91d4643d
...
@@ -3,6 +3,7 @@ package com.yiring.app.domain.district;
...
@@ -3,6 +3,7 @@ package com.yiring.app.domain.district;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
org.locationtech.jts.geom.Geometry
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
...
@@ -36,4 +37,12 @@ public interface DistrictRepository extends JpaRepository<District, Serializable
...
@@ -36,4 +37,12 @@ public interface DistrictRepository extends JpaRepository<District, Serializable
*/
*/
@Query
(
"SELECT d FROM District d WHERE d.name like %?1%"
)
@Query
(
"SELECT d FROM District d WHERE d.name like %?1%"
)
List
<
District
>
findLikeName
(
String
name
);
List
<
District
>
findLikeName
(
String
name
);
/**
* 查询空间信息在区域内的区域信息
* @param geometry 空间信息
* @return 区域信息
*/
@Query
(
value
=
"select d.* from bs_district d where st_contains(d.geometry, :geometry)"
,
nativeQuery
=
true
)
List
<
District
>
findByGeometryContains
(
Geometry
geometry
);
}
}
app/src/main/java/com/yiring/app/domain/location/LocationBeacon.java
浏览文件 @
91d4643d
...
@@ -80,6 +80,7 @@ public class LocationBeacon extends BasicEntity implements Serializable {
...
@@ -80,6 +80,7 @@ public class LocationBeacon extends BasicEntity implements Serializable {
Double
distance
;
Double
distance
;
@Comment
(
"坐标点信息"
)
@Comment
(
"坐标点信息"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
Point
point
;
@FieldMapping
@FieldMapping
...
...
app/src/main/java/com/yiring/app/domain/location/LocationFence.java
浏览文件 @
91d4643d
...
@@ -51,7 +51,7 @@ public class LocationFence extends BasicEntity implements Serializable {
...
@@ -51,7 +51,7 @@ public class LocationFence extends BasicEntity implements Serializable {
private
String
mapName
;
private
String
mapName
;
@Comment
(
"摄像头"
)
@Comment
(
"摄像头"
)
@ManyToOne
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
@JoinColumn
(
name
=
"video_id"
)
@JoinColumn
(
name
=
"video_id"
)
private
Video
video
;
private
Video
video
;
...
@@ -60,7 +60,7 @@ public class LocationFence extends BasicEntity implements Serializable {
...
@@ -60,7 +60,7 @@ public class LocationFence extends BasicEntity implements Serializable {
@Comment
(
"空间信息"
)
@Comment
(
"空间信息"
)
@Type
(
type
=
"jts_geometry"
)
@Type
(
type
=
"jts_geometry"
)
@Column
(
columnDefinition
=
"geometry"
)
@Column
(
columnDefinition
=
"geometry
(Geometry,4326)
"
)
private
Geometry
geometry
;
private
Geometry
geometry
;
@Comment
(
"滞留时间(秒)"
)
@Comment
(
"滞留时间(秒)"
)
...
@@ -87,6 +87,12 @@ public class LocationFence extends BasicEntity implements Serializable {
...
@@ -87,6 +87,12 @@ public class LocationFence extends BasicEntity implements Serializable {
@OneToMany
(
mappedBy
=
"fence"
)
@OneToMany
(
mappedBy
=
"fence"
)
@ToString
.
Exclude
@ToString
.
Exclude
private
Set
<
LocationFenceRule
>
rules
=
new
HashSet
<>(
0
);
private
Set
<
LocationFenceRule
>
rules
=
new
HashSet
<>(
0
);
@ToString
.
Exclude
@Comment
(
"围栏中的标签集合"
)
@Builder
.
Default
@ManyToMany
(
fetch
=
FetchType
.
LAZY
)
Set
<
LocationTag
>
tags
=
new
HashSet
<>(
0
);
/*@SuppressWarnings({ "unused" })
/*@SuppressWarnings({ "unused" })
public enum Mode {
public enum Mode {
NORMAL("常规区域"),
NORMAL("常规区域"),
...
...
app/src/main/java/com/yiring/app/domain/location/LocationFenceAlarm.java
0 → 100644
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
import
com.yiring.app.domain.alarm.AlarmType
;
import
com.yiring.auth.domain.user.User
;
import
com.yiring.common.domain.BasicEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotations.Comment
;
import
org.locationtech.jts.geom.Point
;
/**
* 围栏报警记录
*
* @author Jim
* @version 0.1
* 2022/5/12 21:33
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Entity
@Table
(
name
=
"BS_LOCATION_FENCE_ALARM"
)
@Comment
(
"围栏报警记录"
)
public
class
LocationFenceAlarm
extends
BasicEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
2984248537199016912L
;
@Comment
(
"围栏"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
LocationFence
fence
;
@Comment
(
"触警位置"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
@Comment
(
"地图编号"
)
Long
areaId
;
@Comment
(
"触警人员"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
User
user
;
@Comment
(
"触警标签"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
LocationTag
tag
;
@Comment
(
"报警开始时间"
)
LocalDateTime
startTime
;
@Comment
(
"报警结束时间"
)
LocalDateTime
endTime
;
@Comment
(
"报警类型"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
AlarmType
type
;
@Comment
(
"状态"
)
@Enumerated
(
EnumType
.
STRING
)
Status
status
;
// 推送记录集合(含接收状态)
// TODO
@SuppressWarnings
({
"unused"
})
public
enum
Status
{
ING
(
"进行中"
),
OVER
(
"结束"
);
final
String
text
;
Status
(
String
text
)
{
this
.
text
=
text
;
}
public
String
text
()
{
return
this
.
text
;
}
}
}
app/src/main/java/com/yiring/app/domain/location/LocationFenceAlarmRepository.java
0 → 100644
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
import
java.io.Serializable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
/**
* @author Jim
* @version 0.1
* 2022/5/12 21:34
*/
@Repository
public
interface
LocationFenceAlarmRepository
extends
JpaRepository
<
LocationFenceAlarm
,
Serializable
>,
JpaSpecificationExecutor
<
LocationFenceAlarm
>
{}
app/src/main/java/com/yiring/app/domain/location/LocationFenceRepository.java
浏览文件 @
91d4643d
...
@@ -3,6 +3,7 @@ package com.yiring.app.domain.location;
...
@@ -3,6 +3,7 @@ package com.yiring.app.domain.location;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
org.locationtech.jts.geom.Geometry
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
...
@@ -37,4 +38,12 @@ public interface LocationFenceRepository
...
@@ -37,4 +38,12 @@ public interface LocationFenceRepository
*/
*/
@Query
(
"SELECT f FROM LocationFence f WHERE name like %?1% AND deleted = false"
)
@Query
(
"SELECT f FROM LocationFence f WHERE name like %?1% AND deleted = false"
)
List
<
LocationFence
>
findLikeName
(
String
name
);
List
<
LocationFence
>
findLikeName
(
String
name
);
/**
* 查询空间信息在围栏内的围栏信息
* @param geometry 空间信息
* @return 围栏信息
*/
@Query
(
value
=
"select f.* from bs_location_fence f where st_contains(f.geometry, :geometry)"
,
nativeQuery
=
true
)
List
<
LocationFence
>
findByGeometryContains
(
Geometry
geometry
);
}
}
app/src/main/java/com/yiring/app/domain/location/LocationFenceRuleRepository.java
浏览文件 @
91d4643d
...
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
...
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
/**
/**
* @author tml
* @author tml
* @version 1.0
* @version 1.0
*
@date
2022/4/29 11:40
* 2022/4/29 11:40
*/
*/
@Repository
@Repository
public
interface
LocationFenceRuleRepository
public
interface
LocationFenceRuleRepository
...
...
app/src/main/java/com/yiring/app/domain/location/LocationLog.java
浏览文件 @
91d4643d
...
@@ -71,6 +71,7 @@ public class LocationLog implements Serializable {
...
@@ -71,6 +71,7 @@ public class LocationLog implements Serializable {
User
.
Status
status
;
User
.
Status
status
;
@Comment
(
"坐标点信息"
)
@Comment
(
"坐标点信息"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
Point
point
;
@Comment
(
"信标集合"
)
@Comment
(
"信标集合"
)
...
@@ -83,6 +84,11 @@ public class LocationLog implements Serializable {
...
@@ -83,6 +84,11 @@ public class LocationLog implements Serializable {
@Column
(
columnDefinition
=
"jsonb"
)
@Column
(
columnDefinition
=
"jsonb"
)
JSONArray
fences
;
JSONArray
fences
;
@Comment
(
"区域集合"
)
@Type
(
type
=
"jsonb"
)
@Column
(
columnDefinition
=
"jsonb"
)
JSONArray
districts
;
@Comment
(
"静止/运动"
)
@Comment
(
"静止/运动"
)
Boolean
silent
;
Boolean
silent
;
...
...
app/src/main/java/com/yiring/app/domain/location/LocationTag.java
浏览文件 @
91d4643d
...
@@ -103,6 +103,7 @@ public class LocationTag extends BasicEntity implements Serializable {
...
@@ -103,6 +103,7 @@ public class LocationTag extends BasicEntity implements Serializable {
Integer
category
;
Integer
category
;
@Comment
(
"最后定位坐标"
)
@Comment
(
"最后定位坐标"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
Point
point
;
@SuppressWarnings
({
"unused"
})
@SuppressWarnings
({
"unused"
})
...
...
app/src/main/java/com/yiring/app/domain/location/LocationTagRepository.java
浏览文件 @
91d4643d
...
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository;
...
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository;
/**
/**
* 定位标签JPA
* 定位标签JPA
* @author LJ-2204
* @author LJ-2204
*
@date
2022/4/14
* 2022/4/14
*/
*/
@Repository
@Repository
...
...
app/src/main/java/com/yiring/app/domain/location/LocationTurnover.java
0 → 100644
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
import
com.vladmihalcea.hibernate.type.json.JsonBinaryType
;
import
com.yiring.common.domain.BasicEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.TypeDef
;
/**
* 定位进出记录
*
* @author Jim
* @version 0.1
* 2022/5/12 17:54
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Entity
@TypeDef
(
name
=
"jsonb"
,
typeClass
=
JsonBinaryType
.
class
)
@Table
(
name
=
"BS_LOCATION_TURNOVER"
,
indexes
=
{
@Index
(
columnList
=
"type"
),
@Index
(
columnList
=
"sourceId"
)
})
@Comment
(
"定位进出记录"
)
public
class
LocationTurnover
extends
BasicEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
887764448464587364L
;
@Comment
(
"进出区域/围栏表主键"
)
Long
sourceId
;
@Comment
(
"类型"
)
@Enumerated
(
EnumType
.
STRING
)
Type
type
;
@Comment
(
"定位标签"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
LocationTag
tag
;
@Comment
(
"定位时间"
)
LocalDateTime
time
;
@Comment
(
"进入"
)
Boolean
enter
;
@Comment
(
"是否为最新状态"
)
Boolean
isLatest
;
@SuppressWarnings
({
"unused"
})
public
enum
Type
{
FENCE
(
"围栏"
),
DISTRICT
(
"区域"
);
final
String
text
;
Type
(
String
text
)
{
this
.
text
=
text
;
}
public
String
text
()
{
return
this
.
text
;
}
}
}
app/src/main/java/com/yiring/app/domain/location/LocationTurnoverRepository.java
0 → 100644
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
import
java.io.Serializable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
/**
* @author Jim
* @version 0.1
* 2022/5/12 18:13
*/
@Repository
public
interface
LocationTurnoverRepository
extends
JpaRepository
<
LocationTurnover
,
Serializable
>,
JpaSpecificationExecutor
<
LocationTurnover
>
{}
app/src/main/java/com/yiring/app/domain/rehearsal/AccidentSpot.java
浏览文件 @
91d4643d
...
@@ -48,7 +48,7 @@ public class AccidentSpot extends BasicEntity implements Serializable {
...
@@ -48,7 +48,7 @@ public class AccidentSpot extends BasicEntity implements Serializable {
@Comment
(
"空间信息"
)
@Comment
(
"空间信息"
)
@Type
(
type
=
"jts_geometry"
)
@Type
(
type
=
"jts_geometry"
)
@Column
(
columnDefinition
=
"geometry"
)
@Column
(
columnDefinition
=
"geometry
(Geometry,4326)
"
)
private
Geometry
geometry
;
private
Geometry
geometry
;
@Comment
(
"摄像头"
)
@Comment
(
"摄像头"
)
...
...
app/src/main/java/com/yiring/app/domain/rehearsal/EvacuationZone.java
浏览文件 @
91d4643d
...
@@ -48,7 +48,7 @@ public class EvacuationZone extends BasicEntity implements Serializable {
...
@@ -48,7 +48,7 @@ public class EvacuationZone extends BasicEntity implements Serializable {
@Comment
(
"空间信息"
)
@Comment
(
"空间信息"
)
@Type
(
type
=
"jts_geometry"
)
@Type
(
type
=
"jts_geometry"
)
@Column
(
columnDefinition
=
"geometry"
)
@Column
(
columnDefinition
=
"geometry
(Geometry,4326)
"
)
private
Geometry
geometry
;
private
Geometry
geometry
;
@Comment
(
"摄像头"
)
@Comment
(
"摄像头"
)
...
...
app/src/main/java/com/yiring/app/domain/video/Video.java
浏览文件 @
91d4643d
...
@@ -44,6 +44,7 @@ public class Video implements Serializable {
...
@@ -44,6 +44,7 @@ public class Video implements Serializable {
Long
id
;
Long
id
;
@Comment
(
"坐标点信息"
)
@Comment
(
"坐标点信息"
)
@Column
(
columnDefinition
=
"geometry(Point,4326)"
)
Point
point
;
Point
point
;
@Comment
(
"标识"
)
@Comment
(
"标识"
)
...
...
app/src/main/java/com/yiring/app/job/Mock
Zy
MessageJob.java
→
app/src/main/java/com/yiring/app/job/Mock
Position
MessageJob.java
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
job
;
package
com
.
yiring
.
app
.
job
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xxl.job.core.context.XxlJobHelper
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
com.yiring.app.domain.location.LocationLog
;
import
com.yiring.app.domain.location.LocationLog
;
import
com.yiring.app.domain.location.LocationLogRepository
;
import
com.yiring.app.domain.location.LocationLogRepository
;
import
com.yiring.app.rabbit.config.Zy
RabbitConfig
;
import
com.yiring.app.rabbit.config.Zy
ConfigProperties
;
import
com.yiring.app.util.GeoUtils
;
import
com.yiring.app.util.GeoUtils
;
import
com.yiring.common.constant.DateFormatter
;
import
com.yiring.common.constant.DateFormatter
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -29,7 +31,7 @@ import org.springframework.stereotype.Component;
...
@@ -29,7 +31,7 @@ import org.springframework.stereotype.Component;
@SuppressWarnings
(
"unused"
)
@SuppressWarnings
(
"unused"
)
@Slf4j
@Slf4j
@Component
@Component
public
class
Mock
Zy
MessageJob
{
public
class
Mock
Position
MessageJob
{
@Resource
@Resource
RabbitTemplate
rabbitTemplate
;
RabbitTemplate
rabbitTemplate
;
...
@@ -37,19 +39,36 @@ public class MockZyMessageJob {
...
@@ -37,19 +39,36 @@ public class MockZyMessageJob {
@Resource
@Resource
LocationLogRepository
locationLogRepository
;
LocationLogRepository
locationLogRepository
;
@XxlJob
(
"MockZyMessageHandler"
)
@Resource
public
void
mockMessageHandler
()
{
ZyConfigProperties
.
ZyConfigRabbitmq
rabbitmq
;
log
.
info
(
"MockZyMessageHandler: {}"
,
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
));
@XxlJob
(
"MockPositionHandler"
)
public
void
MockPositionHandler
()
{
JSONObject
extra
=
toJSON
(
XxlJobHelper
.
getJobParam
());
log
.
info
(
"[Mock] Position: {}, {}"
,
mockPositionMessage
(
extra
),
extra
);
}
@XxlJob
(
"MockLowPowerHandler"
)
public
void
MockLowPowerHandler
()
{
JSONObject
extra
=
toJSON
(
XxlJobHelper
.
getJobParam
());
log
.
info
(
"[Mock] LowPower: {}, {}"
,
mockLowPowerMessage
(
extra
),
extra
);
}
@XxlJob
(
"MockDeviceStatusHandler"
)
public
void
MockDeviceStatusHandler
()
{
JSONObject
extra
=
toJSON
(
XxlJobHelper
.
getJobParam
());
log
.
info
(
"[Mock] DeviceStatus: {}, {}"
,
mockDeviceStatusMessage
(
extra
),
extra
);
}
log
.
info
(
"[Mock] Position: {}"
,
mockPositionMessage
());
@XxlJob
(
"MockKeyWarningHandler"
)
log
.
info
(
"[Mock] LowPower: {}"
,
mockLowPowerMessage
());
public
void
MockKeyWarningHandler
()
{
log
.
info
(
"[Mock] DeviceStatus: {}"
,
mockDeviceStatusMessage
());
JSONObject
extra
=
toJSON
(
XxlJobHelper
.
getJobParam
());
log
.
info
(
"[Mock] KeyWarning: {}
"
,
mockKeyWarningMessage
()
);
log
.
info
(
"[Mock] KeyWarning: {}
, {}"
,
mockKeyWarningMessage
(
extra
),
extra
);
}
}
@XxlJob
(
"QueryMessageHandler"
)
@XxlJob
(
"QueryMessageHandler"
)
public
void
queryMessageHandler
()
{
public
void
queryMessageHandler
()
{
log
.
info
(
"Query
Zy
MessageHandler: {}"
,
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
));
log
.
info
(
"QueryMessageHandler: {}"
,
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
));
try
{
try
{
Specification
<
LocationLog
>
spec
=
(
root
,
query
,
cb
)
->
{
Specification
<
LocationLog
>
spec
=
(
root
,
query
,
cb
)
->
{
...
@@ -59,17 +78,31 @@ public class MockZyMessageJob {
...
@@ -59,17 +78,31 @@ public class MockZyMessageJob {
};
};
List
<
LocationLog
>
logs
=
locationLogRepository
.
findAll
(
spec
);
List
<
LocationLog
>
logs
=
locationLogRepository
.
findAll
(
spec
);
log
.
info
(
"
QueryZyMessageHandler
: {}"
,
logs
.
size
());
log
.
info
(
"
log size
: {}"
,
logs
.
size
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
public
JSONObject
send
(
JSONObject
body
)
{
public
JSONObject
send
(
JSONObject
body
)
{
rabbitTemplate
.
convertAndSend
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
,
body
.
toJSONString
());
if
(
rabbitmq
.
isMock
())
{
rabbitTemplate
.
convertAndSend
(
rabbitmq
.
getQueueName
(),
body
.
toJSONString
());
}
return
body
;
return
body
;
}
}
public
JSONObject
toJSON
(
String
params
)
{
JSONObject
extra
=
new
JSONObject
();
try
{
extra
=
JSON
.
parseObject
(
params
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
extra
==
null
?
new
JSONObject
()
:
extra
;
}
private
String
mockTag
()
{
private
String
mockTag
()
{
return
"BTT33333331"
;
return
"BTT33333331"
;
}
}
...
@@ -78,7 +111,7 @@ public class MockZyMessageJob {
...
@@ -78,7 +111,7 @@ public class MockZyMessageJob {
return
10019L
;
return
10019L
;
}
}
private
JSONObject
mockPositionMessage
()
{
private
JSONObject
mockPositionMessage
(
JSONObject
extra
)
{
// 随机生成一个坐标点
// 随机生成一个坐标点
Point
point
=
GeoUtils
.
randomPoint
(
GeoUtils
.
defaultBounds
(),
0
);
Point
point
=
GeoUtils
.
randomPoint
(
GeoUtils
.
defaultBounds
(),
0
);
...
@@ -95,6 +128,7 @@ public class MockZyMessageJob {
...
@@ -95,6 +128,7 @@ public class MockZyMessageJob {
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"voltUnit"
,
"mV"
);
params
.
put
(
"voltUnit"
,
"mV"
);
params
.
put
(
"floor"
,
1
);
params
.
put
(
"floor"
,
1
);
params
.
putAll
(
extra
);
JSONObject
body
=
new
JSONObject
();
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"position"
);
body
.
put
(
"method"
,
"position"
);
...
@@ -102,11 +136,12 @@ public class MockZyMessageJob {
...
@@ -102,11 +136,12 @@ public class MockZyMessageJob {
return
send
(
body
);
return
send
(
body
);
}
}
private
JSONObject
mockLowPowerMessage
()
{
private
JSONObject
mockLowPowerMessage
(
JSONObject
extra
)
{
JSONObject
params
=
new
JSONObject
();
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"voltUnit"
,
"mV"
);
params
.
put
(
"voltUnit"
,
"mV"
);
params
.
putAll
(
extra
);
JSONObject
body
=
new
JSONObject
();
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"lowPower"
);
body
.
put
(
"method"
,
"lowPower"
);
...
@@ -114,7 +149,7 @@ public class MockZyMessageJob {
...
@@ -114,7 +149,7 @@ public class MockZyMessageJob {
return
send
(
body
);
return
send
(
body
);
}
}
private
JSONObject
mockDeviceStatusMessage
()
{
private
JSONObject
mockDeviceStatusMessage
(
JSONObject
extra
)
{
JSONObject
params
=
new
JSONObject
();
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"deviceId"
,
mockTag
());
params
.
put
(
"deviceId"
,
mockTag
());
params
.
put
(
"areaId"
,
mockAreaId
());
params
.
put
(
"areaId"
,
mockAreaId
());
...
@@ -122,6 +157,7 @@ public class MockZyMessageJob {
...
@@ -122,6 +157,7 @@ public class MockZyMessageJob {
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"field_21"
,
"mV"
);
params
.
put
(
"field_21"
,
"mV"
);
params
.
put
(
"updateTime"
,
System
.
currentTimeMillis
());
params
.
put
(
"updateTime"
,
System
.
currentTimeMillis
());
params
.
putAll
(
extra
);
JSONObject
body
=
new
JSONObject
();
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"deviceStatus"
);
body
.
put
(
"method"
,
"deviceStatus"
);
...
@@ -129,7 +165,7 @@ public class MockZyMessageJob {
...
@@ -129,7 +165,7 @@ public class MockZyMessageJob {
return
send
(
body
);
return
send
(
body
);
}
}
private
JSONObject
mockKeyWarningMessage
()
{
private
JSONObject
mockKeyWarningMessage
(
JSONObject
extra
)
{
JSONObject
params
=
new
JSONObject
();
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"entityId"
,
"1522770547178475520"
);
params
.
put
(
"entityId"
,
"1522770547178475520"
);
...
@@ -139,6 +175,7 @@ public class MockZyMessageJob {
...
@@ -139,6 +175,7 @@ public class MockZyMessageJob {
params
.
put
(
"y"
,
100
);
params
.
put
(
"y"
,
100
);
params
.
put
(
"z"
,
0
);
params
.
put
(
"z"
,
0
);
params
.
put
(
"floor"
,
1
);
params
.
put
(
"floor"
,
1
);
params
.
putAll
(
extra
);
JSONObject
body
=
new
JSONObject
();
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"keyWarning"
);
body
.
put
(
"method"
,
"keyWarning"
);
...
...
app/src/main/java/com/yiring/app/rabbit/config/MockZyRabbitConfig.java
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
rabbit
.
config
;
package
com
.
yiring
.
app
.
rabbit
.
config
;
import
org.springframework.amqp.core.Binding
;
import
com.yiring.app.rabbit.receiver.PositionMessageHandler
;
import
org.springframework.amqp.core.BindingBuilder
;
import
javax.annotation.Resource
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.core.*
;
import
org.springframework.amqp.core.TopicExchange
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -16,8 +18,12 @@ import org.springframework.context.annotation.Configuration;
...
@@ -16,8 +18,12 @@ import org.springframework.context.annotation.Configuration;
* 2019/8/21 15:44
* 2019/8/21 15:44
*/
*/
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"zy-config.rabbitmq"
,
value
=
"mock"
,
havingValue
=
"true"
)
public
class
MockZyRabbitConfig
{
public
class
MockZyRabbitConfig
{
@Resource
ZyConfigProperties
.
ZyConfigRabbitmq
rabbitmq
;
/**
/**
* 消息交换机
* 消息交换机
*/
*/
...
@@ -33,16 +39,20 @@ public class MockZyRabbitConfig {
...
@@ -33,16 +39,20 @@ public class MockZyRabbitConfig {
return
new
TopicExchange
(
ZY_TOPIC_EXCHANGE
,
true
,
false
);
return
new
TopicExchange
(
ZY_TOPIC_EXCHANGE
,
true
,
false
);
}
}
@Bean
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
)
public
Queue
mockMessageQueue
()
{
return
new
Queue
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
,
true
,
false
,
false
);
}
@Bean
@Bean
Binding
bindingExchangeMock
(
Binding
bindingExchangeMock
(
@Qualifier
(
ZyRabbitConfig
.
MESSAGE_QUEUES
_NAME
)
Queue
queue
,
@Qualifier
(
ZyRabbitConfig
.
QUEUE_BEAN
_NAME
)
Queue
queue
,
@Qualifier
(
ZY_TOPIC_EXCHANGE
)
TopicExchange
exchange
@Qualifier
(
ZY_TOPIC_EXCHANGE
)
TopicExchange
exchange
)
{
)
{
return
BindingBuilder
.
bind
(
queue
).
to
(
exchange
).
with
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
);
return
BindingBuilder
.
bind
(
queue
).
to
(
exchange
).
with
(
rabbitmq
.
getQueueName
());
}
@Bean
(
ZyRabbitConfig
.
LISTENER_CONTAINER_NAME
)
public
SimpleMessageListenerContainer
simpleMessageListenerContainer
(
PositionMessageHandler
handler
,
@Qualifier
(
ZyRabbitConfig
.
QUEUE_BEAN_NAME
)
Queue
queue
,
@Qualifier
(
RabbitConfig
.
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
return
ZyRabbitConfig
.
buildPositionMessageListenerContainer
(
handler
,
queue
,
connectionFactory
);
}
}
}
}
app/src/main/java/com/yiring/app/rabbit/config/RabbitConfig.java
浏览文件 @
91d4643d
...
@@ -2,15 +2,11 @@
...
@@ -2,15 +2,11 @@
package
com
.
yiring
.
app
.
rabbit
.
config
;
package
com
.
yiring
.
app
.
rabbit
.
config
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
org.springframework.amqp.core.AcknowledgeMode
;
import
org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
;
import
org.springframework.amqp.rabbit.connection.CachingConnectionFactory
;
import
org.springframework.amqp.rabbit.connection.CachingConnectionFactory
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.amqp.RabbitProperties
;
import
org.springframework.boot.autoconfigure.amqp.RabbitProperties
;
import
org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
...
@@ -43,19 +39,6 @@ public class RabbitConfig {
...
@@ -43,19 +39,6 @@ public class RabbitConfig {
@Bean
@Bean
@Primary
@Primary
public
RabbitListenerContainerFactory
<?>
rabbitListenerContainerFactory
(
SimpleRabbitListenerContainerFactoryConfigurer
configurer
,
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
SimpleRabbitListenerContainerFactory
factory
=
new
SimpleRabbitListenerContainerFactory
();
// 手动确认消息模式
factory
.
setAcknowledgeMode
(
AcknowledgeMode
.
MANUAL
);
configurer
.
configure
(
factory
,
connectionFactory
);
return
factory
;
}
@Bean
@Primary
public
RabbitTemplate
rabbitTemplate
(
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
public
RabbitTemplate
rabbitTemplate
(
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
return
new
RabbitTemplate
(
connectionFactory
);
return
new
RabbitTemplate
(
connectionFactory
);
}
}
...
...
app/src/main/java/com/yiring/app/rabbit/config/ZyConfigProperties.java
浏览文件 @
91d4643d
...
@@ -36,6 +36,7 @@ public class ZyConfigProperties {
...
@@ -36,6 +36,7 @@ public class ZyConfigProperties {
@ConfigurationProperties
(
prefix
=
"zy-config.rabbitmq"
)
@ConfigurationProperties
(
prefix
=
"zy-config.rabbitmq"
)
public
static
class
ZyConfigRabbitmq
{
public
static
class
ZyConfigRabbitmq
{
boolean
mock
;
boolean
enabled
;
boolean
enabled
;
String
host
;
String
host
;
int
port
;
int
port
;
...
...
app/src/main/java/com/yiring/app/rabbit/config/ZyRabbitConfig.java
浏览文件 @
91d4643d
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
rabbit
.
config
;
package
com
.
yiring
.
app
.
rabbit
.
config
;
import
com.yiring.app.rabbit.receiver.PositionMessageHandler
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.AcknowledgeMode
;
import
org.springframework.amqp.core.AcknowledgeMode
;
import
org.springframework.amqp.
rabbit.config.SimpleRabbitListenerContainerFactory
;
import
org.springframework.amqp.
core.Queue
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
;
import
org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -31,19 +29,9 @@ public class ZyRabbitConfig {
...
@@ -31,19 +29,9 @@ public class ZyRabbitConfig {
@Resource
@Resource
ZyConfigProperties
.
ZyConfigRabbitmq
rabbitmq
;
ZyConfigProperties
.
ZyConfigRabbitmq
rabbitmq
;
@Resource
ConfigurableApplicationContext
context
;
public
static
final
String
CONNECTION_FACTORY_NAME
=
"zyRabbitConnectionFactory"
;
public
static
final
String
CONNECTION_FACTORY_NAME
=
"zyRabbitConnectionFactory"
;
public
static
final
String
LISTENER_FACTORY_NAME
=
"zyRabbitListenerFactory"
;
public
static
final
String
LISTENER_CONTAINER_NAME
=
"zyPositionMessageListenerContainer"
;
public
static
final
String
TEMPLATE_NAME
=
"zyRabbitTemplate"
;
public
static
final
String
QUEUE_BEAN_NAME
=
"messageHandlerQueue"
;
/**
* 消息队列名称(必须要与配置文件中的 queue-name 完全一致)
* 规则: tenant_msg_${open.client-secret}_${open.client-id}
* 参见文档: 定位平台接口规范V3.0.1 - 通用版.pdf #6
*/
public
static
final
String
MESSAGE_QUEUES_NAME
=
"tenant_msg_12A14FDC_sc21080400"
;
@Bean
(
CONNECTION_FACTORY_NAME
)
@Bean
(
CONNECTION_FACTORY_NAME
)
public
ConnectionFactory
zyConnectionFactory
()
{
public
ConnectionFactory
zyConnectionFactory
()
{
...
@@ -56,27 +44,35 @@ public class ZyRabbitConfig {
...
@@ -56,27 +44,35 @@ public class ZyRabbitConfig {
);
);
}
}
@Bean
(
LISTENER_FACTORY_NAME
)
@Bean
(
LISTENER_CONTAINER_NAME
)
public
RabbitListenerContainerFactory
<?>
rabbitListenerContainerFactory
(
@ConditionalOnProperty
(
prefix
=
"zy-config.rabbitmq"
,
value
=
"mock"
,
havingValue
=
"false"
)
SimpleRabbitListenerContainerFactoryConfigurer
configurer
,
public
SimpleMessageListenerContainer
simpleMessageListenerContainer
(
PositionMessageHandler
handler
,
@Qualifier
(
QUEUE_BEAN_NAME
)
Queue
queue
,
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
)
{
// 检查队列名称是否与配置文件一致,避免监听错误
return
buildPositionMessageListenerContainer
(
handler
,
queue
,
connectionFactory
);
if
(!
MESSAGE_QUEUES_NAME
.
equals
(
rabbitmq
.
getQueueName
()))
{
}
log
.
error
(
"队列名称不一致,请检查配置文件"
);
context
.
close
();
return
null
;
}
SimpleRabbitListenerContainerFactory
factory
=
new
SimpleRabbitListenerContainerFactory
();
@Bean
(
QUEUE_BEAN_NAME
)
// 手动确认消息模式
public
Queue
messageHandlerQueue
()
{
factory
.
setAcknowledgeMode
(
AcknowledgeMode
.
MANUAL
);
return
new
Queue
(
rabbitmq
.
getQueueName
(),
true
,
false
,
false
);
configurer
.
configure
(
factory
,
connectionFactory
);
return
factory
;
}
}
@Bean
(
TEMPLATE_NAME
)
public
static
SimpleMessageListenerContainer
buildPositionMessageListenerContainer
(
public
RabbitTemplate
rabbitTemplate
(
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
PositionMessageHandler
handler
,
return
new
RabbitTemplate
(
connectionFactory
);
Queue
queue
,
ConnectionFactory
connectionFactory
)
{
SimpleMessageListenerContainer
container
=
new
SimpleMessageListenerContainer
();
container
.
setConnectionFactory
(
connectionFactory
);
container
.
setAcknowledgeMode
(
AcknowledgeMode
.
MANUAL
);
container
.
setBatchSize
(
10
);
container
.
setConcurrentConsumers
(
1
);
container
.
setMaxConcurrentConsumers
(
1
);
container
.
setExposeListenerChannel
(
true
);
container
.
setMessageListener
(
handler
);
container
.
addQueues
(
queue
);
return
container
;
}
}
}
}
app/src/main/java/com/yiring/app/rabbit/receiver/
ZyRabbitReceiv
er.java
→
app/src/main/java/com/yiring/app/rabbit/receiver/
PositionMessageHandl
er.java
浏览文件 @
91d4643d
...
@@ -2,31 +2,29 @@
...
@@ -2,31 +2,29 @@
package
com
.
yiring
.
app
.
rabbit
.
receiver
;
package
com
.
yiring
.
app
.
rabbit
.
receiver
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
import
com.yiring.app.
rabbit.config.ZyRabbitConfig
;
import
com.yiring.app.
service.message.PositionMessageService
;
import
com.yiring.
app.service.message.ZyMessageService
;
import
com.yiring.
common.annotation.Times
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitHandler
;
import
org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
/**
* 真源
RabbitMQ 消息监听(消息消费者)
* 真源
消息监听处理器
*
*
* @author Jim
* @author Jim
* @version 0.1
* @version 0.1
* 2022/
4/13 17:13
* 2022/
5/11 16:35
*/
*/
@Slf4j
@Slf4j
@Component
@Component
@Configuration
@Transactional
(
rollbackFor
=
Exception
.
class
)
@ConditionalOnProperty
(
prefix
=
"zy-config.rabbitmq"
,
value
=
"enabled"
,
havingValue
=
"true"
)
public
class
PositionMessageHandler
implements
ChannelAwareMessageListener
{
public
class
ZyRabbitReceiver
{
// TODO
// TODO
// 1. 新增消息订阅定时任务,检查是否正常订阅了真源定位系统的消息
// 1. 新增消息订阅定时任务,检查是否正常订阅了真源定位系统的消息
...
@@ -34,26 +32,15 @@ public class ZyRabbitReceiver {
...
@@ -34,26 +32,15 @@ public class ZyRabbitReceiver {
// 3. 订阅 position(定位数据)、lowPower(低电量报警)、deviceStatus(设备状态)、keyWarning(按键报警)
// 3. 订阅 position(定位数据)、lowPower(低电量报警)、deviceStatus(设备状态)、keyWarning(按键报警)
@Resource
@Resource
ZyMessageService
zy
MessageService
;
PositionMessageService
position
MessageService
;
/**
@Times
(
"Position System Message Handler"
)
* 订阅真源定位系统 RabbitMQ 推送过来的消息(主动订阅的一些消息类别)
@Override
* 参见: 定位平台接口规范V3.0.1 - 通用版.pdf #6
public
void
onMessage
(
Message
message
,
Channel
channel
)
throws
IOException
{
* @param msg 消息内容
* @param channel 消息通道
* @param message 消息主体
* @throws IOException 消息确认异常
*/
@RabbitHandler
// @RabbitListener(
// queues = ZyRabbitConfig.MESSAGE_QUEUES_NAME,
// containerFactory = ZyRabbitConfig.LISTENER_FACTORY_NAME
// )
@RabbitListener
(
queues
=
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
,
containerFactory
=
"rabbitListenerContainerFactory"
)
public
void
listen
(
String
msg
,
Channel
channel
,
Message
message
)
throws
IOException
{
// 消费消息
// 消费消息
zyMessageService
.
consume
(
msg
);
positionMessageService
.
consume
(
new
String
(
message
.
getBody
(),
StandardCharsets
.
UTF_8
)
);
// 手动确认消息已收到
// 手动确认消息已收到
assert
channel
!=
null
;
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
);
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
);
}
}
}
}
app/src/main/java/com/yiring/app/service/message/
Zy
MessageService.java
→
app/src/main/java/com/yiring/app/service/message/
Position
MessageService.java
浏览文件 @
91d4643d
...
@@ -8,7 +8,7 @@ package com.yiring.app.service.message;
...
@@ -8,7 +8,7 @@ package com.yiring.app.service.message;
* @version 0.1
* @version 0.1
* 2022/5/9 10:16
* 2022/5/9 10:16
*/
*/
public
interface
Zy
MessageService
{
public
interface
Position
MessageService
{
/**
/**
* 消费消息
* 消费消息
* @param message 消息内容
* @param message 消息内容
...
...
app/src/main/java/com/yiring/app/service/message/impl/
Zy
MessageServiceImpl.java
→
app/src/main/java/com/yiring/app/service/message/impl/
Position
MessageServiceImpl.java
浏览文件 @
91d4643d
差异被折叠。
点击展开。
app/src/main/java/com/yiring/app/util/GeoUtils.java
浏览文件 @
91d4643d
...
@@ -23,6 +23,8 @@ public class GeoUtils {
...
@@ -23,6 +23,8 @@ public class GeoUtils {
public
final
GeometryFactory
factory
=
new
GeometryFactory
();
public
final
GeometryFactory
factory
=
new
GeometryFactory
();
public
final
int
DEFAULT_SRID
=
4326
;
/**
/**
* 创建点
* 创建点
*
*
...
@@ -31,7 +33,7 @@ public class GeoUtils {
...
@@ -31,7 +33,7 @@ public class GeoUtils {
* @return 点
* @return 点
*/
*/
public
Point
createPoint
(
double
lon
,
double
lat
)
{
public
Point
createPoint
(
double
lon
,
double
lat
)
{
return
factory
.
createPoint
(
new
Coordinate
(
lon
,
lat
)
);
return
createPoint
(
lon
,
lat
,
0
);
}
}
/**
/**
...
@@ -42,7 +44,9 @@ public class GeoUtils {
...
@@ -42,7 +44,9 @@ public class GeoUtils {
* @return 点
* @return 点
*/
*/
public
Point
createPoint
(
double
lon
,
double
lat
,
double
alt
)
{
public
Point
createPoint
(
double
lon
,
double
lat
,
double
alt
)
{
return
factory
.
createPoint
(
new
Coordinate
(
lon
,
lat
,
alt
));
Point
point
=
factory
.
createPoint
(
new
Coordinate
(
lon
,
lat
,
alt
));
point
.
setSRID
(
DEFAULT_SRID
);
return
point
;
}
}
/**
/**
...
@@ -71,13 +75,12 @@ public class GeoUtils {
...
@@ -71,13 +75,12 @@ public class GeoUtils {
y
y
);
);
// 构建
经纬度坐标信息
// 构建
一个坐标点
Coordinate
coordinate
=
new
Coordinate
(
return
createPoint
(
result
.
getDoubleValue
(
"lon"
),
result
.
getDoubleValue
(
"lon"
),
result
.
getDoubleValue
(
"lat"
),
result
.
getDoubleValue
(
"lat"
),
r
oo
t
.
getDoubleValue
(
"altitude"
)
+
z
r
esul
t
.
getDoubleValue
(
"altitude"
)
+
z
);
);
return
factory
.
createPoint
(
coordinate
);
}
}
/**
/**
...
@@ -111,7 +114,7 @@ public class GeoUtils {
...
@@ -111,7 +114,7 @@ public class GeoUtils {
public
Point
randomPoint
(
double
minX
,
double
minY
,
double
maxX
,
double
maxY
,
double
z
)
{
public
Point
randomPoint
(
double
minX
,
double
minY
,
double
maxX
,
double
maxY
,
double
z
)
{
double
x
=
minX
+
(
maxX
-
minX
)
*
Math
.
random
();
double
x
=
minX
+
(
maxX
-
minX
)
*
Math
.
random
();
double
y
=
minY
+
(
maxY
-
minY
)
*
Math
.
random
();
double
y
=
minY
+
(
maxY
-
minY
)
*
Math
.
random
();
return
factory
.
createPoint
(
new
Coordinate
(
x
,
y
,
z
)
);
return
createPoint
(
x
,
y
,
z
);
}
}
/**
/**
...
...
app/src/main/java/com/yiring/app/util/zy/LonLatUtil.java
浏览文件 @
91d4643d
...
@@ -4,6 +4,7 @@ package com.yiring.app.util.zy;
...
@@ -4,6 +4,7 @@ package com.yiring.app.util.zy;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
/**
/**
* 从真源拿到的引擎计算经纬度的工具类
* @author Jim
* @author Jim
* @version 0.1
* @version 0.1
* 2022/5/9 16:41
* 2022/5/9 16:41
...
@@ -16,8 +17,8 @@ public class LonLatUtil {
...
@@ -16,8 +17,8 @@ public class LonLatUtil {
public
static
JSONObject
getRoot
()
{
public
static
JSONObject
getRoot
()
{
JSONObject
root
=
new
JSONObject
();
JSONObject
root
=
new
JSONObject
();
root
.
put
(
"lon"
,
0
D
);
root
.
put
(
"lon"
,
112.85893346021206
);
root
.
put
(
"lat"
,
0
D
);
root
.
put
(
"lat"
,
30.473384230484854
);
root
.
put
(
"x"
,
0
D
);
root
.
put
(
"x"
,
0
D
);
root
.
put
(
"y"
,
0
D
);
root
.
put
(
"y"
,
0
D
);
root
.
put
(
"altitude"
,
0
D
);
root
.
put
(
"altitude"
,
0
D
);
...
...
app/src/main/resources/application-dev.yml
浏览文件 @
91d4643d
...
@@ -83,8 +83,8 @@ xxl:
...
@@ -83,8 +83,8 @@ xxl:
logging
:
logging
:
level
:
level
:
# sql bind parameter
# sql bind parameter
#
org.hibernate.type.descriptor.sql.BasicBinder: trace
org.hibernate.type.descriptor.sql.BasicBinder
:
trace
org.hibernate.type.descriptor.sql.BasicBinder
:
error
#
org.hibernate.type.descriptor.sql.BasicBinder: error
# 真源定位系统相关配置
# 真源定位系统相关配置
zy-config
:
zy-config
:
...
@@ -97,7 +97,7 @@ zy-config:
...
@@ -97,7 +97,7 @@ zy-config:
username
:
admin
username
:
admin
password
:
admin
password
:
admin
virtual-host
:
/
virtual-host
:
/
queue-name
:
tenant_msg_${zy-config.open.client-secret}_${zy-config.open.client-id}
queue-name
:
tenant_msg_${zy-config.open.client-secret}_${zy-config.open.client-id}
_mock
# 开放接口信息配置
# 开放接口信息配置
open
:
open
:
api
:
http://${zy-config.host}:789/positionApi
api
:
http://${zy-config.host}:789/positionApi
...
...
basic-common/util/src/main/java/com/yiring/common/aspect/TimesAspect.java
浏览文件 @
91d4643d
...
@@ -25,9 +25,9 @@ import org.springframework.stereotype.Component;
...
@@ -25,9 +25,9 @@ import org.springframework.stereotype.Component;
public
class
TimesAspect
{
public
class
TimesAspect
{
@Pointcut
(
"@annotation(com.yiring.common.annotation.Times)"
)
@Pointcut
(
"@annotation(com.yiring.common.annotation.Times)"
)
public
void
pointCut
()
{}
public
void
times
()
{}
@Around
(
"
pointCut
()"
)
@Around
(
"
times
()"
)
public
Object
around
(
ProceedingJoinPoint
point
)
throws
Throwable
{
public
Object
around
(
ProceedingJoinPoint
point
)
throws
Throwable
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
Object
result
=
point
.
proceed
();
Object
result
=
point
.
proceed
();
...
...
basic-common/util/src/main/java/com/yiring/common/aspect/XxlJobAspect.java
0 → 100644
浏览文件 @
91d4643d
/* (C) 2021 YiRing, Inc. */
package
com
.
yiring
.
common
.
aspect
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
/**
* XxlJob 注解切面
*
* @author ifzm
* @version 0.1
*/
@Slf4j
@Aspect
@Component
public
class
XxlJobAspect
{
@Pointcut
(
"@annotation(com.xxl.job.core.handler.annotation.XxlJob)"
)
public
void
log
()
{}
@Around
(
"log()"
)
public
Object
around
(
ProceedingJoinPoint
point
)
throws
Throwable
{
try
{
return
point
.
proceed
();
}
catch
(
Exception
e
)
{
log
.
error
(
"XxlJob Execute Error: "
+
e
.
getMessage
(),
e
);
throw
e
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论