C005 運營日報數據採集

運營日報數據採集

 

目的:定時任務每日查詢日報數據,並通過郵件發送相關人員,實現運營日報自動化,提高運營人員工作效率。

 

方法

一、每月1號9點刪臨時中間表重新採集數據(每月從現網rac庫取數據到190數據庫)

 

190數據庫主機上:

定時任務:

0 9 1 * * /home/oracle/gyl/mk_tables_daily_life_payment.sh > /dev/null 2>&1 &

 

定時任務腳本mk_tables_daily_life_payment.sh內容:

su - oracle -c "export NLS_LANG='AMERICAN_AMERICA.UTF8';sqlplus -s helife_portal_interaction/改成用戶密碼"<<EOF

set feedback off;

set heading off;

set pagesize 0; 

set linesize 400;

set verify off; 

set echo off;   

set termout off;

set trimout on; 

set trimspool on;

spool /home/oracle/gyl/log/mk_tables_daily_life_payment.log

@/home/oracle/gyl/mk_tables_daily_life_payment.sql

spool off;

exit;

EOF

 

定時任務執行的mk_tables_daily_life_payment.sql內容:

--前2個月生活繳費記錄(按月建),召回與留存都需用到這張表--

drop table jiaofei_back001;

create table jiaofei_back001 as

select * from PAY_RECORD@Link_rac t

where t.state in (1,6) and to_char(t.create_time, 'yyyy-mm-dd') >= to_char(last_day(add_months(sysdate,-3)) + 1,'yyyy-mm-dd')

and to_char(t.CREATE_TIME, 'yyyy-mm-dd') <= to_char(last_day(add_months(sysdate,-1)),'yyyy-mm-dd')

and t.type in('電費','燃氣費','水費','有線電視費');

--自2018年1月1日至上個月末的繳費記錄(按月建)--

drop table jiaofei_new001;

create table jiaofei_new001 as

select * from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'yyyy-mm-dd')>='2018-01-01'

and to_char(t.CREATE_TIME, 'yyyy-mm-dd') <= to_char(last_day(add_months(sysdate,-1)),'yyyy-mm-dd')

and t.type in('電費','燃氣費','水費','有線電視費');

 

二、每天06:00採集運營日報數據,並把日報數據拷貝到郵件服務器主機上

 

190數據庫主機上:

定時任務:

0 6 * * * /home/oracle/gyl/daily_life_payment.sh > /dev/null 2>&1 &

 

定時任務腳本daily_life_payment.sh內容:

su - oracle -c "export NLS_LANG='AMERICAN_AMERICA.UTF8';sqlplus -s helife_portal_interaction/改成用戶密碼"<<EOF

set feedback off;

set heading off;

set pagesize 0; 

set linesize 400;

set verify off; 

set echo off;   

set termout off;

set trimout on; 

set trimspool on;

spool /home/oracle/gyl/log/daily_life_payment_TMP.csv

@/home/oracle/gyl/daily_life_payment.sql

spool off;

exit;

EOF

source /etc/profile;

echo "" >> /home/oracle/gyl/log/daily_life_payment_TMP.csv;

sed -i '1i\日期,筆數,金額(萬),交易用戶數,每日拉新,拉新率,每日召回人數,召回率,當日留存,留存率,PV,UV' /home/oracle/gyl/log/daily_life_payment_TMP.csv;

iconv -c -f utf-8 -t GB2312 /home/oracle/gyl/log/daily_life_payment_TMP.csv > /home/oracle/gyl/log/生活繳費日報_`date -d "1 days ago" '+%F'`.csv;

scp -P 10022 -i /root/.ssh/monitor_id_rsa /home/oracle/gyl/log/生活繳費日報_`date -d "1 days ago" '+%F'`.csv [email protected]:/root/gyl/daily_life_payment/

 

定時任務執行的daily_life_payment.sql內容:

-- 每日生活繳費

select T1.日期||','||T1.筆數||','||T1.金額萬||','||T1.交易用戶數||','||

T2.每日拉新||','||to_char(T2.每日拉新/T1.交易用戶數*100,'fm9999990.00')||'%,'||

T3.每日召回人數||','||to_char(T3.每日召回人數/T1.交易用戶數*100,'fm9999990.0')||'%,'||

T4.當日留存||','||to_char((sum(當日留存) over(order by T4.日期))/T5.前兩月交易用戶數*100,'fm9999990')||'%,'||

