From e3e623c5e14a1c7a25d9b7c0669bab1e1445e42a Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 26 Jan 2022 16:41:52 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=B6=85=E8=BF=87=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/sam/views_sale.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hb_server/apps/sam/views_sale.py b/hb_server/apps/sam/views_sale.py index 63381f1..c67c5ca 100644 --- a/hb_server/apps/sam/views_sale.py +++ b/hb_server/apps/sam/views_sale.py @@ -42,6 +42,8 @@ class SaleViewSet(CreateUpdateModelAMixin, ListModelMixin, RetrieveModelMixin, C with transaction.atomic(): iproducts = vdata.pop('iproducts') vdata['count'] = len(iproducts) + if vdata['count'] + vdata['order'].delivered_count > vdata['order'].count: + raise exceptions.APIException('超过订单所需数量') sale = Sale.objects.create(**vdata) i_l = [] for i in iproducts: From f0fd992f1836cfb37938bce59e3d587bcd714121 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 26 Jan 2022 16:42:18 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=80=83=E5=8B=A4=E5=A4=A9=E6=95=B0?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/views.py | 8 ++++---- hb_server/apps/srm/serializers.py | 7 ++++++- hb_server/apps/srm/urls.py | 3 ++- hb_server/apps/srm/views.py | 28 ++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 61fb2f4..8755b18 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -20,7 +20,7 @@ from rest_framework import exceptions from apps.system.models import User from apps.system.serializers import UserSimpleSerializer from rest_framework.permissions import AllowAny - +from rest_framework.decorators import action # Create your views here. @@ -79,9 +79,9 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet): user, msg = HRMService.face_compare_from_base64(base64_data) if user: ins, created = ClockRecord.objects.get_or_create( - create_by=request.user, create_time__hour__range = [8,18], - create_time__year=now.year, create_time__month=now.month, - create_time__day=now.day, + create_by = user, create_time__hour__range = [8,18], + create_time__year=now_local.year, create_time__month=now_local.month, + create_time__day=now_local.day, defaults={ 'type':ClockRecord.ClOCK_WORK1, 'create_by':user, diff --git a/hb_server/apps/srm/serializers.py b/hb_server/apps/srm/serializers.py index 10e2b94..2a4e11f 100644 --- a/hb_server/apps/srm/serializers.py +++ b/hb_server/apps/srm/serializers.py @@ -23,4 +23,9 @@ class PlanGanttSerializer(serializers.ModelSerializer): class ProcessYieldSerializer(serializers.Serializer): datetime_start = serializers.DateField(label='开始时间', required=False, allow_null=True) - datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True) \ No newline at end of file + datetime_end = serializers.DateField(label='结束时间', required=False, allow_null=True) + + +class AtWorkCountSerializer(serializers.Serializer): + year = serializers.IntegerField(label='年') + month = serializers.IntegerField(label='月') \ No newline at end of file diff --git a/hb_server/apps/srm/urls.py b/hb_server/apps/srm/urls.py index 0d8a992..2b53153 100644 --- a/hb_server/apps/srm/urls.py +++ b/hb_server/apps/srm/urls.py @@ -3,12 +3,13 @@ from rest_framework import urlpatterns from django.urls import path, include from rest_framework.routers import DefaultRouter -from apps.srm.views import GanttPlan, ProcessYieldView +from apps.srm.views import AtWorkCountView, GanttPlan, ProcessYieldView router = DefaultRouter() urlpatterns = [ path('gantt/plan/', GanttPlan.as_view()), path('process/yield/', ProcessYieldView.as_view()), + path('at_work/', AtWorkCountView.as_view()), path('', include(router.urls)), ] diff --git a/hb_server/apps/srm/views.py b/hb_server/apps/srm/views.py index ec7a398..9dd73cc 100644 --- a/hb_server/apps/srm/views.py +++ b/hb_server/apps/srm/views.py @@ -4,11 +4,12 @@ from rest_framework import serializers from rest_framework.generics import ListAPIView, CreateAPIView from rest_framework.views import APIView from rest_framework.response import Response +from apps.hrm.models import ClockRecord from apps.mtm.models import Process, Step from apps.pm.models import ProductionPlan, SubProductionPlan -from apps.srm.serializers import PlanGanttSerializer, ProcessYieldSerializer +from apps.srm.serializers import AtWorkCountSerializer, PlanGanttSerializer, ProcessYieldSerializer from apps.wpm.models import WProduct, WproductFlow -from django.db.models import Count +from django.db.models import Count, F # Create your views here. class GanttPlan(ListAPIView): @@ -65,3 +66,26 @@ class ProcessYieldView(CreateAPIView): return Response(ret) +class AtWorkCountView(CreateAPIView): + """ + 到岗天数统计 + """ + perms_map = {'get':'*'} + serializer_class = AtWorkCountSerializer + + def create(self, request, *args, **kwargs): + serializer = self.get_serializer(data=request.data) + serializer.is_valid(raise_exception=True) + vdata = serializer.validated_data + ret = ClockRecord.objects.filter( + create_time__year = vdata['year'], + create_time__month = vdata['month'] + ).values( + user_id = F('create_by'), + username = F('create_by__username'), + name = F('create_by__name'), + dept_name = F('create_by__dept__name')).annotate( + count = Count('id') + ) + return Response(list(ret)) + From cb2986ca91efb5092755f063d33dab1b695216ef Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 26 Jan 2022 17:03:24 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=85=A7=E7=89=87bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/services.py | 4 ++-- hb_server/apps/hrm/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py index 7f7334b..1a793b1 100644 --- a/hb_server/apps/hrm/services.py +++ b/hb_server/apps/hrm/services.py @@ -40,9 +40,9 @@ class HRMService: return user, '' return None, '识别失败' - def get_facedata_from_img(cls, img_rpath): + def get_facedata_from_img(cls, img_path): try: - photo_path = settings.BASE_DIR + img_rpath + photo_path = settings.BASE_DIR + img_path picture_of_me = face_recognition.load_image_file(photo_path) my_face_encoding = face_recognition.face_encodings(picture_of_me)[0] face_data_list = my_face_encoding.tolist() diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 8755b18..89dfa66 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -42,7 +42,7 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix serializer.is_valid(raise_exception=True) photo = data.get('photo', None) if instance.photo != photo: - f_l = HRMService.get_facedata_from_img(photo) + f_l = HRMService.get_facedata_from_img(img_path=photo) if f_l: serializer.save(update_by=request.user, face_data = f_l) # 更新人脸缓存 From d54ea2c2dcd7e700e4107a353a1cd417c68f1f2f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 27 Jan 2022 09:28:34 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=85=A7=E7=89=87bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/services.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py index 1a793b1..0786a29 100644 --- a/hb_server/apps/hrm/services.py +++ b/hb_server/apps/hrm/services.py @@ -40,6 +40,7 @@ class HRMService: return user, '' return None, '识别失败' + @classmethod def get_facedata_from_img(cls, img_path): try: photo_path = settings.BASE_DIR + img_path From 8cb4f244d1fa17b60407ff0af5c194c852ec6c5c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 27 Jan 2022 09:33:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=AF=81=E4=BB=B6?= =?UTF-8?q?=E7=85=A7bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/services.py | 10 +++++----- hb_server/apps/hrm/views.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py index 0786a29..bd2f6b4 100644 --- a/hb_server/apps/hrm/services.py +++ b/hb_server/apps/hrm/services.py @@ -21,7 +21,7 @@ class HRMService: os.remove(filepath) except: os.remove(filepath) - return None, '头像解码失败' + return None, '人脸识别失败' # 匹配人脸库 face_datas = cache.get('face_datas') @@ -32,13 +32,13 @@ class HRMService: results = face_recognition.compare_faces(face_datas, unknown_face_encoding, tolerance=0.5) except: - return None, '识别失败' + return None, '人脸匹配失败' for index, value in enumerate(results): if value: # 识别成功 user = User.objects.get(id=face_users[index]) return user, '' - return None, '识别失败' + return None, '人脸匹配失败' @classmethod def get_facedata_from_img(cls, img_path): @@ -47,6 +47,6 @@ class HRMService: picture_of_me = face_recognition.load_image_file(photo_path) my_face_encoding = face_recognition.face_encodings(picture_of_me)[0] face_data_list = my_face_encoding.tolist() - return face_data_list + return face_data_list, '' except: - return None \ No newline at end of file + return None, '人脸识别失败' \ No newline at end of file diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 89dfa66..a1662bc 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -42,13 +42,13 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix serializer.is_valid(raise_exception=True) photo = data.get('photo', None) if instance.photo != photo: - f_l = HRMService.get_facedata_from_img(img_path=photo) + f_l, msg = HRMService.get_facedata_from_img(img_path=photo) if f_l: serializer.save(update_by=request.user, face_data = f_l) # 更新人脸缓存 update_all_user_facedata_cache.delay() return Response() - return Response('头像识别失败', status=status.HTTP_400_BAD_REQUEST) + return Response(msg, status=status.HTTP_400_BAD_REQUEST) serializer.save(update_by=request.user) return Response() From f8bfee6f8928405711bd5ae9bc11e3e793c0e26a Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 27 Jan 2022 09:56:11 +0800 Subject: [PATCH 6/7] =?UTF-8?q?employee=20=E5=A2=9E=E5=8A=A0list=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index a1662bc..988f2be 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -24,7 +24,7 @@ from rest_framework.decorators import action # Create your views here. -class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMixin, RetrieveModelMixin, GenericViewSet): +class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet): """ 员工详细信息 """ @@ -32,6 +32,7 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix queryset = Employee.objects.all() filterset_class = EmployeeFilterSet serializer_class = EmployeeSerializer + search_fields = ['user__name', 'number', 'user__username'] ordering = ['-pk'] def update(self, request, *args, **kwargs): From ec0bcb2fd0f6f8c7d2c86ceb5e42aaffc88c921e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 27 Jan 2022 10:17:24 +0800 Subject: [PATCH 7/7] =?UTF-8?q?employee=20list=20dept=5F=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/serializers.py | 2 +- hb_server/apps/hrm/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hb_server/apps/hrm/serializers.py b/hb_server/apps/hrm/serializers.py index 4f70427..9371ff4 100644 --- a/hb_server/apps/hrm/serializers.py +++ b/hb_server/apps/hrm/serializers.py @@ -9,7 +9,7 @@ from django.db.models.query import Prefetch class EmployeeSerializer(DynamicFieldsSerializerMixin, ModelSerializer): name = serializers.CharField(source='user.name', read_only=True) - dept_ = OrganizationSimpleSerializer(source='user.dept_', read_only=True) + dept_ = OrganizationSimpleSerializer(source='user.dept', read_only=True) class Meta: model = Employee exclude = ['face_data'] diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 988f2be..5bf9457 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -89,7 +89,7 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet): 'create_time':now }) if not created: - ins.create_time = now + ins.update_time = now ins.save() # 设为在岗 user.is_atwork = True