首页合格率统计
This commit is contained in:
parent
aa10f7cee1
commit
f29a5ee5e4
|
@ -20,3 +20,7 @@ class PlanGanttSerializer(serializers.ModelSerializer):
|
|||
def get_children(self, obj):
|
||||
subplans = SubProductionPlan.objects.filter(production_plan=obj).order_by('process__number')
|
||||
return SubplanGanttSerializer(instance=subplans, many=True).data
|
||||
|
||||
class ProcessYieldSerializer(serializers.Serializer):
|
||||
datetime_start = serializers.DateField(label='开始时间', required=False, allow_null=True)
|
||||
datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True)
|
|
@ -3,11 +3,12 @@ from rest_framework import urlpatterns
|
|||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from apps.srm.views import GanttPlan
|
||||
from apps.srm.views import GanttPlan, ProcessYieldView
|
||||
|
||||
router = DefaultRouter()
|
||||
urlpatterns = [
|
||||
path('gantt/plan/', GanttPlan.as_view()),
|
||||
path('process/yield/', ProcessYieldView.as_view()),
|
||||
path('', include(router.urls)),
|
||||
]
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
|
||||
from django.shortcuts import render
|
||||
from rest_framework import serializers
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.generics import ListAPIView, CreateAPIView
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from apps.mtm.models import Process, Step
|
||||
from apps.pm.models import ProductionPlan, SubProductionPlan
|
||||
from apps.srm.serializers import PlanGanttSerializer
|
||||
from apps.srm.serializers import PlanGanttSerializer, ProcessYieldSerializer
|
||||
from apps.wpm.models import WProduct, WproductFlow
|
||||
from django.db.models import Count
|
||||
# Create your views here.
|
||||
|
||||
class GanttPlan(ListAPIView):
|
||||
|
@ -15,4 +20,42 @@ class GanttPlan(ListAPIView):
|
|||
queryset = ProductionPlan.objects.filter(is_deleted=False, is_planed=True).prefetch_related('subplan_plan', 'subplan_plan__process')
|
||||
ordering = ['-id']
|
||||
|
||||
class ProcessYieldView(CreateAPIView):
|
||||
"""
|
||||
工序成品率统计
|
||||
"""
|
||||
perms_map = {'get':'*'}
|
||||
serializer_class = ProcessYieldSerializer
|
||||
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
vdata = serializer.validated_data
|
||||
wpfs = WproductFlow.objects.filter(is_lastlog=True)
|
||||
if vdata.get('datetime_start', None):
|
||||
wpfs = wpfs.filter(update_time__gte = vdata.get('datetime_start'))
|
||||
if vdata.get('datetime_end', None):
|
||||
wpfs = wpfs.filter(update_time__lte = vdata.get('datetime_end'))
|
||||
# 根据产品日志记录进行聚合
|
||||
count_ok_g = list(wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM,
|
||||
WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).values('step__process__id').annotate(count_ok=Count('id')))
|
||||
count_notok_g = list(wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).values('step__process__id',
|
||||
).annotate(count_notok=Count('id')))
|
||||
ret = []
|
||||
process_l = list(Process.objects.filter(is_deleted=False).order_by('number').values('id', 'name'))
|
||||
for i in process_l:
|
||||
ret_item = {'id':i['id'], 'name':i['name'], 'count_ok':0, 'count_notok':0, 'rate':0}
|
||||
for m in count_ok_g:
|
||||
if m['step__process__id'] == ret_item['id']:
|
||||
ret_item['count_ok'] = m['count_ok']
|
||||
for n in count_notok_g:
|
||||
if n['step__process__id'] == ret_item['id']:
|
||||
ret_item['count_notok'] = n['count_notok']
|
||||
rate = (ret_item['count_ok']/(ret_item['count_ok']+ret_item['count_notok'])) \
|
||||
if ret_item['count_ok']+ret_item['count_notok']>0 else 0
|
||||
ret_item['rate'] = rate
|
||||
ret.append(ret_item)
|
||||
return Response(ret)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue