from django.http import JsonResponse from django.shortcuts import render, get_object_or_404, redirect from django.urls import reverse from application.hrm_mgnt.forms import EmployeeInformationForm from application.hrm_mgnt.models import * from common.utils.page_helper import paginate_query_and_assign_numbers def emp_list_view(request): # 声明查询集 query_set = EmployeeInformation.objects.filter().order_by('-employee_id') # 获取查询参数 name = request.GET.get('name', '') department = request.GET.get('department', '') # 根据提供的参数进行筛选 if name: query_set = query_set.filter(name__icontains=name) if department: query_set = query_set.filter(department=request.GET.get('department', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&name={}'.format(name) + '&department={}'.format(department) # Excel上传模板 template_name = "人力资源管理-人员基本信息-Excel上传模板.xlsx" # 构建上下文 context = { "model_config": "hrm_mgnt.EmployeeInformation", "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "人员基本信息表", "name": "emt_list"} ], "filters": [ { "type": "text", "id": "name", "name": "name", "label": "姓名", "placeholder": "请输入姓名" }, { "type": "select", "id": "department", "name": "department", "label": "一级部门", "options": [ {"value": "天信", "display": "天信"}, {"value": "混改", "display": "混改"}, {"value": "艾力芬特", "display": "艾力芬特"}, {"value": "星河", "display": "星河"}, {"value": "星海", "display": "星海"} ] } ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "name": {"type": "text", "width": "180px"}, "id_number": {"type": "text", "width": "220px"}, "gender": {"type": "text", "width": "100px"}, "birthday": {"type": "date", "width": "110px"}, "age": {"type": "text", "width": "80px"}, "height": {"type": "text", "width": "100px"}, "weight": {"type": "text", "width": "100px"}, "blood_type": {"type": "text", "width": "80px"}, "ethnicity": {"type": "text", "width": "180px"}, "domicile": {"type": "text", "width": "220px"}, "marital_status": {"type": "text", "width": "120px"}, "political_affiliation": {"type": "text", "width": "120px"}, "entry_date": {"type": "date", "width": "110px"}, "regularization_date": {"type": "date", "width": "110px"}, "departure_date": {"type": "date", "width": "110px"}, "employment_type": {"type": "text", "width": "100px"}, "status": {"type": "text", "width": "80px"}, "primary_department": {"type": "text", "width": "180px"}, "secondary_department": {"type": "text", "width": "180px"}, "position": {"type": "text", "width": "180px"}, "grade": {"type": "text", "width": "120px"}, "contract_end_date": {"type": "date", "width": "110px"}, "mobile_number": {"type": "text", "width": "150px"}, "email": {"type": "text", "width": "200px"}, "mailing_address": {"type": "text", "width": "280px"}, "emergency_contact": {"type": "text", "width": "150px"}, "relation_with_contact": {"type": "text", "width": "150px"}, "emergency_contact_phone": {"type": "text", "width": "150px"}, "education": {"type": "text", "width": "100px"}, "undergraduate_school": {"type": "text", "width": "220px"}, "graduate_school": {"type": "text", "width": "220px"}, "major": {"type": "text", "width": "220px"}, "technical_title": {"type": "text", "width": "180px"}, "base_salary": {"type": "text", "width": "120px"}, "salary_account_number": {"type": "text", "width": "220px"}, "bank_of_salary_account": {"type": "text", "width": "220px"}, "resignation_type": {"type": "text", "width": "120px"}, "resignation_reason": {"type": "textarea", "width": "300px"} } }, "query_params": query_params, "form_action_url": "emp_list", "modify_url": reverse("emp_list_modify"), "add_url": reverse("emp_list_add"), "delete_url": reverse("emp_list_delete"), } return render(request, 'hrm_mgnt/emp_list.html', context) def emp_list_add(request): if request.method == 'POST': data = { 'name': request.POST.get('name'), 'id_number': request.POST.get('id_number'), 'gender': request.POST.get('gender'), 'birthday': request.POST.get('birthday'), 'age': request.POST.get('age'), 'height': request.POST.get('height'), 'weight': request.POST.get('weight'), 'blood_type': request.POST.get('blood_type'), 'ethnicity': request.POST.get('ethnicity'), 'domicile': request.POST.get('domicile'), 'marital_status': request.POST.get('marital_status'), 'political_affiliation': request.POST.get('political_affiliation'), 'entry_date': request.POST.get('entry_date'), 'regularization_date': request.POST.get('regularization_date'), 'departure_date': request.POST.get('departure_date'), 'employment_type': request.POST.get('employment_type'), 'status': request.POST.get('status'), 'primary_department': request.POST.get('primary_department'), 'secondary_department': request.POST.get('secondary_department'), 'position': request.POST.get('position'), 'grade': request.POST.get('grade'), 'contract_end_date': request.POST.get('contract_end_date'), 'mobile_number': request.POST.get('mobile_number'), 'email': request.POST.get('email'), 'mailing_address': request.POST.get('mailing_address'), 'emergency_contact': request.POST.get('emergency_contact'), 'relation_with_contact': request.POST.get('relation_with_contact'), 'emergency_contact_phone': request.POST.get('emergency_contact_phone'), 'education': request.POST.get('education'), 'undergraduate_school': request.POST.get('undergraduate_school'), 'graduate_school': request.POST.get('graduate_school'), 'major': request.POST.get('major'), 'technical_title': request.POST.get('technical_title'), 'base_salary': request.POST.get('base_salary'), 'salary_account_number': request.POST.get('salary_account_number'), 'bank_of_salary_account': request.POST.get('bank_of_salary_account'), 'resignation_type': request.POST.get('resignation_type'), 'resignation_reason': request.POST.get('resignation_reason') } EmployeeInformation.objects.create(**data) return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def emp_list_modify(request): if request.method == 'POST': employee_id = request.POST.get('employee_id') data = { 'name': request.POST.get('name'), 'id_number': request.POST.get('id_number'), 'gender': request.POST.get('gender'), 'birthday': request.POST.get('birthday'), 'age': request.POST.get('age'), 'height': request.POST.get('height'), 'weight': request.POST.get('weight'), 'blood_type': request.POST.get('blood_type'), 'ethnicity': request.POST.get('ethnicity'), 'domicile': request.POST.get('domicile'), 'marital_status': request.POST.get('marital_status'), 'political_affiliation': request.POST.get('political_affiliation'), 'entry_date': request.POST.get('entry_date'), 'regularization_date': request.POST.get('regularization_date'), 'departure_date': request.POST.get('departure_date'), 'employment_type': request.POST.get('employment_type'), 'status': request.POST.get('status'), 'primary_department': request.POST.get('primary_department'), 'secondary_department': request.POST.get('secondary_department'), 'position': request.POST.get('position'), 'grade': request.POST.get('grade'), 'contract_end_date': request.POST.get('contract_end_date'), 'mobile_number': request.POST.get('mobile_number'), 'email': request.POST.get('email'), 'mailing_address': request.POST.get('mailing_address'), 'emergency_contact': request.POST.get('emergency_contact'), 'relation_with_contact': request.POST.get('relation_with_contact'), 'emergency_contact_phone': request.POST.get('emergency_contact_phone'), 'education': request.POST.get('education'), 'undergraduate_school': request.POST.get('undergraduate_school'), 'graduate_school': request.POST.get('graduate_school'), 'major': request.POST.get('major'), 'technical_title': request.POST.get('technical_title'), 'base_salary': request.POST.get('base_salary'), 'salary_account_number': request.POST.get('salary_account_number'), 'bank_of_salary_account': request.POST.get('bank_of_salary_account'), 'resignation_type': request.POST.get('resignation_type'), 'resignation_reason': request.POST.get('resignation_reason') } EmployeeInformation.objects.filter(employee_id=employee_id).update(**data) return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def emp_list_delete(request): if request.method == 'GET': employee_id = request.GET.get('employee_id') EmployeeInformation.objects.filter(employee_id=employee_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def employee_form_view(request, pk=None): if pk: employee = get_object_or_404(EmployeeInformation, pk=pk) form = EmployeeInformationForm(request.POST or None, instance=employee) form_title = '修改人员基本信息' else: form = EmployeeInformationForm(request.POST or None) form_title = '添加人员基本信息' if request.method == 'POST' and form.is_valid(): form.save() return redirect('employee_list') # 假设有一个员工列表视图 fields = [field.verbose_name for field in EmployeeInformation._meta.fields] return render(request, 'add_edit_modal.html', { 'form': form, 'form_title': form_title, 'fields': fields }) def attd_rec_list_view(request): # 声明查询集 query_set = EmployeeAttendanceRecord.objects.filter().order_by('-record_id') # 获取查询参数 employee = request.GET.get('employee', '') year_month = request.GET.get('year_month', '') primary_department = request.GET.get('primary_department', '') # 根据提供的参数进行筛选 if employee: query_set = query_set.filter(employee__name__icontains=employee) if year_month: query_set = query_set.filter(year_month__icontains=year_month) if primary_department: query_set = query_set.filter(employee__primary_department__icontains=primary_department) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&employee={}'.format(employee) + '&year_month={}'.format( year_month) + '&primary_department={}'.format(primary_department) fields = [ {"label": "记录ID", "field": "record_id", "id": "record_id_id", "type": "text", "is_show": 1, "is_add": 0}, {"label": "员工", "field": "employee_name", "id": "employee_name_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "年月", "field": "year_month", "id": "year_month_id", "type": "date", "is_show": 1, "is_add": 1}, {"label": "迟到", "field": "late", "id": "late_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "早退", "field": "early_leave", "id": "early_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "旷工", "field": "absenteeism", "id": "absenteeism_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "年假", "field": "annual_leave", "id": "annual_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "事假", "field": "personal_leave", "id": "personal_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "病假", "field": "sick_leave", "id": "sick_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "操作", "field": "actions", "id": "actions_id", "type": "actions", "is_show": 1, "is_add": 0} ] # 构建上下文 context = { "items": items, "id_name": "record_id", "query_params": query_params, "model_config": {"app_label": "hrm_mgnt", "model_name": "EmployeeAttendanceRecord", "html_name": "attd_rec_list"}, "breadcrumb_list": [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "员工考勤记录表", "name": "attd_rec_list"}], "filters": [ {"type": "text", "id": "employee", "name": "employee", "label": "员工", "placeholder": "请输入员工姓名"}, {"type": "month", "id": "year_month", "name": "year_month", "label": "年月"}, {"type": "select", "id": "primary_department", "name": "primary_department", "label": "一级部门", "options": [{"value": "天信", "display": "天信"}, {"value": "混改", "display": "混改"}, {"value": "艾力芬特", "display": "艾力芬特"}, {"value": "星河", "display": "星河"}, {"value": "星海", "display": "星海"}]} ], "table_columns": fields, "show_button": {"add": True, "modify": True, "download": True, "upload": True}, "url": { "modify": reverse("attd_rec_list_modify"), "add": reverse("attd_rec_list_add"), "delete": reverse("attd_rec_list_delete"), "download": reverse("download_excel_template", kwargs={"template_name": "人力资源管理-员工考勤记录表-Excel上传模板.xlsx", "fields": fields}), "parse": reverse("common_excel_parse"), "save": reverse("save_excel_table_data"), } } return render(request, 'hrm_mgnt/attd_rec_list.html', context) def attd_rec_list_add(request): if request.method == 'POST': data = { 'employee_id': request.POST.get('employee_id'), 'year_month': request.POST.get('year_month'), 'late': request.POST.get('late'), 'early_leave': request.POST.get('early_leave'), 'absenteeism': request.POST.get('absenteeism'), 'annual_leave': request.POST.get('annual_leave'), 'personal_leave': request.POST.get('personal_leave'), 'sick_leave': request.POST.get('sick_leave'), 'other_leave_details_id': request.POST.get('other_leave_details_id') } EmployeeAttendanceRecord.objects.create(**data) return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def attd_rec_list_modify(request): if request.method == 'POST': record_id = request.POST.get('record_id') data = { 'employee_id': request.POST.get('employee_id'), 'year_month': request.POST.get('year_month'), 'late': request.POST.get('late'), 'early_leave': request.POST.get('early_leave'), 'absenteeism': request.POST.get('absenteeism'), 'annual_leave': request.POST.get('annual_leave'), 'personal_leave': request.POST.get('personal_leave'), 'sick_leave': request.POST.get('sick_leave'), 'other_leave_details_id': request.POST.get('other_leave_details_id') } EmployeeAttendanceRecord.objects.filter(record_id=record_id).update(**data) return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def attd_rec_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') EmployeeAttendanceRecord.objects.filter(record_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def alv_list_view(request): # 声明查询集 query_set = AnnualLeaveRecord.objects.filter().order_by('-record_id') # 获取查询参数 employee_name = request.GET.get('employee_name', '') year = request.GET.get('year', '') # 根据提供的参数进行筛选 if employee_name: query_set = query_set.filter(employee_name__icontains=employee_name) if year: query_set = query_set.filter(year__icontains=year) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&employee_name={}'.format(employee_name) + '&year={}'.format(year) fields = [ {"label": "记录ID", "field": "detail_id", "id": "detail_id_id", "type": "text", "is_show": 1}, {"label": "年份", "field": "year", "id": "year_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "姓名", "field": "employee_name", "id": "employee_name_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "一级部门", "field": "primary_department", "id": "primary_department_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "年假天数", "field": "total_annual_leave", "id": "total_annual_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "已请年假数", "field": "used_annual_leave", "id": "used_annual_leave_id", "type": "number", "is_show": 1, "is_add": 1}, {"label": "剩余年假数", "field": "remaining_annual_leave", "id": "remaining_annual_leave_id", "type": "number", "is_show": 1, "is_add": 0}, {"label": "操作", "field": "actions", "id": "actions_id", "type": "actions", "is_show": 1, "is_add": 0} ] # 构建上下文 context = { "items": items, "id_name": "record_id", "query_params": query_params, "model_config": {"app_label": "hrm_mgnt", "model_name": "AnnualLeaveRecord", "html_name": "alv_list"}, "breadcrumb_list": [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "年假使用记录", "name": "alv_list"}], "filters": [ {"type": "text", "id": "employee_name", "name": "employee_name", "label": "姓名", "placeholder": "请输入姓名"}, {"type": "select", "id": "year", "name": "year", "label": "年度", "options": [{"value": "2024", "display": "2024"}, {"value": "2023", "display": "2023"}, {"value": "2022", "display": "2022"}, {"value": "2021", "display": "2021"}, {"value": "2020", "display": "2020"}]} ], "table_columns": fields, "show_button": {"add": True, "modify": True, "download": True, "upload": True}, "url": { "modify": reverse("alv_list_modify"), "add": reverse("alv_list_add"), "delete": reverse("alv_list_delete"), "download": reverse("download_excel_template", kwargs={"template_name": "人力资源管理-年假使用记录-Excel上传模板.xlsx", "fields": fields}), "parse": reverse("common_excel_parse"), "save": reverse("save_excel_table_data"), } } return render(request, 'hrm_mgnt/alv_list.html', context) def alv_list_add(request): if request.method == 'POST': data = { 'year': request.POST.get('year'), 'employee_name': request.POST.get('employee_name'), 'primary_department': request.POST.get('primary_department'), 'total_annual_leave': request.POST.get('total_annual_leave'), 'used_annual_leave': request.POST.get('used_annual_leave') } record = AnnualLeaveRecord(**data) record.clean() # 验证数据 record.save() return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def alv_list_modify(request): if request.method == 'POST': record_id = request.POST.get('record_id') data = { 'year': request.POST.get('year'), 'employee_name': request.POST.get('employee_name'), 'primary_department': request.POST.get('primary_department'), 'total_annual_leave': request.POST.get('total_annual_leave'), 'used_annual_leave': request.POST.get('used_annual_leave') } record = AnnualLeaveRecord.objects.get(record_id=record_id) for key, value in data.items(): setattr(record, key, value) record.clean() # 验证数据 record.save() return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def alv_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') AnnualLeaveRecord.objects.filter(record_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def rk_list_view(request): # 声明查询集 query_set = Rank.objects.filter().order_by('-rank_id') # 获取查询参数 rank_name = request.GET.get('rank_name', '') # 根据提供的参数进行筛选 if rank_name: query_set = query_set.filter(rank_name__icontains=rank_name) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&rank_name={}'.format(rank_name) fields = [ {"label": "职级ID", "field": "rank_id", "id": "rank_id_id", "type": "text", "is_show": 1, "is_add": 0}, {"label": "职级名称", "field": "rank_name", "id": "rank_name_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "职级描述", "field": "rank_description", "id": "rank_description_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "操作", "field": "actions", "id": "actions_id", "type": "actions", "is_show": 1, "is_add": 0} ] # 准备上下文 context = { 'items': items, 'id_name': 'rank_id', 'query_params': query_params, 'model_config': {"app_label": "hrm_mgnt", "model_name": "Rank", "html_name": "rk_list"}, 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "职级表", "name": "rk_list"}], 'filters': [{"type": "text", "id": "rank_name", "name": "rank_name", "label": "职级名称", "placeholder": "请输入职级名称"}], 'table_columns': fields, 'show_button': {"add": True, "modify": True, "download": True, "upload": True}, 'url': { "modify": reverse("rk_list_modify"), "add": reverse("rk_list_add"), "delete": reverse("rk_list_delete"), "download": reverse("download_excel_template", kwargs={"template_name": "人力资源管理-职级表-Excel上传模板.xlsx", "fields": fields}), "parse": reverse("common_excel_parse"), "save": reverse("save_excel_table_data"), } } return render(request, 'hrm_mgnt/rk_list.html', context) def rk_list_add(request): if request.method == 'POST': data = { 'rank_name': request.POST.get('rank_name'), 'rank_description': request.POST.get('rank_description'), } Rank.objects.create(**data) return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def rk_list_modify(request): if request.method == 'POST': rank_id = request.POST.get('rank_id') data = { 'rank_name': request.POST.get('rank_name'), 'rank_description': request.POST.get('rank_description'), } Rank.objects.filter(rank_id=rank_id).update(**data) return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def rk_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') Rank.objects.filter(rank_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def pst_list_view(request): # 声明查询集 query_set = Position.objects.filter().order_by('-position_id') # 获取查询参数 position_name = request.GET.get('position_name', '') # 根据提供的参数进行筛选 if position_name: query_set = query_set.filter(position_name__icontains=position_name) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&position_name={}'.format(position_name) fields = [ {"label": "职务ID", "field": "position_id", "id": "position_id_id", "type": "text", "is_show": 1, "is_add": 0}, {"label": "职务名称", "field": "position_name", "id": "position_name_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "职务描述", "field": "position_description", "id": "position_description_id", "type": "text", "is_show": 1, "is_add": 1}, {"label": "操作", "field": "actions", "id": "actions_id", "type": "actions", "is_show": 1, "is_add": 0} ] # 准备上下文 context = { 'items': items, 'id_name': 'position_id', 'query_params': query_params, 'model_config': {"app_label": "hrm_mgnt", "model_name": "Position", "html_name": "pst_list"}, 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "岗位表", "name": "pst_list"}], 'filters': [{"type": "text", "id": "position_name", "name": "position_name", "label": "岗位名称", "placeholder": "请输入岗位名称"}], 'table_columns': fields, 'show_button': {"add": True, "modify": True, "download": True, "upload": True}, 'url': { "modify": reverse("pst_list_modify"), "add": reverse("pst_list_add"), "delete": reverse("pst_list_delete"), "download": reverse("download_excel_template", kwargs={"template_name": "人力资源管理-岗位表-Excel上传模板.xlsx", "fields": fields}), "parse": reverse("common_excel_parse"), "save": reverse("save_excel_table_data"), } } return render(request, 'hrm_mgnt/pst_list.html', context) def pst_list_add(request): if request.method == 'POST': data = { 'position_name': request.POST.get('position_name'), 'position_description': request.POST.get('position_description'), } Position.objects.create(**data) return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def pst_list_modify(request): if request.method == 'POST': position_id = request.POST.get('position_id') data = { 'position_name': request.POST.get('position_name'), 'position_description': request.POST.get('position_description'), } Position.objects.filter(position_id=position_id).update(**data) return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def pst_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') Position.objects.filter(position_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405)