查询兼容

This commit is contained in:
Àî×ÚÕñ 2022-09-16 15:50:35 +08:00
parent e35ea56a29
commit 6b1f50b20c
2 changed files with 243 additions and 56 deletions

View File

@ -162,12 +162,32 @@ async def interview_find(
# 格式化数据 # 格式化数据
res_data = chkData(data) res_data = chkData(data)
return schemas.Msg(code=200, msg='ok', data=res_data)
# 面试查询
@router.post("/interview_manner_num")
async def interview_find(
request: Request,
interview: InterviewDo = Depends(InterviewDo),
db: CKDrive = Depends(get_ck_db),
current_user: schemas.UserDB = Depends(deps.get_current_user)
) -> schemas.Msg:
""" interview面试数据查询 """
await interview.init()
res = interview.find_interview_every_sql()
sql = res['sql']
data = await db.execute(sql)
if not data:
return schemas.Msg(code=200, msg='无数据', data=[])
# 格式化数据
res_data = chkData(data)
# 统计数量 # 统计数量
manner_2_num = len([1 for i in res_data if i['hr_manner'] == 2]) manner_2_num = len([1 for i in res_data if i['hr_manner'] == 2])
manner_01_num = len([1 for i in res_data if i['hr_manner'] in [0, 1]]) manner_01_num = len([1 for i in res_data if i['hr_manner'] in [0, 1]])
res_msg = { res_msg = {
'data': res_data,
'manner_2_num': manner_2_num, 'manner_2_num': manner_2_num,
'manner_01_num': manner_01_num, 'manner_01_num': manner_01_num,
} }

View File

@ -281,8 +281,16 @@ class InterviewDo:
}) })
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
updateStr.strip() updateStr.strip()
whereStr.strip() whereStr.strip()
@ -297,7 +305,7 @@ class InterviewDo:
whereStr = '' whereStr = ''
findStr = '' findStr = ''
if not self.find_column: if not self.find_column:
findStr = '*' findStr = 'hr_manner'
else: else:
for fstr in self.find_column: for fstr in self.find_column:
findStr += fstr + ', ' findStr += fstr + ', '
@ -309,29 +317,45 @@ class InterviewDo:
for index, i in enumerate(values): for index, i in enumerate(values):
if index > 0: if index > 0:
whereStr += 'or ' + str(key) + ' like ' + "'%" + i + "%'" + ' ' whereStr += 'or ' + str(key) + ' like ' + "'%" + i + "%'" + ' '
else:
if whereStr:
whereStr += 'and ' + str(key) + ' like ' + "'%" + i + "%'" + ' '
else: else:
whereStr += str(key) + ' like ' + "'%" + i + "%'" + ' ' whereStr += str(key) + ' like ' + "'%" + i + "%'" + ' '
continue continue
if value == '': if value == '':
continue continue
# 单个条件 # 单个条件
if whereStr:
whereStr += 'and ' + str(key) + ' like ' + "'%" + value + "%'" + ' '
else:
whereStr += str(key) + ' like ' + "'%" + value + "%'" + ' ' whereStr += str(key) + ' like ' + "'%" + value + "%'" + ' '
continue continue
if key == 'hr_manner': if key == 'hr_manner':
if value == '': if value == '':
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(0) + ' '
else:
whereStr += str(key) + ' = ' + str(0) + ' ' whereStr += str(key) + ' = ' + str(0) + ' '
whereStr += 'or ' + str(key) + ' = ' + str(1) + ' ' whereStr += 'or ' + str(key) + ' = ' + str(1) + ' '
if isinstance(value, str): if isinstance(value, str):
if not value.strip(): if not value.strip():
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
if whereStr:
sql = f"select {findStr} from HR.resumes where {whereStr}" sql = f"select {findStr} from HR.resumes where {whereStr}"
# sql = f"select * from HR.resumes where {whereStr}" else:
sql = f"select {findStr} from HR.resumes"
print(sql) print(sql)
return { return {
'sql': sql, 'sql': sql,
@ -341,6 +365,9 @@ class InterviewDo:
def find_interview_every_sql(self): def find_interview_every_sql(self):
whereStr = '' whereStr = ''
findStr = '' findStr = ''
if not self.find_column:
findStr = 'hr_manner'
else:
for fstr in self.find_column: for fstr in self.find_column:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
@ -350,20 +377,46 @@ class InterviewDo:
values = value.split(',') values = value.split(',')
for index, i in enumerate(values): for index, i in enumerate(values):
if index > 0: if index > 0:
whereStr += 'or ' + str(key) + 'like %' + "'" + i + "'" + '% ' whereStr += 'or ' + str(key) + ' like ' + "'%" + i + "%'" + ' '
else: else:
whereStr += str(key) + 'like %' + "'" + i + "'" + '% ' if whereStr:
whereStr += 'and ' + str(key) + ' like ' + "'%" + i + "%'" + ' '
else:
whereStr += str(key) + ' like ' + "'%" + i + "%'" + ' '
continue
if value == '':
continue continue
# 单个条件 # 单个条件
whereStr += str(key) + 'like %' + "'" + value + "'" + '% ' if whereStr:
whereStr += 'and ' + str(key) + ' like ' + "'%" + value + "%'" + ' '
else:
whereStr += str(key) + ' like ' + "'%" + value + "%'" + ' '
continue continue
if key == 'hr_manner':
if value == '':
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(0) + ' '
else:
whereStr += str(key) + ' = ' + str(0) + ' '
whereStr += 'or ' + str(key) + ' = ' + str(1) + ' '
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
if whereStr:
sql = f"select {findStr} from HR.resumes where {whereStr}" sql = f"select {findStr} from HR.resumes where {whereStr}"
else:
sql = f"select {findStr} from HR.resumes"
print(sql) print(sql)
return { return {
'sql': sql, 'sql': sql,
@ -382,8 +435,16 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -406,8 +467,16 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -430,8 +499,16 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -454,8 +531,16 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -493,8 +578,16 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
for key, value in self.where.items(): for key, value in self.where.items():
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -519,8 +612,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -560,12 +661,17 @@ class InterviewDo:
findStr += fstr + ', ' findStr += fstr + ', '
is_date = 0 is_date = 0
for key, value in self.where.items(): for key, value in self.where.items():
if key in ['start_time', 'end_time']:
is_date = 1
continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -610,12 +716,17 @@ class InterviewDo:
is_date = 0 is_date = 0
if self.where: if self.where:
for key, value in self.where.items(): for key, value in self.where.items():
if key in ['start_time', 'end_time']:
is_date = 1
continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -663,8 +774,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -707,8 +826,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -751,8 +878,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
@ -802,8 +937,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
findStr = findStr.strip().strip(',') findStr = findStr.strip().strip(',')
@ -846,8 +989,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
@ -892,8 +1043,16 @@ class InterviewDo:
is_date = 1 is_date = 1
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()
@ -944,8 +1103,16 @@ class InterviewDo:
if key in ['start_time', 'end_time']: if key in ['start_time', 'end_time']:
continue continue
if isinstance(value, str): if isinstance(value, str):
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' ' whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' ' whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip() whereStr = whereStr.strip()