fe_calendar_matter.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package fe_calendar
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. )
  9. const (
  10. MatterTypeFree = 1 // 事项类型-自定义事项
  11. MatterTypeEdb = 2 // 事项类型-基础指标
  12. MatterTypePredict = 3 // 事项类型-预测指标
  13. )
  14. type FeCalendarMatter struct {
  15. FeCalendarMatterId int `gorm:"primaryKey;column:fe_calendar_matter_id;type:int(10) unsigned;not null"` // 事项Id
  16. ChartPermissionId int `gorm:"index:idx_chart_permission_id;column:chart_permission_id;type:int(10) unsigned;not null;default:0"` // 品种Id
  17. ChartPermissionName string `gorm:"column:chart_permission_name;type:varchar(128);not null;default:''"` // 品种名称
  18. MatterMonth string `gorm:"index:idx_matter_month;column:matter_month;type:varchar(16);not null;default:''"` // 事项年月:格式2006-01
  19. MatterDate time.Time `gorm:"index:idx_matter_date;column:matter_date;type:date"` // 事项日期
  20. Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 标题
  21. MatterType int `gorm:"column:matter_type;type:tinyint(4) unsigned;not null;default:0"` // 事项类型:1-自定义事项;2-基础指标;3-预测指标
  22. EdbInfoId int `gorm:"column:edb_info_id;type:int(10) unsigned;not null;default:0"` // 指标Id
  23. EdbUniqueCode string `gorm:"column:edb_unique_code;type:varchar(128);not null;default:''"` // 指标唯一编码
  24. EdbCode string `gorm:"column:edb_code;type:varchar(128);not null;default:''"` // 指标编码
  25. FontColor string `gorm:"column:font_color;type:varchar(64);not null;default:''"` // 字体颜色
  26. FillingColor string `gorm:"column:filling_color;type:varchar(64);not null;default:''"` // 填充颜色
  27. FontBold int `gorm:"column:font_bold;type:tinyint(4) unsigned;not null;default:0"` // 字体加粗:0-否;1-是
  28. Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序
  29. SysUserId int `gorm:"column:sys_user_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  30. SysUserName string `gorm:"column:sys_user_name;type:varchar(128);not null;default:''"` // 创建人姓名
  31. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  32. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  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) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FeCalendarMatter, err error) {
  80. fields := strings.Join(fieldArr, ",")
  81. if len(fieldArr) == 0 {
  82. fields = `*`
  83. }
  84. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  85. if orderRule != "" {
  86. order = ` ORDER BY ` + orderRule
  87. }
  88. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  89. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  90. return
  91. }
  92. type FeCalendarMatterItem struct {
  93. FeCalendarMatterId int `description:"事项ID"`
  94. ChartPermissionId int `description:"品种ID"`
  95. ChartPermissionName string `description:"品种名称"`
  96. MatterDate string `description:"事项日期"`
  97. Title string `description:"标题"`
  98. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  99. EdbInfoId int `description:"指标ID"`
  100. EdbUniqueCode string `description:"指标唯一编码"`
  101. EdbCode string `description:"指标编码"`
  102. FontColor string `description:"字体颜色"`
  103. FillingColor string `description:"填充颜色"`
  104. FontBold int `description:"字体加粗:0-否;1-是"`
  105. Sort int `description:"排序"`
  106. }
  107. func FormatFeCalendarMatter2Item(origin *FeCalendarMatter) (item *FeCalendarMatterItem) {
  108. if origin == nil {
  109. return
  110. }
  111. item = new(FeCalendarMatterItem)
  112. item.FeCalendarMatterId = origin.FeCalendarMatterId
  113. item.ChartPermissionId = origin.ChartPermissionId
  114. item.ChartPermissionName = origin.ChartPermissionName
  115. item.MatterDate = utils.TimeTransferString(utils.FormatDate, origin.MatterDate)
  116. item.Title = origin.Title
  117. item.MatterType = origin.MatterType
  118. item.EdbInfoId = origin.EdbInfoId
  119. item.EdbUniqueCode = origin.EdbUniqueCode
  120. item.EdbCode = origin.EdbCode
  121. item.FontColor = origin.FontColor
  122. item.FillingColor = origin.FillingColor
  123. item.FontBold = origin.FontBold
  124. item.Sort = origin.Sort
  125. return
  126. }
  127. // FeCalendarMatterListReq 事项列表请求体
  128. type FeCalendarMatterListReq struct {
  129. ChartPermissionId int `form:"ChartPermissionId" description:"品种ID"`
  130. StartDate string `form:"StartDate" description:"开始日期"`
  131. EndDate string `form:"EndDate" description:"结束日期"`
  132. }
  133. // FeCalendarMatterListItem 事项列表
  134. type FeCalendarMatterListItem struct {
  135. Date string `description:"日期"`
  136. Matters []*FeCalendarMatterItem `description:"日期事项"`
  137. }
  138. // FeCalendarMatterSaveReq 保存事项请求体
  139. type FeCalendarMatterSaveReq struct {
  140. ChartPermissionId int `description:"品种ID"`
  141. MatterDate string `description:"日期"`
  142. Matters []*FeCalendarMatterSaveItem `description:"事项"`
  143. }
  144. type FeCalendarMatterSaveItem struct {
  145. FeCalendarMatterId int `description:"事项ID"`
  146. Title string `description:"标题"`
  147. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  148. EdbInfoId int `description:"指标ID"`
  149. EdbUniqueCode string `description:"指标唯一编码"`
  150. EdbCode string `description:"指标编码"`
  151. FontColor string `description:"字体颜色"`
  152. FillingColor string `description:"填充颜色"`
  153. FontBold int `description:"字体加粗:0-否;1-是"`
  154. Sort int `description:"排序"`
  155. }
  156. func (m *FeCalendarMatter) Save(addMatters, editMatters, removeMatters []*FeCalendarMatter, updateCols []string) (err error) {
  157. tx := global.DmSQL["data"].Begin()
  158. defer func() {
  159. if err != nil {
  160. _ = tx.Rollback()
  161. return
  162. }
  163. _ = tx.Commit()
  164. }()
  165. if len(addMatters) > 0 {
  166. e := tx.CreateInBatches(addMatters, utils.MultiAddNum).Error
  167. if e != nil {
  168. err = fmt.Errorf("insert multi err: %v", e)
  169. return
  170. }
  171. }
  172. if len(editMatters) > 0 {
  173. for _, v := range editMatters {
  174. e := tx.Select(updateCols).Updates(v).Error
  175. if e != nil {
  176. err = fmt.Errorf("update err: %v", e)
  177. return
  178. }
  179. }
  180. }
  181. if len(removeMatters) > 0 {
  182. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  183. for _, v := range removeMatters {
  184. e := tx.Exec(sql, v.FeCalendarMatterId).Error
  185. if e != nil {
  186. err = fmt.Errorf("remove exec err: %v", e)
  187. return
  188. }
  189. }
  190. }
  191. return
  192. }