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

26 lines
970 B
Python

6 months ago
from repository.base_repository import BaseRepository
from entity.wms_ingredients_log import WmsIngredientsLog
class WmsIngredientsLogRepository(BaseRepository):
def get_monthly_net_weight(self):
sql = """
SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,
SUM(net_weight) AS total_weight
FROM wms_ingredients_log
WHERE is_deleted = 0
AND net_weight IS NOT NULL
AND create_time IS NOT NULL
GROUP BY DATE_FORMAT(create_time, '%Y-%m')
ORDER BY month
"""
return self.execute_sql(sql)
def get_ingredients_log_by_code_sn(self, code_sn: str):
sql = """
SELECT *
FROM wms_ingredients_log
WHERE code_sn = :code_sn
AND is_deleted = 0
LIMIT 1
"""
rows = self.execute_sql(sql, {"code_sn": code_sn})
return rows[0] if rows else None