bidamount.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. """
  2. 中标金额字段检查
  3. """
  4. class BidAmountChecker(object):
  5. """
  6. 中标字段检查
  7. """
  8. def __init__(self):
  9. self.errors_tables = {
  10. "0101": {
  11. "name": "建筑行业,预算/中标金额不在:[0.7,1.3]",
  12. "parent_name": "金额错误",
  13. "parent_code": "01",
  14. "checkFn": self.check0101
  15. },
  16. "0102": {
  17. "name": "过大过小,不在[100,10亿]",
  18. "parent_name": "金额错误",
  19. "parent_code": "01",
  20. "checkFn": self.check0102
  21. },
  22. "0103": {
  23. "name": "中标金额小数点位数超过4位",
  24. "parent_name": "金额错误",
  25. "parent_code": "01",
  26. "checkFn": self.check0103
  27. },
  28. "0104": {
  29. "name": "中标金额存在费率,折扣率",
  30. "parent_name": "金额错误",
  31. "parent_code": "01",
  32. "checkFn": self.check0104
  33. },
  34. "0301": {
  35. "name": "中标金额<0",
  36. "parent_name": "金额错误",
  37. "parent_code": "01",
  38. "checkFn": self.check0301
  39. },
  40. "0601": {
  41. "name": "中标金额 > 预算金额",
  42. "parent_name": "金额错误",
  43. "parent_code": "01",
  44. "checkFn": self.check0601
  45. }
  46. }
  47. @staticmethod
  48. def check0101(budget: float, bidamount: float,s_topscopeclass:str,subtype:str) -> bool:
  49. """
  50. 预算和中标金额的比例
  51. :param budget:
  52. :param amount:
  53. :return:返回true 代表异常
  54. """
  55. if subtype in ("中标","成交","合同","验收"):
  56. if "建筑工程" in s_topscopeclass or "建筑" in s_topscopeclass:
  57. if budget and bidamount:
  58. if 0.7 < budget / bidamount < 1.3:
  59. return False
  60. else:
  61. return True
  62. else:
  63. # 两者中有一方为空不判断,---0,None,空字符,空字符串都是空
  64. return False
  65. @staticmethod
  66. def check0102(bidamount: float,subtype:str) -> bool:
  67. """
  68. 中标金额过大过小[100,10亿]
  69. :param price:
  70. :return: 返回true 代表异常
  71. """
  72. if subtype in ("中标", "成交", "合同", "验收"):
  73. if 100 < bidamount < 1000000000:
  74. return False
  75. return True
  76. @staticmethod
  77. def check0103(bidamount: float,subtype:str) -> bool:
  78. """
  79. 中标金额小数点位数超过4位,视为异常
  80. :param price:
  81. :return: 返回true 代表异常
  82. """
  83. if subtype in ("中标", "成交", "合同", "验收"):
  84. # 将数字转换为字符串
  85. number_str = str(bidamount)
  86. # 检查是否有小数点
  87. if '.' in number_str:
  88. # 分割整数部分和小数部分
  89. integer_part, decimal_part = number_str.split('.')
  90. # 返回小数部分的长度
  91. length= len(decimal_part)
  92. else:
  93. length = 0
  94. if length > 4:
  95. return True
  96. @staticmethod
  97. def check0104(supervisorrate:float,subtype:str) -> bool:
  98. """
  99. 中标金额存在费率,折扣率
  100. :param price:
  101. :return: 返回true 代表异常
  102. """
  103. if subtype in ("中标", "成交", "合同", "验收"):
  104. if supervisorrate==0:
  105. return False
  106. return True
  107. @staticmethod
  108. def check0301(bidamount: float) -> bool :
  109. """
  110. 预算<0,视为异常
  111. :return: 返回true 代表异常
  112. """
  113. if bidamount < 0:
  114. return True
  115. return False
  116. @staticmethod
  117. def check0601(bidamount: float,budget:float,subtype:str) -> bool:
  118. """
  119. 中标金额>预算,视为异常
  120. :return: 返回true 代表异常
  121. """
  122. if subtype in ("中标", "成交", "合同", "验收"):
  123. if bidamount > budget:
  124. return True
  125. return False