{ "cells": [ { "cell_type": "markdown", "id": "4925cb3a-bea3-4a4d-9590-6b91b62ca5b4", "metadata": {}, "source": [ "# 体质检测管理" ] }, { "cell_type": "markdown", "id": "2a85feec-695b-4ea8-8093-91a59ed34c7f", "metadata": {}, "source": [ "## 体测单位信息导入" ] }, { "cell_type": "code", "execution_count": null, "id": "c5a0568c-3833-4335-a4b9-600310e1a541", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import pymongo\n", "\n", "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", "mydb = myclient[\"tice\"]\n", "mycol = mydb[\"unit\"]\n", "\n", "name = '中国石油化工股份有限公司安庆炼化分公司'\n", "short_name = '安庆炼化'\n", "myquery = { \"name\": name}\n", "if mycol.find_one(myquery) is None: \n", " wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n", " sheet = wb.active\n", " #sheets = wb.sheetnames\n", " depart = []\n", " dict1 = {}\n", " new_code = []\n", " for n in range(2,sheet.max_row+1):\n", " m_depart = sheet.cell(n,5).value\n", " if m_depart not in depart:\n", " depart.append(sheet.cell(n,5).value)\n", " #print(sheet.cell(n,5).value)\n", "\n", " dict1['name'] = '中国石油化工股份有限公司安庆炼化分公司'\n", " dict1['short_name'] = '安庆炼化'\n", " dict1['depart'] = depart\n", " mycol.insert_one(dict1)\n", " print('ok!')\n", "else:\n", " print('该单位已存在!') \n", " " ] }, { "cell_type": "markdown", "id": "bf42e8af-a506-4e60-a661-b4281e3fef54", "metadata": {}, "source": [ "## 录入体测信息" ] }, { "cell_type": "code", "execution_count": 26, "id": "91a8f4f4-c417-4db7-94ba-2d3404e5c2c9", "metadata": { "execution": { "iopub.execute_input": "2021-10-12T07:52:26.950635Z", "iopub.status.busy": "2021-10-12T07:52:26.949701Z", "iopub.status.idle": "2021-10-12T07:52:27.307490Z", "shell.execute_reply": "2021-10-12T07:52:27.304804Z", "shell.execute_reply.started": "2021-10-12T07:52:26.950528Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok!\n" ] } ], "source": [ "import pymongo\n", "from bson.objectid import ObjectId\n", "from dateutil import parser\n", "\n", "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", "mydb = myclient[\"tice\"]\n", "mycol = mydb[\"unit\"]\n", "mycol1 = mydb[\"event\"]\n", "dict1 = {}\n", "\n", "name = '中国石油化工股份有限公司安庆炼化分公司'\n", "myquery = { \"name\": name}\n", "dict1['code'] = 120\n", "dict1['unit'] = '中国石油化工股份有限公司安庆炼化分公司'\n", "dict1['address'] = '安徽安庆'\n", "dict1['date_begin'] ='2021-09-08'\n", "dict1['date_end'] = '2021-09-30'\n", "if mycol.find_one(myquery) is None: \n", " print('体测单位不存在!')\n", "else:\n", " myquery1 = { \"code\": dict1['code']}\n", " if mycol1.find_one(myquery1) is None:\n", " mycol1.insert_one(dict1)\n", " print('ok!')\n", " else:\n", " print('该体测信息已经存在!')" ] }, { "cell_type": "markdown", "id": "0c144068-4f2d-4901-bd28-725ecb260fd4", "metadata": {}, "source": [ "## 导入单位员工信息" ] }, { "cell_type": "code", "execution_count": 19, "id": "d80c482d-aee2-45cf-8ac8-c357171f17f7", "metadata": { "execution": { "iopub.execute_input": "2021-10-12T06:40:29.318503Z", "iopub.status.busy": "2021-10-12T06:40:29.317557Z", "iopub.status.idle": "2021-10-12T06:40:29.351278Z", "shell.execute_reply": "2021-10-12T06:40:29.348925Z", "shell.execute_reply.started": "2021-10-12T06:40:29.318396Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'_id': ObjectId('6164fc343d39c8cdd2d97179'), 'name': '中国石油化工股份有限公司安庆炼化分公司', 'short_name': '安庆炼化', 'depart': ['办公室', '会议中心', '生产计划部', '设备工程部', '发展规划部', '安全环保部', '消防支队', '财务资产部', '企业管理部', '企业发展研究会', '审计部', '党委组织部', '党群工作部', '纪委监督部', '销售中心', '信息中心', '行政事务中心', '炼油一部', '炼油二部', '化工一部', '化工二部', '腈纶部', '热电部', '储运部', '水务部', '运输部', '电气仪表中心', '质管中心', '物资采购中心', '华成公司', '项目管理部', 'AQ基地', '调研']}\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "import pymongo\n", "from bson.objectid import ObjectId\n", "\n", "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", "mydb = myclient[\"tice\"]\n", "mycol = mydb[\"unit\"]\n", "\n", "myquery = { \"_id\": ObjectId(\"6164fc343d39c8cdd2d97179\")}\n", " \n", "mydoc = mycol.find(myquery)\n", " \n", "for x in mydoc:\n", " print(x)" ] }, { "cell_type": "code", "execution_count": null, "id": "bfed373e-500d-4618-8344-9b8ddd0c5e8c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }