def favorite_func() -> str: """公司客户收藏夹页面""" company_id = get_platform_session_arg("user_id") if company_id is None: return redirect(url_for("web_blueprint.login_func")) else: company = Company.find_by_id(company_id) url_path = request.path # 当前web路径 if isinstance(company, Company): page_index = 1 # 页码 index = request.args.get("index", "1") # 第几页 try: page_index = int(index) except Exception as e: print(e) company_dbref = company.get_dbref() f = {"company_id": company_dbref} s = {"time": -1} p = ['_id', "resume_id"] r = ResumeFavorite.query_by_page(filter_dict=f, sort_dict=s, projection=p, page_index=page_index, page_size=10) ids = [x['resume_id'].id for x in r['data']] f = {"_id": {"$in": ids}} resumes = DriverResume.find_plus(filter_dict=f, sort_dict=s, to_dict=True) for x in resumes: """转期望待遇的数组为字符串,以方便前端展示,此函数已集成在DriverResume类中""" expected_salary = x.get("expected_salary") if isinstance(expected_salary, list): expected_salary = expected_salary[0:2] if len(expected_salary) == 1: expected_salary = "{}k".format( round(expected_salary[0] / 1000, 1)) else: expected_salary = "{}k至{}k".format( round(expected_salary[0] / 1000, 1), round(expected_salary[1] / 1000, 1)) else: expected_salary = "面议" x['expected_salary'] = expected_salary favorite_map = Company.in_favorite(company_id=company_id, drivers=ids, to_str=False) return render_template("web/favorite.html", resumes=resumes, total_record=r['total_record'], total_page=r['total_page'], pages=r['pages'], page_index=page_index, favorite_map=favorite_map, url_path=url_path) else: return redirect(url_for("web_blueprint.login_func"))
def company_resume_func(): """ 公司客户操作司机简历的处理函数,目前的功能是: 1. (公司客户)浏览司机简历. :return: """ company_id = get_platform_session_arg("user_id") resume_id = get_arg(request, "id", "") if isinstance(resume_id, str) and len(resume_id) == 24: resume_id = ObjectId(resume_id) if isinstance(company_id, ObjectId) and isinstance(resume_id, ObjectId): """查简历""" resume = DriverResume.find_by_id(resume_id, to_dict=True) if resume is None: return abort(404) else: """处理头像url""" head_image = resume.get("head_image") # 头像 if head_image is None: head_img_url = "" else: head_img_url = "/web/file/get/{}?fid={}".format( head_image.collection, head_image.id) """隐藏身份证后8位""" id_num = resume.get("id_num") if isinstance(id_num, str) and len(id_num) > 10: id_num = id_num[0:10] + "********" resume['id_num'] = id_num """处理学历""" resume['education'] = "" if (resume['education'] - 1) < 1 or (resume['education'] - 1) > 4 else \ ['小学', '中专', '大专', '本科'][resume['education'] - 1] """处理婚否""" married = {-1: "离异", 0: "未婚", 1: "已婚"}.get(resume['married']) resume['married'] = married if married else "" """处理状态""" status = {-1: "个体经营", 0: "离职", 1: "在职"}.get(resume.get('status')) resume['status'] = status if status else "" """查询工作经历""" work_history = resume.get("work_history") vehicle_type = "" # 常驾车型 if isinstance(work_history, list) and len(work_history) > 0: """有工作经历""" ids = [x.id for x in work_history] s = {"begin": -1} work_history = WorkHistory.find_plus( filter_dict={"_id": { "$in": ids }}, sort_dict=s, to_dict=True) for x in work_history: y = x.get("vehicle_type") x['begin'] = x['begin'].strftime("%F") if isinstance( x['begin'], datetime.datetime) else x['begin'] x['end'] = x['end'].strftime("%F") if isinstance( x['end'], datetime.datetime) else x['end'] if vehicle_type == "" and isinstance(y, str) and len(y) > 0: vehicle_type = y # 把第一个找到的车型当作常驾车型 resume['vehicle_type'] = vehicle_type break else: pass else: work_history = list() """取教育经历""" education_history = resume.get("education_history") if isinstance(education_history, list) and len(education_history) > 0: ids = [x.id for x in education_history] s = {"begin": -1} education_history = Education.find_plus( filter_dict={"_id": { "$in": ids }}, sort_dict=s, to_dict=True) for x in education_history: x['begin'] = x['begin'].strftime("%F") if isinstance( x['begin'], datetime.datetime) else x['begin'] x['end'] = x['end'].strftime("%F") if isinstance( x['end'], datetime.datetime) else x['end'] else: education_history = list() """取荣誉证书""" honor_history = resume.get("honor") if isinstance(honor_history, list) and len(honor_history) > 0: ids = [x.id for x in honor_history] s = {"time": -1} honor_history = Honor.find_plus( filter_dict={"_id": { "$in": ids }}, sort_dict=s, to_dict=True) for x in honor_history: x['time'] = x['time'].strftime("%F") if isinstance( x['time'], datetime.datetime) else x['time'] else: honor_history = list() """收藏映射""" favorite_map = Company.in_favorite(company_id=company_id, drivers=[resume['_id']], to_str=False) return render_template("web/resume.html", resume=resume, head_img_url=head_img_url, work_history=work_history, vehicle_type=vehicle_type, honor_history=honor_history, education_history=education_history, favorite_map=favorite_map) else: return redirect(url_for("web_blueprint.login_func"))
def driver_page_func(): """ 分页显示司机简历页面信息 :return: """ company_id = get_platform_session_arg("user_id") if isinstance(company_id, ObjectId): args = dict() # 传给DriverResume.query_by_page的参数字典 url_path = request.path # 当前web路径 q = dict() # 查询条件 keywords = request.args.get("keywords", "") # 搜索关键词 keywords = keywords.strip() if keywords == "": pass else: keywords = [ x.strip() for x in keywords.split(" ") if x.strip() != "" ] if len(keywords) == 0: pass else: """填充搜索条件,匹配其他表的字段先忽视,因为那需要一个检索服务器,比如elasticsearch""" or_list = list() """匹配简历的字段""" fields = ["living_place", "address", "email"] # 模糊匹配字段 for word in keywords: for field in fields: t = {field: {"$regex": Regex("\S*{}\S*".format(word))}} or_list.append(t) q['$or'] = or_list now = datetime.datetime.now() """从业年限""" i_exp = request.args.get("i_exp", "") if i_exp == "": pass else: try: i_exp = int(i_exp) except Exception as e: print(e) if isinstance(i_exp, int) and i_exp > 0: i_exp = now - datetime.timedelta(days=365 * i_exp) q['rtqc_first_date'] = {"$lte": i_exp} """工作经验""" work_exp = request.args.get("work_exp", "") if work_exp == "": pass else: try: work_exp = int(work_exp) except Exception as e: print(e) if isinstance(work_exp, int) and work_exp > 0: work_exp = now - datetime.timedelta(days=365 * work_exp) q['first_work_date'] = {"$lte": work_exp} """驾龄""" driving_exp = request.args.get("driving_exp", "") if driving_exp == "": pass else: try: driving_exp = int(driving_exp) except Exception as e: print(e) if isinstance(driving_exp, int) and driving_exp > 0: driving_exp = now + datetime.timedelta(days=365 * i_exp) q['dl_first_date'] = {"$lte": driving_exp} """发布时间""" update_date = request.args.get("update_date", "") times = [ 'today', 'three_day', 'week', 'month', 'three_month', 'half_year' ] if update_date in times: if update_date == "today": delta = datetime.timedelta(days=1) elif update_date == "three_day": delta = datetime.timedelta(days=3) elif update_date == "week": delta = datetime.timedelta(days=7) elif update_date == "month": """不精确,暂时这样""" delta = datetime.timedelta(days=30) elif update_date == "three_month": delta = datetime.timedelta(days=90) else: delta = datetime.timedelta(days=181) q['update_date'] = {"$gte": now - delta} """当前状态""" status = request.args.get("driver_status", "") if status == "": pass else: try: status = int(status) except Exception as e: print(e) status = 0 finally: q['status'] = status """驾照级别""" dl_license_class = request.args.get("dl_class", "") if dl_license_class == "": pass else: q['dl_license_class'] = dl_license_class.upper() """期望待遇""" expected_salary = request.args.get("salary", "") if isinstance(expected_salary, str) and expected_salary.find(",") != -1: salary = [int(x) for x in expected_salary.split(",")] min_s = salary[0] max_s = salary[-1] q['expected_salary'] = { "$elemMatch": { "$gte": min_s, "$lte": max_s } } """教育程度""" education = None education_str = request.args.get("education", "1") try: education = int(education_str) except Exception as e: print(e) finally: if isinstance(education, int): q['education'] = {"$gte": education} args['filter_dict'] = q # 添加搜索条件 s = {"update_date": -1} # 默认排序字典 args['sort_dict'] = s # 添加排序字典 projection = [ "_id", "education", "work_experience", "industry_experience", "driving_experience", "gender", "real_name", "age", "status", "dl_license_class", "dl_first_date", "rtqc_license_class", "rtqc_first_date", "want_job", "expected_salary", "birth_date", "last_company", "first_work_date", "update_date" ] args['projection'] = projection # 添加投影数组 """页码""" page_index = 1 index = request.args.get("index", "1") # 第几页 try: page_index = int(index) except Exception as e: print(e) finally: args['page_index'] = page_index r = DriverResume.query_by_page(**args) resumes = r['data'] favorite_map = Company.in_favorite(company_id=company_id, drivers=[x['_id'] for x in resumes], to_str=False) return render_template("web/drivers.html", url_path=url_path, resumes=resumes, total_record=r['total_record'], total_page=r['total_page'], pages=r['pages'], page_index=page_index, favorite_map=favorite_map) else: return redirect(url_for("web_blueprint.login_func"))