python & mysql 操作

【1】源码

工作中涉及的python工具源码实现

费用比较工具源码:

  1 #!/usr/bin/python3
  2 #coding = utf-8
  3 import time, sqlite3, datetime, threading, pymysql, time, logging, os, contextlib, sys, xlrd, xlwt
  4 import psutil, py_compile
  5 from xlutils.copy import copy
  6 import queue
  7 db_mq = queue.Queue()
  8 
  9 if True :
 10     @contextlib.contextmanager
 11     def billing():
 12         try:
 13             if db_mq.empty():
 14                 conn = pymysql.connect(host = '127.0.0.1', port = 3306, user = 'root', passwd = '123456', db = 'test', charset = 'utf8')
 15                 conn.autocommit(True)
 16             else:
 17                 conn = db_mq.get_nowait()
 18                 conn.ping(reconnect = True)
 19             yield conn.cursor()
 20         finally:
 21             conn.cursor().close()
 22             db_mq.put(conn)
 23 else :
 24     @contextlib.contextmanager
 25     def billing():
 26         try:
 27             if db_mq.empty():
 28                 conn = pymysql.connect(host = '127.0.0.1', port = 3306, user = 'root', passwd = '123456', db = 'billing', charset = 'utf8')
 29                 conn.autocommit(True)
 30             else:
 31                 conn = db_mq.get_nowait()
 32                 conn.ping(reconnect = True)
 33             yield conn.cursor()
 34         finally:
 35             conn.cursor().close()
 36             db_mq.put(conn)
 37 
 38  # 限制运行数量为1 防止数据冲突
 39 def isRunning() :
 40     count = 0
 41     status = False
 42     for i in psutil.pids():
 43         if psutil.Process(i).name() == 'compare_sum_fee_20190412.py' or 'compare_sum_fee_20190412.pyc' in psutil.Process(i).cmdline() :
 44             count += 1
 45             if count > 1 :
 46                 status = True
 47                 break
 48     if os.path.exists('/home/work/compare_sum_fee_20190412.py') :
 49         py_compile.compile('/home/work/compare_sum_fee_20190412.py', '/home/work/compare_sum_fee_20190412.pyc')
 50     os.system('chmod 777 /home/work/compare_sum_fee_20190412.pyc')
 51     return status
 52 
 53 # -------------------------------------------------------------
 54 # (1)
 55 cycleid = '201902'
 56 # (2)
 57 isCreateLog = False
 58 # (3)是否打印调试日志
 59 needPrint = False
 60 # (4)
 61 needCreateTable = True
 62 # (5)
 63 tableSuffix = ''
 64 # ----------------------------------------------------------------
 65 
 66 # 创建费用比较表
 67 def create_table_compareFee() :
 68     dropTable = ''' DROP TABLE IF EXISTS compare_fee_%s; '''
 69     createTable = ''' CREATE TABLE `compare_fee_%s` (
 70         `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '记录流水号',
 71         `product_id` VARCHAR(32) DEFAULT NULL COMMENT '产品编号',
 72         `np_id` VARCHAR(36) DEFAULT NULL COMMENT '运营商编号',
 73         `np_sum_duration` INT(11) DEFAULT NULL COMMENT '运营商话单结算总时长',
 74         `np_total_times` BIGINT(11) DEFAULT NULL COMMENT '运营商话单总数',
 75         `np_sum_qty` INT(11) DEFAULT NULL COMMENT '运营商话单总结算量(按公司费率)',
 76         `np_sum_fee` INT(11) DEFAULT NULL COMMENT '运营商话单总结算费(按公司费率)',
 77         `un_sum_duration` INT(11) DEFAULT NULL COMMENT '平台话单计费总时长',
 78         `un_total_times` BIGINT(11) DEFAULT NULL COMMENT '平台话单总数',
 79         `un_sum_fee` INT(11) DEFAULT NULL COMMENT '平台话单计费总费用(分)',
 80         `sum_np_fee` INT(11) DEFAULT NULL COMMENT '运营商话单总结算费(按运营商费率)',
 81         `sum_original_fee` INT(11) DEFAULT NULL COMMENT '原始结算费总和(运营商提供)',
 82         `reserve_00` VARCHAR(16) DEFAULT NULL COMMENT '扩展字段1',
 83         `reserve_01` VARCHAR(16) DEFAULT NULL COMMENT '扩展字段2',
 84         `reserve_02` VARCHAR(32) DEFAULT NULL COMMENT '扩展字段3',
 85         PRIMARY KEY (`id`),
 86         KEY `idx_np_id` (`np_id`),
 87         KEY `idx_product_id` (`product_id`)
 88         ) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='费用对比详单表' 
 89     '''
 90     dropSql = dropTable % (cycleid + tableSuffix)
 91     createSql = createTable % (cycleid + tableSuffix)
 92     if needCreateTable :
 93         with billing() as billingDB :
 94             print('[1]drop create Sql :: %s' % dropSql)
 95             billingDB.execute(dropSql)
 96             print('[2]create table Sql :: %s' % createSql)
 97             billingDB.execute(createSql)
 98             sql = 'UPDATE acct_offlinefile SET state = 4 WHERE cycle_id = \'' + cycleid + '\';'
 99             billingDB.execute(sql)
100             print('[3]update acct_offlinefile set state = 4 all np_id')
101 
102 def get_callingid_code(calling_id) :
103     if calling_id[0:2] == '01' and len(calling_id) == 12 and calling_id[0:3] != '010' :
104         calling_id = calling_id[2:(len(calling_id))]
105 
106     if calling_id[0:1] == '1' and len(calling_id) == 11 :
107         sql = "select area_code from cfg_area_prefix where prefix = '" + calling_id[0:7] + "' limit 1;"
108         with billing() as billingDB :
109             billingDB.execute(sql)
110             results = billingDB.fetchall()
111             if results :
112                 for record in results :
113                     return record['area_code']
114             else :
115                 return ''
116 
117     if calling_id[0:1] == '0' and len(calling_id) >= 4 : 
118         if calling_id[0:2] == '01' or calling_id[0:2] == '02' :
119             return calling_id[0:3]
120         else :
121             return calling_id[0:4]
122     else :
123         is_len = len(calling_id) > 0 and len(calling_id) < 7 and len(calling_id) != 4
124         value = int(calling_id)
125         is_reserve = len(calling_id) == 4 and value > 0 and (value < 5000 or value > 5999)
126         if calling_id[0:3] == '800' or is_len or is_reserve :
127             return '800'
128         else :
129             return ''
130 
131 def analysis_cdr_calltype(np_id) :
132     sql = 'SELECT calling_id FROM np_cdr_' + cycleid + ' WHERE np_id = \'' + np_id + '\' AND ISNULL(ani_code) GROUP BY calling_id;'
133     print('----[1]start : get_callingid_code ......')
134     #print('select_calling_id_sql : ' + sql)
135     results = ()
136     with billing() as billingDB :
137         billingDB.execute(sql)
138         results = billingDB.fetchall()
139     sum_count = 0
140     count = 0
141     if results :
142         sql_const = "UPDATE np_cdr_%s SET ani_code = %s WHERE np_id = %s AND calling_id = %s;"
143         param = []
144         for record in results :
145             cur_code = get_callingid_code(record[0])
146             if len(cur_code) != 0 :
147                 value = []
148                 value.append(int(cycleid))
149                 value.append(cur_code)
150                 value.append(np_id)
151                 value.append(record[0])
152                 param.append(value)
153                 count += 1
154             if 5000 == count :
155                 #print('areacode_param5000 : ', param)
156                 with billing() as billingDB :
157                     billingDB.executemany(sql_const, param)
158                 sum_count += count
159                 print('------update ani_code count : %d ' % sum_count)
160                 count = 0
161                 param.clear()
162         if count > 0 :
163             #print('areacode_param less 5000 : ', param)
164             with billing() as billingDB :
165                 billingDB.executemany(sql_const, param)
166             sum_count += count
167             print('------update ani_code sum_count : %d ' % sum_count)
168             count = 0
169             param.clear()
170             #print('id : %d | calling_id : %s | ani_code : %s | affectrow : %d' % (record[0], str(record[1]), cur_code, billingDB.rowcount))
171     print('----[1]end : get_callingid_code ......')
172 
173     # 分析呼叫类型
174     count = 0
175     sum_count = 0
176     print('----[2]start : analysis_cdr_calltype ......')
177     sql = 'SELECT product_id FROM np_cdr_' + cycleid + ' WHERE np_id = \'' + np_id + '\' AND ISNULL(reserve_00) GROUP BY product_id;'
178     #print('select_product_id_sql : ' + sql)
179     results = ()
180     with billing() as billingDB :    
181         billingDB.execute(sql)
182         results = billingDB.fetchall()
183     if results :
184         sql_result = 'UPDATE np_cdr_%s SET reserve_00 = IF(ani_code = %s, \'市话\', \'长话\') WHERE np_id = %s AND product_id = %s;'
185         param = []
186         for record in results :
187             sql = 'SELECT areacode FROM cfg_productid_areacode WHERE product_id = \'' + record[0] + '\';'
188             codeResult = ()
189             with billing() as billingDB :    
190                 billingDB.execute(sql)
191                 codeResult = billingDB.fetchall()
192             value = []
193             value.append(int(cycleid))
194             if not codeResult :
195                 value.append('')
196             else :
197                 for codeRecord in codeResult :
198                     value.append(codeRecord[0])
199             value.append(np_id)
200             value.append(record[0])
201             param.append(value)
202             count += 1
203             if 5000 == count :
204                 #print('calltype_param5000 : ', param)
205                 with billing() as billingDB :    
206                     billingDB.executemany(sql_result, param)
207                 sum_count += count
208                 print('------update reserve_00 product count : %d ' % sum_count)
209                 count = 0
210                 param.clear()
211         if count > 0 :
212             #print('calltype_param less 5000 : ', param)
213             with billing() as billingDB :    
214                 billingDB.executemany(sql_result, param)
215             sum_count += count
216             print('------update reserve_00 product sum_count : %d ' % sum_count)
217             count = 0
218             param.clear()
219     print('----[2]end : analysis_cdr_calltype ......')
220 
221 # 搜集批价参数
222 def collect_union_fee(value, curProductID, unionType, npCdrType) :
223     cur_fee_unit = 0
224     cur_fee_rate = 0
225     sql = 'SELECT fee_unit, fee_rate FROM cfg_fee_rate WHERE product_id = \'' + curProductID + '\' AND call_type = \'' + unionType + '\';'
226     unionRate = ()
227     with billing() as billingDB : 
228         billingDB.execute(sql)
229         unionRate = billingDB.fetchall()
230     if unionRate :
231         for rateRecord in unionRate :
232             cur_fee_unit = rateRecord[0]
233             cur_fee_rate = rateRecord[1]
234     element = []
235     element.append(int(cycleid))
236     element.append(int(cur_fee_unit))
237     element.append(int(cur_fee_rate))
238     element.append(value)
239     element.append(curProductID)
240     element.append(npCdrType)
241     return element
242 
243 # 计算公司费用
244 def calc_union_fee(value) :
245     print('----[1]start : calc_union_fee ......')
246     sql = 'SELECT product_id FROM np_cdr_' + cycleid
247     sql += ' WHERE np_id = \'' + value + '\''
248     sql += ' AND ISNULL(service_qty) GROUP BY product_id;'
249     results = ()
250     total_count = 0
251     with billing() as billingDB :
252         billingDB.execute(sql)
253         results = billingDB.fetchall()
254         total_count = billingDB.rowcount
255     sql_const = ''' UPDATE np_cdr_%s 
256         SET fee_unit = %s, fee_rate = %s, 
257         service_qty = IF(fee_unit = 0, 0, (FLOOR((duration + fee_unit - 1) / fee_unit))), 
258         service_fee = IF(fee_unit = 0, 0, (FLOOR((duration + fee_unit - 1) / fee_unit) * fee_rate)) 
259         WHERE np_id = %s AND product_id = %s AND reserve_00 = %s; '''
260     param = []
261     count = 0
262     sum_count = 0
263     if total_count > 0 and results :
264         for record in results :
265             curProductID = str(record[0])
266             param.append(collect_union_fee(value, curProductID, '14387', '长话'))
267             param.append(collect_union_fee(value, curProductID, '4097', '市话'))
268             count += 1
269             #print('total : %d | current : %d | product : %s' % (total_count, sum_count, curProductID))
270             if 3000 == count :
271                 #print('fee_param 3000 : ', param)
272                 sum_count += count
273                 with billing() as billingDB :
274                     billingDB.executemany(sql_const, param)
275                 print('------calc union fee progress | total : %d | current : %d ' % (total_count, sum_count))
276                 count = 0
277                 param.clear()
278         if count > 0 :
279             #print('fee_param less 3000 : ', param)
280             sum_count += count
281             with billing() as billingDB :
282                 billingDB.executemany(sql_const, param)
283             print('------calc union fee progress | total : %d | current : %d ' % (total_count, sum_count))
284             count = 0
285             param.clear()
286  
287     print('----[1]end : calc_union_fee ......')
288 
289 def do_by_npid(state) :
290     # 恢复统计前原状态值
291     if 2 == state :
292         sql = 'UPDATE acct_offlinefile SET state = 2 WHERE cycle_id = \'' + cycleid + '\';'
293         with billing() as billingDB :
294             billingDB.execute(sql)
295             effectrow = billingDB.rowcount
296             if effectrow > 0 :
297                 print('----OK. success to update set state = 2 where all np_id')
298         return
299     # 执行过程
300     sql = 'SELECT np_id, np_name FROM acct_offlinefile WHERE cycle_id = \'' + cycleid + '\' AND state = ' + str(state - 1) + ' GROUP BY np_id;'
301     results = ()
302     np_count = 0
303     with billing() as billingDB :
304         billingDB.execute(sql)
305         results = billingDB.fetchall()
306         np_count = billingDB.rowcount
307     if results :
308         count = 0
309         for np in results :
310             count += 1
311             print('--Total : %d || No. %d || np_id : %s || np_name : %s' % (np_count, count, np[0], np[1]))
312             if 3 == state :
313                 analysis_cdr_calltype(np[0])
314             elif 4 == state :
315                 calc_union_fee(np[0])
316             else :
317                 amount_sum_fee(np[0])
318             sql = 'UPDATE acct_offlinefile SET state = ' + str(state) + ' WHERE np_id = \'' + np[0] + '\';'
319             with billing() as billingDB :
320                 billingDB.execute(sql)
321                 if billingDB.rowcount > 0 :
322                     print('----[OK]success to finish update set state = ' + str(state) + ' where np_name = %s' % np[1])
323     
324 def analysis_calltype_by_npid() :
325     do_by_npid(3)
326 
327 def calc_np_cdr_fee_by_npid() :
328     do_by_npid(4)
329 
330 def amount_sum_fee_by_npid() :
331     do_by_npid(5)
332 
333 def restore_initial_state() :
334     do_by_npid(2)
335 
336 def amount_sum_fee(np_id) :
337     print('----[1]start : amount sum fee ......')
338     # 查询所有账号
339     sql = 'SELECT product_id FROM np_cdr_' + cycleid + ' WHERE np_id = \'' + np_id +  '\' GROUP BY product_id;'
340     results = ()
341     with billing() as billingDB :
342         billingDB.execute(sql)
343         results = billingDB.fetchall()
344     count = 0
345     sumCount = 0
346     productFeeDict = {}
347     sql_const = 'insert into compare_fee_' + cycleid + tableSuffix + ' (product_id, np_id, np_sum_duration, np_total_times, np_sum_qty, np_sum_fee, '
348     sql_const += 'un_sum_duration, un_total_times, un_sum_fee, sum_np_fee, sum_original_fee) values '
349 
350     if results :
351         for record in results :
352             curProductID = str(record[0])
353             count += 1
354             sumCount += 1
355             cur_np_sum_fee = 0
356             cur_np_sum_original_fee = 0
357             productFeeDict[curProductID] = '\'' + np_id + '\''
358 
359             sql = 'SELECT product_id, SUM(duration) AS np_sum_duration, COUNT(id) AS np_sum_cdrCnt, SUM(service_qty) AS np_service_qty,' 
360             sql += ' SUM(service_fee) AS np_service_fee, SUM(np_fee) AS np_sum_fee, SUM(original_fee) AS np_sum_original_fee '
361             sql += ' FROM np_cdr_' + cycleid + ' WHERE np_id = \'' + np_id + '\' AND product_id = \'' + curProductID + '\';'
362             np_results = ()
363             with billing() as billingDB :
364                 billingDB.execute(sql)
365                 np_results = billingDB.fetchall()
366             if np_results :
367                 for record in np_results :
368                     productFeeDict[curProductID] = productFeeDict.get(curProductID) + ',' + str(record[1]) + ',' + str(record[2]) + ',' + str(record[3]) + ',' + str(record[4])
369                     cur_np_sum_fee = str(record[5])
370                     cur_np_sum_original_fee = str(record[6])
371 
372             sql = 'SELECT product_id, SUM(total_duration) AS un_sum_duration, SUM(total_times) AS un_sum_cdrCnt,'  
373             sql += ' SUM(total_fee) AS un_sum_fee FROM dat_bill_' + cycleid + ' WHERE call_type & 4097 > 0 AND product_id = \'' + curProductID + '\';'
374             un_results = ()
375             with billing() as billingDB :
376                 billingDB.execute(sql)
377                 un_results = billingDB.fetchall()
378             if un_results :
379                 for record in un_results :
380                     value = {'duration':0, 'cdrCnt':0, 'sumfee':0}
381                     if record[0] :
382                        value['duration'] = record[1]
383                        value['cdrCnt'] = record[2]
384                        value['sumfee'] = record[3]
385                     productFeeDict[curProductID] = productFeeDict.get(curProductID) + ',' + str(value['duration']) + ',' + str(value['cdrCnt']) + ',' + str(value['sumfee'])
386 
387             productFeeDict[curProductID] = productFeeDict.get(curProductID) + ',' + cur_np_sum_fee + ',' + cur_np_sum_original_fee
388             # 写入表中
389             if 5000 == count :
390                 # 写入表中
391                 sql = sql_const
392                 for key, value in productFeeDict.items() :
393                     sql += ' (\'' + key + '\',' + value + '),'
394                 sql = sql[:-1]
395                 sql = sql.replace('None', 'NULL')
396                 with billing() as billingDB :
397                     billingDB.execute(sql)   
398                     print("------success insert into product_id count :: %d" % sumCount)
399                 count = 0
400                 productFeeDict.clear()
401         # 最后一次写入
402         if count > 0 :
403             sql = sql_const
404             for key, value in productFeeDict.items() :
405                 sql += ' (\'' + key + '\',' + value + '),'
406             sql = sql[:-1]
407             sql = sql.replace('None', 'NULL')
408             with billing() as billingDB :
409                 billingDB.execute(sql)
410                 print('------success insert into product_id sumCount :: %d ' % sumCount)
411             count = 0
412             productFeeDict.clear()
413         print('----[1]end : amount sum fee ......')
414 
415 def set_bigger_flag() :
416     print('--[1]start : set bigger flag ......')
417     with billing() as billingDB :
418         sql = 'UPDATE compare_fee_' + cycleid + tableSuffix + ' SET reserve_00 = IF(np_sum_fee > un_sum_fee, 1, 0);' 
419         billingDB.execute(sql)
420     sql = 'SELECT count(id) AS biggerCnt FROM compare_fee_' + cycleid + tableSuffix + ' WHERE reserve_00 = 1;'
421     with billing() as billingDB :
422         billingDB.execute(sql)
423         results = billingDB.fetchall()
424         if results :
425             for record in results :
426                 print('----[npcdr_union_sum_fee > uncdr_sum_fee] total count : %d' % record[0])
427     print('--[2]end : set bigger flag ......')
428 
429 
430 def pickUpNpCdr() : 
431     sql = 'SELECT product_id FROM compare_fee_' + cycleid + tableSuffix + ' WHERE reserve_00 = 1;'
432     with billing() as billingDB :
433         billingDB.execute(sql)
434         results = billingDB.fetchall()
435         productid_count = 0
436         sum_npsdr_count = 0
437         calc_productid_count = 0
438         if results :
439             calc_productid_count = len(results)
440             for record in results :
441                 cur_productId = str(record[0])
442                 sql = ''' INSERT INTO view_dat_sdr_%s(call_id, calling_id, called_id, origin_calling_id, origin_called_id,
443                     custom_id, contract_id, product_id, call_type, access_time, ring_time,
444                     bridge_time, start_time, end_time, source, record_file, extension,
445                     transfer_num, voice_mail, satisfaction_result, last_dtmf, gen_time, ani_code,
446                     dnis_code, ani_desc, dnis_desc, result, duration, service_qty,
447                     service_fee, discount_fee, fee_rate, fee_unit, np_id, np_qty,
448                     np_fee, np_rate, np_unit, flownode_name, flownode_id, cdr_state, insert_time) select
449                     CONCAT('npcdr', id), calling_id, called_id, '', '', 
450                     '', '', product_id, '1', start_time, null, 
451                     null, start_time, end_time, source, '', '',
452                     '', '', '', '', insert_time, ani_code,
453                     '', '', '', 1, duration, service_qty, 
454                     service_fee, 0, fee_rate, fee_unit, np_id, np_qty,
455                     np_fee, np_rate, np_unit, '', '', '01', sysdate()
456                     from np_cdr_%s where product_id = '%s' '''
457                 sql = sql % (cycleid, cycleid, cur_productId)
458                 billingDB.execute(sql)
459                 productid_count += 1
460                 sum_npsdr_count += billingDB.rowcount
461                 print('NO. %d | curProductId : %s | npSdrCnt : %d' % (productid_count, cur_productId, billingDB.rowcount))
462         else :
463             print('pickUp select productids is empty.')
464             return
465             
466         sql = 'SELECT COUNT(id) AS cnt FROM np_cdr_' + cycleid 
467         sql += ' WHERE product_id IN (SELECT product_id FROM compare_fee_' + cycleid + tableSuffix + ' WHERE reserve_00 = 1);'
468         billingDB.execute(sql)
469         results = billingDB.fetchall()
470         calc_total_npcdrCnt = 0
471         if results :
472             for record in results :
473                 calc_total_npcdrCnt = record[0]
474         print('------- OK. Finish pickup npcdr success. Result --------')
475         result_id_count = 'real_productid_count : ' + str(calc_productid_count)
476         result_id_count += ' || pickup_productid_count : ' + str(productid_count) + ' || result : '
477         if calc_productid_count == productid_count :
478             print(result_id_count + 'True')
479         else :
480             print(result_id_count + 'False')
481 
482         result_cdr_count = 'real_total_npcdrCnt : ' + str(calc_total_npcdrCnt)
483         result_cdr_count += ' || pickup_npcdr_count : ' + str(sum_npsdr_count) + ' || result : '
484         if calc_total_npcdrCnt == sum_npsdr_count :
485             print(result_cdr_count + 'True')
486         else :
487             print(result_cdr_count + 'False')
488         print('-----------------------End------------------------------')
489 
490 def set_cdr_valid_flag() :
491     print('--start set valid flag .....')
492     sql = 'SELECT product_id FROM compare_fee_' + cycleid + tableSuffix + ' WHERE reserve_00 = 1;'
493     with billing() as billingDB :
494         billingDB.execute(sql)
495         results = billingDB.fetchall()
496         if results :
497             for record in results :
498                 cur_productId = str(record[0])
499                 sql = 'UPDATE view_dat_sdr_' + cycleid + ' SET reserve_00 = 1 WHERE call_id NOT LIKE \'%npcdr%\' AND product_id = \'' + cur_productId + '\';'
500                 billingDB.execute(sql)
501                 sql = 'UPDATE view_dat_sdr_' + cycleid + ' SET reserve_00 = 2 WHERE call_id LIKE \'%npcdr%\' AND product_id = \'' + cur_productId + '\';'
502                 billingDB.execute(sql)
503         sql = 'UPDATE view_dat_sdr_' + cycleid + ' SET reserve_00 = 0 WHERE ISNULL(reserve_00);'
504         billingDB.execute(sql)
505     print('--end set valid flag ......')
506 
507 
508 if __name__ == '__main__' :
509     if isRunning() :
510         print('只允许运行一个实例')
511         sys.exit(0)
512     else :
513         stdout_backup = None
514         log_file = None
515         if isCreateLog :
516             # make a copy of original stdout route# make a copy of original stdout route
517             stdout_backup = sys.stdout
518             # define the log file that receives your log info
519             log_file = open('message.log', 'w')
520             # redirect print output to log file
521             sys.stdout = log_file
522         begin = datetime.datetime.now()
523                
524         do_step_dict = {'step1': True, 'step2': True, 'step3': True, 'step4': True, 'step5': True, 'step6': False, 'step7': False}
525         # 1.
526         if do_step_dict['step1'] :
527             analysis_calltype_by_npid()
528         # 2.
529         if do_step_dict['step2'] :
530             calc_np_cdr_fee_by_npid()
531         # 3.
532         if do_step_dict['step3'] :
533             create_table_compareFee()
534         # 4.
535         if do_step_dict['step4'] :
536             amount_sum_fee_by_npid()
537         # 5.
538         if do_step_dict['step5'] :
539             set_bigger_flag()
540         # 6.
541         if do_step_dict['step6'] :
542             pickUpNpCdr()
543         # 7.
544         if do_step_dict['step7'] :
545             set_cdr_valid_flag()
546 
547         end = datetime.datetime.now()
548         print('cost total time(s) :: %d ' % ((end - begin).seconds))
549 
550         if isCreateLog :
551             # close open log file
552             log_file.close()
553             # restore the output to initial pattern
554             sys.stdout = stdout_backup

应用的接口,可以通过代码中一一查看。

Good Good Study, Day Day Up.

顺序 选择 循环 总结

猜你喜欢

转载自www.cnblogs.com/Braveliu/p/10716033.html