feat: employee导出并增加是否有定位卡的筛选

This commit is contained in:
caoqianming 2023-04-18 19:34:03 +08:00
parent 3410f5d968
commit aa84d50957
5 changed files with 56 additions and 4 deletions

View File

@ -26,7 +26,7 @@ class ClockRecordFilterSet(filters.FilterSet):
class EmployeeFilterSet(filters.FilterSet):
has_blt = filters.BooleanFilter(method='filter_has_blt')
class Meta:
model = Employee
fields = {
@ -36,6 +36,11 @@ class EmployeeFilterSet(filters.FilterSet):
'belong_dept':['exact']
}
def filter_has_blt(self, queryset, name, value):
if value:
return queryset.exclude(blt__isnull=True)
else:
return queryset.filter(blt=None)
class NotWorkRemarkFilterSet(filters.FilterSet):
year = filters.NumberFilter(method='filter_year')

View File

@ -143,9 +143,12 @@ class EmployeeSerializer(CustomModelSerializer):
read_only_fields = ['is_atwork', 'last_check_time', 'not_work_remark']
def get_blt_(self, obj):
if hasattr(obj, 'tdevice'):
if hasattr(obj, 'blt'):
from apps.third.serializers import TDeviceSimpleSerializer
return TDeviceSimpleSerializer(instance=obj.tdevice).data
return TDeviceSimpleSerializer(instance=obj.blt).data
# if hasattr(obj, 'tdevice'):
# from apps.third.serializers import TDeviceSimpleSerializer
# return TDeviceSimpleSerializer(instance=obj.tdevice).data
return

View File

@ -29,6 +29,7 @@ from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
epTypeOptions = {'employee': '正式员工', 'remployee': '相关方',
'visitor': '访客', 'driver': '货车司机'}
epStateOptions = {10: '在职', 20: '离职', 30: '退休'}
crOptions = {10: '上班打卡', 20: '下班打卡', 30: ''}
crEoptions = {10: '在岗时间短', 20: '在岗时间长', 30: '缺卡', 40: '加班'}
@ -214,6 +215,29 @@ class EmployeeViewSet(CustomModelViewSet):
_, res = dhClient.request(**dhapis['face_group_info'], params=params)
return Response(res)
@action(methods=['get'], detail=False, perms_map={'get': '*'},
serializer_class=serializers.Serializer)
def export_excel(self, request, pk=None):
"""导出excel
导出excel
"""
field_data = ['人员类型', '人员', '手机号', '身份证号', '所属部门', '在职状态', '定位卡号']
queryset = self.filter_queryset(self.get_queryset())
odata = EmployeeSerializer(queryset, many=True).data
# 处理数据
data = []
for i in odata:
data.append(
[epTypeOptions['type'],
i['name'],
i['phone'],
i['id_number'],
i.get('belong_dept_name', ''),
epStateOptions[i['job_state']],
i['blt_'].get('code', '') if 'blt_' in i else '']
)
return Response({'path': export_excel(field_data, data, '打卡记录')})
class ClockRecordViewSet(ListModelMixin, CustomGenericViewSet):
"""

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.12 on 2023-04-18 11:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('hrm', '0011_alter_certificate_number'),
('third', '0007_tdevice_mtask_uid'),
]
operations = [
migrations.AlterField(
model_name='tdevice',
name='employee',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='blt', to='hrm.employee', verbose_name='当前绑定人员'),
),
]

View File

@ -41,7 +41,7 @@ class TDevice(BaseModel):
related_name='tareas', blank=True)
obj_cate = models.CharField('绑定对象', max_length=20, help_text='people/...', null=True, blank=True)
employee = models.OneToOneField(Employee, verbose_name='当前绑定人员', on_delete=models.SET_NULL,
null=True, blank=True)
null=True, blank=True, related_name='blt')
is_clock = models.BooleanField('是否打卡设备', default=False)
access_list = models.JSONField('自动下发人员类型', default=list,
null=False, blank=True, help_text='employee/remployee/visitor/driver')