记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
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
董敬伟
liquidnet-bus-v1
Commits
5c5d7c58
Commit
5c5d7c58
authored
Jun 19, 2021
by
胡佳晨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
脚本增加锁逻辑
parent
4e185e95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
81 deletions
+82
-81
KylinOrderTicketsServiceImpl.java
...vice/kylin/service/impl/KylinOrderTicketsServiceImpl.java
+82
-81
No files found.
liquidnet-bus-service/liquidnet-service-kylin/liquidnet-service-kylin-impl/src/main/java/com/liquidnet/service/kylin/service/impl/KylinOrderTicketsServiceImpl.java
View file @
5c5d7c58
...
...
@@ -1015,99 +1015,100 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
@Override
public
boolean
checkOrderTime
(
String
userId
)
{
List
<
OrderScriptDto
>
dtoData
=
orderTicketsMapper
.
orderScriptDto
(
userId
);
HashMap
<
String
,
Integer
>
map2
=
new
HashMap
<>();
Integer
count
=
0
;
Integer
mqCount
=
0
;
Integer
Acount
=
0
;
for
(
OrderScriptDto
item
:
dtoData
)
{
count
+=
1
;
LinkedList
<
String
>
sqls
=
new
LinkedList
<>();
String
lock
=
"order_lock:"
+
item
.
getOrderCode
();
// if (!redisLockUtil.tryLock(lock, 30, 240)) {
// continue;
// }
if
(
item
.
getStatus
()
==
KylinTableStatusConst
.
ORDER_STATUS0
)
{
LocalDateTime
now
=
LocalDateTime
.
now
();
try
{
KylinOrderTicketVo
vo
=
dataUtils
.
getOrderTicketVo
(
item
.
getOrderTicketsId
());
if
(
vo
.
getStatus
()
!=
0
)
{
continue
;
}
String
lock
=
"order_lock:checkOrderTime:"
+
userId
;
try
{
if
(
redisLockUtil
.
tryLock
(
lock
,
1
,
3600
))
{
List
<
OrderScriptDto
>
dtoData
=
orderTicketsMapper
.
orderScriptDto
(
userId
);
HashMap
<
String
,
Integer
>
map2
=
new
HashMap
<>();
Integer
count
=
0
;
Integer
mqCount
=
0
;
Integer
Acount
=
0
;
for
(
OrderScriptDto
item
:
dtoData
)
{
count
+=
1
;
LinkedList
<
String
>
sqls
=
new
LinkedList
<>();
if
(
item
.
getStatus
()
==
KylinTableStatusConst
.
ORDER_STATUS0
)
{
LocalDateTime
now
=
LocalDateTime
.
now
();
try
{
KylinOrderTicketVo
vo
=
dataUtils
.
getOrderTicketVo
(
item
.
getOrderTicketsId
());
if
(
vo
.
getStatus
()
!=
0
)
{
continue
;
}
//mysql
KylinOrderTickets
orderTickets
=
new
KylinOrderTickets
();
orderTickets
.
setOrderTicketsId
(
item
.
getOrderTicketsId
());
orderTickets
.
setUpdatedAt
(
now
);
KylinOrderTicketStatus
orderTicketStatus
=
new
KylinOrderTicketStatus
();
orderTicketStatus
.
setOrderId
(
item
.
getOrderTicketsId
());
orderTicketStatus
.
setStatus
(
KylinTableStatusConst
.
ORDER_STATUS2
);
orderTicketStatus
.
setUpdatedAt
(
now
);
//vo
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"status"
,
KylinTableStatusConst
.
ORDER_STATUS2
);
map
.
put
(
"updatedAt"
,
DateUtil
.
Formatter
.
yyyyMMddHHmmssSSS
.
format
(
now
));
map
.
put
(
"changeDate"
,
now
);
mongoTemplate
.
getCollection
(
KylinOrderTicketVo
.
class
.
getSimpleName
()).
updateOne
(
Query
.
query
(
Criteria
.
where
(
"orderTicketsId"
).
is
(
orderTickets
.
getOrderTicketsId
())).
getQueryObject
(),
new
BasicDBObject
(
"$set"
,
mongoConverter
.
convertToMongoType
(
map
))
);
LocalDateTime
strTime
=
vo
.
getChangeDate
();
vo
.
setChangeDate
(
now
);
vo
.
setStatus
(
KylinTableStatusConst
.
ORDER_STATUS2
);
vo
.
setUpdatedAt
(
DateUtil
.
Formatter
.
yyyyMMddHHmmssSSS
.
format
(
now
));
redisUtil
.
set
(
KylinRedisConst
.
ORDER
+
vo
.
getOrderTicketsId
(),
vo
);
map2
.
put
(
vo
.
getTicketId
(),
map2
.
get
(
vo
.
getTicketId
())
==
null
?
vo
.
getNumber
()
:
map2
.
get
(
vo
.
getTicketId
())
+
vo
.
getNumber
());
mongoVoUtils
.
resetOrderListVo
(
item
.
getUserId
(),
2
,
item
.
getOrderTicketsId
(),
vo
);
Acount
+=
1
;
//mysql
KylinOrderTickets
orderTickets
=
new
KylinOrderTickets
();
orderTickets
.
setOrderTicketsId
(
item
.
getOrderTicketsId
());
orderTickets
.
setUpdatedAt
(
now
);
KylinOrderTicketStatus
orderTicketStatus
=
new
KylinOrderTicketStatus
();
orderTicketStatus
.
setOrderId
(
item
.
getOrderTicketsId
());
orderTicketStatus
.
setStatus
(
KylinTableStatusConst
.
ORDER_STATUS2
);
orderTicketStatus
.
setUpdatedAt
(
now
);
//vo
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"status"
,
KylinTableStatusConst
.
ORDER_STATUS2
);
map
.
put
(
"updatedAt"
,
DateUtil
.
Formatter
.
yyyyMMddHHmmssSSS
.
format
(
now
));
map
.
put
(
"changeDate"
,
now
);
mongoTemplate
.
getCollection
(
KylinOrderTicketVo
.
class
.
getSimpleName
()).
updateOne
(
Query
.
query
(
Criteria
.
where
(
"orderTicketsId"
).
is
(
orderTickets
.
getOrderTicketsId
())).
getQueryObject
(),
new
BasicDBObject
(
"$set"
,
mongoConverter
.
convertToMongoType
(
map
))
);
LocalDateTime
strTime
=
vo
.
getChangeDate
();
vo
.
setChangeDate
(
now
);
vo
.
setStatus
(
KylinTableStatusConst
.
ORDER_STATUS2
);
vo
.
setUpdatedAt
(
DateUtil
.
Formatter
.
yyyyMMddHHmmssSSS
.
format
(
now
));
redisUtil
.
set
(
KylinRedisConst
.
ORDER
+
vo
.
getOrderTicketsId
(),
vo
);
map2
.
put
(
vo
.
getTicketId
(),
map2
.
get
(
vo
.
getTicketId
())
==
null
?
vo
.
getNumber
()
:
map2
.
get
(
vo
.
getTicketId
())
+
vo
.
getNumber
());
mongoVoUtils
.
resetOrderListVo
(
item
.
getUserId
(),
2
,
item
.
getOrderTicketsId
(),
vo
);
Acount
+=
1
;
// List<KylinOrderTicketEntities> entities = entitiesMapper.selectList(new UpdateWrapper<KylinOrderTicketEntities>().eq("order_id", item.getOrderTicketsId()));
List
<
KylinOrderTicketEntitiesVo
>
entities
=
vo
.
getEntitiesVoList
();
List
<
KylinOrderTicketEntitiesVo
>
entities
=
vo
.
getEntitiesVoList
();
// entitiesMapper.selectList(new UpdateWrapper<KylinOrderTicketEntities>().eq("order_id", item.getOrderTicketsId()));
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
KylinOrderTicketEntitiesVo
items
=
entities
.
get
(
i
);
dataUtils
.
changeBuyInfo
(
items
.
getUserId
(),
items
.
getEnterIdCode
(),
items
.
getPerformanceId
(),
items
.
getTicketId
(),
-
1
);
}
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
KylinOrderTicketEntitiesVo
items
=
entities
.
get
(
i
);
dataUtils
.
changeBuyInfo
(
items
.
getUserId
(),
items
.
getEnterIdCode
(),
items
.
getPerformanceId
(),
items
.
getTicketId
(),
-
1
);
}
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket.close"
));
LinkedList
<
Object
[]>
sqlsDataA
=
new
LinkedList
<>();
sqlsDataA
.
add
(
orderTickets
.
getCloseOrderObject
(
strTime
,
strTime
));
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket.close"
));
LinkedList
<
Object
[]>
sqlsDataA
=
new
LinkedList
<>();
sqlsDataA
.
add
(
orderTickets
.
getCloseOrderObject
(
strTime
,
strTime
));
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket_status.close"
));
LinkedList
<
Object
[]>
sqlsDataB
=
new
LinkedList
<>();
sqlsDataB
.
add
(
orderTicketStatus
.
getCloseOrderObject
(
strTime
,
strTime
));
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket_status.close"
));
LinkedList
<
Object
[]>
sqlsDataB
=
new
LinkedList
<>();
sqlsDataB
.
add
(
orderTicketStatus
.
getCloseOrderObject
(
strTime
,
strTime
));
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket_relation.close"
));
LinkedList
<
Object
[]>
sqlsDataC
=
new
LinkedList
<>();
sqlsDataC
.
add
(
new
Object
[]{
orderTickets
.
getUpdatedAt
(),
orderTickets
.
getOrderTicketsId
(),
strTime
,
strTime
});
sqls
.
add
(
SqlMapping
.
get
(
"kylin_order_ticket_relation.close"
));
LinkedList
<
Object
[]>
sqlsDataC
=
new
LinkedList
<>();
sqlsDataC
.
add
(
new
Object
[]{
orderTickets
.
getUpdatedAt
(),
orderTickets
.
getOrderTicketsId
(),
strTime
,
strTime
});
rabbitTemplate
.
convertAndSend
(
MQConst
.
EXCHANGES_LIQUIDNET_SQL_ORDER_CLOSE
,
MQConst
.
ROUTING_KEY_SQL_ORDER_CLOSE
,
SqlMapping
.
gets
(
sqls
,
sqlsDataA
,
sqlsDataB
,
sqlsDataC
));
mqCount
+=
1
;
}
catch
(
Exception
e
)
{
//redisLockUtil.unlock(lock);
log
.
debug
(
"CHECK TIME SYNC = "
+
e
.
getMessage
());
e
.
printStackTrace
();
return
false
;
rabbitTemplate
.
convertAndSend
(
MQConst
.
EXCHANGES_LIQUIDNET_SQL_ORDER_CLOSE
,
MQConst
.
ROUTING_KEY_SQL_ORDER_CLOSE
,
SqlMapping
.
gets
(
sqls
,
sqlsDataA
,
sqlsDataB
,
sqlsDataC
));
mqCount
+=
1
;
}
catch
(
Exception
e
)
{
log
.
debug
(
"CHECK TIME SYNC = "
+
e
.
getMessage
());
e
.
printStackTrace
();
return
false
;
}
}
}
log
.
debug
(
"COUNT 1 = "
+
count
);
log
.
debug
(
"COUNT 2 = "
+
mqCount
);
log
.
debug
(
"COUNT 3 = "
+
Acount
);
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map2
.
entrySet
())
{
dataUtils
.
changeSurplusGeneral
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
else
{
//redisLockUtil.unlock(lock
);
log
.
debug
(
"WARNING LOCKING"
);
}
}
catch
(
Exception
e
)
{
redisLockUtil
.
unlock
(
lock
);
return
false
;
}
finally
{
redisLockUtil
.
unlock
(
lock
);
}
log
.
debug
(
"COUNT 1 = "
+
count
);
log
.
debug
(
"COUNT 2 = "
+
mqCount
);
log
.
debug
(
"COUNT 3 = "
+
Acount
);
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map2
.
entrySet
())
{
dataUtils
.
changeSurplusGeneral
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
true
;
}
...
...
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