-
Notifications
You must be signed in to change notification settings - Fork 0
/
pData.coffee
149 lines (132 loc) · 5.64 KB
/
pData.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#node pData run
#node pData run -p
#node pData run i18n
async = require('async')
args = null
process.argv.forEach (val, index, array)->
args = array
`app = {};
_ = require('underscore');
_mdb = 'main';
log = console.log;
oid = require('mongodb').ObjectID;
code = args[2];
_env = true;
`
require('./ext/string')
dao = new require('./service/dao')()
dao.pick('main','cache')
dao.pick(code,'post')
_.delay ->
if args.length > 3
if args[3] is '-p'
`
_env = false;
`
else
entity = args[3]
if entity
filter = if entity in ['user','role']
x:'x'
else
{}
dao.remove code, entity, filter, {}, ->
list = []
for it in require("./views/module/#{code}/data/#{entity}")
ob = {}
for k, v of it
if v isnt null and !(k in ['cid', 'version'])
if _.isString(v) and v.isEmpty()
continue
if k.indexOf('_') > -1
[a,b] = k.split('_')
b = b.capitalize()
k = [a, b].join('')
else if k is 'category'
k = 'cat'
if _.isString(v) and v.indexOf('{') is 0
v = JSON.parse v
else if v.length is 19 and v.indexOf('20') is 0
v = Date.parseLocal(v)
k = 'refFile' if k is 'ref_file'
ob[k] = v
if entity is 'user'
if it.woid
ob.wt =
oid: it.woid
delete it.woid
if it.wid
ob.wt.id = it.wid
delete it.wid
if it.wunid
ob.wt.unid = it.wunid
delete it.wunid
else if entity is 'cat'
if ob.label
ob.title = ob.label
delete ob.label
list.push ob
if entity is 'role'
entity += ':title'
else if entity is 'user'
entity += ':username'
for it in list
dao.save code, entity, it, (res)->
if entity is 'activity'
act = res.ops[0]
estr = entity + ':_id'
if act.master and !act.master.isEmpty()
filter =
username:
$in: act.master.split(',')
act.master = {}
dao.find code, 'user', filter, {}, (ru)->
for u in ru
act.master[u._id] = _.pick(u, 'id', 'username', 'title', 'industry', 'introduction')
dao.save code, estr, act, ->
if act.cat
dao.get code, 'cat', {code: act.cat}, (res)->
if res
act.cat =
title: res.title
code: res.code
dao.save code, estr, act, ->
if act.vid
dao.get code, 'venue', {id:act.vid}, (res)->
if res
act.venue =
title: res.title
fee: res.fee
phone: res.phone
lng: res.lng
lat: res.lat
dao.save code, estr, act
else if entity is 'post'
act = res.ops[0]
estr = entity + ':_id'
return if _.isString(act.uid) and act.uid.isEmpty()
log act.uid
dao.get code, 'user', {id: act.uid}, (doc)->
log doc
if doc
act.author =
username: doc.username
id: doc._id
dao.save code, estr, act, ->
if act.cat
dao.get code, 'cat', {code: act.cat}, (res)->
if res
act.cat =
title: res.title
code: res.code
dao.save code, estr, act
else
data = require("./views/module/#{code}/script/data")
dao.save _mdb, 'community:code', data.community
for k, v of data.data
dao.save code, k, v
, 1000
# dao.save code, 'role:title', [data.r], ->
_.delay ->
dao.close()
, 4000