""" 中标金额字段检查 """ class BidAmountChecker(object): """ 中标字段检查 """ def __init__(self): self.errors_tables = { "0101": { "name": "建筑行业,预算/中标金额不在:[0.7,1.3]", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0101 }, "0102": { "name": "过大过小,不在[100,10亿]", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0102 }, "0103": { "name": "中标金额小数点位数超过4位", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0103 }, "0104": { "name": "中标金额存在费率,折扣率", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0104 }, "0301": { "name": "中标金额<0", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0301 }, "0601": { "name": "中标金额 > 预算金额", "parent_name": "金额错误", "parent_code": "01", "checkFn": self.check0601 } } @staticmethod def check0101(budget: float, bidamount: float,s_topscopeclass:str,subtype:str) -> bool: """ 预算和中标金额的比例 :param budget: :param amount: :return:返回true 代表异常 """ if subtype in ("中标","成交","合同","验收"): if "建筑工程" in s_topscopeclass or "建筑" in s_topscopeclass: if budget and bidamount: if 0.7 < budget / bidamount < 1.3: return False else: return True else: # 两者中有一方为空不判断,---0,None,空字符,空字符串都是空 return False @staticmethod def check0102(bidamount: float,subtype:str) -> bool: """ 中标金额过大过小[100,10亿] :param price: :return: 返回true 代表异常 """ if subtype in ("中标", "成交", "合同", "验收"): if 100 < bidamount < 1000000000: return False return True @staticmethod def check0103(bidamount: float,subtype:str) -> bool: """ 中标金额小数点位数超过4位,视为异常 :param price: :return: 返回true 代表异常 """ if subtype in ("中标", "成交", "合同", "验收"): # 将数字转换为字符串 number_str = str(bidamount) # 检查是否有小数点 if '.' in number_str: # 分割整数部分和小数部分 integer_part, decimal_part = number_str.split('.') # 返回小数部分的长度 length= len(decimal_part) else: length = 0 if length > 4: return True @staticmethod def check0104(supervisorrate:float,subtype:str) -> bool: """ 中标金额存在费率,折扣率 :param price: :return: 返回true 代表异常 """ if subtype in ("中标", "成交", "合同", "验收"): if supervisorrate==0: return False return True @staticmethod def check0301(bidamount: float) -> bool : """ 预算<0,视为异常 :return: 返回true 代表异常 """ if bidamount < 0: return True return False @staticmethod def check0601(bidamount: float,budget:float,subtype:str) -> bool: """ 中标金额>预算,视为异常 :return: 返回true 代表异常 """ if subtype in ("中标", "成交", "合同", "验收"): if bidamount > budget: return True return False