guarantee-admin-api-v0.2/Modules/Company/CompanyImpl.py

105 lines
4.6 KiB
Python
Raw Normal View History

2022-05-25 14:41:58 +08:00
import xlrd
2022-05-25 02:58:06 +08:00
2022-05-25 14:41:58 +08:00
from Modules.Company.CompanyObject import BasicBusinessInfo
2022-05-25 17:12:15 +08:00
from Modules.Company.CompanyUtils import CommonUtils, ExcelSheetParser, ExcelParserUtil
from Utils.ObjUtil import SpecObject
2022-05-25 02:58:06 +08:00
2022-05-25 17:12:15 +08:00
class BasicBusinessInfoImpl(object):
2022-05-25 14:41:58 +08:00
2022-05-25 16:12:53 +08:00
def parse_excel_and_create_company(self, file):
2022-05-25 14:41:58 +08:00
""""""
work_book = xlrd.open_workbook(file_contents=file.read())
2022-05-25 17:12:15 +08:00
basic_business_info = BasicBusinessInfo()
2022-05-25 14:41:58 +08:00
for sheet in work_book.sheets():
if sheet.name == '企业信息':
data = ExcelSheetParser(sheet=sheet).parse_sheet1()
2022-05-25 17:12:15 +08:00
# 特殊处理
2022-05-25 16:12:53 +08:00
data['参保人数'] = int(data['参保人数'])
2022-05-25 17:12:15 +08:00
basic_business_info = SpecObject.dict_to_set(instance=BasicBusinessInfo, data=data)
2022-05-25 16:12:53 +08:00
2022-05-25 17:12:15 +08:00
elif sheet.name == '高管股东信息':
executives, shareholders = ExcelSheetParser(sheet=sheet).parse_sheet2()
basic_business_info.shareholder_information = list()
basic_business_info.executive_information = list()
for item in executives:
# 特殊处理
item['出生日期'] = ExcelParserUtil.parse_date(item['出生日期'])
executive = SpecObject.dict_to_set(
instance=BasicBusinessInfo.ExecutiveInformation,
data=item
)
basic_business_info.executive_information.append(executive)
for item in shareholders:
shareholder = SpecObject.dict_to_set(
instance=BasicBusinessInfo.ShareholderInformation,
data=item
)
basic_business_info.shareholder_information.append(shareholder)
pass
2022-05-25 14:41:58 +08:00
# elif sheet.name == '经营情况':
# data = parse_gua_sheet3(sheet)
# for i in data:
# i['企业名称'] = company
# i['所在省份'] = province
# if cid:
# i['cid'] = cid
# col_4.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '客户信息':
# data = parse_gua_sheet4(sheet)
# for i in data:
# i['担保企业'] = company
# if cid:
# i['cid'] = cid
# col_5.update_one({"年度": i['年度'], "客户名称": i['客户名称'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '区域分布':
# data = parse_gua_sheet5(sheet)
# for i in data:
# i['担保企业'] = company
# if cid:
# i['cid'] = cid
# col_6.update_one({"年度": i['年度'], "地区": i['地区'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '行业分布':
# data = parse_gua_sheet5(sheet)
# for i in data:
# i['担保企业'] = company
# if cid:
# i['cid'] = cid
# col_7.update_one({"年度": i['年度'], "所属行业": i['所属行业'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '担保金额分布':
# data = parse_gua_sheet6(sheet)
# for i in data:
# i['担保企业'] = company
# if cid:
# i['cid'] = cid
# col_8.update_one({"年度": i['年度'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '资产负债表':
# data = parse_gua_sheet7(sheet)
# for i in data:
# i['企业名称'] = company
# if cid:
# i['cid'] = cid
# col_9.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
#
# elif sheet.name == '利润表':
# data = parse_gua_sheet8(sheet)
# for i in data:
# i['企业名称'] = company
# if cid:
# i['cid'] = cid
# col_10.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)