Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EventTracking
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨林
EventTracking
Commits
3af73789
Commit
3af73789
authored
Jul 23, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式化工具
parent
b589b91e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
0 deletions
+129
-0
src/main/scala/tools/dataprocess/DataFormat.scala
src/main/scala/tools/dataprocess/DataFormat.scala
+56
-0
src/main/scala/tools/timestamp/DateHelper.scala
src/main/scala/tools/timestamp/DateHelper.scala
+73
-0
No files found.
src/main/scala/tools/dataprocess/DataFormat.scala
0 → 100644
View file @
3af73789
package
tools.dataprocess
import
model.TrackItem
import
tools.geoip.GeoIp
import
tools.json.JsonUtils
import
tools.timestamp.DateHelper
/**
* Created with IntelliJ IDEA.
* Class: FormatTrack
* Description:
* User: lin
* Date: 2021-07-22
* Time: 17:03
*/
object
DataFormat
{
def
formatTrack
(
x
:
String
)
:
TrackItem
=
{
val
data
=
JsonUtils
parseFirstKey
x
val
data_decode
=
data
getOrElse
(
"data_decode"
,
""
)
val
dataMap
=
JsonUtils
parseFirstKey
data_decode
val
lib
=
dataMap
.
getOrElse
(
"lib"
,
""
)
val
libMap
=
JsonUtils
parseFirstKey
lib
val
ip
=
data
.
getOrElse
(
"ip"
,
""
).
replaceAll
(
"\""
,
""
)
TrackItem
(
track_id
=
dataMap
.
getOrElse
(
"_track_id"
,
""
).
replaceAll
(
"\""
,
""
).
toLong
,
distinct_id
=
dataMap
.
getOrElse
(
"distinct_id"
,
""
).
replaceAll
(
"\""
,
""
),
lib_detail
=
libMap
.
getOrElse
(
"$lib_detail"
,
""
).
replaceAll
(
"\""
,
""
),
lib_version
=
libMap
.
getOrElse
(
"$lib_version"
,
""
).
replaceAll
(
"\""
,
""
),
lib
=
libMap
.
getOrElse
(
"$lib"
,
""
).
replaceAll
(
"\""
,
""
),
app_version
=
libMap
.
getOrElse
(
"$app_version"
,
""
).
replaceAll
(
"\""
,
""
),
lib_method
=
libMap
.
getOrElse
(
"$lib_method"
,
""
).
replaceAll
(
"\""
,
""
),
event_name
=
dataMap
.
getOrElse
(
"event"
,
""
).
replaceAll
(
"\""
,
""
),
`type`
=
dataMap
.
getOrElse
(
"type"
,
""
).
replaceAll
(
"\""
,
""
),
properties
=
dataMap
.
getOrElse
(
"properties"
,
""
),
HOST
=
data
.
getOrElse
(
"Host"
,
""
).
replaceAll
(
"\""
,
""
),
user_agent
=
data
.
getOrElse
(
"User_Agent"
,
""
).
replaceAll
(
"\""
,
""
),
ua_platform
=
data
.
getOrElse
(
"ua_platform"
,
""
).
replaceAll
(
"\""
,
""
),
ua_version
=
data
.
getOrElse
(
"ua_version"
,
""
).
replaceAll
(
"\""
,
""
),
ua_language
=
data
.
getOrElse
(
"ua_language"
,
""
).
replaceAll
(
"\""
,
""
),
`connection`
=
data
.
getOrElse
(
"Connection"
,
""
).
replaceAll
(
"\""
,
""
),
Pragma
=
data
.
getOrElse
(
"Pragma"
,
""
).
replaceAll
(
"\""
,
""
),
cache_control
=
data
.
getOrElse
(
"Cache_Control"
,
""
).
replaceAll
(
"\""
,
""
),
accept
=
data
.
getOrElse
(
"Accept"
,
""
).
replaceAll
(
"\""
,
""
),
accept_encoding
=
data
.
getOrElse
(
"Accept_Encoding"
,
""
).
replaceAll
(
"\""
,
""
),
ip
=
ip
,
ip_info
=
JsonUtils
.
parseBeanToString
(
GeoIp
(
ip
).
getCity
),
url
=
data
.
getOrElse
(
"url"
,
""
).
replaceAll
(
"\""
,
""
),
referrer
=
data
.
getOrElse
(
"referrer"
,
""
).
replaceAll
(
"\""
,
""
),
remark
=
data
.
getOrElse
(
"remark"
,
""
).
replaceAll
(
"\""
,
""
),
user_id
=
data
.
getOrElse
(
"user_id"
,
""
).
replaceAll
(
"\""
,
""
),
created_at
=
DateHelper
.
parseTimestampToDataTime
(
data
.
getOrElse
(
"created_at"
,
""
).
toLong
)
)
}
}
src/main/scala/tools/timestamp/DateHelper.scala
0 → 100644
View file @
3af73789
package
tools.timestamp
import
java.text.SimpleDateFormat
import
java.time.format.
{
DateTimeFormatter
,
DateTimeFormatterBuilder
}
import
java.time.
{
OffsetDateTime
,
ZoneId
,
ZonedDateTime
}
import
java.util.Date
import
scala.language.postfixOps
/**
* Created with IntelliJ IDEA.
* Class: DateHelper
* Description: 时间处理类
* User: lin
* Date: 2021-07-19
* Time: 16:17
*/
object
DateHelper
{
private
[
this
]
val
DATE_TIME_FORMATTER
:
DateTimeFormatter
=
new
DateTimeFormatterBuilder
().
appendOptional
(
DateTimeFormatter
.
ISO_DATE_TIME
).
appendOptional
(
DateTimeFormatter
.
ISO_OFFSET_DATE_TIME
).
appendOptional
(
DateTimeFormatter
.
ISO_INSTANT
).
appendOptional
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss.SX"
)).
appendOptional
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ssX"
)).
appendOptional
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)).
toFormatter
.
withZone
(
ZoneId
.
systemDefault
())
/**
* 把时间字符串转换成标准时间
*
* @param str 时间字符串
* @return 标准时间
*/
def
parseDateTimeString
(
str
:
String
)
:
OffsetDateTime
=
ZonedDateTime
.
from
(
DATE_TIME_FORMATTER
.
parse
(
str
)).
toOffsetDateTime
/**
* 时间戳转换成时间
*
* @param timestamp 时间戳(毫秒)
* @param pattern 时间格式
* @return 指定格式的日期
*/
def
parseTimestampToDataTime
(
timestamp
:
Long
,
pattern
:
String
)
:
String
=
new
SimpleDateFormat
(
pattern
).
format
(
new
Date
(
formatTimestamp
(
timestamp
)))
/**
* 时间戳转换成时间(默认格式)
*
* @param timestamp 时间戳(毫秒)
* @return 默认格式“yyyy-MM-dd HH:mm:ss”
*/
def
parseTimestampToDataTime
(
timestamp
:
Long
)
:
String
=
parseTimestampToDataTime
(
formatTimestamp
(
timestamp
),
"yyyy-MM-dd HH:mm:ss"
)
/**
* 把时间格式定为毫秒,如果不是毫秒 x1000
*
* @param timestamp 时间戳
* @return 格式化时间戳
*/
def
formatTimestamp
(
timestamp
:
Long
)
:
Long
=
if
(
timestamp
.
toString
.
length
<
13
)
timestamp
*
1000
else
timestamp
/**
* 把时间转换成时间戳
*
* @param time 时间
* @param pattern 时间格式
* @return 时间戳
*/
def
parseDateTimeToTimestamp
(
time
:
String
,
pattern
:
String
)
:
Long
=
new
SimpleDateFormat
(
pattern
).
parse
(
time
).
getTime
/**
* 把时间转换成时间戳(默认格式)
*
* @param time 时间
* @return 时间戳(默认格式:”yyyy-MM-dd HH:mm:ss“)
*/
def
parseDateTimeToTimestamp
(
time
:
String
)
:
Long
=
parseDateTimeToTimestamp
(
time
,
"yyyy-MM-dd HH:mm:ss"
)
}
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