20211221
This commit is contained in:
1 parent
6d0c3ab4c6
commit
5e79ead37f
1 file changed
+63
-47
+63
-47
@@ -95,7 +95,7 @@
|
|||||||
"short_name = '石家庄炼化'\n",
|
"short_name = '石家庄炼化'\n",
|
||||||
"myquery = {\"name\": name}\n",
|
"myquery = {\"name\": name}\n",
|
||||||
"if mycol.find_one(myquery) is None:\n",
|
"if mycol.find_one(myquery) is None:\n",
|
||||||
" wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n",
|
" wb = openpyxl.load_workbook('data/中石化石家庄人员名单.xlsx')\n",
|
||||||
" sheet = wb.active\n",
|
" sheet = wb.active\n",
|
||||||
" # sheets = wb.sheetnames\n",
|
" # sheets = wb.sheetnames\n",
|
||||||
" depart = []\n",
|
" depart = []\n",
|
||||||
@@ -107,8 +107,8 @@
|
|||||||
" depart.append(sheet.cell(n,5).value)\n",
|
" depart.append(sheet.cell(n,5).value)\n",
|
||||||
" # print(sheet.cell(n,5).value)\n",
|
" # print(sheet.cell(n,5).value)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" dict1['name'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
" dict1['name'] = '中国石油化工股份有限公司石家庄炼化分公司'\n",
|
||||||
" dict1['short_name'] = '安庆炼化'\n",
|
" dict1['short_name'] = '石家庄炼化'\n",
|
||||||
" dict1['depart'] = depart\n",
|
" dict1['depart'] = depart\n",
|
||||||
" mycol.insert_one(dict1)\n",
|
" mycol.insert_one(dict1)\n",
|
||||||
" print('ok!')\n",
|
" print('ok!')\n",
|
||||||
@@ -142,20 +142,22 @@
|
|||||||
"mycol = mydb[\"unit\"]\n",
|
"mycol = mydb[\"unit\"]\n",
|
||||||
"mycol1 = mydb[\"event\"]\n",
|
"mycol1 = mydb[\"event\"]\n",
|
||||||
"dict1 = {}\n",
|
"dict1 = {}\n",
|
||||||
"\n",
|
"dict2 = {}\n",
|
||||||
"name = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
"code = '119'\n",
|
||||||
|
"name = '中国石油化工股份有限公司石家庄炼化分公司'\n",
|
||||||
"myquery = {\"name\": name}\n",
|
"myquery = {\"name\": name}\n",
|
||||||
"dict1['code'] = 120\n",
|
"\n",
|
||||||
"dict1['unit'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
"dict2['unit'] = '中国石油化工股份有限公司石家庄炼化分公司'\n",
|
||||||
"dict1['address'] = '安徽安庆'\n",
|
"dict2['address'] = '河北石家庄'\n",
|
||||||
"dict1['date_begin'] = '2021-09-08'\n",
|
"dict2['date_begin'] = '2021-08-03'\n",
|
||||||
"dict1['date_end'] = '2021-09-30'\n",
|
"dict2['date_end'] = '2021-08-20'\n",
|
||||||
|
"dict1[code] = dict2\n",
|
||||||
"if mycol.find_one(myquery) is None:\n",
|
"if mycol.find_one(myquery) is None:\n",
|
||||||
" print('体测单位不存在!')\n",
|
" print('体测单位不存在!')\n",
|
||||||
"else:\n",
|
"else:\n",
|
||||||
" myquery1 = {\"name\": name,\"event.code\": dict1['code']}\n",
|
" myquery1 = {\"name\": name,\"event.code\": code}\n",
|
||||||
" if mycol.find_one(myquery1) is None:\n",
|
" if mycol.find_one(myquery1) is None:\n",
|
||||||
" mycol.update_one(myquery,{'$push':{'event':dict1}})\n",
|
" mycol.update_one(myquery,{'$set':{f'exam.{code}':dict2}},True)\n",
|
||||||
" print('ok!')\n",
|
" print('ok!')\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" print('该体测信息已经存在!')"
|
" print('该体测信息已经存在!')"
|
||||||
@@ -219,6 +221,14 @@
|
|||||||
"## 获取测试人员名单导入数据库"
|
"## 获取测试人员名单导入数据库"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "611d2cc4-26c3-4c42-82ad-21f843f2c699",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### 安庆炼化"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@@ -287,43 +297,51 @@
|
|||||||
"print('ok!')"
|
"print('ok!')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "edc06db7-9ae5-441a-8273-88ad598096ba",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### 石家庄炼化"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "422270f4-5658-4869-8cc6-cf674ad95abf",
|
"id": "2fc0a54e-6a54-46e4-a9c2-f27243b8918c",
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import json\n",
|
"import json\n",
|
||||||
"import pymongo\n",
|
"import pymongo\n",
|
||||||
"from bson.objectid import ObjectId\n",
|
"from bson.objectid import ObjectId\n",
|
||||||
|
"import os,sys,shutil\n",
|
||||||
"\n",
|
"\n",
|
||||||
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
||||||
"mydb = myclient[\"tice\"]\n",
|
"mydb = myclient[\"tice\"]\n",
|
||||||
"mycol = mydb[\"person1\"]\n",
|
"mycol = mydb[\"person\"]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
"fi_path = os.getcwd() + '/file/210803'\n",
|
||||||
"cursor = db.cursor()\n",
|
"filename = '石家庄炼化人员名单.json'\n",
|
||||||
"\n",
|
"code = '119'\n",
|
||||||
"place_id = 120\n",
|
"fl=os.listdir(fi_path)\n",
|
||||||
"exam_person = []\n",
|
"old = []\n",
|
||||||
"sql = f'SELECT distinct a.avatar_id FROM places_result AS a WHERE a.place_id={place_id} and a.avatar_id < 4999 ORDER BY a.avatar_id '\n",
|
"for fn in fl:\n",
|
||||||
"cursor.execute(sql)\n",
|
" if os.path.isfile(fi_path + '/' + fn):\n",
|
||||||
"results = cursor.fetchall()\n",
|
" ofn = fn.split('.')[0].rjust(5,\"0\")\n",
|
||||||
"cursor.close\n",
|
" old.append(ofn) \n",
|
||||||
"for result in results:\n",
|
"old.sort()\n",
|
||||||
" exam_person.append(str(result[0]).rjust(5,'0'))\n",
|
|
||||||
"\n",
|
|
||||||
"filename = '安庆炼化人员名单.json'\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"list1 = []\n",
|
"list1 = []\n",
|
||||||
"list2 = []\n",
|
"list2 = []\n",
|
||||||
"with open(filename,'r') as fl:\n",
|
"with open(filename,'r') as fl:\n",
|
||||||
" all_person = json.load(fl)\n",
|
" all_person = json.load(fl)\n",
|
||||||
"with open('result.json','r') as fl1:\n",
|
"with open('result1.json','r') as fl1:\n",
|
||||||
" res = json.load(fl1)\n",
|
" res = json.load(fl1)\n",
|
||||||
"for k,v in all_person.items():\n",
|
"for k, v in all_person.items():\n",
|
||||||
" if k in exam_person:\n",
|
" if k in old:\n",
|
||||||
" dict2 = {}\n",
|
" dict2 = {}\n",
|
||||||
" dict3 = {}\n",
|
" dict3 = {}\n",
|
||||||
" dict2['name'] = v['name']\n",
|
" dict2['name'] = v['name']\n",
|
||||||
@@ -338,16 +356,15 @@
|
|||||||
" s = v['id_num']\n",
|
" s = v['id_num']\n",
|
||||||
" dict2['id_num'] = s\n",
|
" dict2['id_num'] = s\n",
|
||||||
" dict2['birth'] = f'{s[6:10]}-{s[10:12]}-{s[12:14]}'\n",
|
" dict2['birth'] = f'{s[6:10]}-{s[10:12]}-{s[12:14]}'\n",
|
||||||
" dict2.setdefault('exam',[])\n",
|
" dict2.setdefault('exam',{})\n",
|
||||||
" dict3['code'] = 120\n",
|
" \n",
|
||||||
|
" #dict3['code'] = 120\n",
|
||||||
" dict3['sn'] = k\n",
|
" dict3['sn'] = k\n",
|
||||||
" dict3['result'] = res[k]\n",
|
" dict3['result'] = res[k]\n",
|
||||||
" dict2['exam'].append(dict3)\n",
|
" dict2['exam'][code] = dict3\n",
|
||||||
" list1.append(dict2)\n",
|
" list1.append(dict2)\n",
|
||||||
"x = mycol.insert_many(list1)\n",
|
"x = mycol.insert_many(list1)\n",
|
||||||
"mycol1 = mydb[\"event\"]\n",
|
"\n",
|
||||||
"myquery = {'code':120}\n",
|
|
||||||
"mycol1.update_one(myquery,{'$push':{'persons':x.inserted_ids}})\n",
|
|
||||||
"print('ok!')"
|
"print('ok!')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -688,14 +705,14 @@
|
|||||||
"mydb = myclient[\"tice\"]\n",
|
"mydb = myclient[\"tice\"]\n",
|
||||||
"mycol = mydb[\"person\"]\n",
|
"mycol = mydb[\"person\"]\n",
|
||||||
"#体质监测编号\n",
|
"#体质监测编号\n",
|
||||||
"code = '120'\n",
|
"code = '119'\n",
|
||||||
"UploadCache = \"uploadcache\"\n",
|
"UploadCache = \"uploadcache\"\n",
|
||||||
"dbURL = \"mongodb://localhost:27017\"\n",
|
"dbURL = \"mongodb://localhost:27017\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"#上传文件\n",
|
"#上传文件\n",
|
||||||
"def upLoadFile(file_coll,file_name,data_link):\n",
|
"def upLoadFile(file_coll,file_name,data_link):\n",
|
||||||
" \n",
|
" \n",
|
||||||
" filter_condition = {\"filename\": code + '-' + os.path.basename(file_name), \"url\": data_link}\n",
|
" filter_condition = {\"filename\": code + '-' + os.path.basename(file_name).rjust(9,\"0\"), \"url\": data_link}\n",
|
||||||
" gridfs_col = GridFS(mydb, collection=file_coll)\n",
|
" gridfs_col = GridFS(mydb, collection=file_coll)\n",
|
||||||
" file_ = \"0\"\n",
|
" file_ = \"0\"\n",
|
||||||
" query = {\"filename\":\"\"}\n",
|
" query = {\"filename\":\"\"}\n",
|
||||||
@@ -717,20 +734,19 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"dict1 = {}\n",
|
"dict1 = {}\n",
|
||||||
"list1 = []\n",
|
"list1 = []\n",
|
||||||
"#mycol.update_one(myquery,{'$push':{'persons':list1}})\n",
|
"\n",
|
||||||
"fl_path = 'file/new'\n",
|
"fl_path = 'file/210803'\n",
|
||||||
"fl=glob.glob(f'{fl_path}/*.pdf')\n",
|
"fl=glob.glob(f'{fl_path}/*.pdf')\n",
|
||||||
"fl.sort()\n",
|
"fl.sort()\n",
|
||||||
"for fi in fl:\n",
|
"for fi in fl:\n",
|
||||||
" dict1 = {}\n",
|
" dict1 = {}\n",
|
||||||
" s = os.path.basename(fi).split('.')[0]\n",
|
" s = os.path.basename(fi).split('.')[0]\n",
|
||||||
" print(s) \n",
|
" ss = s.rjust(5,\"0\")\n",
|
||||||
" ss = upLoadFile(\"report\",fi,\"\")\n",
|
" print(fi,ss) \n",
|
||||||
|
" sss = upLoadFile(\"report\",fi,\"\") \n",
|
||||||
" \n",
|
" \n",
|
||||||
" print(s)\n",
|
" myquery = {f'exam.{code}.sn':ss}\n",
|
||||||
" myquery = {f'exam.{code}.sn':s}\n",
|
" mycol.update_one(myquery,{'$set':{f'exam.{code}.report':sss}},True)\n",
|
||||||
" mycol.update_one(myquery,{'$set':{f'exam.{code}.report':ss}},True)\n",
|
|
||||||
" #print(myquery)\n",
|
|
||||||
" \n"
|
" \n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user