现在的统版系统中,每天有一张"邮政储蓄营业轧帐单",显示了每天的存取交易量,但如果想得到一个月或更多的每天或合计交易量,好像就没办法查了,只能手工汇总统计,现在做了个shell,可以显示指定网点指定月份的交易量和合计,前提是每天的报表已是正确下载,并且在前置机print未删除这些报表.
该shell现限制为能由统版用户执行,生成的统版报表为存放于统版/print/机构号/机构号.log
shell现在的统版用户名为四川的scabs,报表目录为/usr/scabs/print,如各位有所不同,请自行修改.^_^
现在还在考虑加入表格每列竖线功能,使之能成为一张真正的表格,但现在每行的记录字段值设的比较大,如业务笔数至少就要占5位数(万笔),金额至少也要12位,那如果每列再加入竖线,这时在有压缩功能的打印机打印出来是正常的,但由于某些终端显示列数的限制(如我现在的NL-3000每屏只能显示80列),在终端运行该shell查看时报表会挪位........有的终端就可以调整列数,如NL-320....那显示就应该对的吧,不过没试过....
#!/bin/ksh
#查询统计交易量的shell V050810
#乐山市沙湾区邮政局 宋 涛
#改进生成表格每行横线 V050810
#改进生成表格每行标准横线 V050810
#增加表末显示统计功能 V050811
#改进表末统计结果显示小数位的问题 V050812
#增加在命令行使用参数$1,$2及简单帮助 V050812
#增加判断当无报表文件时的出错处理 V050812
#终于加入了表格竖线,但在终端显示不完全 :-( v050812
#改进了表格文件的存盘文件名,改进了月份输入及判断的bug,改进了出错后的显示问题,增加了选择打印功能 V050813
#改进了检测vmore的处理,增加统计平均数,修正了表格显示问题 V050817
trap 'tput sgr0 rm ${printdir}temp.log 2>/dev/null; echo ' 0 1 2 3 9 15
clear
tput bold
test "$LOGNAME" != "scabs" && { tput bel echo "\033[05m" "\n\n Sorry ! 本 程 序 只 能 由 scabs 用 户 执 行 !\n\n" \
tput sgr0 exit 0 }
jg=$1
mm=$2
if [ "$jg" = "-h" ]
then
tput bel
echo '\n 查询统计交易量\n'
echo " 调用格式:" `basename $0` "[ 机构号 ] [ 月份 ] \n"
echo ' 机构号: 9位机构代码, -h 为帮助 ,q 或 Q 为退出\n'
echo ' 月份: 1或2位查询统计的月份,回车则默认为当月月份,q 或 Q 为退出\n'
echo ' \n\n 注: 以上参数均为可选参数,作用是快捷操作,如无参数,则在程序中进行输入\n'
exit 0
fi
while :
do
tput cup 3 5
test "$jg" = "" && { echo " 查 询 统 计 交 易 量 \n" \
echo -n "\n 请输入欲查询统计的机构号(输入为 q 为退出): \c" read jg }
test "$jg" = "q" -o "jg" = "Q" && exit 0
printdir="/usr/scabs/print/"
if [ -d $printdir$jg ]
then
break
else
echo "\n $jg 该机构目录不存在 \n" read jg= tput cup 4 0
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
continue
fi
done
while :
do
tput cup 8
test "$mm" = "" && { echo -n " 请输入欲查询统计的月份(输入为 q 为退出): \c" read mm }
test "$mm" = "q" -o "$mm" = "Q" && exit 0
test "$mm" = "" && { mm=`date +%m` break }
if [ `expr $mm : "^[0-9][0-9]*$"` -gt 0 ]
then
:
else
echo "\n $mm 月份必须为数值\n" read mm= tput cup 8 0
echo " "
echo " "
echo " "
echo " "
continue
fi
if [ "$mm" -gt 0 -a "$mm" -le 12 ]
then
test `expr length $mm` -eq 1 && mm=`printf "%01d"$mm` break
else
echo "\n $mm 月份输入错误\n" read mm= tput cup 8 0
echo " "
echo " "
echo " "
echo " "
continue
fi
done
cd $printdir$jg
fn=`ls rpt_Mnacc_001${jg}${mm}*.dat 2>/dev/null`
test "$fn" = "" && { echo "\n 未找到 $mm 月的报表文件 !\n " exit 0 }
fn=`echo $fn|awk '{print $1}'`
dmjg=`tr "|" '\n'<$fn |sed -n '1p;2p'`
echo "\n 查 询 统 计 交 易 量 表\n" >${printdir}${jg}/${jg}${mm}.log
echo $dmjg | awk '{printf("%10s%9s%12s%s\n"),"机构号: ",$1,"网点名称: ",$2}' >>${printdir}${jg}/${jg}${mm}.log
echo "┌─────────────────┬──────────────┬─────────────┐" >>${printdir}${jg}/${jg}${mm}.log
echo "│ 存入 │ 支取 │ 结余 │" | awk '{printf("%s%21s%15s%15s%15s%13s%15s\n",$1,$2,$3,$4,$5,$6,$7)}' >>${printdir}${jg}/${jg}${mm}.log
echo "├──┬───┬───┬──────┼───┬───┬──────┼────┬────────┤" >>${printdir}${jg}/${jg}${mm}.log
echo "│ 日期 │ 笔数 │ 续存 │ 金额 │ 销户 │ 支取 │ 金额 │ 户数 │ 余额 │" \
| awk '{printf("%s%2s%s%6s%s%6s%s%12s%s%6s%s%6s%s%12s%s%8s%s%16s%s\n"),$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19}'\
>>${printdir}${jg}/${jg}${mm}.log
>${printdir}temp.log
for fn in `ls rpt_Mnacc_001${jg}${mm}*.dat`
do
rq=`echo $fn|cut -c23-26`
mx=`tr "|" '\n' <$fn |sed -n '312p;313p;;314p;315p;316p;317p;320p;321p'`
echo $mx >> ${printdir}temp.log
echo "├──┼───┼───┼──────┼───┼───┼──────┼────┼────────┤" >>${printdir}${jg}/${jg}${mm}.log
echo "│" $rq $mx "│" \
|awk '{printf("%s%2s%s%6d%s%6d%s%12.2f%s%6d%s%6d%s%12.2f%s%8d%s%16.2f%s\n"),$1,$2,"│",$3,"│",$4,"│",$5,"│",$6,"│",$7,"│",$8,"│",$9,"│",$10,$11}' >>${printdir}${jg}/${jg}${mm}.log
done
echo "├──┼───┼───┼──────┼───┼───┼──────┼────┼────────┤" >>${printdir}${jg}/${jg}${mm}.log
sum=`awk '{a+=$1} {b+=$2} {c+=$3} {d+=$4} {e+=$5} {f+=$6} {g+=$7} {i+=$8} END{printf("%6d%6d%12.2f%6d%6d%12.2f%8d%16.2f%4d"),a,b,c,d,e,f,g,i,NR}' ${printdir}temp.log`
avg=`echo $sum| awk '{printf("%6d%6d%12.2f%6d%6d%12.2f%8d%16.2f%"),$1/$9,$2/$9,$3/$9,$4/$9,$5/$9,$6/$9,$7/$9,$8/$9}'`
echo $avg |awk '{printf("%s%2s%s%6d%s%6d%s%12.2f%s%6d%s%6d%s%12.2f%s%8d%s%16.2f%s\n"),"│","平均","│",$1,"│",$2,"│",$3,"│",$4,"│",$5,"│",$6,"│",$7,"│",$8,"│"}' >> ${printdir}${jg}/${jg}${mm}.log
echo "├──┼───┼───┼──────┼───┼───┼──────┼────┼────────┤" >>${printdir}${jg}/${jg}${mm}.log
echo $sum |awk '{printf("%s%2s%s%6d%s%6d%s%12.2f%s%6d%s%6d%s%12.2f%s%8d%s%16.2f%s\n"),"│","汇总","│",$1,"│",$2,"│",$3,"│",$4,"│",$5,"│",$6,"│",$7,"│",$8,"│"}' >> ${printdir}${jg}/${jg}${mm}.log
echo "└──┴───┴───┴──────┴───┴───┴──────┴────┴────────┘" >>${printdir}${jg}/${jg}${mm}.log
clear
test -e /usr/bin/vmore -a -r /usr/bin/vmore -a -x /usr/bin/vmore && \
vmore ${printdir}${jg}/${jg}${mm}.log || pg ${printdir}${jg}/${jg}${mm}.log
echo -n '\n\n 需要打印该报表吗( y 为打印,其它为退出): '
read prin
test "$prin" = "y" -o "$prin" = "Y" || exit 0
ttyname="/dev/"`tty|cut -c6-12`
ls ${printdir}${jg}/${jg}${mm}.log > ${printdir}temp.log
list=`cat ${printdir}temp.log | awk '{print $1}'`
for fl in $list
do
echo "\\033[5i"
cat $fl >$ttyname
echo "\\033[4i"
done
|
|
|