InitTable.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package util
  2. import "fmt"
  3. type GTable struct {
  4. GenTable GenTable
  5. GenTableColumn []GenTableColumn
  6. }
  7. var GTables = make([]GTable, 0)
  8. // InitTable 初始化表格生成
  9. func InitTable() {
  10. for i := range MTables {
  11. table := MTables[i]
  12. //表格
  13. gt := GenTable{
  14. TableName: table.Name,
  15. TableComment: table.Comment,
  16. Name: table.GreatHump,
  17. RouterName: table.LittleHump,
  18. Remark: table.Comment,
  19. }
  20. list, _ := GetGenTableList(gt, 1, 1)
  21. if list.Total == 0 {
  22. gt, _ = SaveGenTable(&gt)
  23. } else {
  24. gt = list.List[0].(GenTable)
  25. }
  26. gtcs := make([]GenTableColumn, 0)
  27. for j := range table.MColumns {
  28. column := table.MColumns[j]
  29. gtc := GenTableColumn{
  30. TableId: gt.Id,
  31. ColumnName: column.Name,
  32. }
  33. subList, _ := GetGenTableColumnList(gtc, 1, 1)
  34. if gtc.TableId == 34 {
  35. fmt.Println(subList.List[0])
  36. }
  37. if subList.Total == 0 {
  38. //gtc, _ = SaveGenTableColumn(&gtc)
  39. } else {
  40. gtc = subList.List[0].(GenTableColumn)
  41. }
  42. gtcs = append(gtcs, gtc)
  43. }
  44. GTables = append(GTables, GTable{
  45. GenTable: gt,
  46. GenTableColumn: gtcs,
  47. })
  48. }
  49. }
  50. func UpdateTable() {
  51. list, err := GetGenTableList(GenTable{}, 1, 10000)
  52. if err != nil {
  53. fmt.Println(err)
  54. return
  55. }
  56. SqlMap := map[string]GenTable{}
  57. for i := range list.List {
  58. gt := list.List[i].(GenTable)
  59. SqlMap[gt.TableName] = gt
  60. }
  61. MTableMap := map[string]MTable{}
  62. for i := range MTables {
  63. table := MTables[i]
  64. MTableMap[table.Name] = table
  65. }
  66. for s := range MTableMap {
  67. if SqlMap[s].Id == 0 {
  68. DeleteGenTable(SqlMap[s].Id)
  69. }
  70. }
  71. }