From 367d9b31ddb2812688fcc366fb7cdb2c863439f9 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 10 Mar 2023 16:07:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=A1=E6=97=B6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0008_clockrecord_exception_type.py | 18 ++++++++++++++++++ apps/hrm/models.py | 7 +++++++ apps/hrm/services.py | 11 ++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 apps/hrm/migrations/0008_clockrecord_exception_type.py diff --git a/apps/hrm/migrations/0008_clockrecord_exception_type.py b/apps/hrm/migrations/0008_clockrecord_exception_type.py new file mode 100644 index 00000000..ba6d844b --- /dev/null +++ b/apps/hrm/migrations/0008_clockrecord_exception_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2023-03-10 07:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hrm', '0007_alter_employee_job_state'), + ] + + operations = [ + migrations.AddField( + model_name='clockrecord', + name='exception_type', + field=models.PositiveSmallIntegerField(blank=True, choices=[(10, '在岗时间短'), (20, '在岗时间长')], null=True, verbose_name='异常类型'), + ), + ] diff --git a/apps/hrm/models.py b/apps/hrm/models.py index 0b5e3e05..dd4ad618 100755 --- a/apps/hrm/models.py +++ b/apps/hrm/models.py @@ -83,10 +83,17 @@ class ClockRecord(BaseModel): (ClOCK_ON, '上班打卡'), (CLOCK_OFF, '下班打卡'), ) + E_TYPE_LESS = 10 + E_TYPE_MORE = 20 + E_TYPE_CHOISE = ( + (E_TYPE_LESS, '在岗时间短'), + (E_TYPE_MORE, '在岗时间长') + ) type = models.PositiveSmallIntegerField('打卡类型', choices=type_choice, default=ClOCK_ON) employee = models.ForeignKey(Employee, verbose_name='对应人员', on_delete=models.CASCADE) trigger = models.CharField('触发', max_length=20) detail = models.JSONField('相关记录', default=dict, null=False, blank=True) + exception_type = models.PositiveSmallIntegerField('异常类型', choices=E_TYPE_CHOISE, null=True, blank=True) class Certificate(CommonAModel): diff --git a/apps/hrm/services.py b/apps/hrm/services.py index af1259af..2f6a7455 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -332,6 +332,15 @@ class HrmService: ep.is_atwork = False ep.last_check_time = s_time_f ep.save() + # 判断是否有异常 + cr_e = ClockRecord.objects.filter(create_time__lte=cr_20.create_time).exclude(id=cr_20.id).order_by('-create_time').first() + time_d = cr_20.create_time - cr_e.create_time + if time_d < timedelta(hours=7): + cr_20.exception_type = ClockRecord.E_TYPE_LESS + cr_20.save() + elif time_d > timedelta(hours=14): + cr_20.exception_type = ClockRecord.E_TYPE_MORE + cr_20.save() # 进行相关方/访客项目更新 Visit.objects.filter(state=Visit.V_ENTER, visitors__employee__id_number=id_number).update( @@ -339,4 +348,4 @@ class HrmService: Rpj.objects.filter(state=Rpj.RPJ_ENTER, remployees__employee__id_number=id_number).update( state=Rpj.RPJ_WORKING) - # 此处可触发安全帽事件逻辑 + # 此处可触发安全帽事件逻辑 \ No newline at end of file