import os import django import random from datetime import date, timedelta, datetime from django.utils import timezone # 设置 Django 环境 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'XH_Digital_Management.settings') django.setup() from application.exec_tbl.models import FinancialData, MonthlyFinancialData, ReceivablesData, ReceivablesDetail, \ EmployeeStatus, EmployeePerformance, EmployeeAttendance, ProjectLedger def generate_test_data(): # 生成 FinancialData 测试数据 for year in range(2018, 2024): data = FinancialData.objects.create( year=year, annual_revenue=random.uniform(1000000, 5000000), annual_new_revenue=random.uniform(100000, 500000), annual_existing_revenue=random.uniform(500000, 4000000), annual_operating_costs=random.uniform(500000, 3000000), annual_expenses=random.uniform(100000, 500000), operating_profit=random.uniform(50000, 1000000), unfinished_annual_revenue=random.uniform(50000, 200000), daily_income_target_remaining=random.uniform(1000, 5000) ) print(f"Created FinancialData: {data}") # 生成 MonthlyFinancialData 测试数据 for year in range(2018, 2024): for month in range(1, 13): year_month = f"{year}-{str(month).zfill(2)}" data = MonthlyFinancialData.objects.create( year_month=year_month, current_month_income=random.uniform(50000, 200000), monthly_income_target=random.uniform(100000, 200000), monthly_target_completion_rate=random.uniform(0, 100), current_month_new_income=random.uniform(10000, 50000), monthly_new_income_target=random.uniform(20000, 60000), monthly_new_income_completion_rate=random.uniform(0, 100), current_month_existing_income=random.uniform(30000, 150000), monthly_existing_income_target=random.uniform(50000, 150000), monthly_existing_income_completion_rate=random.uniform(0, 100), annual_accumulated_income=random.uniform(500000, 3000000), accumulated_target_completion_rate=random.uniform(0, 100) ) print(f"Created MonthlyFinancialData: {data}") # 生成 ReceivablesData 测试数据 for i in range(5): data = ReceivablesData.objects.create( total_receivables=random.uniform(50000, 200000), receivables_0_3_months=random.uniform(10000, 50000), receivables_3_6_months=random.uniform(5000, 30000), receivables_6_12_months=random.uniform(1000, 20000), receivables_1_2_years=random.uniform(500, 15000), receivables_2_3_years=random.uniform(100, 10000), receivables_3_5_years=random.uniform(50, 5000), receivables_over_5_years=random.uniform(10, 1000) ) print(f"Created ReceivablesData: {data}") # 生成 ReceivablesDetail 测试数据 for i in range(10): data = ReceivablesDetail.objects.create( project_name=f"项目{i}", primary_department=f"一级部门{i}", project_manager=f"项目负责人{i}", outstanding_amount=random.uniform(1000, 50000) ) print(f"Created ReceivablesDetail: {data}") # 生成 EmployeeStatus 测试数据 data = EmployeeStatus.objects.create( total_employees=random.randint(50, 200), new_employees_current_year=random.randint(10, 50), regularized_employees=random.randint(5, 30), probation_failed=random.randint(0, 10), employees_left_current_year=random.randint(5, 30), intern_employees=random.randint(1, 10), part_time_employees=random.randint(1, 20) ) print(f"Created EmployeeStatus: {data}") # 生成 EmployeePerformance 测试数据 for year in range(2018, 2024): for i in range(10): data = EmployeePerformance.objects.create( year=year, name=f"员工{i}", department=f"一级部门{i}", current_year_income=random.uniform(50000, 200000), income_target=random.uniform(100000, 200000), income_target_completion_rate=random.uniform(0, 100), commission_paid=random.uniform(5000, 20000), accrued_amount=random.uniform(1000, 10000), other_bonuses=random.uniform(1000, 10000) ) print(f"Created EmployeePerformance: {data}") # 生成 EmployeeAttendance 测试数据 for i in range(10): data = EmployeeAttendance.objects.create( name=f"员工{i}", late=random.randint(0, 10), early_departure=random.randint(0, 10), absenteeism=random.randint(0, 5), annual_leave=random.randint(0, 15), personal_leave=random.randint(0, 10), sick_leave=random.randint(0, 10), other_leave=random.randint(0, 5) ) print(f"Created EmployeeAttendance: {data}") # 生成 ProjectLedger 测试数据 for i in range(10): data = ProjectLedger.objects.create( project_name=f"项目{i}", start_date=date.today() - timedelta(days=random.randint(30, 365)), end_date=date.today() + timedelta(days=random.randint(30, 365)), primary_department=f"一级部门{i}", customer_name=f"客户{i}", province=f"省份{i}", city=f"城市{i}", district=f"区县{i}", project_leader=f"负责人{i}", project_members=f"成员{i}, 成员{i + 1}, 成员{i + 2}", project_status=random.choice(['进行中', '暂停', '待收款', '完成']), resource_type=random.choice(['公司', '个人']), project_nature=random.choice(['新增', '存量', '新增及存量', '老客户新业务']), project_progress=f"进度{i * 10}%", contract_date=date.today() - timedelta(days=random.randint(30, 365)), contract_amount=random.uniform(100000, 500000), contract_rate=random.uniform(0, 10), revenue=random.uniform(50000, 200000), cost_rate=random.uniform(0, 10), cost=random.uniform(30000, 150000), net_income=random.uniform(10000, 50000), total_amount_including_tax=random.uniform(50000, 200000), repayment_amount=random.uniform(10000, 50000), receivable_net_income=random.uniform(10000, 50000), actual_net_income=random.uniform(10000, 50000), outstanding_net_income=random.uniform(10000, 50000), notes=f"备注{i}" ) print(f"Created ProjectLedger: {data}") if __name__ == "__main__": generate_test_data()