Update: Refactor to absolute imports, fix QPS limits, and enhance Gitea sync with SQLite support
This commit is contained in:
@@ -10,13 +10,13 @@ import os
|
||||
import json
|
||||
from typing import Dict, Tuple, Optional, Any, List, Union
|
||||
|
||||
from ..utils.log_utils import get_logger
|
||||
from .handlers.barcode_mapper import BarcodeMapper
|
||||
from .handlers.unit_converter_handlers import (
|
||||
from app.core.utils.log_utils import get_logger
|
||||
from app.core.excel.handlers.barcode_mapper import BarcodeMapper
|
||||
from app.core.excel.handlers.unit_converter_handlers import (
|
||||
JianUnitHandler, BoxUnitHandler, TiHeUnitHandler,
|
||||
GiftUnitHandler, UnitHandler
|
||||
)
|
||||
from .validators import ProductValidator
|
||||
from app.core.excel.validators import ProductValidator
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
from typing import Dict, Any
|
||||
|
||||
# 导出所有处理程序类
|
||||
from .barcode_mapper import BarcodeMapper
|
||||
from .unit_converter_handlers import JianUnitHandler, BoxUnitHandler, TiHeUnitHandler, GiftUnitHandler, UnitHandler
|
||||
from app.core.excel.handlers.barcode_mapper import BarcodeMapper
|
||||
from app.core.excel.handlers.unit_converter_handlers import JianUnitHandler, BoxUnitHandler, TiHeUnitHandler, GiftUnitHandler, UnitHandler
|
||||
@@ -7,7 +7,7 @@
|
||||
import logging
|
||||
from typing import Dict, Optional, Any
|
||||
|
||||
from ...utils.log_utils import get_logger
|
||||
from app.core.utils.log_utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import logging
|
||||
from typing import Dict, Optional, Any, Tuple, Protocol
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from ...utils.log_utils import get_logger
|
||||
from app.core.utils.log_utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@@ -14,17 +14,17 @@ from xlutils.copy import copy as xlcopy
|
||||
from typing import Dict, List, Optional, Tuple, Union, Any, Callable
|
||||
from datetime import datetime
|
||||
|
||||
from ...config.settings import ConfigManager
|
||||
from ..utils.log_utils import get_logger
|
||||
from ..handlers.column_mapper import ColumnMapper
|
||||
from ..utils.file_utils import (
|
||||
from app.config.settings import ConfigManager
|
||||
from app.core.utils.log_utils import get_logger
|
||||
from app.core.handlers.column_mapper import ColumnMapper
|
||||
from app.core.utils.file_utils import (
|
||||
ensure_dir,
|
||||
get_file_extension,
|
||||
get_files_by_extensions,
|
||||
load_json,
|
||||
save_json
|
||||
)
|
||||
from ..utils.string_utils import (
|
||||
from app.core.utils.string_utils import (
|
||||
clean_string,
|
||||
clean_barcode,
|
||||
format_barcode
|
||||
|
||||
@@ -14,23 +14,23 @@ from xlutils.copy import copy as xlcopy
|
||||
from typing import Dict, List, Optional, Tuple, Union, Any, Callable
|
||||
from datetime import datetime
|
||||
|
||||
from ...config.settings import ConfigManager
|
||||
from ..utils.log_utils import get_logger
|
||||
from ..utils.file_utils import (
|
||||
from app.config.settings import ConfigManager
|
||||
from app.core.utils.log_utils import get_logger
|
||||
from app.core.utils.file_utils import (
|
||||
ensure_dir,
|
||||
get_file_extension,
|
||||
get_latest_file,
|
||||
load_json,
|
||||
save_json
|
||||
)
|
||||
from ..utils.string_utils import (
|
||||
from app.core.utils.string_utils import (
|
||||
clean_string,
|
||||
extract_number,
|
||||
format_barcode,
|
||||
parse_monetary_string
|
||||
)
|
||||
from .converter import UnitConverter
|
||||
from ..handlers.column_mapper import ColumnMapper
|
||||
from app.core.excel.converter import UnitConverter
|
||||
from app.core.handlers.column_mapper import ColumnMapper
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -40,15 +40,19 @@ class ExcelProcessor:
|
||||
提取条码、单价和数量,并按照采购单模板的格式填充
|
||||
"""
|
||||
|
||||
def __init__(self, config, product_db=None):
|
||||
def __init__(self, config, product_db=None, missing_barcodes_cb: Optional[Callable[[List[str]], None]] = None):
|
||||
"""
|
||||
初始化Excel处理器
|
||||
|
||||
Args:
|
||||
config: 配置信息
|
||||
product_db: 商品数据库实例(可选,由外部传入以共享)
|
||||
missing_barcodes_cb: 缺失条码的回调函数,接收条码列表
|
||||
"""
|
||||
self.config = config
|
||||
self.missing_barcodes_cb = missing_barcodes_cb
|
||||
self.current_missing_barcodes = [] # 记录当前文件处理中缺失的条码
|
||||
self.current_file_path = "" # 记录当前处理的文件路径
|
||||
|
||||
# 修复ConfigParser对象没有get_path方法的问题
|
||||
try:
|
||||
@@ -62,7 +66,7 @@ class ExcelProcessor:
|
||||
logger.warning(f"模板文件不存在: {self.template_path}")
|
||||
|
||||
# 设置缓存文件路径
|
||||
self.cache_file = os.path.join(self.output_dir, "processed_files.json")
|
||||
self.cache_file = os.path.join(self.output_dir, "excel_process_records.json")
|
||||
self.processed_files = self._load_processed_files()
|
||||
|
||||
# 确保目录存在
|
||||
@@ -80,7 +84,7 @@ class ExcelProcessor:
|
||||
if product_db is not None:
|
||||
self.product_db = product_db
|
||||
else:
|
||||
from ..db.product_db import ProductDatabase
|
||||
from app.core.db.product_db import ProductDatabase
|
||||
db_path = config.get_path('Paths', 'product_db', fallback='data/product_cache.db') if hasattr(config, 'get_path') else 'data/product_cache.db'
|
||||
tpl_folder = config.get('Paths', 'template_folder', fallback='templates')
|
||||
item_data = config.get('Templates', 'item_data', fallback='商品资料.xlsx')
|
||||
@@ -220,6 +224,21 @@ class ExcelProcessor:
|
||||
# 跳过空条码行
|
||||
if not product['barcode']:
|
||||
continue
|
||||
|
||||
# 检查条码是否存在于数据库(商品资料)
|
||||
bc = product['barcode']
|
||||
mem = self.product_db.get_memory(bc)
|
||||
if not mem or mem.get('confidence', 0) < 50:
|
||||
# 如果不存在,或者置信度低(说明不是来自商品资料模板),记录为缺失
|
||||
if bc not in self.current_missing_barcodes:
|
||||
self.current_missing_barcodes.append(bc)
|
||||
# 记录到数据库
|
||||
self.product_db.record_missing_barcode(
|
||||
bc,
|
||||
product.get('name', ''),
|
||||
self.current_file_path
|
||||
)
|
||||
logger.warning(f"条码缺失: {bc} ({product.get('name', '')})")
|
||||
|
||||
# 检查备注列,过滤换货、退货、作废等非采购行
|
||||
skip_row = False
|
||||
@@ -606,6 +625,9 @@ class ExcelProcessor:
|
||||
if not os.path.exists(file_path):
|
||||
logger.error(f"文件不存在: {file_path}")
|
||||
return None
|
||||
|
||||
self.current_missing_barcodes = [] # 重置缺失列表
|
||||
self.current_file_path = file_path # 设置当前处理文件路径
|
||||
|
||||
try:
|
||||
# 读取Excel文件时不立即指定表头
|
||||
@@ -672,6 +694,14 @@ class ExcelProcessor:
|
||||
|
||||
# 不再自动打开输出目录
|
||||
logger.info(f"采购单已保存到: {output_file}")
|
||||
|
||||
# 处理完成,如果有缺失条码,触发回调
|
||||
if self.current_missing_barcodes and self.missing_barcodes_cb:
|
||||
try:
|
||||
self.missing_barcodes_cb(self.current_missing_barcodes)
|
||||
except Exception as e:
|
||||
logger.error(f"触发缺失条码回调失败: {e}")
|
||||
|
||||
if progress_cb:
|
||||
try:
|
||||
progress_cb(100)
|
||||
|
||||
@@ -8,8 +8,8 @@ import re
|
||||
import logging
|
||||
from typing import Dict, Any, Optional, List, Tuple, Union
|
||||
|
||||
from ..utils.log_utils import get_logger
|
||||
from ..utils.string_utils import parse_monetary_string
|
||||
from app.core.utils.log_utils import get_logger
|
||||
from app.core.utils.string_utils import parse_monetary_string
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user