|
@@ -185,32 +185,34 @@ def check(obj: any, rules) -> any:
|
|
|
if qa:
|
|
|
field_qa["%s_qa" % field] = qa
|
|
|
continue
|
|
|
- if field not in check_chain:
|
|
|
- continue
|
|
|
- checker = check_chain[field]["checker"] # 获取检测器
|
|
|
- for err,err_detail in rules[field].items(): # 获取检测的规则
|
|
|
- # 错误类型检查
|
|
|
- if err not in checker.errors_tables:
|
|
|
- qa[err] = f"{field}:服务端未定义错误类型"
|
|
|
- field_qa["%s_qa" % field] = qa
|
|
|
- continue
|
|
|
- func = checker.errors_tables[err]["checkFn"] # 获取检查方法
|
|
|
- status, params = check_params(func, obj) # 多参数解决方案
|
|
|
- if status:
|
|
|
- # 开始执行函数
|
|
|
- #判断返回是否是数值,是数值的话,为标的物的检查规则,标的物返回的是打分结果(float类型),不是错误类型
|
|
|
- result = func(**params)
|
|
|
- if isinstance(result, float):
|
|
|
- qa[err]=result
|
|
|
+ # 3. 如果字段存在且类型正确,进入 check_chain 检查
|
|
|
+ if field in check_chain:
|
|
|
+ checker = check_chain[field]["checker"] # 获取检测器
|
|
|
+ for err,err_detail in rules[field].items(): # 获取检测的规则
|
|
|
+ # 错误类型检查
|
|
|
+ if err not in checker.errors_tables:
|
|
|
+ qa[err] = f"{field}:服务端未定义错误类型"
|
|
|
+ field_qa["%s_qa" % field] = qa
|
|
|
+ continue
|
|
|
+ func = checker.errors_tables[err]["checkFn"] # 获取检查方法
|
|
|
+ status, params = check_params(func, obj) # 多参数解决方案
|
|
|
+ if status:
|
|
|
+ # 开始执行函数
|
|
|
+ #判断返回是否是数值,是数值的话,为标的物的检查规则,标的物返回的是打分结果(float类型),不是错误类型
|
|
|
+ result = func(**params)
|
|
|
+ if isinstance(result, float):
|
|
|
+ qa[err]=result
|
|
|
+ else:
|
|
|
+ if result:
|
|
|
+ qa[err] = err_detail.get("name","")
|
|
|
else:
|
|
|
- if result:
|
|
|
- qa[err] = err_detail.get("name","")
|
|
|
- else:
|
|
|
- # 参数不满足要求
|
|
|
- qa[err] = f"{field}:必须参数(字段)缺失"
|
|
|
+ # 参数不满足要求
|
|
|
+ qa[err] = f"{field}:必须参数(字段)缺失"
|
|
|
# 只有当qa不为空时才添加到field_qa
|
|
|
if qa:
|
|
|
field_qa["%s_qa" % field] = qa
|
|
|
+ elif field not in check_chain:
|
|
|
+ pass # 明确不存储无错误且无需检查的字段
|
|
|
score=bid_score(field_qa,obj)
|
|
|
field_qa["score"]=score
|
|
|
return field_qa
|