import os from datetime import datetime import django import random import string import shortuuid from faker import Faker # 设置 DJANGO_SETTINGS_MODULE 环境变量 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WideRating2024.settings") # 初始化 Django 配置 django.setup() from company_data.models import CompanyResearchInfo, SimpleFinancialReport, CompanyCreditData fake = Faker('zh_CN') def generate_company_research_info(): company_research_info = CompanyResearchInfo( company_id=shortuuid.uuid(), company_name=fake.company(), legal_entity_name=fake.name(), shareholder_nature=random.choice(['个人', '私企', '国企', '政府']), main_business=fake.catch_phrase(), senior_management_experience=round(random.uniform(1, 20), 2), has_board=random.choice(['是', '否']), board_members_count=random.randint(1, 10), has_supervisory_board=random.choice(['是', '否']), supervisory_members_count=random.randint(1, 10), annual_support_funds=round(random.uniform(100000, 1000000), 2), management_staff_count=random.randint(10, 100), functional_staff_count=random.randint(10, 100), sales_staff_count=random.randint(10, 100), technical_service_staff_count=random.randint(10, 100), bachelors_or_above_count=random.randint(10, 50), below_bachelors_count=random.randint(10, 50), year_end_total_employees=random.randint(50, 200), annual_resignation_count=random.randint(1, 10), training_participation_count=random.randint(100, 500), average_weekly_working_days=round(random.uniform(4, 7), 2), average_daily_working_hours=round(random.uniform(6, 10), 2), work_related_casualties=random.randint(0, 10), sales_amount=round(random.uniform(100000, 1000000), 2), returns_amount=round(random.uniform(10000, 100000), 2), privacy_breach_incidents=random.choice(['是', '否']), total_service_times=random.randint(100, 500), valid_customer_complaints=random.randint(0, 20), complaints_resolved=random.randint(0, 20), complaint_response_time=round(random.uniform(0.5, 24), 2), rmb_account_bank_name=random.choice(['天朝银行', '天朝商业银行', '天朝建设银行', '天朝农业银行', '天朝邮政储蓄银行']), rmb_bank_account=''.join(random.choices(string.digits, k=16)), foreign_currency_bank_name=random.choice(['鹰酱银行', '龟谷银行', '棒子银行', '小日子银行', '骆驼银行']), foreign_currency_bank_account=''.join(random.choices(string.ascii_uppercase + string.digits, k=18)), loan_card_number=''.join(random.choices(string.ascii_uppercase + string.digits, k=16)), operating_site_area=round(random.uniform(100, 1000), 2), operating_site_location=fake.address(), operating_site_ownership=random.choice(['自有', '租赁']), has_quality_management_system=random.choice(['是', '否']), has_financial_management_system=random.choice(['是', '否']), has_contract_management_system=random.choice(['是', '否']), has_hr_management_system=random.choice(['是', '否']), business_credit_record=fake.paragraph(), customs_credit_record=fake.paragraph(), bank_credit_record=fake.paragraph(), court_credit_record=fake.paragraph(), production_safety_information=fake.paragraph(), social_responsibility_implementation=fake.paragraph(), ) company_research_info.save() return company_research_info def generate_simple_financial_report(company, year): simple_financial_report = SimpleFinancialReport( financial_report_id=shortuuid.uuid(), company=company, company_name=company.company_name, report_date=datetime(year, 12, 31), currency_funds=round(random.uniform(10000, 100000), 2), accounts_receivable=round(random.uniform(10000, 100000), 2), other_receivables=round(random.uniform(10000, 100000), 2), prepayments=round(random.uniform(10000, 100000), 2), inventory=round(random.uniform(10000, 100000), 2), total_current_assets=round(random.uniform(100000, 1000000), 2), total_non_current_assets=round(random.uniform(100000, 1000000), 2), original_value_fixed_assets=round(random.uniform(100000, 1000000), 2), accumulated_depreciation=round(random.uniform(10000, 100000), 2), net_value_fixed_assets=round(random.uniform(100000, 1000000), 2), total_fixed_assets=round(random.uniform(100000, 1000000), 2), total_intangible_and_other_assets=round(random.uniform(10000, 100000), 2), total_assets=round(random.uniform(1000000, 10000000), 2), short_term_loans=round(random.uniform(10000, 100000), 2), notes_payable=round(random.uniform(10000, 100000), 2), accounts_payable=round(random.uniform(10000, 100000), 2), advance_payments=round(random.uniform(10000, 100000), 2), interest_payable=round(random.uniform(1000, 10000), 2), other_payables=round(random.uniform(1000, 10000), 2), total_current_liabilities=round(random.uniform(100000, 1000000), 2), long_term_loans=round(random.uniform(10000, 100000), 2), bonds_payable=round(random.uniform(10000, 100000), 2), total_non_current_liabilities=round(random.uniform(100000, 1000000), 2), total_liabilities=round(random.uniform(1000000, 10000000), 2), undistributed_profit=round(random.uniform(10000, 100000), 2), total_equity=round(random.uniform(100000, 1000000), 2), operating_income=round(random.uniform(100000, 1000000), 2), operating_costs=round(random.uniform(10000, 100000), 2), interest_expense=round(random.uniform(1000, 10000), 2), net_profit=round(random.uniform(10000, 100000), 2), audited=random.choice(['是', '否']), accounting_firm=random.choice(['普华永道中天会计师事务所(特殊普通合伙)', '安永华明会计师事务所(特殊普通合伙)', '毕马威华振会计师事务所(特殊普通合伙)', '德勤华永会计师事务所(特殊普通合伙)']), ) simple_financial_report.save() # 创建企业信用数据 def generate_company_credit_data(company): company_credit_data = CompanyCreditData( company_credit_data_id=shortuuid.uuid(), company=company, company_name=company.company_name, years_in_operation=random.randint(1, 30), shareholder_changes_last_three_years=random.randint(0, 5), negative_public_opinions_ratio=round(random.uniform(0, 1), 2), litigation_announcements=random.randint(0, 10), tax_credit_rating=random.choice(['A', 'B', 'C', 'D']), double_random_check_result=fake.sentence(), abnormal_business_operations=random.randint(0, 10), tax_notice=random.randint(0, 10), admin_penalty_warnings=random.randint(0, 10), admin_penalty_confiscation=random.randint(0, 10), judgment_debtor=random.randint(0, 10), dishonest_judgment_debtor=random.randint(0, 10), tax_violations=random.randint(0, 10), serious_violations=random.randint(0, 10), ) company_credit_data.save() def main(): # 生成30条模拟数据 for _ in range(30): company = generate_company_research_info() generate_company_credit_data(company) for year in range(2019, 2024): generate_simple_financial_report(company, year) if __name__ == "__main__": main()