Files
backend-Eprocurement/services/bastmergedocx.sh
2025-12-05 06:21:42 +07:00

59 lines
2.5 KiB
Bash

#res=$(curl -i -X POST -H "Content-Type: application/json" -H 'x-username:proc' -H 'x-password:pr0c2022#tc3l' http://localhost:8083/PoiWord82/authentification/sync.sh 2>/dev/null)
cd /home/nodejs/wsproc/services/
p=/home/nodejs/wsproc/services/processbast.txt
if [ -f $p ];
then
echo "another process detected, Exiting.."
exit 1;
fi
echo "Starting Time : "`date` > $p
# printf "\n" >> $p
# ==== GET TOken
rm -rf r.json
curl -s -X POST -H "Content-Type: application/json" -H 'x-username:proc' -H 'x-password:pr0c2022#tc3l' http://localhost:8083/PoiWord82/authentification/sync.sh > r.json
token=$(cat r.json | jq -r '.response.token') >> $p
# echo $token
# ==== Merge Docx
# curl -s -X POST -H "Content-Type: application/" -H 'x-token:'$token -d '{"idxjustification":"0"}' http://localhost:8083/PoiWord82/main/sync.sh/mergedoc > m.json
# idxjustification=$(echo "SELECT _idx FROM dbproc.tbl_justification where ismergedoc=0 order by _idx asc limit 1" | mysql -h172.17.12.71 -ussotcel -pssotcel#20i7)
idxbast=`mysql -h172.17.12.71 -ussotcel -pssotcel#20i7 -s -N -e "SELECT _idx FROM dbproc.vw_bast where ismergedoc=0 order by _idx asc limit 1"`
if [ -z "$idxbast" ]
then
echo "\$idxbast is empty"
else
curl -s --location --request POST "http://localhost:8083/PoiWord82/main/sync.sh/mergedocbast" \
--header "x-token: "$token \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "idx="""$idxbast > mbast.json
# cat mbast.json
filedocmerge=$(cat mbast.json | jq -r '.response.filedocmerge[0]')
# echo $filedocmerge
statuscode=$(cat mbast.json | jq -r '.metadata.code')
if [ "$statuscode" == 200 ]
then
mysql -h172.17.12.71 -ussotcel -pssotcel#20i7 -e "update dbproc.tbl_bast set ismergedoc=1,mergedate=now(),filedoc='$filedocmerge' where _idx='$idxbast'"
fi
# # === Create Docx to PDF
curl -s --location --request POST "http://localhost:8083/PoiWord82/main/sync.sh/docxtopdfbast" \
--header "x-token: "$token \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "docxfilename=$filedocmerge" > mbast.json
# cat mbast.json
filedocxpdf=$(cat mbast.json | jq -r '.response.filepdf[0]')
mysql -h172.17.12.71 -ussotcel -pssotcel#20i7 -e "update dbproc.tbl_bast set filepdf='$filedocxpdf' where _idx='$idxbast'"
cat mbast.json >> $p
printf "\n" >> $p
echo "End Time : "`date` >> $p
cat $p > lastprocessbast.txt
fi
rm -rf $p
rm -rf mbast.json