from django.http import JsonResponse from django.shortcuts import render from django.urls import reverse from application.hrm_mgnt.models import * from common.utils.page_helper import paginate_query_and_assign_numbers def pst_list_view(request): # 声明查询集 query_set = Position.objects.filter().order_by('-position_id') # 获取查询参数 position_name = request.GET.get('position_name', '') # 根据提供的参数进行筛选 if request.GET.get('position_name', ''): query_set = query_set.filter(position_name__icontains=request.GET.get('position_name', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&position_name={}' + format(position_name) # 准备上下文 context = { 'items': items, 'list_key': 'position_id', 'filters': [{"type": "text", "id": "position_name", "name": "position_name", "label": "岗位名称", "placeholder": "请输入岗位名称"}], 'form_action_url': 'pst_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "岗位表", "name": "pst_list"}], 'query_params': query_params, 'table_columns': [{"header": "岗位名称", "field": "position_name"}, {"header": "岗位描述", "field": "position_description"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/pst_list.html', context) def rk_list_view(request): # 声明查询集 query_set = Rank.objects.filter().order_by('-rank_id') # 获取查询参数 rank_name = request.GET.get('rank_name', '') # 根据提供的参数进行筛选 if request.GET.get('rank_name', ''): query_set = query_set.filter(rank_name__icontains=request.GET.get('rank_name', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&rank_name={}' + format(rank_name) # 准备上下文 context = { 'items': items, 'list_key': 'rank_id', 'filters': [{"type": "text", "id": "rank_name", "name": "rank_name", "label": "职级名称", "placeholder": "请输入职级名称"}], 'form_action_url': 'rk_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "职级表", "name": "rk_list"}], 'query_params': query_params, 'table_columns': [{"header": "职级名称", "field": "rank_name"}, {"header": "职级描述", "field": "rank_description"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/rk_list.html', context) 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 request.GET.get('employee', ''): query_set = query_set.filter(employee__icontains=request.GET.get('employee', '')) if request.GET.get('year_month', ''): query_set = query_set.filter(year_month__icontains=request.GET.get('year_month', '')) if request.GET.get('primary_department', ''): query_set = query_set.filter(primary_department__icontains=request.GET.get('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) # 准备上下文 context = { 'items': items, 'list_key': 'record_id', '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": "星海"}]}], 'form_action_url': 'attd_rec_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "员工考勤记录表", "name": "attd_rec_list"}], 'query_params': query_params, 'table_columns': [{"header": "员工", "field": "employee"}, {"header": "年月", "field": "year_month"}, {"header": "迟到", "field": "late"}, {"header": "早退", "field": "early_leave"}, {"header": "旷工", "field": "absenteeism"}, {"header": "年假", "field": "annual_leave"}, {"header": "事假", "field": "personal_leave"}, {"header": "病假", "field": "sick_leave"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/attd_rec_list.html', context) 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 request.GET.get('employee_name', ''): query_set = query_set.filter(employee_name__icontains=request.GET.get('employee_name', '')) if request.GET.get('year', ''): query_set = query_set.filter(year__icontains=request.GET.get('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) # 准备上下文 context = { 'items': items, 'list_key': 'record_id', '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"}]}], 'form_action_url': 'alv_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "年假使用记录", "name": "alv_list"}], 'query_params': query_params, 'table_columns': [{"header": "年份", "field": "year"}, {"header": "姓名", "field": "employee_name"}, {"header": "一级部门", "field": "primary_department"}, {"header": "年假天数", "field": "total_annual_leave"}, {"header": "已请年假数", "field": "used_annual_leave"}, {"header": "剩余年假数", "field": "remaining_annual_leave"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/alv_list.html', context) 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 request.GET.get('name', ''): query_set = query_set.filter(name=request.GET.get('name', '')) if request.GET.get('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) fields = { "name": {"id": "operation_name", "type": "text", "label": "姓名"}, "id_number": {"id": "operation_id_number", "type": "text", "label": "身份证号"}, "gender": {"id": "operation_gender", "type": "select", "label": "性别", "options": ["男", "女", "其他"]}, "birthday": {"id": "operation_birthday", "type": "date", "label": "生日"}, "age": {"id": "operation_age", "type": "number", "label": "年龄"}, "height": {"id": "operation_height", "type": "number", "label": "身高(cm)"}, "weight": {"id": "operation_weight", "type": "number", "label": "体重(kg)"}, "blood_type": {"id": "operation_blood_type", "type": "select", "label": "血型", "options": ["A", "B", "AB", "O", "其他"]}, "ethnicity": {"id": "operation_ethnicity", "type": "text", "label": "民族"}, "domicile": {"id": "operation_domicile", "type": "text", "label": "户籍地"}, "marital_status": {"id": "operation_marital_status", "type": "select", "label": "婚姻状态", "options": ["未婚", "已婚未育", "已婚已育", "离婚", "其他"]}, "political_affiliation": {"id": "operation_political_affiliation", "type": "select", "label": "政治面貌", "options": ["共产党员", "共青团员", "群众", "其他"]}, "entry_date": {"id": "operation_entry_date", "type": "date", "label": "入职时间"}, "regularization_date": {"id": "operation_regularization_date", "type": "date", "label": "转正日期"}, "departure_date": {"id": "operation_departure_date", "type": "date", "label": "离职时间"}, "employment_type": {"id": "operation_employment_type", "type": "select", "label": "用工性质", "options": ["全职", "兼职", "实习"]}, "status": {"id": "operation_status", "type": "select", "label": "状态", "options": ["在职", "离职"]}, "primary_department": {"id": "operation_primary_department", "type": "text", "label": "一级部门"}, "secondary_department": {"id": "operation_secondary_department", "type": "text", "label": "二级部门"}, "position": {"id": "operation_position", "type": "text", "label": "职务"}, "grade": {"id": "operation_grade", "type": "text", "label": "职级"}, "contract_end_date": {"id": "operation_contract_end_date", "type": "date", "label": "当前合同到期时间"}, "mobile_number": {"id": "operation_mobile_number", "type": "text", "label": "手机号"}, "email": {"id": "operation_email", "type": "email", "label": "邮箱"}, "mailing_address": {"id": "operation_mailing_address", "type": "text", "label": "通信地址"}, "emergency_contact": {"id": "operation_emergency_contact", "type": "text", "label": "紧急联系人"}, "relation_with_contact": {"id": "operation_relation_with_contact", "type": "text", "label": "与本人关系"}, "emergency_contact_phone": {"id": "operation_emergency_contact_phone", "type": "text", "label": "紧急联系人电话"}, "education": {"id": "operation_education", "type": "select", "label": "学历", "options": ["高中", "大专", "本科", "硕士研究生", "博士研究生", "其他"]}, "undergraduate_school": {"id": "operation_undergraduate_school", "type": "text", "label": "本科毕业院校"}, "graduate_school": {"id": "operation_graduate_school", "type": "text", "label": "研究生毕业院校"}, "major": {"id": "operation_major", "type": "text", "label": "专业"}, "technical_title": {"id": "operation_technical_title", "type": "text", "label": "技术职称"}, "base_salary": {"id": "operation_base_salary", "type": "number", "label": "基础工资"}, "salary_account_number": {"id": "operation_salary_account_number", "type": "text", "label": "工资卡号"}, "bank_of_salary_account": {"id": "operation_bank_of_salary_account", "type": "text", "label": "工资卡开户行"}, "resignation_type": {"id": "operation_resignation_type", "type": "select", "label": "离职类型", "options": ["合同期满", "主动辞职", "无条件辞职", "试用未通过", "辞退", "其他"]}, "resignation_reason": {"id": "operation_resignation_reason", "type": "textarea", "label": "离职原因"} } # 构建上下文 context = { "items": items, "list_key": "employee_id", "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": "星海"}]}], "form_action_url": "emp_list", "breadcrumb_list": [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "人员基本信息表", "name": "emt_list"}], "query_params": query_params, "table_columns": [{"header": "姓名", "field": "name"}, {"header": "身份证号", "field": "id_number"}, {"header": "性别", "field": "gender"}, {"header": "生日", "field": "birthday"}, {"header": "年龄", "field": "age"}, {"header": "身高(cm)", "field": "height"}, {"header": "体重(kg)", "field": "weight"}, {"header": "血型", "field": "blood_type"}, {"header": "民族", "field": "ethnicity"}, {"header": "户籍地", "field": "domicile"}, {"header": "婚姻状态", "field": "marital_status"}, {"header": "政治面貌", "field": "political_affiliation"}, {"header": "入职时间", "field": "entry_date"}, {"header": "转正日期", "field": "regularization_date"}, {"header": "离职时间", "field": "departure_date"}, {"header": "用工性质", "field": "employment_type"}, {"header": "状态", "field": "status"}, {"header": "一级部门", "field": "primary_department"}, {"header": "二级部门", "field": "secondary_department"}, {"header": "职务", "field": "position"}, {"header": "职级", "field": "grade"}, {"header": "当前合同到期时间", "field": "contract_end_date"}, {"header": "手机号", "field": "mobile_number"}, {"header": "邮箱", "field": "email"}, {"header": "通信地址", "field": "mailing_address"}, {"header": "紧急联系人", "field": "emergency_contact"}, {"header": "与本人关系", "field": "relation_with_contact"}, {"header": "紧急联系人电话", "field": "emergency_contact_phone"}, {"header": "学历", "field": "education"}, {"header": "本科毕业院校", "field": "undergraduate_school"}, {"header": "研究生毕业院校", "field": "graduate_school"}, {"header": "专业", "field": "major"}, {"header": "技术职称", "field": "technical_title"}, {"header": "基础工资", "field": "base_salary"}, {"header": "工资卡号", "field": "salary_account_number"}, {"header": "工资卡开户行", "field": "bank_of_salary_account"}, {"header": "离职类型", "field": "resignation_type"}, {"header": "离职原因", "field": "resignation_reason"}, {"header": "操作", "field": "actions"}], "show_modify_button": True, "show_add_button": True, "show_download_button": True, "show_upload_button": True, "modify_url": reverse("emp_list_modify"), "add_url": reverse("emp_list_add"), "delete_url": reverse("emp_list_delete"), "form_fields_config": {"fields": fields}, "excel_upload_config": { "template_url": reverse("download_excel_template", kwargs={"template_name": '人力资源管理-人员基本信息-Excel上传模板.xlsx', "fields": fields}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_map": { "name": "姓名", "id_number": "身份证号", "gender": "性别", "birthday": "生日", "age": "年龄", "height": "身高(cm)", "weight": "体重(kg)", "blood_type": "血型", "ethnicity": "民族", "domicile": "户籍地", "marital_status": "婚姻状态", "political_affiliation": "政治面貌", "entry_date": "入职时间", "regularization_date": "转正日期", "departure_date": "离职时间", "employment_type": "用工性质", "status": "状态", "primary_department": "一级部门", "secondary_department": "二级部门", "position": "职务", "grade": "职级", "contract_end_date": "当前合同到期时间", "mobile_number": "手机号", "email": "邮箱", "mailing_address": "通信地址", "emergency_contact": "紧急联系人", "relation_with_contact": "与本人关系", "emergency_contact_phone": "紧急联系人电话", "education": "学历", "undergraduate_school": "本科毕业院校", "graduate_school": "研究生毕业院校", "major": "专业", "technical_title": "技术职称", "base_salary": "基础工资", "salary_account_number": "工资卡号", "bank_of_salary_account": "工资卡开户行", "resignation_type": "离职类型", "resignation_reason": "离职原因" }, "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"}} } } 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)