fe_calendar_matter.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package fe_calendar
  2. import (
  3. "eta_gn/eta_task/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. const (
  9. MatterTypeFree = 1 // 事项类型-自定义事项
  10. MatterTypeEdb = 2 // 事项类型-基础指标
  11. MatterTypePredict = 3 // 事项类型-预测指标
  12. )
  13. // FeCalendarMatter 外汇日历-事项表
  14. type FeCalendarMatter struct {
  15. FeCalendarMatterId int `gorm:"column:fe_calendar_matter_id;primaryKey"` // `orm:"column(fe_calendar_matter_id);pk" description:"事项ID"`
  16. ChartPermissionId int `description:"品种ID"`
  17. ChartPermissionName string `description:"品种名称"`
  18. MatterMonth string `description:"事项年月:格式2006-01"`
  19. MatterDate time.Time `description:"事项日期"`
  20. Title string `description:"标题"`
  21. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  22. EdbInfoId int `description:"指标ID"`
  23. EdbUniqueCode string `description:"指标唯一编码"`
  24. EdbCode string `description:"指标编码"`
  25. FontColor string `description:"字体颜色"`
  26. FillingColor string `description:"填充颜色"`
  27. FontBold int `description:"字体加粗:0-否;1-是"`
  28. Sort int `description:"排序"`
  29. SysUserId int `description:"创建人ID"`
  30. SysUserName string `description:"创建人姓名"`
  31. CreateTime time.Time `description:"创建时间"`
  32. ModifyTime time.Time `description:"更新时间"`
  33. }
  34. var FeCalendarMatterCols = struct {
  35. FeCalendarMatterId string
  36. ChartPermissionId string
  37. ChartPermissionName string
  38. MatterMonth string
  39. MatterDate string
  40. Title string
  41. MatterType string
  42. EdbInfoId string
  43. EdbUniqueCode string
  44. EdbCode string
  45. FontColor string
  46. FillingColor string
  47. FontBold string
  48. Sort string
  49. SysUserId string
  50. SysUserName string
  51. CreateTime string
  52. ModifyTime string
  53. }{
  54. FeCalendarMatterId: "fe_calendar_matter_id",
  55. ChartPermissionId: "chart_permission_id",
  56. ChartPermissionName: "chart_permission_name",
  57. MatterMonth: "matter_month",
  58. MatterDate: "matter_date",
  59. Title: "title",
  60. MatterType: "matter_type",
  61. EdbInfoId: "edb_info_id",
  62. EdbUniqueCode: "edb_unique_code",
  63. EdbCode: "edb_code",
  64. FontColor: "font_color",
  65. FillingColor: "filling_color",
  66. FontBold: "font_bold",
  67. Sort: "sort",
  68. SysUserId: "sys_user_id",
  69. SysUserName: "sys_user_name",
  70. CreateTime: "create_time",
  71. ModifyTime: "modify_time",
  72. }
  73. func (m *FeCalendarMatter) TableName() string {
  74. return "fe_calendar_matter"
  75. }
  76. func (m *FeCalendarMatter) PrimaryId() string {
  77. return FeCalendarMatterCols.FeCalendarMatterId
  78. }
  79. func (m *FeCalendarMatter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FeCalendarMatter, err error) {
  80. //o := orm.NewOrmUsingDB("data")
  81. //order := ``
  82. //if orderRule != "" {
  83. // order = ` ORDER BY ` + orderRule
  84. //}
  85. //sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  86. //err = o.Raw(sql, pars).QueryRow(&item)
  87. order := ``
  88. if orderRule != "" {
  89. order = ` ORDER BY ` + orderRule
  90. }
  91. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  92. err = global.DmSQL["data"].Raw(sql, pars...).First(&item).Error
  93. return
  94. }
  95. func (m *FeCalendarMatter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  96. //o := orm.NewOrmUsingDB("data")
  97. //sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  98. //err = o.Raw(sql, pars).QueryRow(&count)
  99. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  100. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  101. return
  102. }
  103. func (m *FeCalendarMatter) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FeCalendarMatter, err error) {
  104. //o := orm.NewOrmUsingDB("data")
  105. //fields := strings.Join(fieldArr, ",")
  106. //if len(fieldArr) == 0 {
  107. // fields = `*`
  108. //}
  109. //order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  110. //if orderRule != "" {
  111. // order = ` ORDER BY ` + orderRule
  112. //}
  113. //sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  114. //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  115. fields := strings.Join(fieldArr, ",")
  116. if len(fieldArr) == 0 {
  117. fields = `*`
  118. }
  119. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  120. if orderRule != "" {
  121. order = ` ORDER BY ` + orderRule
  122. }
  123. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  124. pars = append(pars, startSize, pageSize)
  125. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  126. return
  127. }