T6.pv||','||T6.uv  from

(select count(distinct t.pay_account) as 前兩月交易用戶數 from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') >= to_char(add_months(sysdate-1,-2), 'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM') <= to_char(add_months(sysdate-1,-1), 'YYYY-MM')

and t.type in('電費','燃氣費','水費','有線電視費')) T5,

(select to_char(t.create_time, 'MM"月"DD"日"') as 日期, count(1) as 筆數,

to_char(sum(t.money)/1000000,'fm9999990.0') as 金額萬, count(distinct t.pay_account) as 交易用戶數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

group by to_char(t.create_time, 'MM"月"DD"日"')

order by to_char(t.create_time, 'MM"月"DD"日"') asc) T1

left join

(select to_char(t.create_time, 'MM"月"DD"日"') as 日期, count(distinct t.pay_account) as 每日拉新 from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and not exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account )

group by to_char(t.create_time, 'MM"月"DD"日"')) T2

on T1.日期=T2.日期

left join

(select to_char(t.create_time, 'MM"月"DD"日"') as 日期, count(distinct t.pay_account) as 每日召回人數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account)

and not exists (select * from jiaofei_back001 c where c.pay_account=t.pay_account)

group by to_char(t.create_time, 'MM"月"DD"日"')) T3

on T1.日期=T3.日期

left join

(select to_char(t.create_time, 'MM"月"DD"日"') as 日期, count(distinct t.pay_account) as 當日留存

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account)

and exists (select * from jiaofei_back001 c where c.pay_account=t.pay_account)

group by to_char(t.create_time, 'MM"月"DD"日"')) T4

on T1.日期=T4.日期

left join

(select to_char(t.time, 'MM"月"DD"日"') as 日期, count(1) as pv, count(distinct t.user_name) as uv

from client_start_record_new t

where t.module like '%生活繳費H5新版-端內%'

and to_char(t.time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.time, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

group by to_char(t.time, 'MM"月"DD"日"')) T6

on T1.日期=T6.日期;

 

-- 當月生活繳費

select to_char(sysdate-1-1, 'MM"月彙總"')||','||T1.筆數||','||T1.金額萬||','||T1.交易用戶數||','||

T2.每日拉新||','||to_char(T2.每日拉新/T1.交易用戶數*100,'fm9999990.00')||'%,'||

T3.每日召回人數||','||to_char(T3.每日召回人數/T1.交易用戶數*100,'fm9999990.0')||'%,'||

T4.當日留存||','||to_char(T4.當日留存/T5.前兩月交易用戶數*100,'fm9999990')||'%,'||

T6.pv||','||T6.uv  from

(select count(1) as 筆數, to_char(sum(t.money)/1000000,'fm9999990.0') as 金額萬, count(distinct t.pay_account) as 交易用戶數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')) T1,

(select count(distinct t.pay_account) as 每日拉新 from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and not exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account )) T2,

(select count(distinct t.pay_account) as 每日召回人數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account)

and not exists (select * from jiaofei_back001 c where c.pay_account=t.pay_account)) T3,

(select count(distinct t.pay_account) as 當日留存

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')

and t.type in('電費','燃氣費','水費','有線電視費')

and exists (select * from jiaofei_new001 b where b.pay_account=t.pay_account)

and exists (select * from jiaofei_back001 c where c.pay_account=t.pay_account)) T4,

(select count(distinct t.pay_account) as 前兩月交易用戶數 from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'YYYY-MM') >= to_char(add_months(sysdate-1,-2), 'YYYY-MM')

and to_char(t.CREATE_TIME, 'YYYY-MM') <= to_char(add_months(sysdate-1,-1), 'YYYY-MM')

and t.type in('電費','燃氣費','水費','有線電視費')) T5,

(select count(1) as pv, count(distinct t.user_name) as uv from client_start_record_new t

where t.module like '%生活繳費H5新版-端內%'

and to_char(t.time, 'YYYY-MM') = to_char(sysdate-1,'YYYY-MM')

and to_char(t.time, 'YYYY-MM-DD') <= to_char(sysdate-1,'YYYY-MM-DD')) T6;

 

-- 上月同期生活繳費

select T2.日期||','||T2.筆數||','||T2.金額萬||','||T2.交易用戶數 from

(select to_char(add_months(sysdate-1,-1), 'MM"月"DD"日彙總"') as 日期, count(1) as 筆數, to_char(sum(t.money)/1000000,'fm9999990.0') as 金額萬, count(distinct t.pay_account) as 交易用戶數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'yyyy-mm') = to_char(add_months(sysdate-1,-1), 'yyyy-mm')

