views.py
资源名称:views.rar [点击查看]
上传用户:jxswkc
上传日期:2021-11-29
资源大小:2k
文件大小:5k
源码类别:
Internet/IE编程
开发平台:
Python
- #coding:utf-8
- #date:2010-04-20
- #append:2010-04-29
- #author:zhaomf
- from pyExcelerator import *
- from django.shortcuts import render_to_response
- import time
- import os
- import cx_Oracle
- # Excel style configration
- font = Font()
- font.bold = True
- style = XFStyle()
- style.font = font
- def wm(request):
- db=cx_Oracle.connect('net_union/wI89mG@168.10.98.35:1521/ora10g')
- cursor=db.cursor()
- if request.method == 'POST':
- time_start=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time1'],"%Y-%m-%d"))+'00:00:00'
- time_end=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time2'],"%Y-%m-%d"))+'23:59:59'
- else:
- time_start=time.strftime("%Y-%m-%d ",time.localtime())+'00:00:00'
- time_end=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
- 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")
- row=cursor.fetchall()
- db.close()
- province_list=[]
- province_yw_data=[]
- sum_quota_before=0
- sum_quota_after=0
- sum_quota=0
- for x in row:
- province_list.append(x[0][:4].replace('黑龙','黑龙江').replace('内蒙','内蒙古'))
- 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],})
- sum_quota_before+=x[2]
- sum_quota_after+=x[3]
- sum_quota+=x[4]
- sum_rate=str(float(sum_quota)/float(sum_quota_before)*100)[:str(float(sum_quota)/float(sum_quota_before)*100).index('.')+3]+'%'
- pp=[]
- for i in province_list:
- pp.append({'province':i,'yw_sum':province_list.count(i)})
- province_yw_sum=[y for y in pp if y not in locals()['_[1]']]
- a=Workbook()
- b=a.add_sheet('data')
- b.write(0,0,time_start+"~"+time_end,style)
- b.write(1,0,u'平台',style)
- b.write(1,1,u'业务',style)
- b.write(1,2,u'扣量前',style)
- b.write(1,3,u'扣量后',style)
- b.write(1,4,u'扣量数',style)
- b.write(1,5,u'扣量百分比',style)
- i=0
- while (i<len(province_list)):
- b.write(i+2,0,province_yw_data[i]['platform'].decode('utf-8'))
- b.write(i+2,1,province_yw_data[i]['yw'].decode('utf-8'))
- b.write(i+2,2,province_yw_data[i]['quota_before'])
- b.write(i+2,3,province_yw_data[i]['quota_after'])
- b.write(i+2,4,province_yw_data[i]['quota'])
- b.write(i+2,5,province_yw_data[i]['quota_rate'])
- i+=1
- a.save('D:/django/wm/template/data.xls')
- 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})
- def wx(request):
- db=cx_Oracle.connect('bwisp_qw/bW13pA@168.10.98.23:1521/ora10g')
- cursor=db.cursor()
- if request.method == 'POST':
- da=request.POST['da']
- mocode=request.POST['mocode']
- time_start=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time1'],"%Y-%m-%d"))+'00:00:00'
- time_end=time.strftime("%Y-%m-%d ",time.strptime(request.POST['time2'],"%Y-%m-%d"))+'23:59:59'
- else:
- da='106610981'
- mocode='62'
- time_start=time.strftime("%Y-%m-%d ",time.localtime(time.time() - 7*86400))+'00:00:00'
- time_end=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
- 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")
- row=cursor.fetchall()
- db.close()
- wx_data=[]
- for x in row:
- wx_data.append({'mobileno':x[0],'orderservid':x[1],'ordertime':x[2],'modtime':x[3],'status':x[4],'da':x[5],'mocode':x[6]})
- aa=Workbook()
- bb=aa.add_sheet('data')
- bb.write(0,0,time_start+"~"+time_end,style)
- bb.write(1,0,u'手机号',style)
- bb.write(1,1,u'订购业务id',style)
- bb.write(1,2,u'首次订购时间',style)
- bb.write(1,3,u'订购关系更改时间',style)
- bb.write(1,4,u'订购状态',style)
- bb.write(1,5,u'长号码',style)
- bb.write(1,6,u'上行指令',style)
- j=0
- while (j<len(wx_data)):
- bb.write(j+2,0,wx_data[j]['mobileno'])
- bb.write(j+2,1,wx_data[j]['orderservid'])
- bb.write(j+2,2,wx_data[j]['ordertime'].strftime("%Y-%m-%d %H:%M:%S"))
- bb.write(j+2,3,wx_data[j]['modtime'].strftime("%Y-%m-%d %H:%M:%S"))
- bb.write(j+2,4,wx_data[j]['status'])
- bb.write(j+2,5,wx_data[j]['da'])
- bb.write(j+2,6,wx_data[j]['mocode'])
- j+=1
- aa.save('D:/django/wm/template/wx_data.xls')
- return render_to_response('wx.html',{'mocode':mocode,'da':da,'time_start':time_start,'time_end':time_end,'wx_data':wx_data})