From e53024c9bc399cdd10f4921947f654d394f5caea Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 21 Jan 2022 16:13:32 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E4=BA=BA=E8=84=B8=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=94=A8=E7=BC=93=E5=AD=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/services.py | 29 ++++++++++++++-------- hb_server/apps/hrm/signals.py | 6 ++++- hb_server/apps/hrm/tasks.py | 27 +++++++++++++++++++-- hb_server/apps/hrm/views.py | 44 ++++++++++++++-------------------- hb_server/server/settings.py | 4 ++-- 5 files changed, 69 insertions(+), 41 deletions(-) diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py index a80cb8e..8cfb277 100644 --- a/hb_server/apps/hrm/services.py +++ b/hb_server/apps/hrm/services.py @@ -3,7 +3,9 @@ import uuid import face_recognition import os from apps.hrm.models import Employee +from apps.hrm.tasks import update_all_user_facedata_cache from apps.system.models import User +from django.core.cache import cache class HRMService: @@ -22,18 +24,25 @@ class HRMService: return None, '头像解码失败' # 匹配人脸库 - user_faces = Employee.objects.filter(face_data__isnull=False, - user__is_active=True).values('user', 'face_data') - user_l = [] - face_l = [] - for i in user_faces: - user_l.append(i['user']) - face_l.append(i['face_data']) + face_datas = cache.get('face_datas') + face_users = cache.get('face_users') + if face_datas is None: + update_all_user_facedata_cache() - results = face_recognition.compare_faces(face_l, unknown_face_encoding, tolerance=0.5) + results = face_recognition.compare_faces(face_datas, unknown_face_encoding, tolerance=0.5) for index, value in enumerate(results): if value: # 识别成功 - user = User.objects.get(id=user_l[index]) + user = User.objects.get(id=face_users[index]) return user, '' - return None, '识别失败' \ No newline at end of file + return None, '识别失败' + + def get_facedata_from_img(cls, img_rpath): + try: + photo_path = settings.BASE_DIR + img_rpath + 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 + except: + return None \ No newline at end of file diff --git a/hb_server/apps/hrm/signals.py b/hb_server/apps/hrm/signals.py index a2a7312..7e8c922 100644 --- a/hb_server/apps/hrm/signals.py +++ b/hb_server/apps/hrm/signals.py @@ -2,8 +2,12 @@ from django.db.models.signals import post_save from apps.system.models import User from django.dispatch import receiver from apps.hrm.models import Employee +from django.conf import settings +import face_recognition +import logging +logger = logging.getLogger('log') @receiver(post_save, sender=User) def createEmployee(sender, instance, created, **kwargs): if created: - Employee.objects.get_or_create(user=instance) \ No newline at end of file + Employee.objects.get_or_create(user=instance) diff --git a/hb_server/apps/hrm/tasks.py b/hb_server/apps/hrm/tasks.py index bd4449b..d5d5a9f 100644 --- a/hb_server/apps/hrm/tasks.py +++ b/hb_server/apps/hrm/tasks.py @@ -1,8 +1,31 @@ from __future__ import absolute_import, unicode_literals from celery import shared_task +from apps.hrm.models import Employee +from apps.system.models import User +from django.core.cache import cache @shared_task -def x(): - print('ok') \ No newline at end of file +def update_all_user_not_atwork(): + """ + 将所有员工设为非在岗状态 + """ + User.objects.all().update(is_atwork=False) + +@shared_task +def update_all_user_facedata_cache(): + """ + 更新人脸数据缓存 + """ + facedata_queyset = Employee.objects.filter(face_data__isnull=False, + user__is_active=True).values('user', 'face_data') + face_users = [] + face_datas = [] + for i in facedata_queyset: + face_users.append(i['user']) + face_datas.append(i['face_data']) + cache.set('face_users', face_users, timeout=None) + cache.set('face_datas', face_datas, timeout=None) + + \ No newline at end of file diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index 9c533d0..e41ee48 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -8,10 +8,9 @@ from apps.hrm.services import HRMService from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin from apps.hrm.models import ClockRecord, Employee from apps.hrm.serializers import ClockRecordListSerializer, EmployeeSerializer, FaceClockCreateSerializer, FaceLoginSerializer -import face_recognition -from django.conf import settings -from django.core.cache import cache -import logging + + + from rest_framework.generics import CreateAPIView from rest_framework import status from rest_framework_simplejwt.tokens import RefreshToken @@ -19,20 +18,8 @@ from rest_framework import exceptions from apps.system.models import User from apps.system.serializers import UserSimpleSerializer from rest_framework.permissions import AllowAny -logger = logging.getLogger('log') -def load_face_data(username:int, path:str): - """ - 将某用户face_encoding加载进缓存 - """ - face_datas = cache.get_or_set('face_datas', {}, timeout=None) - photo_path = settings.BASE_DIR + path - picture_of_me = face_recognition.load_image_file(photo_path) - my_face_encoding = face_recognition.face_encodings(picture_of_me)[0] - face_datas[username] = my_face_encoding - cache.set('face_datas', face_datas, timeout=None) - return my_face_encoding # Create your views here. class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMixin, RetrieveModelMixin, GenericViewSet): @@ -44,16 +31,21 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix serializer_class = EmployeeSerializer ordering = ['-pk'] - def perform_update(self, serializer): - instance = serializer.save(update_by = self.request.user) - try: - photo_path = settings.BASE_DIR + instance.photo - picture_of_me = face_recognition.load_image_file(photo_path) - my_face_encoding = face_recognition.face_encodings(picture_of_me)[0] - instance.face_data = my_face_encoding.tolist() - instance.save() - except: - logger.error('人脸识别出错') + def update(self, request, *args, **kwargs): + partial = kwargs.pop('partial', False) + instance = self.get_object() + data = request.data + serializer = self.get_serializer(instance, data=data, partial=partial) + serializer.is_valid(raise_exception=True) + photo = data.get('photo', None) + if instance.photo != photo: + f_l = HRMService.get_facedata_from_img(photo) + if f_l: + serializer.save(update_by=request.user, face_data = f_l) + return Response() + return Response('头像识别失败', status=status.HTTP_400_BAD_REQUEST) + serializer.save(update_by=request.user) + return Response() class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet): diff --git a/hb_server/server/settings.py b/hb_server/server/settings.py index cc780f3..5cf9d99 100644 --- a/hb_server/server/settings.py +++ b/hb_server/server/settings.py @@ -194,7 +194,7 @@ AUTHENTICATION_BACKENDS = ( # CACHES = { # "default": { # "BACKEND": "django_redis.cache.RedisCache", -# "LOCATION": "redis://redis:6379/1", +# "LOCATION": "redis://127.0.0.1:6379/0", # "OPTIONS": { # "CLIENT_CLASS": "django_redis.client.DefaultClient", # "PICKLE_VERSION": -1 @@ -203,7 +203,7 @@ AUTHENTICATION_BACKENDS = ( # } # celery配置,celery正常运行必须安装redis -CELERY_BROKER_URL = "redis://redis:6379/0" # 任务存储 +CELERY_BROKER_URL = "redis://127.0.0.1:6379/1" # 任务存储 CELERYD_MAX_TASKS_PER_CHILD = 100 # 每个worker最多执行300个任务就会被销毁,可防止内存泄露 CELERY_TIMEZONE = 'Asia/Shanghai' # 设置时区 CELERY_ENABLE_UTC = True # 启动时区设置 From 743d7ce862be40310d15e013a3723ccd51829e12 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 21 Jan 2022 16:21:21 +0800 Subject: [PATCH 02/16] =?UTF-8?q?employee=20list=20=E5=8E=BB=E9=99=A4face?= =?UTF-8?q?=5Fdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/serializers.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/hb_server/apps/hrm/serializers.py b/hb_server/apps/hrm/serializers.py index 429cc40..31eb30d 100644 --- a/hb_server/apps/hrm/serializers.py +++ b/hb_server/apps/hrm/serializers.py @@ -6,20 +6,9 @@ from apps.system.serializers import UserListSerializer, UserSimpleSerializer from django.db.models.query import Prefetch class EmployeeSerializer(ModelSerializer): - # user_ = UserListSerializer(source='user', read_only=True) class Meta: model = Employee - fields = '__all__' - # @staticmethod - # def setup_eager_loading(queryset): - # """ Perform necessary eager loading of data. """ - # queryset = queryset.select_related('user', 'user__dept') - # # queryset = queryset.prefetch_related('user','user__dept') - # queryset = queryset.prefetch_related( - # Prefetch('user_', - # queryset=User.objects.filter(employee_user__isnull=True)) - # ) - # return queryset + exclude = ['face_data'] class FaceLoginSerializer(serializers.Serializer): base64 = serializers.CharField() From 65fe7f060b92093f42be344323121be0873ce5dc Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 21 Jan 2022 16:35:37 +0800 Subject: [PATCH 03/16] =?UTF-8?q?equip=20simple=E5=A2=9E=E5=8A=A0type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index e41ee48..dafe59c 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -1,3 +1,4 @@ +from functools import update_wrapper from django.shortcuts import render from django.utils import timezone from rest_framework.response import Response @@ -5,6 +6,7 @@ from rest_framework.viewsets import ModelViewSet, GenericViewSet from rest_framework.mixins import UpdateModelMixin, RetrieveModelMixin, CreateModelMixin, ListModelMixin from apps.hrm.filters import ClockRecordFilterSet from apps.hrm.services import HRMService +from apps.hrm.tasks import update_all_user_facedata_cache from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin from apps.hrm.models import ClockRecord, Employee from apps.hrm.serializers import ClockRecordListSerializer, EmployeeSerializer, FaceClockCreateSerializer, FaceLoginSerializer @@ -42,6 +44,8 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix f_l = HRMService.get_facedata_from_img(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) serializer.save(update_by=request.user) From c2d2e2405b5f9bd4b9353f123cca042acbb3401d Mon Sep 17 00:00:00 2001 From: shijing Date: Fri, 21 Jan 2022 17:14:36 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=93=8D=E4=BD=9C=E4=BA=BA=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=BE=AE=E8=B0=83=E5=88=B7=E8=84=B8=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_client/src/api/hrm.js | 15 ++++ .../src/components/faceLogin/tracking.vue | 36 ++------ hb_client/src/router/index.js | 2 +- hb_client/src/views/dashboard/index.vue | 84 +++++++++++++++++-- hb_client/src/views/qm/producttest.vue | 54 +++++++++--- hb_client/src/views/qm/taskrecordfrom.vue | 28 ++++++- hb_client/src/views/wpm/need.vue | 26 +++++- 7 files changed, 192 insertions(+), 53 deletions(-) create mode 100644 hb_client/src/api/hrm.js diff --git a/hb_client/src/api/hrm.js b/hb_client/src/api/hrm.js new file mode 100644 index 0000000..beca22f --- /dev/null +++ b/hb_client/src/api/hrm.js @@ -0,0 +1,15 @@ +import request from '@/utils/request' +export function faceLogin(data) { + return request({ + url: '/hrm/facelogin/', + method: 'post', + data + }) +} +export function clockRecord(data) { + return request({ + url: '/hrm/clock_record/', + method: 'post', + data + }) +} diff --git a/hb_client/src/components/faceLogin/tracking.vue b/hb_client/src/components/faceLogin/tracking.vue index 4ef978b..bb11c75 100644 --- a/hb_client/src/components/faceLogin/tracking.vue +++ b/hb_client/src/components/faceLogin/tracking.vue @@ -10,8 +10,7 @@ diff --git a/hb_client/src/views/qm/producttest.vue b/hb_client/src/views/qm/producttest.vue index c8e9e87..763842d 100644 --- a/hb_client/src/views/qm/producttest.vue +++ b/hb_client/src/views/qm/producttest.vue @@ -96,6 +96,14 @@ + + + + + + @@ -896,9 +981,11 @@ .el-card.is-always-shadow { height: auto !important; } + .dashboard-container { margin: 5px 6px; } + .dashboardTopCard, .dashboardMiddle, .dashboardBottomRow { -webkit-border-radius: 5px; -moz-border-radius: 5px; @@ -907,12 +994,15 @@ background: #ffffff; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1); } + .dashboardBottomRow { margin-bottom: 0; } + .dashboardCardPadding { padding: 5px 20px 20px 20px; } + /**/ .cardsWrap { display: flex; @@ -921,69 +1011,85 @@ float: left; font-size: 14px; } + .svgIconWrap { margin-right: 20px; width: 50px; height: 50px; border-radius: 15px; text-align: center; + .svgIcon { font-size: 24px; margin-top: 13px } } + .cardsWrap:nth-child(1) { .svgIconWrap { background: #e9f3ff; + .svgIcon { color: #409EFF; } } } + .cardsWrap:nth-child(2) { .svgIconWrap { background: #fff1de; + .svgIcon { color: #ffb23f; } } } + .cardsWrap:nth-child(3) { .svgIconWrap { background: #d9f6d8; + .svgIcon { color: #54cb48; } } } + .cardsWrap:nth-child(4) { .svgIconWrap { background: #f0e8fd; + .svgIcon { color: #a378e4; } } } + .cardsWrap:nth-child(5) { .svgIconWrap { background: #f7e5ea; + .svgIcon { color: #f27197; } } } + .totalCountText { height: 20px; line-height: 20px } + .totalCountNum { height: 30px; } + .totalCount { font-size: 25px; font-weight: bold; color: #626262; } + /**/ .CardTitleWrap { display: flex; @@ -1000,6 +1106,7 @@ margin-right: 7px; margin-top: 8px; } + .dashboardCardTitle { height: 34px; line-height: 34px; @@ -1009,6 +1116,7 @@ vertical-align: middle; margin-right: 7px; } + .stockMore { font-size: 12px; font-weight: normal; @@ -1016,12 +1124,15 @@ cursor: pointer; } } + /*成品率筛选条件*/ .dashboardCardHand { display: flex; justify-content: space-between; + .dashboardCardFilter { display: flex; + .convenientWrap { display: flex; border: 1px solid #DCDFE6; @@ -1030,19 +1141,23 @@ line-height: 30px; margin-left: 10px; font-size: 12px; + .convenientBtn { cursor: pointer; width: 50px; text-align: center; border-right: 1px solid #DCDFE6; } + .convenientBtn:last-child { border-right: 0; border-radius: 0 6px 6px 0; } + .convenientBtn:first-child { border-radius: 6px 0 0 6px; } + .activeIndex { color: #ffffff; background: #409EFF; @@ -1050,10 +1165,12 @@ } } } + .anim { transition: all 0.5s; margin-top: -35px; //高度等于行高 } + .lists { height: 100%; line-height: 35px; @@ -1061,22 +1178,27 @@ overflow-y: scroll; padding-right: 40px; margin: 0 !important; + .listItem { height: 40px; line-height: 40px; font-size: 16px; + .itemText { display: flex; justify-content: space-between; } } } + #chartColumn > div { height: 100% !important; + canvas { height: 100% !important; } } + #dashboardMiddle .el-range-editor--medium.el-input__inner, #dashboardMiddle .el-range-editor.el-input__inner { height: 30px !important; From aec8841ba6861ee7eb04e838e5c7e1c08f0ace6a Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 13:47:08 +0800 Subject: [PATCH 06/16] =?UTF-8?q?sam=20order=E5=A2=9E=E5=8A=A0=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/sam/filters.py | 18 ++++++++++++++++-- hb_server/apps/sam/models.py | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/hb_server/apps/sam/filters.py b/hb_server/apps/sam/filters.py index 779e7b4..a0c3626 100644 --- a/hb_server/apps/sam/filters.py +++ b/hb_server/apps/sam/filters.py @@ -1,22 +1,36 @@ from django_filters import rest_framework as filters from apps.sam.models import Order +from django.db.models import F +from datetime import datetime, timedelta class OrderFilterSet(filters.FilterSet): create_time_start = filters.DateFilter(field_name="create_time", lookup_expr='gte') create_time_end = filters.DateFilter(field_name="create_time", lookup_expr='lte') material = filters.NumberFilter(method='filter_material') + tag = filters.CharFilter(method='filter_tag') class Meta: model = Order - fields = ['product', 'contract', 'customer', 'create_time_start', 'create_time_end'] + fields = ['product', 'contract', 'customer', 'create_time_start', + 'create_time_end', 'tag'] def filter_material(self, queryset, name, value): """ 按物料筛选 """ - return queryset.filter(plan_order__subplan_plan__progress_subplan__material__id=value).distinct() + return queryset.filter( + plan_order__subplan_plan__progress_subplan__material__id=value).distinct() + def filter_tag(self, queryset, name, value): + if value == 'near_delivery': + day7_after = datetime.now() + timedelta(days=7) + queryset = queryset.filter(delivered_count__lt=F('count'), + delivery_date__lte = datetime.date(day7_after)) + elif value == 'out_delivery': + queryset = queryset.filter(delivered_count__lt=F('count'), + delivery_date__gt = datetime.date(datetime.now())) + return queryset class ContractFilterSet(filters.FilterSet): create_time_start = filters.DateFilter(field_name="create_time", lookup_expr='gte') diff --git a/hb_server/apps/sam/models.py b/hb_server/apps/sam/models.py index 3e51a97..bceb63c 100644 --- a/hb_server/apps/sam/models.py +++ b/hb_server/apps/sam/models.py @@ -66,6 +66,7 @@ class Order(CommonAModel): planed_count = models.PositiveIntegerField('已排数量', default=0) delivered_count = models.PositiveIntegerField('已交货数量', default=0) delivery_date = models.DateField('交货日期') + need_mtest = models.BooleanField('是否需要军检', default=False) class Meta: verbose_name = '订单信息' verbose_name_plural = verbose_name From 444914fde9214679206213d9088fb2695e45e1a4 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 13:55:28 +0800 Subject: [PATCH 07/16] =?UTF-8?q?wproduct=20list=20=E5=A2=9E=E5=8A=A0order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sam/migrations/0011_order_need_mtest.py | 18 ++++ hb_server/apps/wpm/serializers.py | 1 + hb_server/apps/wpm/views.py | 3 +- hb_server/utils/mixins.py | 82 +++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 hb_server/apps/sam/migrations/0011_order_need_mtest.py create mode 100644 hb_server/utils/mixins.py diff --git a/hb_server/apps/sam/migrations/0011_order_need_mtest.py b/hb_server/apps/sam/migrations/0011_order_need_mtest.py new file mode 100644 index 0000000..81ebb27 --- /dev/null +++ b/hb_server/apps/sam/migrations/0011_order_need_mtest.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.9 on 2022-01-24 05:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sam', '0010_auto_20211208_1408'), + ] + + operations = [ + migrations.AddField( + model_name='order', + name='need_mtest', + field=models.BooleanField(default=False, verbose_name='是否需要军检'), + ), + ] diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 3181088..6716fdb 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -157,6 +157,7 @@ class WProductListSerializer(serializers.ModelSerializer): warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True) children = serializers.SerializerMethodField() to_order_ = OrderSimpleSerializer(source='to_order', read_only=True) + order_ = OrderSimpleSerializer(source='subproduction_plan__production_plan__order', read_only=True) class Meta: model = WProduct fields = '__all__' diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index e300f40..f5be060 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -148,7 +148,8 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): """ perms_map = {'*': '*'} queryset = WProduct.objects.select_related('step', 'material', - 'subproduction_plan', 'warehouse', 'to_order').prefetch_related('wproduct_child') + 'subproduction_plan', 'warehouse', 'subproduction_plan__production_plan__order', + 'to_order').prefetch_related('wproduct_child') serializer_class = WProductListSerializer filterset_class = WProductFilterSet search_fields = ['number'] diff --git a/hb_server/utils/mixins.py b/hb_server/utils/mixins.py new file mode 100644 index 0000000..b0ccb80 --- /dev/null +++ b/hb_server/utils/mixins.py @@ -0,0 +1,82 @@ +""" +Mixin to dynamically select only a subset of fields per DRF resource. +""" +import warnings + +from django.conf import settings + + +class DynamicFieldsMixin(object): + """ + A serializer mixin that takes an additional `fields` argument that controls + which fields should be displayed. + """ + + @property + def fields(self): + """ + Filters the fields according to the `fields` query parameter. + A blank `fields` parameter (?fields) will remove all fields. Not + passing `fields` will pass all fields individual fields are comma + separated (?fields=id,name,url,email). + """ + fields = super(DynamicFieldsMixin, self).fields + + if not hasattr(self, '_context'): + # We are being called before a request cycle + return fields + + # Only filter if this is the root serializer, or if the parent is the + # root serializer with many=True + is_root = self.root == self + parent_is_list_root = self.parent == self.root and getattr(self.parent, 'many', False) + if not (is_root or parent_is_list_root): + return fields + + try: + request = self.context['request'] + except KeyError: + conf = getattr(settings, 'DRF_DYNAMIC_FIELDS', {}) + if not conf.get('SUPPRESS_CONTEXT_WARNING', False) is True: + warnings.warn('Context does not have access to request. ' + 'See README for more information.') + return fields + + # NOTE: drf test framework builds a request object where the query + # parameters are found under the GET attribute. + params = getattr( + request, 'query_params', getattr(request, 'GET', None) + ) + if params is None: + warnings.warn('Request object does not contain query paramters') + + try: + filter_fields = params.get('fields', None).split(',') + except AttributeError: + filter_fields = None + + try: + omit_fields = params.get('omit', None).split(',') + except AttributeError: + omit_fields = [] + + # Drop any fields that are not specified in the `fields` argument. + existing = set(fields.keys()) + if filter_fields is None: + # no fields param given, don't filter. + allowed = existing + else: + allowed = set(filter(None, filter_fields)) + + # omit fields in the `omit` argument. + omitted = set(filter(None, omit_fields)) + + for field in existing: + + if field not in allowed: + fields.pop(field, None) + + if field in omitted: + fields.pop(field, None) + + return fields \ No newline at end of file From c39d62c9a57271aca61d608bdf007dfd9ff7b939 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 14:31:07 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E5=8E=BB=E9=99=A4is=5Fmtested=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/inm/serializers.py | 1 - hb_server/apps/sam/serializers.py | 2 +- hb_server/apps/sam/views.py | 7 ------- hb_server/apps/wpm/models.py | 2 -- hb_server/apps/wpm/serializers.py | 10 ++++++++-- hb_server/apps/wpm/views.py | 3 +-- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/hb_server/apps/inm/serializers.py b/hb_server/apps/inm/serializers.py index 766a164..e04b115 100644 --- a/hb_server/apps/inm/serializers.py +++ b/hb_server/apps/inm/serializers.py @@ -51,7 +51,6 @@ class MaterialBatchSerializer(serializers.ModelSerializer): class IProductListSerializer(serializers.ModelSerializer): material_ = MaterialSimpleSerializer(source='material', read_only=True) warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True) - is_mtested = serializers.BooleanField(source='wproduct.is_mtested', read_only=True) is_mtestok = serializers.BooleanField(source='wproduct.is_mtestok', read_only=True) remark_mtest = serializers.CharField(source='wproduct.remark_mtest', read_only=True) diff --git a/hb_server/apps/sam/serializers.py b/hb_server/apps/sam/serializers.py index 154b1e7..a397c63 100644 --- a/hb_server/apps/sam/serializers.py +++ b/hb_server/apps/sam/serializers.py @@ -63,7 +63,7 @@ class OrderSimpleSerializer(serializers.ModelSerializer): customer_ = CustomerSimpleSerializer(source='customer', read_only=True) class Meta: model = Order - fields = '__all__' + fields = ['id', 'number', 'contract_', 'customer_', 'need_test'] class SaleCreateSerializer(serializers.ModelSerializer): iproducts = serializers.PrimaryKeyRelatedField(queryset=IProduct.objects.all(), many=True) diff --git a/hb_server/apps/sam/views.py b/hb_server/apps/sam/views.py index a239d8e..357706e 100644 --- a/hb_server/apps/sam/views.py +++ b/hb_server/apps/sam/views.py @@ -136,13 +136,6 @@ class SaleViewSet(CreateUpdateCustomMixin, ListModelMixin, RetrieveModelMixin, C fifo.inout_date = timezone.now() fifo.create_by = request.user fifo.save() - # 出库条目 暂时不校验是否军检 - # spds = SaleProduct.objects.filter(sale=obj) - # for i in spds: - # if i.is_mtested and i.is_mtestok: - # pass - # else: - # raise exceptions.APIException('存在未军检产品') # 创建出库条目 ips = IProduct.objects.filter(sale_iproduct__sale=obj) items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id')) diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index c52a061..9027301 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -120,7 +120,6 @@ class WProduct(CommonAModel): on_delete=models.SET_NULL, null=True, blank=True, related_name='wp_ticket') to_order = models.ForeignKey('sam.order', verbose_name='指派的订单', null=True, blank=True, on_delete = models.CASCADE) - is_mtested = models.BooleanField('是否军检', default=False) is_mtestok = models.BooleanField('是否军检合格', null=True, blank=True) remark_mtest = models.TextField('军检备注', null=True, blank=True) last_test_result = models.BooleanField('最后一次检验结果', null=True, blank=True) @@ -194,7 +193,6 @@ class WproductFlow(CommonAModel): ticket = models.ForeignKey('wf.ticket', verbose_name='当前工单', on_delete=models.SET_NULL, null=True, blank=True) to_order = models.ForeignKey('sam.order', verbose_name='指派的订单', null=True, blank=True, on_delete = models.CASCADE) - is_mtested = models.BooleanField('是否军检', default=False) is_mtestok = models.BooleanField('是否军检合格', null=True, blank=True) remark_mtest = models.TextField('军检备注', null=True, blank=True) last_test_result = models.BooleanField('最后一次检验结果', null=True, blank=True) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 6716fdb..9436243 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -157,7 +157,7 @@ class WProductListSerializer(serializers.ModelSerializer): warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True) children = serializers.SerializerMethodField() to_order_ = OrderSimpleSerializer(source='to_order', read_only=True) - order_ = OrderSimpleSerializer(source='subproduction_plan__production_plan__order', read_only=True) + order_ = serializers.SerializerMethodField() class Meta: model = WProduct fields = '__all__' @@ -167,6 +167,11 @@ class WProductListSerializer(serializers.ModelSerializer): if wps.exists(): return WProductBaseSerializer(instance=wps, many=True).data return [] + + def get_order_(self, obj): + order = Order.objects.select_related('contract', 'customer').filter( + plan_order__subplan_plan__wproduct_subplan=obj).first() + return OrderSimpleSerializer(instance=order).data class WProductCardBaseSerializer(serializers.ModelSerializer): """ @@ -225,6 +230,8 @@ class WProductDetailSerializer(serializers.ModelSerializer): subproduction_plan_ = SubproductionPlanSimpleSerializer(source='subproduction_plan', read_only=True) warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True) children = serializers.SerializerMethodField() + to_order_ = OrderSimpleSerializer(source='to_order', read_only=True) + order_ = OrderSimpleSerializer(source='subproduction_plan__production_plan__order', read_only=True) class Meta: model = WProduct fields = '__all__' @@ -232,7 +239,6 @@ class WProductDetailSerializer(serializers.ModelSerializer): def get_children(self, obj): wps = WProduct.objects.filter(child=obj) if wps.exists(): - print(wps) return WProductBaseSerializer(instance=wps, many=True).data return [] diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index f5be060..d1f9c5a 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -399,12 +399,11 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): 军检 """ obj = self.get_object() - if obj.is_mtested: + if obj.is_mtestok is None: raise exceptions.APIException('已进行军检') if obj.material.type != Material.MA_TYPE_GOOD: raise exceptions.APIException('军检必须是成品') obj.remark_mtest = request.data.get('remark_mtest', None) - obj.is_mtested = True is_mtestok = request.data.get('is_mtestok') obj.is_mtestok = is_mtestok if is_mtestok: From eaa6da6a4f378cb87178e2c36c4b1fb96fbb2c84 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 15:21:07 +0800 Subject: [PATCH 09/16] sam order simple bug --- hb_server/apps/inm/serializers.py | 2 +- hb_server/apps/sam/serializers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hb_server/apps/inm/serializers.py b/hb_server/apps/inm/serializers.py index e04b115..3569848 100644 --- a/hb_server/apps/inm/serializers.py +++ b/hb_server/apps/inm/serializers.py @@ -53,7 +53,7 @@ class IProductListSerializer(serializers.ModelSerializer): warehouse_ = WareHouseSimpleSerializer(source='warehouse', read_only=True) is_mtestok = serializers.BooleanField(source='wproduct.is_mtestok', read_only=True) remark_mtest = serializers.CharField(source='wproduct.remark_mtest', read_only=True) - + class Meta: model = IProduct fields = '__all__' diff --git a/hb_server/apps/sam/serializers.py b/hb_server/apps/sam/serializers.py index a397c63..81ed0df 100644 --- a/hb_server/apps/sam/serializers.py +++ b/hb_server/apps/sam/serializers.py @@ -63,7 +63,7 @@ class OrderSimpleSerializer(serializers.ModelSerializer): customer_ = CustomerSimpleSerializer(source='customer', read_only=True) class Meta: model = Order - fields = ['id', 'number', 'contract_', 'customer_', 'need_test'] + fields = ['id', 'number', 'contract_', 'customer_', 'need_mtest'] class SaleCreateSerializer(serializers.ModelSerializer): iproducts = serializers.PrimaryKeyRelatedField(queryset=IProduct.objects.all(), many=True) From ceb0fe2354a5d64e8ee98de034edfc244d820db2 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 15:38:52 +0800 Subject: [PATCH 10/16] =?UTF-8?q?drf=E5=8A=A8=E6=80=81=E5=AD=97=E6=AE=B5mi?= =?UTF-8?q?xins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/system/filters.py | 10 ++++++---- hb_server/apps/system/serializers.py | 3 ++- hb_server/utils/mixins.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hb_server/apps/system/filters.py b/hb_server/apps/system/filters.py index 4199790..0702953 100644 --- a/hb_server/apps/system/filters.py +++ b/hb_server/apps/system/filters.py @@ -3,9 +3,11 @@ from .models import User class UserFilter(filters.FilterSet): + name = filters.CharFilter(field_name='name', lookup_expr='contains') + fields = filters.CharFilter(method='filter_fields') class Meta: model = User - fields = { - 'name': ['exact', 'contains'], - 'is_active': ['exact'], - } + fields = ['name', 'is_active', 'fields'] + + def filter_fields(self, queryset, name, value): + return queryset \ No newline at end of file diff --git a/hb_server/apps/system/serializers.py b/hb_server/apps/system/serializers.py index 8d644b3..d74c8a2 100644 --- a/hb_server/apps/system/serializers.py +++ b/hb_server/apps/system/serializers.py @@ -5,6 +5,7 @@ from rest_framework import serializers from .models import (Dict, DictType, File, Organization, Permission, Position, Role, User) +from utils.mixins import DynamicFieldsMixin class IntervalSerializer(serializers.ModelSerializer): class Meta: @@ -132,7 +133,7 @@ class UserSimpleSerializer(serializers.ModelSerializer): # fields = ['id', 'username', 'name', 'is_active', 'dept_name', 'dept'] -class UserListSerializer(serializers.ModelSerializer): +class UserListSerializer(DynamicFieldsMixin, serializers.ModelSerializer): """ 用户列表序列化 """ diff --git a/hb_server/utils/mixins.py b/hb_server/utils/mixins.py index b0ccb80..f3538d0 100644 --- a/hb_server/utils/mixins.py +++ b/hb_server/utils/mixins.py @@ -1,9 +1,9 @@ """ Mixin to dynamically select only a subset of fields per DRF resource. """ -import warnings +# import warnings -from django.conf import settings +# from django.conf import settings class DynamicFieldsMixin(object): @@ -36,10 +36,10 @@ class DynamicFieldsMixin(object): try: request = self.context['request'] except KeyError: - conf = getattr(settings, 'DRF_DYNAMIC_FIELDS', {}) - if not conf.get('SUPPRESS_CONTEXT_WARNING', False) is True: - warnings.warn('Context does not have access to request. ' - 'See README for more information.') + # conf = getattr(settings, 'DRF_DYNAMIC_FIELDS', {}) + # if not conf.get('SUPPRESS_CONTEXT_WARNING', False) is True: + # warnings.warn('Context does not have access to request. ' + # 'See README for more information.') return fields # NOTE: drf test framework builds a request object where the query @@ -47,8 +47,8 @@ class DynamicFieldsMixin(object): params = getattr( request, 'query_params', getattr(request, 'GET', None) ) - if params is None: - warnings.warn('Request object does not contain query paramters') + # if params is None: + # warnings.warn('Request object does not contain query paramters') try: filter_fields = params.get('fields', None).split(',') From f6a7ada99fccac748db1e2efa4f9fa3f8a68ec11 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 15:48:25 +0800 Subject: [PATCH 11/16] =?UTF-8?q?drf=20=E5=8A=A8=E6=80=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5omit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/system/filters.py | 8 +++++++- hb_server/utils/mixins.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hb_server/apps/system/filters.py b/hb_server/apps/system/filters.py index 0702953..2aa0dba 100644 --- a/hb_server/apps/system/filters.py +++ b/hb_server/apps/system/filters.py @@ -1,13 +1,19 @@ from django_filters import rest_framework as filters from .models import User +from utils.mixins import DynamicFieldsFilterMixin -class UserFilter(filters.FilterSet): +class UserFilter(DynamicFieldsFilterMixin, filters.FilterSet): name = filters.CharFilter(field_name='name', lookup_expr='contains') fields = filters.CharFilter(method='filter_fields') + omit = filters.CharFilter(method='filter_omit') class Meta: model = User fields = ['name', 'is_active', 'fields'] def filter_fields(self, queryset, name, value): + return queryset + + + def filter_omit(self, queryset, name, value): return queryset \ No newline at end of file diff --git a/hb_server/utils/mixins.py b/hb_server/utils/mixins.py index f3538d0..7a37a3c 100644 --- a/hb_server/utils/mixins.py +++ b/hb_server/utils/mixins.py @@ -2,9 +2,13 @@ Mixin to dynamically select only a subset of fields per DRF resource. """ # import warnings +from django_filters import rest_framework as filters # from django.conf import settings - +class DynamicFieldsFilterMixin(object): + fields = filters.CharFilter(method='filter_fields') + def filter_fields(self, queryset, name, value): + return queryset class DynamicFieldsMixin(object): """ From efc101d2a16866ba04e39e38e02d8ced344d0364 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 24 Jan 2022 16:21:00 +0800 Subject: [PATCH 12/16] =?UTF-8?q?drf=20=E5=8A=A8=E6=80=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20mixins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/inm/filters.py | 3 ++- hb_server/apps/system/filters.py | 11 +---------- hb_server/apps/system/serializers.py | 4 ++-- hb_server/apps/wpm/filters.py | 7 ++++++- hb_server/apps/wpm/serializers.py | 3 ++- hb_server/utils/mixins.py | 14 ++++++++++++-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/hb_server/apps/inm/filters.py b/hb_server/apps/inm/filters.py index 73f92a6..41dcf61 100644 --- a/hb_server/apps/inm/filters.py +++ b/hb_server/apps/inm/filters.py @@ -15,7 +15,8 @@ class MbFilterSet(filters.FilterSet): def filter_tag(self, queryset, name, value): if value == 'expired': - queryset = queryset.exclude(expiration_date=None).filter(expiration_date__lte=timezone.now()) + queryset = queryset.exclude(expiration_date=None).filter( + expiration_date__lte=timezone.now()) return queryset diff --git a/hb_server/apps/system/filters.py b/hb_server/apps/system/filters.py index 2aa0dba..22ef179 100644 --- a/hb_server/apps/system/filters.py +++ b/hb_server/apps/system/filters.py @@ -5,15 +5,6 @@ from utils.mixins import DynamicFieldsFilterMixin class UserFilter(DynamicFieldsFilterMixin, filters.FilterSet): name = filters.CharFilter(field_name='name', lookup_expr='contains') - fields = filters.CharFilter(method='filter_fields') - omit = filters.CharFilter(method='filter_omit') class Meta: model = User - fields = ['name', 'is_active', 'fields'] - - def filter_fields(self, queryset, name, value): - return queryset - - - def filter_omit(self, queryset, name, value): - return queryset \ No newline at end of file + fields = ['name', 'is_active'] \ No newline at end of file diff --git a/hb_server/apps/system/serializers.py b/hb_server/apps/system/serializers.py index d74c8a2..1e397c5 100644 --- a/hb_server/apps/system/serializers.py +++ b/hb_server/apps/system/serializers.py @@ -5,7 +5,7 @@ from rest_framework import serializers from .models import (Dict, DictType, File, Organization, Permission, Position, Role, User) -from utils.mixins import DynamicFieldsMixin +from utils.mixins import DynamicFieldsSerializerMixin class IntervalSerializer(serializers.ModelSerializer): class Meta: @@ -133,7 +133,7 @@ class UserSimpleSerializer(serializers.ModelSerializer): # fields = ['id', 'username', 'name', 'is_active', 'dept_name', 'dept'] -class UserListSerializer(DynamicFieldsMixin, serializers.ModelSerializer): +class UserListSerializer(DynamicFieldsSerializerMixin, serializers.ModelSerializer): """ 用户列表序列化 """ diff --git a/hb_server/apps/wpm/filters.py b/hb_server/apps/wpm/filters.py index 54454f8..c4db494 100644 --- a/hb_server/apps/wpm/filters.py +++ b/hb_server/apps/wpm/filters.py @@ -2,6 +2,7 @@ from django_filters import rest_framework as filters from apps.mtm.models import Material, Step from apps.wpm.services import WpmServies +from utils.mixins import DynamicFieldsFilterMixin from .models import Operation, OperationMaterial, OperationRecord, WMaterial, WProduct @@ -28,11 +29,15 @@ class WMaterialFilterSet(filters.FilterSet): return queryset -class WProductFilterSet(filters.FilterSet): +class WProductFilterSet(DynamicFieldsFilterMixin, filters.FilterSet): tag = filters.CharFilter(method='filter_tag') production_plan = filters.NumberFilter( field_name='subproduction_plan__production_plan') + def filter_fields(self, queryset, name, value): + return queryset + def filter_omit(self, queryset, name, value): + return queryset class Meta: model = WProduct fields = ['step', 'subproduction_plan', 'material', diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 9436243..cf7ca24 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -20,6 +20,7 @@ from apps.system.serializers import UserSimpleSerializer from apps.wpm.models import Operation, OperationEquip, OperationMaterial, OperationWproduct, Pick, WMaterial, WProduct, OperationRecord, OperationRecordItem, WprouctTicket from django.db import transaction from apps.sam.models import Order +from utils.mixins import DynamicFieldsSerializerMixin class PickHalfSerializer(serializers.Serializer): id = serializers.PrimaryKeyRelatedField(queryset=SubProductionProgress.objects.all(), label='子计划进度ID') @@ -147,7 +148,7 @@ class WProductBaseSerializer(serializers.ModelSerializer): model = WProduct fields = '__all__' -class WProductListSerializer(serializers.ModelSerializer): +class WProductListSerializer(DynamicFieldsSerializerMixin, serializers.ModelSerializer): """ 半成品列表 """ diff --git a/hb_server/utils/mixins.py b/hb_server/utils/mixins.py index 7a37a3c..d62062d 100644 --- a/hb_server/utils/mixins.py +++ b/hb_server/utils/mixins.py @@ -7,10 +7,20 @@ from django_filters import rest_framework as filters # from django.conf import settings class DynamicFieldsFilterMixin(object): fields = filters.CharFilter(method='filter_fields') + omit = filters.CharFilter(method='filter_omit') def filter_fields(self, queryset, name, value): return queryset -class DynamicFieldsMixin(object): + def filter_omit(self, queryset, name, value): + return queryset + + @property + def fields(self): + fields = super(DynamicFieldsFilterMixin, self).fields + fields.extend(['fields', 'omit']) + return fields + +class DynamicFieldsSerializerMixin(object): """ A serializer mixin that takes an additional `fields` argument that controls which fields should be displayed. @@ -24,7 +34,7 @@ class DynamicFieldsMixin(object): passing `fields` will pass all fields individual fields are comma separated (?fields=id,name,url,email). """ - fields = super(DynamicFieldsMixin, self).fields + fields = super(DynamicFieldsSerializerMixin, self).fields if not hasattr(self, '_context'): # We are being called before a request cycle From 84ba98925db8faadea1e578422cd4a65140c795c Mon Sep 17 00:00:00 2001 From: shijing Date: Tue, 25 Jan 2022 08:48:05 +0800 Subject: [PATCH 13/16] 0124 --- hb_client/src/components/Gantt/dashGantt.vue | 12 ++ hb_client/src/views/dashboard/index.vue | 205 +++++++++---------- 2 files changed, 109 insertions(+), 108 deletions(-) diff --git a/hb_client/src/components/Gantt/dashGantt.vue b/hb_client/src/components/Gantt/dashGantt.vue index 4d84376..9bb04ed 100644 --- a/hb_client/src/components/Gantt/dashGantt.vue +++ b/hb_client/src/components/Gantt/dashGantt.vue @@ -299,6 +299,18 @@ } } , }, + watch: { + '$route.path': function (newVal) { + if(newVal==='/dashboard'){ + this.$refs.leftMenu.handlerSelect(this.list[0]); + this.$refs.chart.scrollTo({ + top: 0, + left: this.list[0].left - 30, + behavior: "smooth" + }); + } + } + }, data() { return { windowWidth:0, diff --git a/hb_client/src/views/dashboard/index.vue b/hb_client/src/views/dashboard/index.vue index d041f9a..a5cb9e0 100644 --- a/hb_client/src/views/dashboard/index.vue +++ b/hb_client/src/views/dashboard/index.vue @@ -4,7 +4,7 @@
数据统计
-
+
{{contractTotalCurrent}}
+
@@ -149,6 +152,8 @@
- - + + +
@@ -217,7 +228,7 @@
@@ -269,13 +280,13 @@
@@ -286,37 +297,29 @@
    -
  • +
  • - {{item.name}}2021-12-30 + {{item.name}}({{item.unit}})剩余{{item.count}},低于安全库存{{item.count_safe}}