and to_char(t.CREATE_TIME, 'yyyy-mm-dd') <= to_char(add_months(sysdate-1, -1), 'yyyy-mm-dd')

and to_char(add_months(last_day(sysdate-1), -1), 'yyyy-mm-dd') >= to_char(add_months(sysdate-1,-1), 'yyyy-mm-dd')

and t.type in('電費','燃氣費','水費','有線電視費')) T2;

 

-- 上月同期環比

select '環比,'||to_char((T1.筆數-T2.筆數)/T2.筆數*100,'fm9999990.00')||'%,'||

to_char((T1.金額萬-T2.金額萬)/T2.金額萬*100,'fm9999990.00')||'%,'||

to_char((T1.交易用戶數-T2.交易用戶數)/T2.交易用戶數*100,'fm9999990.00')||'%,'

from

(select to_char(sysdate-1,'MM"月"DD"日"') as 日期, count(1) as 筆數, to_char(sum(t.money)/1000000,'fm9999990.0') as 金額萬, count(distinct t.pay_account) as 交易用戶數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'yyyy-mm') = to_char(sysdate-1,'yyyy-mm')

and to_char(t.CREATE_TIME, 'yyyy-mm-dd') <= to_char(sysdate-1,'yyyy-mm-dd')

and t.type in('電費','燃氣費','水費','有線電視費')) T1,

(select to_char(add_months(sysdate-1,-1), 'MM"月"DD"日"') as 日期, count(1) as 筆數, to_char(sum(t.money)/1000000,'fm9999990.0') as 金額萬, count(distinct t.pay_account) as 交易用戶數

from PAY_RECORD@link_rac t

where t.state in (1,6) and to_char(t.create_time, 'yyyy-mm') = to_char(add_months(sysdate-1,-1), 'yyyy-mm')

and to_char(t.CREATE_TIME, 'yyyy-mm-dd') <= to_char(add_months(sysdate-1, -1), 'yyyy-mm-dd')

and to_char(add_months(last_day(sysdate-1), -1), 'yyyy-mm-dd') >= to_char(add_months(sysdate-1,-1), 'yyyy-mm-dd')

and t.type in('電費','燃氣費','水費','有線電視費')) T2;

 

日報附件結果如下:

日期

筆數

金額(萬)

交易用戶數

每日拉新

拉新率

每日召回人數

召回率

當日留存

留存率

PV

UV

3月1日

1152

14.3

1009

49

4.86%

150

14.90%

810

1%

63466

29751

3月2日

2352

28.6

1839

89

4.84%

186

10.10%

1564

4%

68709

31328

3月3日

6077

69.8

4567

137

3.00%

484

10.60%

3946

9%

85498

25601

3月4日

8092

91.2

6122

201

3.28%

694

11.30%

5227

17%

98353

26530

3月5日

6961

81

5415

204

3.77%

694

12.80%

4517

24%

86870

24138

3月6日

4679

56.1

3728

175

4.69%

478

12.80%

3075

29%

70205

21804

3月7日

3559

41.5

2828

144

5.09%

405

14.30%

2279

32%

59897

19976

3月8日

3588

41.8

2814

110

3.91%

399

14.20%

2305

35%

56655

18615

3月9日

3209

37.9

2516

139

5.52%

362

14.40%

2015

38%

55944

19736

3月10日

3680

43

2936

146

4.97%

449

15.30%

2341

42%

88356

37786

3月11日

3001

35

2371

102

4.30%

373

15.70%

1896

45%

71617

31671

3月12日

2952

31.6

2259

114

5.05%

296

13.10%

1849

48%

80954

33428

3月13日

2827

31.5

2185

79

3.62%

309

14.10%

1797

50%

73547

29200

3月14日

2417

24.9

1888

98

5.19%

242

12.80%

1548

53%

61099

24199

3月15日

2223

23.8

1724

97

5.63%

222

12.90%

1405

55%

58665

23396

3月16日

2822

29.4

2202

100

4.54%

302

13.70%

1800

57%

83328

35298

3月17日

2672

28.6

2095

94

4.49%

247

11.80%

1754

60%

73403

30506

3月18日

2554

29.8

1995

102

5.11%

259

13.00%

1634

62%

63626

25849

3月19日

2362

28.3

