# -*- coding: utf-8 -*- # @Time : 2023/9/26 11:02 # @Author : tx # @File : report_drug_logs.py # @Description : from fastapi.encoders import jsonable_encoder from tortoise.queryset import QuerySet from conf import setting # from models.drug_use_log import DrugUseLog, DrugUseStateEnum from helper.export.base import ReportExport from helper.drug import milligram_to_gram from helper.report import report_drug_logs class ReportDrugUseLogs(ReportExport): def __init__(self, request, keyword): super().__init__() self.title = "流转日志" self.stateDict = {0: "入库", 1: "归还", 2: "领用", 3: "空瓶", 4: "报废"} self.request = request self.keyword = keyword async def parse_data(self, request, keyword): """ 解析数据 :return: """ keyword.page_no = 0 result = await report_drug_logs(request, keyword) self.drug_attribute_key_list = result.get("attribute_key") return result.get("data") def parse_key_finds_list(self): """ 解析键列名 :return: """ key_list = ["state", "position", "users", "weight", "use_weight", "created_at"] finds_list = ["流转类型", "位置", "用户", "余量", "用量", "创建时间"] self.key_list = self.drug_attribute_key_list + key_list self.finds_list = self.drug_attribute_key_list + finds_list async def main(self): """ 主函数 :param kwargs: :return: """ self.data_list = await self.parse_data(self.request, self.keyword) self.parse_key_finds_list()