Browse Source

修复错别单词colume -> column, 删除tag中多余的;

main
SliverHorn 4 years ago
parent
commit
485a49693b
  1. 8
      server/api/v1/sys_auto_code.go
  2. 12
      server/model/request/sys_autocode.go
  3. 2
      server/router/sys_auto_code.go
  4. 6
      server/service/sys_auto_code.go
  5. 4
      web/src/api/autoCode.js
  6. 22
      web/src/view/systemTools/autoCode/index.vue

8
server/api/v1/sys_auto_code.go

@ -139,16 +139,16 @@ func GetDB(c *gin.Context) {
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/getDatabase [get]
func GetColume(c *gin.Context) {
// @Router /autoCode/getColumn [get]
func GetColumn(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
tableName := c.Query("tableName")
err, columes := service.GetColume(tableName, dbName)
err, columns := service.GetColumn(tableName, dbName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
} else {
response.OkWithData(gin.H{
"columes": columes,
"columns": columns,
}, c)
}
}

12
server/model/request/sys_autocode.go

@ -1,16 +1,16 @@
package request
type DBReq struct {
Database string `json:"database";gorm:"column:database"`
Database string `json:"database" gorm:"column:database"`
}
type TableReq struct {
TableName string `json:"tableName"`
}
type ColumeReq struct {
ColumeName string `json:"columeName";gorm:"column:colume_name"`
DataType string `json:"dataType";gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong";gorm:"column:data_type_long"`
ColumeComment string `json:"columeComment";gorm:"column:colume_comment"`
type ColumnReq struct {
ColumnName string `json:"columnName" gorm:"column:column_name"`
DataType string `json:"dataType" gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
}

2
server/router/sys_auto_code.go

@ -15,6 +15,6 @@ func InitAutoCodeRouter(Router *gin.RouterGroup) {
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
AutoCodeRouter.GET("getColume", v1.GetColume) // 获取指定表所有字段信息
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
}
}

6
server/service/sys_auto_code.go

@ -128,7 +128,7 @@ func GetDB() (err error, DBNames []request.DBReq) {
return err, DBNames
}
func GetColume(tableName string, dbName string) (err error, Columes []request.ColumeReq) {
err = global.GVA_DB.Raw("SELECT COLUMN_NAME colume_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT colume_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columes).Error
return err, Columes
func GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) {
err = global.GVA_DB.Raw("SELECT COLUMN_NAME column_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT colume_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columns).Error
return err, Columns
}

4
web/src/api/autoCode.js

@ -59,9 +59,9 @@ export const getTable = (params) => {
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/getColume [get]
export const getColume = (params) => {
export const getColumn = (params) => {
return service({
url: "/autoCode/getColume",
url: "/autoCode/getColumn",
method: 'get',
params,
})

22
web/src/view/systemTools/autoCode/index.vue

@ -36,7 +36,7 @@
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="getColume" type="primary">使用此表创建</el-button>
<el-button @click="getColumn" type="primary">使用此表创建</el-button>
</el-form-item>
</el-form>
</el-collapse-item>
@ -145,7 +145,7 @@ const fieldTemplate = {
import FieldDialog from "@/view/systemTools/autoCode/component/fieldDialog.vue";
import { toUpperCase, toHump } from "@/utils/stringFun.js";
import { createTemp, getDB, getTable, getColume } from "@/api/autoCode.js";
import { createTemp, getDB, getTable, getColumn } from "@/api/autoCode.js";
import { getDict } from "@/utils/dictionary";
export default {
@ -316,9 +316,9 @@ export default {
}
this.dbform.tableName = "";
},
async getColume() {
async getColumn() {
const gormModelList = ["id", "created_at", "updated_at", "deleted_at"];
const res = await getColume(this.dbform);
const res = await getColumn(this.dbform);
if (res.code == 0) {
const tbHump = toHump(this.dbform.tableName);
this.form.structName = toUpperCase(tbHump);
@ -328,19 +328,19 @@ export default {
this.form.description = tbHump + "表";
this.form.autoCreateApiToSql = true;
this.form.fields = [];
res.data.columes &&
res.data.columes.map(item => {
if (!gormModelList.some(gormfd => gormfd == item.columeName)) {
const fbHump = toHump(item.columeName);
res.data.columns &&
res.data.columns.map(item => {
if (!gormModelList.some(gormfd => gormfd == item.columnName)) {
const fbHump = toHump(item.columnName);
this.form.fields.push({
fieldName: toUpperCase(fbHump),
fieldDesc: item.columeComment || fbHump + "字段",
fieldDesc: item.columnComment || fbHump + "字段",
fieldType: this.fdMap[item.dataType],
dataType: item.dataType,
fieldJson: fbHump,
dataTypeLong: item.dataTypeLong,
columnName: item.columeName,
comment: item.columeComment,
columnName: item.columnName,
comment: item.columnComment,
fieldSearchType: "",
dictType:""
});

Loading…
Cancel
Save