1883

107

5.68%

259

13.80%

1517

65%

63525

25635

3月20日

2170

25.4

1749

106

6.06%

238

13.60%

1405

67%

59906

24017

3月21日

1727

20.5

1410

83

5.89%

221

15.70%

1106

68%

61375

27525

3月22日

1336

16.8

1084

68

6.27%

153

14.10%

863

70%

43330

18031

3月23日

1272

14.5

1076

61

5.67%

165

15.30%

850

71%

6901

4377

3月24日

1940

14.3

1773

728

41.06%

423

23.90%

622

72%

55975

21940

3月25日

1218

11.9

1096

306

27.92%

257

23.40%

533

73%

49286

20428

3月26日

988

11.5

848

86

10.14%

142

16.70%

620

74%

46714

20408

3月27日

1003

11

841

53

6.30%

137

16.30%

651

75%

41340

17858

3月28日

944

9.3

792

50

6.31%

106

13.40%

636

76%

41875

18450

3月29日

882

10

739

53

7.17%

131

17.70%

555

76%

39896

17259

3月30日

916

10

789

69

8.75%

120

15.20%

600

77%

39659

17077

03月彙總

81575

923.2

52551

3805

7.24%

8304

15.80%

40442

60%

1849974

488779

02月29日彙總

77684

1094.5

51303

 

 

 

 

 

 

 

 

環比

5.01%

-15.65%

2.43%

 

 

 

 

 

 

 

 

注:環比是與上月同期數據比較,但無2月30日,所以就與2月29日環比

 

三、每天08:00發送運營日報郵件

 

郵件發送附件日報數據給相關人員,且正文還需要顯示部分日報數據

 

郵件服務器主機上(跳轉機):

定時任務:

0 8 * * * /root/gyl/daily_life_payment.sh > /dev/null 2>&1 &

 

定時任務腳本daily_life_payment.sh內容:

source /etc/profile;

cd /root/gyl/daily_life_payment/

MailText()

{

iconv -f GB2312 -t utf-8 生活繳費日報_`date -d "1 days ago" '+%F'`.csv > utf-8.csv

cat utf-8.csv | grep `date -d last-day +%m月%d日` | awk -F , '{print "每日生活繳費 交易筆數:"$2,",金額(萬):"$3,",人數:"$4}';

cat utf-8.csv | grep `date -d last-day +%m月彙總` | awk -F , '{print "當月生活繳費 交易筆數:"$2,",金額(萬):"$3,",人數:"$4}';

s1=`cat utf-8.csv | grep "日彙總" | awk -F , '{print $2}'`;

s2=`cat utf-8.csv | grep "日彙總" | awk -F , '{print $3}'`;

s3=`cat utf-8.csv | grep "日彙總" | awk -F , '{print $4}'`;

s4=`cat utf-8.csv | grep "環比" | awk -F , '{print $2}'`;

s5=`cat utf-8.csv | grep "環比" | awk -F , '{print $3}'`;

s6=`cat utf-8.csv | grep "環比" | awk -F , '{print $4}'`;

echo "上月同期生活繳費 交易筆數:$s1,環比:$s4,金額:$s2,環比:$s5,人數:$s3,環比:$s6";

echo ""

cat utf-8.csv | grep `date -d last-day +%m月%d日` | awk -F , '{print "每日生活繳費 新用戶數:"$5,",拉新率:"$6}';

cat utf-8.csv | grep `date -d last-day +%m月彙總` | awk -F , '{print "每日生活繳費 新用戶數:"$5}';

echo ""

cat utf-8.csv | grep `date -d last-day +%m月%d日` | awk -F , '{print "每日生活繳費 召回用戶數:"$7,",召回率:"$8}';

cat utf-8.csv | grep `date -d last-day +%m月彙總` | awk -F , '{print "每月生活繳費 召回用戶數:"$7}';

echo ""

cat utf-8.csv | grep `date -d last-day +%m月%d日` | awk -F , '{print "每日生活繳費 留存用戶數:"$9,",留存率:"$10}';

cat utf-8.csv | grep `date -d last-day +%m月彙總` | awk -F , '{print "每月生活繳費 留存用戶數:"$9}';

}

MailText > milText.txt

cat milText.txt | mailx -s "生活繳費日報"`date -d "1 days ago" '+%F'` -a 生活繳費日報_`date -d "1 days ago" '+%F'`.csv -r [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

 

郵件正文內容如下:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章