-
    -
  • -
    - 某某批货临近交货日期2021-12-20 -
    -
  • +
    • - {{item}}2021-12-20 + {{item.name}}({{item.number}}){{item.delivery_date}}到交货日期
    -
      -
    • -
      - 某某批货临近过期2021-11-20 -
      -
    • +
      • - {{item}}2021-12-20 + {{item.name}}({{item.number}}){{item.delivery_date}}到期
      @@ -333,16 +336,13 @@ import echarts from 'echarts' import {mapGetters} from 'vuex'; import {getUserList} from "@/api/user"; - import {getPlanGantt} from "@/api/srm"; - import {getProcessYield} from "@/api/srm"; import {getMaterialList} from "@/api/mtm"; - // import {getInventoryList} from "@/api/inm"; import {getProductionplanList} from "@/api/pm"; import {getmaterialbatchList} from "@/api/inm"; import gantt from "@/components/Gantt/dashGantt"; import {getpEquipmentList} from "@/api/equipment"; - import {getContractList, getOrderList} from "@/api/sam"; - + import {getProcessYield ,getPlanGantt} from "@/api/srm"; + import {getContractList , getOrderList} from "@/api/sam"; export default { components: {gantt}, name: 'Dashboard', @@ -358,22 +358,22 @@ currentYear: null, currentMonth: null, currentDay: null, + pageCounts: 5, userPage: 1, userPageSize: 10, userTotal: 0, equipmentPage: 1, equipmentPageSize: 10, equipmentTotal: 0, - remindPage: 1, - remindPageSize: 20, - remindTotal: 0, + warningPage: 1, + warningPageSize: 10, + warningTotal: 0, tableIndex: null, chartIndex: null, tableDate: '2021-12', chartDate: [], proList: [], userList: [], - remindList: [], warningList: [], equipmentList: [], list: [ @@ -427,27 +427,47 @@ ]) }, watch: { - "$route": { - handler(route) { - if (route.name === 'dashboard') { - // that.handlerCheckList(this.list); - } + '$route.path': function (newVal) { + if(newVal==='/dashboard') { + this.getUserList();//用户列表 + this.getEquipmentList();//设备列表 + this.getGanttData();//甘特图数据 + this.getStatisticsData();//统计数据 + this.getNoticeData();//提醒列表 } } }, methods: { + setClass:function(check_date) { + let obj = {}; + if(check_date!=null){ + let dat = new Date(); + let time = dat.getTime(); + let check = new Date(check_date).getTime(); + let timeDiffer = (check-time)/1000/60/60/24; + if (4>timeDiffer&&timeDiffer>0) { + obj = 'warning'; + }else if (timeDiffer<0) { + obj = "danger"; + } + } + return obj; + }, getNoticeData() { this.ScrollUp(); }, ScrollUp() { - this.intNum = setInterval(() => { - this.animate = true; - setTimeout(() => { - this.list.push(this.list[0]); - this.list.shift(); - this.animate = false; - }, 500) - }, 1000); + let that = this; + that.intNum = setInterval(() => { + if(that.warningList.length>3){ + that.animate = true; + setTimeout(() => { + that.warningList.push(that.warningList[0]); + that.warningList.shift(); + that.animate = false; + }, 3000) + } + }, 3000); }, //鼠标移上去停止 Stop() { @@ -526,9 +546,11 @@ }); //获取库存警告 - getMaterialList({tag: 'low_inm'}).then((response) => { + getMaterialList({page: 1, page_size:that.warningPageSize,tag: 'low_inm'}).then((response) => { if (response.data) { + debugger; that.warningList = response.data.results; + that.warningTotal = response.data.count; } }); }, @@ -561,7 +583,7 @@ getUserList() { let that = this; that.listLoadingUser = true; - getUserList({page: that.userPage, page_size: that.userPageSize}).then((response) => { + getUserList({page: that.userPage, page_size: that.userPageSize, fields: 'id,name,dept_name,is_atwork'}).then((response) => { if (response.data) { that.userList = response.data.results; that.userTotal = response.data.count; @@ -575,7 +597,7 @@ let that = this; that.listLoadingUser = true; that.userPage = val; - getUserList({page: val, page_size: that.userPageSize}).then((response) => { + getUserList({page: val, page_size: that.userPageSize, fields: 'id,name,dept_name,is_atwork'}).then((response) => { if (response.data) { that.userList = response.data.results; that.userTotal = response.data.count; @@ -592,8 +614,8 @@ that.userList.push(that.userList[0]); that.userList.shift(); that.animateUser = false; - }, 500) - }, 1000); + }, 3000) + }, 3000); }, //鼠标移上去停止 stopScroll() { @@ -767,9 +789,9 @@ } else if (index === '3') { this.$router.push({name: 'management', params: {page: 1, page_size: 20}}) } else if (index === '4') { - this.$router.push({name: 'product', params: {page: 1, page_size: 20, material__type: 1}}) + this.$router.push({name: 'product'}) } else if (index === '5') { - this.$router.push({name: 'product', params: {page: 1, page_size: 20, material__type: 1}}) + this.$router.push({name: 'unproduct'}) } }, //便捷查询按钮 @@ -857,35 +879,39 @@ }, //提示 activeNameClick(tab) { + debugger; + debugger; let that = this; + that.warningPage = 1; + that.warningList = []; if (tab.label === '库存警告') { - getMaterialList({page: 0, tag: 'low_inm'}).then((response) => { + getMaterialList({page: 1, page_size:that.warningPageSize, tag: 'low_inm'}).then((response) => { if (response.data) { - that.warningList = response.data; - that.remindTotal = response.data.length; + that.warningList = response.data.results; + that.warningTotal = response.data.count; } }); } else if (tab.label === '临近交货') { - getmaterialbatchList({page: 0, tag: 'expired'}).then((response) => { + getOrderList({page: 1, page_size:that.warningPageSize,tag:'near_delivery'}).then((response) => { if (response.data) { - that.warningList = response.data; - that.remindTotal = response.data.length; + that.warningList = response.data.results; + that.warningTotal = response.data.count; } }); } else if (tab.label === '过期提醒') { - getmaterialbatchList({page: 0, tag: 'expired'}).then((response) => { + getmaterialbatchList({page: 1, page_size:that.warningPageSize, tag: 'expired'}).then((response) => { if (response.data) { - that.warningList = response.data; - that.remindTotal = response.data.length; + that.warningList = response.data.results; + that.warningTotal = response.data.count; } }); } }, - handleRemindSizeChange(val) { - this.remindPageSize = val; - this.remindPage = 1; + handleWarningSizeChange(val) { + this.warningPageSize = val; + this.warningPage = 1; }, - handleRemindCurrentChange(val) { + handleWarningCurrentChange(val) { console.log(`当前页: ${val}`); }, getGanttData() { @@ -976,16 +1002,13 @@ }, } -