fix(固资): 1.docs中后续每次固资快照同步成功后,这个清理会自动执行,不需要手工再删;2.增加账套字段
This commit is contained in:
1 parent
1bd9f278fe
commit
6e78c10171
3 files changed
+67
-15
No files matched your search
@@ -39,6 +39,7 @@ class FixedAssetsSnapshotService:
|
||||
"资产编号",
|
||||
"资产名称",
|
||||
"规格型号",
|
||||
"账套",
|
||||
"保管人姓名",
|
||||
"保管部门名称",
|
||||
"存放位置名称",
|
||||
@@ -74,6 +75,11 @@ class FixedAssetsSnapshotService:
|
||||
"X": "被资本",
|
||||
"Z": "停用",
|
||||
}
|
||||
ACCOUNT_BOOK_MAP = {
|
||||
"HXJM": "和信精密",
|
||||
"HTT": "和泰科技",
|
||||
"HTE": "和泰电子",
|
||||
}
|
||||
STOPWORDS_PATTERN = re.compile(
|
||||
r"(固定资产|固资|资产编号|财产编号|资产编码|编号|资产名称|设备名称|资产|设备|请问|帮我|看下|查下|查询|统计|核对|看看|我想知道|有多少台?|有多少|多少台?|多少|明细|列表|数据|结果|并且|以及|还有|和|按|根据|生成图表|生成excel|生成表单|导出excel|导出表单|导出)",
|
||||
re.IGNORECASE,
|
||||
@@ -132,6 +138,7 @@ class FixedAssetsSnapshotService:
|
||||
f"资产编号:{row.get('资产编号', '')}",
|
||||
f"资产名称:{row.get('资产名称', '')}",
|
||||
f"规格型号:{row.get('规格型号', '')}",
|
||||
f"账套:{row.get('账套', '')}({row.get('营运中心代码', '')})",
|
||||
f"保管人姓名:{row.get('保管人姓名', '')}",
|
||||
f"保管部门名称:{row.get('保管部门名称', '')}",
|
||||
f"存放位置名称:{row.get('存放位置名称', '')}",
|
||||
@@ -257,6 +264,10 @@ ORDER BY faj.faj02
|
||||
columns[idx]: cls._stringify(value)
|
||||
for idx, value in enumerate(raw_row)
|
||||
}
|
||||
item["账套"] = cls.ACCOUNT_BOOK_MAP.get(
|
||||
item.get("营运中心代码", "").strip().upper(),
|
||||
item.get("营运中心代码", ""),
|
||||
)
|
||||
item["资产状态"] = cls.STATUS_MAP.get(item.get("资产状态代码", "").upper(), item.get("资产状态代码", ""))
|
||||
item["资产性质"] = cls.NATURE_MAP.get(item.get("资产性质代码", ""), item.get("资产性质代码", ""))
|
||||
item["备注"] = cls._build_remark(item)
|
||||
@@ -391,6 +402,7 @@ INSERT INTO fixed_assets (
|
||||
item.get("资产编号", ""),
|
||||
item.get("资产名称", ""),
|
||||
item.get("规格型号", ""),
|
||||
item.get("账套", ""),
|
||||
item.get("保管人姓名", ""),
|
||||
item.get("保管部门名称", ""),
|
||||
item.get("存放位置名称", ""),
|
||||
@@ -460,23 +472,29 @@ INSERT INTO fixed_assets (
|
||||
cls._log("warning", f"Failed to remove temp snapshot file {temp_file}: {exc}")
|
||||
|
||||
@classmethod
|
||||
def _cleanup_history_snapshots(cls, keep_count: int | None = None) -> None:
|
||||
"""仅保留最新 N 份历史快照,额外旧文件自动清理。"""
|
||||
cls._ensure_storage_dirs()
|
||||
snapshots_dir = cls._snapshots_dir()
|
||||
cls._cleanup_temp_snapshot_files(snapshots_dir)
|
||||
def _cleanup_versioned_files(
|
||||
cls,
|
||||
directory: Path,
|
||||
*,
|
||||
patterns: tuple[str, ...],
|
||||
keep_count: int,
|
||||
) -> None:
|
||||
"""按版本号仅保留最近 N 份历史文件,跳过 latest 固定别名文件。"""
|
||||
if not directory.exists():
|
||||
return
|
||||
|
||||
safe_keep_count = max(1, int(keep_count or current_app.config.get("FIXED_ASSETS_HISTORY_KEEP_COUNT", 3) or 3))
|
||||
version_files: dict[str, list[Path]] = {}
|
||||
for pattern in ("FixedAssets_*.db", "FixedAssets_*.xlsx"):
|
||||
for file_path in snapshots_dir.glob(pattern):
|
||||
for pattern in patterns:
|
||||
for file_path in directory.glob(pattern):
|
||||
if file_path.name.startswith("~$"):
|
||||
continue
|
||||
version_key = file_path.stem
|
||||
version_files.setdefault(version_key, []).append(file_path)
|
||||
match = re.fullmatch(r"FixedAssets_(\d{8}_\d{6})", file_path.stem)
|
||||
if not match:
|
||||
continue
|
||||
version_files.setdefault(match.group(1), []).append(file_path)
|
||||
|
||||
version_keys = sorted(version_files.keys(), reverse=True)
|
||||
obsolete_keys = version_keys[safe_keep_count:]
|
||||
obsolete_keys = version_keys[keep_count:]
|
||||
for version_key in obsolete_keys:
|
||||
for file_path in version_files.get(version_key, []):
|
||||
try:
|
||||
@@ -484,6 +502,28 @@ INSERT INTO fixed_assets (
|
||||
except OSError as exc:
|
||||
cls._log("warning", f"Failed to remove obsolete snapshot file {file_path}: {exc}")
|
||||
|
||||
@classmethod
|
||||
def _cleanup_history_snapshots(cls, keep_count: int | None = None) -> None:
|
||||
"""仅保留最新 N 份历史快照,额外旧文件自动清理。"""
|
||||
cls._ensure_storage_dirs()
|
||||
snapshots_dir = cls._snapshots_dir()
|
||||
cls._cleanup_temp_snapshot_files(snapshots_dir)
|
||||
safe_keep_count = max(1, int(keep_count or current_app.config.get("FIXED_ASSETS_HISTORY_KEEP_COUNT", 3) or 3))
|
||||
cls._cleanup_versioned_files(
|
||||
snapshots_dir,
|
||||
patterns=("FixedAssets_*.db", "FixedAssets_*.xlsx"),
|
||||
keep_count=safe_keep_count,
|
||||
)
|
||||
|
||||
if current_app.config.get("FIXED_ASSETS_EXPORT_TO_DOCS", True):
|
||||
docs_root = cls._docs_export_root()
|
||||
cls._cleanup_temp_snapshot_files(docs_root)
|
||||
cls._cleanup_versioned_files(
|
||||
docs_root,
|
||||
patterns=("FixedAssets_*.xlsx",),
|
||||
keep_count=safe_keep_count,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_snapshot_available(cls) -> bool:
|
||||
return cls._latest_db_path().exists()
|
||||
@@ -728,6 +768,7 @@ WITH deduped_assets AS (
|
||||
asset_no AS "资产编号",
|
||||
asset_name AS "资产名称",
|
||||
specification AS "规格型号",
|
||||
operating_center_code AS "账套",
|
||||
custodian_name AS "保管人姓名",
|
||||
department_name AS "保管部门名称",
|
||||
location_name AS "存放位置名称",
|
||||
|
||||
Reference in new issue
Block a user