98 lines
2.7 KiB
Python
98 lines
2.7 KiB
Python
|
import json
|
|||
|
import requests
|
|||
|
import time
|
|||
|
import os
|
|||
|
import random
|
|||
|
|
|||
|
from esg.esg_db import *
|
|||
|
|
|||
|
|
|||
|
def get_data_template(template_name):
|
|||
|
data_template_path = '/static/template/{}.json'.format(template_name)
|
|||
|
with open(os.path.dirname(__file__) + data_template_path, "r", encoding='utf-8') as f:
|
|||
|
data_template = json.load(f)
|
|||
|
return data_template
|
|||
|
|
|||
|
|
|||
|
def update_process_status(rid, update_data):
|
|||
|
"""
|
|||
|
调用更新流程接口
|
|||
|
Parameters:
|
|||
|
update_data dict 需要更新的数据
|
|||
|
Returns:
|
|||
|
result str 更新结果
|
|||
|
"""
|
|||
|
url = "http://api.fecribd.com/etl_tfse/company/update_process_data"
|
|||
|
token = "dmfd7FshT!5Wng9^gcCcQV7T6FBnVgl4"
|
|||
|
headers = {'token': token, 'Content-Type': 'application/json; charset=UTF-8'}
|
|||
|
data = json.dumps({"rid": rid, "types": "ESG评价流程", "renew_data": update_data})
|
|||
|
requests.post(url, headers=headers, data=data)
|
|||
|
|
|||
|
|
|||
|
def get_current_year():
|
|||
|
"""
|
|||
|
获取当前年度
|
|||
|
Parameters:
|
|||
|
-
|
|||
|
Returns:
|
|||
|
current_year 当前年度
|
|||
|
"""
|
|||
|
current_year = time.strftime("%Y", time.localtime()) + "年"
|
|||
|
return current_year
|
|||
|
|
|||
|
|
|||
|
|
|||
|
def gen_new_rid():
|
|||
|
"""
|
|||
|
生成新的评价ID,如果该ID存在,则重新生成
|
|||
|
Parameters:
|
|||
|
-
|
|||
|
Returns:
|
|||
|
new_id: 生成的企业ID
|
|||
|
"""
|
|||
|
# 生成新ID
|
|||
|
new_id = make_id(8)
|
|||
|
# 检查新ID是否存在,如果存在则继续生成新ID
|
|||
|
case = find_rating_records({"评价ID": new_id}) is []
|
|||
|
while case:
|
|||
|
new_id = make_id(8)
|
|||
|
# 新ID可使用,返回新ID
|
|||
|
return new_id
|
|||
|
|
|||
|
|
|||
|
def make_3_report_dates():
|
|||
|
"""
|
|||
|
生成最近三年报告期 日期
|
|||
|
Parameters:
|
|||
|
-
|
|||
|
Returns:
|
|||
|
report_dates 三年报告期
|
|||
|
"""
|
|||
|
current_year = int(time.strftime("%Y", time.localtime()))-1
|
|||
|
date_01 = str(current_year) + '年'
|
|||
|
date_02 = str(current_year-1) + '年'
|
|||
|
date_03 = str(current_year-2) + '年'
|
|||
|
report_dates = [date_01, date_02, date_03]
|
|||
|
return report_dates
|
|||
|
|
|||
|
|
|||
|
def make_id(num):
|
|||
|
"""
|
|||
|
随机生成字符串
|
|||
|
"""
|
|||
|
choices = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|||
|
salt = ''
|
|||
|
for i in range(num):
|
|||
|
salt += random.choice(choices)
|
|||
|
return salt
|
|||
|
|
|||
|
|
|||
|
def prepare_risk_data(cid, rid, company_name):
|
|||
|
# 执行风险数据清洗程序
|
|||
|
url = "http://api.fecribd.com/etl_tfse/rating/esg_risk_data"
|
|||
|
token = "dmfd7FshT!5Wng9^gcCcQV7T6FBnVgl4"
|
|||
|
headers = {'token': token, 'Content-Type': 'application/json; charset=UTF-8'}
|
|||
|
data = json.dumps({"company_id": cid, "company_name": company_name, "evaluation_id": rid})
|
|||
|
requests.post(url, headers=headers, data=data)
|
|||
|
# 风险数据清洗完成后更新流程状态
|
|||
|
update_process_status(rid, {"评价流程.清洗风险数据": 1})
|