注入基础数据

main
RogerWork 3 months ago
parent e87526749f
commit ebe7e0b6e0
  1. 18
      dspt_api/migrations/0012_alter_ecapi_description.py
  2. 18
      dspt_api/migrations/0013_alter_ecapiparams_description.py
  3. 4
      dspt_api/models.py
  4. 100
      dspt_api/util/insert_api_to_db.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='接口描述'),
),
]

@ -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='参数描述'),
),
]

@ -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)

@ -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()
Loading…
Cancel
Save