capital.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. capital投资金额字段检查
  3. """
  4. class CapitalChecker(object):
  5. """
  6. 投资金额字段检查
  7. """
  8. def __init__(self):
  9. self.errors_tables = {
  10. "0103": {
  11. "name": "投资金额小数点位数超过4位",
  12. "parent_name": "金额错误",
  13. "parent_code": "01",
  14. "checkFn": self.check0103
  15. },
  16. "0201": {
  17. "name": "投资金额<0",
  18. "parent_name": "金额错误",
  19. "parent_code": "01",
  20. "checkFn": self.check0201
  21. }
  22. }
  23. @staticmethod
  24. def check0103(capital: float) -> bool :
  25. """
  26. 投资金额小数点位数超过4位,视为异常
  27. :param price:
  28. :return: 返回true 代表异常
  29. """
  30. # 将数字转换为字符串
  31. number_str = str(capital)
  32. # 检查是否有小数点
  33. if '.' in number_str:
  34. # 分割整数部分和小数部分
  35. integer_part, decimal_part = number_str.split('.')
  36. # 返回小数部分的长度
  37. length= len(decimal_part)
  38. else:
  39. length = 0
  40. if length > 4 :
  41. return True
  42. @staticmethod
  43. def check0201(capital: float) -> bool :
  44. """
  45. 投资金额<0,视为异常
  46. :return: 返回true 代表异常
  47. """
  48. if capital < 0:
  49. return True
  50. return False