def get_job_type(self, obj): job_type_code = obj.job_type if job_type_code: code_name = CacheCode().filter(dtype='job', code=job_type_code).first() if not code_name: return '未知' return code_name.name return '未知'
def salaryhidden(salary): logger.debug('需要隐私化的薪资为:{}'.format(salary)) expectsalary = CacheCode().filter(dtype='expectsalary').all() for i in expectsalary: if int(i.key_name.split('-')[0]) <= salary and int( i.key_name.split('-')[1]) >= salary: return i.name return '50k以上'
def get_learn_certificate(self, obj): learn_certificate_code = obj.learn_certificate if learn_certificate_code: code_name = CacheCode().filter(dtype='education', code=learn_certificate_code).first() if not code_name: return learn_certificate_code return code_name.name return '未知'
def search_criteria(request): if request.method == 'GET': codes = CacheCode().filter(status='1').all() logger.info('获取codes对应码') redis_codes = cache.get('codes') if not redis_codes: logger.info('从redis中读取codes信息失败,需要添加缓存信息') else: logger.info('从redis中读取codes信息成功,直接返回数据') # 准备给前端返回的数据信息 return JsonResponse({ 'status': 200, 'msg': '已找到字典数据', 'data': redis_codes }) # 设置全量数据列表 all_list = [] # 设置key种类列表 list = [] logger.info('开始从SQL中读取codes表,马上开始整理') # 设置字典信息的key值 for k, i in enumerate(codes): if i.dtype not in list: list.append(i.dtype) all_list.append({'dtype': i.dtype, 'sublist': []}) for k, i in enumerate(codes): for num, det in enumerate(all_list): if i.dtype == det['dtype']: if not i.name == '未知': det['sublist'].append({'name': i.name, 'code': i.code}) logger.info('codes表整理完成') if not redis_codes: logger.info('确定redis中没有codes码,开始将SQL中整理好的codes码载入redis') cache.set('codes', all_list) logger.info('设定当前codes码永不过期') cache.persist('codes') # 准备给前端返回的数据信息 response_data = {'status': 200, 'msg': '已找到字典数据', 'data': all_list} logger.info('字典信息已返回') return JsonResponse(response_data)
def search_resume_job(uid, search_job): ''' search_resume_job :param search_job 职位 :return resume_list 一个数据库列表对象 ''' # 首先根据用户的查询条件去缓存中获取历史搜索数据 resume_list = cache.get('search:uid_{}:job_search:{}'.format( uid, search_job)) logger.info('缓存中search:uid_{}:job_search:{}的数据为:{}'.format( uid, search_job, resume_list)) if not resume_list: logger.info( '缓存中没有找到search_job_search_{}的数据,正在按照搜索条件进行设置'.format(search_job)) q1 = Q() # 定义好一个Q对象来做高级搜索条件 q2 = Q() # 定义一个code码的查询对象 q1.children.append(('dtype', 'job')) # dtype状态为job q1.children.append(('name__icontains', search_job)) # name包含用户搜索数据 logger.info('code的查询条件:{}'.format(q1)) codes = CacheCode().filter(q1).all() if not codes: logger.info('没有符合要求的code码,错误的搜索条件,直接返回无数据,不设置redis') return None for i in codes: q2.connector = 'OR' q2.children.append(('job_type', i.code)) logger.info('code的查询码:{}'.format(q2)) # 根据返回的简历id去查询出所有简历的对应数据,并分页 resume_list = HrResumeBase.objects.filter(status='1').filter(~Q( up_user_id=uid)).filter(q2).all().order_by('-opt_time') # print(resume_list.query) if not resume_list: logger.info('按照con的搜索条件没有查询到符合要求的数据,设置redis缓存失败') # 准备给前端返回的数据信息 return None else: logger.info('缓存数据设置中') cache.set('search:job_search:{}'.format(search_job), resume_list, RESUME_CACHE_TIME) # 设置缓存数据,并将缓存数据设置1小时 return resume_list else: return resume_list
def XLS_update(request): if request.method == 'GET': try: s = request.session['s'] logger.info(s) except: s = {'msg': '请上传需要解析的数据'} return render(request, 'xsl_update.html', s) if request.method == 'POST': f = request.FILES.get('file_xls') excel_type = f.name.split('.')[-1] if excel_type in ['xlsx', 'xls']: # 开始解析上传的excel表格 wb = xlrd.open_workbook(filename=None, file_contents=f.read()) table = wb.sheets()[0] rows = table.nrows # 总行数 dic = { 'resume_phone': None, 'school': None, 'education_info': None, 'is_job': None, 'company_info': None, 'real_score': None, 'hands_on': None, 'expect_salary': None, } try: with transaction.atomic(): # 控制数据库事务交易 for i, v in enumerate(table.row_values(0)): if '姓名' in v: dic['name'] = i if '联系方式' in v: dic['resume_phone'] = i if '职位' in v: dic['job_type'] = i if '学校' in v: dic['school'] = i if '在职状态' in v: dic['is_job'] = i if '上一家公司规模' in v: dic['company_info'] = i if '推荐评分' in v: dic['real_score'] = i if '平均换工作率' in v: dic['hands_on'] = i if '最低期望薪资' in v: dic['expect_salary'] = i if '工作年限(年)' in v: dic['work_process'] = i success = 0 error = [] for i in range(1, rows): rowVlaues = table.row_values(i) phone = rowVlaues[dic['resume_phone']] if phone is None or phone is '': error.append('{}:这条数据缺少手机号'.format( rowVlaues[dic['name']])) continue phone = str(int(phone)) obj = HrResumeBase.objects.filter( phone=str(phone)).first() if not obj: error.append('{}:在数据库中没有找到对应的手机号{}'.format( rowVlaues[dic['name']], str(phone))) continue resume_id = obj.id company_info = str(int( rowVlaues[dic['company_info']])) + '人以上企业经验' is_job = rowVlaues[dic['is_job']] if '离职' in is_job: is_job = '离职' elif '在职' in is_job: is_job = '在职' create_time = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') real_score = str(int(rowVlaues[dic['real_score']])) hands_on = '平均换工作率{}年'.format( str(int(rowVlaues[dic['hands_on']]))) school = rowVlaues[dic['school']] job_type = rowVlaues[dic['job_type']] code = CacheCode().filter(dtype='job').filter( key_name__contains=job_type).values( 'code').first() if not code: code = None else: code = code['code'] work_process = str(int(rowVlaues[dic['work_process']])) expect_salary = int(rowVlaues[dic['expect_salary']]) if expect_salary < 1000: expect_salary = int(str(expect_salary) + '000') return_obj = HrResumeAuth.objects.update_or_create( pk_id=resume_id, id=str(uuid.uuid1().hex), company_info=company_info, is_job=is_job, create_time=create_time, create_psn='XSL', real_score=real_score, hands_on=hands_on, star_level='4') logger.info( '简历id:{},手机号:{},学校:{},上一家公司规模:{},推荐评分:{},平均换工作率:{},数据库更新结果:{}' .format(resume_id, phone, school, company_info, real_score, hands_on, return_obj)) if return_obj[1]: success = success + 1 obj.school = school obj.work_process = work_process obj.job_status = is_job obj.expect_salary = expect_salary obj.job_type = code obj.save() msg = '服务器解析完成' sc = 'display:block;' date = '表格数据:{}条,'.format(rows - 1) date_success = success date_error = rows - 1 - success s = { 'msg': msg, 'sc': sc, 'date': date, 'date_success': date_success, 'date_error': date_error, 'error': error } request.session['s'] = s except: msg = '解析excel文件失败,请检查数据是否完整' sc = None date = None date_success = None date_error = None error = None logger.error('上传文件类型错误!') s = { 'msg': msg, 'sc': sc, 'date': date, 'date_success': date_success, 'date_error': date_error, 'error': error } request.session['s'] = s logger.error('解析excel文件或者数据插入错误') else: msg = '解析excel文件失败,请检查数据是否完整' sc = None date = None date_success = None date_error = None logger.error('上传文件类型错误!') s = { 'msg': msg, 'sc': sc, 'date': date, 'date_success': date_success, 'date_error': date_error } request.session['s'] = s return redirect('system:XLS_update')
def search_resume_condition_query(**kwargs): ''' search_resume_condition_query :param job 职位 :param education 学历 :param work_process 工作经验 :param expectsalary 期望薪资 :paramisjob 是否在职 :parameducation_way 学校性质 :paramschool_type 学校等级 :payrange_start 薪资范围搜索,起始范围 :payrange_end 薪资范围搜索,结束范围 :return resume_list 一个数据库列表对象 ''' # 将调用方法的参数进行下输出,好记录错误 for k, v in kwargs.items(): logger.info('search_resume_condition_query-->{}:{}'.format(k, v)) resume_list = cache.get( 'search:uid_{}:resume_search:job_{}:education_{}:workprocess_{}:expectsalary_{}:isjob_{}:educationway_{}:schooltype_{}:' 'payrangestart_{}:payrangeend_{}'.format( kwargs['uid'], kwargs['job'], kwargs['education'], kwargs['work_process'], kwargs['expectsalary'], kwargs['isjob'], kwargs['education_way'], kwargs['school_type'], kwargs['payrange_start'], kwargs['payrange_end'])) logger.info( '缓存中search:uid_{}:resume_search:job_{}:education_{}:workprocess_{}:expectsalary_{}:isjob_{}:educationway_{}:' 'schooltype_{}:payrangestart_{}:payrangeend_{}'.format( kwargs['uid'], kwargs['job'], kwargs['education'], kwargs['work_process'], kwargs['expectsalary'], kwargs['isjob'], kwargs['education_way'], kwargs['school_type'], kwargs['payrange_start'], kwargs['payrange_end'], resume_list)) if not resume_list: logger.info('没有找到缓存数据,开始数据库条件搜索') q1 = Q() # 定义好一个Q对象来做高级搜索条件 q2 = Q() con = Q() q1.children.append(('status', '1')) # 简历状态为1是活动简历 # 判断用户是否带了uid if kwargs['uid']: q2.children.append(('up_user_id', kwargs['uid'])) # 判断用户是否带了job的搜索条件 if kwargs['job']: q1.children.append(('job_type', kwargs['job'])) # 判断用户是否带了education的搜索条件 if kwargs['education']: q1.children.append(('learn_certificate', kwargs['education'])) # 判断用户是否带了isjob的code码 if kwargs['isjob']: name = CacheCode().filter( code=kwargs['isjob'], dtype='isjob').values_list('name').first() q1.children.append(('job_status', name[0])) # 判断用户是否带了education_way的code码 if kwargs['education_way']: q1.children.append(('school_nature', kwargs['education_way'])) # 判断用户是否带了school_type的code码 if kwargs['school_type']: q1.children.append(('school_level', kwargs['school_type'])) # 判断用户是否带了workprocess的搜索条件,如果有workprocess的搜索条件,对一些code码进行处理 if kwargs['work_process']: name = CacheCode().filter( code=kwargs['work_process'], dtype='workprocess').values_list('name').first() logger.info('打印当前workprocess的code码信息--------->{}'.format(name)) if '应届生' in name: q1.children.append(('work_process', '0')) elif '1年以内' in name: q1.children.append(('work_process__gt', '0')) q1.children.append(('work_process__lte', '1')) elif '1-3年' in name: q1.children.append(('work_process__gte', '1')) q1.children.append(('work_process__lt', '3')) elif '3-5年' in name: q1.children.append(('work_process__gte', '3')) q1.children.append(('work_process__lt', '5')) elif '5年及以上' in name: q1.children.append(('work_process__gte', '5')) # 判断用户是否带了expectsalary的搜索条件,如果有expectsalary的搜索条件,对一些code码进行处理 if kwargs['expectsalary']: name = CacheCode().filter( code=kwargs['expectsalary'], dtype='expectsalary').values_list('name').first() logger.info('打印当前expectsalary的code码信息--------->{}'.format(name)) if '5k-10k' in name: q1.children.append(('expect_salary__gte', '5000')) q1.children.append(('expect_salary__lt', '10000')) elif '10k-15k' in name: q1.children.append(('expect_salary__gte', '10000')) q1.children.append(('expect_salary__lt', '15000')) elif '15k-20k' in name: q1.children.append(('expect_salary__gte', '15000')) q1.children.append(('expect_salary__lt', '20000')) elif '20k-25k' in name: q1.children.append(('expect_salary__gte', '20000')) q1.children.append(('expect_salary__lt', '25000')) elif '25k-30k' in name: q1.children.append(('expect_salary__gte', '25000')) q1.children.append(('expect_salary__lt', '30000')) elif '30k-40k' in name: q1.children.append(('expect_salary__gte', '30000')) q1.children.append(('expect_salary__lt', '40000')) elif '40k-50k' in name: q1.children.append(('expect_salary__gte', '40000')) q1.children.append(('expect_salary__lt', '50000')) else: if kwargs['payrange_start'] and kwargs['payrange_end']: q1.children.append( ('expect_salary__gte', kwargs['payrange_start'])) q1.children.append( ('expect_salary__lte', kwargs['payrange_end'])) elif not (kwargs['payrange_start']) and kwargs['payrange_end']: q1.children.append(('expect_salary__gte', 0)) q1.children.append( ('expect_salary__lte', kwargs['payrange_end'])) elif kwargs['payrange_start'] and not (kwargs['payrange_end']): q1.children.append( ('expect_salary__gte', kwargs['payrange_start'])) q1.children.append(('expect_salary__lte', 99999999)) con.add(q1, 'AND') con.add(q2, 'AND NOT') logger.info('打印搜索条件:{}'.format(con)) resume_list = HrResumeBase.objects.filter(con).order_by('-opt_time') # print(resume_list.query) # logging.info('需要检查的sql语句为:{}'.format(resume_list.query)) if resume_list: logger.info('数据库值搜索成功,共找到{}条数据,并将数据设置到redis中'.format( resume_list.__len__())) cache.set( 'search:uid_{}:resume_search:job_{}:education_{}:workprocess_{}:expectsalary_{}:isjob_{}:educationway_{}:schooltype_{}:' 'payrangestart_{}:payrangeend_{}'.format( kwargs['uid'], kwargs['job'], kwargs['education'], kwargs['work_process'], kwargs['expectsalary'], kwargs['isjob'], kwargs['education_way'], kwargs['school_type'], kwargs['payrange_start'], kwargs['payrange_end']), resume_list, RESUME_CACHE_TIME) return resume_list else: return None else: return resume_list
def get_school_nature(self, obj): school_nature_code = obj.school_nature if school_nature_code: code_obj = CacheCode().filter(dtype='education_way', code=school_nature_code).first() return code_obj.name return ''
def user_collect(uid, search_criteria): ''' user_collect :param uid 用户的uid :param search_criteria 用户的搜索条件 :return resume_list 一个数据库列表对象 ''' # 根据用户UUID以及收藏collect标识来获取当前用户的所有搜藏简历,并返回简历id # user_collects = HrUserResumeRelation.objects.filter(uid=uid, type='collect').values_list('resume_id').order_by( # '-create_time') # logger.info('查询到该用户的的搜藏数量:{}'.format(user_collects.__len__())) # 从redis中获取推荐列表失败,开始重建redis缓存 # base_list_obj = HrResumeBase.objects.all().extra( # tables=['hr_user_resume_relation'], # where=['hr_user_resume_relation.uid="{}"'.format(uid),'hr_user_resume_relation.resume_id = hr_resume_base.id', 'hr_user_resume_relation.type="collect"'], # select={'collect_time': 'hr_user_resume_relation.create_time'} # ).order_by('-collect_time') # # print(base_list_obj.query) # 判断是否查到了数据,如果没有数据证明该用户没有收藏信息 # if not user_collects: # return None # q2 = Q() q3 = Q() con = Q() if search_criteria: q1 = Q() # 定义好一个Q对象来做高级搜索条件 q1.children.append(('dtype', 'job')) # dtype状态为job q1.children.append( ('name__icontains', search_criteria)) # name包含用户搜索数据 logger.info('q1的查询条件:{}'.format(q1)) codes = CacheCode().filter(q1).all() logger.info('q1的查询结果为:{}'.format(codes.__len__())) if codes.__len__() > 0: for i in codes: q3.connector = 'OR' q3.children.append(('job_type', i.code)) else: return None # q2.children.append(('id__in', user_collects)) # q2.children.append(('status', '1')) con.add(q3, 'AND') # con.add(q2, 'AND') logger.info('con的查询条件为:{}'.format(con)) # 根据返回的简历id去查询出所有简历的对应数据,并分页 resume_list = HrResumeBase.objects.filter(status='1').filter(con).extra( tables=['hr_user_resume_relation'], where=[ 'hr_user_resume_relation.uid="{}"'.format(uid), 'hr_user_resume_relation.resume_id = hr_resume_base.id', 'hr_user_resume_relation.type="collect"' ], select={ 'collect_time': 'hr_user_resume_relation.create_time' }).order_by('-collect_time') return resume_list