InitTable.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Sort: int64(j),
  32. ColumnName: column.Name,
  33. ColumnComment: column.Comment,
  34. ColumnType: column.SqlTypeName,
  35. GoType: FormatSqlType(column.SqlTypeName),
  36. GoField: column.GreatHump,
  37. IsKey: func() string {
  38. if column.IsKey {
  39. return "1"
  40. }
  41. return "0"
  42. }(),
  43. IsIncrement: "0",
  44. IsRequired: "0",
  45. QueryType: "",
  46. VueShowType: "",
  47. DictType: "",
  48. }
  49. subList, _ := GetGenTableColumnList(gtc, 1, 1)
  50. if subList.Total == 0 {
  51. gtc, _ = SaveGenTableColumn(&gtc)
  52. } else {
  53. gtc = subList.List[0].(GenTableColumn)
  54. }
  55. gtcs = append(gtcs, gtc)
  56. }
  57. GTables = append(GTables, GTable{
  58. GenTable: gt,
  59. GenTableColumn: gtcs,
  60. })
  61. }
  62. }
  63. func UpdateTable() {
  64. list, err := GetGenTableList(GenTable{}, 1, 10000)
  65. if err != nil {
  66. fmt.Println(err)
  67. return
  68. }
  69. SqlMap := map[string]GenTable{}
  70. for i := range list.List {
  71. gt := list.List[i].(GenTable)
  72. SqlMap[gt.TableName] = gt
  73. }
  74. MTableMap := map[string]MTable{}
  75. for i := range MTables {
  76. table := MTables[i]
  77. MTableMap[table.Name] = table
  78. }
  79. for s := range MTableMap {
  80. if SqlMap[s].Id == 0 {
  81. DeleteGenTable(SqlMap[s].Id)
  82. }
  83. }
  84. }