Skip to content

Commit 8dc0c46

Browse files
noahchiwyyalt
authored andcommitted
feat: 增加业务信息表 (closed #378)
1 parent a78858e commit 8dc0c46

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.15 on 2025-04-14 04:05
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("gsekit", "0015_auto_20230714_1639"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="job",
15+
name="bk_app_code",
16+
field=models.CharField(default="gsekit2", max_length=32, verbose_name="蓝鲸应用ID"),
17+
),
18+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 3.2.15 on 2025-04-14 04:09
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("gsekit", "0016_alter_job_bk_app_code"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="Business",
15+
fields=[
16+
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
17+
("bk_biz_id", models.IntegerField(verbose_name="业务 ID")),
18+
("bk_biz_name", models.CharField(max_length=255, verbose_name="业务名称")),
19+
("created_at", models.DateTimeField(auto_now_add=True)),
20+
("updated_at", models.DateTimeField(auto_now=True)),
21+
],
22+
options={
23+
"verbose_name": "业务信息",
24+
"verbose_name_plural": "业务信息",
25+
},
26+
),
27+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Tencent is pleased to support the open source community by making 蓝鲸 (Blueking) available.
4+
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and limitations under the License.
10+
"""
11+
from celery.task import periodic_task
12+
from celery.schedules import crontab
13+
from apps.api import CCApi
14+
15+
from blueapps.utils.logger import logger
16+
17+
from apps.gsekit.process.models import Business
18+
19+
20+
@periodic_task(run_every=crontab(hour=0, minute=0))
21+
def sync_business():
22+
all_biz_list = CCApi.search_business({"fields": ["bk_biz_id", "bk_biz_name"]}, use_admin=True).get("info") or []
23+
24+
for item in all_biz_list:
25+
bk_biz_id = item.get("bk_biz_id")
26+
bk_biz_name = item.get("bk_biz_name")
27+
try:
28+
# 假设 bk_biz_id 是唯一标识,根据它来查找记录
29+
Business.objects.update_or_create(bk_biz_id=bk_biz_id, defaults={"bk_biz_name": bk_biz_name})
30+
except Exception as e:
31+
logger.info(f"处理数据 {bk_biz_id} 时出现错误: {e}")

apps/gsekit/process/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,19 @@ class Meta:
140140
]
141141
verbose_name = _("进程实例(ProcessInst)")
142142
verbose_name_plural = _("进程实例(ProcessInst)")
143+
144+
145+
class Business(models.Model):
146+
bk_biz_id = models.IntegerField(verbose_name="业务 ID")
147+
bk_biz_name = models.CharField(max_length=255, verbose_name="业务名称")
148+
# 记录对象的创建时间,在对象首次创建时自动设置
149+
created_at = models.DateTimeField(auto_now_add=True)
150+
# 记录对象的最后修改时间,每次对象保存时自动更新
151+
updated_at = models.DateTimeField(auto_now=True)
152+
153+
def __str__(self):
154+
return self.bk_biz_name
155+
156+
class Meta:
157+
verbose_name = "业务信息"
158+
verbose_name_plural = verbose_name

0 commit comments

Comments
 (0)