查询兼容

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,9 +281,17 @@ class InterviewDo:
})
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
updateStr.strip()
whereStr.strip()
sql = f"alter table HR.resumes update {updateStr} where {whereStr}"
@ -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 + ', '
@ -310,28 +318,44 @@ class InterviewDo:
if index > 0:
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 == '':
whereStr += str(key) + ' = ' + str(0) + ' '
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
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
# sql = f"select * from HR.resumes where {whereStr}"
if whereStr:
sql = f"select {findStr} from HR.resumes where {whereStr}"
else:
sql = f"select {findStr} from HR.resumes"
print(sql)
return {
'sql': sql,
@ -341,8 +365,11 @@ class InterviewDo:
def find_interview_every_sql(self):
whereStr = ''
findStr = ''
for fstr in self.find_column:
findStr += fstr + ', '
if not self.find_column:
findStr = 'hr_manner'
else:
for fstr in self.find_column:
findStr += fstr + ', '
for key, value in self.where.items():
if key in ['interview_id', 'hr_id', 'interview_name', 'hr_name']:
# 多个条件
@ -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):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
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,9 +435,17 @@ class InterviewDo:
findStr += fstr + ', '
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
@ -406,9 +467,17 @@ class InterviewDo:
findStr += fstr + ', '
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
@ -430,9 +499,17 @@ class InterviewDo:
findStr += fstr + ', '
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
@ -454,9 +531,17 @@ class InterviewDo:
findStr += fstr + ', '
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
@ -493,9 +578,17 @@ class InterviewDo:
findStr += fstr + ', '
for key, value in self.where.items():
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
sql = f"select {findStr} from HR.resumes where {whereStr}"
@ -519,9 +612,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -560,13 +661,18 @@ 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):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -610,13 +716,18 @@ 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):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -663,9 +774,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -707,9 +826,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -751,9 +878,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
# 有日期条件
@ -802,9 +937,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
findStr = findStr.strip().strip(',')
@ -846,9 +989,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
# 有日期条件
@ -892,9 +1043,17 @@ class InterviewDo:
is_date = 1
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
# 有日期条件
@ -944,9 +1103,17 @@ class InterviewDo:
if key in ['start_time', 'end_time']:
continue
if isinstance(value, str):
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
if not value.strip():
continue
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + "'" + value + "'" + ' '
else:
whereStr += str(key) + ' = ' + "'" + value + "'" + ' '
continue
whereStr += str(key) + ' = ' + str(value) + ' '
if whereStr:
whereStr += 'and ' + str(key) + ' = ' + str(value) + ' '
else:
whereStr += str(key) + ' = ' + str(value) + ' '
whereStr = whereStr.strip()
# 有日期条件