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.
111 lines
5.5 KiB
111 lines
5.5 KiB
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
'''
|
|
@Date:2022/07/19 09:43:08
|
|
'''
|
|
from sqlalchemy import or_, and_
|
|
from db_logic.db_base import Repository
|
|
from models.medicament_models import EntityMedicamentVariety
|
|
|
|
|
|
#药剂品种业务逻辑类
|
|
class BllMedicamentVariety(Repository):
|
|
#_instance_lock = threading.Lock()
|
|
## 实现单例模式
|
|
#def __new__(cls, *args, **kwargs):
|
|
# if not hasattr(BllMedicamentVariety, "_instance"):
|
|
# with BllMedicamentVariety._instance_lock:
|
|
# if not hasattr(BllMedicamentVariety, "_instance"):
|
|
# BllMedicamentVariety._instance = object.__new__(cls)
|
|
# return BllMedicamentVariety._instance
|
|
|
|
def __init__(self, entityType=EntityMedicamentVariety):
|
|
return super().__init__(entityType)
|
|
|
|
# # 创建药剂品种
|
|
# def createDrugVariety(self, customerId, name, englishName, casNumber, purity, unit, speciUnit, speci, entityUser=EntityUser()):
|
|
# entity = self.findEntity(and_(EntityMedicamentVariety.Name == name, EntityMedicamentVariety.Purity == purity,
|
|
# EntityMedicamentVariety.Unit == unit, EntityMedicamentVariety.SpeciUnit == speciUnit, EntityMedicamentVariety.Speci == speci))
|
|
# print(entity, 6666666666)
|
|
# if(entity is None):
|
|
# entity = EntityMedicamentVariety()
|
|
# entity.VarietyId = Utils.UUID()
|
|
# entity.CustomerId = customerId
|
|
# entity.InventoryWarningValue = 10
|
|
# entity.ShelfLifeWarningValue = 10
|
|
# entity.UseDaysWarningValue = 10
|
|
# entity.Name = name
|
|
# entity.EnglishName = englishName
|
|
# entity.CASNumber = casNumber
|
|
# entity.Purity = purity
|
|
# entity.Unit = unit
|
|
# entity.SpeciUnit = speciUnit
|
|
# entity.TotalCount = 1
|
|
# entity.InventoryWarningValue = 2
|
|
# entity.NormalCount = 1
|
|
# entity.UseCount = 0
|
|
# entity.EmptyCount = 0
|
|
# entity.IsSupervise = 0
|
|
# entity.Speci = speci
|
|
# entity.CreateDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
# entity.CreateUserId = entityUser.UserId
|
|
# entity.CreateUserName = entityUser.RealName
|
|
# self.insert(entity)
|
|
# else:
|
|
# entity.TotalCount += 1
|
|
# entity.NormalCount += 1
|
|
# self.update(entity)
|
|
# entity = self.session.merge(entity)
|
|
# return entity
|
|
|
|
# # 获取品种统计
|
|
# def getVarietyStatistics(self):
|
|
# SQL = """
|
|
# SELECT b.VarietyId as VarietyId, COUNT(CASE when IsEmpty = 1 then 1 end) as QuarterlyEmptyCount,
|
|
# sum(CASE when IsEmpty = 1 then a.price else 0 end) as QuarterlyEmptyPrice, COUNT(CASE when RecordType = 1 then 1 end) as
|
|
# QuarterlyPutInCount from RMS_MedicamentVariety as b LEFT JOIN RMS_MedicamentRecord as a on
|
|
# b.VarietyId = a.VarietyId and MONTH((a.CreateDate)) = MONTH(now()) and Date_format
|
|
# (a.CreateDate, '%Y') = (DATE_FORMAT(now(), '%Y')) GROUP by b.VarietyId
|
|
# """
|
|
# # 获取季度数据
|
|
# quarter_data = BllMedicamentVariety().execute(SQL).fetchall()
|
|
# quarter_data = json.loads(Utils.resultAlchemyData(
|
|
# Utils.mysqlTable2Model(quarter_data)))
|
|
# SQL = """SELECT b.VarietyId as VarietyId, COUNT(CASE when IsEmpty = 1 then a.CreateDate end)
|
|
# as YearEmptyCount, sum(CASE when IsEmpty = 1 then a.price else 0 end) as YearEmptyPrice,
|
|
# COUNT(CASE when RecordType = 1 then 1 end) as YearPutInCount from RMS_MedicamentVariety as b LEFT JOIN
|
|
# RMS_MedicamentRecord as a on b.VarietyId = a.VarietyId and year((a.CreateDate)) =
|
|
# year(now()) GROUP by b.VarietyId"""
|
|
|
|
# # 获取年度数据
|
|
# year_data = BllMedicamentVariety().execute(SQL).fetchall()
|
|
# year_data = json.loads(Utils.resultAlchemyData(
|
|
# Utils.mysqlTable2Model(year_data)))
|
|
# SQL = """
|
|
# select a.VarietyId as VarietyId, a.Name,a.Purity,a.CASNumber,a.IsSupervise,
|
|
# sum(case when b.`Status` = 1 then 1 else 0 end) as NormalCount,
|
|
# sum(case when b.`Status` = 1 or b.`Status` = 2 then 1 else 0 end) as TotalCount,
|
|
# sum(case when b.`Status` = 2 then 1 else 0 end) as UseCount,
|
|
# sum(case when b.`Status` = 1 or b.`Status` = 2 then b.Price else 0 end) as StockPrice
|
|
# from RMS_MedicamentVariety as a LEFT JOIN RMS_Medicament
|
|
# as b on b.VarietyId = a.VarietyId GROUP BY a.VarietyId
|
|
# """
|
|
# # 获取药剂数据
|
|
# med_data = BllMedicamentVariety().execute(SQL).fetchall()
|
|
# med_data = json.loads(Utils.resultAlchemyData(
|
|
# Utils.mysqlTable2Model(med_data)))
|
|
# data_list = []
|
|
# new_data_list = []
|
|
# # 便利数据合通过VarietyId相同合并字典
|
|
# for quarter in quarter_data:
|
|
# for year in year_data:
|
|
# if quarter['VarietyId'] == year['VarietyId']:
|
|
# new_data = dict(quarter, **year)
|
|
# data_list.append(new_data)
|
|
# for data_dict in data_list:
|
|
# for med in med_data:
|
|
# if data_dict['VarietyId'] == med['VarietyId']:
|
|
# new_data = dict(data_dict, **med)
|
|
# new_data_list.append(new_data)
|
|
# return new_data_list
|