信息转换需求,将详细信息转换成缩略信息存储。
客户给出内部订单信息如W18024-SY,W对应Westinghouse品牌,18024对应订单号,SY对应工厂SYTHTF。
转换后输出信息因该为A18024FB
如E17229-2-SY中,-2表示17229订单第二次生产。转换后为B172292B
#!/bin/bash
brandcode=
factorycode=
ordertailcode=
#A Westinghouse
#B Element
brandmap=(AW BE) #建立映射关系
function brandtrans()
{
for ((i=0; i<${#brandmap[@]}; i++))
do
tmp=${brandmap[$i]}
tbrand=${tmp:1}
if [ "$brand" = "$tbrand" ];then
brandcode=${tmp:0:1}
return;
fi
done
echo " brandmap not find."
}
#A Kunshan KONKA
#B SYTHTF
#C Anhui KONKA
factorycodemap=(AKK BSY CAK D EMTC F 0SH 1HH 2CH 3YH 4NP 5DP 6ZC 7GE 8KE 9NC) #建立映射关系
function factorycodetrans()
{
for ((i=0; i<${#factorycodemap[@]}; i++))
do
tmp=${factorycodemap[$i]}
tfactory=${tmp:1}
if [ "$factory" = "$tfactory" ];then
factorycode=${tmp:0:1}
return;
fi
done
echo " factorymap not find."
}
ordertailmap=(11 22 33 44 55 66 77 88 99 A10 B11 C12 D13 E14 015)
function ordertailcodetrans()
{
for ((i=0; i<${#ordertailmap[@]}; i++))
do
tmp=${ordertailmap[$i]}
tordertail=${tmp:1}
if [ "$ordertail" = "$tordertail" ];then
ordertailcode=${tmp:0:1}
return;
fi
done
echo " ordertailmap not find."
}
#tf_order=E18024-SY
if [ "${tf_order}" = "" ];then
read -p " THTF order id:" tf_order
else
echo " THTF order id:${tf_order}"
fi
if [ "${tf_order}" = "" ];then
return
fi
array=(${tf_order//-/ }) #${parameter//pattern/string} 用string来替换parameter变量中所有匹配的pattern
brand=${tf_order:0:1} #取字符串的 0开始 1个长度的字符
orderid=${array[0]:1} #取array[0] 1开始到结尾的字符
if [ ${#array[@]} -eq 2 ];then # array的长度=${#array[@]}
factory=${array[1]}
ordertailcode=F
else
factory=${array[2]}
ordertail=${array[1]}
ordertailcodetrans
fi
brandtrans
factorycodetrans
if [ "${brandcode}" = "" ] || [ "${orderid}" = "" ] || [ "${ordertailcode}" = "" ] || [ "${ordertailcode}" = "" ];then
Customized_Number=${tf_order}
else
Customized_Number=${brandcode}${orderid}${ordertailcode}${factorycode}
fi
echo " "${tf_order}" -> "${Customized_Number}
if [ "${Order_Config_path}" != "" ]; then
sed -i "s/Customized_Number=.*/Customized_Number=${Customized_Number}/g" ${Order_Config_path}/projects/board/INI/netready/NetReady.ini
else
echo " Customer order not set, run source ctv_env.sh"
fi