diff --git a/jcloud/api/domain_west.py b/jcloud/api/domain_west.py index 215e800..8a3bf02 100644 --- a/jcloud/api/domain_west.py +++ b/jcloud/api/domain_west.py @@ -1050,12 +1050,46 @@ def west_domain_add_dns_record(**data): error_msg = response.get('msg', response.get('message', '未知错误')) return {"status": "error", "message": f"添加DNS记录失败: {error_msg}"} + # 获取新增记录的ID + record_id = response.get("data", {}).get("id") + + # 异步添加记录到本地数据库 + if record_id: + try: + # 查找对应的域名记录 + domain_records = jingrow.get_all( + "Jsite Domain", + {"domain": domain}, + ["name"] + ) + + if domain_records: + domain_record = domain_records[0] + jingrow.enqueue( + "jingrow.client.insert_pg", + pg={ + "pagetype": "Dns Resolution", + "parenttype": "Jsite Domain", + "parent": domain_record.name, + "parentfield": "dns_resolution", + "host": host, + "type": record_type, + "value": value, + "ttl": str(ttl), + "level": str(level), + "line": line, + "record_id": record_id + } + ) + except Exception as e: + jingrow.log_error(f"域名 {domain} DNS记录异步添加失败", f"错误: {str(e)}") + # 返回成功结果 return { "status": "success", "message": "DNS记录添加成功", "data": { - "id": response.get("data", {}).get("id"), + "id": record_id, "domain": domain, "host": host, "type": record_type, diff --git a/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.json b/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.json index 65fffa9..975ff90 100644 --- a/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.json +++ b/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.json @@ -5,6 +5,7 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "record_id", "host", "type", "line", @@ -69,13 +70,20 @@ "fieldtype": "Data", "in_list_view": 1, "label": "状态" + }, + { + "columns": 1, + "fieldname": "record_id", + "fieldtype": "Data", + "label": "记录ID", + "read_only": 1 } ], "grid_page_length": 50, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2025-07-31 20:34:50.907647", + "modified": "2025-08-05 01:00:02.459889", "modified_by": "Administrator", "module": "Jcloud", "name": "Dns Resolution", diff --git a/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.py b/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.py index ce454b1..a04a6af 100644 --- a/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.py +++ b/jcloud/jcloud/pagetype/dns_resolution/dns_resolution.py @@ -20,6 +20,7 @@ class DnsResolution(Document): parent: DF.Data parentfield: DF.Data parenttype: DF.Data + record_id: DF.Data | None record_status: DF.Data | None ttl: DF.Data | None type: DF.Literal["", "A", "CNAME", "MX", "TXT", "AAAA", "SRV"]