校正性别

This commit is contained in:
曹前明 2022-10-22 23:33:03 +08:00
parent 97710370b6
commit 08d1faf97e
3 changed files with 38 additions and 6 deletions

View File

@ -13,12 +13,14 @@ from apps.develop.tasks import backup_database, backup_media, reload_web_git, re
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from apps.ecm.service import check_not_in_place, create_remind, handle_xx_event, loc_change, notify_event, rail_in, snap_and_analyse from apps.ecm.service import check_not_in_place, create_remind, handle_xx_event, loc_change, notify_event, rail_in, snap_and_analyse
from apps.ecm.tasks import opl_task, update_count_people from apps.ecm.tasks import opl_task, update_count_people
from apps.hrm.models import Employee
from apps.opm.models import Opl from apps.opm.models import Opl
from apps.third.dahua import dhClient from apps.third.dahua import dhClient
from apps.third.speaker import spClient from apps.third.speaker import spClient
from apps.third.models import TDevice from apps.third.models import TDevice
from apps.utils.sms import send_sms from apps.utils.sms import send_sms
from apps.utils.speech import generate_voice from apps.utils.speech import generate_voice
from apps.utils.tools import get_info_from_id
from apps.utils.viewsets import CustomGenericViewSet from apps.utils.viewsets import CustomGenericViewSet
from apps.utils.wx import wxClient from apps.utils.wx import wxClient
@ -297,11 +299,6 @@ class TestViewSet(CustomGenericViewSet):
def correct_rail(self, request, pk=None): def correct_rail(self, request, pk=None):
pass pass
@action(methods=['post'], detail=False, serializer_class=Serializer)
def test_not_in_place(self, request, pk=None):
check_not_in_place(Opl.objects.get(id='1568880208688320512'))
return Response()
@action(methods=['post'], detail=False, serializer_class=SpeakerSerializer) @action(methods=['post'], detail=False, serializer_class=SpeakerSerializer)
def test_speaker(self, request, pk=None): def test_speaker(self, request, pk=None):
spClient.speak(path='/media/2022/09/11/349b3451-50b9-4501-aded-c85a76967920.mp3', sns=request.data['sns'], spClient.speak(path='/media/2022/09/11/349b3451-50b9-4501-aded-c85a76967920.mp3', sns=request.data['sns'],
@ -314,6 +311,16 @@ class TestViewSet(CustomGenericViewSet):
check_not_in_place(opl=Opl.objects.get(id=opl)) check_not_in_place(opl=Opl.objects.get(id=opl))
return Response() return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer)
def correct_gender(self, request, pk=None):
objs = Employee.objects.get_queryset(all=True).all()
for i in objs:
if i.id_number:
ret = get_info_from_id(i.id_number)
i.gender = ret['gender']
i.save()
return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer) @action(methods=['post'], detail=False, serializer_class=Serializer)
def send_wx_msg(self, request, pk=None): def send_wx_msg(self, request, pk=None):
"""微信模板消息发送测试 """微信模板消息发送测试

View File

@ -15,7 +15,7 @@ from apps.third.dahua import dhClient
from apps.third.tapis import dhapis from apps.third.tapis import dhapis
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from apps.utils.tools import check_id_number_e, check_phone_e from apps.utils.tools import check_id_number_e, check_phone_e, get_info_from_id
class EmployeeSimpleSerializer(CustomModelSerializer): class EmployeeSimpleSerializer(CustomModelSerializer):
@ -60,6 +60,9 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
return instance return instance
def update(self, instance, validated_data): def update(self, instance, validated_data):
id_number = validated_data['id_number']
ret = get_info_from_id(id_number)
validated_data['gender'] = ret['gender']
old_photo = instance.photo old_photo = instance.photo
old_job_state = instance.job_state old_job_state = instance.job_state
instance = super().update(instance, validated_data) instance = super().update(instance, validated_data)
@ -98,6 +101,17 @@ class EmployeeImproveSerializer(CustomModelSerializer):
class Meta: class Meta:
model = Employee model = Employee
fields = ['photo', 'id_number', 'email', 'gender', 'signature', 'photo_f', 'signature_f', 'phone'] fields = ['photo', 'id_number', 'email', 'gender', 'signature', 'photo_f', 'signature_f', 'phone']
extra_kwargs = {
'number': {'required': True},
'photo': {'required': True},
'id_number': {'required': True},
}
def update(self, instance, validated_data):
id_number = validated_data['id_number']
ret = get_info_from_id(id_number)
validated_data['gender'] = ret['gender']
return super().update(instance, validated_data)
class ChannelAuthoritySerializer(serializers.Serializer): class ChannelAuthoritySerializer(serializers.Serializer):

View File

@ -112,6 +112,17 @@ def check_id_number_e(val):
return val return val
def get_info_from_id(val):
birth = val[6:14]
birth_year = birth[0:4]
age = datetime.now().year - int(birth_year)
sex = int(val[-2])
gender = ''
if sex/2:
gender = ''
return dict(age=age, gender=gender)
def check_id_number(idcard): def check_id_number(idcard):
"""校验身份证号 """校验身份证号