Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
40b73ea3
Commit
40b73ea3
authored
Sep 26, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor:
💡
lockupdate
parent
37a6c434
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
119 deletions
+156
-119
awards.controller.d.ts
v2.0/dist/controller/awards.controller.d.ts
+2
-2
stat.controller.d.ts
v2.0/dist/controller/stat.controller.d.ts
+1
-1
index.d.ts
v2.0/dist/index.d.ts
+2
-2
lockUpdate.d.ts
v2.0/dist/utils/package/lockUpdate.d.ts
+6
-2
lockUpdate.js
v2.0/dist/utils/package/lockUpdate.js
+94
-84
lockUpdate.js.map
v2.0/dist/utils/package/lockUpdate.js.map
+1
-1
lockUpdate.ts
v2.0/src/utils/package/lockUpdate.ts
+50
-27
No files found.
v2.0/dist/controller/awards.controller.d.ts
View file @
40b73ea3
...
...
@@ -32,11 +32,11 @@ export default class AwardsController {
/**
* 权益重新领取
*/
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{}:
{},
[
awardSer
]:
[
AwardsService
]):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
object
[]
|
number
[]
|
string
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
CodeType
|
IAwards
,
true
>>
;
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{}:
{},
[
awardSer
]:
[
AwardsService
]):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
string
[]
|
object
[]
|
number
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
CodeType
|
IAwards
,
true
>>
;
/**
* 概率抽奖
*/
drawLotteryPrize
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
]):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
object
[]
|
number
[]
|
string
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
{
drawLotteryPrize
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
]):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
string
[]
|
object
[]
|
number
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
{
data
:
{
type
:
number
;
name
:
string
;
...
...
v2.0/dist/controller/stat.controller.d.ts
View file @
40b73ea3
...
...
@@ -18,5 +18,5 @@ export default class StatController {
/**
* 统计数据
*/
getStats
(
context
:
IContext
<
IGetStatsParams
>
):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
object
[]
|
number
[]
|
string
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
any
,
true
>>
;
getStats
(
context
:
IContext
<
IGetStatsParams
>
):
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
string
[]
|
object
[]
|
number
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
any
,
true
>>
;
}
v2.0/dist/index.d.ts
View file @
40b73ea3
...
...
@@ -15,8 +15,8 @@ declare const _default: {
list
:
IAwards
[];
}
>>
;
receiveObjectPrize
:
(
context
:
IContext
<
import
(
"./controller/awards.controller"
).
IReceiveOjectParams
>
,
{}:
{},
[
awardSer
]:
[
import
(
"./service"
).
AwardsService
])
=>
Promise
<
IResult
<
boolean
>>
;
receiveEnamePrize
:
(
context
:
IContext
<
import
(
"./controller/awards.controller"
).
IReceiveEnameParams
>
,
{}:
{},
[
awardSer
]:
[
import
(
"./service"
).
AwardsService
])
=>
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
object
[]
|
number
[]
|
string
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
import
(
"taobao-mini-sdk/lib/utils/codetypes"
).
CodeType
|
IAwards
,
true
>>
;
receiveEnamePrize
:
(
context
:
IContext
<
import
(
"./controller/awards.controller"
).
IReceiveEnameParams
>
,
{}:
{},
[
awardSer
]:
[
import
(
"./service"
).
AwardsService
])
=>
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
string
[]
|
object
[]
|
number
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
import
(
"taobao-mini-sdk/lib/utils/codetypes"
).
CodeType
|
IAwards
,
true
>>
;
doHelp
:
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
vipInfo
,
activityInfo
}:
IControllerInfos
,
[
userService
,
taskService
,
accessService
]:
[
import
(
"./service/user.service"
).
default
,
import
(
"./service"
).
TaskService
,
import
(
"./service"
).
AccessService
])
=>
Promise
<
IResult
<
boolean
>>
;
getStats
:
(
context
:
IContext
<
import
(
"./controller/stat.controller"
).
IGetStatsParams
>
)
=>
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
object
[]
|
number
[]
|
string
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
any
,
true
>>
;
getStats
:
(
context
:
IContext
<
import
(
"./controller/stat.controller"
).
IGetStatsParams
>
)
=>
Promise
<
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
string
|
boolean
|
object
|
string
[]
|
object
[]
|
number
[],
false
>
|
import
(
"taobao-mini-sdk/lib/utils/resultmodel"
).
Result
<
any
,
true
>>
;
};
export
default
_default
;
v2.0/dist/utils/package/lockUpdate.d.ts
View file @
40b73ea3
/** @format */
export
interface
IDaoQuery
{
dao
:
IBaseDao
;
query
:
IMongoQuery
;
}
/**
* 并发更新
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
id:_id}}, {dao: activityprizedao, query: {id:_id
}}]
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
_id:_id}}, {dao: activityprizedao, query: {userNick, status ...
}}]
* @param {*} fn
* @param {*} times
*/
export
declare
const
lockUpdate
:
(
daoqueryArr
:
any
,
fn
:
any
,
times
?:
number
)
=>
Promise
<
any
>
;
export
declare
const
lockUpdate
:
(
daoqueryArr
:
IDaoQuery
[],
fn
:
()
=>
{},
times
?:
number
)
=>
Promise
<
{}
>
;
/**
* 调用示例
*/
v2.0/dist/utils/package/lockUpdate.js
View file @
40b73ea3
This diff is collapsed.
Click to expand it.
v2.0/dist/utils/package/lockUpdate.js.map
View file @
40b73ea3
{"version":3,"file":"lockUpdate.js","sourceRoot":"","sources":["../../../src/utils/package/lockUpdate.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,6CAA4C;AAE5C;;;;;GAKG;AACU,QAAA,UAAU,GAAG,UAAO,WAAW,EAAE,EAAE,EAAE,KAAS;IAAT,sBAAA,EAAA,SAAS;;QAoDzD,SAAS,OAAO,CAAC,EAAE;YACjB,OAAO,IAAI,OAAO,CAAC,UAAA,OAAO;gBACxB,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAA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C,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,EAAA;;oCAA7E,IAAI,GAAG,SAAsE;oCACjF,OAAO,CAAC,GAAG,CAAC,+BAAgB,EAAE,IAAI,CAAC,CAAA;oCACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oCACf,sBAAO,IAAI,EAAA;;;yBACZ,EAAE,EAAE,CAAC,EAAA;wBALN,sBAAO,SAKD,EAAA;;;;CACP;AAED,SAAe,IAAI,CAAC,WAAW;;;;;wBACtB,qBAAM,WAAW,CAAC,MAAM,CAAC,UAAO,IAAI,EAAE,QAAQ;;;;;oCACnD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;oCACtB,qBAAM,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,EAAA;;oCAA7E,IAAI,GAAG,SAAsE;oCACjF,OAAO,CAAC,GAAG,CAAC,+BAAgB,EAAE,IAAI,CAAC,CAAA;oCACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oCACf,sBAAO,IAAI,EAAA;;;yBACZ,EAAE,EAAE,CAAC,EAAA;wBANN,sBAAO,SAMD,EAAA;;;;CACP;AAED;;GAEG;AACH,MAAM;AACN,sFAAsF;AACtF,8DAA8D;AAC9D,8BAA8B;AAC9B,6BAA6B;AAC7B,SAAS;AACT,MAAM;AACN,oBAAoB;AACpB,cAAc;AACd,0CAA0C;AAC1C,IAAI;AACJ,eAAe"}
\ No newline at end of file
v2.0/src/utils/package/lockUpdate.ts
View file @
40b73ea3
...
...
@@ -2,40 +2,49 @@
import
{
CODE_TYPES
}
from
'../../constants'
export
interface
IDaoQuery
{
dao
:
IBaseDao
query
:
IMongoQuery
}
/**
* 并发更新
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
id:_id}}, {dao: activityprizedao, query: {id:_id
}}]
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
_id:_id}}, {dao: activityprizedao, query: {userNick, status ...
}}]
* @param {*} fn
* @param {*} times
*/
export
const
lockUpdate
=
async
(
daoqueryArr
,
fn
,
times
=
5
)
=>
{
if
(
typeof
daoqueryArr
!==
'object'
&&
!
Array
.
isArray
(
daoqueryArr
)
)
{
export
const
lockUpdate
=
async
(
daoqueryArr
:
IDaoQuery
[],
fn
:
()
=>
{}
,
times
=
5
)
=>
{
if
(
typeof
daoqueryArr
!==
'object'
)
{
console
.
log
(
`lockUpdate 参数错误`
)
return
false
}
if
(
typeof
daoqueryArr
===
'object'
)
{
if
(
!
(
daoqueryArr
instanceof
Array
)
)
{
daoqueryArr
=
[
daoqueryArr
]
}
let
error
=
false
for
(
let
i
=
0
;
i
<
daoqueryArr
.
length
;
i
++
)
{
let
daoquery
=
daoqueryArr
[
i
]
if
(
!
daoquery
.
dao
||
!
daoquery
.
query
)
{
error
=
true
console
.
log
(
`daoquery`
,
daoquery
)
break
}
}
if
(
error
)
{
throw
Error
(
`调用lockUpdate方法参数不符合规范`
)
}
let
time
=
0
console
.
log
(
`进入update并发处理次数`
,
times
)
let
success
=
false
try
{
while
(
time
++
<
times
&&
!
success
)
{
// 依次锁住表
let
updateRes
=
[]
daoqueryArr
.
forEach
(
async
daoquery
=>
{
let
canupdate
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
2
}
})
updateRes
.
push
(
canupdate
)
})
let
updateRes
=
await
lock
(
daoqueryArr
)
console
.
log
(
`updateRes`
,
updateRes
)
// 若都锁定成功了,执行内部调用
if
(
!
daoqueryArr
.
includes
(
0
))
{
if
(
updateRes
.
every
(
v
=>
v
===
1
))
{
const
ret
=
await
fn
()
daoqueryArr
.
forEach
(
async
daoquery
=>
{
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}
})
console
.
log
(
`更新lockStatus为0`
,
ures
)
})
console
.
log
(
`完成调用,解锁操作执行--------------`
)
await
unLock
(
daoqueryArr
)
success
=
true
return
ret
}
else
{
...
...
@@ -46,27 +55,41 @@ export const lockUpdate = async (daoqueryArr, fn, times = 5) => {
}
}
catch
(
e
)
{
console
.
log
(
e
)
daoqueryArr
.
forEach
(
async
daoquery
=>
{
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}
})
console
.
log
(
`更新lockStatus为0`
,
ures
)
})
success
=
false
await
unLock
(
daoqueryArr
)
success
=
true
}
console
.
log
(
`daoqueryArr`
,
daoqueryArr
)
// 稍后重试
if
(
!
success
)
{
daoqueryArr
.
forEach
(
async
daoquery
=>
{
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}
})
console
.
log
(
`操作
${
times
}
次后更新lockStatus为0`
,
ures
)
})
await
unLock
(
daoqueryArr
)
return
CODE_TYPES
.
ERROR_UPDATE_RETRY
}
function
waitFor
(
ms
)
{
function
waitFor
(
ms
:
number
)
{
return
new
Promise
(
resolve
=>
{
setTimeout
(
resolve
,
ms
)
})
}
}
async
function
unLock
(
daoqueryArr
)
{
return
await
daoqueryArr
.
reduce
(
async
(
prev
,
daoquery
)
=>
{
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}
})
console
.
log
(
`更新lockStatus为1`
,
ures
)
prev
.
push
(
ures
)
return
prev
},
[])
}
async
function
lock
(
daoqueryArr
)
{
return
await
daoqueryArr
.
reduce
(
async
(
prev
,
daoquery
)
=>
{
console
.
log
(
`daoquery`
,
daoquery
)
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
2
}
})
console
.
log
(
`更新lockStatus为2`
,
ures
)
prev
.
push
(
ures
)
return
prev
},
[])
}
/**
* 调用示例
*/
...
...
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