2021-12-03 14:15:24 +08:00
|
|
|
|
import copy
|
2021-12-15 10:55:20 +08:00
|
|
|
|
import json
|
2021-12-03 14:15:24 +08:00
|
|
|
|
import time
|
2021-12-15 10:55:20 +08:00
|
|
|
|
import requests
|
2021-12-03 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
from common.scripts import read_json_file, file_path, make_id
|
2021-12-02 17:20:48 +08:00
|
|
|
|
from input.db import *
|
2021-12-03 14:15:24 +08:00
|
|
|
|
from user.db import find_user_info
|
|
|
|
|
from user.scripts import check_verified
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_year():
|
|
|
|
|
"""
|
|
|
|
|
获取当前年度
|
|
|
|
|
Parameters:
|
|
|
|
|
-
|
|
|
|
|
Returns:
|
|
|
|
|
current_year 当前年度
|
|
|
|
|
"""
|
|
|
|
|
current_year = time.strftime("%Y", time.localtime()) + "年"
|
|
|
|
|
return current_year
|
|
|
|
|
|
2021-12-02 17:20:48 +08:00
|
|
|
|
|
2021-12-03 14:15:24 +08:00
|
|
|
|
def make_3_report_dates():
|
|
|
|
|
"""
|
|
|
|
|
生成最近三年报告期 日期
|
|
|
|
|
Parameters:
|
|
|
|
|
-
|
|
|
|
|
Returns:
|
|
|
|
|
report_dates 三年报告期
|
|
|
|
|
"""
|
|
|
|
|
current_year = int(time.strftime("%Y", time.localtime()))
|
|
|
|
|
date_01 = str(current_year) + '-12-31'
|
|
|
|
|
date_02 = str(current_year-1) + '-12-31'
|
|
|
|
|
date_03 = str(current_year-2) + '-12-31'
|
|
|
|
|
report_dates = [date_01, date_02, date_03]
|
|
|
|
|
return report_dates
|
2021-12-02 17:20:48 +08:00
|
|
|
|
|
2021-12-03 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
def gen_new_rid():
|
|
|
|
|
"""
|
|
|
|
|
生成新的评价ID,如果该ID存在,则重新生成
|
|
|
|
|
Parameters:
|
|
|
|
|
-
|
|
|
|
|
Returns:
|
|
|
|
|
new_id: 生成的企业ID
|
|
|
|
|
"""
|
|
|
|
|
# 生成新ID
|
|
|
|
|
new_id = make_id()
|
|
|
|
|
# 检查新ID是否存在,如果存在则继续生成新ID
|
|
|
|
|
case = find_rating_records({"评价ID": new_id}) is []
|
|
|
|
|
while case:
|
|
|
|
|
new_id = make_id()
|
|
|
|
|
# 新ID可使用,返回新ID
|
|
|
|
|
return new_id
|
2021-12-02 17:20:48 +08:00
|
|
|
|
|
|
|
|
|
|
2021-12-06 16:17:10 +08:00
|
|
|
|
def get_company_type(cid):
|
|
|
|
|
"""
|
|
|
|
|
获取企业填报的企业类型
|
|
|
|
|
Parameters:
|
|
|
|
|
cid: 企业ID
|
|
|
|
|
Returns:
|
|
|
|
|
industry
|
|
|
|
|
若没有查询到行业 返回空值
|
|
|
|
|
"""
|
|
|
|
|
# 根据企业ID获取企业当年填报的企业类型
|
|
|
|
|
choose_industry = find_rating_inputs({"企业ID": cid, "评价年度": get_current_year()})[0]['行业选择']
|
|
|
|
|
|
|
|
|
|
if not len(choose_industry) > 1:
|
|
|
|
|
return None
|
|
|
|
|
else:
|
|
|
|
|
return choose_industry[0]
|
|
|
|
|
|
|
|
|
|
|
2021-12-02 17:20:48 +08:00
|
|
|
|
def rating_records_by_cid(cid):
|
|
|
|
|
"""
|
|
|
|
|
查询一家企业的所有评价记录
|
|
|
|
|
Parameters:
|
|
|
|
|
cid: 企业ID
|
|
|
|
|
Returns:
|
|
|
|
|
records: 企业的评价记录
|
|
|
|
|
"""
|
|
|
|
|
records = find_rating_records({"企业ID": cid})
|
2021-12-13 09:56:14 +08:00
|
|
|
|
[record.pop('企业ID') if records is not None else None for record in records]
|
2021-12-02 17:20:48 +08:00
|
|
|
|
return records
|
2021-12-03 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
|
2021-12-07 17:17:26 +08:00
|
|
|
|
def start_general_rating_script(cid):
|
2021-12-03 14:15:24 +08:00
|
|
|
|
"""
|
|
|
|
|
开始进行综合评价的数据填报
|
|
|
|
|
Parameters:
|
|
|
|
|
cid: 企业ID
|
|
|
|
|
Returns:
|
|
|
|
|
record 填报信息
|
|
|
|
|
"""
|
|
|
|
|
# 检查是否已认证
|
|
|
|
|
if not check_verified(cid):
|
|
|
|
|
return "该企业未认证", {}
|
|
|
|
|
|
|
|
|
|
# 根据企业ID和当前年度查询是否存在当年的填报记录
|
2021-12-03 17:11:23 +08:00
|
|
|
|
exist_input_form = find_rating_inputs({"企业ID": cid, "评价年度": get_current_year()})
|
2021-12-03 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
# 若存在填报记录,根据评价ID查询评价记录该评价是否完成
|
2021-12-03 17:11:23 +08:00
|
|
|
|
if exist_input_form:
|
2021-12-03 14:15:24 +08:00
|
|
|
|
# 已完成 本年度不能再填报
|
2021-12-03 17:11:23 +08:00
|
|
|
|
if find_rating_records({"评价ID": exist_input_form[0]["评价ID"]})[0]['进行状态'] == "完成":
|
2021-12-03 14:15:24 +08:00
|
|
|
|
return "本年度已评价", {}
|
|
|
|
|
# 未完成 返回已经填报保存的数据
|
|
|
|
|
else:
|
2021-12-03 17:11:23 +08:00
|
|
|
|
exist_input_form[0].pop('评价ID')
|
|
|
|
|
exist_input_form[0].pop('企业ID')
|
|
|
|
|
return "继续填报", exist_input_form[0]
|
2021-12-03 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
# 不存在填报记录 新生成填报记录、评价记录 返回空填报记录对象
|
|
|
|
|
else:
|
2021-12-03 17:11:23 +08:00
|
|
|
|
# 新生成填报ID
|
2021-12-03 14:15:24 +08:00
|
|
|
|
new_rid = gen_new_rid()
|
2021-12-03 17:11:23 +08:00
|
|
|
|
# 生成报告期
|
2021-12-03 14:15:24 +08:00
|
|
|
|
report_dates = make_3_report_dates()
|
|
|
|
|
|
|
|
|
|
# 新填报记录
|
2021-12-08 14:05:25 +08:00
|
|
|
|
new_input = read_json_file(file_path('/input/static/template/input.json'))
|
2021-12-03 14:15:24 +08:00
|
|
|
|
new_input['评价ID'] = new_rid
|
|
|
|
|
new_input['企业ID'] = cid
|
|
|
|
|
new_input['企业名称'] = find_user_info({"企业ID": cid})[0]['企业名称']
|
|
|
|
|
new_input['评价年度'] = get_current_year()
|
|
|
|
|
for sheets in ['资产负债表', '利润表', '补充数据表']:
|
|
|
|
|
for i in range(3):
|
|
|
|
|
new_input['财务填报'][sheets][i]['报告期'] = report_dates[i]
|
|
|
|
|
|
|
|
|
|
# 生成新评价记录
|
2021-12-08 14:05:25 +08:00
|
|
|
|
rating = read_json_file(file_path('/input/static/template/rating.json'))
|
2021-12-03 14:15:24 +08:00
|
|
|
|
rating['评价ID'] = new_rid
|
|
|
|
|
rating['企业ID'] = cid
|
|
|
|
|
rating['评价项目'] = "综合信用评价"
|
|
|
|
|
rating['评价方式'] = "企业申报"
|
|
|
|
|
rating['进行状态'] = "进行"
|
|
|
|
|
|
|
|
|
|
# 深拷贝新填报记录,不然保存后会生成_id
|
|
|
|
|
return_input = copy.deepcopy(new_input)
|
|
|
|
|
# 插入新填报记录
|
|
|
|
|
insert_general_input(new_input)
|
|
|
|
|
# 插入新评价记录
|
|
|
|
|
insert_rating_records(rating)
|
|
|
|
|
|
|
|
|
|
return "开始填报", return_input
|
2021-12-03 17:11:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_general_input_form(cid, input_form):
|
|
|
|
|
"""
|
|
|
|
|
保存综合信用评价填报
|
|
|
|
|
Parameters:
|
|
|
|
|
cid: 企业ID
|
|
|
|
|
input_form: 填报表单
|
|
|
|
|
Returns:
|
|
|
|
|
res: desc
|
|
|
|
|
"""
|
|
|
|
|
rid = find_rating_records({"企业ID": cid, "进行状态": "进行"})[0]['评价ID']
|
|
|
|
|
update_general_input(rid, input_form)
|
2021-12-06 15:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def choose_industry_script():
|
|
|
|
|
"""
|
|
|
|
|
选择行业
|
|
|
|
|
Parameters:
|
|
|
|
|
-
|
|
|
|
|
Returns:
|
2021-12-15 10:55:20 +08:00
|
|
|
|
-
|
2021-12-06 15:44:52 +08:00
|
|
|
|
"""
|
2021-12-08 14:05:25 +08:00
|
|
|
|
data = read_json_file(file_path('/input/static/template/industry.json'))
|
2021-12-06 15:44:52 +08:00
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
2021-12-06 16:17:10 +08:00
|
|
|
|
def questionnaire_script(industry):
|
2021-12-06 15:44:52 +08:00
|
|
|
|
"""
|
2021-12-06 16:17:10 +08:00
|
|
|
|
问卷模板
|
2021-12-06 15:44:52 +08:00
|
|
|
|
Parameters:
|
2021-12-06 16:17:10 +08:00
|
|
|
|
industry: 行业
|
2021-12-06 15:44:52 +08:00
|
|
|
|
Returns:
|
2021-12-06 16:17:10 +08:00
|
|
|
|
data: 问卷内容
|
2021-12-06 15:44:52 +08:00
|
|
|
|
"""
|
2021-12-08 14:05:25 +08:00
|
|
|
|
data = read_json_file(file_path('/input/static/questionnaire/{}.json'.format(industry)))
|
2021-12-06 15:44:52 +08:00
|
|
|
|
return data
|
2021-12-15 10:55:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exec_general_rating_scripts(cid):
|
|
|
|
|
"""
|
|
|
|
|
Notes
|
|
|
|
|
Parameters:
|
|
|
|
|
-
|
|
|
|
|
Returns:
|
|
|
|
|
-
|
|
|
|
|
"""
|
|
|
|
|
# pre
|
|
|
|
|
record = find_rating_records({"企业ID": cid, "进行状态": "进行"})
|
|
|
|
|
|
|
|
|
|
if not record:
|
|
|
|
|
info = "没有正在进行的评价"
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
# Parameters
|
|
|
|
|
rid = record[0]["评价ID"]
|
|
|
|
|
inputs = find_rating_inputs({"评价ID": rid})[0]
|
|
|
|
|
risks = {"风险数据": find_risk_data(rid)[0]}
|
|
|
|
|
risks["风险数据"].pop('企业ID')
|
|
|
|
|
risks["风险数据"].pop('评价ID')
|
|
|
|
|
rating_inputs = {**inputs, **risks}
|
|
|
|
|
|
|
|
|
|
# main
|
|
|
|
|
url = "http://139.9.249.34:51012/tfse_rating/rating/general_model"
|
|
|
|
|
token = "X0gSlC!YE8jmr2jJr&ilcjS83j!tsoh5"
|
|
|
|
|
headers = {'token': token, "Content-Type": "application/json;charset=UTF-8"}
|
|
|
|
|
data = json.dumps({"input_data": rating_inputs})
|
|
|
|
|
res = requests.post(url, headers=headers, data=data)
|
|
|
|
|
if res.status_code == 200:
|
|
|
|
|
update_rating_records({"评价ID": rid}, {"进行状态": "完成"})
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|