bidamount.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. "0701": {
  47. "name": "建筑行业中标金额不在预算的 70%-130%范围",
  48. "parent_name": "金额错误",
  49. "parent_code": "01",
  50. "checkFn": self.check0701
  51. }
  52. }
  53. @staticmethod
  54. def check0101(budget: float, bidamount: float) -> bool:
  55. """
  56. 预算和中标金额的比例
  57. :param budget:
  58. :param amount:
  59. :return:返回true 代表异常
  60. """
  61. if budget and bidamount:
  62. if 0.7 < budget / bidamount < 1.3:
  63. return False
  64. else:
  65. return True
  66. else:
  67. # 两者中有一方为空不判断,---0,None,空字符,空字符串都是空
  68. return False
  69. @staticmethod
  70. def check0102(bidamount: float) -> bool:
  71. """
  72. 中标金额过大过小[100,10亿]
  73. :param price:
  74. :return: 返回true 代表异常
  75. """
  76. if 100 < bidamount < 1000000000:
  77. return False
  78. return True
  79. @staticmethod
  80. def check0103(bidamount: float) -> bool:
  81. """
  82. 中标金额小数点位数超过4位,视为异常
  83. :param price:
  84. :return: 返回true 代表异常
  85. """
  86. # 将数字转换为字符串
  87. number_str = str(bidamount)
  88. # 检查是否有小数点
  89. if '.' in number_str:
  90. # 分割整数部分和小数部分
  91. integer_part, decimal_part = number_str.split('.')
  92. # 返回小数部分的长度
  93. length= len(decimal_part)
  94. else:
  95. length = 0
  96. if length > 4 :
  97. return True
  98. @staticmethod
  99. def check0104(supervisorrate:float) -> bool:
  100. """
  101. 中标金额存在费率,折扣率
  102. :param price:
  103. :return: 返回true 代表异常
  104. """
  105. if supervisorrate==0 :
  106. return False
  107. return True
  108. @staticmethod
  109. def check0301(bidamount: float) -> bool :
  110. """
  111. 预算<0,视为异常
  112. :return: 返回true 代表异常
  113. """
  114. if bidamount < 0:
  115. return True
  116. return False
  117. @staticmethod
  118. def check0601(bidamount: float,budget:float) -> bool:
  119. """
  120. 中标金额>预算,视为异常
  121. :return: 返回true 代表异常
  122. """
  123. if bidamount > budget:
  124. return True
  125. return False
  126. @staticmethod
  127. def check0701(bidamount: float, budget: float,s_topscopeclass:str) -> bool:
  128. """
  129. 建筑行业中标金额不在预算的 70%-130%范围,视为异常
  130. :return: 返回true 代表异常
  131. """
  132. if s_topscopeclass in ["建筑", "建筑工程"]:
  133. # 独立判断1:低于70%
  134. if bidamount < budget * 0.7:
  135. return True
  136. # 独立判断2:高于130%
  137. if bidamount > budget * 1.3:
  138. return True
  139. return False