fe_calendar_matter.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. // 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. type FeCalendarMatter struct {
  36. FeCalendarMatterId int `gorm:"primaryKey;column:fe_calendar_matter_id;type:int(10) unsigned;not null"` // 事项Id
  37. ChartPermissionId int `gorm:"index:idx_chart_permission_id;column:chart_permission_id;type:int(10) unsigned;not null;default:0"` // 品种Id
  38. ChartPermissionName string `gorm:"column:chart_permission_name;type:varchar(128);not null;default:''"` // 品种名称
  39. MatterMonth string `gorm:"index:idx_matter_month;column:matter_month;type:varchar(16);not null;default:''"` // 事项年月:格式2006-01
  40. MatterDate time.Time `gorm:"index:idx_matter_date;column:matter_date;type:date"` // 事项日期
  41. Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 标题
  42. MatterType int `gorm:"column:matter_type;type:tinyint(4) unsigned;not null;default:0"` // 事项类型:1-自定义事项;2-基础指标;3-预测指标
  43. EdbInfoId int `gorm:"column:edb_info_id;type:int(10) unsigned;not null;default:0"` // 指标Id
  44. EdbUniqueCode string `gorm:"column:edb_unique_code;type:varchar(128);not null;default:''"` // 指标唯一编码
  45. EdbCode string `gorm:"column:edb_code;type:varchar(128);not null;default:''"` // 指标编码
  46. FontColor string `gorm:"column:font_color;type:varchar(64);not null;default:''"` // 字体颜色
  47. FillingColor string `gorm:"column:filling_color;type:varchar(64);not null;default:''"` // 填充颜色
  48. FontBold int `gorm:"column:font_bold;type:tinyint(4) unsigned;not null;default:0"` // 字体加粗:0-否;1-是
  49. Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序
  50. SysUserId int `gorm:"column:sys_user_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  51. SysUserName string `gorm:"column:sys_user_name;type:varchar(128);not null;default:''"` // 创建人姓名
  52. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  53. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  54. }
  55. var FeCalendarMatterCols = struct {
  56. FeCalendarMatterId string
  57. ChartPermissionId string
  58. ChartPermissionName string
  59. MatterMonth string
  60. MatterDate string
  61. Title string
  62. MatterType string
  63. EdbInfoId string
  64. EdbUniqueCode string
  65. EdbCode string
  66. FontColor string
  67. FillingColor string
  68. FontBold string
  69. Sort string
  70. SysUserId string
  71. SysUserName string
  72. CreateTime string
  73. ModifyTime string
  74. }{
  75. FeCalendarMatterId: "fe_calendar_matter_id",
  76. ChartPermissionId: "chart_permission_id",
  77. ChartPermissionName: "chart_permission_name",
  78. MatterMonth: "matter_month",
  79. MatterDate: "matter_date",
  80. Title: "title",
  81. MatterType: "matter_type",
  82. EdbInfoId: "edb_info_id",
  83. EdbUniqueCode: "edb_unique_code",
  84. EdbCode: "edb_code",
  85. FontColor: "font_color",
  86. FillingColor: "filling_color",
  87. FontBold: "font_bold",
  88. Sort: "sort",
  89. SysUserId: "sys_user_id",
  90. SysUserName: "sys_user_name",
  91. CreateTime: "create_time",
  92. ModifyTime: "modify_time",
  93. }
  94. func (m *FeCalendarMatter) TableName() string {
  95. return "fe_calendar_matter"
  96. }
  97. func (m *FeCalendarMatter) PrimaryId() string {
  98. return FeCalendarMatterCols.FeCalendarMatterId
  99. }
  100. //func (m *FeCalendarMatter) Create() (err error) {
  101. // o := orm.NewOrmUsingDB("data")
  102. // id, err := o.Insert(m)
  103. // if err != nil {
  104. // return
  105. // }
  106. // m.FeCalendarMatterId = int(id)
  107. // return
  108. //}
  109. //func (m *FeCalendarMatter) CreateMulti(items []*FeCalendarMatter) (err error) {
  110. // if len(items) == 0 {
  111. // return
  112. // }
  113. // o := orm.NewOrmUsingDB("data")
  114. // _, err = o.InsertMulti(len(items), items)
  115. // return
  116. //}
  117. //func (m *FeCalendarMatter) Update(cols []string) (err error) {
  118. // o := orm.NewOrmUsingDB("data")
  119. // _, err = o.Update(m, cols...)
  120. // return
  121. //}
  122. //func (m *FeCalendarMatter) Del() (err error) {
  123. // o := orm.NewOrmUsingDB("data")
  124. // sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  125. // _, err = o.Raw(sql, m.FeCalendarMatterId).Exec()
  126. // return
  127. //}
  128. //func (m *FeCalendarMatter) MultiDel(menuIds []int) (err error) {
  129. // if len(menuIds) == 0 {
  130. // return
  131. // }
  132. // o := orm.NewOrmUsingDB("data")
  133. // sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  134. // _, err = o.Raw(sql, menuIds).Exec()
  135. // return
  136. //}
  137. //func (m *FeCalendarMatter) GetItemById(id int) (item *FeCalendarMatter, err error) {
  138. // o := orm.NewOrmUsingDB("data")
  139. // sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  140. // err = o.Raw(sql, id).QueryRow(&item)
  141. // return
  142. //}
  143. //func (m *FeCalendarMatter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FeCalendarMatter, err error) {
  144. // o := orm.NewOrmUsingDB("data")
  145. // order := ``
  146. // if orderRule != "" {
  147. // order = ` ORDER BY ` + orderRule
  148. // }
  149. // sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  150. // err = o.Raw(sql, pars).QueryRow(&item)
  151. // return
  152. //}
  153. //func (m *FeCalendarMatter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  154. // o := orm.NewOrmUsingDB("data")
  155. // sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  156. // err = o.Raw(sql, pars).QueryRow(&count)
  157. // return
  158. //}
  159. func (m *FeCalendarMatter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FeCalendarMatter, err error) {
  160. //o := orm.NewOrmUsingDB("data")
  161. fields := strings.Join(fieldArr, ",")
  162. if len(fieldArr) == 0 {
  163. fields = `*`
  164. }
  165. order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  166. if orderRule != "" {
  167. order = ` ORDER BY ` + orderRule
  168. }
  169. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  170. //_, err = o.Raw(sql, pars).QueryRows(&items)
  171. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  172. return
  173. }
  174. //func (m *FeCalendarMatter) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FeCalendarMatter, err error) {
  175. // o := orm.NewOrmUsingDB("data")
  176. // fields := strings.Join(fieldArr, ",")
  177. // if len(fieldArr) == 0 {
  178. // fields = `*`
  179. // }
  180. // order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
  181. // if orderRule != "" {
  182. // order = ` ORDER BY ` + orderRule
  183. // }
  184. // sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  185. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  186. // return
  187. //}
  188. type FeCalendarMatterItem struct {
  189. FeCalendarMatterId int `description:"事项ID"`
  190. ChartPermissionId int `description:"品种ID"`
  191. ChartPermissionName string `description:"品种名称"`
  192. MatterDate string `description:"事项日期"`
  193. Title string `description:"标题"`
  194. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  195. EdbInfoId int `description:"指标ID"`
  196. EdbUniqueCode string `description:"指标唯一编码"`
  197. EdbCode string `description:"指标编码"`
  198. FontColor string `description:"字体颜色"`
  199. FillingColor string `description:"填充颜色"`
  200. FontBold int `description:"字体加粗:0-否;1-是"`
  201. Sort int `description:"排序"`
  202. }
  203. func FormatFeCalendarMatter2Item(origin *FeCalendarMatter) (item *FeCalendarMatterItem) {
  204. if origin == nil {
  205. return
  206. }
  207. item = new(FeCalendarMatterItem)
  208. item.FeCalendarMatterId = origin.FeCalendarMatterId
  209. item.ChartPermissionId = origin.ChartPermissionId
  210. item.ChartPermissionName = origin.ChartPermissionName
  211. item.MatterDate = utils.TimeTransferString(utils.FormatDate, origin.MatterDate)
  212. item.Title = origin.Title
  213. item.MatterType = origin.MatterType
  214. item.EdbInfoId = origin.EdbInfoId
  215. item.EdbUniqueCode = origin.EdbUniqueCode
  216. item.EdbCode = origin.EdbCode
  217. item.FontColor = origin.FontColor
  218. item.FillingColor = origin.FillingColor
  219. item.FontBold = origin.FontBold
  220. item.Sort = origin.Sort
  221. return
  222. }
  223. // FeCalendarMatterListReq 事项列表请求体
  224. type FeCalendarMatterListReq struct {
  225. ChartPermissionId int `form:"ChartPermissionId" description:"品种ID"`
  226. StartDate string `form:"StartDate" description:"开始日期"`
  227. EndDate string `form:"EndDate" description:"结束日期"`
  228. }
  229. // FeCalendarMatterListItem 事项列表
  230. type FeCalendarMatterListItem struct {
  231. Date string `description:"日期"`
  232. Matters []*FeCalendarMatterItem `description:"日期事项"`
  233. }
  234. // FeCalendarMatterSaveReq 保存事项请求体
  235. type FeCalendarMatterSaveReq struct {
  236. ChartPermissionId int `description:"品种ID"`
  237. MatterDate string `description:"日期"`
  238. Matters []*FeCalendarMatterSaveItem `description:"事项"`
  239. }
  240. type FeCalendarMatterSaveItem struct {
  241. FeCalendarMatterId int `description:"事项ID"`
  242. Title string `description:"标题"`
  243. MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
  244. EdbInfoId int `description:"指标ID"`
  245. EdbUniqueCode string `description:"指标唯一编码"`
  246. EdbCode string `description:"指标编码"`
  247. FontColor string `description:"字体颜色"`
  248. FillingColor string `description:"填充颜色"`
  249. FontBold int `description:"字体加粗:0-否;1-是"`
  250. Sort int `description:"排序"`
  251. }
  252. func (m *FeCalendarMatter) Save(addMatters, editMatters, removeMatters []*FeCalendarMatter, updateCols []string) (err error) {
  253. //o := orm.NewOrmUsingDB("data")
  254. //tx, e := o.Begin()
  255. //if e != nil {
  256. // err = fmt.Errorf("begin tx err: %s", e.Error())
  257. // return
  258. //}
  259. //defer func() {
  260. // if err != nil {
  261. // _ = tx.Rollback()
  262. // return
  263. // }
  264. // _ = tx.Commit()
  265. //}()
  266. //if len(addMatters) > 0 {
  267. // _, e = tx.InsertMulti(len(addMatters), addMatters)
  268. // if e != nil {
  269. // err = fmt.Errorf("insert multi err: %s", e.Error())
  270. // return
  271. // }
  272. //}
  273. //if len(editMatters) > 0 {
  274. // for _, v := range editMatters {
  275. // _, e = tx.Update(v, updateCols...)
  276. // if e != nil {
  277. // err = fmt.Errorf("update err: %s", e.Error())
  278. // return
  279. // }
  280. // }
  281. //}
  282. //if len(removeMatters) > 0 {
  283. // p, e := tx.Raw(fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())).Prepare()
  284. // if e != nil {
  285. // err = fmt.Errorf("remove prepare err: %s", e.Error())
  286. // return
  287. // }
  288. // defer func() {
  289. // _ = p.Close()
  290. // }()
  291. // for _, v := range removeMatters {
  292. // _, e = p.Exec(v.FeCalendarMatterId)
  293. // if e != nil {
  294. // err = fmt.Errorf("remove exec err: %s", e.Error())
  295. // return
  296. // }
  297. // }
  298. //}
  299. tx := global.DmSQL["data"].Begin()
  300. defer func() {
  301. if err != nil {
  302. _ = tx.Rollback()
  303. return
  304. }
  305. _ = tx.Commit()
  306. }()
  307. if len(addMatters) > 0 {
  308. e := tx.CreateInBatches(addMatters, utils.MultiAddNum).Error
  309. if e != nil {
  310. err = fmt.Errorf("insert multi err: %v", e)
  311. return
  312. }
  313. }
  314. if len(editMatters) > 0 {
  315. for _, v := range editMatters {
  316. e := tx.Select(updateCols).Updates(v).Error
  317. if e != nil {
  318. err = fmt.Errorf("update err: %v", e)
  319. return
  320. }
  321. }
  322. }
  323. if len(removeMatters) > 0 {
  324. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  325. for _, v := range removeMatters {
  326. e := tx.Exec(sql, v.FeCalendarMatterId).Error
  327. if e != nil {
  328. err = fmt.Errorf("remove exec err: %v", e)
  329. return
  330. }
  331. }
  332. }
  333. return
  334. }