From 2263c8231fb2b0cf2b540cd573454451c2b84670 Mon Sep 17 00:00:00 2001 From: whm <973418690@qq.com> Date: Sat, 29 Nov 2025 04:24:32 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8E=A8=E6=B5=8B=E5=B7=A5=E5=86=B5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=202.=E6=B5=8B=E7=82=B9=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/checkpoint.py | 3 +- app/services/checkpoint.py | 10 ++- app/utils/construction_monitor.py | 105 ++++++++++++++++++------------ app/utils/scheduler.py | 6 +- 4 files changed, 76 insertions(+), 48 deletions(-) diff --git a/app/api/checkpoint.py b/app/api/checkpoint.py index 83105d9..8b2f938 100644 --- a/app/api/checkpoint.py +++ b/app/api/checkpoint.py @@ -35,7 +35,7 @@ async def get_point_ids_by_linecode( checkpoint_service = CheckpointService() try: - point_ids = checkpoint_service.get_point_ids_by_linecode(db, request.linecode) + point_ids,point_id_dict = checkpoint_service.get_point_ids_by_linecode(db, request.linecode) return { "code": 0, @@ -43,6 +43,7 @@ async def get_point_ids_by_linecode( "data": { "linecode": request.linecode, "point_ids": point_ids, + "point_id_dict": point_id_dict, "count": len(point_ids) } } diff --git a/app/services/checkpoint.py b/app/services/checkpoint.py index 35528f5..947df22 100644 --- a/app/services/checkpoint.py +++ b/app/services/checkpoint.py @@ -254,10 +254,14 @@ class CheckpointService(BaseService[Checkpoint]): print(nyid_list) # 2. 根据NYID列表查询沉降数据表,获取所有point_id(去重) - point_id_query = db.query(SettlementData.point_id).filter( + point_id_query = db.query( + SettlementData.point_id + ).filter( SettlementData.NYID.in_(nyid_list) ).distinct() - point_id_list = [result.point_id for result in point_id_query.all() if result.point_id] + point_id_list = [f'{result.point_id}' for result in point_id_query.all() if result.point_id] + # -{db.query(Checkpoint.aname).filter(Checkpoint.point_id == result.point_id).first().aname} + point_id_dict = {item :db.query(Checkpoint.aname).filter(Checkpoint.point_id == item).first().aname for item in point_id_list} - return point_id_list + return point_id_list,point_id_dict diff --git a/app/utils/construction_monitor.py b/app/utils/construction_monitor.py index b3290a5..c7ec4a0 100644 --- a/app/utils/construction_monitor.py +++ b/app/utils/construction_monitor.py @@ -11,69 +11,90 @@ class ConstructionMonitorUtils: def __init__(self): # 原始工况周期映射表(保持不变) self.base_periods = { - "仰拱(底板)施工完成后,第1个月": 7, - "仰拱(底板)施工完成后,第2至3个月": 14, - "仰拱(底板)施工完成后,3个月以后": 30, - "无砟轨道铺设后,第1至3个月": 30, - "无砟轨道铺设后,4至12个月": 90, - "无砟轨道铺设后,12个月以后": 180, + + "仰拱(底板)施工完成后,第1个月": 7, + "仰拱(底板)施工完成后,第2至3个月": 14, + "仰拱(底板)施工完成后,3个月以后": 30, + "无砟轨道铺设后,第1至3个月": 30, + "无砟轨道铺设后,4至12个月": 90, + "无砟轨道铺设后,12个月以后": 180, "墩台施工到一定高度": 30, "墩台混凝土施工": 30, - "预制梁桥,架梁前": 30, - "预制梁桥,预制梁架设前": 1, - "预制梁桥,预制梁架设后": 7, - "桥位施工桥梁,制梁前": 30, - "桥位施工桥梁,上部结构施工中": 1, + "预制梁桥,架梁前": 30, + "预制梁桥,预制梁架设前": 1, + "预制梁桥,预制梁架设后": 7, + "桥位施工桥梁,制梁前": 30, + "桥位施工桥梁,上部结构施工中": 1, "架桥机(运梁车)通过": 7, "桥梁主体工程完工后,第1至3个月": 7, # 包含英文逗号的原始数据 - "桥梁主体工程完工后,第4至6个月": 14, - "桥梁主体工程完工后,6个月以后": 30, - "轨道铺设期间,前": 30, - "轨道铺设期间,后": 14, - "轨道铺设完成后,第1个月": 14, - "轨道铺设完成后,2至3个月": 30, - "轨道铺设完成后,4至12个月": 90, - "轨道铺设完成后,12个月以后": 180, - "填筑或堆载,一般情况": 1, - "填筑或堆载,沉降量突变情况": 1, - "填筑或堆载,两次填筑间隔时间较长情况": 3, # 该工况原周期为3天 - "堆载预压或路基填筑完成,第1至3个月": 7, - "堆载预压或路基填筑完成,第4至6个月": 14, - "堆载预压或路基填筑完成,6个月以后": 30, + "桥梁主体工程完工后,第4至6个月": 14, + "桥梁主体工程完工后,6个月以后": 30, + "轨道铺设期间,前": 30, + "轨道铺设期间,后": 14, + "轨道铺设完成后,第1个月": 14, + "轨道铺设完成后,2至3个月": 30, + "轨道铺设完成后,4至12个月": 90, + "轨道铺设完成后,12个月以后": 180, + "填筑或堆载,一般情况": 1, + "填筑或堆载,沉降量突变情况": 1, + "填筑或堆载,两次填筑间隔时间较长情况": 3, # 该工况原周期为3天 + "堆载预压或路基填筑完成,第1至3个月": 7, + "堆载预压或路基填筑完成,第4至6个月": 14, + "堆载预压或路基填筑完成,6个月以后": 30, "架桥机(运梁车)首次通过前": 1, - "架桥机(运梁车)首次通过后,前3天": 1, + "架桥机(运梁车)首次通过后,前3天": 1, "架桥机(运梁车)首次通过后": 7, - "轨道板(道床)铺设后,第1个月": 14, - "轨道板(道床)铺设后,第2至3个月": 30, - "轨道板(道床)铺设后,3个月以后": 90, - "架桥机(运梁车) 首次通过后": 7, - "架桥机(运梁车) 首次通过前": 1, + "轨道板(道床)铺设后,第1个月": 14, + "轨道板(道床)铺设后,第2至3个月": 30, + "轨道板(道床)铺设后,3个月以后": 90 } # 构建中英文括号+逗号兼容映射表 self.compatible_periods = self._build_compatible_brackets_map() + def _build_compatible_brackets_map(self) -> Dict[str, int]: - """构建支持中英文括号、中英文逗号的兼容映射表""" + """构建支持中英文括号、中英文逗号,且忽略所有空格的兼容映射表""" compatible_map = {} for original_key, period in self.base_periods.items(): - # 1. 保留原始key + # ========== 第一步:处理原始key的空格和符号,生成基础变体 ========== + # 1. 清洗空格:去除首尾+全角空格+合并连续空格+最终删除所有空格 + key_no_space = original_key.strip().replace(" ", " ").replace(" ", " ").replace(" ", "") + # 2. 原始key(未清洗空格) compatible_map[original_key] = period - - # 2. 生成中文括号版key + # 3. 无空格的原始符号key + if key_no_space not in compatible_map: + compatible_map[key_no_space] = period + + # ========== 第二步:生成中文括号变体(含空格/无空格) ========== + # 带空格的中文括号key chinese_bracket_key = original_key.replace("(", "(").replace(")", ")") - if chinese_bracket_key != original_key: + if chinese_bracket_key != original_key and chinese_bracket_key not in compatible_map: compatible_map[chinese_bracket_key] = period - - # 3. 生成英文逗号转中文逗号版key + # 无空格的中文括号key + chinese_bracket_no_space = key_no_space.replace("(", "(").replace(")", ")") + if chinese_bracket_no_space not in compatible_map: + compatible_map[chinese_bracket_no_space] = period + + # ========== 第三步:生成中文逗号变体(含空格/无空格) ========== + # 带空格的中文逗号key chinese_comma_key = original_key.replace(",", ",") - if chinese_comma_key != original_key: + if chinese_comma_key != original_key and chinese_comma_key not in compatible_map: compatible_map[chinese_comma_key] = period - - # 4. 生成中文括号+中文逗号混合版key + # 无空格的中文逗号key + chinese_comma_no_space = key_no_space.replace(",", ",") + if chinese_comma_no_space not in compatible_map: + compatible_map[chinese_comma_no_space] = period + + # ========== 第四步:生成中文括号+逗号混合变体(含空格/无空格) ========== + # 带空格的混合变体key mixed_key = chinese_bracket_key.replace(",", ",") if mixed_key != original_key and mixed_key not in compatible_map: compatible_map[mixed_key] = period - + # 无空格的混合变体key + mixed_no_space = chinese_bracket_no_space.replace(",", ",") + if mixed_no_space not in compatible_map: + compatible_map[mixed_no_space] = period + return compatible_map def get_due_data(self, input_data: List[List[Dict]], start: int = 0, end: int = 0, current_date: datetime = None) -> Dict[str, List[Dict]]: diff --git a/app/utils/scheduler.py b/app/utils/scheduler.py index eb8ba2b..2cdfc1d 100644 --- a/app/utils/scheduler.py +++ b/app/utils/scheduler.py @@ -241,6 +241,7 @@ def scheduled_get_max_nyid_by_point_id(start: int = 0,end: int = 0): # 2. 计算到期数据 monitor = ConstructionMonitorUtils() daily_data = monitor.get_due_data(result,start=start,end=end) + print(daily_data) # time.sleep(10000) data = daily_data['data'] error_data = daily_data['error_data'] @@ -256,7 +257,6 @@ def scheduled_get_max_nyid_by_point_id(start: int = 0,end: int = 0): print(max_num) # 提取冬休数据的point_id列表 new_list = [int(w['point_id']) for w in winters] - print(new_list) # 获取更多历史记录 nyid_list = daily_service.get_nyid_by_point_id(db, new_list, max_num) w_list = monitor.get_due_data(nyid_list,start=start,end=end) @@ -298,7 +298,7 @@ def scheduled_get_max_nyid_by_point_id(start: int = 0,end: int = 0): d['account_data'] = account_response.__dict__ if account_response else None else: d['account_data'] = None - print(f"一共有{len(data)}条数据{data}") + print(f"一共有{len(data)}条数据") # 6. 构造DailyData数据并批量创建 # daily_create_data1 = set() daily_create_data = [] @@ -320,6 +320,8 @@ def scheduled_get_max_nyid_by_point_id(start: int = 0,end: int = 0): daily_create_data.append(tem) # 批量创建记录 if daily_create_data: + # with open('data.json', 'w', encoding='utf-8') as f: + # json.dump(daily_create_data, f, ensure_ascii=False, indent=4) created_records = daily_service.batch_create_by_account_nyid(db, daily_create_data) logger.info(f"定时任务完成:成功创建{len(created_records)}条DailyData记录,共处理{len(data)}个point_id数据") else: