fe_calendar_matter.go 4.2 KB

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