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

105 lines
4.6 KiB
Python

import xlrd
from Modules.Company.CompanyObject import BasicBusinessInfo
from Modules.Company.CompanyUtils import CommonUtils, ExcelSheetParser, ExcelParserUtil
from Utils.ObjUtil import SpecObject
class BasicBusinessInfoImpl(object):
def parse_excel_and_create_company(self, file):
""""""
work_book = xlrd.open_workbook(file_contents=file.read())
basic_business_info = BasicBusinessInfo()
for sheet in work_book.sheets():
if sheet.name == '企业信息':
data = ExcelSheetParser(sheet=sheet).parse_sheet1()
# 特殊处理
data['参保人数'] = int(data['参保人数'])
basic_business_info = SpecObject.dict_to_set(instance=BasicBusinessInfo, data=data)
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
# 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)