remove_his_detail.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. max_day="2021-01-01"
  3. year=
  4. while getopts ":y:m:" opt; do
  5. case $opt in
  6. y)
  7. year=$OPTARG
  8. ;;
  9. m)
  10. month=$OPTARG
  11. ;;
  12. ?)
  13. echo "usage: dumpdata -y=2019 -m=2"
  14. exit 1
  15. ;;
  16. esac
  17. done
  18. if [ ! -n "$year" ]; then
  19. echo "no year paramerter"
  20. exit 1
  21. fi
  22. if [ ! -n "$month" ]; then
  23. echo "no month paramerter"
  24. exit 1
  25. fi
  26. start_month=$(printf "%02d" ${month})
  27. start_year=${year}
  28. next_month=$(expr ${month} + 1)
  29. if [ $next_month -gt 12 ]; then
  30. end_month="01"
  31. end_year=$(expr ${year} + 1)
  32. else
  33. end_month=$(printf "%02d" ${next_month})
  34. end_year=${year}
  35. fi
  36. start_day="${start_year}-${start_month}-01"
  37. start_time="${start_year}-${start_month}-01 00:00:00"
  38. start_ts=$(date -u -d ${start_day} +%s)000
  39. echo "start ts: $start_ts"
  40. echo "start time: $start_time"
  41. end_day="${end_year}-${end_month}-01"
  42. end_ts=$(date -u -d ${end_day} +%s)000
  43. end_time="${end_year}-${end_month}-01 00:00:00"
  44. echo "end_day: $end_day"
  45. echo "end_time: $end_time"
  46. echo "end ts: $end_ts"
  47. if [ "$end_day" \> "$max_day" ]; then
  48. echo "invalid day."
  49. exit 1
  50. fi
  51. make_js() {
  52. _db_name=$1
  53. _col_name=$2
  54. _start_ts=$3
  55. _end_ts=$4
  56. _output_file=$5
  57. echo "use ${_db_name};" >${_output_file}
  58. echo 'var bulk = db.getCollection("'${_col_name}'").initializeUnorderedBulkOp();' >>${_output_file}
  59. echo 'bulk.find({"$and": [{"dateTimeAdded": {"$gte":new Date('${_start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${_end_ts}')}}]}).remove();' >>${_output_file}
  60. echo "bulk.execute();" >>${_output_file}
  61. cat ${_output_file}
  62. }
  63. echo "====================== dealer_income_proxies begin ============================="
  64. make_js "report_his" "dealer_income_proxies" ${start_ts} ${end_ts} "temp.js"
  65. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  66. rm temp.js
  67. echo "====================== dealer_income_proxies end =============================\n"
  68. echo "====================== ConsumeRecord begin ============================="
  69. make_js "washpay_his" "ConsumeRecord" ${start_ts} ${end_ts} "temp.js"
  70. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  71. rm temp.js
  72. echo "====================== ConsumeRecord end =============================\n"
  73. echo "====================== RechargeRecord begin ============================="
  74. make_js "washpay_his" "RechargeRecord" ${start_ts} ${end_ts} "temp.js"
  75. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  76. rm temp.js
  77. echo "====================== RechargeRecord end =============================\n"