修改了分支机构排序的逻辑:省份优先
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,7 +2,7 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
*.pyc
|
||||||
# Django stuff:
|
# Django stuff:
|
||||||
media/
|
media/
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,9 @@
|
|||||||
<table class="items-center bg-transparent w-full border-collapse ">
|
<table class="items-center bg-transparent w-full border-collapse ">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-gray-100">
|
<tr class="bg-gray-100">
|
||||||
|
<th class="px-6 bg-blueGray-50 text-blueGray-500 align-middle border border-solid border-blueGray-100 py-3 text-base uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left">
|
||||||
|
所在省份
|
||||||
|
</th>
|
||||||
<th class="px-6 bg-blueGray-50 text-blueGray-500 align-middle border border-solid border-blueGray-100 py-3 text-base uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left">
|
<th class="px-6 bg-blueGray-50 text-blueGray-500 align-middle border border-solid border-blueGray-100 py-3 text-base uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left">
|
||||||
分支机构名称
|
分支机构名称
|
||||||
<br>
|
<br>
|
||||||
@@ -17,33 +20,39 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in branches %}
|
{% for province, branches in branches_by_province.items %}
|
||||||
<!-- 这里是其他行的处理逻辑 -->
|
{% for item in branches %}
|
||||||
<tr class="{% if forloop.counter|divisibleby:2 %}bg-gray-100{% else %}bg-white{% endif %}">
|
<tr class="{% if forloop.parentloop.counter|divisibleby:2 %}bg-gray-100{% else %}bg-white{% endif %}">
|
||||||
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
{% if forloop.first %}
|
||||||
<a href="{% url 'branch-detail' item.pk %}"
|
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200" rowspan="{{ branches|length }}">
|
||||||
class="bg-transparent hover:bg-blue-900 hover:text-white p-2 rounded-md">
|
{{ province }}
|
||||||
{{ item.name }}
|
</td>
|
||||||
</a>
|
{% endif %}
|
||||||
</td>
|
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
||||||
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
<a href="{% url 'branch-detail' item.pk %}"
|
||||||
{{ item.category }}
|
class="bg-transparent hover:bg-blue-900 hover:text-white p-2 rounded-md">
|
||||||
</td>
|
{{ item.name }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
||||||
|
{{ item.category }}
|
||||||
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tr class="bg-gray-200 font-bold">
|
<tr class="bg-gray-200 font-bold">
|
||||||
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
||||||
分支机构类别统计
|
分支机构类别统计
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200">
|
<td class="px-6 py-4 whitespace-no-wrap text-left border-b border-gray-200" colspan="2">
|
||||||
A型: {{ type_a_count }}家 | B型: {{ type_b_count }}家 | C型: {{ type_c_count }}家
|
A型: {{ type_a_count }}家 | B型: {{ type_b_count }}家 | C型: {{ type_c_count }}家
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="bg-gray-50">
|
<tr class="bg-gray-50">
|
||||||
<td colspan="2" class="px-6 py-4 text-right border-b border-gray-200">
|
<td colspan="3" class="px-6 py-4 text-right border-b border-gray-200">
|
||||||
<div class="flex justify-end space-x-3">
|
<div class="flex justify-end space-x-3">
|
||||||
<a href="{% url 'export-branches-xls' %}" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-black font-medium rounded-lg shadow-md transition duration-150 ease-in-out transform hover:scale-105">
|
<a href="{% url 'export-branches-xls' %}" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-black font-medium rounded-lg shadow-md transition duration-150 ease-in-out transform hover:scale-105">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
|||||||
@@ -228,13 +228,17 @@ def BranchAll(request):
|
|||||||
|
|
||||||
# 生成branchinfo的视图
|
# 生成branchinfo的视图
|
||||||
def Branchinfo(request):
|
def Branchinfo(request):
|
||||||
branches = Branch.objects.all()
|
branches = Branch.objects.all().order_by('location', 'name')
|
||||||
# 统计A型、B型、C型分支机构的数量
|
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_a_count = branches.filter(category='A型').count()
|
||||||
type_b_count = branches.filter(category='B型').count()
|
type_b_count = branches.filter(category='B型').count()
|
||||||
type_c_count = branches.filter(category='C型').count()
|
type_c_count = branches.filter(category='C型').count()
|
||||||
context = {
|
context = {
|
||||||
'branches': branches,
|
'branches_by_province': branches_by_province,
|
||||||
'type_a_count': type_a_count,
|
'type_a_count': type_a_count,
|
||||||
'type_b_count': type_b_count,
|
'type_b_count': type_b_count,
|
||||||
'type_c_count': type_c_count,
|
'type_c_count': type_c_count,
|
||||||
|
|||||||
74
update_provinces.py
Normal file
74
update_provinces.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user