| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- # -*- coding: utf-8 -*-
- # @Author : YY
- # @FileName: sys_price_info_conf_mapper.py
- # @Time : 2025-12-22 04:49:51
- from typing import List
- from datetime import datetime
- from flask import g
- from sqlalchemy import select, update, delete, func
- from ruoyi_admin.ext import db
- from ruoyi_common.domain.entity import SysPriceConf
- from ruoyi_system.domain.po import SysPriceConfPo
- class SysPriceInfoConfMapper:
- """价目配置表Mapper"""
- @staticmethod
- def select_priceinfo_conf_list(sys: SysPriceConf) -> List[SysPriceConf]:
- """
- 查询价目配置表列表
- Args:
- sys (sys_price_info_conf): 价目配置表对象
- Returns:
- List[sys_price_info_conf]: 价目配置表列表
- """
- try:
- # 构建查询条件
- stmt = select(SysPriceConfPo)
- if sys.conf_id is not None:
- stmt = stmt.where(SysPriceConfPo.conf_id == sys.conf_id)
- if sys.module_index is not None:
- stmt = stmt.where(SysPriceConfPo.module_index == sys.module_index)
- if sys.category is not None:
- stmt = stmt.where(SysPriceConfPo.category == sys.category)
- if sys.attributes is not None:
- stmt = stmt.where(SysPriceConfPo.attributes == sys.attributes)
- if "criterian_meta" in g and g.criterian_meta.page:
- g.criterian_meta.page.stmt = stmt
- result = db.session.execute(stmt).scalars().all()
- return [SysPriceConf.model_validate(item) for item in result] if result else []
- except Exception as e:
- print(f"查询价目配置表列表出错: {e}")
- return []
- @staticmethod
- def select_sys_price_info_conf_by_id(conf_id: int) -> SysPriceConf:
- """
- 根据ID查询价目配置表
- Args:
- conf_id (int): conf_id
- Returns:
- sys_price_info_conf: 价目配置表对象
- """
- try:
- result = db.session.get(SysPriceConfPo, conf_id)
- return SysPriceConf.model_validate(result) if result else None
- except Exception as e:
- print(f"根据ID查询价目配置表出错: {e}")
- return None
- @staticmethod
- def insert_sys_price_info_conf(sys: SysPriceConf) -> int:
- """
- 新增价目配置表
- Args:
- sys (sys_price_info_conf): 价目配置表对象
- Returns:
- int: 插入的记录数
- """
- try:
- now = datetime.now()
- new_po = SysPriceConfPo()
-
- # 如果 conf_id 为空,需要生成新的主键值
- if sys.conf_id is None:
- # 查询当前最大 conf_id 值
- max_id_stmt = select(func.max(SysPriceConfPo.conf_id))
- max_id_result = db.session.execute(max_id_stmt).scalar()
- # 如果表中没有数据,从1开始;否则最大值+1
- new_po.conf_id = (max_id_result + 1) if max_id_result is not None else 1
- else:
- new_po.conf_id = sys.conf_id
-
- new_po.module_index = sys.module_index
- new_po.category = sys.category
- new_po.attributes = sys.attributes
- db.session.add(new_po)
- db.session.commit()
- sys.conf_id = new_po.conf_id
- return 1
- except Exception as e:
- db.session.rollback()
- print(f"新增价目配置表出错: {e}")
- return 0
- @staticmethod
- def update_sys_price_info_conf(sys: SysPriceConf) -> int:
- """
- 修改价目配置表
- Args:
- sys (sys_price_info_conf): 价目配置表对象
- Returns:
- int: 更新的记录数
- """
- try:
- existing = db.session.get(SysPriceConfPo, sys.conf_id)
- if not existing:
- return 0
- now = datetime.now()
- # 主键不参与更新
- existing.module_index = sys.module_index
- existing.category = sys.category
- existing.attributes = sys.attributes
- db.session.commit()
- return 1
- except Exception as e:
- db.session.rollback()
- print(f"修改价目配置表出错: {e}")
- return 0
- @staticmethod
- def delete_sys_price_info_conf_by_ids(ids: List[int]) -> int:
- """
- 批量删除价目配置表
- Args:
- ids (List[int]): ID列表
- Returns:
- int: 删除的记录数
- """
- try:
- stmt = delete(SysPriceConfPo).where(SysPriceConfPo.conf_id.in_(ids))
- result = db.session.execute(stmt)
- db.session.commit()
- return result.rowcount
- except Exception as e:
- db.session.rollback()
- print(f"批量删除价目配置表出错: {e}")
- return 0
|