diff --git a/.gitignore b/.gitignore index ef88847..5cd4aeb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ __pycache__/ *.py[cod] *$py.class - +*.pyc # Django stuff: media/ diff --git a/fzjgact/huodong/__pycache__/urls.cpython-311.pyc b/fzjgact/huodong/__pycache__/urls.cpython-311.pyc index 4073f15..d79bbe7 100644 Binary files a/fzjgact/huodong/__pycache__/urls.cpython-311.pyc and b/fzjgact/huodong/__pycache__/urls.cpython-311.pyc differ diff --git a/fzjgact/huodong/__pycache__/views.cpython-311.pyc b/fzjgact/huodong/__pycache__/views.cpython-311.pyc index 1247d81..661d527 100644 Binary files a/fzjgact/huodong/__pycache__/views.cpython-311.pyc and b/fzjgact/huodong/__pycache__/views.cpython-311.pyc differ diff --git a/fzjgact/huodong/templates/branch_info.html b/fzjgact/huodong/templates/branch_info.html index 2b4996e..cee8103 100644 --- a/fzjgact/huodong/templates/branch_info.html +++ b/fzjgact/huodong/templates/branch_info.html @@ -6,6 +6,9 @@ + - {% for item in branches %} - - - - + {% for province, branches in branches_by_province.items %} + {% for item in branches %} + + {% if forloop.first %} + + {% endif %} + + - + + {% endfor %} {% endfor %} - -
+ 所在省份 + 分支机构名称
@@ -17,33 +20,39 @@
- - {{ item.name }} - - - {{ item.category }} -
+ {{ province }} + + + {{ item.name }} + + + {{ item.category }} +
分支机构类别统计 + A型: {{ type_a_count }}家 | B型: {{ type_b_count }}家 | C型: {{ type_c_count }}家
+
diff --git a/fzjgact/huodong/views.py b/fzjgact/huodong/views.py index 90b11b7..7a33c71 100644 --- a/fzjgact/huodong/views.py +++ b/fzjgact/huodong/views.py @@ -228,13 +228,17 @@ def BranchAll(request): # 生成branchinfo的视图 def Branchinfo(request): - branches = Branch.objects.all() - # 统计A型、B型、C型分支机构的数量 + branches = Branch.objects.all().order_by('location', 'name') + from collections import defaultdict + branches_by_province = defaultdict(list) + for branch in branches: + branches_by_province[branch.location].append(branch) + branches_by_province = dict(sorted(branches_by_province.items())) type_a_count = branches.filter(category='A型').count() type_b_count = branches.filter(category='B型').count() type_c_count = branches.filter(category='C型').count() context = { - 'branches': branches, + 'branches_by_province': branches_by_province, 'type_a_count': type_a_count, 'type_b_count': type_b_count, 'type_c_count': type_c_count, diff --git a/update_provinces.py b/update_provinces.py new file mode 100644 index 0000000..e5d1874 --- /dev/null +++ b/update_provinces.py @@ -0,0 +1,74 @@ +from openai import OpenAI +from fzjgact.huodong.models import Branch + +client = OpenAI( + base_url="https://integrate.api.nvidia.com/v1", + api_key="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" +) + +def get_correct_province(branch_name, current_location): + prompt = f"""请根据以下分支机构名称,返回一个正确的中国省份名称(全称,如:浙江省、北京市、上海市、广东省等)。 + +分支机构名称:{branch_name} +当前省份:{current_location} + +要求: +1. 只返回省份名称,不要包含任何其他文字 +2. 省份名称必须是中国的省级行政区全称 +3. 如果无法确定,返回当前省份名称""" + + completion = client.chat.completions.create( + model="deepseek-ai/deepseek-r1", + messages=[{"role": "user", "content": prompt}], + temperature=0.3, + top_p=0.7, + max_tokens=100, + stream=False + ) + + reasoning = getattr(completion.choices[0].message, "reasoning_content", None) + if reasoning: + print(f"推理过程: {reasoning}") + + result = completion.choices[0].message.content.strip() + print(f"原始结果: {result}") + + return result + +def update_branch_provinces(): + branches = Branch.objects.all() + total = branches.count() + updated_count = 0 + + print(f"开始处理 {total} 个分支机构...") + print("=" * 80) + + for index, branch in enumerate(branches, 1): + print(f"\n[{index}/{total}] 处理: {branch.name}") + print(f"当前省份: {branch.location}") + + try: + correct_province = get_correct_province(branch.name, branch.location) + print(f"建议省份: {correct_province}") + + if correct_province != branch.location: + old_location = branch.location + branch.location = correct_province + branch.save() + print(f"✓ 已更新: {old_location} -> {correct_province}") + updated_count += 1 + else: + print("- 省份未变化") + + except Exception as e: + print(f"✗ 处理失败: {e}") + + print("-" * 80) + + print(f"\n处理完成!") + print(f"总计: {total} 个分支机构") + print(f"已更新: {updated_count} 个") + print(f"未变化: {total - updated_count} 个") + +if __name__ == "__main__": + update_branch_provinces()