#!/bin/bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)
exec 1>>$CUR_DIR"/log/sh.log"
exec 2>>$CUR_DIR"/log/sh.log.wf"
. ~/.bashrc
filename=$1
readfile=$CUR_DIR/var/${filename}
echo $datafile
currentdate=`date +'%Y%m%d'`
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
# 将current转换为时间戳,精确到毫秒
# currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
csvfile=$CUR_DIR/data/${currentdate}".csv"
# 读文件放入数组
arr=()
while read line
do
arr[${#arr[*]}]=$line
done < $readfile
echo ${arr[@]}
# 遍历数组拼成字符串
uids=''
for i in ${arr[@]}
do
uids="$uids$i,"
done
# 去掉最后一个逗号
uids=${uids%*,}
echo $uids
sql="select F_trans_buyer_user_id,count(1) as cnt from wallet.t_wallet_info where F_business_time>='2018-02-28' and F_business_time<='2018-03-28' and F_trans_buyer_user_id in ($uids) and F_business_type=5 group by F_trans_buyer_user_id"
echo $sql
ret=`echo -e ${sql} |gp_rd -t -A`
echo $ret
for var in $ret
do
echo $var
uid=`echo -e $var |awk -F '|' '{print $1}' `
cnt=`echo -e $var |awk -F '|' '{print $2}' `
if [ "$cnt" = "" ]
then
cnt=0
fi
`echo -e "${uid}\t${cnt}" >> $csvfile`
done
# alias gp_rd='psql -h *.*.*.* -p 5432 -d gp_pay -U data_rd'