diff --git a/company/db.py b/company/db.py index 7683f95..7cecf72 100644 --- a/company/db.py +++ b/company/db.py @@ -2,6 +2,7 @@ import pymongo client_tfse = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format('root', 'sromitdTW569kC#M', '116.63.130.34', 27018)) client_tyc = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format('root', 'gP%40DwMSVd5Sh6EiH', '116.63.130.34', 27019)) +client_admin = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format('root', 'RYIHrqml#LSW6#!*', '116.63.130.34', 27020)) def find_data_in_tyc(param1, param2, param3): @@ -64,3 +65,20 @@ def conserve_data_to_tfse(param1, param2, param3, param4): collection = client_tfse[param1][param2] collection.update_one(param3, {"$set": param4}, upsert=True) + +def update_data(param1, param2, param3, param4): + """ + 更新数据 + Parameters: + param1: string 数据库 + param2: string 数据集 + param3: string 查询条件 + param4: dict 需要更新的数据 + Returns: + - + """ + collection = client_admin[param1][param2] + res = collection.update_one(param3, {"$set": param4}) + info = res.raw_result['updatedExisting'] + return info + diff --git a/company/routes.py b/company/routes.py index 3bd9257..7b21f39 100644 --- a/company/routes.py +++ b/company/routes.py @@ -71,3 +71,23 @@ def esg_rating(): esg_rating_etl(rid) return {"info": "数据准备完成"}, 200 + + +@company_route.route('/update_process_data', methods=['POST']) +@verify_token +def update_process(): + """ + 更新流程数据 + Parameters: + rid str 评价ID + data dict 需要更新的数据 + Returns: + - + """ + rid = request.json['rid'] + renew_data = request.json['renew_data'] + + info = update_process_scripts(rid, renew_data) + status = 200 if info else 210 + result = '更新成功' if info else '更新失败' + return {"info": result}, status diff --git a/company/scripts.py b/company/scripts.py index da4f868..8f8c084 100644 --- a/company/scripts.py +++ b/company/scripts.py @@ -6,7 +6,7 @@ import requests import pandas as pd from common.scripts import read_json_file, sub_dict, df_iterrows -from company.db import find_data_in_tyc, insert_data_to_tfse, find_data_in_tfse, conserve_data_to_tfse +from company.db import find_data_in_tyc, insert_data_to_tfse, find_data_in_tfse, conserve_data_to_tfse, update_data from rating.scripts.risk_detail import associate_risk_detail, change_log_detail @@ -812,3 +812,16 @@ def calculate_weight(param): weight_data = json.load(f) weight = str(round(param[1] / weight_data[param[0]] * 100, 2)) + '%' return weight + + +def update_process_scripts(param1, param2): + """ + 更新流程数据 + Parameters: + param1 str 评价ID + param2 dict 需要更新的数据 + Returns: + result bool 更新结果 + """ + info = update_data('看板', '评价流程', {"评价ID": param1}, param2) + return info