2024-06-06 15:08:38 +08:00
|
|
|
import os
|
|
|
|
import django
|
|
|
|
import random
|
|
|
|
from datetime import datetime, timedelta
|
2024-05-16 21:23:15 +08:00
|
|
|
|
2024-06-06 15:08:38 +08:00
|
|
|
# 设置 Django 环境
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'XH_Digital_Management.settings')
|
|
|
|
django.setup()
|
|
|
|
|
|
|
|
from application.busi_tbl.models import (
|
|
|
|
DepartmentAnnualPerformance, DepartmentMonthlyIncome, DepartmentMonthlyCost, DepartmentMonthlyProfit,
|
|
|
|
DepartmentProjectProgress, DepartmentProjectSettlement, DepartmentProjectPayment, DepartmentRevenueStructure,
|
|
|
|
DepartmentProfitStructure, DepartmentProjectManagerIncomeCommission, DepartmentAttendance
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def generate_test_data():
|
|
|
|
# 生成 DepartmentAnnualPerformance 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
data = DepartmentAnnualPerformance.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year=year,
|
|
|
|
annual_revenue=random.uniform(1000, 5000),
|
|
|
|
annual_revenue_completion_rate=random.uniform(50, 100),
|
|
|
|
annual_new_revenue=random.uniform(500, 2000),
|
|
|
|
annual_new_revenue_completion_rate=random.uniform(50, 100),
|
|
|
|
annual_existing_revenue=random.uniform(500, 3000),
|
|
|
|
annual_existing_revenue_completion_rate=random.uniform(50, 100),
|
|
|
|
annual_operating_costs=random.uniform(500, 3000),
|
|
|
|
annual_operating_costs_utilization_rate=random.uniform(50, 100),
|
|
|
|
annual_expenses=random.uniform(100, 500),
|
|
|
|
annual_expenses_utilization_rate=random.uniform(50, 100),
|
|
|
|
operating_profit=random.uniform(50, 1000),
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentAnnualPerformance: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentMonthlyIncome 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
data = DepartmentMonthlyIncome.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year_month=year_month,
|
|
|
|
current_month_income=random.uniform(500, 2000),
|
|
|
|
monthly_income_target=random.uniform(1000, 2000),
|
|
|
|
monthly_target_completion_rate=random.uniform(0, 100),
|
|
|
|
current_month_new_income=random.uniform(100, 500),
|
|
|
|
monthly_new_income_target=random.uniform(200, 600),
|
|
|
|
monthly_new_income_completion_rate=random.uniform(0, 100),
|
|
|
|
current_month_existing_income=random.uniform(300, 1500),
|
|
|
|
monthly_existing_income_target=random.uniform(500, 1500),
|
|
|
|
monthly_existing_income_completion_rate=random.uniform(0, 100),
|
|
|
|
annual_accumulated_income=random.uniform(5000, 30000),
|
|
|
|
accumulated_target_completion_rate=random.uniform(0, 100)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentMonthlyIncome: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentMonthlyCost 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
data = DepartmentMonthlyCost.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year_month=year_month,
|
|
|
|
current_month_cost=random.uniform(500, 2000),
|
|
|
|
monthly_cost_limit=random.uniform(1000, 2000),
|
|
|
|
monthly_cost_utilization_rate=random.uniform(0, 100),
|
|
|
|
annual_accumulated_cost=random.uniform(5000, 30000),
|
|
|
|
accumulated_cost_utilization_rate=random.uniform(0, 100)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentMonthlyCost: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentMonthlyProfit 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
data = DepartmentMonthlyProfit.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year_month=year_month,
|
|
|
|
operating_profit=random.uniform(500, 2000),
|
|
|
|
annual_operating_profit=random.uniform(5000, 30000)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentMonthlyProfit: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentProjectProgress 测试数据
|
|
|
|
for i in range(10):
|
|
|
|
data = DepartmentProjectProgress.objects.create(
|
|
|
|
primary_department=f"一级部门{i}",
|
|
|
|
project_name=f"项目{i}",
|
|
|
|
project_type="开发",
|
|
|
|
project_manager=f"负责人{i}",
|
|
|
|
project_status="进行中",
|
|
|
|
project_progress=f"{random.randint(0, 100)}%",
|
|
|
|
project_nature="内部项目",
|
|
|
|
contract_date=datetime.today() - timedelta(days=random.randint(30, 365)),
|
|
|
|
target_amount=random.uniform(100000, 500000),
|
|
|
|
contract_rate=random.uniform(1, 10),
|
|
|
|
revenue=random.uniform(50000, 200000),
|
|
|
|
cost_rate=random.uniform(1, 10),
|
|
|
|
cost=random.uniform(30000, 150000),
|
|
|
|
net_income=random.uniform(10000, 50000),
|
|
|
|
transaction_amount=random.uniform(100000, 500000),
|
|
|
|
total_tax_inclusive_amount=random.uniform(50000, 200000),
|
|
|
|
payment_received=random.uniform(10000, 50000)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentProjectProgress: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentProjectSettlement 测试数据
|
|
|
|
for i in range(10):
|
|
|
|
data = DepartmentProjectSettlement.objects.create(
|
|
|
|
primary_department=f"一级部门{i}",
|
|
|
|
project_name=f"项目{i}",
|
|
|
|
revenue=random.uniform(50000, 200000),
|
|
|
|
operating_costs=random.uniform(30000, 150000),
|
|
|
|
taxes_and_surcharges=random.uniform(5000, 20000),
|
|
|
|
operating_profit=random.uniform(10000, 50000),
|
|
|
|
company_retention=random.uniform(1000, 10000),
|
|
|
|
project_commission=random.uniform(500, 5000),
|
|
|
|
project_provision_fund=random.uniform(500, 5000)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentProjectSettlement: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentProjectPayment 测试数据
|
|
|
|
for i in range(10):
|
|
|
|
data = DepartmentProjectPayment.objects.create(
|
|
|
|
primary_department=f"一级部门{i}",
|
|
|
|
project_name=f"项目{i}",
|
|
|
|
project_type="开发",
|
|
|
|
project_manager=f"负责人{i}",
|
|
|
|
total_tax_inclusive_amount=random.uniform(50000, 200000),
|
|
|
|
payment_received=random.uniform(10000, 50000),
|
|
|
|
outstanding_payment_amount=random.uniform(1000, 10000),
|
|
|
|
receivable_net_income=random.uniform(10000, 50000),
|
|
|
|
actual_net_income=random.uniform(10000, 50000),
|
|
|
|
outstanding_net_income=random.uniform(1000, 10000)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentProjectPayment: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentRevenueStructure 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
data = DepartmentRevenueStructure.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year_month=year_month,
|
|
|
|
project_type="开发",
|
|
|
|
total_tax_inclusive_amount=random.uniform(50000, 200000),
|
|
|
|
percentage=random.uniform(0, 100),
|
|
|
|
cumulative_tax_inclusive_amount=random.uniform(100000, 500000),
|
|
|
|
cumulative_percentage=random.uniform(0, 100)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentRevenueStructure: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentProfitStructure 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
data = DepartmentProfitStructure.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
year_month=year_month,
|
|
|
|
project_type="开发",
|
|
|
|
net_receivable_income=random.uniform(50000, 200000),
|
|
|
|
percentage=random.uniform(0, 100),
|
|
|
|
cumulative_net_receivable_income=random.uniform(100000, 500000),
|
|
|
|
cumulative_percentage=random.uniform(0, 100)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentProfitStructure: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentProjectManagerIncomeCommission 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
for i in range(10):
|
|
|
|
data = DepartmentProjectManagerIncomeCommission.objects.create(
|
|
|
|
primary_department="测试部门",
|
|
|
|
name=f"项目经理{i}",
|
|
|
|
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),
|
|
|
|
annual_accumulated_income=random.uniform(500000, 3000000),
|
|
|
|
annual_target_completion_rate=random.uniform(0, 100),
|
|
|
|
current_month_commission=random.uniform(5000, 20000),
|
|
|
|
current_month_accrued_commission=random.uniform(1000, 10000),
|
|
|
|
annual_accumulated_commission=random.uniform(50000, 200000),
|
|
|
|
annual_accumulated_accrued_commission=random.uniform(10000, 50000)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentProjectManagerIncomeCommission: {data}")
|
|
|
|
|
|
|
|
# 生成 DepartmentAttendance 测试数据
|
|
|
|
for year in range(2018, 2024):
|
|
|
|
for month in range(1, 13):
|
|
|
|
year_month = f"{year}-{str(month).zfill(2)}"
|
|
|
|
for i in range(10):
|
|
|
|
data = DepartmentAttendance.objects.create(
|
|
|
|
primary_department=f"一级部门{i}",
|
|
|
|
year_month=year_month,
|
|
|
|
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),
|
|
|
|
total_days=random.randint(0, 30)
|
|
|
|
)
|
|
|
|
print(f"Created DepartmentAttendance: {data}")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
generate_test_data()
|