操作界面
这个小系统一共包含4个脚本
sh | 功能 | 备注 |
oneKey.sh | 主程序,调用其他程序,对外提供功能 | |
menu.sh | 勾画菜单 | |
function.sh | 提供操作数据库接口 | |
valid.sh | 操作mysql数据库,验证数据 |
menu.sh
画字符菜单
#!/bin/bash function print_main_menu(){ cat <<EOF ####################################### # 1)创建数据库 # # 2)导入电商端数据 # # 3)创建电商端数据库并导入数据 # # 4)验证电商端数据数据有效性 # # 5)删除数据库 # # 6)打印菜单 # # 7)退出 # ####################################### EOF }
function.sh
#!/bin/bash #作者: #版本:v1.0 #用途:创建mysql 数据库和数据库表 #创建数据库 4个必须参数(user,password,database_name,charset) function create_database_01(){ USER="$1" PASSWORD="$2" IP="$3" DATEBASE_NAME="$4" DATABASE_CHARSET="utf8" mysql -h $IP -u $USER -p$PASSWORD <<EOF 2>/dev/null create database $DATEBASE_NAME charset=$DATABASE_CHARSET; EOF if [[ $? -eq 0 ]]; then echo "数据库"$DATEBASE_NAME"创建成功" else echo "数据库"$DATEBASE_NAME"创建失败" exit 1; fi } #扫描地区目录中数据库文件夹,按顺序执行 function init_database_02(){ USER="$1" PASSWORD="$2" IP="$3" DATEBASE_NAME="$4" AREACODE="$5" while read line; do mysql -h $IP -u $USER -p$PASSWORD $DATEBASE_NAME <$line 2>/dev/null done < <(ls ./$AREACODE/*.sql -rt) if [[ $? -eq 0 ]]; then echo "往"$DATEBASE_NAME"导入数据成功" else echo "往"$DATEBASE_NAME"导入数据失败" exit 1; fi } #删除数据库 function drop_database_02(){ USER="$1" PASSWORD="$2" IP="$3" DATEBASE_NAME="$4" mysql -h $IP -u $USER -p$PASSWORD <<EOF 2>/dev/null drop database $DATEBASE_NAME; EOF if [[ $? -eq 0 ]]; then echo "数据库"$DATEBASE_NAME"删除成功" else echo "数据库"$DATEBASE_NAME"删除失败" exit 1; fi } #读取参数 function readstdin(){ read -p "please input ip[localhost]:" ip if [[ -z "$ip" ]]; then ip="localhost" fi read -p "please input db login user[root]:" username if [[ -z "$username" ]]; then username="root" fi read -p "please input db login password:" password read -p "please input db name:" dbname }
valida.sh
#!/bin/bash dbname="test_jd_dspt_wh" nsrsbh="420112568371402" mysql="mysql -h 192.168.15.9 -u root -p123456 $dbname" #$mysql "use $dbname" sql="select count(nsrsbh) into @v01 from dj_nsrxx where nsrsbh=$nsrsbh; select if(@v01<=0,‘纳税人识别号在dj_nsrxx表中没有记录‘, ‘验证01[纳税人识别号在dj_nsrxx表中存在]验证通过!!!‘); select dsptbm into @dsptbm from dj_nsrxx where nsrsbh=$nsrsbh; select pt.dsptmc into @dsptmc from dj_dzswpt_kz kz ,dj_dzswpt pt where kz.id =pt.id and [email protected]; select if(@dsptmc is not null,concat(‘验证02通过纳税人电商平台信息:‘,@dsptmc),‘验证02[纳税人电商平台信息为空]验证不通过!!!‘); select hy_dm into @vhy from dj_nsrxx where [email protected]; select kpzt into @vkpzt from dj_nsrxx where [email protected]; select nsrzt_dm into @vnsrzt from dj_nsrxx where [email protected]; select if(@vhy!=5200,‘纳税人行业代码不等于5200‘,‘验证03[纳税人行业代码等于5200]验证通过!!!‘); select if(@vnsrzt!=21,‘纳税人状态代码不等于21‘,‘验证04[纳税人状态代码等于21]验证通过!!!‘); select if(@vkpzt!=1,‘纳税人开票状态不等于1‘,‘验证05[纳税人开票状态等于1]验证通过!!!‘); SELECT COUNT(1) into @nsrztcount FROM fp_nsrzt WHERE SWJG_DM = (SELECT SZ_SWJG_DM FROM dj_nsrxx WHERE NSRSBH = @vnsrsbh) AND NSRZT_DM = @vnsrzt; select if(@nsrztcount<=0,‘纳税人税务机关[SZ_SWJG_DM]不存在或状态与纳税人信息不匹配‘,‘验证06[纳税人所在税务机关SZ_SWJG_DM有效]验证通过!!!‘); select ‘上述所有验证均通过,可保证订单可以下发成功‘; select count(1) into @vjccount2 from fp_pz pz, fp_nsrjc jc where jc.NSRSBH=pz.NSRSBH and pz.FPZL_DM=jc.FPZL_DM and [email protected]; select if(@vjccount2<=0,‘纳税人票种或结存为空‘,‘验证07[纳税人开票结存]验证通过!!!‘); select count(1) into @dymbcount from dm_dymb mb where SWJG_DM=(select SZ_SWJG_DM from dj_nsrxx where [email protected]); select if(@dymbcount<4,‘所在税务机关打印模板数目不足4个‘,‘验证08[打印模板]验证通过,不保证模板路径有效!!!‘); select concat(‘____‘,PYFILEURL) as ‘打印模板如下‘ from dm_dymb mb where SWJG_DM=(select SZ_SWJG_DM from dj_nsrxx where [email protected]); select qzid into @vqzid from fp_qzcx where [email protected]; select if(@vqzid is null,‘纳税人签章信息不存在‘,‘验证09[签章信息]验证通过!!!‘); "; $mysql -N -L -s -e "$sql"
时间: 2024-10-08 13:25:22