InitTable.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package service
  2. import (
  3. "go-create/util"
  4. )
  5. type GTable struct {
  6. GenTable GenTable
  7. GenTableColumn []GenTableColumn
  8. }
  9. var GTables = make([]GTable, 0)
  10. // InitTable 初始化表格生成
  11. func InitTable() {
  12. for i := range util.MTables {
  13. table := util.MTables[i]
  14. //表格
  15. gt := GenTable{
  16. TableName: table.Name,
  17. TableComment: table.Comment,
  18. Name: table.GreatHump,
  19. RouterName: table.LittleHump,
  20. Remark: table.Comment,
  21. }
  22. list, _ := GetGenTableList(gt, 1, 1)
  23. if list.Total == 0 {
  24. gt, _ = SaveGenTable(&gt)
  25. } else {
  26. gt = list.List[0].(GenTable)
  27. }
  28. gtcs := make([]GenTableColumn, 0)
  29. for j := range table.MColumns {
  30. column := table.MColumns[j]
  31. gtc := GenTableColumn{
  32. TableId: gt.Id,
  33. Sort: int64(j),
  34. ColumnName: column.Name,
  35. ColumnComment: column.Comment,
  36. ColumnType: column.SqlTypeName,
  37. GoType: util.FormatSqlType(column.SqlTypeName),
  38. GoField: column.GreatHump,
  39. IsKey: func() string {
  40. if column.IsKey {
  41. return "1"
  42. }
  43. return "0"
  44. }(),
  45. IsIncrement: "0",
  46. IsRequired: "0",
  47. QueryType: "",
  48. VueShowType: "",
  49. DictType: "",
  50. }
  51. subList, _ := GetGenTableColumnList(gtc, 1, 1)
  52. if subList.Total == 0 {
  53. gtc, _ = SaveGenTableColumn(&gtc)
  54. } else {
  55. gtc = subList.List[0].(GenTableColumn)
  56. }
  57. gtcs = append(gtcs, gtc)
  58. }
  59. GTables = append(GTables, GTable{
  60. GenTable: gt,
  61. GenTableColumn: gtcs,
  62. })
  63. }
  64. }
  65. type VMTemple struct {
  66. Name string
  67. }