storage_service.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from src.storage.storage_prototype import storage_prototype
  2. from src.export.exporter_factory import exporter_factory
  3. from src.logic.process_factory import process_factory
  4. from src.storage.storage import storage
  5. from src.validation.validator import validator
  6. import json
  7. class storage_service:
  8. __data = []
  9. def __init__(self, data: list):
  10. self.__data = data
  11. self.__vtor = validator()
  12. @staticmethod
  13. def create_response(data, app):
  14. """Создать JSON"""
  15. data = exporter_factory().create("json").export_models(data)
  16. data = json.dumps(data, indent=4, ensure_ascii=False)
  17. result = app.response_class(
  18. response=data, status=200, mimetype="application/json; charset=utf-8"
  19. )
  20. return result
  21. def create_turns_nomen(self, strg, nomen, **kwargs):
  22. """Отфильтровать по номенклатуре"""
  23. prototype = storage_prototype(self.__data)
  24. transactions = prototype.filter_nom(nomen).data
  25. processing = process_factory().create(storage.process_turn_key(), strg)
  26. rests = processing.create(transactions)
  27. return rests
  28. def create_turns_dt(self, strg, from_dt, to_dt, **kwargs):
  29. """Отфильтровать по временному диапазону"""
  30. prototype = storage_prototype(self.__data)
  31. transactions = prototype.filter_dt(from_dt, to_dt).data
  32. processing = process_factory().create(storage.process_turn_key(), strg)
  33. rests = processing.create(transactions)
  34. return rests
  35. def create_turns_recipe(self, strg, recipe, **kwargs):
  36. """Отфильтровать по рецепту"""
  37. prototype = storage_prototype(self.__data)
  38. transactions = prototype.filter_recipe(recipe).data
  39. processing = process_factory().create(storage.process_turn_key(), strg)
  40. rests = processing.create(transactions)
  41. return rests
  42. @property
  43. def data(self) -> list:
  44. return self.__data