fe_calendar_matter.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package fe_calendar
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/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 `orm:"column(fe_calendar_matter_id);pk" gorm:"primaryKey" 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. FeCalendarAiArticleId int `description:"生成的AI数据点评文章ID"`
  35. }
  36. var FeCalendarMatterCols = struct {
  37. FeCalendarMatterId string
  38. ChartPermissionId string
  39. ChartPermissionName string
  40. MatterMonth string
  41. MatterDate string
  42. Title string
  43. MatterType string
  44. EdbInfoId string
  45. EdbUniqueCode string
  46. EdbCode string
  47. FontColor string
  48. FillingColor string
  49. FontBold string
  50. Sort string
  51. SysUserId string
  52. SysUserName string
  53. CreateTime string
  54. ModifyTime string
  55. FeCalendarAiArticleId string
  56. }{
  57. FeCalendarMatterId: "fe_calendar_matter_id",
  58. ChartPermissionId: "chart_permission_id",
  59. ChartPermissionName: "chart_permission_name",
  60. MatterMonth: "matter_month",
  61. MatterDate: "matter_date",
  62. Title: "title",
  63. MatterType: "matter_type",
  64. EdbInfoId: "edb_info_id",
  65. EdbUniqueCode: "edb_unique_code",
  66. EdbCode: "edb_code",
  67. FontColor: "font_color",
  68. FillingColor: "filling_color",
  69. FontBold: "font_bold",
  70. Sort: "sort",
  71. SysUserId: "sys_user_id",
  72. SysUserName: "sys_user_name",
  73. CreateTime: "create_time",
  74. ModifyTime: "modify_time",
  75. FeCalendarAiArticleId: "fe_calendar_ai_article_id",
  76. }
  77. func (m *FeCalendarMatter) TableName() string {
  78. return "fe_calendar_matter"
  79. }
  80. func (m *FeCalendarMatter) PrimaryId() string {
  81. return FeCalendarMatterCols.FeCalendarMatterId
  82. }
  83. func (m *FeCalendarMatter) Create() (err error) {
  84. o := global.DbMap[utils.DbNameIndex]
  85. err = o.Create(m).Error
  86. return
  87. }
  88. func (m *FeCalendarMatter) CreateMulti(items []*FeCalendarMatter) (err error) {
  89. if len(items) == 0 {
  90. return
  91. }
  92. o := global.DbMap[utils.DbNameIndex]
  93. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  94. return
  95. }
  96. func (m *FeCalendarMatter) Update(cols []string) (err error) {
  97. o := global.DbMap[utils.DbNameIndex]
  98. err = o.Select(cols).Updates(m).Error
  99. return
  100. }
  101. func (m *FeCalendarMatter) Del() (err error) {
  102. o := global.DbMap[utils.DbNameIndex]
  103. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  104. err = o.Exec(sql, m.FeCalendarMatterId).Error
  105. return
  106. }
  107. func (m *FeCalendarMatter) MultiDel(menuIds []int) (err error) {
  108. if len(menuIds) == 0 {
  109. return
  110. }
  111. o := global.DbMap[utils.DbNameIndex]
  112. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  113. err = o.Exec(sql, menuIds).Error
  114. return
  115. }
  116. func (m *FeCalendarMatter) GetItemById(id int) (item *FeCalendarMatter, err error) {
  117. o := global.DbMap[utils.DbNameIndex]
  118. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  119. err = o.Raw(sql, id).First(&item).Error
  120. return
  121. }
  122. func (m *FeCalendarMatter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FeCalendarMatter, err error) {
  123. o := global.DbMap[utils.DbNameIndex]
  124. order := ``
  125. if orderRule != "" {
  126. order = ` ORDER BY ` + orderRule
  127. }
  128. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  129. err = o.Raw(sql, pars...).First(&item).Error
  130. return
  131. }
  132. func (m *FeCalendarMatter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  133. o := global.DbMap[utils.DbNameIndex]
  134. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  135. err = o.Raw(sql, pars...).Scan(&count).Error
  136. return
  137. }
  138. func (m *FeCalendarMatter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FeCalendarMatter, err error) {
  139. o := global.DbMap[utils.DbNameIndex]
  140. fields := strings.Join(fieldArr, ",")
  141. if len(fieldArr) == 0 {
  142. fields = `*`
  143. }
  144. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  145. if orderRule != "" {
  146. order = ` ORDER BY ` + orderRule
  147. }
  148. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  149. err = o.Raw(sql, pars...).Find(&items).Error
  150. return
  151. }
  152. func (m *FeCalendarMatter) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FeCalendarMatter, err error) {
  153. o := global.DbMap[utils.DbNameIndex]
  154. fields := strings.Join(fieldArr, ",")
  155. if len(fieldArr) == 0 {
  156. fields = `*`
  157. }
  158. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  159. if orderRule != "" {
  160. order = ` ORDER BY ` + orderRule
  161. }
  162. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  163. pars = append(pars, startSize, pageSize)
  164. err = o.Raw(sql, pars...).Find(&items).Error
  165. return
  166. }
  167. type FeCalendarMatterItem struct {
  168. FeCalendarMatterId int `description:"事项ID"`
  169. ChartPermissionId int `description:"品种ID"`
  170. ChartPermissionName string `description:"品种名称"`
  171. MatterDate string `description:"事项日期"`
  172. Title string `description:"标题"`
  173. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  174. EdbInfoId int `description:"指标ID"`
  175. EdbUniqueCode string `description:"指标唯一编码"`
  176. EdbCode string `description:"指标编码"`
  177. FontColor string `description:"字体颜色"`
  178. FillingColor string `description:"填充颜色"`
  179. FontBold int `description:"字体加粗:0-否;1-是"`
  180. Sort int `description:"排序"`
  181. FeCalendarAiArticleId int `description:"生成的AI数据点评文章ID"`
  182. }
  183. func FormatFeCalendarMatter2Item(origin *FeCalendarMatter) (item *FeCalendarMatterItem) {
  184. if origin == nil {
  185. return
  186. }
  187. item = new(FeCalendarMatterItem)
  188. item.FeCalendarMatterId = origin.FeCalendarMatterId
  189. item.ChartPermissionId = origin.ChartPermissionId
  190. item.ChartPermissionName = origin.ChartPermissionName
  191. item.MatterDate = utils.TimeTransferString(utils.FormatDate, origin.MatterDate)
  192. item.Title = origin.Title
  193. item.MatterType = origin.MatterType
  194. item.EdbInfoId = origin.EdbInfoId
  195. item.EdbUniqueCode = origin.EdbUniqueCode
  196. item.EdbCode = origin.EdbCode
  197. item.FontColor = origin.FontColor
  198. item.FillingColor = origin.FillingColor
  199. item.FontBold = origin.FontBold
  200. item.Sort = origin.Sort
  201. item.FeCalendarAiArticleId = origin.FeCalendarAiArticleId
  202. return
  203. }
  204. // FeCalendarMatterListReq 事项列表请求体
  205. type FeCalendarMatterListReq struct {
  206. ChartPermissionId int `form:"ChartPermissionId" description:"品种ID"`
  207. StartDate string `form:"StartDate" description:"开始日期"`
  208. EndDate string `form:"EndDate" description:"结束日期"`
  209. }
  210. // FeCalendarMatterListItem 事项列表
  211. type FeCalendarMatterListItem struct {
  212. Date string `description:"日期"`
  213. Matters []*FeCalendarMatterItem `description:"日期事项"`
  214. }
  215. // FeCalendarMatterSaveReq 保存事项请求体
  216. type FeCalendarMatterSaveReq struct {
  217. ChartPermissionId int `description:"品种ID"`
  218. MatterDate string `description:"日期"`
  219. Matters []*FeCalendarMatterSaveItem `description:"事项"`
  220. }
  221. type FeCalendarMatterSaveItem struct {
  222. FeCalendarMatterId int `description:"事项ID"`
  223. Title string `description:"标题"`
  224. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  225. EdbInfoId int `description:"指标ID"`
  226. EdbUniqueCode string `description:"指标唯一编码"`
  227. EdbCode string `description:"指标编码"`
  228. FontColor string `description:"字体颜色"`
  229. FillingColor string `description:"填充颜色"`
  230. FontBold int `description:"字体加粗:0-否;1-是"`
  231. Sort int `description:"排序"`
  232. FeCalendarAiArticleId int `description:"生成的AI数据点评文章ID"`
  233. }
  234. func (m *FeCalendarMatter) Save(addMatters, editMatters, removeMatters []*FeCalendarMatter, updateCols []string) (err error) {
  235. o := global.DbMap[utils.DbNameIndex]
  236. tx := o.Begin()
  237. defer func() {
  238. if err != nil {
  239. _ = tx.Rollback()
  240. return
  241. }
  242. _ = tx.Commit()
  243. }()
  244. if len(addMatters) > 0 {
  245. e := tx.CreateInBatches(addMatters, utils.MultiAddNum).Error
  246. if e != nil {
  247. err = fmt.Errorf("insert multi err: %s", e.Error())
  248. return
  249. }
  250. }
  251. if len(editMatters) > 0 {
  252. for _, v := range editMatters {
  253. e := tx.Select(updateCols).Updates(v).Error
  254. if e != nil {
  255. err = fmt.Errorf("update err: %s", e.Error())
  256. return
  257. }
  258. }
  259. }
  260. if len(removeMatters) > 0 {
  261. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  262. for _, v := range removeMatters {
  263. e := tx.Exec(sql, v.FeCalendarMatterId).Error
  264. if e != nil {
  265. err = fmt.Errorf("remove exec err: %s", e.Error())
  266. return
  267. }
  268. }
  269. }
  270. return
  271. }