manual_edb.go 13 KB

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