package datacenter import ( "appPlatform/overall" "appPlatform/overall/publicmethod" "encoding/json" "fmt" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2024-12-24 11:43:02 @ 功能: 获取数据表 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GainDataTable(c *gin.Context) { dataVal, err := publicmethod.ReceiveData(c) //接收数据处理 if err != nil { publicmethod.Result(100, err, c) return } var requestData DataBastType err = json.Unmarshal(dataVal, &requestData) if err != nil { publicmethod.Result(100, err, c) return } // var requestData DataBastType // err := c.ShouldBindJSON(&requestData) // if err != nil { // publicmethod.Result(100, err, c) // return // } if requestData.Type == "" { publicmethod.Result(1, err, c, "未知数据库类型!请先确实是什么数据库类型!") return } if requestData.DataBaseName == "" { publicmethod.Result(1, err, c, "请输入数据库名称!") return } if requestData.Ip == "" { publicmethod.Result(1, err, c, "请输入数据库地址!") return } if requestData.UserName == "" { publicmethod.Result(1, err, c, "请输入用户名!") return } if requestData.Pwd == "" { publicmethod.Result(1, err, c, "请输入密码!") return } tableInfo, err := requestData.ObtainDataBaseAllTableMysql() // fmt.Printf("tableInfo:%v\n", tableInfo) // for _, v := range tableInfo { // // if v.TableKey != "taskrecord" { // sql := fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN %v bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '创建人行政组织';", v.TableKey, "createrOrg") // overall.CONSTANT_DB_CustomerForm.Exec(sql) // // } // } // for _, v := range tableInfo { // // if v.TableKey != "taskrecord" { // sql := fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN %v bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '创建人岗位';", v.TableKey, "createrPositon") // overall.CONSTANT_DB_CustomerForm.Exec(sql) // // } // } for _, v := range tableInfo { var haveWordKey []string for _, tv := range v.Fields { if !publicmethod.IsInTrue[string](tv.Field, haveWordKey) { haveWordKey = append(haveWordKey, tv.Field) } } if len(haveWordKey) > 0 { WriteTableKey(v.TableKey, haveWordKey) } } publicmethod.Result(0, tableInfo, c) } /* * @ 作者: 秦东 @ 时间: 2026-01-13 10:32:27 @ 功能: 写入表格欠缺的字段 */ func WriteTableKey(tableName string, wordKey []string) { oldTable := []string{"id", "masters_key", "creater", "createrOrg", "creater_time", "edit_time", "flow_id", "states", "flowIsOpen", "createrPositon"} for _, ov := range oldTable { if !publicmethod.IsInTrue[string](ov, wordKey) { sql := fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN %v bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '创建人岗位';", tableName, ov) overall.CONSTANT_DB_CustomerForm.Exec(sql) } } }