manual_edb.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. // TargetDetailResp 指标数据结构体
  9. type TargetDetailResp struct {
  10. Detail *EdbInfoItem
  11. ClassifyList []*EdbdataClassify
  12. }
  13. // GetTargetByTradeCode
  14. // @Description: 根据手工指标编码获取指标信息
  15. // @author: Roc
  16. // @datetime 2024-07-16 14:18:10
  17. // @param tradeCode string
  18. // @return item *Edbinfo
  19. // @return err error
  20. func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
  21. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? `
  22. //o := orm.NewOrmUsingDB("edb")
  23. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  24. err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error
  25. return
  26. }
  27. // GetCountManualUserClassify
  28. // @Description: 根据用户ID和分类ID获取关系数量
  29. // @author: Roc
  30. // @datetime 2024-07-16 14:27:58
  31. // @param sysUserId int
  32. // @param classifyId int
  33. // @return total int
  34. // @return err error
  35. func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
  36. //o := orm.NewOrmUsingDB("data")
  37. sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
  38. //err = o.Raw(sql, sysUserId, classifyId).QueryRow(&total)
  39. err = global.DmSQL["data"].Raw(sql, sysUserId, classifyId).Scan(&total).Error
  40. return
  41. }
  42. func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
  43. //o := orm.NewOrmUsingDB("edb")
  44. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? `
  45. //err = o.Raw(sql, classifyId).QueryRow(&item)
  46. err = global.DmSQL["edb"].Raw(sql, classifyId).First(&item).Error
  47. return
  48. }
  49. // GetEdbDataListByCode
  50. // @Description: 通过指标ID获取所有数据
  51. // @author: Roc
  52. // @datetime 2024-07-16 15:32:41
  53. // @param tradeCode string
  54. // @return items []*Edbdata
  55. // @return err error
  56. func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
  57. 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 `
  58. //o := orm.NewOrmUsingDB("edb")
  59. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  60. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  61. return
  62. }
  63. // EdbInfoListItem
  64. type EdbInfoListItem struct {
  65. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  66. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  67. Unit string `orm:"column(UNIT);" description:"单位"`
  68. Remark string `orm:"column(REMARK);" description:"备注"`
  69. Frequency string `description:"频度"`
  70. ClassifyId int `description:"分类id"`
  71. ClassifyName string `description:"分类名称"`
  72. CreateDate string `description:"创建时间"`
  73. UserId int `description:"录入用户id"`
  74. NoticeTime string `description:"通知时间"`
  75. Mobile string `description:"录入者手机号"`
  76. ModifyDate string `description:"待更新日期"`
  77. ModifyTime string `description:"数据更新时间"`
  78. Status string `description:"状态:未完成/完成"`
  79. UniqueCode string
  80. IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
  81. UserName string `description:"录入用户名称"`
  82. StartDate string `description:"数据开始日期"`
  83. EndDate string `description:"数据结束日期"`
  84. LatestValue float64 `description:"指标最新值"`
  85. }
  86. // EdbListResp 指标数据结构体
  87. type EdbListResp struct {
  88. List []*EdbInfoListItem
  89. Paging *paging.PagingItem `description:"分页数据"`
  90. }
  91. // GetEdbInfoList
  92. // @Description: 根据条件获取指标列表
  93. // @author: Roc
  94. // @datetime 2024-07-17 10:34:05
  95. // @param condition string
  96. // @param pars []interface{}
  97. // @return items []*Edbinfo
  98. // @return err error
  99. func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
  100. //o := orm.NewOrmUsingDB("edb")
  101. sql := `SELECT DISTINCT a.* FROM edbinfo AS a WHERE a.classify_id > 0 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. sql += ` ORDER BY a.create_date DESC `
  106. if pageSize > 0 {
  107. sql += ` LIMIT ?,? `
  108. pars = append(pars, startSize)
  109. pars = append(pars, pageSize)
  110. }
  111. //_, err = o.Raw(sql, pars).QueryRows(&items)
  112. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  113. return
  114. }
  115. // GetCountEdbInfoList
  116. // @Description: 根据条件获取指标数量
  117. // @author: Roc
  118. // @datetime 2024-07-17 14:51:00
  119. // @param condition string
  120. // @param pars []interface{}
  121. // @return total int
  122. // @return err error
  123. func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
  124. //o := orm.NewOrmUsingDB("edb")
  125. sql := `SELECT COUNT(1) ct FROM edbinfo AS a WHERE a.classify_id > 0 `
  126. if condition != "" {
  127. sql += condition
  128. }
  129. sql += ` ORDER BY a.create_date DESC `
  130. //err = o.Raw(sql, pars).QueryRow(&total)
  131. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&total).Error
  132. return
  133. }
  134. // OnlyMultiAddEdbdata
  135. // @Description: 批量添加指标数据
  136. // @author: Roc
  137. // @datetime 2024-07-18 16:48:55
  138. // @param items []*Edbdata
  139. // @return err error
  140. func OnlyMultiAddEdbdata(items []*Edbdata) (err error) {
  141. //o := orm.NewOrmUsingDB("edb")
  142. //_, err = o.InsertMulti(utils.MultiAddNum, items)
  143. err = global.DmSQL["edb"].CreateInBatches(items, utils.MultiAddNum).Error
  144. return
  145. }
  146. // DelEdbdataByCodeAndDateList
  147. // @Description: 根据指标编码和日期列表批量删除指标的明细数据
  148. // @author: Roc
  149. // @datetime 2024-07-18 16:54:27
  150. // @param tradeCode string
  151. // @param dateList []string
  152. // @return err error
  153. func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) {
  154. num := len(dateList)
  155. if num <= 0 {
  156. return
  157. }
  158. //o := orm.NewOrmUsingDB("edb")
  159. sql := `delete from edbdata WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) `
  160. //_, err = o.Raw(sql, tradeCode, dateList).Exec()
  161. err = global.DmSQL["edb"].Exec(sql, tradeCode, dateList).Error
  162. return
  163. }
  164. // UpdateManualIsJoinEdbStatus
  165. // @Description: 根据手工数据加入指标的状态
  166. // @author: Roc
  167. // @datetime 2024-07-22 11:29:13
  168. // @param edbCode string
  169. // @param isJoinEdb int 是否加入指标库
  170. // @return err error
  171. func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
  172. //o := orm.NewOrmUsingDB("edb")
  173. sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
  174. //_, err = o.Raw(sql, isJoinEdb, edbCode).Exec()
  175. err = global.DmSQL["edb"].Exec(sql, isJoinEdb, edbCode).Error
  176. return
  177. }
  178. // BatchManualEdbReq 指标数据结构体
  179. type BatchManualEdbReq struct {
  180. //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  181. FrequencyList []string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  182. Keyword string `description:"关键字"`
  183. ClassifyIdList []int `description:"所选品种id列表"`
  184. UserIdList []int `description:"所选用户id列表"`
  185. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  186. TradeCodeList []string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  187. PageSize int `form:"PageSize" json:"PageSize"`
  188. CurrentIndex int `form:"CurrentIndex" form:"CurrentIndex"`
  189. }
  190. // DelManualIndexByCodeList
  191. // @Description: 根据指标编码列表删除指标
  192. // @author: Roc
  193. // @datetime 2024-07-30 14:10:12
  194. // @param codeList []string
  195. // @return err error
  196. func DelManualIndexByCodeList(codeList []string) (err error) {
  197. num := len(codeList)
  198. if num <= 0 {
  199. return
  200. }
  201. //to, err := orm.NewOrmUsingDB("edb").Begin()
  202. to := global.DmSQL["edb"].Begin()
  203. defer func() {
  204. if err != nil {
  205. _ = to.Rollback()
  206. } else {
  207. _ = to.Commit()
  208. }
  209. }()
  210. // 删除指标
  211. sql := `DELETE FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  212. //_, err = to.Raw(sql, codeList).Exec()
  213. err = to.Exec(sql, codeList).Error
  214. if err != nil {
  215. }
  216. // 删除指标数据
  217. sql = `DELETE FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  218. // _, err = to.Raw(sql, codeList).Exec()
  219. err = to.Exec(sql, codeList).Error
  220. if err != nil {
  221. }
  222. return
  223. }
  224. // GetEdbinfoListBySecNameList
  225. // @Description: 根据指标名称获取列表数据
  226. // @author: Roc
  227. // @datetime 2024-07-30 19:14:25
  228. // @param secNameList []string
  229. // @return item []*Edbinfo
  230. // @return err error
  231. func GetEdbinfoListBySecNameList(secNameList []string) (items []*Edbinfo, err error) {
  232. num := len(secNameList)
  233. if num <= 0 {
  234. return
  235. }
  236. sql := `SELECT * FROM edbinfo WHERE SEC_NAME in (` + utils.GetOrmInReplace(num) + ` ) AND REMARK='手动' `
  237. //o := orm.NewOrmUsingDB("edb")
  238. //_, err = o.Raw(sql, secNameList).QueryRows(&items)
  239. err = global.DmSQL["edb"].Raw(sql, secNameList).Find(&items).Error
  240. return
  241. }
  242. // GetTargetsDataListByCodeList
  243. // @Description: 根据code列表获取指标数据列表
  244. // @author: Roc
  245. // @datetime 2024-07-30 19:19:36
  246. // @param tradeCodeList []string
  247. // @return items []*Edbdata
  248. // @return err error
  249. func GetTargetsDataListByCodeList(tradeCodeList []string) (items []*Edbdata, err error) {
  250. num := len(tradeCodeList)
  251. if num <= 0 {
  252. return
  253. }
  254. //o := orm.NewOrmUsingDB("edb")
  255. sql := `SELECT * FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + ` ) ORDER BY DT ASC `
  256. //_, err = o.Raw(sql, tradeCodeList).QueryRows(&items)
  257. err = global.DmSQL["edb"].Raw(sql, tradeCodeList).Find(&items).Error
  258. return
  259. }
  260. // EdbinfoOpRecord
  261. // @Description: 手工数据的操作日志
  262. type EdbinfoOpRecord struct {
  263. EdbinfoOpRecordId int `gorm:"column:edbinfo_op_record_id;primaryKey;type:int" orm:"column(edbinfo_op_record_id);pk" gorm:"primaryKey" description:"操作记录ID"`
  264. TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255)" orm:"column(TRADE_CODE)" description:"指标编码"`
  265. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(remark)" description:"操作信息"`
  266. UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"用户id"`
  267. UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"用户姓名"`
  268. CreateTime time.Time `gorm:"column:CREATE_TIME;type:datetime" orm:"column(create_time)" description:"创建时间"`
  269. }
  270. // Remark备注:
  271. // 1、创建指标
  272. // 2、编辑指标
  273. // 3、更新数据
  274. // 4、数据资产由<xxx>转移给<xxx>
  275. // Create
  276. // @Description: 添加手工数据的操作日志
  277. // @author: Roc
  278. // @receiver m
  279. // @datetime 2024-07-30 16:25:55
  280. // @return err error
  281. func (m *EdbinfoOpRecord) Create() (err error) {
  282. //o := orm.NewOrmUsingDB("edb")
  283. //_, err = o.Insert(m)
  284. err = global.DmSQL["edb"].Create(m).Error
  285. return
  286. }
  287. // MulCreate
  288. // @Description: 批量添加手工数据的操作日志
  289. // @author: Roc
  290. // @receiver m
  291. // @datetime 2024-08-01 11:05:02
  292. // @param list []*EdbinfoOpRecord
  293. // @return err error
  294. func (m *EdbinfoOpRecord) MulCreate(list []*EdbinfoOpRecord) (err error) {
  295. //o := orm.NewOrmUsingDB("edb")
  296. //_, err = o.InsertMulti(utils.MultiAddNum, list)
  297. err = global.DmSQL["edb"].CreateInBatches(list, utils.MultiAddNum).Error
  298. return
  299. }
  300. // EdbinfoOpRecordItem
  301. // @Description: 手工数据的操作日志
  302. type EdbinfoOpRecordItem struct {
  303. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  304. Remark string `orm:"column(remark)" description:"操作信息"`
  305. UserId int `orm:"column(user_id)" description:"用户id"`
  306. UserName string `orm:"column(user_name)" description:"用户姓名"`
  307. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  308. }
  309. // EdbinfoOpRecordListResp 指标数据结构体
  310. type EdbinfoOpRecordListResp struct {
  311. List []*EdbinfoOpRecordItem
  312. Paging *paging.PagingItem `description:"分页数据"`
  313. }
  314. // GetEdbinfoOpRecordPageList
  315. // @Description: 根据指标编码获取手工数据的操作日志
  316. // @author: Roc
  317. // @datetime 2024-07-30 17:32:33
  318. // @param tradeCode string
  319. // @param startSize int
  320. // @param total int
  321. // @return pageSize int
  322. // @return items []*EdbinfoOpRecordItem
  323. // @return err error
  324. func GetEdbinfoOpRecordPageList(tradeCode string, startSize, pageSize int) (total int, items []*EdbinfoOpRecordItem, err error) {
  325. //o := orm.NewOrmUsingDB("edb")
  326. sql := `SELECT count(1) FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? `
  327. //err = o.Raw(sql, tradeCode).QueryRow(&total)
  328. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&total).Error
  329. if err != nil {
  330. return
  331. }
  332. sql = `SELECT a.* FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ORDER BY a.create_time DESC LIMIT ?,?`
  333. //_, err = o.Raw(sql, tradeCode, startSize, pageSize).QueryRows(&items)
  334. err = global.DmSQL["edb"].Raw(sql, tradeCode, startSize, pageSize).Find(&items).Error
  335. return
  336. }
  337. // GetManualEdbCountByCondition
  338. // @Description: 根据获取手工数据条数
  339. // @author: Roc
  340. // @datetime 2024-08-05 09:37:16
  341. // @param condition string
  342. // @param pars []interface{}
  343. // @return count int
  344. // @return err error
  345. func GetManualEdbCountByCondition(condition string, pars []interface{}) (count int, err error) {
  346. //o := orm.NewOrmUsingDB("edb")
  347. sql := ` SELECT COUNT(1) AS count FROM edbinfo WHERE 1=1 `
  348. if condition != "" {
  349. sql += condition
  350. }
  351. //err = o.Raw(sql, pars).QueryRow(&count)
  352. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error
  353. return
  354. }
  355. // DelEdbinfoOpRecordByTradeCode
  356. // @Description: 根据指标编码删除操作日志
  357. // @author: Roc
  358. // @datetime 2024-08-05 10:27:29
  359. // @param tradeCode string
  360. // @return err error
  361. func DelEdbinfoOpRecordByTradeCode(tradeCode string) (err error) {
  362. //o := orm.NewOrmUsingDB("edb")
  363. sql := ` DELETE FROM edbinfo_op_record WHERE TRADE_CODE = ? `
  364. //_, err = o.Raw(sql, tradeCode).Exec()
  365. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  366. return
  367. }