manual_edb.go 14 KB

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