Commit fe703f3c authored by wanli's avatar wanli

update

parent 33028d70
# 代码生成工具
使用Python Jinja2模板引擎,自动生成代码。
......@@ -2,7 +2,8 @@
"application": {},
"controllers": [
{
"className": "",
"className": "CacheDataResource",
"modelName": "cache_data",
"post": {},
"delete": {},
"get": {},
......@@ -49,8 +50,8 @@
]
},
{
"tableName": "cache_data",
"className": "CacheDataModel",
"tableName": "cache_data",
"fields": [
{
"name": "id",
......@@ -104,13 +105,15 @@
]
}
],
"resources": [
"views": [
{
"post": {},
"delete": {},
"get": {},
"put": {},
"router": ""
"name": "",
"path": "/test/<string:id>",
"className": ""
}
],
"utils": []
......
......@@ -4,9 +4,12 @@ def handleResources():
pass
def handleController():
# 根据模型字段自动从models列表中取出file name信息和class name信息
pass
def handleModel():
# 将所有有默认值的字段分为一组,没有默认值的字段分为另一组
# 生成模板代码时,无默认值的字段在前,有默认值的字段字在后
pass
def hanleRender():
......
# -*- coding: utf-8 -*-
\ No newline at end of file
......@@ -30,6 +30,3 @@ class MyModel(MyMixin, Base):
name = Column(String(1000))
db = SQLAlchemy()
\ No newline at end of file
class BaseModel(db.Model):
id = Column(Integer, primary_key=True)
\ No newline at end of file
......@@ -4,7 +4,7 @@ import uuid
from datetime import datetime
from . import db
class BaseModel(object):
class BaseModel(db.Model):
create_date = db.Column(db.DateTime, default=datetime.now)
create_by = db.Column(db.String(64))
update_date = db.Column(db.DateTime, default=datetime.now)
......
# -*- coding: utf-8 -*-
\ No newline at end of file
# -*- coding: utf-8 -*-
from flask import Blueprint
from flask_restful import Api
from . import .
api_v1 = Blueprint('api_v1', __name__)
api = Api(api_v1)
api.add_resource(area.AreaListResource, '/area/', endpoint='area')
api.add_resource(area.AreaResource, '/area/<int:id>')
api.add_resource(cache_data.CacheDataListResource, '/cache', endpoint='cache')
api.add_resource(company_contact.ContactListResource, '/companyPhone/')
api.add_resource(company_contact.ContactResource, '/companyPhone/<int:id>')
api.add_resource(company.CompanyListResource, '/company/')
api.add_resource(company.ExtendCompanyResource, '/company/openApi')
api.add_resource(company.CompanyResource, '/company/<string:id>')
api.add_resource(dictionary.DictListResource, '/dictionary/')
api.add_resource(dictionary.ExtendDictResource, '/dictionary/groupBy')
api.add_resource(dictionary.DictResource, '/dictionary/<int:id>')
api.add_resource(equipment_attrs.AttrsListResource, '/equipmentAttributes/')
api.add_resource(equipment_attrs.AttrsResource, '/equipmentAttributes/<string:id>')
api.add_resource(equipment_attrs.AttrValuesListResource, '/equipmentAttributes/attr/')
api.add_resource(equipment_attrs.AttrValuesResource, '/equipmentAttributes/attr/<string:id>')
api.add_resource(equipment_login.LoginListResource, '/equipmentLoginLog/')
api.add_resource(equipment_msg.MessageListResource, '/equipmentMessage/')
api.add_resource(equipment_type.TypeListResource, '/equipmentTypes/')
api.add_resource(equipment_type.TypeResource, '/equipmentTypes/<string:id>')
api.add_resource(equipment_phone.PhoneListResource, '/equipmentPhone/')
api.add_resource(equipment_phone.PhoneResource, '/equipmentPhone/<int:id>')
api.add_resource(terminal_code.CodeListResource, '/equipmentTerminalCode/')
api.add_resource(equipment_operate.OperateLogListResource, '/terminalLog/')
api.add_resource(equipment_parameters.ParameterListResource, '/equipmentParameter/')
api.add_resource(equipment_parameters.ParameterResource, '/equipmentParameter/<int:id>')
api.add_resource(equipment_parameters.CustomParametersResource, '/parameters/custom/')
api.add_resource(equipment_history_data.HistoryDataResource, '/historyData/<string:id>/')
api.add_resource(equipment_history_data.HistoryChartResource, '/historyData/chart/<string:id>/')
api.add_resource(equipment_now_data.NowDataListResource, '/equipmentNowData/')
api.add_resource(equipment_now_data.NowDataResource, '/equipmentNowData/<string:id>')
api.add_resource(equipment_now_data.ChartDataResource, '/equipmentNowData/chart/<string:id>')
api.add_resource(equipment.EquipmentListResource, '/equipment/')
api.add_resource(equipment.EquipmentResource, '/equipment/<string:id>')
api.add_resource(equipment.ExtendEquipmentResource, '/equipment/exists')
api.add_resource(equipment.EquipmentsConfig, '/equipment/config')
api.add_resource(equipment.LabEquipmentResource, '/equipment/getLabEquipment')
api.add_resource(equipment.TerminalCodeResource, '/equipment/getTerminalCode')
api.add_resource(user.UserListResource, '/user/')
api.add_resource(user.UserResource, '/user/<string:id>')
api.add_resource(user.ExtendUserResource, '/user/updateOperation/<string:id>')
api.add_resource(user_weixin.UserWeiXinListResource, '/userWeixin/')
api.add_resource(user_weixin.UserWeiXinResource, '/userWeixin/<string:id>')
api.add_resource(warning_report.WarningReportListResource, '/warningReport/')
api.add_resource(warning_type.WarningTypeListResource, '/warningTypes/')
api.add_resource(warning_type.WarningTypeResource, '/warningTypes/<string:id>')
api.add_resource(firmware.FirmwareListResource, '/firmware/')
api.add_resource(firmware.FirmwareResource, '/firmware/<int:id>')
api.add_resource(menu.MenuListResource, '/menu/')
api.add_resource(menu.MenuResource, '/menu/<string:id>')
api.add_resource(operation.OperationListResource, '/operation/')
api.add_resource(operation.OperationResource, '/operation/<string:id>')
api.add_resource(operation.UserOperationResource, '/operation/getUserOperation/<string:user>')
api.add_resource(operation.MenuOperationResource, '/operation/getMenuOperation/')
api.add_resource(role.RoleListResource, '/role/')
api.add_resource(role.RoleResource, '/role/<string:id>')
api.add_resource(role_user.RoleUserListResource, '/roleUser/')
api.add_resource(role_permission.RolePermissionListResource, '/rolePermission/')
api.add_resource(role_permission.RolePermissionResource, '/rolePermission/<string:id>')
api.add_resource(role_permission.ExtendRolePermission, '/rolePermission/type/<string:type>')
api.add_resource(permission.PermissionListResource, '/permission/')
api.add_resource(permission.PermissionResource, '/permission/<string:id>')
api.add_resource(permission_related.RelatedListResource, '/permissionRelated/')
api.add_resource(permission_related.ExtendRelatedResource, '/permissionRelated/batch/')
api.add_resource(permission_related.RelatedResource, '/permissionRelated/<string:id>')
api.add_resource(public.UserInfoResource, '/public/login')
api.add_resource(public.FileResource, '/public/fileRequest/')
api.add_resource(public.WeixinLogin, '/public/weixin/login/')
api.add_resource(public.BackstageResource, '/public/equipmentMap')
api.add_resource(public.SystemResource, '/public/dashboard')
api.add_resource(public.LogoutResource, '/public/logout')
api.add_resource(containers.ContainerListResource, '/containers/')
api.add_resource(synchronous.CompanySyncResource, '/synchronous/company/')
api.add_resource(synchronous.EquipmentSyncResource, '/synchronous/equipment/')
api.add_resource(synchronous.CompanyThirdPartySyncResource, '/synchronous/thirdparty/company/')
api.add_resource(synchronous.EquipmentThirdPartySyncResource, '/synchronous/thirdparty/equipment/')
api.add_resource(synchronous.UserSyncResource, '/synchronous/user/')
api.add_resource(report.ReportResource, '/report/')
api.add_resource(openapi.APIEquipmentResource, '/openapi/equipment/')
\ No newline at end of file
from models import db
from models.{{ file_name }} import {{ class_name }}
class {{ className }}(object):
def __init__(self):
super({{ className }}, self).__init__()
def get(self, params):
# handle business code
pass
def post(self, params):
# handle business code
pass
def put(self, params):
# handle business code
pass
def delete(self, params):
# handle business code
pass
\ No newline at end of file
......@@ -4,44 +4,24 @@ from . import db
from datetime import datetime
from .base import BaseModel, PrimaryModel
class AreaModel(db.Model):
__tablename__ = 'qj_area'
areaId = db.Column(db.Integer, primary_key = True, autoincrement = True)
areaCode = db.Column(db.String(20), index = True)
areaName = db.Column(db.String(20), index = True)
level = db.Column(db.SmallInteger, index = True, default = 0)
cityCode = db.Column(db.String(20))
center = db.Column(db.String(50))
parentId = db.Column(db.Integer, index = True)
hasChildren = db.Column(db.Boolean)
create_date = db.Column(db.DateTime, default=datetime.now)
create_by = db.Column(db.String(64))
update_date = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
update_by = db.Column(db.String(64))
sort = db.Column(db.Integer)
del_flag = db.Column(db.Boolean)
class {{ className }}(db.Model):
__tablename__ = '{{ tableName }}'
{% for key, value in fields.items() %}
{% if value.get('primaryKey', None) %}
value.get('name') = db.Column(db.{{ value.get('dataType') }}, primary_key = True, {% if value.get('autoIncrement') %}autoincrement = True{% endif %})
{% else %}
value.get('name') = db.Column(db.{{ value.get('dataType') }}{% if value.get("length", None) %}(value.get("length")){% endif %}{% if value.get("index", False) %}, index = True{% endif %}{% if value.get("default", None) %}, default = value.get("default"){% endif %})
{% endif %}
{% endfor %}
# __table_args__ = (
# db.Index('idx_areaName', 'areaName', mysql_using='btree'),
# db.Index('idx_areaCode', 'areaCode', mysql_using='btree'),
# db.Index('idx_parentId', 'parentId', mysql_using='btree'),
# db.Index('idx_level', 'level', mysql_using='btree')
# )
def __init__(self, areaCode, areaName, cityCode, center, create_date, update_date, level = 0, parentId = 0, hasChildren = 0, create_by = None, update_by = None, sort = 0, del_flag = 0):
self.areaCode = areaCode
self.areaName = areaName
self.level = level
self.cityCode = cityCode
self.center = center
self.parentId = parentId
self.hasChildren = hasChildren
self.create_date = create_date
self.create_by = create_by
self.update_date = update_date
self.update_by = update_by
self.sort = sort
self.del_flag = del_flag
def __init__(self{% for for key, value in fields.items() %}, {{ value.get("name") }}{% endfor %}):
{% for key, value in fields.items() %}
self.{{ value.get("name") }} = {{ value.get("name") }}
{% endfor %}
def __repr__(self):
return '<Area %r>' % (self.areaId)
return '<{{ className }} %r>' % (self.{{ fields[0]["name"] }})
# -*- coding: utf-8 -*-
from flask import Blueprint
from flask_restful import Api
from . import {% for i, router in enumerate(routers) in %}{% if i != 0 %},{% endif %}{{ router }}{% endfor %}
api_v1 = Blueprint('api_v1', __name__)
api = Api(api_v1)
{% for v in views %}
api.add_resource({{ name }}.{{ clasName }}, '{{ path }}'{% if endpoint %}, endpoint={{ endpoint }}{% endif %})
{% endfor %}
from flask import current_app
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
from flask_jwt_extended import ( jwt_required, get_jwt_identity )
from common import code, pretty_result
class {{ className }}(Resource):
def __init__(self):
self.parser = RequestParser()
@jwt_required
def get(self):
self.parser.add_argument("currentPage", type=int, location="args", default=1)
self.parser.add_argument("pageSize", type=int, location="args", default=15)
self.parser.add_argument("equipment", type=int, location="args", required=False)
args = self.parser.parse_args()
try:
except Exception as e:
current_app.logger.error(e)
db.session.rollback()
return pretty_result(code.DB_ERROR)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment