门禁授权的bug修改
This commit is contained in:
parent
6eabca5314
commit
25cd71ad59
|
@ -80,9 +80,9 @@ class EventSerializer(serializers.ModelSerializer):
|
|||
employee_ = EmployeeSerializer(source='employee', read_only=True)
|
||||
vchannel_ = TDeviceSimpleSerializer(source='vchannel', read_only=True)
|
||||
handle_user_name = serializers.CharField(source='handle_user.name', read_only=True)
|
||||
face_img = MyFilePathField()
|
||||
global_img = MyFilePathField()
|
||||
voice = MyFilePathField()
|
||||
face_img_f = MyFilePathField(source='face_img', read_only=True)
|
||||
global_img_f = MyFilePathField(source='global_img', read_only=True)
|
||||
voice_f = MyFilePathField(source='voice', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from datetime import datetime, timedelta
|
||||
from apps.hrm.errors import PHONE_F_WRONG
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework import serializers
|
||||
|
@ -57,28 +58,43 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
|
|||
@transaction.atomic
|
||||
def create(self, validated_data):
|
||||
instance = super().create(validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
if settings.DAHUA_ENABLED and dhClient and instance.type == 'employee':
|
||||
# 如果是内部员工
|
||||
HrmService.sync_dahua_employee(ep=instance)
|
||||
return instance
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
old_photo = instance.photo
|
||||
old_job_state = instance.job_state
|
||||
instance = super().update(instance, validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo)
|
||||
if instance.job_state == 20 and instance.user: # 如果离职了关闭账户
|
||||
instance.user.is_active = False
|
||||
instance.user.save()
|
||||
# 同时去除门禁授权
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
if instance.type == 'employee':
|
||||
start_time = None
|
||||
end_time = None
|
||||
if instance.job_state == 20 and old_job_state == 10: # 离职
|
||||
now = datetime.now()
|
||||
start_time = now
|
||||
end_time = now + timedelta(minutes=60)
|
||||
elif instance.job_state == 10 and old_job_state == 20: # 重新在职
|
||||
now = datetime.now()
|
||||
start_time = now
|
||||
end_time = now + timedelta(days=7300)
|
||||
HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo,
|
||||
start_time=start_time, end_time=end_time)
|
||||
return instance
|
||||
|
||||
|
||||
class EmployeeImproveSerializer(CustomModelSerializer):
|
||||
photo = MyFilePathField()
|
||||
signature = MyFilePathField()
|
||||
photo_f = MyFilePathField(source='photo', read_only=True)
|
||||
signature_f = MyFilePathField(source='signature', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Employee
|
||||
fields = ['photo', 'id_number', 'email', 'gender', 'signature']
|
||||
fields = ['photo', 'id_number', 'email', 'gender', 'signature', 'photo_f', 'signature_f']
|
||||
|
||||
|
||||
class ChannelAuthoritySerializer(serializers.Serializer):
|
||||
|
@ -92,8 +108,8 @@ class EmployeeSerializer(CustomModelSerializer):
|
|||
belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
|
||||
post_name = serializers.CharField(source='post.name', read_only=True)
|
||||
blt_ = serializers.SerializerMethodField()
|
||||
photo = MyFilePathField()
|
||||
signature = MyFilePathField()
|
||||
photo_f = MyFilePathField(source='photo', read_only=True)
|
||||
signature_f = MyFilePathField(source='signature', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Employee
|
||||
|
@ -128,7 +144,7 @@ class NotWorkRemarkListSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class CertificateCreateUpdateSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
file_f = MyFilePathField(source='file', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Certificate
|
||||
|
@ -137,7 +153,7 @@ class CertificateCreateUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class CertificateSerializer(CustomModelSerializer):
|
||||
employee_name = serializers.CharField(source='employee.name', read_only=True)
|
||||
file = MyFilePathField()
|
||||
file_f = MyFilePathField(source='file', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Certificate
|
||||
|
|
|
@ -6,6 +6,7 @@ from apps.utils.tools import rannum, ranstr
|
|||
from datetime import datetime
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class HrmService:
|
||||
|
||||
@classmethod
|
||||
|
@ -127,7 +128,7 @@ class HrmService:
|
|||
cardId = res['id']
|
||||
cardNumber = str(ep.id)[3:8] + rannum(5)
|
||||
now = datetime.now()
|
||||
if start_time is None: # 如果未规定时间
|
||||
if start_time is None: # 如果未规定时间范围, 默认50年
|
||||
startDate = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
endDate = (datetime(year=now.year+50,
|
||||
month=now.month, day=1)).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
@ -203,7 +204,8 @@ class HrmService:
|
|||
# 如果是内部员工创建上班打卡记录(更新)
|
||||
if ep and ep.is_atwork is False:
|
||||
now = timezone.now()
|
||||
cr_10 = ClockRecord.objects.filter(type=10, employee=ep, create_time__year=now.year, create_time__month=now.month, create_time__day=now.day).first()
|
||||
cr_10 = ClockRecord.objects.filter(
|
||||
type=10, employee=ep, create_time__year=now.year, create_time__month=now.month, create_time__day=now.day).first()
|
||||
if cr_10:
|
||||
if now < cr_10.create_by:
|
||||
cr_10.create_by = now
|
||||
|
@ -228,7 +230,8 @@ class HrmService:
|
|||
# 如果是内部员工创建下班打卡记录(更新)
|
||||
if ep and ep.is_atwork:
|
||||
now = timezone.now()
|
||||
cr_20 = ClockRecord.objects.filter(type=20, employee=ep, create_time__year=now.year, create_time__month=now.month, create_time__day=now.day).first()
|
||||
cr_20 = ClockRecord.objects.filter(
|
||||
type=20, employee=ep, create_time__year=now.year, create_time__month=now.month, create_time__day=now.day).first()
|
||||
if cr_20:
|
||||
if now > cr_20.create_by:
|
||||
cr_20.create_by = now
|
||||
|
|
|
@ -125,7 +125,7 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class OplCertSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
file_f = MyFilePathField(source='file', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = OplCert
|
||||
|
|
|
@ -140,7 +140,7 @@ class RemployeeUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class RemployeeSerializer(CustomModelSerializer):
|
||||
rparty_name = serializers.CharField(source='rparty.name', read_only=True)
|
||||
photo = MyFilePathField()
|
||||
photo_f = MyFilePathField(source='photo', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Remployee
|
||||
|
@ -156,7 +156,7 @@ class RcertificateCreateUpdateSerializer(CustomModelSerializer):
|
|||
class RcertificateSerializer(CustomModelSerializer):
|
||||
remployee_name = serializers.CharField(source='remployee.name', read_only=True)
|
||||
rparty_name = serializers.CharField(source='rparty.name', read_only=True)
|
||||
file = MyFilePathField()
|
||||
file_f = MyFilePathField(source='file', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Rcertificate
|
||||
|
@ -240,11 +240,11 @@ class RpjmemberUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class RpjcertificateSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
file_f = MyFilePathField(source='file', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Rpjcertificate
|
||||
fields = ['rcertificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file']
|
||||
fields = ['rcertificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file', 'file_f']
|
||||
|
||||
|
||||
class RpjmemberSerializer(CustomModelSerializer):
|
||||
|
|
|
@ -39,6 +39,7 @@ class RpartyViewSet(CustomModelViewSet):
|
|||
分配账号
|
||||
"""
|
||||
obj = self.get_object()
|
||||
post = Post.objects.get(code='remployee')
|
||||
if obj.admin:
|
||||
ins = obj.admin
|
||||
else:
|
||||
|
@ -47,13 +48,18 @@ class RpartyViewSet(CustomModelViewSet):
|
|||
ins = serializer.save(type='remployee', password=make_password('0000'))
|
||||
obj.admin = ins
|
||||
obj.save()
|
||||
post = Post.objects.get(code='remployee')
|
||||
UserPost.objects.get_or_create(user=ins, dept=obj.dept,
|
||||
defaults={
|
||||
'user': ins,
|
||||
'dept': obj.dept,
|
||||
'post': post
|
||||
})
|
||||
up = UserPost.objects.filter(user=ins).order_by('sort', 'create_time').first()
|
||||
if up:
|
||||
ins.belong_dept = up.dept
|
||||
ins.post = up.post
|
||||
ins.update_by = self.request.user
|
||||
ins.save()
|
||||
return Response()
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib.auth.models import UserManager
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from apps.utils.models import CommonAModel, CommonBModel, BaseModel, SoftDeletableManagerMixin
|
||||
from apps.utils.models import CommonADModel, CommonAModel, CommonBModel, BaseModel, SoftDeletableManagerMixin
|
||||
|
||||
|
||||
class DataFilter(models.IntegerChoices):
|
||||
|
@ -60,7 +60,7 @@ class Dept(CommonAModel):
|
|||
return self.name
|
||||
|
||||
|
||||
class Role(CommonAModel):
|
||||
class Role(CommonADModel):
|
||||
"""
|
||||
角色
|
||||
"""
|
||||
|
|
|
@ -300,7 +300,7 @@ class UserListSerializer(CustomModelSerializer):
|
|||
"""
|
||||
belong_dept_ = DeptSimpleSerializer(source='belong_dept', read_only=True)
|
||||
# posts_ = PostSimpleSerializer(source='posts', many=True)
|
||||
avatar = MyFilePathField()
|
||||
avatar_f = MyFilePathField(source='avatar', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
|
|
@ -409,7 +409,7 @@ class UserViewSet(CustomModelViewSet):
|
|||
search_fields = ['username', 'name', 'phone', 'email']
|
||||
select_related_fields = ['superior', 'belong_dept']
|
||||
prefetch_related_fields = ['posts', 'roles', 'depts']
|
||||
ordering = ['type']
|
||||
ordering = ['type', 'create_time']
|
||||
|
||||
# def filter_queryset(self, queryset):
|
||||
# if not self.detail:
|
||||
|
|
|
@ -204,7 +204,7 @@ class TDeviceViewSet(ListModelMixin, UpdateModelMixin, DestroyModelMixin, Custom
|
|||
json = {
|
||||
"pageNum": 1,
|
||||
"pageSize": 1000,
|
||||
'channelTypeList': ["1"],
|
||||
'unitTypeList': ["1"],
|
||||
'includeSubOwnerCodeFlag': True
|
||||
}
|
||||
_, res = dhClient.request(**dhapis['channel_list'], json=json)
|
||||
|
@ -230,7 +230,7 @@ class TDeviceViewSet(ListModelMixin, UpdateModelMixin, DestroyModelMixin, Custom
|
|||
json = {
|
||||
"pageNum": 1,
|
||||
"pageSize": 1000,
|
||||
'channelTypeList': ["7"],
|
||||
'unitTypeList': ["7"],
|
||||
'includeSubOwnerCodeFlag': True
|
||||
}
|
||||
_, res = dhClient.request(**dhapis['channel_list'], json=json)
|
||||
|
@ -240,8 +240,9 @@ class TDeviceViewSet(ListModelMixin, UpdateModelMixin, DestroyModelMixin, Custom
|
|||
if td:
|
||||
pass
|
||||
else:
|
||||
td = TDevice(code=i['channelCode'], type=TDevice.DEVICE_VCHANNEL)
|
||||
td = TDevice(code=i['channelCode'], type=TDevice.DEVICE_DCHANNEL)
|
||||
td.name = i['channelName']
|
||||
# td.access_list = ['employee', 'remployee', 'visitor']
|
||||
td.save()
|
||||
return Response()
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class VisitorCreateSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class VisitorSerializer(CustomModelSerializer):
|
||||
photo = MyFilePathField()
|
||||
photo_f = MyFilePathField(source='photo', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Visitor
|
||||
|
|
|
@ -167,9 +167,9 @@ class WfService(object):
|
|||
elif destination_participant_type == State.PARTICIPANT_TYPE_POST: # 岗位
|
||||
user_queryset = User.objects.filter(posts__in=destination_participant)
|
||||
# 如果选择了岗位, 可能需要走过滤策略
|
||||
if state.filter_dept:
|
||||
if not new_ticket_data.get(state.filter_dept, None):
|
||||
raise ParseError('部门过滤字段错误')
|
||||
if state.filter_dept not in [0, '0', None]:
|
||||
# if not new_ticket_data.get(state.filter_dept, None):
|
||||
# raise ParseError('部门过滤字段错误')
|
||||
dpts = Dept.objects.filter(id=new_ticket_data[state.filter_dept])
|
||||
user_queryset = user_queryset.filter(depts__in=dpts)
|
||||
# if state.filter_policy == 1:
|
||||
|
@ -185,9 +185,9 @@ class WfService(object):
|
|||
elif destination_participant_type == State.PARTICIPANT_TYPE_ROLE: # 角色
|
||||
user_queryset = User.objects.filter(roles__in=destination_participant)
|
||||
# 如果选择了角色, 需要走过滤策略
|
||||
if state.filter_dept:
|
||||
if not new_ticket_data.get(state.filter_dept, None):
|
||||
raise ParseError('部门过滤字段错误')
|
||||
if state.filter_dept not in [0, '0', None]:
|
||||
# if not new_ticket_data.get(state.filter_dept, None):
|
||||
# raise ParseError('部门过滤字段错误')
|
||||
dpts = Dept.objects.filter(id=new_ticket_data[state.filter_dept])
|
||||
user_queryset = user_queryset.filter(depts__in=dpts)
|
||||
# if state.filter_policy == 1:
|
||||
|
|
Loading…
Reference in New Issue