feat: 代码生成功能适配pg数据库

This commit is contained in:
insistence
2025-02-18 11:36:33 +08:00
parent 15686b44ad
commit 2a486dc01e
11 changed files with 322 additions and 184 deletions

View File

@@ -12,10 +12,10 @@ from config.enums import BusinessType
from config.get_db import get_db
from module_admin.annotation.log_annotation import Log
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.entity.vo.user_vo import CurrentUserModel
from module_admin.service.login_service import LoginService
from {{ packageName }}.service.{{ businessName }}_service import {{ BusinessName }}Service
from {{ packageName }}.entity.vo.{{ businessName }}_vo import Delete{{ BusinessName }}Model, {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
from {{ packageName }}.entity.vo.user_vo import CurrentUserModel
from utils.common_util import bytes2file_response
from utils.log_util import logger
from utils.page_util import PageResponseModel
@@ -30,7 +30,7 @@ from utils.response_util import ResponseUtil
)
async def get_{{ moduleName }}_{{ businessName }}_list(
request: Request,
{{ businessName }}_page_query: {{ BusinessName }}PageQueryModel = Depends({{ BusinessName }}PageQueryModel.as_query),
{% if table.crud or table.sub %}{{ businessName }}_page_query{% elif table.tree %}{{ businessName }}_query{% endif %}: {{ BusinessName }}PageQueryModel = Depends({{ BusinessName }}PageQueryModel.as_query),
query_db: AsyncSession = Depends(get_db),
):
{% if table.crud or table.sub %}

View File

@@ -3,7 +3,7 @@
{% set pkParentheseIndex = pkColumn.column_comment.find("") %}
{% set pk_field_comment = pkColumn.column_comment[:pkParentheseIndex] if pkParentheseIndex != -1 else pkColumn.column_comment %}
{% for column in columns %}
{% if column.python_field == "createTime" %}
{% if column.query and column.query_type == 'BETWEEN' and column.python_field == "createTime" %}
from datetime import datetime, time
{% endif %}
{% endfor %}
@@ -12,8 +12,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
{% if table.sub %}
from sqlalchemy.orm import selectinload
{% endif %}
{% if table.sub %}
from {{ packageName }}.entity.do.{{ businessName }}_do import {{ ClassName }}, {{ subClassName }}
from {{ packageName }}.entity.vo.{{ businessName }}_vo import {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel, {{ subTable.business_name | capitalize }}Model
{% else %}
from {{ packageName }}.entity.do.{{ businessName }}_do import {{ ClassName }}
from {{ packageName }}.entity.vo.{{ businessName }}_vo import {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
{% endif %}
from utils.page_util import PageUtil

View File

@@ -75,7 +75,7 @@ class {{ BusinessName }}Service:
{% set parentheseIndex = column.column_comment.find("") %}
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
{% if column.required %}
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object)
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object):
raise ServiceException(message=f'新增{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
{% endif %}
{% endfor %}
@@ -83,8 +83,8 @@ class {{ BusinessName }}Service:
{% if table.sub %}
add_{{ businessName }} = await {{ BusinessName }}Dao.add_{{ businessName }}_dao(query_db, page_object)
if add_{{ businessName }}:
for sub_table in page_object.{{ subclassName }}_list:
await {{ BusinessName }}Dao.add_{{ subTable.business_name }}_dao(query_db, sub_table)
for sub_table in page_object.{{ subclassName }}_list:
await {{ BusinessName }}Dao.add_{{ subTable.business_name }}_dao(query_db, sub_table)
{% else %}
await {{ BusinessName }}Dao.add_{{ businessName }}_dao(query_db, page_object)
{% endif %}
@@ -110,7 +110,7 @@ class {{ BusinessName }}Service:
{% set parentheseIndex = column.column_comment.find("") %}
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
{% if column.required %}
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object)
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object):
raise ServiceException(message=f'修改{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
{% endif %}
{% endfor %}