Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
e012e7c0
Commit
e012e7c0
authored
Oct 09, 2023
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加TdEngine
parent
75f985d2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
189 additions
and
26 deletions
+189
-26
pom.xml
...system-jxiop/amos-boot-module-jxiop-bigscreen-biz/pom.xml
+5
-0
TdEngineConfig.java
...oin/amos/boot/module/jxiop/biz/config/TdEngineConfig.java
+73
-0
IndicatorData.java
...join/amos/boot/module/jxiop/biz/entity/IndicatorData.java
+37
-0
LargeScreenImpl.java
...s/boot/module/jxiop/biz/service/impl/LargeScreenImpl.java
+8
-7
PowerGenerationImpl.java
...ot/module/jxiop/biz/service/impl/PowerGenerationImpl.java
+59
-19
application-dev.properties
...gscreen-biz/src/main/resources/application-dev.properties
+7
-0
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/pom.xml
View file @
e012e7c0
...
...
@@ -41,6 +41,11 @@
<version>
1.9.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
3.2.4
</version>
</dependency>
</dependencies>
<build>
...
...
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/config/TdEngineConfig.java
0 → 100644
View file @
e012e7c0
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jxiop
.
biz
.
config
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
javax.sql.DataSource
;
/**
* 从数据源配置
* 若需要配置更多数据源 , 直接在yml中添加数据源配置再增加相应的新的数据源配置类即可
*/
@Configuration
@MapperScan
(
basePackages
=
"com.yeejoin.amos.boot.module.jxiop.biz.tdmapper"
,
sqlSessionFactoryRef
=
"taosSqlSessionFactory"
)
public
class
TdEngineConfig
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TdEngineConfig
.
class
);
// 精确到 cluster 目录,以便跟其他数据源隔离
private
static
final
String
MAPPER_LOCATION
=
"classpath*:mapper/tdengine/*.xml"
;
@Value
(
"${spring.db3.datasource.url}"
)
private
String
dbUrl
;
@Value
(
"${spring.db3.datasource.username}"
)
private
String
username
;
@Value
(
"${spring.db3.datasource.password}"
)
private
String
password
;
@Value
(
"${spring.db3.datasource.driver-class-name}"
)
private
String
driverClassName
;
@Bean
(
name
=
"taosDataSource"
)
//声明其为Bean实例
public
DataSource
clusterDataSource
()
{
DruidDataSource
datasource
=
new
DruidDataSource
();
datasource
.
setUrl
(
this
.
dbUrl
);
datasource
.
setUsername
(
username
);
datasource
.
setPassword
(
password
);
datasource
.
setDriverClassName
(
driverClassName
);
return
datasource
;
}
@Bean
(
name
=
"taosTransactionManager"
)
public
DataSourceTransactionManager
clusterTransactionManager
()
{
return
new
DataSourceTransactionManager
(
clusterDataSource
());
}
@Bean
(
name
=
"taosSqlSessionFactory"
)
public
SqlSessionFactory
clusterSqlSessionFactory
(
@Qualifier
(
"taosDataSource"
)
DataSource
culsterDataSource
)
throws
Exception
{
final
MybatisSqlSessionFactoryBean
sessionFactory
=
new
MybatisSqlSessionFactoryBean
();
sessionFactory
.
setDataSource
(
culsterDataSource
);
sessionFactory
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
()
.
getResources
(
TdEngineConfig
.
MAPPER_LOCATION
));
sessionFactory
.
setTypeAliasesPackage
(
"com.yeejoin.amos.boot.module.jxiop.biz.entity"
);
//mybatis 数据库字段与实体类属性驼峰映射配置
sessionFactory
.
getObject
().
getConfiguration
().
setMapUnderscoreToCamelCase
(
true
);
return
sessionFactory
.
getObject
();
}
}
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/entity/IndicatorData.java
0 → 100644
View file @
e012e7c0
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jxiop
.
biz
.
entity
;
import
lombok.Data
;
import
java.util.Date
;
@Data
public
class
IndicatorData
{
private
String
id
;
private
String
address
;
private
String
dataType
;
private
String
equipmentSpecificName
;
private
String
gatewayId
;
private
String
isAlarm
;
private
Date
createdTime
;
private
String
unit
;
private
String
value
;
private
Float
valueF
;
private
String
valueLabel
;
private
String
equipmentIndexName
;
private
String
equipmentNumber
;
private
String
displayName
;
}
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/LargeScreenImpl.java
View file @
e012e7c0
...
...
@@ -306,6 +306,7 @@ public class LargeScreenImpl {
ybfbn
=
new
BigDecimal
(
ybfbn
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
mapdta
.
put
(
"NJHWC"
,
ybfbn
);
try
{
System
.
out
.
println
(
JSON
.
toJSONString
(
mapdta
));
emqKeeper
.
getMqttClient
().
publish
(
"qyyxzb/"
+
s
,
JSON
.
toJSONString
(
mapdta
).
getBytes
(),
0
,
false
);
}
catch
(
MqttException
e
)
{
e
.
printStackTrace
();
...
...
@@ -417,13 +418,13 @@ public class LargeScreenImpl {
List
<
String
>
value
=
new
ArrayList
<>();
value
.
add
(
RSD
);
Map
<
String
,
List
<
String
>>
map
=
new
HashMap
<>();
map
.
put
(
"equipmentIndexName"
,
value
);
map
.
put
(
"equipmentIndexName
.keyword
"
,
value
);
List
<
String
>
value1
=
new
ArrayList
<>();
value1
.
add
(
monthy
);
map
.
put
(
"moon"
,
value1
);
map
.
put
(
"moon
.keyword
"
,
value1
);
List
<?
extends
Terms
.
Bucket
>
lidate
=
commonServiceImpl
.
getgroupsum
(
map
,
"value"
,
"day"
,
ESDailyPowerGeneration
.
class
);
List
<?
extends
Terms
.
Bucket
>
lidate
=
commonServiceImpl
.
getgroupsum
(
map
,
"value"
,
"day
.keyword
"
,
ESDailyPowerGeneration
.
class
);
Map
<
String
,
Double
>
mapdta
=
new
HashMap
<>();
DecimalFormat
format2
=
new
DecimalFormat
(
"#.0000"
);
...
...
@@ -466,13 +467,13 @@ public class LargeScreenImpl {
List
<
String
>
value
=
new
ArrayList
<>();
value
.
add
(
RSD
);
Map
<
String
,
List
<
String
>>
map
=
new
HashMap
<>();
map
.
put
(
"equipmentIndexName"
,
value
);
map
.
put
(
"gatewayId"
,
gatewayId
);
map
.
put
(
"equipmentIndexName
.keyword
"
,
value
);
map
.
put
(
"gatewayId
.keyword
"
,
gatewayId
);
List
<
String
>
value1
=
new
ArrayList
<>();
value1
.
add
(
monthy
);
map
.
put
(
"moon"
,
value1
);
map
.
put
(
"moon
.keyword
"
,
value1
);
List
<?
extends
Terms
.
Bucket
>
lidate
=
commonServiceImpl
.
getgroupsum
(
map
,
"value"
,
"day"
,
ESDailyPowerGeneration
.
class
);
List
<?
extends
Terms
.
Bucket
>
lidate
=
commonServiceImpl
.
getgroupsum
(
map
,
"value"
,
"day
.keyword
"
,
ESDailyPowerGeneration
.
class
);
Map
<
String
,
Double
>
mapdta
=
new
HashMap
<>();
DecimalFormat
format2
=
new
DecimalFormat
(
"#.0000"
);
...
...
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/PowerGenerationImpl.java
View file @
e012e7c0
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jxiop
.
biz
.
service
.
impl
;
//package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto
;
import
com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration
;
import
com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration
;
import
com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESYearPowerGeneration
;
import
com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans
;
import
com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto
;
import
com.yeejoin.amos.boot.module.jxiop.biz.entity.IndicatorData
;
import
com.yeejoin.amos.boot.module.jxiop.biz.repository.ESDailyPowerGenerationRepository
;
import
com.yeejoin.amos.boot.module.jxiop.biz.repository.ESMoonPowerGenerationRepository
;
import
com.yeejoin.amos.boot.module.jxiop.biz.repository.ESYearPowerGenerationRepository
;
import
com.yeejoin.amos.boot.module.jxiop.biz.tdmapper.IndicatorDataMapper
;
import
com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.stereotype.Service
;
...
...
@@ -38,7 +42,8 @@ public class PowerGenerationImpl {
ESMoonPowerGenerationRepository
moonPowerGenerationRepository
;
@Autowired
ESDailyPowerGenerationRepository
dailyPowerGenerationRepository
;
@Autowired
(
required
=
true
)
IndicatorDataMapper
indicatorDataMapper
;
//获取指定指标,当天最后一条数据
public
List
<
IndexDto
>
getlast
(
String
gatewayId
,
String
value
,
String
daty
){
...
...
@@ -67,23 +72,45 @@ public class PowerGenerationImpl {
//@Async("jxiopAsyncExecutor")
public
void
addPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
String
gatewayId
,
String
value
,
String
dateFormat
,
String
type
,
String
stationType
,
String
datyvalue
){
//获取指标值
List
<
IndexDto
>
indexDto
=
null
;
// List<IndexDto> indexDto=null;
List
<
IndicatorData
>
indexDto
=
null
;
Date
currentDayStartTime
=
DateUtils
.
getCurrentDayStartTime
(
new
Date
());
Date
currentDayEndTime
=
DateUtils
.
getCurrentDayEndTime
(
new
Date
());
String
startTime
=
DateUtils
.
convertDateToString
(
currentDayStartTime
,
DateUtils
.
DATE_TIME_PATTERN
);
String
endTime
=
DateUtils
.
convertDateToString
(
currentDayEndTime
,
DateUtils
.
DATE_TIME_PATTERN
);
Double
flags
=
null
;
if
(
"FDZ"
.
equals
(
stationType
)){
indexDto
=
this
.
getlast
(
gatewayId
,
value
,
datyvalue
);
//indexDto= this.getlast(gatewayId,value, datyvalue);
indexDto
=
indicatorDataMapper
.
selectlastfd
(
value
,
gatewayId
,
startTime
,
endTime
);
}
else
{
//增加系数转化
//"日发电量"
if
(
"日发电量"
.
equals
(
value
)){
//"日发电量"
flags
=
CommonConstans
.
pvGenPoweActor
*
CommonConstans
.
pvGenPoweActorDay
;
}
else
if
(
"月发电量"
.
equals
(
value
)){
//"月发电量"
flags
=
CommonConstans
.
pvGenPoweActornew
;
}
else
{
indexDto
=
this
.
getlastgf
(
gatewayId
,
value
,
datyvalue
);
//"年发电量"
flags
=
CommonConstans
.
pvGenPoweActorYear
;
}
indexDto
=
indicatorDataMapper
.
selectlastgf
(
value
,
gatewayId
,
startTime
,
endTime
);
//indexDto= this.getlastgf(gatewayId,value,datyvalue);
}
SimpleDateFormat
myFmt2
=
new
SimpleDateFormat
(
dateFormat
);
Date
now
=
new
Date
();
String
daty
=
myFmt2
.
format
(
now
);
this
.
PowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
type
);
this
.
PowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
type
,
flags
);
}
//更新es
public
void
PowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
IndexDto
>
indexDto
,
String
daty
,
String
type
){
public
void
PowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
IndicatorData
>
indexDto
,
String
daty
,
String
type
,
Double
flags
){
Calendar
calendar
=
Calendar
.
getInstance
();
int
day
=
calendar
.
get
(
Calendar
.
DATE
);
int
month
=
calendar
.
get
(
Calendar
.
MONTH
)
+
1
;
...
...
@@ -100,15 +127,15 @@ public class PowerGenerationImpl {
switch
(
type
)
{
case
"day"
:
List
<
ESDailyPowerGeneration
>
listd
=
this
.
getESDailyPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
day
),
monthy
);
List
<
ESDailyPowerGeneration
>
listd
=
this
.
getESDailyPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
day
),
monthy
,
flags
);
dailyPowerGenerationRepository
.
saveAll
(
listd
);
break
;
case
"moon"
:
List
<
ESMoonPowerGeneration
>
listm
=
this
.
getESMoonPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
month
),
yeary
);
List
<
ESMoonPowerGeneration
>
listm
=
this
.
getESMoonPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
month
),
yeary
,
flags
);
moonPowerGenerationRepository
.
saveAll
(
listm
);
break
;
case
"year"
:
List
<
ESYearPowerGeneration
>
listy
=
this
.
getESYearPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
year
));
List
<
ESYearPowerGeneration
>
listy
=
this
.
getESYearPowerGeneration
(
stationCacheInfoDto
,
indexDto
,
daty
,
String
.
valueOf
(
year
)
,
flags
);
yearPowerGenerationRepository
.
saveAll
(
listy
);
break
;
default
:
...
...
@@ -119,11 +146,16 @@ public class PowerGenerationImpl {
// 组装数据
public
List
<
ESDailyPowerGeneration
>
getESDailyPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
IndexDto
>
indexDto
,
String
daty
,
String
day
,
String
month
){
public
List
<
ESDailyPowerGeneration
>
getESDailyPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
IndicatorData
>
indexDto
,
String
daty
,
String
day
,
String
month
,
Double
flags
){
List
<
ESDailyPowerGeneration
>
list
=
new
ArrayList
<>();
if
(
indexDto
!=
null
&&!
indexDto
.
isEmpty
()){
for
(
IndexDto
dto
:
indexDto
)
{
for
(
IndicatorData
dto
:
indexDto
)
{
double
value
=
dto
.
getValueF
()!=
null
?(
double
)
dto
.
getValueF
():
0.0
;
if
(
flags
!=
null
){
value
=
value
*
flags
;
}
ESDailyPowerGeneration
dailyPowerGeneration
=
new
ESDailyPowerGeneration
(
daty
+
"_"
+
dto
.
getAddress
(),
stationCacheInfoDto
.
getStationId
(),
...
...
@@ -134,7 +166,7 @@ public class PowerGenerationImpl {
day
,
dto
.
getGatewayId
(),
new
Date
(),
dto
.
getValue
()!=
null
?
Double
.
valueOf
(
dto
.
getValue
()):
null
,
value
,
dto
.
getEquipmentIndexName
(),
dto
.
getEquipmentNumber
(),
dto
.
getAddress
(),
...
...
@@ -145,10 +177,14 @@ public class PowerGenerationImpl {
}
return
list
;
}
public
List
<
ESMoonPowerGeneration
>
getESMoonPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
Ind
exDto
>
indexDto
,
String
daty
,
String
day
,
String
year
){
public
List
<
ESMoonPowerGeneration
>
getESMoonPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
Ind
icatorData
>
indexDto
,
String
daty
,
String
day
,
String
year
,
Double
flags
){
List
<
ESMoonPowerGeneration
>
list
=
new
ArrayList
<>();
if
(
indexDto
!=
null
&&!
indexDto
.
isEmpty
()){
for
(
IndexDto
dto
:
indexDto
)
{
for
(
IndicatorData
dto
:
indexDto
)
{
double
value
=
dto
.
getValueF
()!=
null
?(
double
)
dto
.
getValueF
():
0.0
;
if
(
flags
!=
null
){
value
=
value
*
flags
;
}
ESMoonPowerGeneration
moonPowerGeneration
=
new
ESMoonPowerGeneration
(
daty
+
"_"
+
dto
.
getAddress
(),
stationCacheInfoDto
.
getStationId
(),
...
...
@@ -159,7 +195,7 @@ public class PowerGenerationImpl {
day
,
dto
.
getGatewayId
(),
new
Date
(),
dto
.
getValue
()!=
null
?
Double
.
valueOf
(
dto
.
getValue
()):
null
,
value
,
dto
.
getEquipmentIndexName
(),
dto
.
getEquipmentNumber
(),
dto
.
getAddress
(),
...
...
@@ -170,10 +206,14 @@ public class PowerGenerationImpl {
}
return
list
;
}
public
List
<
ESYearPowerGeneration
>
getESYearPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
Ind
exDto
>
indexDto
,
String
daty
,
String
day
){
public
List
<
ESYearPowerGeneration
>
getESYearPowerGeneration
(
StationCacheInfoDto
stationCacheInfoDto
,
List
<
Ind
icatorData
>
indexDto
,
String
daty
,
String
day
,
Double
flags
){
List
<
ESYearPowerGeneration
>
list
=
new
ArrayList
<>();
if
(
indexDto
!=
null
&&!
indexDto
.
isEmpty
()){
for
(
IndexDto
dto
:
indexDto
)
{
for
(
IndicatorData
dto
:
indexDto
)
{
double
value
=
dto
.
getValueF
()!=
null
?(
double
)
dto
.
getValueF
():
0.0
;
if
(
flags
!=
null
){
value
=
value
*
flags
;
}
ESYearPowerGeneration
yearPowerGeneration
=
new
ESYearPowerGeneration
(
daty
+
"_"
+
dto
.
getAddress
(),
stationCacheInfoDto
.
getStationId
(),
...
...
@@ -184,7 +224,7 @@ public class PowerGenerationImpl {
day
,
dto
.
getGatewayId
(),
new
Date
(),
dto
.
getValue
()!=
null
?
Double
.
valueOf
(
dto
.
getValue
()):
null
,
value
,
dto
.
getEquipmentIndexName
(),
dto
.
getEquipmentNumber
(),
dto
.
getAddress
()
...
...
amos-boot-system-jxiop/amos-boot-module-jxiop-bigscreen-biz/src/main/resources/application-dev.properties
View file @
e012e7c0
...
...
@@ -12,6 +12,13 @@ spring.db2.datasource.username=root
spring.db2.datasource.password
=
Yeejoin@2020
spring.db2.datasource.driver-class-name
:
com.mysql.cj.jdbc.Driver
spring.db3.datasource.url
=
jdbc:TAOS-RS://139.9.170.47:6041/iot_data?user=root&password=taosdata&timezone=GMT%2b8&allowMultiQueries=true
spring.db3.datasource.username
=
root
spring.db3.datasource.password
=
taosdata
spring.db3.datasource.driver-class-name
:
com.taosdata.jdbc.rs.RestfulDriver
## eureka properties:
eureka.instance.hostname
=
172.16.10.220
eureka.client.serviceUrl.defaultZone
=
http://admin:a1234560@${eureka.instance.hostname}:10001/eureka/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment