fe_calendar_matter.go 10 KB

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