|
| 1 | +from config.env import DataBaseConfig |
| 2 | + |
| 3 | + |
1 | 4 | class CommonConstant: |
2 | 5 | """ |
3 | 6 | 常用常量 |
@@ -150,3 +153,329 @@ class MenuConstant: |
150 | 153 | LAYOUT = 'Layout' |
151 | 154 | PARENT_VIEW = 'ParentView' |
152 | 155 | INNER_LINK = 'InnerLink' |
| 156 | + |
| 157 | + |
| 158 | +class GenConstant: |
| 159 | + """ |
| 160 | + 代码生成常量 |
| 161 | +
|
| 162 | + TPL_CRUD: 单表(增删改查 |
| 163 | + TPL_TREE: 树表(增删改查) |
| 164 | + TPL_SUB: 主子表(增删改查) |
| 165 | + TREE_CODE: 树编码字段 |
| 166 | + TREE_PARENT_CODE: 树父编码字段 |
| 167 | + TREE_NAME: 树名称字段 |
| 168 | + PARENT_MENU_ID: 上级菜单ID字段 |
| 169 | + PARENT_MENU_NAME: 上级菜单名称字段 |
| 170 | + COLUMNTYPE_STR: 数据库字符串类型 |
| 171 | + COLUMNTYPE_TEXT: 数据库文本类型 |
| 172 | + COLUMNTYPE_TIME: 数据库时间类型 |
| 173 | + COLUMNTYPE_GEOMETRY: 数据库字空间类型 |
| 174 | + COLUMNTYPE_NUMBER: 数据库数字类型 |
| 175 | + COLUMNNAME_NOT_EDIT: 页面不需要编辑字段 |
| 176 | + COLUMNNAME_NOT_LIST: 页面不需要显示的列表字段 |
| 177 | + COLUMNNAME_NOT_QUERY: 页面不需要查询字段 |
| 178 | + BASE_ENTITY: Entity基类字段 |
| 179 | + TREE_ENTITY: Tree基类字段 |
| 180 | + HTML_INPUT: 文本框 |
| 181 | + HTML_TEXTAREA: 文本域 |
| 182 | + HTML_SELECT: 下拉框 |
| 183 | + HTML_RADIO: 单选框 |
| 184 | + HTML_CHECKBOX: 复选框 |
| 185 | + HTML_DATETIME: 日期控件 |
| 186 | + HTML_IMAGE_UPLOAD: 图片上传控件 |
| 187 | + HTML_FILE_UPLOAD: 文件上传控件 |
| 188 | + HTML_EDITOR: 富文本控件 |
| 189 | + TYPE_DECIMAL: 高精度计算类型 |
| 190 | + TYPE_DATE: 时间类型 |
| 191 | + QUERY_LIKE: 模糊查询 |
| 192 | + QUERY_EQ: 相等查询 |
| 193 | + REQUIRE: 需要 |
| 194 | + DB_TO_SQLALCHEMY_TYPE_MAPPING: 数据库类型与sqlalchemy类型映射 |
| 195 | + DB_TO_PYTHON_TYPE_MAPPING: 数据库类型与python类型映射 |
| 196 | + """ |
| 197 | + |
| 198 | + TPL_CRUD = 'crud' |
| 199 | + TPL_TREE = 'tree' |
| 200 | + TPL_SUB = 'sub' |
| 201 | + TREE_CODE = 'treeCode' |
| 202 | + TREE_PARENT_CODE = 'treeParentCode' |
| 203 | + TREE_NAME = 'treeName' |
| 204 | + PARENT_MENU_ID = 'parentMenuId' |
| 205 | + PARENT_MENU_NAME = 'parentMenuName' |
| 206 | + COLUMNTYPE_STR = ( |
| 207 | + ['character varying', 'varchar', 'character', 'char'] |
| 208 | + if DataBaseConfig.db_type == 'postgresql' |
| 209 | + else ['char', 'varchar', 'nvarchar', 'varchar2'] |
| 210 | + ) |
| 211 | + COLUMNTYPE_TEXT = ( |
| 212 | + ['text', 'citext'] if DataBaseConfig.db_type == 'postgresql' else ['tinytext', 'text', 'mediumtext', 'longtext'] |
| 213 | + ) |
| 214 | + COLUMNTYPE_TIME = ( |
| 215 | + [ |
| 216 | + 'date', |
| 217 | + 'time', |
| 218 | + 'time with time zone', |
| 219 | + 'time without time zone', |
| 220 | + 'timestamp', |
| 221 | + 'timestamp with time zone', |
| 222 | + 'timestamp without time zone', |
| 223 | + 'interval', |
| 224 | + ] |
| 225 | + if DataBaseConfig.db_type == 'postgresql' |
| 226 | + else ['datetime', 'time', 'date', 'timestamp'] |
| 227 | + ) |
| 228 | + COLUMNTYPE_GEOMETRY = ( |
| 229 | + ['point', 'line', 'lseg', 'box', 'path', 'polygon', 'circle'] |
| 230 | + if DataBaseConfig.db_type == 'postgresql' |
| 231 | + else [ |
| 232 | + 'geometry', |
| 233 | + 'point', |
| 234 | + 'linestring', |
| 235 | + 'polygon', |
| 236 | + 'multipoint', |
| 237 | + 'multilinestring', |
| 238 | + 'multipolygon', |
| 239 | + 'geometrycollection', |
| 240 | + ] |
| 241 | + ) |
| 242 | + COLUMNTYPE_NUMBER = [ |
| 243 | + 'tinyint', |
| 244 | + 'smallint', |
| 245 | + 'mediumint', |
| 246 | + 'int', |
| 247 | + 'number', |
| 248 | + 'integer', |
| 249 | + 'bit', |
| 250 | + 'bigint', |
| 251 | + 'float', |
| 252 | + 'double', |
| 253 | + 'decimal', |
| 254 | + ] |
| 255 | + COLUMNNAME_NOT_EDIT = ['id', 'create_by', 'create_time', 'del_flag'] |
| 256 | + COLUMNNAME_NOT_LIST = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time'] |
| 257 | + COLUMNNAME_NOT_QUERY = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time', 'remark'] |
| 258 | + BASE_ENTITY = ['createBy', 'createTime', 'updateBy', 'updateTime', 'remark'] |
| 259 | + TREE_ENTITY = ['parentName', 'parentId', 'orderNum', 'ancestors', 'children'] |
| 260 | + HTML_INPUT = 'input' |
| 261 | + HTML_TEXTAREA = 'textarea' |
| 262 | + HTML_SELECT = 'select' |
| 263 | + HTML_RADIO = 'radio' |
| 264 | + HTML_CHECKBOX = 'checkbox' |
| 265 | + HTML_DATETIME = 'datetime' |
| 266 | + HTML_IMAGE_UPLOAD = 'imageUpload' |
| 267 | + HTML_FILE_UPLOAD = 'fileUpload' |
| 268 | + HTML_EDITOR = 'editor' |
| 269 | + TYPE_DECIMAL = 'Decimal' |
| 270 | + TYPE_DATE = ['date', 'time', 'datetime'] |
| 271 | + QUERY_LIKE = 'LIKE' |
| 272 | + QUERY_EQ = 'EQ' |
| 273 | + REQUIRE = '1' |
| 274 | + DB_TO_SQLALCHEMY_TYPE_MAPPING = ( |
| 275 | + { |
| 276 | + 'boolean': 'Boolean', |
| 277 | + 'smallint': 'SmallInteger', |
| 278 | + 'integer': 'Integer', |
| 279 | + 'bigint': 'BigInteger', |
| 280 | + 'real': 'Float', |
| 281 | + 'double precision': 'Float', |
| 282 | + 'numeric': 'Numeric', |
| 283 | + 'character varying': 'String', |
| 284 | + 'character': 'String', |
| 285 | + 'text': 'Text', |
| 286 | + 'bytea': 'LargeBinary', |
| 287 | + 'date': 'Date', |
| 288 | + 'time': 'Time', |
| 289 | + 'time with time zone': 'Time', |
| 290 | + 'time without time zone': 'Time', |
| 291 | + 'timestamp': 'DateTime', |
| 292 | + 'timestamp with time zone': 'DateTime', |
| 293 | + 'timestamp without time zone': 'DateTime', |
| 294 | + 'interval': 'Interval', |
| 295 | + 'json': 'JSON', |
| 296 | + 'jsonb': 'JSONB', |
| 297 | + 'uuid': 'Uuid', |
| 298 | + 'inet': 'INET', |
| 299 | + 'cidr': 'CIDR', |
| 300 | + 'macaddr': 'MACADDR', |
| 301 | + 'point': 'Geometry', |
| 302 | + 'line': 'Geometry', |
| 303 | + 'lseg': 'Geometry', |
| 304 | + 'box': 'Geometry', |
| 305 | + 'path': 'Geometry', |
| 306 | + 'polygon': 'Geometry', |
| 307 | + 'circle': 'Geometry', |
| 308 | + 'bit': 'Bit', |
| 309 | + 'bit varying': 'Bit', |
| 310 | + 'tsvector': 'TSVECTOR', |
| 311 | + 'tsquery': 'TSQUERY', |
| 312 | + 'xml': 'String', |
| 313 | + 'array': 'ARRAY', |
| 314 | + 'composite': 'JSON', |
| 315 | + 'enum': 'Enum', |
| 316 | + 'range': 'Range', |
| 317 | + 'money': 'Numeric', |
| 318 | + 'pg_lsn': 'BigInteger', |
| 319 | + 'txid_snapshot': 'String', |
| 320 | + 'oid': 'BigInteger', |
| 321 | + 'regproc': 'String', |
| 322 | + 'regclass': 'String', |
| 323 | + 'regtype': 'String', |
| 324 | + 'regrole': 'String', |
| 325 | + 'regnamespace': 'String', |
| 326 | + 'int2vector': 'ARRAY', |
| 327 | + 'oidvector': 'ARRAY', |
| 328 | + 'pg_node_tree': 'Text', |
| 329 | + } |
| 330 | + if DataBaseConfig.db_type == 'postgresql' |
| 331 | + else { |
| 332 | + # 数值类型 |
| 333 | + 'TINYINT': 'SmallInteger', |
| 334 | + 'SMALLINT': 'SmallInteger', |
| 335 | + 'MEDIUMINT': 'Integer', |
| 336 | + 'INT': 'Integer', |
| 337 | + 'INTEGER': 'Integer', |
| 338 | + 'BIGINT': 'BigInteger', |
| 339 | + 'FLOAT': 'Float', |
| 340 | + 'DOUBLE': 'Float', |
| 341 | + 'DECIMAL': 'DECIMAL', |
| 342 | + 'BIT': 'Integer', |
| 343 | + # 日期和时间类型 |
| 344 | + 'DATE': 'Date', |
| 345 | + 'TIME': 'Time', |
| 346 | + 'DATETIME': 'DateTime', |
| 347 | + 'TIMESTAMP': 'TIMESTAMP', |
| 348 | + 'YEAR': 'Integer', |
| 349 | + # 字符串类型 |
| 350 | + 'CHAR': 'CHAR', |
| 351 | + 'VARCHAR': 'String', |
| 352 | + 'TINYTEXT': 'Text', |
| 353 | + 'TEXT': 'Text', |
| 354 | + 'MEDIUMTEXT': 'Text', |
| 355 | + 'LONGTEXT': 'Text', |
| 356 | + 'BINARY': 'BINARY', |
| 357 | + 'VARBINARY': 'VARBINARY', |
| 358 | + 'TINYBLOB': 'LargeBinary', |
| 359 | + 'BLOB': 'LargeBinary', |
| 360 | + 'MEDIUMBLOB': 'LargeBinary', |
| 361 | + 'LONGBLOB': 'LargeBinary', |
| 362 | + # 枚举和集合类型 |
| 363 | + 'ENUM': 'Enum', |
| 364 | + 'SET': 'String', |
| 365 | + # JSON 类型 |
| 366 | + 'JSON': 'JSON', |
| 367 | + # 空间数据类型(需要扩展支持,如 GeoAlchemy2) |
| 368 | + 'GEOMETRY': 'Geometry', # 需要安装 geoalchemy2 |
| 369 | + 'POINT': 'Geometry', |
| 370 | + 'LINESTRING': 'Geometry', |
| 371 | + 'POLYGON': 'Geometry', |
| 372 | + 'MULTIPOINT': 'Geometry', |
| 373 | + 'MULTILINESTRING': 'Geometry', |
| 374 | + 'MULTIPOLYGON': 'Geometry', |
| 375 | + 'GEOMETRYCOLLECTION': 'Geometry', |
| 376 | + } |
| 377 | + ) |
| 378 | + DB_TO_PYTHON_TYPE_MAPPING = ( |
| 379 | + { |
| 380 | + 'boolean': 'bool', |
| 381 | + 'smallint': 'int', |
| 382 | + 'integer': 'int', |
| 383 | + 'bigint': 'int', |
| 384 | + 'real': 'float', |
| 385 | + 'double precision': 'float', |
| 386 | + 'numeric': 'Decimal', |
| 387 | + 'character varying': 'str', |
| 388 | + 'character': 'str', |
| 389 | + 'text': 'str', |
| 390 | + 'bytea': 'bytes', |
| 391 | + 'date': 'date', |
| 392 | + 'time': 'time', |
| 393 | + 'time with time zone': 'time', |
| 394 | + 'time without time zone': 'time', |
| 395 | + 'timestamp': 'datetime', |
| 396 | + 'timestamp with time zone': 'datetime', |
| 397 | + 'timestamp without time zone': 'datetime', |
| 398 | + 'interval': 'timedelta', |
| 399 | + 'json': 'dict', |
| 400 | + 'jsonb': 'dict', |
| 401 | + 'uuid': 'str', |
| 402 | + 'inet': 'str', |
| 403 | + 'cidr': 'str', |
| 404 | + 'macaddr': 'str', |
| 405 | + 'point': 'list', |
| 406 | + 'line': 'list', |
| 407 | + 'lseg': 'list', |
| 408 | + 'box': 'list', |
| 409 | + 'path': 'list', |
| 410 | + 'polygon': 'list', |
| 411 | + 'circle': 'list', |
| 412 | + 'bit': 'int', |
| 413 | + 'bit varying': 'int', |
| 414 | + 'tsvector': 'str', |
| 415 | + 'tsquery': 'str', |
| 416 | + 'xml': 'str', |
| 417 | + 'array': 'list', |
| 418 | + 'composite': 'dict', |
| 419 | + 'enum': 'str', |
| 420 | + 'range': 'list', |
| 421 | + 'money': 'Decimal', |
| 422 | + 'pg_lsn': 'int', |
| 423 | + 'txid_snapshot': 'str', |
| 424 | + 'oid': 'int', |
| 425 | + 'regproc': 'str', |
| 426 | + 'regclass': 'str', |
| 427 | + 'regtype': 'str', |
| 428 | + 'regrole': 'str', |
| 429 | + 'regnamespace': 'str', |
| 430 | + 'int2vector': 'list', |
| 431 | + 'oidvector': 'list', |
| 432 | + 'pg_node_tree': 'str', |
| 433 | + } |
| 434 | + if DataBaseConfig.db_type == 'postgresql' |
| 435 | + else { |
| 436 | + # 数值类型 |
| 437 | + 'TINYINT': 'int', |
| 438 | + 'SMALLINT': 'int', |
| 439 | + 'MEDIUMINT': 'int', |
| 440 | + 'INT': 'int', |
| 441 | + 'INTEGER': 'int', |
| 442 | + 'BIGINT': 'int', |
| 443 | + 'FLOAT': 'float', |
| 444 | + 'DOUBLE': 'float', |
| 445 | + 'DECIMAL': 'Decimal', |
| 446 | + 'BIT': 'int', |
| 447 | + # 日期和时间类型 |
| 448 | + 'DATE': 'date', |
| 449 | + 'TIME': 'time', |
| 450 | + 'DATETIME': 'datetime', |
| 451 | + 'TIMESTAMP': 'datetime', |
| 452 | + 'YEAR': 'int', |
| 453 | + # 字符串类型 |
| 454 | + 'CHAR': 'str', |
| 455 | + 'VARCHAR': 'str', |
| 456 | + 'TINYTEXT': 'str', |
| 457 | + 'TEXT': 'str', |
| 458 | + 'MEDIUMTEXT': 'str', |
| 459 | + 'LONGTEXT': 'str', |
| 460 | + 'BINARY': 'bytes', |
| 461 | + 'VARBINARY': 'bytes', |
| 462 | + 'TINYBLOB': 'bytes', |
| 463 | + 'BLOB': 'bytes', |
| 464 | + 'MEDIUMBLOB': 'bytes', |
| 465 | + 'LONGBLOB': 'bytes', |
| 466 | + # 枚举和集合类型 |
| 467 | + 'ENUM': 'str', |
| 468 | + 'SET': 'str', |
| 469 | + # JSON 类型 |
| 470 | + 'JSON': 'dict', |
| 471 | + # 空间数据类型(通常需要特殊处理) |
| 472 | + 'GEOMETRY': 'bytes', |
| 473 | + 'POINT': 'bytes', |
| 474 | + 'LINESTRING': 'bytes', |
| 475 | + 'POLYGON': 'bytes', |
| 476 | + 'MULTIPOINT': 'bytes', |
| 477 | + 'MULTILINESTRING': 'bytes', |
| 478 | + 'MULTIPOLYGON': 'bytes', |
| 479 | + 'GEOMETRYCOLLECTION': 'bytes', |
| 480 | + } |
| 481 | + ) |
0 commit comments