views.py
上传用户:jxswkc
上传日期:2021-11-29
资源大小:2k
文件大小:5k
源码类别:

Internet/IE编程

开发平台:

Python

  1. #coding:utf-8
  2. #date:2010-04-20
  3. #append:2010-04-29
  4. #author:zhaomf
  5. from pyExcelerator import *
  6. from django.shortcuts import render_to_response
  7. import time
  8. import os
  9. import cx_Oracle
  10. # Excel style configration
  11. font = Font()
  12. font.bold = True
  13. style = XFStyle()
  14. style.font = font
  15. def wm(request):
  16.     db=cx_Oracle.connect('net_union/wI89mG@168.10.98.35:1521/ora10g')
  17.     cursor=db.cursor()
  18.     if request.method == 'POST':
  19.         time_start=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time1'],"%Y-%m-%d"))+'00:00:00'
  20.         time_end=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time2'],"%Y-%m-%d"))+'23:59:59'
  21.     else:
  22.         time_start=time.strftime("%Y-%m-%d ",time.localtime())+'00:00:00'
  23.         time_end=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
  24.     cursor.execute("select a.platform,a.ywcode,a.quota,b.quota, (a.quota-b.quota),round(((a.quota-b.quota)/a.quota),4)*100 ||'%' from (select  platform,ywcode,count(*) quota from REPORT_USER where sendtime between '"+time_start+"' and '"+time_end+"' group by platform,ywcode) a  inner join (select  platform,ywcode,count(*) quota from REPORT_USER where flag=1 and sendtime between  '"+time_start+"' and '"+time_end+"' group by platform,ywcode) b  on a.ywcode=b.ywcode group by a.platform,a.ywcode,a.quota,b.quota order by a.platform")
  25.     row=cursor.fetchall()
  26.     db.close()
  27.     province_list=[]
  28.     province_yw_data=[]
  29.     sum_quota_before=0
  30.     sum_quota_after=0
  31.     sum_quota=0
  32.     for x in row:
  33.         province_list.append(x[0][:4].replace('黑龙','黑龙江').replace('内蒙','内蒙古'))
  34.         province_yw_data.append({'province':x[0][:4].replace('黑龙','黑龙江').replace('内蒙','内蒙古'),'platform':x[0],'yw':x[1],'quota_before':x[2],'quota_after':x[3],'quota':x[4],'quota_rate':x[5],})
  35.         sum_quota_before+=x[2]
  36.         sum_quota_after+=x[3]
  37.         sum_quota+=x[4]
  38.     sum_rate=str(float(sum_quota)/float(sum_quota_before)*100)[:str(float(sum_quota)/float(sum_quota_before)*100).index('.')+3]+'%'    
  39.     pp=[]
  40.     for i in province_list:
  41.         pp.append({'province':i,'yw_sum':province_list.count(i)})
  42.     province_yw_sum=[y for y in pp if y not in locals()['_[1]']]
  43.     a=Workbook()
  44.     b=a.add_sheet('data')
  45.     b.write(0,0,time_start+"~"+time_end,style)
  46.     b.write(1,0,u'平台',style)
  47.     b.write(1,1,u'业务',style)
  48.     b.write(1,2,u'扣量前',style)
  49.     b.write(1,3,u'扣量后',style)
  50.     b.write(1,4,u'扣量数',style)
  51.     b.write(1,5,u'扣量百分比',style)
  52.     i=0
  53.     while (i<len(province_list)):
  54.         b.write(i+2,0,province_yw_data[i]['platform'].decode('utf-8'))
  55.         b.write(i+2,1,province_yw_data[i]['yw'].decode('utf-8'))
  56.         b.write(i+2,2,province_yw_data[i]['quota_before'])
  57.         b.write(i+2,3,province_yw_data[i]['quota_after'])
  58.         b.write(i+2,4,province_yw_data[i]['quota'])
  59.         b.write(i+2,5,province_yw_data[i]['quota_rate'])
  60.         i+=1
  61.     a.save('D:/django/wm/template/data.xls')
  62.     return render_to_response('wm.html',{'sum_rate':sum_rate,'sum_quota_before':sum_quota_before,'sum_quota_after':sum_quota_after,'sum_quota':sum_quota,'time_start':time_start,'time_end':time_end,'province_yw_sum':province_yw_sum,'province_yw_data':province_yw_data})
  63. def wx(request):
  64.     db=cx_Oracle.connect('bwisp_qw/bW13pA@168.10.98.23:1521/ora10g')
  65.     cursor=db.cursor()
  66.     if request.method == 'POST':
  67.         da=request.POST['da']
  68.         mocode=request.POST['mocode']
  69.         time_start=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time1'],"%Y-%m-%d"))+'00:00:00'
  70.         time_end=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time2'],"%Y-%m-%d"))+'23:59:59'
  71.     else:
  72.         da='106610981'
  73.         mocode='62'
  74.         time_start=time.strftime("%Y-%m-%d ",time.localtime(time.time() - 7*86400))+'00:00:00'
  75.         time_end=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
  76.     cursor.execute("select mobileno,orderservid,ordertime,modtime,status,da,mocode from sms_user_all where da='"+str(da)+"' and mocode='"+str(mocode)+"' and to_char(ordertime,'yyyy-mm-dd hh24:mi:ss') between '"+time_start+"' and '"+time_end+"' order by ordertime desc")
  77.     row=cursor.fetchall()
  78.     db.close()
  79.     wx_data=[]
  80.     for x in row:
  81.      wx_data.append({'mobileno':x[0],'orderservid':x[1],'ordertime':x[2],'modtime':x[3],'status':x[4],'da':x[5],'mocode':x[6]})
  82.     aa=Workbook()
  83.     bb=aa.add_sheet('data')
  84.     bb.write(0,0,time_start+"~"+time_end,style)
  85.     bb.write(1,0,u'手机号',style)
  86.     bb.write(1,1,u'订购业务id',style)
  87.     bb.write(1,2,u'首次订购时间',style)
  88.     bb.write(1,3,u'订购关系更改时间',style)
  89.     bb.write(1,4,u'订购状态',style)
  90.     bb.write(1,5,u'长号码',style)
  91.     bb.write(1,6,u'上行指令',style)
  92.     j=0
  93.     while (j<len(wx_data)):
  94.         bb.write(j+2,0,wx_data[j]['mobileno'])
  95.         bb.write(j+2,1,wx_data[j]['orderservid'])
  96.         bb.write(j+2,2,wx_data[j]['ordertime'].strftime("%Y-%m-%d %H:%M:%S"))
  97.         bb.write(j+2,3,wx_data[j]['modtime'].strftime("%Y-%m-%d %H:%M:%S"))
  98.         bb.write(j+2,4,wx_data[j]['status'])
  99.         bb.write(j+2,5,wx_data[j]['da'])
  100.         bb.write(j+2,6,wx_data[j]['mocode'])
  101.         j+=1
  102.     aa.save('D:/django/wm/template/wx_data.xls')
  103.     return render_to_response('wx.html',{'mocode':mocode,'da':da,'time_start':time_start,'time_end':time_end,'wx_data':wx_data})