fix: 大屏统计按新品牌实体,材料种类统计改为细分种类并排除空值
- 材料种类卡片:从 material_subcategory 改为 material_category 去重计数,排除 null/空 - 材料子类分布图:排除 material_subcategory 为空的材料,避免出现 null 类目 - 品牌数卡片:从 Factory.count 改为 Brand.count - 品牌材料分布图:按 material.brand.name 分组,排除无品牌材料;前端字段同步 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
75dde5243e
commit
85ed7a20c1
|
|
@ -4,6 +4,7 @@ from rest_framework.response import Response
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from apps.material.models import Material
|
from apps.material.models import Material
|
||||||
from apps.factory.models import Factory
|
from apps.factory.models import Factory
|
||||||
|
from apps.brand.models import Brand
|
||||||
|
|
||||||
|
|
||||||
def _build_brochure_url(request, brochure_field):
|
def _build_brochure_url(request, brochure_field):
|
||||||
|
|
@ -27,26 +28,42 @@ def overview_statistics(request):
|
||||||
# 材料总数
|
# 材料总数
|
||||||
total_materials = approved_materials.count()
|
total_materials = approved_materials.count()
|
||||||
|
|
||||||
# 材料种类(材料子类数量)
|
# 材料种类(细分种类数量,排除空值)
|
||||||
total_material_categories = approved_materials.values('material_subcategory').distinct().count()
|
total_material_categories = (
|
||||||
|
approved_materials
|
||||||
|
.exclude(material_category__isnull=True)
|
||||||
|
.exclude(material_category='')
|
||||||
|
.values('material_category')
|
||||||
|
.distinct()
|
||||||
|
.count()
|
||||||
|
)
|
||||||
|
|
||||||
# 品牌数(工厂数)
|
# 品牌数
|
||||||
total_brands = Factory.objects.count()
|
total_brands = Brand.objects.count()
|
||||||
|
|
||||||
# 按专业类别的材料数量分布
|
# 按专业类别的材料数量分布
|
||||||
major_category_stats = approved_materials.values('major_category').annotate(
|
major_category_stats = approved_materials.values('major_category').annotate(
|
||||||
count=Count('id')
|
count=Count('id')
|
||||||
).order_by('-count')
|
).order_by('-count')
|
||||||
|
|
||||||
# 按材料子类的材料数量分布
|
# 按材料子类的材料数量分布(排除空值)
|
||||||
material_subcategory_stats = approved_materials.values('material_subcategory').annotate(
|
material_subcategory_stats = (
|
||||||
count=Count('id')
|
approved_materials
|
||||||
).order_by('-count')[:10]
|
.exclude(material_subcategory__isnull=True)
|
||||||
|
.exclude(material_subcategory='')
|
||||||
|
.values('material_subcategory')
|
||||||
|
.annotate(count=Count('id'))
|
||||||
|
.order_by('-count')[:10]
|
||||||
|
)
|
||||||
|
|
||||||
# 按所属品牌的材料数量分布
|
# 按所属品牌的材料数量分布(排除无品牌的材料)
|
||||||
brand_stats = approved_materials.values('factory__factory_name').annotate(
|
brand_stats = (
|
||||||
count=Count('id')
|
approved_materials
|
||||||
).order_by('-count')
|
.exclude(brand__isnull=True)
|
||||||
|
.values('brand__name')
|
||||||
|
.annotate(count=Count('id'))
|
||||||
|
.order_by('-count')
|
||||||
|
)
|
||||||
|
|
||||||
# 按省份的工厂数量分布
|
# 按省份的工厂数量分布
|
||||||
region_stats = Factory.objects.values('province').annotate(
|
region_stats = Factory.objects.values('province').annotate(
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ const updateCharts = () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const brandData = (stats.value.brand_stats || []).map((item) => ({
|
const brandData = (stats.value.brand_stats || []).map((item) => ({
|
||||||
name: item.factory__factory_name,
|
name: item.brand__name,
|
||||||
value: item.count
|
value: item.count
|
||||||
}))
|
}))
|
||||||
charts[2].setOption({
|
charts[2].setOption({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue