Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wj-datacenter-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
jinan
wj-datacenter-platform
Commits
39975e3a
Commit
39975e3a
authored
Feb 28, 2025
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 失衡优化记录优化时间处理逻辑
parent
d34dcb95
Pipeline
#52
failed with stages
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
5 deletions
+37
-5
CrossStrategyOptConsumerHandler.java
...nji/datacenter/kafka/CrossStrategyOptConsumerHandler.java
+2
-1
ImbalanceAlgorithmDTO.java
.../net/wanji/datacenter/pojo/dto/ImbalanceAlgorithmDTO.java
+3
-0
CrossStrategyResultEntity.java
...nji/datacenter/pojo/entity/CrossStrategyResultEntity.java
+2
-0
CrossStrategyOptServiceImpl.java
.../datacenter/service/impl/CrossStrategyOptServiceImpl.java
+27
-0
DataProcessServiceImpl.java
...wanji/datacenter/service/impl/DataProcessServiceImpl.java
+3
-4
No files found.
wj-datacenter-service/src/main/java/net/wanji/datacenter/kafka/CrossStrategyOptConsumerHandler.java
View file @
39975e3a
...
...
@@ -70,7 +70,8 @@ public class CrossStrategyOptConsumerHandler implements KafkaListenerErrorHandle
crossStrategyOptService
.
save
(
imbalanceAlgorithmDTO
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"当前失衡策略数据处理异常:{}"
,
message
);
log
.
error
(
"当前失衡策略数据处理异常:{}"
,
e
);
log
.
error
(
"当前失衡策略数据内容:{}"
,
message
);
throw
new
Exception
(
e
);
}
acknowledgment
.
acknowledge
();
...
...
wj-datacenter-service/src/main/java/net/wanji/datacenter/pojo/dto/ImbalanceAlgorithmDTO.java
View file @
39975e3a
...
...
@@ -59,6 +59,9 @@ public class ImbalanceAlgorithmDTO {
// 方案具体信息
private
SchemeData
data
;
private
Integer
isSuccessed
;
// 开始 = 1 结束 = -1
private
Integer
control_method
;
private
Integer
control_duration
;
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
...
...
wj-datacenter-service/src/main/java/net/wanji/datacenter/pojo/entity/CrossStrategyResultEntity.java
View file @
39975e3a
...
...
@@ -61,4 +61,6 @@ public class CrossStrategyResultEntity {
private
String
emptyTurn
;
@TableField
(
"dt"
)
private
Integer
dt
;
@TableField
(
"duration"
)
private
Integer
duration
;
}
wj-datacenter-service/src/main/java/net/wanji/datacenter/service/impl/CrossStrategyOptServiceImpl.java
View file @
39975e3a
package
net
.
wanji
.
datacenter
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
net.wanji.common.utils.tool.JacksonUtils
;
...
...
@@ -11,11 +12,14 @@ import net.wanji.datacenter.pojo.dto.ImbalanceAlgorithmDTO;
import
net.wanji.datacenter.pojo.dto.PhaseEmptyDataDTO
;
import
net.wanji.datacenter.pojo.entity.CrossStrategyResultEntity
;
import
net.wanji.datacenter.service.CrossStrategyOptService
;
import
org.apache.dubbo.common.utils.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
/**
...
...
@@ -97,6 +101,28 @@ public class CrossStrategyOptServiceImpl implements CrossStrategyOptService {
@Override
public
void
save
(
ImbalanceAlgorithmDTO
dto
)
{
try
{
if
(
Objects
.
equals
(-
1
,
dto
.
getControl_method
()))
{
String
crossId
=
dto
.
getCrossId
();
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
Date
issueTime
=
dto
.
getIssueTime
();
Date
date
=
new
Date
();
String
currentDate
=
format
.
format
(
date
);
LambdaQueryWrapper
<
CrossStrategyResultEntity
>
query
=
new
LambdaQueryWrapper
<
CrossStrategyResultEntity
>();
query
.
eq
(
CrossStrategyResultEntity:
:
getCrossId
,
crossId
);
query
.
eq
(
CrossStrategyResultEntity:
:
getDt
,
currentDate
);
query
.
orderByDesc
(
CrossStrategyResultEntity:
:
getIssueTime
);
query
.
last
(
"limit 1"
);
List
<
CrossStrategyResultEntity
>
results
=
crossStrategyResultMapper
.
selectList
(
query
);
if
(!
CollectionUtils
.
isEmpty
(
results
)
&&
results
.
size
()
==
1
)
{
CrossStrategyResultEntity
crossStrategyResultEntity
=
results
.
get
(
0
);
long
offset
=
date
.
getTime
()
-
issueTime
.
getTime
();
int
duration
=
(
int
)
(
offset
/
1000
);
log
.
warn
(
"当前失衡路口:{},当前路口发生事件:{}, 计算时间差:{}"
,
crossId
,
issueTime
,
duration
);
crossStrategyResultEntity
.
setDuration
(
duration
+
crossStrategyResultEntity
.
getDuration
());
crossStrategyResultMapper
.
updateById
(
crossStrategyResultEntity
);
}
return
;
}
ObjectMapper
mapper
=
JacksonUtils
.
getInstance
();
CrossStrategyResultEntity
crossStrategyResultEntity
=
new
CrossStrategyResultEntity
();
crossStrategyResultEntity
.
setCrossId
(
dto
.
getPlatformId
());
...
...
@@ -118,6 +144,7 @@ public class CrossStrategyOptServiceImpl implements CrossStrategyOptService {
crossStrategyResultEntity
.
setControlDir
(
dto
.
getControlDir
());
crossStrategyResultEntity
.
setData
(
mapper
.
writeValueAsString
(
dto
.
getData
()));
crossStrategyResultEntity
.
setResponseContent
(
dto
.
getResponseContent
());
crossStrategyResultEntity
.
setDuration
(
dto
.
getControl_duration
());
if
(
Objects
.
nonNull
(
issueTime
))
{
String
parse
=
DateUtil
.
format
(
issueTime
,
"yyyyMMdd"
);
crossStrategyResultEntity
.
setDt
(
Integer
.
valueOf
(
parse
));
...
...
wj-datacenter-service/src/main/java/net/wanji/datacenter/service/impl/DataProcessServiceImpl.java
View file @
39975e3a
package
net
.
wanji
.
datacenter
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException
;
import
lombok.extern.slf4j.Slf4j
;
import
net.wanji.common.utils.tool.BeanListUtils
;
import
net.wanji.databus.dao.mapper.*
;
...
...
@@ -166,7 +165,7 @@ public class DataProcessServiceImpl implements DataProcessService {
if
(
Objects
.
nonNull
(
eventInfoPO
))
{
Double
trafficIndex
=
crossDataRealtimePO
.
getTrafficIndex
();
eventInfoPO
.
setTrafficIndex
(
trafficIndex
);
while
(
retryCount
<=
3
)
{
while
(
retryCount
<=
5
)
{
try
{
eventInfoMapper
.
updateOne
(
eventInfoPO
);
return
;
...
...
@@ -175,9 +174,9 @@ public class DataProcessServiceImpl implements DataProcessService {
log
.
warn
(
"检测到死锁,进行第 {} 次重试"
,
retryCount
);
try
{
// 等待一会,避免立刻冲突
Thread
.
sleep
(
1
00
);
Thread
.
sleep
(
3
00
);
}
catch
(
InterruptedException
ignored
)
{
log
.
warn
(
"检测到死锁, Thread.sleep
1
00ms,异常:{}"
,
ignored
);
log
.
warn
(
"检测到死锁, Thread.sleep
3
00ms,异常:{}"
,
ignored
);
}
}
}
...
...
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