diff --git a/hb_client/src/api/equipment.js b/hb_client/src/api/equipment.js
index 2eadc6b..d4707e9 100644
--- a/hb_client/src/api/equipment.js
+++ b/hb_client/src/api/equipment.js
@@ -36,34 +36,34 @@ export function deleteEquipment(id, data) {
}
export function getEquipmentrecordList(query) {
return request({
- url: '/em/equipmentrecord/',
+ url: '/em/echeck_record/',
method: 'get',
params: query
})
}
export function getEquipmentrecordAll() {
return request({
- url: '/em/equipmentrecord/',
+ url: '/em/echeck_record/',
method: 'get'
})
}
export function createEquipmentrecord(data) {
return request({
- url: '/em/equipmentrecord/',
+ url: '/em/echeck_record/',
method: 'post',
data
})
}
export function updateEquipmentrecord(id, data) {
return request({
- url: `/em/equipmentrecord/${id}/`,
+ url: `/em/echeck_record/${id}/`,
method: 'put',
data
})
}
export function deleteEquipmentrecord(id, data) {
return request({
- url: `/em/equipmentrecord/${id}/`,
+ url: `/em/echeck_record/${id}/`,
method: 'delete',
data
})
diff --git a/hb_client/src/api/wpm.js b/hb_client/src/api/wpm.js
index 76affca..5653ac6 100644
--- a/hb_client/src/api/wpm.js
+++ b/hb_client/src/api/wpm.js
@@ -357,4 +357,14 @@ export function getCard(id) {
url: `/wpm/wproduct/${id}/card/`,
method: 'GET',
})
-}
\ No newline at end of file
+}
+
+//指派发货订单
+
+export function toorder(data) {
+ return request({
+ url: '/wpm/wproduct/to_order/',
+ method: 'post',
+ data
+ })
+}
diff --git a/hb_client/src/router/index.js b/hb_client/src/router/index.js
index 48514da..126f360 100644
--- a/hb_client/src/router/index.js
+++ b/hb_client/src/router/index.js
@@ -273,12 +273,6 @@ export const asyncRoutes = [
name: 'record',
component: () => import('@/views/em/record'),
meta: { title: '校准检定记录', icon: 'example', perms: ['em_record'] }
- },
- {
- path: 'detection ',
- name: 'detection ',
- component: () => import('@/views/em/detection'),
- meta: { title: '运维记录', icon: 'example', perms: ['em_detection'] }
}
]
},
@@ -399,6 +393,12 @@ export const asyncRoutes = [
name: 'producttest',
component: () => import('@/views/qm/producttest'),
meta: { title: '成品检验', icon: 'example', perms: ['index_manage'] }
+ },
+ {
+ path: 'unproduct',
+ name: 'unproduct',
+ component: () => import('@/views/qm/unproduct'),
+ meta: { title: '不合格品', icon: 'example', perms: ['index_manage'] }
}
]
diff --git a/hb_client/src/views/em/detection.vue b/hb_client/src/views/em/detection.vue
index 4091991..c45bf3c 100644
--- a/hb_client/src/views/em/detection.vue
+++ b/hb_client/src/views/em/detection.vue
@@ -2,109 +2,116 @@
- 新增设备
-
- 搜索
- 重置
-
-
+ 新增设备
+
+ 搜索
+ 重置
+
-
+
-
+
{{ scope.row.number }}
-
+
- {{ mgmtype_[scope.row.mgmtype] }}
+ {{
+ mgmtype_[scope.row.mgmtype]
+ }}
-
+
{{ waytype_[scope.row.way] }}
-
+
{{ scope.row.standard }}
-
+
{{ scope.row.cycle }}
-
+
+ {{ scope.row.check_date }}
+
+
+
+ {{ scope.row.next_check_date }}
+
+
+
{{ scope.row.name }}
-
+
{{ scope.row.model }}
-
-
+
+
{{ scope.row.factory }}
-
+
{{ usetype_[scope.row.way] }}
-
- {{ state_[scope.row.statedm] }}
+
+ {{ state_[scope.row.state] }}
-
+
- {{ scope.row.keeper_.username }}
+ {{
+ scope.row.keeper_.username
+ }}
-
+
{{ scope.row.place }}
-
-
- {{item.name}}
-
-
+
+
+ {{ item.name }}
{{ scope.row.description }}
-
-
+
-
编辑
@@ -137,130 +144,153 @@
label-position="right"
:rules="rule1"
>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ :value="item.value"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
取消
@@ -285,13 +307,19 @@
+
diff --git a/hb_client/src/views/sam/order.vue b/hb_client/src/views/sam/order.vue
index f64155d..116d226 100644
--- a/hb_client/src/views/sam/order.vue
+++ b/hb_client/src/views/sam/order.vue
@@ -206,8 +206,8 @@ export default {
dialogVisible: false,
dialogType: "new",
rule1: {
- number: [{ required: true, message: "请输入", trigger: "blur" }],
- customer: [{ required: true, message: "请输入", trigger: "blur" }],
+
+
product: [{ required: true, message: "请输入", trigger: "blur" }],
delivery_date: [{ required: true, message: "请输入", trigger: "blur" }],
},
diff --git a/hb_client/src/views/sam/sales.vue b/hb_client/src/views/sam/sales.vue
index a85a9b1..46d04df 100644
--- a/hb_client/src/views/sam/sales.vue
+++ b/hb_client/src/views/sam/sales.vue
@@ -262,7 +262,7 @@ export default {
if (response.data) {
this.sale.customer = response.data.customer;
this.sale.product = response.data.product;
- getiproductList({page:0,material__type:1,material:this.sale.product}).then((response) => {
+ getiproductList({page:0,to_order:response.data.id}).then((response) => {
if (response.data) {
this.iproductoptions=response.data;
}
diff --git a/hb_client/src/views/wpm/operationdo.vue b/hb_client/src/views/wpm/operationdo.vue
index d6806ca..3cf6c68 100644
--- a/hb_client/src/views/wpm/operationdo.vue
+++ b/hb_client/src/views/wpm/operationdo.vue
@@ -3,8 +3,10 @@
基本信息
+
- 查看作业指导书
+
+ 查看作业指导书
-
-
-
-
- {{ scope.row.file_.name }}
-
-
-
+ size="70%">
+
@@ -602,7 +599,7 @@ import {
createOutputs,
deleteOperationeinput
} from "@/api/wpm";
-
+import mammoth from "mammoth";
import { getrffieldList,gettechdocList } from "@/api/mtm";
import checkPermission from "@/utils/permission";
import { getprogressList } from "@/api/pm";
@@ -731,13 +728,15 @@ export default {
outputData: [],
tprogressData: [],
tool:"",
+ wordText: "",
+
};
},
computed: {},
watch: {},
created() {
this.id = this.$route.params.id; //操作ID
-
+ this.readbook();
this.getList(); //边角料
this.getpwpList(); //半成品
this.getequList(); //设备
@@ -752,11 +751,35 @@ export default {
checkPermission,
//作业指导书
+
+ getWordText() {
+ this.drawer=true;
+ const xhr = new XMLHttpRequest();
+
+ xhr.open("get", this.techdocList, true);
+
+ xhr.responseType = "arraybuffer";
+
+ xhr.onload = () => {
+ if (xhr.status == 200) {
+
+ mammoth.convertToHtml({ arrayBuffer: new Uint8Array(xhr.response) }).then((resultObject) => {
+ this.$nextTick(() => {
+
+ this.wordText = resultObject.value;
+
+ });
+ });
+ }
+ };
+ xhr.send();
+ },
readbook(){
- this.drawer=true;
+
gettechdocList({operation:this.id,page:0}).then((response) => {
if (response.data) {
- this.techdocList= response.data;
+ this.techdocList= response.data[0].file_.file;
+ console.log( this.techdocList);
}
});
},
diff --git a/hb_client/src/views/wpm/productjy.vue b/hb_client/src/views/wpm/productjy.vue
index 3719cb4..7878be1 100644
--- a/hb_client/src/views/wpm/productjy.vue
+++ b/hb_client/src/views/wpm/productjy.vue
@@ -12,9 +12,11 @@
highlight-current-row
max-height="600"
>
-
+
- {{ scope.row.material_.name }}
+ {{
+ scope.row.material_.name
+ }}
@@ -25,7 +27,7 @@
{{ actstate_[scope.row.act_state] }}
-
+
{{ scope.row.step_.name }}
@@ -33,14 +35,17 @@
检验
+ >检验
检验记录
+ >检验记录
@@ -58,9 +63,12 @@
批量入库
-
+ >批量入库
+
+ 批量选择订单
+
+
-
-
-
+
+
- {{ scope.row.material_.name }}
+ {{
+ scope.row.material_.name
+ }}
@@ -88,19 +95,32 @@
{{ actstate_[scope.row.act_state] }}
-
-
- {{ scope.row.step_.name }}
+
+
+ {{scope.row.to_order_.number }}
+
+
+
+ {{scope.row.to_order_.customer_.name }}
+
+
+
+
+ {{scope.row.to_order_.contract_.name }}
+
+
+
+
+
入库
-
+ >入库
+
@@ -115,8 +135,17 @@
-
-
+
+
-
+
@@ -187,18 +183,20 @@
/>
-
-
-
+
+
+
{{ scope.row.form_.name }}
- {{ checkTypes[scope.row.type] }}
+ {{
+ checkTypes[scope.row.type]
+ }}
@@ -211,17 +209,10 @@
检验
-
- 查看
-
- 删除
+ >检验
+ 查看
+ 删除
@@ -230,164 +221,11 @@
确 定
-
-
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/hb_server/apps/hrm/filters.py b/hb_server/apps/hrm/filters.py
new file mode 100644
index 0000000..40c9b45
--- /dev/null
+++ b/hb_server/apps/hrm/filters.py
@@ -0,0 +1,9 @@
+from django_filters import rest_framework as filters
+from apps.hrm.models import ClockRecord
+
+class ClockRecordFilterSet(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')
+ class Meta:
+ model = ClockRecord
+ fields = ['create_by', 'create_time_start', 'create_time_end']
\ No newline at end of file
diff --git a/hb_server/apps/hrm/migrations/0004_clockrecord.py b/hb_server/apps/hrm/migrations/0004_clockrecord.py
new file mode 100644
index 0000000..97ae889
--- /dev/null
+++ b/hb_server/apps/hrm/migrations/0004_clockrecord.py
@@ -0,0 +1,32 @@
+# Generated by Django 3.2.9 on 2022-01-21 06:45
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('hrm', '0003_employee_face_data'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='ClockRecord',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
+ ('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
+ ('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
+ ('type', models.PositiveSmallIntegerField(choices=[(10, '上班打卡')], default=10, verbose_name='打卡类型')),
+ ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='clockrecord_create_by', to=settings.AUTH_USER_MODEL, verbose_name='创建人')),
+ ('update_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='clockrecord_update_by', to=settings.AUTH_USER_MODEL, verbose_name='最后编辑人')),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/hb_server/apps/hrm/models.py b/hb_server/apps/hrm/models.py
index 5f95387..490237e 100644
--- a/hb_server/apps/hrm/models.py
+++ b/hb_server/apps/hrm/models.py
@@ -36,8 +36,12 @@ class Employee(CommonAModel):
def __str__(self):
return self.name
-# class Attendance(CommonADModel):
-# """
-# 出勤记录
-# """
-
\ No newline at end of file
+class ClockRecord(CommonADModel):
+ """
+ 打卡记录
+ """
+ ClOCK_WORK1 = 10
+ type_choice = (
+ (ClOCK_WORK1, '上班打卡'),
+ )
+ type = models.PositiveSmallIntegerField('打卡类型', choices=type_choice, default=ClOCK_WORK1)
\ No newline at end of file
diff --git a/hb_server/apps/hrm/serializers.py b/hb_server/apps/hrm/serializers.py
index 7a14400..31eb30d 100644
--- a/hb_server/apps/hrm/serializers.py
+++ b/hb_server/apps/hrm/serializers.py
@@ -1,25 +1,24 @@
from apps.system.models import User
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
-from .models import Employee
+from .models import ClockRecord, Employee
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()
+
+
+class FaceClockCreateSerializer(serializers.Serializer):
+ base64 = serializers.CharField()
+
+class ClockRecordListSerializer(serializers.ModelSerializer):
+ create_by_ = UserSimpleSerializer(source='create_by', read_only=True)
+ class Meta:
+ model = ClockRecord
+ fields = '__all__'
diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py
new file mode 100644
index 0000000..8cfb277
--- /dev/null
+++ b/hb_server/apps/hrm/services.py
@@ -0,0 +1,48 @@
+from django.conf import settings
+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:
+
+ @classmethod
+ def face_compare_from_base64(cls, base64_data):
+ filename = str(uuid.uuid4())
+ filepath = settings.BASE_DIR +'/temp/' + filename +'.png'
+ with open(filepath, 'wb') as f:
+ f.write(base64_data)
+ try:
+ unknown_picture = face_recognition.load_image_file(filepath)
+ unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
+ os.remove(filepath)
+ except:
+ os.remove(filepath)
+ return None, '头像解码失败'
+
+ # 匹配人脸库
+ 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_datas, unknown_face_encoding, tolerance=0.5)
+ for index, value in enumerate(results):
+ if value:
+ # 识别成功
+ user = User.objects.get(id=face_users[index])
+ return user, ''
+ 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
new file mode 100644
index 0000000..d5d5a9f
--- /dev/null
+++ b/hb_server/apps/hrm/tasks.py
@@ -0,0 +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 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/urls.py b/hb_server/apps/hrm/urls.py
index 293124c..55c2e55 100644
--- a/hb_server/apps/hrm/urls.py
+++ b/hb_server/apps/hrm/urls.py
@@ -1,11 +1,12 @@
from django.db.models import base
from rest_framework import urlpatterns
-from apps.hrm.views import EmployeeViewSet, FaceLogin
+from apps.hrm.views import ClockRecordViewSet, EmployeeViewSet, FaceLogin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register('employee', EmployeeViewSet, basename='employee')
+router.register('clock_record', ClockRecordViewSet, basename='clock_record')
urlpatterns = [
path('facelogin/', FaceLogin.as_view()),
path('', include(router.urls)),
diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py
index e4b7b3e..dafe59c 100644
--- a/hb_server/apps/hrm/views.py
+++ b/hb_server/apps/hrm/views.py
@@ -1,33 +1,27 @@
+from functools import update_wrapper
from django.shortcuts import render
+from django.utils import timezone
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet, GenericViewSet
-from rest_framework.mixins import UpdateModelMixin, RetrieveModelMixin
+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 Employee
-from apps.hrm.serializers import EmployeeSerializer, FaceLoginSerializer
-import face_recognition
-from django.conf import settings
-from django.core.cache import cache
-import logging
+from apps.hrm.models import ClockRecord, Employee
+from apps.hrm.serializers import ClockRecordListSerializer, EmployeeSerializer, FaceClockCreateSerializer, FaceLoginSerializer
+
+
+
from rest_framework.generics import CreateAPIView
from rest_framework import status
from rest_framework_simplejwt.tokens import RefreshToken
-
+from rest_framework import exceptions
from apps.system.models import User
-logger = logging.getLogger('log')
+from apps.system.serializers import UserSimpleSerializer
+from rest_framework.permissions import AllowAny
-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):
@@ -39,20 +33,74 @@ 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)
+ # 更新人脸缓存
+ update_all_user_facedata_cache.delay()
+ return Response()
+ return Response('头像识别失败', status=status.HTTP_400_BAD_REQUEST)
+ serializer.save(update_by=request.user)
+ return Response()
+
+
+class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet):
+ """
+ 打卡记录
+ """
+ perms_map = {'get':'*', 'post':'*'}
+ authentication_classes = []
+ permission_classes = [AllowAny]
+ queryset = ClockRecord.objects.select_related('create_by').all()
+ serializer_class = ClockRecordListSerializer
+ filterset_class = ClockRecordFilterSet
+ ordering = ['-pk']
+
+ def get_serializer_class(self):
+ if self.action == 'create':
+ return FaceClockCreateSerializer
+ return super().get_serializer_class()
+
+ def create(self, request, *args, **kwargs):
+ now = timezone.now()
+ now_local = timezone.localtime()
+ if 8<=now_local.hour<=17:
+ base64_data = base64.urlsafe_b64decode(tran64(
+ request.data.get('base64').replace(' ', '+')))
+ 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,
+ defaults={
+ 'type':ClockRecord.ClOCK_WORK1,
+ 'create_by':user,
+ 'create_time':now
+ })
+ if not created:
+ ins.create_time = now
+ ins.save()
+ # 设为在岗
+ user.is_atwork = True
+ user.save()
+ return Response(UserSimpleSerializer(instance=user).data)
+ return Response(msg, status=status.HTTP_400_BAD_REQUEST)
+ return Response('非打卡时间范围', status=status.HTTP_400_BAD_REQUEST)
+
+
+
+
-import uuid
import base64
-import os
def tran64(s):
missing_padding = len(s) % 4
@@ -70,41 +118,13 @@ class FaceLogin(CreateAPIView):
"""
人脸识别登录
"""
- # serializer = FaceLoginSerializer(data=request.data)
- # serializer.is_valid(raise_exception=True)
- filename = str(uuid.uuid4())
- filepath = settings.BASE_DIR +'/temp/' + filename +'.png'
- with open(filepath, 'wb') as f:
- data = tran64(request.data.get('base64').replace(' ', '+'))
- f.write(base64.urlsafe_b64decode(data))
- # picture_of_me = face_recognition.load_image_file(settings.BASE_DIR +'/temp/me.png')
- # my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
- #results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding, tolerance=0.2)
- try:
- unknown_picture = face_recognition.load_image_file(filepath)
- unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
- os.remove(filepath)
- except:
- os.remove(filepath)
- return Response('头像解码失败', status=status.HTTP_400_BAD_REQUEST)
-
- # 匹配人脸库
- 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'])
-
- results = face_recognition.compare_faces(face_l, unknown_face_encoding, tolerance=0.5)
- for index, value in enumerate(results):
- if value:
- # 识别成功
- user = User.objects.get(id=user_l[index])
- refresh = RefreshToken.for_user(user)
- return Response({
- 'refresh': str(refresh),
- 'access': str(refresh.access_token),
- 'username':user.username
- })
- return Response('未找到对应用户', status=status.HTTP_400_BAD_REQUEST)
\ No newline at end of file
+ base64_data = base64.urlsafe_b64decode(tran64(request.data.get('base64').replace(' ', '+')))
+ user, msg = HRMService.face_compare_from_base64(base64_data)
+ if user:
+ refresh = RefreshToken.for_user(user)
+ return Response({
+ 'refresh': str(refresh),
+ 'access': str(refresh.access_token),
+ 'username':user.username
+ })
+ return Response(msg, status=status.HTTP_400_BAD_REQUEST)
\ No newline at end of file
diff --git a/hb_server/apps/inm/serializers.py b/hb_server/apps/inm/serializers.py
index e983108..766a164 100644
--- a/hb_server/apps/inm/serializers.py
+++ b/hb_server/apps/inm/serializers.py
@@ -9,6 +9,7 @@ from apps.mtm.serializers import MaterialSimpleSerializer
from django.db import transaction
+
class WareHouseSerializer(serializers.ModelSerializer):
create_by_ = UserSimpleSerializer('create_by', read_only=True)
diff --git a/hb_server/apps/system/migrations/0004_user_is_atwork.py b/hb_server/apps/system/migrations/0004_user_is_atwork.py
new file mode 100644
index 0000000..b512387
--- /dev/null
+++ b/hb_server/apps/system/migrations/0004_user_is_atwork.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.9 on 2022-01-21 05:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('system', '0003_auto_20210812_0909'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='user',
+ name='is_atwork',
+ field=models.BooleanField(default=False, verbose_name='当前在岗'),
+ ),
+ ]
diff --git a/hb_server/apps/system/models.py b/hb_server/apps/system/models.py
index c773fcf..e77eae3 100644
--- a/hb_server/apps/system/models.py
+++ b/hb_server/apps/system/models.py
@@ -116,6 +116,7 @@ class User(AbstractUser):
superior = models.ForeignKey(
'self', null=True, blank=True, on_delete=models.SET_NULL, verbose_name='上级主管')
roles = models.ManyToManyField(Role, blank=True, verbose_name='角色')
+ is_atwork = models.BooleanField('当前在岗', default=False)
class Meta:
verbose_name = '用户信息'
diff --git a/hb_server/apps/system/serializers.py b/hb_server/apps/system/serializers.py
index 10636ea..8d644b3 100644
--- a/hb_server/apps/system/serializers.py
+++ b/hb_server/apps/system/serializers.py
@@ -141,7 +141,9 @@ class UserListSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['id', 'name', 'phone', 'email', 'position',
- 'username', 'is_active', 'date_joined', 'dept_name', 'dept', 'roles', 'avatar', 'roles_name']
+ 'username', 'is_active', 'date_joined',
+ 'dept_name', 'dept', 'roles', 'avatar',
+ 'roles_name', 'is_atwork']
@staticmethod
def setup_eager_loading(queryset):
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 # 启动时区设置