manual_edb.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type TargetDetailResp struct {
  9. Detail *EdbInfoItem
  10. ClassifyList []*EdbdataClassify
  11. }
  12. func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
  13. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? `
  14. err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error
  15. return
  16. }
  17. func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
  18. sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
  19. err = global.DmSQL["data"].Raw(sql, sysUserId, classifyId).Scan(&total).Error
  20. return
  21. }
  22. func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
  23. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? `
  24. err = global.DmSQL["edb"].Raw(sql, classifyId).First(&item).Error
  25. return
  26. }
  27. func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
  28. 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 `
  29. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  30. return
  31. }
  32. type EdbInfoListItem struct {
  33. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  34. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  35. Unit string `orm:"column(UNIT);" description:"单位"`
  36. Remark string `orm:"column(REMARK);" description:"备注"`
  37. Frequency string `description:"频度"`
  38. ClassifyId int `description:"分类id"`
  39. ClassifyName string `description:"分类名称"`
  40. CreateDate string `description:"创建时间"`
  41. UserId int `description:"录入用户id"`
  42. NoticeTime string `description:"通知时间"`
  43. Mobile string `description:"录入者手机号"`
  44. ModifyDate string `description:"待更新日期"`
  45. ModifyTime string `description:"数据更新时间"`
  46. Status string `description:"状态:未完成/完成"`
  47. UniqueCode string
  48. IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
  49. UserName string `description:"录入用户名称"`
  50. StartDate string `description:"数据开始日期"`
  51. EndDate string `description:"数据结束日期"`
  52. LatestValue float64 `description:"指标最新值"`
  53. }
  54. type EdbListResp struct {
  55. List []*EdbInfoListItem
  56. Paging *paging.PagingItem `description:"分页数据"`
  57. }
  58. func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
  59. sql := `SELECT DISTINCT a.* FROM edbinfo AS a WHERE a.classify_id > 0 `
  60. if condition != "" {
  61. sql += condition
  62. }
  63. sql += ` ORDER BY a.create_date DESC `
  64. if pageSize > 0 {
  65. sql += ` LIMIT ?,? `
  66. pars = append(pars, startSize)
  67. pars = append(pars, pageSize)
  68. }
  69. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  70. return
  71. }
  72. func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
  73. sql := `SELECT COUNT(1) ct FROM edbinfo AS a WHERE a.classify_id > 0 `
  74. if condition != "" {
  75. sql += condition
  76. }
  77. sql += ` ORDER BY a.create_date DESC `
  78. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&total).Error
  79. return
  80. }
  81. func OnlyMultiAddEdbdata(items []*Edbdata) (err error) {
  82. err = global.DmSQL["edb"].CreateInBatches(items, utils.MultiAddNum).Error
  83. return
  84. }
  85. func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) {
  86. num := len(dateList)
  87. if num <= 0 {
  88. return
  89. }
  90. sql := `delete from edbdata WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) `
  91. err = global.DmSQL["edb"].Exec(sql, tradeCode, dateList).Error
  92. return
  93. }
  94. func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
  95. sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
  96. err = global.DmSQL["edb"].Exec(sql, isJoinEdb, edbCode).Error
  97. return
  98. }
  99. type BatchManualEdbReq struct {
  100. FrequencyList []string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  101. Keyword string `description:"关键字"`
  102. ClassifyIdList []int `description:"所选品种id列表"`
  103. UserIdList []int `description:"所选用户id列表"`
  104. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  105. TradeCodeList []string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  106. PageSize int `form:"PageSize" json:"PageSize"`
  107. CurrentIndex int `form:"CurrentIndex" form:"CurrentIndex"`
  108. }
  109. func DelManualIndexByCodeList(codeList []string) (err error) {
  110. num := len(codeList)
  111. if num <= 0 {
  112. return
  113. }
  114. to := global.DmSQL["edb"].Begin()
  115. defer func() {
  116. if err != nil {
  117. _ = to.Rollback()
  118. } else {
  119. _ = to.Commit()
  120. }
  121. }()
  122. sql := `DELETE FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  123. err = to.Exec(sql, codeList).Error
  124. if err != nil {
  125. }
  126. sql = `DELETE FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  127. err = to.Exec(sql, codeList).Error
  128. if err != nil {
  129. }
  130. return
  131. }
  132. func GetEdbinfoListBySecNameList(secNameList []string) (items []*Edbinfo, err error) {
  133. num := len(secNameList)
  134. if num <= 0 {
  135. return
  136. }
  137. sql := `SELECT * FROM edbinfo WHERE SEC_NAME in (` + utils.GetOrmInReplace(num) + ` ) AND REMARK='手动' `
  138. err = global.DmSQL["edb"].Raw(sql, secNameList).Find(&items).Error
  139. return
  140. }
  141. func GetTargetsDataListByCodeList(tradeCodeList []string) (items []*Edbdata, err error) {
  142. num := len(tradeCodeList)
  143. if num <= 0 {
  144. return
  145. }
  146. sql := `SELECT * FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + ` ) ORDER BY DT ASC `
  147. err = global.DmSQL["edb"].Raw(sql, tradeCodeList).Find(&items).Error
  148. return
  149. }
  150. type EdbinfoOpRecord struct {
  151. EdbinfoOpRecordId int `gorm:"column:edbinfo_op_record_id;primaryKey;type:int" orm:"column(edbinfo_op_record_id);pk" gorm:"primaryKey" description:"操作记录ID"`
  152. TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255)" orm:"column(TRADE_CODE)" description:"指标编码"`
  153. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(remark)" description:"操作信息"`
  154. UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"用户id"`
  155. UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"用户姓名"`
  156. CreateTime time.Time `gorm:"column:CREATE_TIME;type:datetime" orm:"column(create_time)" description:"创建时间"`
  157. }
  158. func (m *EdbinfoOpRecord) Create() (err error) {
  159. err = global.DmSQL["edb"].Create(m).Error
  160. return
  161. }
  162. func (m *EdbinfoOpRecord) MulCreate(list []*EdbinfoOpRecord) (err error) {
  163. err = global.DmSQL["edb"].CreateInBatches(list, utils.MultiAddNum).Error
  164. return
  165. }
  166. type EdbinfoOpRecordItem struct {
  167. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  168. Remark string `orm:"column(remark)" description:"操作信息"`
  169. UserId int `orm:"column(user_id)" description:"用户id"`
  170. UserName string `orm:"column(user_name)" description:"用户姓名"`
  171. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  172. }
  173. type EdbinfoOpRecordListResp struct {
  174. List []*EdbinfoOpRecordItem
  175. Paging *paging.PagingItem `description:"分页数据"`
  176. }
  177. func GetEdbinfoOpRecordPageList(tradeCode string, startSize, pageSize int) (total int, items []*EdbinfoOpRecordItem, err error) {
  178. sql := `SELECT count(1) FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? `
  179. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&total).Error
  180. if err != nil {
  181. return
  182. }
  183. sql = `SELECT a.* FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ORDER BY a.create_time DESC LIMIT ?,?`
  184. err = global.DmSQL["edb"].Raw(sql, tradeCode, startSize, pageSize).Find(&items).Error
  185. return
  186. }
  187. func GetManualEdbCountByCondition(condition string, pars []interface{}) (count int, err error) {
  188. sql := ` SELECT COUNT(1) AS count FROM edbinfo WHERE 1=1 `
  189. if condition != "" {
  190. sql += condition
  191. }
  192. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error
  193. return
  194. }
  195. func DelEdbinfoOpRecordByTradeCode(tradeCode string) (err error) {
  196. sql := ` DELETE FROM edbinfo_op_record WHERE TRADE_CODE = ? `
  197. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  198. return
  199. }