Ticket #190: list2.groovy

File list2.groovy, 7.3 KB (added by chenyang, 12 years ago)
Line 
1/** µŒ³ö°æÖ÷¹€×÷Á¿Í³ŒÆ */
2import groovy.sql.*
3import java.io.*
4
5def dburl = "jdbc:mysql://192.168.74.5:3310/bbs7_lady_app?useUnicode=true&characterEncoding=GBK"
6def username = "bbs7_lady_app"
7def password = "bbs7_lady_app"
8def db_driver = "com.mysql.jdbc.Driver"
9
10//def dburl = "jdbc:mysql://192.168.237.215:3308/bbs7_lady_app?useUnicode=true&characterEncoding=GBK"
11//def username = "bbs7_lady_app"
12//def password = "lady7bbsmysql"
13//def db_driver = "com.mysql.jdbc.Driver"
14
15def pg_dburl = 'jdbc:postgresql://192.168.74.10:5432/bbs7_lady_app'
16def pg_username = "bbs7_lady_app"
17def pg_password = "bbs7_lady_app"
18def pg_db_driver = "org.postgresql.Driver"
19
20//def pg_dburl = 'jdbc:postgresql://192.168.239.230:5432/bbs7_lady_app'
21//def pg_username = "bbs7_lady_app"
22//def pg_password = "LadYbbs#X38v#"
23//def pg_db_driver = "org.postgresql.Driver"
24
25def db = Sql.newInstance(dburl, username, password, db_driver)
26
27def pg_db = Sql.newInstance(pg_dburl, pg_username, pg_password, pg_db_driver)
28
29def uid_username = [:]
30
31//²é³öËùÓаæÖ÷
32def uids = []
33
34//°æÖ÷¶ÔÓŠµÄ°æ¿é
35def uid_fid = [:]
36
37db.eachRow("""
38        SELECT a.uid uid, a.fid fid, b.name name, a.roleid roleid, c.name rolename
39                 FROM bbs7_user_forum_role a, bbs7_forum b, bbs7_role c
40                WHERE (a.roleid=7 or a.roleid=8 or a.roleid=9) AND a.fid=b.fid AND a.roleid=c.id
41 """) { row ->
42                if (uid_fid[row.uid+""] == null){
43                        uid_fid[row.uid+""]     = [row.fid]
44                }else{
45                        uid_fid[row.uid+""]     << row.fid
46                }
47               
48                if (!uids.contains(row.uid)){
49                        uids << row.uid
50                }
51}
52
53
54//²é³öËùÓз¢Ìû
55def uid_countpost = [:]
56
57def count_topic= 10
58       
59count_topic.times { seq ->
60        def suffix = ""
61        if(seq != 0){
62                suffix = "_" + seq     
63        }
64        def sql = """ SELECT a.operatorid uid , c.fid , COUNT(1) as total
65                                  FROM bbs7_log_topic_201311 a,
66                                bbs7_topic${suffix} b,
67                                (SELECT a.uid uid, a.fid fid, b.name NAME, a.roleid roleid, c.name rolename
68                                 FROM bbs7_user_forum_role a, bbs7_forum b, bbs7_role c
69                        WHERE (a.roleid=7 OR a.roleid=8 OR a.roleid=9) AND a.fid=b.fid AND a.roleid=c.id ) AS  c
70                        WHERE (ACTION= 'replyTopic' OR ACTION = 'postTopic' )
71                        AND a.tid = b.tid
72                        AND b.fid = c.fid
73                        AND a.operatorid = c.uid
74                        GROUP BY a.operatorid
75                        """ as String
76
77        db.eachRow(sql){ row ->
78
79                if(uid_countpost[row.uid+""] == null){
80                        uid_countpost[row.uid+""] = row.total
81                }else{
82                        uid_countpost[row.uid+""] += row.total
83                }
84        }
85}
86               
87
88def opeartor = [
89        "topTopic":"Ö÷ÌâÖÃÏî",
90        "setPick":"ÉèÖ÷Ì⟫»ª",
91        "deleteTopic":"ÉŸ³ýÖ÷Ìâ",
92        "deletePost":"ÉŸ³ý»ØÌû",
93        "move":"ÒÆÌû",
94        "upTopic":"ÌáÉýÖ÷Ìâ",
95        "downTopic":"ϳÁÖ÷Ìâ",
96        "highlight":"ÉèÖÃÖ÷ÌâžßÁÁ",
97        "unLockTopic":"œâËøÓû§",
98        "copyTopic":"¿œ±ŽÖ÷Ìâ",
99        "scoreGrade":"ÆÀ·Ö",
100        "handleReport":"ŽŠÀíŸÙ±š",
101        "lockUser":"ËøÓû§"
102]
103
104def start = Date.parse("yyyy-MM-dd","2013-11-01")
105def end = Date.parse("yyyy-MM-dd HH:mm:ss","2013-11-30 23:59:59")
106
107//def start = "2013-11-01"
108//def end = "2013-12-01"
109
110def uid_action = [:]
111
112def query(def db, def sql, def uid, def uid_action){
113        db.eachRow(sql) { row ->
114                if (uid_action[uid] != null){
115                        if (uid_action[uid][row.action] != null){
116                                uid_action[uid][row.action] = uid_action[uid][row.action] + 1
117                        }else{
118                                uid_action[uid][row.action] = 1
119                        }
120                }else{
121                        uid_action[uid] = [:]
122                }
123        }               
124}
125
126uid_onlinetime = [:]
127//ͳŒÆÔÚÏßʱ³€
128uids.each {uid ->
129        db.eachRow("SELECT uid,SUM(onlineminutes) onlineminutes FROM bbs7_online_time_201311 WHERE uid = ${uid}"){ row ->
130                uid_onlinetime[row.uid+""] = row.onlineminutes == null ? 0 : row.onlineminutes
131        }
132}
133
134//ͳŒÆÌû×Ó²Ù×÷ÈÕÖŸ
135uids.each { uid ->
136
137        def sql = """
138                select topiclogid, logid, operatorid, operatorip, tid, pid, action,
139                        reason, createat, summary1, summary2, summary3 from bbs7_log_topic_201311 where 1=1
140                        and operatorid = ${uid} and createat >= ${start} and createat <= ${end}
141                        order by createat desc
142        """
143        query(db, sql, uid, uid_action)
144
145}
146
147//ͳŒÆÓû§Ïà¹Ø²Ù×÷ÈÕÖŸ
148uids.each { uid ->
149        def sql = """
150                select userlogid, logid, operatorid, operatorip, uid, action,
151                        reason, createat, summary1, summary2, summary3 from bbs7_log_user_201311 where 1=1
152                        and operatorid = ${uid} and createat >= ${start} and createat <= ${end}
153                        order by createat desc
154        """
155        query(db, sql, uid, uid_action)
156
157}
158
159//ͳŒÆ»ý·ÖÏà¹Ø²Ù×÷ÈÕÖŸ
160uids.each { uid ->
161        def sql = """
162                select scorelogid, logid, operatorid, operatorip, uid, action,
163                        reason, createat, summary1, summary2, summary3 from bbs7_log_score_201311 where 1=1
164                        and operatorid = ${uid} and createat >= ${start} and createat <= ${end}
165                        order by createat desc
166        """
167        query(db, sql, uid, uid_action)
168
169}
170
171//»ñÈ¡Óû§Ãû
172uids.each {uid ->
173        pg_db.eachRow("select uid, username from bbs7_user where uid = ${uid}"){ row ->
174                uid_username[row.uid +""] = row.username
175        }
176}
177
178def f = new File("working2.csv")
179
180if (f.exists()){
181        f.delete()
182}
183
184f.append("uid")
185f.append(",")
186
187f.append("Óû§Ãû")
188f.append(",")
189
190f.append("ÔÚÏßʱŒä")
191f.append(",")
192
193f.append("°æÄÚ·¢ÌûÊý")
194f.append(",")
195
196opeartor.each { k, v ->
197        f.append(v)
198        f.append(",")
199}
200f.append("\n")
201
202class Report{
203        def uid
204        def username
205        int onlineminutes
206        int countpost
207        int topTopic
208        int setPick
209        int deleteTopic
210        int deletePost
211        int move
212        int upTopic
213        int downTopic
214        int highlight
215        int unLockTopic
216        int copyTopic
217        int scoreGrade
218        int handleReport
219        int lockUser
220}
221
222def reports = []
223
224uid_action.each{ uid, action ->
225
226        def report = new Report()
227        report.uid = uid
228        report.username = uid_username[uid+""]
229        report.onlineminutes = uid_onlinetime[uid+""] == null ? 0 :  uid_onlinetime[uid+""]
230        report.countpost = uid_countpost[uid+""] == null ? 0 : uid_countpost[uid+""]
231        report.setPick = action["setPick"] == null ? 0 : action["setPick"]
232        report.deleteTopic = action["deleteTopic"] == null ? 0 : action["deleteTopic"]
233        report.deletePost = action["deletePost"] == null ? 0 : action["deletePost"]
234        report.move = action["move"] == null ? 0 : action["move"]
235        report.upTopic = action["upTopic"] == null ? 0 : action["upTopic"]
236        report.downTopic = action["downTopic"] == null ? 0 : action["downTopic"]
237        report.highlight = action["highlight"] == null ? 0 : action["highlight"]
238        report.unLockTopic = action["unLockTopic"] == null ? 0 : action["unLockTopic"]
239        report.copyTopic = action["copyTopic"] == null ? 0 : action["copyTopic"]
240        report.scoreGrade = action["scoreGrade"] == null ? 0 : action["scoreGrade"]
241        report.handleReport = action["handleReport"] == null ? 0 : action["handleReport"]
242        report.lockUser = action["lockUser"] == null ? 0 : action["lockUser"]
243        reports << report
244}
245
246reports.each {
247        f.append(it.uid)       
248        f.append(",")
249        f.append(it.username)   
250        f.append(",")
251        f.append(it.onlineminutes)     
252        f.append(",")
253        f.append(it.countpost) 
254        f.append(",")
255        f.append(it.topTopic)
256        f.append(",")
257        f.append(it.setPick)
258        f.append(",")
259        f.append(it.deleteTopic)
260        f.append(",")
261        f.append(it.deletePost)
262        f.append(",")
263        f.append(it.move)
264        f.append(",")
265        f.append(it.upTopic)
266        f.append(",")
267        f.append(it.downTopic)
268        f.append(",")
269        f.append(it.highlight)
270        f.append(",")
271        f.append(it.unLockTopic)
272        f.append(",")
273        f.append(it.copyTopic)
274        f.append(",")
275        f.append(it.scoreGrade)
276        f.append(",")
277        f.append(it.handleReport)
278        f.append(",")
279        f.append(it.lockUser)
280        f.append("\n")
281}
282