manual_edb.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. )
  7. // TargetDetailResp 指标数据结构体
  8. type TargetDetailResp struct {
  9. Detail *EdbInfoItem
  10. ClassifyList []*EdbdataClassify
  11. }
  12. // GetTargetByTradeCode
  13. // @Description: 根据手工指标编码获取指标信息
  14. // @author: Roc
  15. // @datetime 2024-07-16 14:18:10
  16. // @param tradeCode string
  17. // @return item *Edbinfo
  18. // @return err error
  19. func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
  20. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? `
  21. o := orm.NewOrmUsingDB("edb")
  22. err = o.Raw(sql, tradeCode).QueryRow(&item)
  23. return
  24. }
  25. // GetCountManualUserClassify
  26. // @Description: 根据用户ID和分类ID获取关系数量
  27. // @author: Roc
  28. // @datetime 2024-07-16 14:27:58
  29. // @param sysUserId int
  30. // @param classifyId int
  31. // @return total int
  32. // @return err error
  33. func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
  34. o := orm.NewOrmUsingDB("data")
  35. sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
  36. err = o.Raw(sql, sysUserId, classifyId).QueryRow(&total)
  37. return
  38. }
  39. func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
  40. o := orm.NewOrmUsingDB("edb")
  41. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? `
  42. err = o.Raw(sql, classifyId).QueryRow(&item)
  43. return
  44. }
  45. // GetEdbDataListByCode
  46. // @Description: 通过指标ID获取所有数据
  47. // @author: Roc
  48. // @datetime 2024-07-16 15:32:41
  49. // @param tradeCode string
  50. // @return items []*Edbdata
  51. // @return err error
  52. func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
  53. sql := ` SELECT TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time FROM edbdata WHERE TRADE_CODE = ? GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
  54. o := orm.NewOrmUsingDB("edb")
  55. _, err = o.Raw(sql, tradeCode).QueryRows(&items)
  56. return
  57. }
  58. // EdbInfoListItem
  59. type EdbInfoListItem struct {
  60. TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
  61. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  62. Unit string `orm:"column(UNIT);" description:"单位"`
  63. Remark string `orm:"column(REMARK);" description:"备注"`
  64. Frequency string `description:"频度"`
  65. ClassifyId int `description:"分类id"`
  66. ClassifyName string `description:"分类名称"`
  67. CreateDate string `description:"创建时间"`
  68. UserId int `description:"录入用户id"`
  69. NoticeTime string `description:"通知时间"`
  70. Mobile string `description:"录入者手机号"`
  71. ModifyDate string `description:"待更新日期"`
  72. Status string `description:"状态:未完成/完成"`
  73. UniqueCode string
  74. IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
  75. UserName string `description:"录入用户名称"`
  76. }
  77. // EdbListResp 指标数据结构体
  78. type EdbListResp struct {
  79. List []*EdbInfoListItem
  80. Paging *paging.PagingItem `description:"分页数据"`
  81. }
  82. // GetEdbInfoList
  83. // @Description: 根据条件获取指标列表
  84. // @author: Roc
  85. // @datetime 2024-07-17 10:34:05
  86. // @param condition string
  87. // @param pars []interface{}
  88. // @return items []*Edbinfo
  89. // @return err error
  90. func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
  91. o := orm.NewOrmUsingDB("edb")
  92. sql := `SELECT DISTINCT a.* FROM edbinfo AS a WHERE a.REMARK='手动' `
  93. if condition != "" {
  94. sql += condition
  95. }
  96. sql += ` ORDER BY a.create_date DESC `
  97. if pageSize > 0 {
  98. sql += ` LIMIT ?,? `
  99. pars = append(pars, startSize, pageSize)
  100. }
  101. _, err = o.Raw(sql, pars).QueryRows(&items)
  102. return
  103. }
  104. // GetCountEdbInfoList
  105. // @Description: 根据条件获取指标数量
  106. // @author: Roc
  107. // @datetime 2024-07-17 14:51:00
  108. // @param condition string
  109. // @param pars []interface{}
  110. // @return total int
  111. // @return err error
  112. func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
  113. o := orm.NewOrmUsingDB("edb")
  114. sql := `SELECT COUNT(1) ct FROM edbinfo AS a WHERE a.REMARK='手动' `
  115. if condition != "" {
  116. sql += condition
  117. }
  118. sql += ` ORDER BY a.create_date DESC `
  119. err = o.Raw(sql, pars).QueryRow(&total)
  120. return
  121. }
  122. // OnlyMultiAddEdbdata
  123. // @Description: 批量添加指标数据
  124. // @author: Roc
  125. // @datetime 2024-07-18 16:48:55
  126. // @param items []*Edbdata
  127. // @return err error
  128. func OnlyMultiAddEdbdata(items []*Edbdata) (err error) {
  129. o := orm.NewOrmUsingDB("edb")
  130. _, err = o.InsertMulti(utils.MultiAddNum, items)
  131. return
  132. }
  133. // DelEdbdataByCodeAndDateList
  134. // @Description: 根据指标编码和日期列表批量删除指标的明细数据
  135. // @author: Roc
  136. // @datetime 2024-07-18 16:54:27
  137. // @param tradeCode string
  138. // @param dateList []string
  139. // @return err error
  140. func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) {
  141. num := len(dateList)
  142. if num <= 0 {
  143. return
  144. }
  145. o := orm.NewOrmUsingDB("edb")
  146. sql := `delete from edbdata AS a WHERE a.TRADE_CODE=? and DT in (` + utils.GetOrmInReplace(num) + `) `
  147. _, err = o.Raw(sql, tradeCode, dateList).Exec()
  148. return
  149. }
  150. // UpdateManualIsJoinEdbStatus
  151. // @Description: 根据手工数据加入指标的状态
  152. // @author: Roc
  153. // @datetime 2024-07-22 11:29:13
  154. // @param edbCode string
  155. // @param isJoinEdb int 是否加入指标库
  156. // @return err error
  157. func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
  158. o := orm.NewOrmUsingDB("edb")
  159. sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
  160. _, err = o.Raw(sql, isJoinEdb, edbCode).Exec()
  161. return
  162. }
  163. // BatchManualEdbReq 指标数据结构体
  164. type BatchManualEdbReq struct {
  165. IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  166. FrequencyList []string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  167. Keyword string `description:"关键字"`
  168. ClassifyIdList []int `description:"所选品种id列表"`
  169. UserIdList []int `description:"所选用户id列表"`
  170. ListAll bool `form:"ListAll" description:"列表全选"`
  171. TradeCodeList []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  172. PageSize int `form:"PageSize"`
  173. CurrentIndex int `form:"CurrentIndex"`
  174. }