base_item.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. import feapder.utils.tools as tools
  3. from feapder import Item
  4. class SwordFishProjectItem(Item):
  5. def __init__(self):
  6. super(SwordFishProjectItem, self).__init__(
  7. save=True # 是否入库,默认入库=True,不入库=False
  8. )
  9. @property
  10. def save(self) -> bool:
  11. return self.__dict__["save"]
  12. @save.setter
  13. def save(self, enable: bool):
  14. self.__dict__["save"] = enable
  15. @property
  16. def fingerprint(self):
  17. args = []
  18. # 1、入库字段去重
  19. for key, value in self.to_dict.items():
  20. if value:
  21. if (self.unique_key and key in self.unique_key) or not self.unique_key:
  22. args.append(str(value))
  23. # 2、入库字段去重_招投标字段
  24. bidding = self.to_dict.get("item", {})
  25. for key, value in bidding.items():
  26. if value:
  27. if (self.unique_key and key in self.unique_key) or not self.unique_key:
  28. args.append(str(value))
  29. # 3、非入库字段去重
  30. if self.unique_key:
  31. for key in filter(lambda x: x not in bidding and x not in self.to_dict, self.unique_key):
  32. if key not in args:
  33. args.append(str(key))
  34. if args:
  35. args = sorted(args)
  36. return tools.get_md5(*args) + "&&" + tools.get_sha256(*args)
  37. else:
  38. return None