Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
6ceb4aca
提交
6ceb4aca
authored
5月 11, 2022
作者:
17607474349
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'merge_dev' of
https://gitlab.yiring.com/chemical-kesai/kshg-api
into dev_lijing
上级
1e4dab2f
08daed85
隐藏空白字符变更
内嵌
并排
正在显示
38 个修改的文件
包含
1250 行增加
和
326 行删除
+1250
-326
.gitignore
.gitignore
+1
-0
README.md
README.md
+2
-3
build.gradle
app/build.gradle
+5
-3
XxlJobConfig.java
app/src/main/java/com/yiring/app/config/XxlJobConfig.java
+61
-0
RehearsalPlanStatusEnum.java
...iring/app/constant/rehearsal/RehearsalPlanStatusEnum.java
+63
-0
RiskLevelEnum.java
...java/com/yiring/app/constant/rehearsal/RiskLevelEnum.java
+68
-0
LocationBeacon.java
...n/java/com/yiring/app/domain/location/LocationBeacon.java
+0
-15
LocationLog.java
...main/java/com/yiring/app/domain/location/LocationLog.java
+17
-30
LocationLogRepository.java
...com/yiring/app/domain/location/LocationLogRepository.java
+1
-2
LocationTag.java
...main/java/com/yiring/app/domain/location/LocationTag.java
+4
-9
TagTimeId.java
...c/main/java/com/yiring/app/domain/location/TagTimeId.java
+47
-0
ZyRealtimeLog.java
...rc/main/java/com/yiring/app/domain/log/ZyRealtimeLog.java
+6
-4
AccidentSpotRepository.java
...m/yiring/app/domain/rehearsal/AccidentSpotRepository.java
+10
-10
RehearsalPlan.java
...n/java/com/yiring/app/domain/rehearsal/RehearsalPlan.java
+74
-0
MockZyMessageJob.java
app/src/main/java/com/yiring/app/job/MockZyMessageJob.java
+148
-0
MockZyRabbitConfig.java
...java/com/yiring/app/rabbit/config/MockZyRabbitConfig.java
+48
-0
RabbitConfig.java
.../main/java/com/yiring/app/rabbit/config/RabbitConfig.java
+7
-2
ZyRabbitConfig.java
...ain/java/com/yiring/app/rabbit/config/ZyRabbitConfig.java
+7
-0
ZyRabbitReceiver.java
...java/com/yiring/app/rabbit/receiver/ZyRabbitReceiver.java
+9
-177
LocationTagServiceImpl.java
...app/service/location/tag/impl/LocationTagServiceImpl.java
+17
-7
LocationTagTypeServiceImpl.java
...service/location/tag/impl/LocationTagTypeServiceImpl.java
+2
-2
ZyMessageService.java
...java/com/yiring/app/service/message/ZyMessageService.java
+17
-0
ZyMessageServiceImpl.java
...yiring/app/service/message/impl/ZyMessageServiceImpl.java
+200
-0
AccidentSpotService.java
...com/yiring/app/service/rehearsal/AccidentSpotService.java
+22
-0
AccidentSpotServiceImpl.java
...g/app/service/rehearsal/impl/AccidentSpotServiceImpl.java
+28
-2
GeoUtils.java
app/src/main/java/com/yiring/app/util/GeoUtils.java
+57
-0
TimeIdGenerator.java
app/src/main/java/com/yiring/app/util/TimeIdGenerator.java
+23
-0
LonLatUtil.java
app/src/main/java/com/yiring/app/util/zy/LonLatUtil.java
+119
-0
HelloController.java
app/src/main/java/com/yiring/app/web/HelloController.java
+14
-0
AccidentSpotController.java
.../com/yiring/app/web/rehearsal/AccidentSpotController.java
+25
-14
EvacuationZoneController.java
...om/yiring/app/web/rehearsal/EvacuationZoneController.java
+3
-0
application-dev.yml
app/src/main/resources/application-dev.yml
+38
-18
build.gradle
basic-common/core/build.gradle
+1
-6
BasicEntity.java
...e/src/main/java/com/yiring/common/domain/BasicEntity.java
+0
-15
Times.java
...til/src/main/java/com/yiring/common/annotation/Times.java
+23
-0
RequestAspect.java
...src/main/java/com/yiring/common/aspect/RequestAspect.java
+6
-3
TimesAspect.java
...l/src/main/java/com/yiring/common/aspect/TimesAspect.java
+67
-0
build.gradle
build.gradle
+10
-4
没有找到文件。
.gitignore
浏览文件 @
6ceb4aca
...
@@ -38,3 +38,4 @@ out/
...
@@ -38,3 +38,4 @@ out/
node_modules
node_modules
logs/
logs/
.jpb/
README.md
浏览文件 @
6ceb4aca
...
@@ -29,9 +29,8 @@
...
@@ -29,9 +29,8 @@
-
[
x
]
[
conventional-changelog
]
(https://www.cnblogs.com/mengfangui/p/12634845.html)
-
[
x
]
[
conventional-changelog
]
(https://www.cnblogs.com/mengfangui/p/12634845.html)
-
[
x
]
用户及权限模块(目录/菜单/按钮),预览初始化权限配置
[
SQL 脚本
](
./basic-auth/src/main/resources/init-test-mysql.sql
)
-
[
x
]
用户及权限模块(目录/菜单/按钮),预览初始化权限配置
[
SQL 脚本
](
./basic-auth/src/main/resources/init-test-mysql.sql
)
-
[
x
]
通用文件上传模块
-
[
x
]
通用文件上传模块
-
[
]
通用字典管理模块
-
[
x
]
通用字典管理模块
-
[
]
XXL-JOB 定时任务模块
-
[
x
]
XXL-JOB 定时任务模块
-
[
x
]
@Convert 处理 Raw JSON 数据格式转换
-
[
]
扩展 PostgresDialect 实现时序查询函数
-
[
]
扩展 PostgresDialect 实现时序查询函数
---
---
...
...
app/build.gradle
浏览文件 @
6ceb4aca
...
@@ -13,6 +13,8 @@ dependencies {
...
@@ -13,6 +13,8 @@ dependencies {
implementation
'org.springframework.boot:spring-boot-starter-amqp'
implementation
'org.springframework.boot:spring-boot-starter-amqp'
implementation
"org.springframework.boot:spring-boot-starter-websocket"
implementation
"org.springframework.boot:spring-boot-starter-websocket"
implementation
"org.springframework.boot:spring-boot-starter-reactor-netty"
implementation
"org.springframework.boot:spring-boot-starter-reactor-netty"
implementation
"org.springframework.cloud:spring-cloud-starter-openfeign"
implementation
"org.springframework.cloud:spring-cloud-commons"
// 💬 Mock/Test Env
// 💬 Mock/Test Env
runtimeOnly
'com.h2database:h2'
runtimeOnly
'com.h2database:h2'
// 💬 Prod/Dev Env
// 💬 Prod/Dev Env
...
@@ -70,10 +72,10 @@ dependencies {
...
@@ -70,10 +72,10 @@ dependencies {
// myexcel
// myexcel
implementation
"com.github.liaochong:myexcel:${myexcelVersion}"
implementation
"com.github.liaochong:myexcel:${myexcelVersion}"
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign
implementation
"org.springframework.cloud:spring-cloud-starter-openfeign:${openfeignVersion}"
// feign-okhttp
// feign-okhttp
implementation
"io.github.openfeign:feign-okhttp:${feignOkhttpVersion}"
implementation
"io.github.openfeign:feign-okhttp:${feignOkhttpVersion}"
// xxl-job
implementation
"com.xuxueli:xxl-job-core:${xxlJobVersion}"
}
}
app/src/main/java/com/yiring/app/config/XxlJobConfig.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
config
;
import
cn.hutool.core.util.StrUtil
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
javax.annotation.Resource
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.experimental.FieldDefaults
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* xxl-job 配置
*/
@Slf4j
@Data
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Configuration
@ConfigurationProperties
(
prefix
=
"xxl.job"
)
public
class
XxlJobConfig
{
@Resource
InetUtils
inetUtils
;
String
adminAddresses
;
String
accessToken
;
String
executorAppName
;
String
executorAddress
;
String
executorIp
;
Integer
executorPort
=
9999
;
String
executorLogPath
;
Integer
executorLogRetentionDays
=
30
;
@Bean
public
XxlJobSpringExecutor
xxlJobExecutor
()
{
log
.
info
(
">>>>>>>>>>> xxl-job init: {}"
,
adminAddresses
);
if
(
StrUtil
.
isBlank
(
executorIp
))
{
executorIp
=
inetUtils
.
findFirstNonLoopbackAddress
().
getHostAddress
();
}
if
(
StrUtil
.
isBlank
(
executorAddress
))
{
executorAddress
=
"http://"
+
executorIp
+
":"
+
executorPort
;
}
XxlJobSpringExecutor
xxlJobSpringExecutor
=
new
XxlJobSpringExecutor
();
xxlJobSpringExecutor
.
setAdminAddresses
(
adminAddresses
);
xxlJobSpringExecutor
.
setAppname
(
executorAppName
);
xxlJobSpringExecutor
.
setAddress
(
executorAddress
);
xxlJobSpringExecutor
.
setIp
(
executorIp
);
xxlJobSpringExecutor
.
setPort
(
executorPort
);
xxlJobSpringExecutor
.
setAccessToken
(
accessToken
);
xxlJobSpringExecutor
.
setLogPath
(
executorLogPath
);
xxlJobSpringExecutor
.
setLogRetentionDays
(
executorLogRetentionDays
);
return
xxlJobSpringExecutor
;
}
}
app/src/main/java/com/yiring/app/constant/rehearsal/RehearsalPlanStatusEnum.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
constant
.
rehearsal
;
import
com.yiring.app.vo.CodeNameVo
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.Getter
;
/**
* 演练计划状态枚举(1:未启动, 2:进行中, 3:已结束)
* @author tml
* @version 1.0
* @date 2022/5/9 17:29
*/
public
enum
RehearsalPlanStatusEnum
{
/**
*未启动
*/
UN_START
(
1
,
"未启动"
),
/**
*进行中
*/
RUNNING
(
2
,
"进行中"
),
/**
* 已结束
*/
END
(
3
,
"已结束"
);
@Getter
private
final
Integer
code
;
@Getter
private
final
String
name
;
private
static
final
List
<
CodeNameVo
>
LIST
;
static
{
LIST
=
new
ArrayList
<>();
for
(
RehearsalPlanStatusEnum
item
:
values
())
{
LIST
.
add
(
new
CodeNameVo
(
item
.
getCode
(),
item
.
getName
()));
}
}
RehearsalPlanStatusEnum
(
Integer
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
public
static
List
<
CodeNameVo
>
getAll
()
{
return
LIST
;
}
public
static
String
getByCode
(
Integer
code
)
{
for
(
RehearsalPlanStatusEnum
item
:
values
())
{
if
(
item
.
getCode
().
equals
(
code
))
{
return
item
.
getName
();
}
}
return
"未知状态"
;
}
}
app/src/main/java/com/yiring/app/constant/rehearsal/RiskLevelEnum.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
constant
.
rehearsal
;
import
com.yiring.app.vo.CodeNameVo
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.Getter
;
/**
* 演练计划风险等级枚举(1:红色风险, 2:橙色风险, 3:黄色风险, 4:蓝色风险)
* @author tml
* @version 1.0
* @date 2022/5/9 17:28
*/
public
enum
RiskLevelEnum
{
/**
* 红色风险
*/
RED
(
1
,
"红色风险"
),
/**
* 橙色风险
*/
ORANGE
(
2
,
"橙色风险"
),
/**
* 黄色风险
*/
YELLOW
(
3
,
"黄色风险"
),
/**
* 蓝色风险
*/
BLUE
(
4
,
"蓝色风险"
);
@Getter
private
final
Integer
code
;
@Getter
private
final
String
name
;
private
static
final
List
<
CodeNameVo
>
LIST
;
static
{
LIST
=
new
ArrayList
<>();
for
(
RiskLevelEnum
item
:
values
())
{
LIST
.
add
(
new
CodeNameVo
(
item
.
getCode
(),
item
.
getName
()));
}
}
RiskLevelEnum
(
Integer
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
public
static
List
<
CodeNameVo
>
getAll
()
{
return
LIST
;
}
public
static
String
getByCode
(
Integer
code
)
{
for
(
RiskLevelEnum
item
:
values
())
{
if
(
item
.
getCode
().
equals
(
code
))
{
return
item
.
getName
();
}
}
return
"未知风险"
;
}
}
app/src/main/java/com/yiring/app/domain/location/LocationBeacon.java
浏览文件 @
6ceb4aca
...
@@ -8,14 +8,12 @@ import java.io.Serializable;
...
@@ -8,14 +8,12 @@ import java.io.Serializable;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.Hibernate
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Comment
;
import
org.locationtech.jts.geom.Point
;
import
org.locationtech.jts.geom.Point
;
...
@@ -100,17 +98,4 @@ public class LocationBeacon extends BasicEntity implements Serializable {
...
@@ -100,17 +98,4 @@ public class LocationBeacon extends BasicEntity implements Serializable {
@ManyToMany
@ManyToMany
@ToString
.
Exclude
@ToString
.
Exclude
Set
<
LocationFence
>
fences
=
new
HashSet
<>(
0
);
Set
<
LocationFence
>
fences
=
new
HashSet
<>(
0
);
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
Hibernate
.
getClass
(
this
)
!=
Hibernate
.
getClass
(
o
))
return
false
;
LocationBeacon
that
=
(
LocationBeacon
)
o
;
return
getId
()
!=
null
&&
Objects
.
equals
(
getId
(),
that
.
getId
());
}
@Override
public
int
hashCode
()
{
return
getClass
().
hashCode
();
}
}
}
app/src/main/java/com/yiring/app/domain/location/LocationLog.java
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
package
com
.
yiring
.
app
.
domain
.
location
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.vladmihalcea.hibernate.type.json.JsonType
;
import
com.vladmihalcea.hibernate.type.json.Json
Binary
Type
;
import
com.yiring.auth.domain.user.User
;
import
com.yiring.auth.domain.user.User
;
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
java.util.HashSet
;
import
java.util.Set
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.CreationTimestamp
;
import
org.hibernate.annotations.Type
;
import
org.hibernate.annotations.Type
;
import
org.hibernate.annotations.TypeDef
;
import
org.hibernate.annotations.TypeDef
;
import
org.locationtech.jts.geom.Point
;
import
org.locationtech.jts.geom.Point
;
...
@@ -40,19 +38,17 @@ import org.locationtech.jts.geom.Point;
...
@@ -40,19 +38,17 @@ import org.locationtech.jts.geom.Point;
@FieldNameConstants
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Entity
@Entity
@TypeDef
(
name
=
"json
"
,
typeClass
=
Json
Type
.
class
)
@TypeDef
(
name
=
"json
b"
,
typeClass
=
JsonBinary
Type
.
class
)
@Table
(
name
=
"BS_LOCATION_LOG"
)
@Table
(
name
=
"BS_LOCATION_LOG"
,
indexes
=
{
@Index
(
name
=
"idx_time"
,
columnList
=
"time"
)
}
)
@Comment
(
"定位数据"
)
@Comment
(
"定位数据"
)
public
class
LocationLog
implements
Serializable
{
public
class
LocationLog
implements
Serializable
{
@Serial
@Serial
private
static
final
long
serialVersionUID
=
3467455881020691989L
;
private
static
final
long
serialVersionUID
=
3467455881020691989L
;
@Id
@Comment
(
"定位标签时序复合主键"
)
@Comment
(
"时间"
)
@EmbeddedId
@Column
(
nullable
=
false
,
columnDefinition
=
"timestamp without time zone"
)
TagTimeId
id
;
@CreationTimestamp
LocalDateTime
time
;
@Comment
(
"地图 ID"
)
@Comment
(
"地图 ID"
)
Long
areaId
;
Long
areaId
;
...
@@ -64,7 +60,7 @@ public class LocationLog implements Serializable {
...
@@ -64,7 +60,7 @@ public class LocationLog implements Serializable {
* 来源于定位数据产生时刻标签所属的人员
* 来源于定位数据产生时刻标签所属的人员
*/
*/
@Comment
(
"用户"
)
@Comment
(
"用户"
)
@ManyToOne
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
@JoinColumn
(
name
=
"user_id"
)
@JoinColumn
(
name
=
"user_id"
)
User
user
;
User
user
;
...
@@ -72,29 +68,20 @@ public class LocationLog implements Serializable {
...
@@ -72,29 +68,20 @@ public class LocationLog implements Serializable {
* 来源于定位标签定位时刻的人员状态
* 来源于定位标签定位时刻的人员状态
*/
*/
@Comment
(
"用户状态"
)
@Comment
(
"用户状态"
)
String
status
;
User
.
Status
status
;
@Comment
(
"标签"
)
@ManyToOne
@JoinColumn
(
name
=
"tag_id"
)
LocationTag
tag
;
@Comment
(
"坐标点信息"
)
@Comment
(
"坐标点信息"
)
@Type
(
type
=
"jts_geometry"
)
@Column
(
columnDefinition
=
"point"
)
Point
point
;
Point
point
;
@Comment
(
"信标集合"
)
@Comment
(
"信标集合"
)
@Builder
.
Default
@Type
(
type
=
"jsonb"
)
@OneToMany
@Column
(
columnDefinition
=
"jsonb"
)
@ToString
.
Exclude
JSONArray
beacons
;
Set
<
LocationBeacon
>
beacons
=
new
HashSet
<>(
0
);
@Comment
(
"围栏集合"
)
@Comment
(
"围栏集合"
)
@Builder
.
Default
@Type
(
type
=
"jsonb"
)
@OneToMany
@Column
(
columnDefinition
=
"jsonb"
)
@ToString
.
Exclude
JSONArray
fences
;
Set
<
LocationFence
>
fences
=
new
HashSet
<>(
0
);
@Comment
(
"静止/运动"
)
@Comment
(
"静止/运动"
)
Boolean
silent
;
Boolean
silent
;
...
@@ -106,8 +93,8 @@ public class LocationLog implements Serializable {
...
@@ -106,8 +93,8 @@ public class LocationLog implements Serializable {
String
voltUnit
;
String
voltUnit
;
@Comment
(
"原始数据"
)
@Comment
(
"原始数据"
)
@
org
.
hibernate
.
annotations
.
Type
(
type
=
"json
"
)
@
Type
(
type
=
"jsonb
"
)
@Column
(
columnDefinition
=
"json"
)
@Column
(
columnDefinition
=
"json
b
"
)
JSONObject
raw
;
JSONObject
raw
;
@Comment
(
"定位时间"
)
@Comment
(
"定位时间"
)
...
...
app/src/main/java/com/yiring/app/domain/location/LocationLogRepository.java
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
package
com
.
yiring
.
app
.
domain
.
location
;
import
java.io.Serializable
;
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.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
...
@@ -14,4 +13,4 @@ import org.springframework.stereotype.Repository;
...
@@ -14,4 +13,4 @@ import org.springframework.stereotype.Repository;
@Repository
@Repository
public
interface
LocationLogRepository
public
interface
LocationLogRepository
extends
JpaRepository
<
LocationLog
,
Serializable
>,
JpaSpecificationExecutor
<
LocationLog
>
{}
extends
JpaRepository
<
LocationLog
,
TagTimeId
>,
JpaSpecificationExecutor
<
LocationLog
>
{}
app/src/main/java/com/yiring/app/domain/location/LocationTag.java
浏览文件 @
6ceb4aca
...
@@ -6,7 +6,6 @@ import com.yiring.common.annotation.FieldMapping;
...
@@ -6,7 +6,6 @@ import com.yiring.common.annotation.FieldMapping;
import
com.yiring.common.domain.BasicEntity
;
import
com.yiring.common.domain.BasicEntity
;
import
java.io.Serial
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.Objects
;
import
java.util.Objects
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.*
;
...
@@ -15,6 +14,7 @@ import lombok.experimental.FieldNameConstants;
...
@@ -15,6 +14,7 @@ import lombok.experimental.FieldNameConstants;
import
lombok.experimental.SuperBuilder
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.Hibernate
;
import
org.hibernate.Hibernate
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Comment
;
import
org.locationtech.jts.geom.Point
;
/**
/**
* 定位标签
* 定位标签
...
@@ -82,8 +82,7 @@ public class LocationTag extends BasicEntity implements Serializable {
...
@@ -82,8 +82,7 @@ public class LocationTag extends BasicEntity implements Serializable {
@Comment
(
"静止/运动"
)
@Comment
(
"静止/运动"
)
Boolean
silent
;
Boolean
silent
;
@OneToOne
@ManyToOne
@JoinColumn
(
name
=
"user_id"
)
@Comment
(
"绑定用户"
)
@Comment
(
"绑定用户"
)
User
user
;
User
user
;
...
@@ -103,12 +102,8 @@ public class LocationTag extends BasicEntity implements Serializable {
...
@@ -103,12 +102,8 @@ public class LocationTag extends BasicEntity implements Serializable {
@Comment
(
"类型(1:内部/2:访客)"
)
@Comment
(
"类型(1:内部/2:访客)"
)
Integer
category
;
Integer
category
;
@FieldMapping
(
value
=
"raiseTimestamp"
,
desc
=
"更新时间戳"
,
type
=
Long
.
class
)
@Comment
(
"最后定位坐标"
)
@Comment
(
"更新时间"
)
Point
point
;
LocalDateTime
updateTime
;
@Comment
(
"创建时间"
)
LocalDateTime
createTime
;
@SuppressWarnings
({
"unused"
})
@SuppressWarnings
({
"unused"
})
public
enum
Type
{
public
enum
Type
{
...
...
app/src/main/java/com/yiring/app/domain/location/TagTimeId.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
location
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
javax.persistence.Column
;
import
javax.persistence.Embeddable
;
import
javax.persistence.FetchType
;
import
javax.persistence.OneToOne
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotations.Comment
;
/**
* 定位标签时序联合主键
* @author Jim
* @version 0.1
* 2022/5/10 10:24
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Embeddable
public
class
TagTimeId
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
5254861902659471641L
;
@Comment
(
"定位标签"
)
@OneToOne
(
fetch
=
FetchType
.
LAZY
)
LocationTag
tag
;
@Comment
(
"定位时间"
)
@Column
(
nullable
=
false
,
columnDefinition
=
"timestamp without time zone"
)
LocalDateTime
time
;
public
TagTimeId
(
LocationTag
tag
)
{
this
.
tag
=
tag
;
this
.
time
=
LocalDateTime
.
now
();
}
}
app/src/main/java/com/yiring/app/domain/log/ZyRealtimeLog.java
浏览文件 @
6ceb4aca
...
@@ -11,7 +11,8 @@ import lombok.*;
...
@@ -11,7 +11,8 @@ import lombok.*;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.CreationTimestamp
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.hibernate.annotations.Type
;
import
org.hibernate.annotations.TypeDef
;
import
org.hibernate.annotations.TypeDef
;
/**
/**
...
@@ -45,10 +46,11 @@ public class ZyRealtimeLog implements Serializable {
...
@@ -45,10 +46,11 @@ public class ZyRealtimeLog implements Serializable {
@Serial
@Serial
private
static
final
long
serialVersionUID
=
5545864821082386L
;
private
static
final
long
serialVersionUID
=
5545864821082386L
;
@Id
@Comment
(
"时间"
)
@Comment
(
"时间"
)
@Id
@GeneratedValue
(
generator
=
"time-id"
)
@GenericGenerator
(
name
=
"time-id"
,
strategy
=
"com.yiring.app.util.TimeIdGenerator"
)
@Column
(
nullable
=
false
,
columnDefinition
=
"timestamp without time zone"
)
@Column
(
nullable
=
false
,
columnDefinition
=
"timestamp without time zone"
)
@CreationTimestamp
LocalDateTime
time
;
LocalDateTime
time
;
@Comment
(
"类型"
)
@Comment
(
"类型"
)
...
@@ -56,7 +58,7 @@ public class ZyRealtimeLog implements Serializable {
...
@@ -56,7 +58,7 @@ public class ZyRealtimeLog implements Serializable {
String
method
;
String
method
;
@Comment
(
"内容"
)
@Comment
(
"内容"
)
@
org
.
hibernate
.
annotations
.
Type
(
type
=
"jsonb"
)
@Type
(
type
=
"jsonb"
)
@Column
(
nullable
=
false
,
columnDefinition
=
"jsonb"
)
@Column
(
nullable
=
false
,
columnDefinition
=
"jsonb"
)
JSONObject
raw
;
JSONObject
raw
;
}
}
app/src/main/java/com/yiring/app/domain/rehearsal/AccidentSpotRepository.java
浏览文件 @
6ceb4aca
...
@@ -43,22 +43,22 @@ public interface AccidentSpotRepository
...
@@ -43,22 +43,22 @@ public interface AccidentSpotRepository
List
<
AccidentSpot
>
findLikeName
(
String
name
);
List
<
AccidentSpot
>
findLikeName
(
String
name
);
/**
/**
* 批量
启用
* 批量
删除
* @param ids
事故点
id集
* @param ids id集
* @param now 当前时间
* @param now 当前时间
* @return
启用了多少
条数据
* @return
删除了几
条数据
*/
*/
@Query
(
"UPDATE AccidentSpot SET enable = true,updateTime = :now WHERE id in (:ids) AND deleted = false"
)
@Query
(
"UPDATE AccidentSpot SET deleted = true, updateTime = :now WHERE id IN (:ids)"
)
@Modifying
int
batchRemove
(
@Param
(
"ids"
)
Set
<
Long
>
ids
,
@Param
(
"now"
)
LocalDateTime
now
);
int
batchEnable
(
@Param
(
"ids"
)
Set
<
Long
>
ids
,
@Param
(
"now"
)
LocalDateTime
now
);
/**
/**
* 批量停用
* 批量
启用/
停用
* @param ids 事故点id集
* @param ids 事故点id集
* @param now 当前时间
* @param now 当前时间
* @return 停用了多少条数据
* @param enable true:启用 false:停用
* @return 启用/停用了多少条数据
*/
*/
@Query
(
"UPDATE AccidentSpot SET enable =
false ,updateTime = :now WHERE id in
(:ids) AND deleted = false"
)
@Query
(
"UPDATE AccidentSpot SET enable =
:enable ,updateTime = :now WHERE id IN
(:ids) AND deleted = false"
)
@Modifying
@Modifying
int
batch
UnEnable
(
@Param
(
"ids"
)
Set
<
Long
>
ids
,
@Param
(
"now"
)
LocalDateTime
now
);
int
batch
Enable
(
@Param
(
"ids"
)
Set
<
Long
>
ids
,
@Param
(
"enable"
)
boolean
enable
,
@Param
(
"now"
)
LocalDateTime
now
);
}
}
app/src/main/java/com/yiring/app/domain/rehearsal/RehearsalPlan.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
domain
.
rehearsal
;
import
com.yiring.common.domain.BasicEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.Table
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Where
;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 17:07
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@FieldNameConstants
@SuperBuilder
(
toBuilder
=
true
)
@Where
(
clause
=
"deleted = false"
)
@Table
(
name
=
"BS_REHEARSAL_PLAN"
)
@Comment
(
"演练计划信息"
)
public
class
RehearsalPlan
extends
BasicEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
5215681932640062553L
;
@Comment
(
"演练主题"
)
private
String
topical
;
@Comment
(
"事故点"
)
@ManyToOne
@JoinColumn
(
name
=
"accident_spot_id"
)
private
AccidentSpot
accidentSpot
;
@Comment
(
"周边范围(事故点周围多少米)"
)
private
Integer
scope
;
@Comment
(
"撤离区"
)
@ManyToOne
@JoinColumn
(
name
=
"evacuation_zone_id"
)
private
EvacuationZone
evacuationZone
;
@Comment
(
"风险程度(1:红色风险, 2:橙色风险, 3:黄色风险, 4:蓝色风险)"
)
private
Integer
riskLevel
;
@Comment
(
"事故信息"
)
private
String
accidentMsg
;
@Comment
(
"演练时间"
)
private
LocalDateTime
rehearsalTime
;
@Comment
(
"推送信息"
)
private
String
pushMsg
;
@Comment
(
"演练计划的状态(1:未启动, 2:进行中, 3:已结束)"
)
private
Integer
status
;
@Comment
(
"逻辑删除"
)
private
boolean
deleted
;
}
app/src/main/java/com/yiring/app/job/MockZyMessageJob.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
job
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
com.yiring.app.domain.location.LocationLog
;
import
com.yiring.app.domain.location.LocationLogRepository
;
import
com.yiring.app.rabbit.config.ZyRabbitConfig
;
import
com.yiring.app.util.GeoUtils
;
import
com.yiring.common.constant.DateFormatter
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
javax.annotation.Resource
;
import
javax.persistence.criteria.Predicate
;
import
lombok.extern.slf4j.Slf4j
;
import
org.locationtech.jts.geom.Point
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Component
;
/**
* 模拟真源消息日志推送
*
* @author Jim
* @version 0.1
* 2022/5/7 15:26
*/
@SuppressWarnings
(
"unused"
)
@Slf4j
@Component
public
class
MockZyMessageJob
{
@Resource
RabbitTemplate
rabbitTemplate
;
@Resource
LocationLogRepository
locationLogRepository
;
@XxlJob
(
"MockZyMessageHandler"
)
public
void
mockMessageHandler
()
{
log
.
info
(
"MockZyMessageHandler: {}"
,
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
));
log
.
info
(
"[Mock] Position: {}"
,
mockPositionMessage
());
log
.
info
(
"[Mock] LowPower: {}"
,
mockLowPowerMessage
());
log
.
info
(
"[Mock] DeviceStatus: {}"
,
mockDeviceStatusMessage
());
log
.
info
(
"[Mock] KeyWarning: {}"
,
mockKeyWarningMessage
());
}
@XxlJob
(
"QueryMessageHandler"
)
public
void
queryMessageHandler
()
{
log
.
info
(
"QueryZyMessageHandler: {}"
,
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
));
try
{
Specification
<
LocationLog
>
spec
=
(
root
,
query
,
cb
)
->
{
Predicate
predicate
=
cb
.
conjunction
();
predicate
.
getExpressions
().
add
(
cb
.
lessThanOrEqualTo
(
root
.
get
(
"id"
).
get
(
"time"
),
LocalDateTime
.
now
()));
return
predicate
;
};
List
<
LocationLog
>
logs
=
locationLogRepository
.
findAll
(
spec
);
log
.
info
(
"QueryZyMessageHandler: {}"
,
logs
.
size
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
public
JSONObject
send
(
JSONObject
body
)
{
rabbitTemplate
.
convertAndSend
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
,
body
.
toJSONString
());
return
body
;
}
private
String
mockTag
()
{
return
"BTT33333331"
;
}
private
Long
mockAreaId
()
{
return
10019L
;
}
private
JSONObject
mockPositionMessage
()
{
// 随机生成一个坐标点
Point
point
=
GeoUtils
.
randomPoint
(
GeoUtils
.
defaultBounds
(),
0
);
// 模拟定位数据
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"areaId"
,
mockAreaId
());
params
.
put
(
"silent"
,
false
);
params
.
put
(
"beacons"
,
"BTI22085237,BTI22085238"
);
params
.
put
(
"longitude"
,
point
.
getCoordinate
().
getX
());
params
.
put
(
"latitude"
,
point
.
getCoordinate
().
getY
());
params
.
put
(
"altitude"
,
point
.
getCoordinate
().
getZ
());
params
.
put
(
"locationTime"
,
System
.
currentTimeMillis
());
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"voltUnit"
,
"mV"
);
params
.
put
(
"floor"
,
1
);
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"position"
);
body
.
put
(
"params"
,
params
);
return
send
(
body
);
}
private
JSONObject
mockLowPowerMessage
()
{
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"voltUnit"
,
"mV"
);
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"lowPower"
);
body
.
put
(
"params"
,
params
);
return
send
(
body
);
}
private
JSONObject
mockDeviceStatusMessage
()
{
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"deviceId"
,
mockTag
());
params
.
put
(
"areaId"
,
mockAreaId
());
params
.
put
(
"deviceType"
,
"BTI"
);
params
.
put
(
"volt"
,
3650
);
params
.
put
(
"field_21"
,
"mV"
);
params
.
put
(
"updateTime"
,
System
.
currentTimeMillis
());
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"deviceStatus"
);
body
.
put
(
"params"
,
params
);
return
send
(
body
);
}
private
JSONObject
mockKeyWarningMessage
()
{
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"tagId"
,
mockTag
());
params
.
put
(
"entityId"
,
"1522770547178475520"
);
params
.
put
(
"areaId"
,
mockAreaId
());
params
.
put
(
"raiseTime"
,
System
.
currentTimeMillis
());
params
.
put
(
"x"
,
100
);
params
.
put
(
"y"
,
100
);
params
.
put
(
"z"
,
0
);
params
.
put
(
"floor"
,
1
);
JSONObject
body
=
new
JSONObject
();
body
.
put
(
"method"
,
"keyWarning"
);
body
.
put
(
"params"
,
params
);
return
send
(
body
);
}
}
app/src/main/java/com/yiring/app/rabbit/config/MockZyRabbitConfig.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
rabbit
.
config
;
import
org.springframework.amqp.core.Binding
;
import
org.springframework.amqp.core.BindingBuilder
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.core.TopicExchange
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* 模拟真源 rabbitmq 消息队列配置
*
* @author ifzm
* 2019/8/21 15:44
*/
@Configuration
public
class
MockZyRabbitConfig
{
/**
* 消息交换机
*/
public
static
final
String
ZY_TOPIC_EXCHANGE
=
"zy.topic.exchange"
;
/**
* 订阅模式
*
* @return TopicExchange
*/
@Bean
(
ZY_TOPIC_EXCHANGE
)
TopicExchange
exchange
()
{
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
Binding
bindingExchangeMock
(
@Qualifier
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
)
Queue
queue
,
@Qualifier
(
ZY_TOPIC_EXCHANGE
)
TopicExchange
exchange
)
{
return
BindingBuilder
.
bind
(
queue
).
to
(
exchange
).
with
(
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
);
}
}
app/src/main/java/com/yiring/app/rabbit/config/RabbitConfig.java
浏览文件 @
6ceb4aca
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
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.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
;
...
@@ -9,6 +10,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
...
@@ -9,6 +10,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import
org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory
;
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
;
...
@@ -25,7 +27,7 @@ public class RabbitConfig {
...
@@ -25,7 +27,7 @@ public class RabbitConfig {
@Resource
@Resource
RabbitProperties
rabbitProperties
;
RabbitProperties
rabbitProperties
;
p
rivate
static
final
String
CONNECTION_FACTORY_NAME
=
"rabbitConnectionFactory"
;
p
ublic
static
final
String
CONNECTION_FACTORY_NAME
=
"rabbitConnectionFactory"
;
@Bean
(
CONNECTION_FACTORY_NAME
)
@Bean
(
CONNECTION_FACTORY_NAME
)
@Primary
@Primary
...
@@ -42,10 +44,13 @@ public class RabbitConfig {
...
@@ -42,10 +44,13 @@ public class RabbitConfig {
@Bean
@Bean
@Primary
@Primary
public
RabbitListenerContainerFactory
<?>
rabbitListenerContainerFactory
(
public
RabbitListenerContainerFactory
<?>
rabbitListenerContainerFactory
(
SimpleRabbitListenerContainerFactoryConfigurer
configurer
,
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
)
{
SimpleRabbitListenerContainerFactory
factory
=
new
SimpleRabbitListenerContainerFactory
();
SimpleRabbitListenerContainerFactory
factory
=
new
SimpleRabbitListenerContainerFactory
();
factory
.
setConnectionFactory
(
connectionFactory
);
// 手动确认消息模式
factory
.
setAcknowledgeMode
(
AcknowledgeMode
.
MANUAL
);
configurer
.
configure
(
factory
,
connectionFactory
);
return
factory
;
return
factory
;
}
}
...
...
app/src/main/java/com/yiring/app/rabbit/config/ZyRabbitConfig.java
浏览文件 @
6ceb4aca
...
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -6,6 +6,7 @@ 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.rabbit.config.SimpleRabbitListenerContainerFactory
;
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.RabbitListenerContainerFactory
;
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.amqp.SimpleRabbitListenerContainerFactoryConfigurer
;
...
@@ -35,6 +36,7 @@ public class ZyRabbitConfig {
...
@@ -35,6 +36,7 @@ public class ZyRabbitConfig {
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_FACTORY_NAME
=
"zyRabbitListenerFactory"
;
public
static
final
String
TEMPLATE_NAME
=
"zyRabbitTemplate"
;
/**
/**
* 消息队列名称(必须要与配置文件中的 queue-name 完全一致)
* 消息队列名称(必须要与配置文件中的 queue-name 完全一致)
...
@@ -72,4 +74,9 @@ public class ZyRabbitConfig {
...
@@ -72,4 +74,9 @@ public class ZyRabbitConfig {
configurer
.
configure
(
factory
,
connectionFactory
);
configurer
.
configure
(
factory
,
connectionFactory
);
return
factory
;
return
factory
;
}
}
@Bean
(
TEMPLATE_NAME
)
public
RabbitTemplate
rabbitTemplate
(
@Qualifier
(
CONNECTION_FACTORY_NAME
)
ConnectionFactory
connectionFactory
)
{
return
new
RabbitTemplate
(
connectionFactory
);
}
}
}
app/src/main/java/com/yiring/app/rabbit/receiver/ZyRabbitReceiver.java
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
rabbit
.
receiver
;
package
com
.
yiring
.
app
.
rabbit
.
receiver
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
import
com.yiring.app.domain.location.*
;
import
com.yiring.app.domain.log.ZyRealtimeLog
;
import
com.yiring.app.domain.log.ZyRealtimeLogRepository
;
import
com.yiring.app.rabbit.config.ZyRabbitConfig
;
import
com.yiring.app.rabbit.config.ZyRabbitConfig
;
import
com.yiring.app.
util.GeoUtils
;
import
com.yiring.app.
service.message.ZyMessageService
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.locationtech.jts.geom.Point
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitHandler
;
import
org.springframework.amqp.rabbit.annotation.RabbitHandler
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.domain.Example
;
import
org.springframework.messaging.simp.SimpMessagingTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
/**
* 真源 RabbitMQ 消息监听(消息消费者)
* 真源 RabbitMQ 消息监听(消息消费者)
...
@@ -48,19 +34,7 @@ public class ZyRabbitReceiver {
...
@@ -48,19 +34,7 @@ public class ZyRabbitReceiver {
// 3. 订阅 position(定位数据)、lowPower(低电量报警)、deviceStatus(设备状态)、keyWarning(按键报警)
// 3. 订阅 position(定位数据)、lowPower(低电量报警)、deviceStatus(设备状态)、keyWarning(按键报警)
@Resource
@Resource
LocationTagRepository
locationTagRepository
;
ZyMessageService
zyMessageService
;
@Resource
LocationBeaconRepository
locationBeaconRepository
;
@Resource
LocationLogRepository
locationLogRepository
;
@Resource
SimpMessagingTemplate
simpMessagingTemplate
;
@Resource
ZyRealtimeLogRepository
zyRealtimeLogRepository
;
/**
/**
* 订阅真源定位系统 RabbitMQ 推送过来的消息(主动订阅的一些消息类别)
* 订阅真源定位系统 RabbitMQ 推送过来的消息(主动订阅的一些消息类别)
...
@@ -71,157 +45,15 @@ public class ZyRabbitReceiver {
...
@@ -71,157 +45,15 @@ public class ZyRabbitReceiver {
* @throws IOException 消息确认异常
* @throws IOException 消息确认异常
*/
*/
@RabbitHandler
@RabbitHandler
@RabbitListener
(
// @RabbitListener(
queues
=
ZyRabbitConfig
.
MESSAGE_QUEUES_NAME
,
// queues = ZyRabbitConfig.MESSAGE_QUEUES_NAME,
containerFactory
=
ZyRabbitConfig
.
LISTENER_FACTORY_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
{
public
void
listen
(
String
msg
,
Channel
channel
,
Message
message
)
throws
IOException
{
// 消费消息
zyMessageService
.
consume
(
msg
);
// 手动确认消息已收到
// 手动确认消息已收到
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
);
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
false
);
try
{
// 将消息转换成 JSON 格式
JSONObject
info
=
JSON
.
parseObject
(
msg
);
log
.
info
(
"Receiver Message: {}"
,
info
);
// 解构消息内容
JSONObject
data
=
info
.
getJSONObject
(
"params"
);
String
method
=
info
.
getString
(
"method"
);
// 记录日志
ZyRealtimeLog
realtimeLog
=
ZyRealtimeLog
.
builder
().
method
(
method
).
raw
(
info
).
build
();
zyRealtimeLogRepository
.
save
(
realtimeLog
);
// 业务处理
switch
(
method
)
{
// 实时定位
case
"position"
->
processPositionMessage
(
data
);
// 设备低电量
case
"lowPower"
->
processLowPowerMessage
(
data
);
// 设备状态变更
case
"deviceStatus"
->
processDeviceStatusMessage
(
data
);
// 按键报警
case
"keyWarning"
->
processKeyWarningMessage
(
data
);
// 围栏报警
case
"enclosure"
->
log
.
warn
(
"Ignore Message Type [enclosure]: {}"
,
info
);
default
->
log
.
warn
(
"Unknown Message Type: {}"
,
info
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
/**
* 处理定位消息
* @param data 消息内容
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processPositionMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"Position Message: {}"
,
data
);
// 包装消息
// TODO
// 1. 解析消息内容,进行围栏、出入标识判断等处理,将定位记录录入数据库
// 2. 创建一条需要进行消息推送的记录
// 3. 将记录推送的消息推送模块
// 4. 检查是否触发围栏告警,记录告警数据,并推送消息
// 定位时间
Instant
instant
=
Instant
.
ofEpochMilli
(
data
.
getLongValue
(
"locationTime"
));
LocalDateTime
time
=
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
// 定位的基本信息
LocationLog
locationLog
=
LocationLog
.
builder
()
.
raw
(
data
)
.
locationTime
(
time
)
.
silent
(
data
.
getBoolean
(
"silent"
))
.
volt
(
data
.
getInteger
(
"volt"
))
.
voltUnit
(
data
.
getString
(
"voltUnit"
))
.
build
();
// 设置空间点位信息
Point
point
=
GeoUtils
.
createPoint
(
data
.
getDoubleValue
(
"longitude"
),
data
.
getDoubleValue
(
"latitude"
),
data
.
getDoubleValue
(
"altitude"
)
);
locationLog
.
setPoint
(
point
);
// 查询定位标签
Example
<
LocationTag
>
example
=
Example
.
of
(
LocationTag
.
builder
().
code
(
data
.
getString
(
"tagId"
)).
build
());
Optional
<
LocationTag
>
optional
=
locationTagRepository
.
findOne
(
example
);
if
(
optional
.
isPresent
())
{
LocationTag
tag
=
optional
.
get
();
// 设置定位标签
locationLog
.
setTag
(
tag
);
// 定位标签当时所属的用户
locationLog
.
setUser
(
tag
.
getUser
());
// 查询当前用户的状态
// TODO
}
// 查询定位信标
Set
<
String
>
codes
=
Arrays
.
stream
(
data
.
getString
(
"beacons"
).
split
(
","
))
.
map
(
beacon
->
beacon
.
replaceAll
(
"\\(.*\\)"
,
""
))
.
collect
(
Collectors
.
toSet
());
Set
<
LocationBeacon
>
beacons
=
locationBeaconRepository
.
findByCodeIn
(
codes
);
locationLog
.
setBeacons
(
beacons
);
// 查询定位所在围栏信息
Set
<
LocationFence
>
fences
=
locationLog
.
getBeacons
()
.
stream
()
.
map
(
LocationBeacon:
:
getFences
)
.
flatMap
(
Set:
:
stream
)
.
collect
(
Collectors
.
toSet
());
locationLog
.
setFences
(
fences
);
// TODO
// 并计算出入标记(围栏、区域)
// 写入数据
locationLogRepository
.
saveAndFlush
(
locationLog
);
// 更新定位标签卡电量信息
// TODO
// WebSocket 推送定位消息
// 消息内容需要确定 TODO
simpMessagingTemplate
.
convertAndSend
(
"/topic/position"
,
"{}"
);
// TODO
// 判断围栏告警是否触发,触发写入告警记录,并推送消息
}
/**
* 处理低电量报警消息
* @param data 消息内容
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processLowPowerMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"LowPower Message: {}"
,
data
);
}
/**
* 处理设备状态更新消息
* @param data 消息内容
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processDeviceStatusMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"DeviceStatus Message: {}"
,
data
);
}
/**
* 处理按键报警消息
* @param data 消息内容
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processKeyWarningMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"KeyWarning Message: {}"
,
data
);
}
}
}
}
app/src/main/java/com/yiring/app/service/location/tag/impl/LocationTagServiceImpl.java
浏览文件 @
6ceb4aca
...
@@ -16,7 +16,10 @@ import com.yiring.app.domain.location.LocationTagRepository;
...
@@ -16,7 +16,10 @@ import com.yiring.app.domain.location.LocationTagRepository;
import
com.yiring.app.excel.location.tag.LocationTagExportExcel
;
import
com.yiring.app.excel.location.tag.LocationTagExportExcel
;
import
com.yiring.app.excel.location.tag.LocationTagImportExcel
;
import
com.yiring.app.excel.location.tag.LocationTagImportExcel
;
import
com.yiring.app.feign.zy.location.tag.LocationTagClient
;
import
com.yiring.app.feign.zy.location.tag.LocationTagClient
;
import
com.yiring.app.param.location.tag.*
;
import
com.yiring.app.param.location.tag.LocationTagAddParam
;
import
com.yiring.app.param.location.tag.LocationTagDeleteParam
;
import
com.yiring.app.param.location.tag.LocationTagExportParam
;
import
com.yiring.app.param.location.tag.LocationTagFindParam
;
import
com.yiring.app.param.zy.location.tag.ZyLocationTagAddParam
;
import
com.yiring.app.param.zy.location.tag.ZyLocationTagAddParam
;
import
com.yiring.app.service.location.tag.LocationTagService
;
import
com.yiring.app.service.location.tag.LocationTagService
;
import
com.yiring.app.util.zy.ZyUtil
;
import
com.yiring.app.util.zy.ZyUtil
;
...
@@ -24,6 +27,7 @@ import com.yiring.app.vo.location.tag.LocationTagIndexVo;
...
@@ -24,6 +27,7 @@ import com.yiring.app.vo.location.tag.LocationTagIndexVo;
import
com.yiring.app.vo.location.tag.LocationTagVo
;
import
com.yiring.app.vo.location.tag.LocationTagVo
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.domain.BasicEntity
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.IndexParam
;
import
com.yiring.common.param.IndexParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.param.PageParam
;
...
@@ -33,7 +37,10 @@ import java.io.InputStream;
...
@@ -33,7 +37,10 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -42,7 +49,10 @@ import javax.persistence.criteria.Predicate;
...
@@ -42,7 +49,10 @@ import javax.persistence.criteria.Predicate;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.springframework.data.domain.*
;
import
org.springframework.data.domain.Example
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -120,7 +130,7 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -120,7 +130,7 @@ public class LocationTagServiceImpl implements LocationTagService {
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
silent
),
locationTagFindParam
.
getSilent
()));
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
silent
),
locationTagFindParam
.
getSilent
()));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
...
@@ -183,7 +193,7 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -183,7 +193,7 @@ public class LocationTagServiceImpl implements LocationTagService {
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
silent
),
locationTagExportParam
.
getSilent
()));
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
silent
),
locationTagExportParam
.
getSilent
()));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
...
@@ -318,7 +328,7 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -318,7 +328,7 @@ public class LocationTagServiceImpl implements LocationTagService {
predicates
.
add
(
cb
.
like
(
root
.
get
(
LocationTag
.
Fields
.
code
),
"%"
+
indexParam
.
getStr
()
+
"%"
));
predicates
.
add
(
cb
.
like
(
root
.
get
(
LocationTag
.
Fields
.
code
),
"%"
+
indexParam
.
getStr
()
+
"%"
));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
...
@@ -352,7 +362,7 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -352,7 +362,7 @@ public class LocationTagServiceImpl implements LocationTagService {
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
used
),
locationTagFindParam
.
getUsed
()));
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
used
),
locationTagFindParam
.
getUsed
()));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
...
...
app/src/main/java/com/yiring/app/service/location/tag/impl/LocationTagTypeServiceImpl.java
浏览文件 @
6ceb4aca
...
@@ -72,7 +72,7 @@ public class LocationTagTypeServiceImpl implements LocationTagTypeService {
...
@@ -72,7 +72,7 @@ public class LocationTagTypeServiceImpl implements LocationTagTypeService {
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
category
),
locationTagTypeFindParam
.
getCategory
()));
predicates
.
add
(
cb
.
equal
(
root
.
get
(
LocationTag
.
Fields
.
category
),
locationTagTypeFindParam
.
getCategory
()));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
...
@@ -119,7 +119,7 @@ public class LocationTagTypeServiceImpl implements LocationTagTypeService {
...
@@ -119,7 +119,7 @@ public class LocationTagTypeServiceImpl implements LocationTagTypeService {
predicates
.
add
(
cb
.
and
(
in
));
predicates
.
add
(
cb
.
and
(
in
));
}
}
Order
order
=
cb
.
desc
(
root
.
get
(
LocationTag
.
Fields
.
createTime
));
Order
order
=
cb
.
desc
(
root
.
get
(
BasicEntity
.
Fields
.
createTime
));
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
return
cq
.
orderBy
(
order
).
where
(
predicates
.
toArray
(
new
Predicate
[
0
])).
getRestriction
();
};
};
List
<
LocationTag
>
locationTags
=
locationTagRepository
.
findAll
(
specification
);
List
<
LocationTag
>
locationTags
=
locationTagRepository
.
findAll
(
specification
);
...
...
app/src/main/java/com/yiring/app/service/message/ZyMessageService.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
service
.
message
;
/**
* 真源消息处理 Service
*
* @author Jim
* @version 0.1
* 2022/5/9 10:16
*/
public
interface
ZyMessageService
{
/**
* 消费消息
* @param message 消息内容
*/
void
consume
(
String
message
);
}
app/src/main/java/com/yiring/app/service/message/impl/ZyMessageServiceImpl.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
service
.
message
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yiring.app.domain.location.*
;
import
com.yiring.app.domain.log.ZyRealtimeLog
;
import
com.yiring.app.domain.log.ZyRealtimeLogRepository
;
import
com.yiring.app.service.message.ZyMessageService
;
import
com.yiring.app.util.GeoUtils
;
import
com.yiring.auth.domain.user.User
;
import
com.yiring.common.annotation.Times
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.util.Arrays
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.locationtech.jts.geom.Point
;
import
org.springframework.data.domain.Example
;
import
org.springframework.messaging.simp.SimpMessagingTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* 真源消息处理实现类
*
* @author Jim
* @version 0.1
* 2022/5/9 10:22
*/
@Slf4j
@Service
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
ZyMessageServiceImpl
implements
ZyMessageService
{
@Resource
LocationTagRepository
locationTagRepository
;
@Resource
LocationLogRepository
locationLogRepository
;
@Resource
SimpMessagingTemplate
simpMessagingTemplate
;
@Resource
ZyRealtimeLogRepository
zyRealtimeLogRepository
;
@Times
@Override
public
void
consume
(
String
message
)
{
// 将消息转换成 JSON 格式
JSONObject
info
=
JSON
.
parseObject
(
message
);
log
.
info
(
"Receiver Message: {}"
,
info
);
// 解构消息内容
JSONObject
data
=
info
.
getJSONObject
(
"params"
);
String
method
=
info
.
getString
(
"method"
);
// 记录日志
ZyRealtimeLog
realtimeLog
=
ZyRealtimeLog
.
builder
().
method
(
method
).
raw
(
info
).
build
();
zyRealtimeLogRepository
.
save
(
realtimeLog
);
// 业务处理
switch
(
method
)
{
// 实时定位
case
"position"
->
processPositionMessage
(
data
);
// 设备低电量
case
"lowPower"
->
processLowPowerMessage
(
data
);
// 设备状态变更
case
"deviceStatus"
->
processDeviceStatusMessage
(
data
);
// 按键报警
case
"keyWarning"
->
processKeyWarningMessage
(
data
);
// 围栏报警
case
"enclosure"
->
log
.
warn
(
"Ignore Message Type [enclosure]: {}"
,
info
);
default
->
log
.
warn
(
"Unknown Message Type: {}"
,
info
);
}
}
/**
* 处理定位消息
* @param data 消息内容
*/
public
void
processPositionMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"Position Message: {}"
,
data
);
// 包装消息
// TODO
// 1. 解析消息内容,进行围栏、出入标识判断等处理,将定位记录录入数据库
// 2. 创建一条需要进行消息推送的记录
// 3. 将记录推送的消息推送模块
// 4. 检查是否触发围栏告警,记录告警数据,并推送消息
// 查询定位标签
String
tagId
=
data
.
getString
(
"tagId"
);
Example
<
LocationTag
>
example
=
Example
.
of
(
LocationTag
.
builder
().
code
(
tagId
).
build
());
Optional
<
LocationTag
>
optional
=
locationTagRepository
.
findOne
(
example
);
if
(
optional
.
isEmpty
())
{
log
.
warn
(
"Tag Not Found: {}"
,
tagId
);
return
;
}
// 构建复合主键
LocationTag
tag
=
optional
.
get
();
TagTimeId
id
=
new
TagTimeId
(
tag
);
// 定位时间
Instant
instant
=
Instant
.
ofEpochMilli
(
data
.
getLongValue
(
"locationTime"
));
LocalDateTime
locationTime
=
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
// 定位的基本信息
LocationLog
locationLog
=
LocationLog
.
builder
()
.
id
(
id
)
.
locationTime
(
locationTime
)
.
areaId
(
data
.
getLong
(
"areaId"
))
.
floor
(
data
.
getString
(
"floor"
))
.
silent
(
data
.
getBoolean
(
"silent"
))
.
volt
(
data
.
getInteger
(
"volt"
))
.
voltUnit
(
data
.
getString
(
"voltUnit"
))
.
raw
(
data
)
.
build
();
// 获取定位卡当前绑定的用户
User
user
=
tag
.
getUser
();
if
(
user
!=
null
)
{
// 定位标签当时所属的用户
locationLog
.
setUser
(
user
);
// 查询当前用户的状态
locationLog
.
setStatus
(
user
.
getStatus
());
}
// 设置空间点位信息
Point
point
=
GeoUtils
.
createPoint
(
data
.
getDoubleValue
(
"longitude"
),
data
.
getDoubleValue
(
"latitude"
),
data
.
getDoubleValue
(
"altitude"
)
);
locationLog
.
setPoint
(
point
);
// 定位信标
Set
<
String
>
codes
=
Arrays
.
stream
(
data
.
getString
(
"beacons"
).
split
(
","
))
.
map
(
beacon
->
beacon
.
replaceAll
(
"\\(.*\\)"
,
""
))
.
collect
(
Collectors
.
toSet
());
locationLog
.
setBeacons
(
new
JSONArray
().
fluentAddAll
(
codes
));
// TODO
// 并计算出入标记(围栏、区域)
// 写入数据
locationLogRepository
.
saveAndFlush
(
locationLog
);
// 更新定位标签卡状态信息
tag
.
setPoint
(
locationLog
.
getPoint
());
tag
.
setVolt
(
locationLog
.
getVolt
());
tag
.
setVoltUnit
(
locationLog
.
getVoltUnit
());
tag
.
setSilent
(
locationLog
.
getSilent
());
locationTagRepository
.
save
(
tag
);
// WebSocket 推送定位消息
// 消息内容需要确定 TODO
simpMessagingTemplate
.
convertAndSend
(
"/topic/position"
,
"{}"
);
// TODO
// 判断围栏告警是否触发,触发写入告警记录,并推送消息
}
/**
* 处理低电量报警消息
* @param data 消息内容
*/
public
void
processLowPowerMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"LowPower Message: {}"
,
data
);
}
/**
* 处理设备状态更新消息
* @param data 消息内容
*/
public
void
processDeviceStatusMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"DeviceStatus Message: {}"
,
data
);
}
/**
* 处理按键报警消息
* @param data 消息内容
*/
public
void
processKeyWarningMessage
(
JSONObject
data
)
{
// TODO
log
.
info
(
"KeyWarning Message: {}"
,
data
);
}
}
app/src/main/java/com/yiring/app/service/rehearsal/AccidentSpotService.java
浏览文件 @
6ceb4aca
...
@@ -11,6 +11,7 @@ import com.yiring.common.param.IdParam;
...
@@ -11,6 +11,7 @@ import com.yiring.common.param.IdParam;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.vo.PageVo
;
import
com.yiring.common.vo.PageVo
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.validation.Valid
;
/**
/**
* @author tml
* @author tml
...
@@ -40,6 +41,13 @@ public interface AccidentSpotService {
...
@@ -40,6 +41,13 @@ public interface AccidentSpotService {
Result
<
String
>
removeAccidentSpot
(
IdParam
param
);
Result
<
String
>
removeAccidentSpot
(
IdParam
param
);
/**
/**
* 批量删除事故点
* @param ids 事故点id集
* @return 是否成功
*/
Result
<
String
>
batchRemove
(
Set
<
Long
>
ids
);
/**
* 根据id查询事故点信息
* 根据id查询事故点信息
* @param param id
* @param param id
* @return 事故点信息
* @return 事故点信息
...
@@ -62,6 +70,20 @@ public interface AccidentSpotService {
...
@@ -62,6 +70,20 @@ public interface AccidentSpotService {
Result
<
PageVo
<
IdNameVo
>>
findAccidentList
(
String
name
);
Result
<
PageVo
<
IdNameVo
>>
findAccidentList
(
String
name
);
/**
/**
* 启用一个事故点
* @param idParam 事故点id
* @return 是否成功
*/
Result
<
String
>
enable
(
@Valid
IdParam
idParam
);
/**
* 停用一个事故点
* @param idParam 事故点id
* @return 是否成功
*/
Result
<
String
>
unEnable
(
@Valid
IdParam
idParam
);
/**
* 批量启用事故点
* 批量启用事故点
* @param ids 事故点id集
* @param ids 事故点id集
* @return 是否成功
* @return 是否成功
...
...
app/src/main/java/com/yiring/app/service/rehearsal/impl/AccidentSpotServiceImpl.java
浏览文件 @
6ceb4aca
...
@@ -90,6 +90,12 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
...
@@ -90,6 +90,12 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
}
}
@Override
@Override
public
Result
<
String
>
batchRemove
(
Set
<
Long
>
ids
)
{
int
num
=
accidentSpotRepository
.
batchRemove
(
ids
,
LocalDateTime
.
now
());
return
Result
.
ok
(
"删除了"
+
num
+
"个事故点"
);
}
@Override
public
Result
<
AccidentSpotVo
>
findById
(
IdParam
param
)
{
public
Result
<
AccidentSpotVo
>
findById
(
IdParam
param
)
{
Optional
<
AccidentSpot
>
optional
=
accidentSpotRepository
.
findById
(
param
.
getId
());
Optional
<
AccidentSpot
>
optional
=
accidentSpotRepository
.
findById
(
param
.
getId
());
if
(
optional
.
isEmpty
())
{
if
(
optional
.
isEmpty
())
{
...
@@ -137,14 +143,34 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
...
@@ -137,14 +143,34 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
}
}
@Override
@Override
public
Result
<
String
>
enable
(
IdParam
idParam
)
{
Optional
<
AccidentSpot
>
optional
=
accidentSpotRepository
.
findById
(
idParam
.
getId
());
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
EXPECTATION_FAILED
,
"要启用的事故点不存在"
);
}
optional
.
get
().
setEnable
(
true
);
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
unEnable
(
IdParam
idParam
)
{
Optional
<
AccidentSpot
>
optional
=
accidentSpotRepository
.
findById
(
idParam
.
getId
());
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
EXPECTATION_FAILED
,
"要停用的事故点不存在"
);
}
optional
.
get
().
setEnable
(
false
);
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
batchEnable
(
Set
<
Long
>
ids
)
{
public
Result
<
String
>
batchEnable
(
Set
<
Long
>
ids
)
{
int
num
=
accidentSpotRepository
.
batchEnable
(
ids
,
LocalDateTime
.
now
());
int
num
=
accidentSpotRepository
.
batchEnable
(
ids
,
true
,
LocalDateTime
.
now
());
return
Result
.
ok
(
"启用了"
+
num
+
"个事故点"
);
return
Result
.
ok
(
"启用了"
+
num
+
"个事故点"
);
}
}
@Override
@Override
public
Result
<
String
>
batchUnEnable
(
Set
<
Long
>
ids
)
{
public
Result
<
String
>
batchUnEnable
(
Set
<
Long
>
ids
)
{
int
num
=
accidentSpotRepository
.
batch
UnEnable
(
ids
,
LocalDateTime
.
now
());
int
num
=
accidentSpotRepository
.
batch
Enable
(
ids
,
false
,
LocalDateTime
.
now
());
return
Result
.
ok
(
"停用了"
+
num
+
"个事故点"
);
return
Result
.
ok
(
"停用了"
+
num
+
"个事故点"
);
}
}
}
}
app/src/main/java/com/yiring/app/util/GeoUtils.java
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
util
;
package
com
.
yiring
.
app
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yiring.app.util.zy.LonLatUtil
;
import
lombok.experimental.UtilityClass
;
import
lombok.experimental.UtilityClass
;
import
org.locationtech.jts.geom.Coordinate
;
import
org.locationtech.jts.geom.Coordinate
;
import
org.locationtech.jts.geom.GeometryFactory
;
import
org.locationtech.jts.geom.GeometryFactory
;
...
@@ -53,6 +55,61 @@ public class GeoUtils {
...
@@ -53,6 +55,61 @@ public class GeoUtils {
// TODO
// TODO
// 根据真源定位系统设置的坐标系,转换为经纬度
// 根据真源定位系统设置的坐标系,转换为经纬度
// 根据北向的地图左下角坐标点,矩形长宽距离,结合二维图片的像素比,计算经纬度
// 根据北向的地图左下角坐标点,矩形长宽距离,结合二维图片的像素比,计算经纬度
// 左下角经纬度信息(基准点)
// TODO: 需要从真源获取后更新
JSONObject
root
=
LonLatUtil
.
getRoot
();
// 计算经纬度
JSONObject
result
=
LonLatUtil
.
ComputeLonLat
(
root
.
getDoubleValue
(
"lon"
),
root
.
getDoubleValue
(
"lat"
),
root
.
getDoubleValue
(
"x"
),
root
.
getDoubleValue
(
"y"
),
x
,
y
);
// 构建经纬度坐标信息
Coordinate
coordinate
=
new
Coordinate
(
result
.
getDoubleValue
(
"lon"
),
result
.
getDoubleValue
(
"lat"
),
root
.
getDoubleValue
(
"altitude"
)
+
z
);
return
factory
.
createPoint
(
coordinate
);
}
/**
* 获取经纬度边界
* @return 经纬度边界
*/
public
static
double
[]
defaultBounds
()
{
// 数据来源于 2D 正射影像图转 mbtiles 描述文件
return
new
double
[]
{
112.858891
,
30.473306
,
112.866217
,
30.481243
};
}
/**
* 根据经纬度边界随机生成一个坐标点
* @param bounds 经纬度边界
* @param z 高度
* @return 坐标点
*/
public
Point
randomPoint
(
double
[]
bounds
,
double
z
)
{
return
randomPoint
(
bounds
[
0
],
bounds
[
1
],
bounds
[
2
],
bounds
[
3
],
z
);
}
/**
* 根据经纬度边界随机生成一个坐标点
* @param minX 最小经度
* @param minY 最小纬度
* @param maxX 最大经度
* @param maxY 最大纬度
* @param z 高度
* @return 坐标点
*/
public
Point
randomPoint
(
double
minX
,
double
minY
,
double
maxX
,
double
maxY
,
double
z
)
{
double
x
=
minX
+
(
maxX
-
minX
)
*
Math
.
random
();
double
y
=
minY
+
(
maxY
-
minY
)
*
Math
.
random
();
return
factory
.
createPoint
(
new
Coordinate
(
x
,
y
,
z
));
return
factory
.
createPoint
(
new
Coordinate
(
x
,
y
,
z
));
}
}
}
}
app/src/main/java/com/yiring/app/util/TimeIdGenerator.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
util
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
org.hibernate.HibernateException
;
import
org.hibernate.engine.spi.SharedSessionContractImplementor
;
import
org.hibernate.id.IdentifierGenerator
;
import
org.springframework.stereotype.Component
;
/**
* @author Jim
* @version 0.1
* 2022/5/10 18:26
*/
@Component
public
class
TimeIdGenerator
implements
IdentifierGenerator
{
public
Serializable
generate
(
SharedSessionContractImplementor
session
,
Object
object
)
throws
HibernateException
{
return
LocalDateTime
.
now
();
}
}
app/src/main/java/com/yiring/app/util/zy/LonLatUtil.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
app
.
util
.
zy
;
import
com.alibaba.fastjson.JSONObject
;
/**
* @author Jim
* @version 0.1
* 2022/5/9 16:41
*/
public
class
LonLatUtil
{
static
final
long
LonLat_A
=
6378137
;
static
final
double
LonLat_B
=
6356752.3142
;
static
final
double
LonLat_F
=
1
/
298.257223563
;
public
static
JSONObject
getRoot
()
{
JSONObject
root
=
new
JSONObject
();
root
.
put
(
"lon"
,
0
D
);
root
.
put
(
"lat"
,
0
D
);
root
.
put
(
"x"
,
0
D
);
root
.
put
(
"y"
,
0
D
);
root
.
put
(
"altitude"
,
0
D
);
return
root
;
}
// lon:基准点经度
// lat:基准点纬度
// distance:目标点离基准点距离
// angle:目标点与基准点连线和正北方向夹角
public
static
JSONObject
ComputeLonLat
(
double
lon
,
double
lat
,
double
rootX
,
double
rootY
,
double
postX
,
double
postY
)
{
double
distance
=
getDistance
(
rootX
,
rootY
,
postX
,
postY
);
double
alpha1
=
(
Math
.
PI
/
2
)
-
Math
.
atan2
(
postY
-
rootY
,
postX
-
rootX
);
double
sinAlpha1
=
Math
.
sin
(
alpha1
);
double
cosAlpha1
=
Math
.
cos
(
alpha1
);
double
tanU1
=
(
1
-
LonLat_F
)
*
Math
.
tan
(
Rad
(
lat
));
double
cosU1
=
1
/
Math
.
sqrt
((
1
+
tanU1
*
tanU1
));
double
sinU1
=
tanU1
*
cosU1
;
double
sigma1
=
Math
.
atan2
(
tanU1
,
cosAlpha1
);
double
sinAlpha
=
cosU1
*
sinAlpha1
;
double
cosSqAlpha
=
1
-
sinAlpha
*
sinAlpha
;
double
uSq
=
cosSqAlpha
*
((
LonLat_A
*
LonLat_A
)
-
LonLat_B
*
LonLat_B
)
/
(
LonLat_B
*
LonLat_B
);
double
A
=
1
+
uSq
/
16384
*
(
4096
+
uSq
*
(-
768
+
uSq
*
(
320
-
175
*
uSq
)));
double
B
=
uSq
/
1024
*
(
256
+
uSq
*
(-
128
+
uSq
*
(
74
-
47
*
uSq
)));
double
sigma
=
distance
/
(
LonLat_B
*
A
);
double
sigmaP
=
2
*
Math
.
PI
;
double
cos2SigmaM
=
Math
.
cos
(
2
*
sigma1
+
sigma
);
double
sinSigma
=
Math
.
sin
(
sigma
);
double
cosSigma
=
Math
.
cos
(
sigma
);
while
(
Math
.
abs
(
sigma
-
sigmaP
)
>
1
e
-
12
)
{
cos2SigmaM
=
Math
.
cos
(
2
*
sigma1
+
sigma
);
sinSigma
=
Math
.
sin
(
sigma
);
cosSigma
=
Math
.
cos
(
sigma
);
double
deltaSigma
=
B
*
sinSigma
*
(
cos2SigmaM
+
B
/
4
*
(
cosSigma
*
(-
1
+
2
*
cos2SigmaM
*
cos2SigmaM
)
-
B
/
6
*
cos2SigmaM
*
(-
3
+
4
*
sinSigma
*
sinSigma
)
*
(-
3
+
4
*
cos2SigmaM
*
cos2SigmaM
)
)
);
sigmaP
=
sigma
;
sigma
=
distance
/
(
LonLat_B
*
A
)
+
deltaSigma
;
}
double
tmp
=
sinU1
*
sinSigma
-
cosU1
*
cosSigma
*
cosAlpha1
;
double
lat2
=
Math
.
atan2
(
sinU1
*
cosSigma
+
cosU1
*
sinSigma
*
cosAlpha1
,
(
1
-
LonLat_F
)
*
Math
.
sqrt
(
sinAlpha
*
sinAlpha
+
tmp
*
tmp
)
);
double
lambda
=
Math
.
atan2
(
sinSigma
*
sinAlpha1
,
cosU1
*
cosSigma
-
sinU1
*
sinSigma
*
cosAlpha1
);
double
C
=
LonLat_F
/
16
*
cosSqAlpha
*
(
4
+
LonLat_F
*
(
4
-
3
*
cosSqAlpha
));
double
L
=
lambda
-
(
1
-
C
)
*
LonLat_F
*
sinAlpha
*
(
sigma
+
C
*
sinSigma
*
(
cos2SigmaM
+
C
*
cosSigma
*
(-
1
+
2
*
cos2SigmaM
*
cos2SigmaM
)));
// double revAz = Math.atan2(sinAlpha, -tmp); // final bearing4
JSONObject
lonLat
=
new
JSONObject
();
lonLat
.
put
(
"lon"
,
lon
+
Deg
(
L
));
lonLat
.
put
(
"lat"
,
Deg
(
lat2
));
return
lonLat
;
}
public
static
double
Rad
(
double
d
)
{
return
d
*
Math
.
PI
/
180.0
;
}
public
static
double
Deg
(
double
d
)
{
return
d
*
180
/
Math
.
PI
;
}
public
static
double
getDistance
(
double
rootX
,
double
rootY
,
double
postX
,
double
postY
)
{
double
dx2
=
Math
.
pow
((
rootX
-
postX
),
2
);
double
dy2
=
Math
.
pow
((
rootY
-
postY
),
2
);
double
dz2
=
Math
.
pow
((
0
),
2
);
return
Math
.
sqrt
(
dx2
+
dy2
+
dz2
);
}
}
app/src/main/java/com/yiring/app/web/HelloController.java
浏览文件 @
6ceb4aca
...
@@ -12,6 +12,10 @@ import java.util.Arrays;
...
@@ -12,6 +12,10 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.List
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.locationtech.jts.geom.Geometry
;
import
org.locationtech.jts.geom.Polygon
;
import
org.locationtech.jts.io.ParseException
;
import
org.locationtech.jts.io.WKTReader
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -52,4 +56,14 @@ public class HelloController {
...
@@ -52,4 +56,14 @@ public class HelloController {
public
Result
<
String
>
test
()
{
public
Result
<
String
>
test
()
{
return
Result
.
ok
(
ZyUtil
.
manageLogin
());
return
Result
.
ok
(
ZyUtil
.
manageLogin
());
}
}
@GetMapping
(
"test2"
)
public
Result
<
Geometry
>
test2
()
throws
ParseException
{
WKTReader
reader
=
new
WKTReader
();
Geometry
geometry
=
reader
.
read
(
"POLYGON((114.13726247683384 22.57453153296995,114.13726253585672 22.57362062876488,114.1379932868094 22.57336379439826,114.13860672275516 22.573820711775532,114.13726247683384 22.57453153296995))"
);
Polygon
polygon
=
(
Polygon
)
geometry
;
return
Result
.
ok
(
polygon
);
}
}
}
app/src/main/java/com/yiring/app/web/rehearsal/AccidentSpotController.java
浏览文件 @
6ceb4aca
...
@@ -7,6 +7,7 @@ import com.yiring.app.param.rehearsal.AccidentSpotModifyParam;
...
@@ -7,6 +7,7 @@ import com.yiring.app.param.rehearsal.AccidentSpotModifyParam;
import
com.yiring.app.service.rehearsal.AccidentSpotService
;
import
com.yiring.app.service.rehearsal.AccidentSpotService
;
import
com.yiring.app.vo.IdNameVo
;
import
com.yiring.app.vo.IdNameVo
;
import
com.yiring.app.vo.rehearsal.AccidentSpotVo
;
import
com.yiring.app.vo.rehearsal.AccidentSpotVo
;
import
com.yiring.auth.param.IdsParam
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.domain.BasicEntity
;
import
com.yiring.common.domain.BasicEntity
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.IdParam
;
...
@@ -16,10 +17,8 @@ import io.swagger.annotations.Api;
...
@@ -16,10 +17,8 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.Set
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
javax.validation.constraints.NotEmpty
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
...
@@ -58,6 +57,12 @@ public class AccidentSpotController {
...
@@ -58,6 +57,12 @@ public class AccidentSpotController {
return
accidentSpotService
.
removeAccidentSpot
(
param
);
return
accidentSpotService
.
removeAccidentSpot
(
param
);
}
}
@ApiOperation
(
"批量删除事故点"
)
@PostMapping
(
"/batchRemove"
)
public
Result
<
String
>
batchRemove
(
@Valid
IdsParam
idsParam
)
{
return
accidentSpotService
.
batchRemove
(
idsParam
.
toIds
());
}
@ApiOperation
(
"根据id查询事故点"
)
@ApiOperation
(
"根据id查询事故点"
)
@GetMapping
(
"/findById"
)
@GetMapping
(
"/findById"
)
public
Result
<
AccidentSpotVo
>
findById
(
@Valid
IdParam
param
)
{
public
Result
<
AccidentSpotVo
>
findById
(
@Valid
IdParam
param
)
{
...
@@ -87,21 +92,27 @@ public class AccidentSpotController {
...
@@ -87,21 +92,27 @@ public class AccidentSpotController {
return
accidentSpotService
.
findAccidentList
(
name
);
return
accidentSpotService
.
findAccidentList
(
name
);
}
}
@ApiOperation
(
"启用一个事故点"
)
@PostMapping
(
"/enable"
)
public
Result
<
String
>
enable
(
@Valid
IdParam
idParam
)
{
return
accidentSpotService
.
enable
(
idParam
);
}
@ApiOperation
(
"停用一个事故点"
)
@PostMapping
(
"/unEnable"
)
public
Result
<
String
>
unEnable
(
@Valid
IdParam
idParam
)
{
return
accidentSpotService
.
unEnable
(
idParam
);
}
@ApiOperation
(
"批量启用"
)
@ApiOperation
(
"批量启用"
)
@ApiImplicitParam
(
value
=
"事故点id集"
,
example
=
"1,2,3"
,
name
=
"ids"
)
@PostMapping
(
"/batchEnable"
)
@GetMapping
(
"/batchEnable"
)
public
Result
<
String
>
batchEnable
(
@Valid
IdsParam
idsParam
)
{
public
Result
<
String
>
batchEnable
(
return
accidentSpotService
.
batchEnable
(
idsParam
.
toIds
());
@RequestParam
(
value
=
"ids"
,
required
=
false
)
@NotEmpty
(
message
=
"请传入至少一个事故点"
)
Set
<
Long
>
ids
)
{
return
accidentSpotService
.
batchEnable
(
ids
);
}
}
@ApiOperation
(
"批量停用"
)
@ApiOperation
(
"批量停用"
)
@ApiImplicitParam
(
value
=
"事故点id集"
,
example
=
"1,2,3"
,
name
=
"ids"
)
@PostMapping
(
"/batchUnEnable"
)
@GetMapping
(
"/batchUnEnable"
)
public
Result
<
String
>
batchUnEnable
(
@Valid
IdsParam
idsParam
)
{
public
Result
<
String
>
batchUnEnable
(
return
accidentSpotService
.
batchUnEnable
(
idsParam
.
toIds
());
@RequestParam
(
value
=
"ids"
,
required
=
false
)
@NotEmpty
(
message
=
"请传入至少一个事故点"
)
Set
<
Long
>
ids
)
{
return
accidentSpotService
.
batchUnEnable
(
ids
);
}
}
}
}
app/src/main/java/com/yiring/app/web/rehearsal/EvacuationZoneController.java
浏览文件 @
6ceb4aca
...
@@ -58,6 +58,9 @@ public class EvacuationZoneController {
...
@@ -58,6 +58,9 @@ public class EvacuationZoneController {
@ApiOperation
(
"查询撤离区下拉框"
)
@ApiOperation
(
"查询撤离区下拉框"
)
@GetMapping
(
"/findEvacuationPullDown"
)
@GetMapping
(
"/findEvacuationPullDown"
)
public
Result
<
PageVo
<
IdNameVo
>>
findEvacuationPullDown
(
String
name
)
{
public
Result
<
PageVo
<
IdNameVo
>>
findEvacuationPullDown
(
String
name
)
{
if
(
name
==
null
)
{
name
=
""
;
}
return
evacuationZoneService
.
findEvacuationPullDown
(
name
);
return
evacuationZoneService
.
findEvacuationPullDown
(
name
);
}
}
...
...
app/src/main/resources/application-dev.yml
浏览文件 @
6ceb4aca
...
@@ -3,6 +3,11 @@ env:
...
@@ -3,6 +3,11 @@ env:
host
:
192.168.0.156
host
:
192.168.0.156
spring
:
spring
:
servlet
:
multipart
:
enabled
:
true
max-file-size
:
50MB
max-request-size
:
100MB
datasource
:
datasource
:
url
:
jdbc:postgresql://${env.host}:5432/kshg_app
url
:
jdbc:postgresql://${env.host}:5432/kshg_app
username
:
admin
username
:
admin
...
@@ -26,24 +31,16 @@ spring:
...
@@ -26,24 +31,16 @@ spring:
username
:
admin
username
:
admin
password
:
123456
password
:
123456
virtual-host
:
/
virtual-host
:
/
# 开启发送端确认
data
:
publisher-confirm-type
:
correlated
redis
:
# 开启接收端确认
repositories
:
publisher-returns
:
true
enabled
:
false
template
:
# 处理多网卡选举
# 消息抵达队列,异步回调 confirm
cloud
:
mandatory
:
true
inetutils
:
listener
:
preferred-networks
:
192.168.0
simple
:
# 手动确认消息
acknowledge-mode
:
manual
servlet
:
multipart
:
enabled
:
true
max-file-size
:
50MB
max-request-size
:
100MB
# knife4j
# knife4j
(swagger)
knife4j
:
knife4j
:
enable
:
true
enable
:
true
basic
:
basic
:
...
@@ -62,10 +59,33 @@ minio:
...
@@ -62,10 +59,33 @@ minio:
bucket
:
kshg
bucket
:
kshg
domain
:
${minio.endpoint}/${minio.bucket}
domain
:
${minio.endpoint}/${minio.bucket}
# 任务调度
xxl
:
job
:
### 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
admin-addresses
:
http://${env.host}:8080/xxl-job-admin
### 执行器通讯TOKEN [选填]:非空时启用;
access-token
:
local
### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
executor-app-name
:
kshg-app
### 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
executor-address
:
### 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
executor-ip
:
### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
executor-port
:
### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
executor-log-path
:
/data/applogs/xxl-job/jobhandler
### 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
executor-log-retention-days
:
30
# 日志
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
# 真源定位系统相关配置
# 真源定位系统相关配置
zy-config
:
zy-config
:
host
:
project.yz-online.com
host
:
project.yz-online.com
...
...
basic-common/core/build.gradle
浏览文件 @
6ceb4aca
...
@@ -17,12 +17,7 @@ dependencies {
...
@@ -17,12 +17,7 @@ dependencies {
// JTS 几何对象操作库
// JTS 几何对象操作库
implementation
"org.locationtech.jts:jts-core:${jtsVersion}"
implementation
"org.locationtech.jts:jts-core:${jtsVersion}"
/*// https://mvnrepository.com/artifact/com.graphhopper.external/jackson-datatype-jts
// https://mvnrepository.com/artifact/org.n52.jackson/jackson-datatype-jts/1.2.10
implementation("com.graphhopper.external:jackson-datatype-jts:1.0-2.7") {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
exclude group: 'org.locationtech.jts', module: 'jts-core'
}*/
// https://mvnrepository.com/artifact/com.graphhopper.external/jackson-datatype-jts
implementation
(
"org.n52.jackson:jackson-datatype-jts:1.2.10"
)
{
implementation
(
"org.n52.jackson:jackson-datatype-jts:1.2.10"
)
{
exclude
group:
'com.fasterxml.jackson.core'
,
module:
'jackson-databind'
exclude
group:
'com.fasterxml.jackson.core'
,
module:
'jackson-databind'
exclude
group:
'com.fasterxml.jackson.core'
,
module:
'jackson-annotations'
exclude
group:
'com.fasterxml.jackson.core'
,
module:
'jackson-annotations'
...
...
basic-common/core/src/main/java/com/yiring/common/domain/BasicEntity.java
浏览文件 @
6ceb4aca
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
package
com
.
yiring
.
common
.
domain
;
package
com
.
yiring
.
common
.
domain
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.Objects
;
import
javax.persistence.Column
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
...
@@ -11,7 +10,6 @@ import lombok.*;
...
@@ -11,7 +10,6 @@ import lombok.*;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.Hibernate
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.CreationTimestamp
;
import
org.hibernate.annotations.CreationTimestamp
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.hibernate.annotations.GenericGenerator
;
...
@@ -52,17 +50,4 @@ public abstract class BasicEntity {
...
@@ -52,17 +50,4 @@ public abstract class BasicEntity {
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
@UpdateTimestamp
@UpdateTimestamp
LocalDateTime
updateTime
;
LocalDateTime
updateTime
;
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
Hibernate
.
getClass
(
this
)
!=
Hibernate
.
getClass
(
o
))
return
false
;
BasicEntity
that
=
(
BasicEntity
)
o
;
return
id
!=
null
&&
Objects
.
equals
(
id
,
that
.
id
);
}
@Override
public
int
hashCode
()
{
return
getClass
().
hashCode
();
}
}
}
basic-common/util/src/main/java/com/yiring/common/annotation/Times.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
common
.
annotation
;
import
java.lang.annotation.*
;
/**
* 耗时计算注解
*
* @author Jim
* @version 0.1
* 2022/4/7 15:21
*/
@SuppressWarnings
({
"unused"
})
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
Times
{
/**
* 描述
*/
String
value
()
default
""
;
}
basic-common/util/src/main/java/com/yiring/common/aspect/RequestAspect.java
浏览文件 @
6ceb4aca
...
@@ -3,6 +3,7 @@ package com.yiring.common.aspect;
...
@@ -3,6 +3,7 @@ package com.yiring.common.aspect;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.yiring.common.constant.DateFormatter
;
import
com.yiring.common.constant.DateFormatter
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.util.Commons
;
import
com.yiring.common.util.Commons
;
...
@@ -34,7 +35,7 @@ public class RequestAspect {
...
@@ -34,7 +35,7 @@ public class RequestAspect {
Boolean
debug
;
Boolean
debug
;
@Pointcut
(
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping) || @annotation(org.springframework.web.bind.annotation.ExceptionHandler)"
"@annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping) || @annotation(org.springframework.web.bind.annotation.
PutMapping) || @annotation(org.springframework.web.bind.annotation.DeleteMapping) || @annotation(org.springframework.web.bind.annotation.PatchMapping) || @annotation(org.springframework.web.bind.annotation.
ExceptionHandler)"
)
)
public
void
apiPointCut
()
{}
public
void
apiPointCut
()
{}
...
@@ -52,8 +53,10 @@ public class RequestAspect {
...
@@ -52,8 +53,10 @@ public class RequestAspect {
// Print Request Log (Optional Replace: MDC)
// Print Request Log (Optional Replace: MDC)
String
extra
=
""
;
String
extra
=
""
;
if
(
Boolean
.
TRUE
.
equals
(
debug
))
{
if
(
Boolean
.
TRUE
.
equals
(
debug
))
{
extra
+=
String
.
format
(
"\nHeaders: %s"
,
JSONObject
.
toJSONString
(
ServletUtil
.
getHeaderMap
(
request
),
true
));
String
headers
=
JSONObject
.
toJSONString
(
ServletUtil
.
getHeaderMap
(
request
),
SerializerFeature
.
PrettyFormat
);
extra
+=
String
.
format
(
"\nParams: %s"
,
JSONObject
.
toJSONString
(
ServletUtil
.
getParamMap
(
request
),
true
));
String
params
=
JSONObject
.
toJSONString
(
ServletUtil
.
getParamMap
(
request
),
SerializerFeature
.
PrettyFormat
);
extra
+=
String
.
format
(
"\nHeaders: %s"
,
headers
);
extra
+=
String
.
format
(
"\nParams: %s"
,
params
);
if
(
result
instanceof
Result
)
{
if
(
result
instanceof
Result
)
{
extra
+=
extra
+=
String
.
format
(
String
.
format
(
...
...
basic-common/util/src/main/java/com/yiring/common/aspect/TimesAspect.java
0 → 100644
浏览文件 @
6ceb4aca
/* (C) 2021 YiRing, Inc. */
package
com
.
yiring
.
common
.
aspect
;
import
cn.hutool.core.util.StrUtil
;
import
com.yiring.common.annotation.Times
;
import
java.lang.reflect.Method
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.JoinPoint
;
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
;
/**
* 耗时计算注解切面
*
* @author ifzm
* @version 0.1
*/
@Slf4j
@Aspect
@Component
public
class
TimesAspect
{
@Pointcut
(
"@annotation(com.yiring.common.annotation.Times)"
)
public
void
pointCut
()
{}
@Around
(
"pointCut()"
)
public
Object
around
(
ProceedingJoinPoint
point
)
throws
Throwable
{
long
start
=
System
.
currentTimeMillis
();
Object
result
=
point
.
proceed
();
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"[Times] {}: {} ms"
,
getTimesValue
(
point
),
end
-
start
);
return
result
;
}
public
String
getTimesValue
(
JoinPoint
joinPoint
)
{
// 获取切入点的目标类
Class
<?>
targetClass
=
joinPoint
.
getTarget
().
getClass
();
// 获取切入方法名
String
methodName
=
joinPoint
.
getSignature
().
getName
();
// 获取切入方法参数
Object
[]
arguments
=
joinPoint
.
getArgs
();
// 获取目标类的所有方法
Method
[]
methods
=
targetClass
.
getMethods
();
String
timesValue
=
methodName
;
for
(
Method
method
:
methods
)
{
// 方法名相同、包含目标注解、方法参数个数相同(避免有重载)
if
(
method
.
getName
().
equals
(
methodName
)
&&
method
.
isAnnotationPresent
(
Times
.
class
)
&&
method
.
getParameterTypes
().
length
==
arguments
.
length
)
{
String
value
=
method
.
getAnnotation
(
Times
.
class
).
value
();
if
(
StrUtil
.
isNotEmpty
(
value
))
{
timesValue
=
value
;
}
}
}
return
timesValue
;
}
}
build.gradle
浏览文件 @
6ceb4aca
...
@@ -3,6 +3,8 @@ buildscript {
...
@@ -3,6 +3,8 @@ buildscript {
maven
{
url
"https://plugins.gradle.org/m2/"
}
maven
{
url
"https://plugins.gradle.org/m2/"
}
}
}
ext
{
ext
{
// https://start.spring.io/
springCloudVersion
=
'2021.0.2'
// https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter
// https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter
knife4jVersion
=
'2.0.9'
knife4jVersion
=
'2.0.9'
// https://mvnrepository.com/artifact/io.swagger/swagger-annotations
// https://mvnrepository.com/artifact/io.swagger/swagger-annotations
...
@@ -26,11 +28,9 @@ buildscript {
...
@@ -26,11 +28,9 @@ buildscript {
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
jtsVersion
=
'1.18.2'
jtsVersion
=
'1.18.2'
// https://mvnrepository.com/artifact/com.vladmihalcea/hibernate-types-55
// https://mvnrepository.com/artifact/com.vladmihalcea/hibernate-types-55
hibernateTypesVersion
=
'2.16.
1
'
hibernateTypesVersion
=
'2.16.
2
'
// https://mvnrepository.com/artifact/com.github.liaochong/myexcel
// https://mvnrepository.com/artifact/com.github.liaochong/myexcel
myexcelVersion
=
'4.1.1'
myexcelVersion
=
'4.1.1'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign
openfeignVersion
=
'3.1.1'
// https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp
// https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp
feignOkhttpVersion
=
'11.8'
feignOkhttpVersion
=
'11.8'
}
}
...
@@ -38,7 +38,7 @@ buildscript {
...
@@ -38,7 +38,7 @@ buildscript {
plugins
{
plugins
{
id
'java'
id
'java'
id
'org.springframework.boot'
version
'2.6.
6
'
id
'org.springframework.boot'
version
'2.6.
7
'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id
'io.spring.dependency-management'
version
'1.0.11.RELEASE'
id
'io.spring.dependency-management'
version
'1.0.11.RELEASE'
// https://plugins.gradle.org/plugin/com.diffplug.spotless
// https://plugins.gradle.org/plugin/com.diffplug.spotless
...
@@ -81,6 +81,12 @@ subprojects {
...
@@ -81,6 +81,12 @@ subprojects {
annotationProcessor
'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor
'org.springframework.boot:spring-boot-configuration-processor'
}
}
dependencyManagement
{
imports
{
mavenBom
"org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
[
compileJava
,
compileTestJava
,
javadoc
]*.
options
*.
encoding
=
'UTF-8'
[
compileJava
,
compileTestJava
,
javadoc
]*.
options
*.
encoding
=
'UTF-8'
tasks
.
withType
(
JavaCompile
)
{
tasks
.
withType
(
JavaCompile
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论