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.

110 lines
2.5 KiB

# -*- coding:utf-8 -*-
"""
@Created on : 2023/7/24 10:25
@Author: hxl
@Des:
"""
import hashlib
import os
import platform
from collections import namedtuple
from datetime import datetime
import psutil
from pytz import timezone
from conf import setting
def ostruct(kv: dict):
return namedtuple('OpenStruct', ' '.join(kv.keys()))(**kv)
def isBlank(term):
return not (term and term.strip())
def timezone_now():
zone = timezone(setting.TIMEZONE)
return datetime.now(zone)
def rfid_reverse(rfid):
"""
读卡器反转
"""
if setting.RFID_REVERSE:
rfid = "".join(reversed([rfid[i:i + 2] for i in range(0, len(rfid), 2)]))
rfid = rfid.upper()
return rfid
def encrypt_md5(text):
# 创建一个 MD5 对象
md5 = hashlib.md5()
# 更新哈希对象的输入值,需要将字符串编码为字节型再进行更新
md5.update(text.encode('utf-8'))
# 计算并返回哈希值的十六进制表示
return md5.hexdigest()
# 判断当前系统是linux还是windows
system_name = platform.system()
# 获取当前插入U盘路径
def get_UDisk_path():
if system_name == 'Windows':
disk_list = psutil.disk_partitions()
# 获取U盘路径
u_path = [disk.device for disk in disk_list if disk.opts == 'rw,removable']
if u_path:
return u_path[0]
elif system_name == "Linux":
r = os.popen('ls -a /media/yanyi')
text = r.read()
r.close()
udisklist = text.splitlines()
if (len(udisklist) >= 3):
return '/media/yanyi/' + udisklist[2]
return ""
# 创建文件夹
def mkdir(path):
folder = os.path.exists(path)
if not folder:
os.makedirs(path)
# 获取配液按天自增编号
def get_seq_no(number):
"""
储备液编号 = 打印标签
格式如CB230728001
"""
# zone = timezone(setting.TIMEZONE) # 时区
# today = datetime.now(zone).strftime('%y%m%d')
today = datetime.now().strftime('%y%m%d')
return "CB%s%03d" % (today, number)
# 获取数字和单位
def number_and_unit(input_str):
"""
获取数量和单位
支持如下的常见格式12.23g/ml,12g,12.3ml等
"""
pattern = r"(\d+\.?\d+)([a-zA-Z/]+)" # 匹配数字和单位的正则表达式
match = re.match(pattern, input_str)
if match:
weight = match.group(1) # 获取数字部分
unit = match.group(2) # 获取单位部分
return weight, unit
else:
return None, None