From ebe7e0b6e030d2577f2fb8a36e69d25406ac1647 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Wed, 7 Aug 2024 08:38:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=85=A5=E5=9F=BA=E7=A1=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0012_alter_ecapi_description.py | 18 ++++ .../0013_alter_ecapiparams_description.py | 18 ++++ dspt_api/models.py | 4 +- dspt_api/util/insert_api_to_db.py | 100 ++++++++++++++++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 dspt_api/migrations/0012_alter_ecapi_description.py create mode 100644 dspt_api/migrations/0013_alter_ecapiparams_description.py create mode 100644 dspt_api/util/insert_api_to_db.py diff --git a/dspt_api/migrations/0012_alter_ecapi_description.py b/dspt_api/migrations/0012_alter_ecapi_description.py new file mode 100644 index 0000000..f9f6f4c --- /dev/null +++ b/dspt_api/migrations/0012_alter_ecapi_description.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-08-05 09:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0011_alter_ecrequestlog_request_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='ecapi', + name='description', + field=models.CharField(max_length=50, verbose_name='接口描述'), + ), + ] diff --git a/dspt_api/migrations/0013_alter_ecapiparams_description.py b/dspt_api/migrations/0013_alter_ecapiparams_description.py new file mode 100644 index 0000000..1f22563 --- /dev/null +++ b/dspt_api/migrations/0013_alter_ecapiparams_description.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-08-05 10:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0012_alter_ecapi_description'), + ] + + operations = [ + migrations.AlterField( + model_name='ecapiparams', + name='description', + field=models.CharField(max_length=5000, verbose_name='参数描述'), + ), + ] diff --git a/dspt_api/models.py b/dspt_api/models.py index c6b1448..b2419da 100644 --- a/dspt_api/models.py +++ b/dspt_api/models.py @@ -36,7 +36,7 @@ class EcEnv(models.Model): class EcApi(models.Model): id = models.IntegerField(primary_key=True) - description = models.CharField(verbose_name='接口描述', max_length=20, null=False) + description = models.CharField(verbose_name='接口描述', max_length=50, null=False) path = models.CharField(verbose_name='接口地址', max_length=50, null=False) type = models.CharField(verbose_name='会员非会员', max_length=20, default='', null=False) # 会员 member 非会员 nonmember @@ -53,7 +53,7 @@ class EcApiParams(models.Model): id = models.IntegerField(primary_key=True) api_id = models.IntegerField(verbose_name='接口id', null=False) param = models.CharField(verbose_name='参数', max_length=50, null=False) - description = models.CharField(verbose_name='参数描述', max_length=500, null=False) + description = models.CharField(verbose_name='参数描述', max_length=5000, null=False) value = models.CharField(verbose_name='参数值模版', max_length=500, null=True, blank=True) is_checked = models.BooleanField(verbose_name='是否默认勾选', null=False, default=False) is_request = models.BooleanField(verbose_name='是否是必选项', null=False, default=False) diff --git a/dspt_api/util/insert_api_to_db.py b/dspt_api/util/insert_api_to_db.py new file mode 100644 index 0000000..0e622d7 --- /dev/null +++ b/dspt_api/util/insert_api_to_db.py @@ -0,0 +1,100 @@ +import pymysql +from pymysql.cursors import DictCursor + +db_config = { + 'host': 'home.rogersun.cn', + 'database': 'dingxin_toolbox', + 'user': 'dingxin', + 'password': 'cine123456', + 'port': 3306, +} + +db_conn = pymysql.Connect(**db_config) +db_cursor = db_conn.cursor(DictCursor) + +api_data = { + 'desc': '3.5.4 发卡明细对账', + 'path': 'cinema/send-card-bill', + 'type': 'member', +} + +params_data = [ + { + 'param': 'format', + 'description': '返回数据格式:xml或json', + 'value': 'json', + 'is_checked': 1, + 'is_request': 1, + }, + { + 'param': 'pid', + 'description': '合作商id', + 'value': None, + 'is_checked': 1, + 'is_request': 1, + }, +{ + 'param': 'cid', + 'description': '影院ID', + 'value': None, + 'is_checked': 1, + 'is_request': 1, + }, +{ + 'param': 'start_date', + 'description': '对账开始日期 示例 2016-03-01', + 'value': None, + 'is_checked': 1, + 'is_request': 1, + }, +{ + 'param': 'end_date', + 'description': '对账结束日期 示例 2016-03-01', + 'value': None, + 'is_checked': 1, + 'is_request': 1, + }, +{ + 'param': 'start_order_time', + 'description': '查询订单开始时间,如:2016-03-01 00:00:00 首次调用不传,默认为{start_date 00:00:00},之后调用按返回字段startOrderTime进行调用该时间只能在start_date与end_date范围内', + 'value': None, + 'is_checked': 0, + 'is_request': 0, + }, +{ + 'param': 'page_len', + 'description': '每次获取订单数,默认1000。范围:大于等于1000,小于等于2000。', + 'value': None, + 'is_checked': 0, + 'is_request': 0, + }, +] +params_data.append({ + 'param': '_sig', + 'description': '接口签名', + 'value': None, + 'is_checked': 1, + 'is_request': 1, +}) + +api_sql = """ +insert into dingxin_toolbox.ec_api (id, description, path, type) +values (NULL, %s, %s, %s); +""" + +r = db_cursor.execute(api_sql, (api_data['desc'], api_data['path'], api_data['type'])) +db_conn.commit() + +get_id = """select id from dingxin_toolbox.ec_api where path = %s;""" +r1 = db_cursor.execute(get_id, (api_data['path'],)) +api_id = db_cursor.fetchone()['id'] +print(api_id) + +param_sql = """insert into dingxin_toolbox.ec_api_params (id, api_id, param, description, value, is_checked, is_request) +values (NULL, %s, %s, %s, %s, %s, %s);""" + +for param in params_data: + print(param) + r2 = db_cursor.execute(param_sql, ( + api_id, param['param'], param['description'], param['value'], param['is_checked'], param['is_request'])) +db_conn.commit()