查询兼容

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)
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_01_num = len([1 for i in res_data if i['hr_manner'] in [0, 1]])
res_msg = {
'data': res_data,
'manner_2_num': manner_2_num,
'manner_01_num': manner_01_num,
}

View File

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