You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python
# encoding: utf-8
"""
@author: tx
@file: template.py
@time: 2023/6/3 17:15
@desc:
"""
import collections
from tortoise import fields, models
from conf.setting import setting
class TemplateItem(models.Model):
key = fields.CharField(max_length=255, description='key')
text = fields.CharField(max_length=255, description='文本')
checked = fields.BooleanField(max_length=255, description='是否必填')
required = fields.BooleanField(max_length=255, description='是否选中')
reserved = fields.IntField(description='0关键字段, 1重要字段, 2自定义字段')
type = fields.CharField(max_length=255, description='类型string(文本), date(日期), number(数字)')
class Meta:
table = 'template_items'
table_description = '药剂模板表'
class Template(models.Model):
id = fields.UUIDField(pk=True)
name = fields.CharField(max_length=255, description='模板名称')
tags = fields.TextField(description='唯一约束字段')
xlsx = fields.JSONField(null=True, description='入库单模板')
archive = fields.ForeignKeyField('rms.Archive', null=True, description='入库单模板')
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
class Meta:
table = 'templates'
table_description = '药剂模板表'
def parse_xlsx_transfer(self):
"""翻译xlsx模板数据"""
xlsx = list(filter(lambda i: i.get("checked"), self.xlsx))
# xlsx_transfer = {f"{item.get('key')}": f"{item.get('text')}" for item in xlsx}
xlsx_transfer = collections.OrderedDict()
for item in xlsx:
key = item.get('key')
text = item.get('text')
xlsx_transfer[key] = text
# 盒装药剂字段键值
if setting.BOX_TRANSFER_DICT:
xlsx_transfer.update(setting.BOX_TRANSFER_DICT)
xlsx_type = {f"{item.get('key')}": f"{item.get('type')}" for item in xlsx}
xlsx_required = {f"{item.get('key')}": f"{item.get('required')}" for item in xlsx}
return {"xlsx_transfer": xlsx_transfer, "xlsx_type": xlsx_type, "xlsx_required": xlsx_required}
def get_checked_xlsx(self):
xlsx = list(filter(lambda i: i.get("checked"), self.xlsx))
return xlsx