Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
d46a2de5
Commit
d46a2de5
authored
Sep 24, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
aa90cae6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
212 additions
and
0 deletions
+212
-0
forumAboutMe.js
app/controllers/admin/forumAboutMe.js
+22
-0
forumAboutMEService.js
app/service/forumAboutMEService.js
+190
-0
No files found.
app/controllers/admin/forumAboutMe.js
0 → 100644
View file @
d46a2de5
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
);
var
last_handle_date
=
false
;
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
router
.
post
(
'/aboutme/startFetch'
,
function
(
req
,
res
,
next
)
{
var
curDate
=
new
Date
();
if
(
last_handle_date
&&
curDate
-
last_handle_date
<
1000
*
60
*
60
*
1
){
//该操作比较耗时1小时只允许执行一次
return
res
.
json
(
_
.
assign
({
data
:
'不要重复操作'
},
returnCode
.
SUCCESS
));
}
last_handle_date
=
curDate
;
console
.
log
(
'start fetch thread and comment'
);
forumAboutMEService
.
FetchThreadToAboutMe
();
forumAboutMEService
.
FetchCommentToAboutMe
();
res
.
json
(
_
.
assign
({
data
:
'正在处理'
},
returnCode
.
SUCCESS
));
});
\ No newline at end of file
app/service/forumAboutMEService.js
View file @
d46a2de5
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumComment
=
mongoose
.
model
(
'ForumComment'
);
var
ForumAboutMe
=
mongoose
.
model
(
'ForumAboutMe'
);
var
THREAD_TYPE
=
1
;
var
COMMENTLEVEL1_TYPE
=
2
;
var
COMMENTLEVEL2_TYPE
=
3
;
var
forumCommentService
=
require
(
'./forumCommentService'
);
var
forumThreadService
=
require
(
'./forumThreadService'
);
var
then
=
require
(
'thenjs'
);
var
_
=
require
(
'lodash'
);
var
async
=
require
(
'async'
);
/**开始批处理文章和评论到关于我的**/
function
canImportThreadToAboutme
(
tid
,
callback
){
ForumAboutMe
.
findOne
({
thread
:
tid
,
type
:
THREAD_TYPE
},
function
(
err
,
result
)
{
if
(
err
)
{
//有错直接忽略错误
callback
(
null
,
false
);
}
else
{
callback
(
null
,
!
result
);
}
});
}
function
canImportCommentLevel1ToAboutme
(
cid
,
callback
){
ForumAboutMe
.
findOne
({
commentLevel1
:
cid
,
type
:
COMMENTLEVEL1_TYPE
},
function
(
err
,
result
)
{
if
(
err
)
{
//有错直接忽略错误
callback
(
null
,
false
);
}
else
{
callback
(
null
,
!
result
);
}
});
}
function
canImportCommentLevel2ToAboutme
(
cid
,
callback
){
ForumAboutMe
.
findOne
({
commentLevel2
:
cid
,
type
:
COMMENTLEVEL2_TYPE
},
function
(
err
,
result
)
{
if
(
err
)
{
//有错直接忽略错误
callback
(
null
,
false
);
}
else
{
callback
(
null
,
!
result
);
}
});
}
function
saveThread
(
thread
){
var
forumAboutMe
=
new
ForumAboutMe
({
ent_code
:
thread
.
ent_code
,
from
:
thread
.
from
,
type
:
THREAD_TYPE
,
thread
:
thread
.
_id
,
threadStatus
:
thread
.
status
,
created
:
thread
.
created
||
new
Date
()
});
forumAboutMe
.
save
(
function
(
err
){
if
(
err
){
console
.
log
(
err
);
}
});
}
function
saveCommentLevel1
(
thread
,
commentLevel1
){
var
forumAboutMe
=
new
ForumAboutMe
({
ent_code
:
commentLevel1
.
ent_code
,
from
:
commentLevel1
.
from
,
to
:
thread
.
from
,
type
:
COMMENTLEVEL1_TYPE
,
thread
:
thread
.
_id
,
threadStatus
:
thread
.
status
,
commentLevel1
:
commentLevel1
.
_id
,
commentLevel1Status
:
commentLevel1
.
status
,
created
:
commentLevel1
.
created
||
new
Date
()
});
forumAboutMe
.
save
(
function
(
err
){
if
(
err
){
console
.
log
(
err
);
}
});
};
function
saveCommentLevel2
(
thread
,
commentLevel1
,
commentLevel2
){
var
forumAboutMe
=
new
ForumAboutMe
({
ent_code
:
commentLevel2
.
ent_code
,
from
:
commentLevel2
.
from
,
to
:
commentLevel2
.
to
,
type
:
COMMENTLEVEL2_TYPE
,
thread
:
thread
.
_id
,
threadStatus
:
thread
.
status
,
commentLevel1
:
commentLevel1
.
_id
,
commentLevel1Status
:
commentLevel1
.
status
,
commentLevel2
:
commentLevel2
.
_id
,
commentLevel2ThreadFrom
:
thread
.
from
,
commentLevel2Status
:
commentLevel2
.
status
,
created
:
commentLevel2
.
created
||
new
Date
()
});
forumAboutMe
.
save
(
function
(
err
){
if
(
err
){
console
.
log
(
err
);
}
});
};
function
FetchCommentToAboutMeByPage
(
pageNo
,
pageSize
,
count
,
condition
,
callback
){
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumComment
.
find
(
condition
).
skip
(
skip
).
limit
(
limit
).
select
(
'_id ent_code from to thread comments status created'
).
populate
({
path
:
'thread'
,
select
:
'_id ent_code from status created'
}).
exec
(
function
(
err
,
commentLevel1s
)
{
if
(
commentLevel1s
&&
commentLevel1s
.
length
>
0
){
_
.
forEach
(
commentLevel1s
,
function
(
commentLevel1
){
canImportCommentLevel1ToAboutme
(
commentLevel1
.
_id
,
function
(
err
,
result
){
if
(
result
){
saveCommentLevel1
(
commentLevel1
.
thread
||
{},
commentLevel1
);
//子评论
if
(
commentLevel1
.
comments
&&
commentLevel1
.
comments
.
length
>
0
){
commentLevel1
.
comments
.
forEach
(
function
(
commentLevel2_id
){
canImportCommentLevel2ToAboutme
(
commentLevel2_id
,
function
(
err
,
result
){
if
(
result
){
ForumComment
.
findOne
({
_id
:
commentLevel2_id
}).
select
(
'_id ent_code from to status created'
).
exec
(
function
(
err
,
commentLevel2
){
if
(
commentLevel2
){
saveCommentLevel2
(
commentLevel1
.
thread
||
{},
commentLevel1
,
commentLevel2
);
}
});
}
});
});
}
}
});
});
}
setTimeout
(
callback
,
1000
);
});
}
function
FetchThreadToAboutMeByPage
(
pageNo
,
pageSize
,
count
,
condition
,
callback
){
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumThread
.
find
(
condition
).
skip
(
skip
).
limit
(
limit
).
select
(
'_id ent_code from status created'
).
exec
(
function
(
err
,
threads
)
{
if
(
threads
&&
threads
.
length
>
0
){
_
.
forEach
(
threads
,
function
(
thread
){
canImportThreadToAboutme
(
thread
.
_id
,
function
(
err
,
result
){
result
&&
saveThread
(
thread
);
})
});
}
setTimeout
(
callback
,
1000
);
});
}
exports
.
FetchThreadToAboutMe
=
function
(){
var
pageSize
=
50
;
var
tasks
=
[];
var
condition
=
{};
ForumThread
.
find
(
condition
).
count
(
function
(
err
,
count
){
if
(
count
){
_
.
forEach
(
_
.
range
((
count
/
pageSize
)
+
1
),
function
(
o
,
pageNO
){
tasks
.
push
(
function
(
cb
){
FetchThreadToAboutMeByPage
(
pageNO
,
pageSize
,
count
,
condition
,
cb
);
});
});
async
.
parallel
(
tasks
,
function
(
err
,
result
)
{
});
}
});
};
exports
.
FetchCommentToAboutMe
=
function
(){
var
pageSize
=
50
;
var
tasks
=
[];
var
condition
=
{
level
:
1
};
ForumComment
.
find
(
condition
).
count
(
function
(
err
,
count
){
if
(
count
){
_
.
forEach
(
_
.
range
((
count
/
pageSize
)
+
1
),
function
(
o
,
pageNO
){
tasks
.
push
(
function
(
cb
){
FetchCommentToAboutMeByPage
(
pageNO
,
pageSize
,
count
,
condition
,
cb
);
});
});
async
.
parallel
(
tasks
,
function
(
err
,
result
)
{
});
}
});
};
/**结束批处理文章和评论到关于我的**/
exports
.
saveThread
=
function
(
thread
){
var
forumAboutMe
=
new
ForumAboutMe
({
ent_code
:
thread
.
ent_code
,
...
...
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