fe_calendar_matter.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. }
  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) Create() (err error) {
  81. o := global.DbMap[utils.DbNameIndex]
  82. err = o.Create(m).Error
  83. return
  84. }
  85. func (m *FeCalendarMatter) CreateMulti(items []*FeCalendarMatter) (err error) {
  86. if len(items) == 0 {
  87. return
  88. }
  89. o := global.DbMap[utils.DbNameIndex]
  90. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  91. return
  92. }
  93. func (m *FeCalendarMatter) Update(cols []string) (err error) {
  94. o := global.DbMap[utils.DbNameIndex]
  95. err = o.Select(cols).Updates(m).Error
  96. return
  97. }
  98. func (m *FeCalendarMatter) Del() (err error) {
  99. o := global.DbMap[utils.DbNameIndex]
  100. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  101. err = o.Exec(sql, m.FeCalendarMatterId).Error
  102. return
  103. }
  104. func (m *FeCalendarMatter) MultiDel(menuIds []int) (err error) {
  105. if len(menuIds) == 0 {
  106. return
  107. }
  108. o := global.DbMap[utils.DbNameIndex]
  109. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  110. err = o.Exec(sql, menuIds).Error
  111. return
  112. }
  113. func (m *FeCalendarMatter) GetItemById(id int) (item *FeCalendarMatter, err error) {
  114. o := global.DbMap[utils.DbNameIndex]
  115. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  116. err = o.Raw(sql, id).First(&item).Error
  117. return
  118. }
  119. func (m *FeCalendarMatter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FeCalendarMatter, err error) {
  120. o := global.DbMap[utils.DbNameIndex]
  121. order := ``
  122. if orderRule != "" {
  123. order = ` ORDER BY ` + orderRule
  124. }
  125. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  126. err = o.Raw(sql, pars...).First(&item).Error
  127. return
  128. }
  129. func (m *FeCalendarMatter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  130. o := global.DbMap[utils.DbNameIndex]
  131. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  132. err = o.Raw(sql, pars...).Scan(&count).Error
  133. return
  134. }
  135. func (m *FeCalendarMatter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FeCalendarMatter, err error) {
  136. o := global.DbMap[utils.DbNameIndex]
  137. fields := strings.Join(fieldArr, ",")
  138. if len(fieldArr) == 0 {
  139. fields = `*`
  140. }
  141. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  142. if orderRule != "" {
  143. order = ` ORDER BY ` + orderRule
  144. }
  145. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  146. err = o.Raw(sql, pars...).Find(&items).Error
  147. return
  148. }
  149. func (m *FeCalendarMatter) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FeCalendarMatter, err error) {
  150. o := global.DbMap[utils.DbNameIndex]
  151. fields := strings.Join(fieldArr, ",")
  152. if len(fieldArr) == 0 {
  153. fields = `*`
  154. }
  155. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  156. if orderRule != "" {
  157. order = ` ORDER BY ` + orderRule
  158. }
  159. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  160. pars = append(pars, startSize, pageSize)
  161. err = o.Raw(sql, pars...).Find(&items).Error
  162. return
  163. }
  164. type FeCalendarMatterItem struct {
  165. FeCalendarMatterId int `description:"事项ID"`
  166. ChartPermissionId int `description:"品种ID"`
  167. ChartPermissionName string `description:"品种名称"`
  168. MatterDate string `description:"事项日期"`
  169. Title string `description:"标题"`
  170. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  171. EdbInfoId int `description:"指标ID"`
  172. EdbUniqueCode string `description:"指标唯一编码"`
  173. EdbCode string `description:"指标编码"`
  174. FontColor string `description:"字体颜色"`
  175. FillingColor string `description:"填充颜色"`
  176. FontBold int `description:"字体加粗:0-否;1-是"`
  177. Sort int `description:"排序"`
  178. }
  179. func FormatFeCalendarMatter2Item(origin *FeCalendarMatter) (item *FeCalendarMatterItem) {
  180. if origin == nil {
  181. return
  182. }
  183. item = new(FeCalendarMatterItem)
  184. item.FeCalendarMatterId = origin.FeCalendarMatterId
  185. item.ChartPermissionId = origin.ChartPermissionId
  186. item.ChartPermissionName = origin.ChartPermissionName
  187. item.MatterDate = utils.TimeTransferString(utils.FormatDate, origin.MatterDate)
  188. item.Title = origin.Title
  189. item.MatterType = origin.MatterType
  190. item.EdbInfoId = origin.EdbInfoId
  191. item.EdbUniqueCode = origin.EdbUniqueCode
  192. item.EdbCode = origin.EdbCode
  193. item.FontColor = origin.FontColor
  194. item.FillingColor = origin.FillingColor
  195. item.FontBold = origin.FontBold
  196. item.Sort = origin.Sort
  197. return
  198. }
  199. // FeCalendarMatterListReq 事项列表请求体
  200. type FeCalendarMatterListReq struct {
  201. ChartPermissionId int `form:"ChartPermissionId" description:"品种ID"`
  202. StartDate string `form:"StartDate" description:"开始日期"`
  203. EndDate string `form:"EndDate" description:"结束日期"`
  204. }
  205. // FeCalendarMatterListItem 事项列表
  206. type FeCalendarMatterListItem struct {
  207. Date string `description:"日期"`
  208. Matters []*FeCalendarMatterItem `description:"日期事项"`
  209. }
  210. // FeCalendarMatterSaveReq 保存事项请求体
  211. type FeCalendarMatterSaveReq struct {
  212. ChartPermissionId int `description:"品种ID"`
  213. MatterDate string `description:"日期"`
  214. Matters []*FeCalendarMatterSaveItem `description:"事项"`
  215. }
  216. type FeCalendarMatterSaveItem struct {
  217. FeCalendarMatterId int `description:"事项ID"`
  218. Title string `description:"标题"`
  219. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  220. EdbInfoId int `description:"指标ID"`
  221. EdbUniqueCode string `description:"指标唯一编码"`
  222. EdbCode string `description:"指标编码"`
  223. FontColor string `description:"字体颜色"`
  224. FillingColor string `description:"填充颜色"`
  225. FontBold int `description:"字体加粗:0-否;1-是"`
  226. Sort int `description:"排序"`
  227. }
  228. func (m *FeCalendarMatter) Save(addMatters, editMatters, removeMatters []*FeCalendarMatter, updateCols []string) (err error) {
  229. o := global.DbMap[utils.DbNameIndex]
  230. tx := o.Begin()
  231. defer func() {
  232. if err != nil {
  233. _ = tx.Rollback()
  234. return
  235. }
  236. _ = tx.Commit()
  237. }()
  238. if len(addMatters) > 0 {
  239. e := tx.CreateInBatches(addMatters, utils.MultiAddNum).Error
  240. if e != nil {
  241. err = fmt.Errorf("insert multi err: %s", e.Error())
  242. return
  243. }
  244. }
  245. if len(editMatters) > 0 {
  246. for _, v := range editMatters {
  247. e := tx.Select(updateCols).Updates(v).Error
  248. if e != nil {
  249. err = fmt.Errorf("update err: %s", e.Error())
  250. return
  251. }
  252. }
  253. }
  254. if len(removeMatters) > 0 {
  255. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  256. for _, v := range removeMatters {
  257. e := tx.Exec(sql, v.FeCalendarMatterId).Error
  258. if e != nil {
  259. err = fmt.Errorf("remove exec err: %s", e.Error())
  260. return
  261. }
  262. }
  263. }
  264. return
  265. }