Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
117293c7
Commit
117293c7
authored
Mar 29, 2020
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
735ed0fe
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
236 additions
and
20 deletions
+236
-20
bpo-web/app/base/api/impl/testApi.js
+15
-3
bpo-web/app/base/service/impl/dkcontractSve.js
+33
-0
bpo-web/app/base/service/impl/econtractSve.js
+33
-0
bpo-web/app/base/service/impl/entcontractSve.js
+33
-0
bpo-web/app/base/utils/downcontractClient.js
+54
-0
bpo-web/app/base/utils/publishClient.js
+63
-0
bpo-web/app/base/utils/redisClient.js
+5
-17
No files found.
bpo-web/app/base/api/impl/testApi.js
View file @
117293c7
...
...
@@ -10,11 +10,23 @@ var moment = require('moment')
class
TestApi
{
constructor
()
{
this
.
utilesignbaoSve
=
System
.
getObject
(
"service.utilesignbaoSve"
);
this
.
redisClient
=
System
.
getObject
(
"util.redisClient"
);
this
.
downcontractClient
=
System
.
getObject
(
"util.downcontractClient"
);
// this.publishClient = System.getObject("util.publishClient");
}
async
personTwo
()
{
let
rs
=
await
this
.
utilesignbaoSve
.
personTwo
({
name
:
"王昆"
,
"idno"
:
"222403198301071778"
},
"test"
);
return
rs
;
async
testAddDL
(
obj
)
{
let
contracts
=
obj
.
contracts
||
[];
for
(
let
p
of
contracts
)
{
await
this
.
redisClient
.
rpush
(
"bpo:contract:download"
,
JSON
.
stringify
(
p
));
}
return
{
msg
:
"success"
}
}
async
donloadContract
(
obj
)
{
this
.
downcontractClient
.
donloadContract
();
return
{
msg
:
"start success"
};
}
async
genPosterQrcodeImg
(
obj
)
{
...
...
bpo-web/app/base/service/impl/dkcontractSve.js
View file @
117293c7
...
...
@@ -304,6 +304,39 @@ class DKcontractService extends ServiceBase {
}
}
async
downloadContract
(
id
)
{
try
{
let
contract
=
await
this
.
dao
.
findById
(
id
);
if
(
!
contract
||
contract
.
eflowstatus
!=
"2"
||
contract
.
fileurl
)
{
return
;
}
//await this.syncYzSign(2134);
// 请求文件地址
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
else
{
await
this
.
utilesignbaoSve
.
archiveProcess
({
flowId
:
contract
.
eflowid
},
"econtractSve"
);
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
}
}
catch
(
e
)
{
console
.
error
(
e
);
return
{
code
:
-
200
,
message
:
"error"
,
data
:
{}
};
}
}
async
getContractUrl
(
id
)
{
var
contract
=
await
this
.
findById
(
id
);
if
(
contract
.
fileurl
)
{
...
...
bpo-web/app/base/service/impl/econtractSve.js
View file @
117293c7
...
...
@@ -2073,6 +2073,39 @@ class EcontractService extends ServiceBase {
return
system
.
getErrResult2
(
"接口异常"
);
}
}
async
downloadContract
(
id
)
{
try
{
let
contract
=
await
this
.
dao
.
findById
(
id
);
if
(
!
contract
||
contract
.
eflowstatus
!=
"2"
||
contract
.
fileurl
)
{
return
;
}
//await this.syncYzSign(2134);
// 请求文件地址
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
else
{
await
this
.
utilesignbaoSve
.
archiveProcess
({
flowId
:
contract
.
eflowid
},
"econtractSve"
);
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
}
}
catch
(
e
)
{
console
.
error
(
e
);
return
{
code
:
-
200
,
message
:
"error"
,
data
:
{}
};
}
}
}
module
.
exports
=
EcontractService
;
bpo-web/app/base/service/impl/entcontractSve.js
View file @
117293c7
...
...
@@ -757,6 +757,39 @@ class EntcontractService extends ServiceBase {
}
}
async
downloadContract
(
id
)
{
try
{
let
contract
=
await
this
.
dao
.
findById
(
id
);
if
(
!
contract
||
contract
.
eflowstatus
!=
"2"
||
contract
.
fileurl
)
{
return
;
}
//await this.syncYzSign(2134);
// 请求文件地址
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
else
{
await
this
.
utilesignbaoSve
.
archiveProcess
({
flowId
:
contract
.
eflowid
},
"econtractSve"
);
let
fileRs
=
await
this
.
utilesignbaoSve
.
downloadUserContractFile
(
contract
.
eflowid
,
"econtractSve"
);
if
(
fileRs
.
code
==
1
&&
fileRs
.
data
.
selfossUrl
)
{
contract
.
fileurl
=
fileRs
.
data
.
selfossUrl
;
await
contract
.
save
();
this
.
syncYzSign
(
contract
.
id
);
}
}
}
catch
(
e
)
{
console
.
error
(
e
);
return
{
code
:
-
200
,
message
:
"error"
,
data
:
{}
};
}
}
async
syncYzSign
(
contractId
)
{
// 查询合同
var
contract
=
await
this
.
dao
.
findById
(
contractId
);
...
...
bpo-web/app/base/utils/downcontractClient.js
0 → 100644
View file @
117293c7
const
system
=
require
(
"../system"
);
// const redis = require("redis");
const
settings
=
require
(
"../../config/settings"
);
// const bluebird = require("bluebird");
// bluebird.promisifyAll(redis);
const
redisClient
=
system
.
getObject
(
"util.redisClient"
);
// const logCtl=system.getObject("web.oplogCtl");
class
DownContractClient
{
constructor
()
{
this
.
KEY
=
"DOWN_LOAD_CONTRACT_KEY"
;
this
.
sve
=
{
e
:
system
.
getObject
(
"service.econtractSve"
),
dk
:
system
.
getObject
(
"service.dkcontractSve"
),
ent
:
system
.
getObject
(
"service.entcontractSve"
),
}
}
async
donloadContract
()
{
// 定时器执行服务,这个简单加锁就够用
let
v
=
await
redisClient
.
get
(
this
.
KEY
);
if
(
v
)
{
return
;
}
try
{
await
redisClient
.
setWithEx
(
this
.
KEY
,
123
,
60
);
await
this
.
doDownLoad
();
redisClient
.
delete
(
this
.
KEY
);
}
catch
(
e
)
{
console
.
log
(
e
);
redisClient
.
delete
(
this
.
KEY
);
}
}
async
doDownLoad
()
{
let
len
=
await
redisClient
.
llen
(
"bpo:contract:download"
)
||
0
;
if
(
!
len
)
{
redisClient
.
delete
(
this
.
KEY
);
return
;
}
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
let
item
=
await
redisClient
.
rpop
(
"bpo:contract:download"
);
item
=
JSON
.
parse
(
item
);
try
{
await
this
.
sve
[
item
.
sve
].
downloadContract
(
item
.
id
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
console
.
log
(
item
);
}
}
}
module
.
exports
=
DownContractClient
;
bpo-web/app/base/utils/publishClient.js
0 → 100644
View file @
117293c7
const
System
=
require
(
"../system"
);
const
redis
=
require
(
"redis"
);
const
settings
=
require
(
"../../config/settings"
);
const
bluebird
=
require
(
"bluebird"
);
bluebird
.
promisifyAll
(
redis
);
// const logCtl=System.getObject("web.oplogCtl");
class
PublishClient
{
constructor
()
{
const
redisConfig
=
settings
.
redis
();
this
.
client
=
redis
.
createClient
({
host
:
redisConfig
.
host
,
port
:
redisConfig
.
port
,
password
:
redisConfig
.
password
,
db
:
redisConfig
.
db
,
retry_strategy
:
function
(
options
)
{
// if (options.error && options.error.code === 'ECONNREFUSED') {
// // End reconnecting on a specific error and flush all commands with
// // a individual error
// return new Error('The server refused the connection');
// }
if
(
options
.
total_retry_time
>
1000
*
60
*
60
)
{
// End reconnecting after a specific timeout and flush all commands
// with a individual error
return
new
Error
(
'Retry time exhausted'
);
}
if
(
options
.
attempt
>
10
)
{
// End reconnecting with built in error
return
10000
;
}
// reconnect after
return
Math
.
min
(
options
.
attempt
*
100
,
3000
);
}
});
this
.
client
.
on
(
"error"
,
function
(
err
)
{
console
.
log
(
"Error "
+
err
);
});
}
async
publish
(
channel
,
msg
){
console
.
log
(
channel
+
":"
+
msg
);
return
this
.
client
.
publishAsync
(
channel
,
msg
);
}
async
rpush
(
key
,
val
)
{
return
this
.
client
.
rpushAsync
(
key
,
val
);
}
async
lpush
(
key
,
val
)
{
return
this
.
client
.
lpushAsync
(
key
,
val
);
}
async
rpop
(
key
)
{
this
.
client
.
rpop
(
key
);
}
async
lpop
(
key
)
{
this
.
client
.
lpop
(
key
);
}
}
module
.
exports
=
PublishClient
;
bpo-web/app/base/utils/redisClient.js
View file @
117293c7
...
...
@@ -4,7 +4,6 @@ const settings=require("../../config/settings");
const
bluebird
=
require
(
"bluebird"
);
bluebird
.
promisifyAll
(
redis
);
// const logCtl=System.getObject("web.oplogCtl");
const
CONTRACT_DOWNLOAD_CHANNEL
=
"bpo:contract:download"
;
class
RedisClient
{
constructor
(){
const
redisConfig
=
settings
.
redis
();
...
...
@@ -99,22 +98,6 @@ class RedisClient{
}
}
});
// 做一个简单队列
this
.
queueClient
=
this
.
client
.
duplicate
();
this
.
queueClient
.
on
(
"error"
,
function
(
err
)
{
console
.
log
(
"queueClient Error "
+
err
);
});
var
self
=
this
;
this
.
queueClient
.
on
(
"message"
,
async
function
(
channel
,
message
)
{
console
.
log
(
channel
,
message
,
'------------- queue message ------------------- '
);
});
this
.
queueClient
.
subscribeAsync
(
CONTRACT_DOWNLOAD_CHANNEL
);
}
async
queuePublish
(
channel
,
msg
){
channel
=
channel
||
CONTRACT_DOWNLOAD_CHANNEL
;
console
.
log
(
"queuePublish msg: "
,
channel
,
msg
);
return
this
.
queueClient
.
publishAsync
(
channel
,
msg
);
}
async
subscribe
(
channel
,
chatserver
){
if
(
!
this
.
chatserver
){
...
...
@@ -228,6 +211,11 @@ class RedisClient{
async
incr
(
key
){
return
this
.
client
.
incrAsync
(
key
);
}
async
blpop
(
key
,
d
)
{
return
await
this
.
client
.
blpopAsync
(
key
,
d
);
}
}
module
.
exports
=
RedisClient
;
// var client=new RedisClient();
...
...
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