handle_data.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. package eta_bridge
  2. import (
  3. "encoding/json"
  4. "eta/eta_task/models/data_manage"
  5. "eta/eta_task/utils"
  6. "fmt"
  7. "strings"
  8. )
  9. // handleData
  10. // @Description: 监听的数据处理
  11. // @author: Roc
  12. // @datetime 2024-03-11 14:52:49
  13. // @param edbUpdateLog *data_manage.EdbUpdateLog
  14. // @return pushIndexData *PushIndexParamDataReq
  15. // @return pushEdbClassify *PushEdbClassifyItemReq
  16. // @return pushIndexValue *PushIndexValueItemReq
  17. // @return err error
  18. func handleData(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  19. switch edbUpdateLog.OpType {
  20. case "insert":
  21. return handleInsert(edbUpdateLog)
  22. case "update":
  23. return handleUpdate(edbUpdateLog)
  24. case "delete":
  25. return handleDelete(edbUpdateLog)
  26. }
  27. return
  28. }
  29. // handleInsert
  30. // @Description: 新增数据处理
  31. // @author: Roc
  32. // @datetime 2024-03-11 14:53:03
  33. // @param edbUpdateLog *data_manage.EdbUpdateLog
  34. // @return pushIndexData *PushIndexParamDataReq
  35. // @return pushEdbClassify *PushEdbClassifyItemReq
  36. // @return pushIndexValue *PushIndexValueItemReq
  37. // @return err error
  38. func handleInsert(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  39. data := edbUpdateLog.NewData
  40. //指标信息
  41. if edbUpdateLog.OpTableName == "edb_info" {
  42. var edbInfo *data_manage.EdbInfoItem
  43. err = json.Unmarshal([]byte(data), &edbInfo)
  44. if err != nil {
  45. return
  46. }
  47. // 预测指标不处理
  48. if edbInfo.EdbInfoType == 1 {
  49. return
  50. }
  51. // 计算指标不处理
  52. if edbInfo.EdbType == 2 {
  53. return
  54. }
  55. // 自有数据不处理
  56. if edbInfo.Source == utils.DATA_SOURCE_BUSINESS {
  57. return
  58. }
  59. // 获取数据源中指标的基础信息
  60. origInfo := getOrigInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, edbInfo.EdbName)
  61. // 指标信息
  62. pushIndexData = &PushIndexParamDataReq{
  63. SourceIndexCode: edbInfo.EdbCode,
  64. IndexCode: getIndexCode(edbInfo.Source, edbInfo.EdbCode),
  65. IndexName: origInfo.EdbName,
  66. IndexShortName: edbInfo.EdbName,
  67. FrequenceName: edbInfo.Frequency,
  68. UnitName: edbInfo.Unit,
  69. AssetBeginDate: edbInfo.StartDate,
  70. AssetEndDate: edbInfo.EndDate,
  71. CreateUser: edbInfo.SysUserRealName,
  72. IndexCreateTime: edbInfo.CreateTime,
  73. UpdateUser: edbInfo.SysUserRealName,
  74. DetailUpdateTime: getMaxModifyTime(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
  75. IndexUpdateTime: edbInfo.ModifyTime,
  76. OrginSource: edbInfo.SourceName,
  77. OrginSysSource: origInfo.SourceName,
  78. SysSource: "产研平台",
  79. SourceType: getSourceType(edbInfo.Source),
  80. Status: 1,
  81. }
  82. // 指标与分类的关系信息
  83. pushEdbClassify = &PushEdbClassifyItemReq{
  84. Id: fmt.Sprint(edbInfo.EdbInfoId),
  85. ClassifyId: edbInfo.ClassifyId,
  86. IndexCode: getIndexCode(edbInfo.Source, edbInfo.EdbCode),
  87. CreateTime: edbInfo.CreateTime,
  88. CreateUser: edbInfo.SysUserRealName,
  89. UpdateTime: edbInfo.ModifyTime,
  90. UpdateUser: edbInfo.SysUserRealName,
  91. }
  92. return
  93. }
  94. // 分类信息
  95. //if edbUpdateLog.OpTableName == "edb_classify" {
  96. // var edbClassify *data_manage.EdbClassify
  97. // err = json.Unmarshal([]byte(data), &edbClassify)
  98. // if err != nil {
  99. // return
  100. // }
  101. //
  102. // // 指标信息
  103. // pushClassify = PushClassifyItemReq{
  104. // ClassifyId: int(edbClassify.ClassifyID),
  105. // ClassifyType: int(edbClassify.ClassifyType),
  106. // ClassifyName: edbClassify.ClassifyName,
  107. // ParentId: int(edbClassify.ParentID),
  108. // HasData: int(edbClassify.HasData),
  109. // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
  110. // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
  111. // SysUserId: int(edbClassify.SysUserID),
  112. // SysUserRealName: edbClassify.SysUserRealName,
  113. // Level: int(edbClassify.Level),
  114. // UniqueCode: edbClassify.UniqueCode,
  115. // SortColumn: int(edbClassify.Sort),
  116. // }
  117. //
  118. // return
  119. //}
  120. // 数据信息
  121. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  122. // 计算指标不处理
  123. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
  124. return
  125. }
  126. // 预测指标不处理
  127. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
  128. return
  129. }
  130. var edbData *data_manage.EdbData
  131. err = json.Unmarshal([]byte(data), &edbData)
  132. if err != nil {
  133. return
  134. }
  135. source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
  136. if source <= 0 {
  137. // 没有找到来源,那就过滤
  138. return
  139. }
  140. // 数据信息
  141. pushIndexValue = &PushIndexValueItemReq{
  142. Id: getIndexDataId(source, subSource, edbData.EdbDataId),
  143. IndexCode: getIndexCode(source, edbData.EdbCode),
  144. Value: fmt.Sprint(edbData.Value),
  145. BusinessDate: edbData.DataTime,
  146. CreateTime: edbData.CreateTime,
  147. UpdateTime: edbData.ModifyTime,
  148. Status: "1",
  149. }
  150. return
  151. }
  152. return
  153. }
  154. // handleDelete
  155. // @Description: 删除数据处理
  156. // @author: Roc
  157. // @datetime 2024-03-11 14:53:20
  158. // @param edbUpdateLog *data_manage.EdbUpdateLog
  159. // @return pushIndexData *PushIndexParamDataReq
  160. // @return pushEdbClassify *PushEdbClassifyItemReq
  161. // @return pushIndexValue *PushIndexValueItemReq
  162. // @return err error
  163. func handleDelete(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  164. data := edbUpdateLog.OldData
  165. //指标信息
  166. if edbUpdateLog.OpTableName == "edb_info" {
  167. var edbInfo *data_manage.EdbInfoItem
  168. err = json.Unmarshal([]byte(data), &edbInfo)
  169. if err != nil {
  170. return
  171. }
  172. // 预测指标不处理
  173. if edbInfo.EdbInfoType == 1 {
  174. return
  175. }
  176. // 计算指标不处理
  177. if edbInfo.EdbType == 2 {
  178. return
  179. }
  180. // 自有数据不处理
  181. if edbInfo.Source == utils.DATA_SOURCE_BUSINESS {
  182. return
  183. }
  184. // 获取数据源中指标的基础信息
  185. origInfo := getOrigInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, edbInfo.EdbName)
  186. // 指标信息
  187. pushIndexData = &PushIndexParamDataReq{
  188. SourceIndexCode: edbInfo.EdbCode,
  189. IndexCode: getIndexCode(edbInfo.Source, edbInfo.EdbCode),
  190. IndexName: origInfo.EdbName,
  191. IndexShortName: edbInfo.EdbName,
  192. FrequenceName: edbInfo.Frequency,
  193. UnitName: edbInfo.Unit,
  194. AssetBeginDate: edbInfo.StartDate,
  195. AssetEndDate: edbInfo.EndDate,
  196. CreateUser: edbInfo.SysUserRealName,
  197. IndexCreateTime: edbInfo.CreateTime,
  198. UpdateUser: edbInfo.SysUserRealName,
  199. DetailUpdateTime: edbUpdateLog.CreateTime.Format(utils.FormatDateTime),
  200. IndexUpdateTime: edbInfo.ModifyTime,
  201. OrginSource: edbInfo.SourceName,
  202. OrginSysSource: origInfo.SourceName,
  203. SysSource: "产研平台",
  204. SourceType: getSourceType(edbInfo.Source),
  205. Status: 0,
  206. }
  207. // 指标与分类的关系信息
  208. pushEdbClassify = &PushEdbClassifyItemReq{
  209. Id: fmt.Sprint(edbInfo.EdbInfoId),
  210. ClassifyId: edbInfo.ClassifyId,
  211. IndexCode: getIndexCode(edbInfo.Source, edbInfo.EdbCode),
  212. CreateTime: edbInfo.CreateTime,
  213. CreateUser: edbInfo.SysUserRealName,
  214. UpdateTime: edbInfo.ModifyTime,
  215. UpdateUser: edbInfo.SysUserRealName,
  216. }
  217. return
  218. }
  219. // 分类信息
  220. //if edbUpdateLog.OpTableName == "edb_classify" {
  221. // var edbClassify *data_manage.EdbClassify
  222. // err = json.Unmarshal([]byte(data), &edbClassify)
  223. // if err != nil {
  224. // return
  225. // }
  226. //
  227. // // 指标信息
  228. // pushClassify = PushClassifyItemReq{
  229. // ClassifyId: int(edbClassify.ClassifyID),
  230. // ClassifyType: int(edbClassify.ClassifyType),
  231. // ClassifyName: edbClassify.ClassifyName,
  232. // ParentId: int(edbClassify.ParentID),
  233. // HasData: int(edbClassify.HasData),
  234. // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
  235. // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
  236. // SysUserId: int(edbClassify.SysUserID),
  237. // SysUserRealName: edbClassify.SysUserRealName,
  238. // Level: int(edbClassify.Level),
  239. // UniqueCode: edbClassify.UniqueCode,
  240. // SortColumn: int(edbClassify.Sort),
  241. // }
  242. //
  243. // return
  244. //}
  245. // 数据信息
  246. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  247. // 计算指标不处理
  248. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
  249. return
  250. }
  251. // 预测指标不处理
  252. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
  253. return
  254. }
  255. var edbData *data_manage.EdbData
  256. err = json.Unmarshal([]byte(data), &edbData)
  257. if err != nil {
  258. return
  259. }
  260. source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
  261. if source <= 0 {
  262. // 没有找到来源,那就过滤
  263. return
  264. }
  265. // 数据信息
  266. pushIndexValue = &PushIndexValueItemReq{
  267. Id: getIndexDataId(source, subSource, edbData.EdbDataId),
  268. IndexCode: getIndexCode(source, edbData.EdbCode),
  269. Value: fmt.Sprint(edbData.Value),
  270. BusinessDate: edbData.DataTime,
  271. CreateTime: edbData.CreateTime,
  272. UpdateTime: edbData.ModifyTime,
  273. Status: "0",
  274. }
  275. return
  276. }
  277. return
  278. }
  279. // handleUpdate
  280. // @Description: 更新数据处理
  281. // @author: Roc
  282. // @datetime 2024-03-11 14:53:35
  283. // @param edbUpdateLog *data_manage.EdbUpdateLog
  284. // @return pushIndexData *PushIndexParamDataReq
  285. // @return pushEdbClassify *PushEdbClassifyItemReq
  286. // @return pushIndexValue *PushIndexValueItemReq
  287. // @return err error
  288. func handleUpdate(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  289. oldData := edbUpdateLog.OldData
  290. newData := edbUpdateLog.NewData
  291. //指标信息
  292. if edbUpdateLog.OpTableName == "edb_info" {
  293. var oldEdbInfo *data_manage.EdbInfoItem
  294. err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
  295. if err != nil {
  296. return
  297. }
  298. // 预测指标不处理
  299. if oldEdbInfo.EdbInfoType == 1 {
  300. return
  301. }
  302. // 计算指标不处理
  303. if oldEdbInfo.EdbType == 2 {
  304. return
  305. }
  306. // 自有数据不处理
  307. if oldEdbInfo.Source == utils.DATA_SOURCE_BUSINESS {
  308. return
  309. }
  310. var newEdbInfo *data_manage.EdbInfoItem
  311. err = json.Unmarshal([]byte(newData), &newEdbInfo)
  312. if err != nil {
  313. return
  314. }
  315. isUpdateEdbInfo := checkUpdateType(oldEdbInfo, newEdbInfo)
  316. // 指标信息
  317. if isUpdateEdbInfo {
  318. // 获取数据源中指标的基础信息
  319. origInfo := getOrigInfo(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode, newEdbInfo.EdbName)
  320. pushIndexData = &PushIndexParamDataReq{
  321. SourceIndexCode: newEdbInfo.EdbCode,
  322. IndexCode: getIndexCode(newEdbInfo.Source, newEdbInfo.EdbCode),
  323. IndexName: origInfo.EdbName,
  324. IndexShortName: newEdbInfo.EdbName,
  325. FrequenceName: newEdbInfo.Frequency,
  326. UnitName: newEdbInfo.Unit,
  327. AssetBeginDate: newEdbInfo.StartDate,
  328. AssetEndDate: newEdbInfo.EndDate,
  329. CreateUser: newEdbInfo.SysUserRealName,
  330. IndexCreateTime: newEdbInfo.CreateTime,
  331. UpdateUser: newEdbInfo.SysUserRealName,
  332. DetailUpdateTime: getMaxModifyTime(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
  333. IndexUpdateTime: newEdbInfo.ModifyTime,
  334. OrginSource: newEdbInfo.SourceName,
  335. OrginSysSource: origInfo.SourceName,
  336. SysSource: "产研平台",
  337. SourceType: getSourceType(newEdbInfo.Source),
  338. Status: 1,
  339. }
  340. }
  341. // 指标与分类的关系信息
  342. if oldEdbInfo.ClassifyId != newEdbInfo.ClassifyId {
  343. pushEdbClassify = &PushEdbClassifyItemReq{
  344. Id: fmt.Sprint(newEdbInfo.EdbInfoId),
  345. ClassifyId: newEdbInfo.ClassifyId,
  346. IndexCode: getIndexCode(newEdbInfo.Source, newEdbInfo.EdbCode),
  347. CreateTime: newEdbInfo.CreateTime,
  348. CreateUser: newEdbInfo.SysUserRealName,
  349. UpdateTime: newEdbInfo.ModifyTime,
  350. UpdateUser: newEdbInfo.SysUserRealName,
  351. }
  352. }
  353. return
  354. }
  355. // 数据信息
  356. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  357. // 计算指标不处理
  358. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
  359. return
  360. }
  361. // 预测指标不处理
  362. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
  363. return
  364. }
  365. var edbData *data_manage.EdbData
  366. err = json.Unmarshal([]byte(newData), &edbData)
  367. if err != nil {
  368. return
  369. }
  370. source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
  371. if source <= 0 {
  372. // 没有找到来源,那就过滤
  373. return
  374. }
  375. // 数据信息
  376. pushIndexValue = &PushIndexValueItemReq{
  377. Id: getIndexDataId(source, subSource, edbData.EdbDataId),
  378. IndexCode: getIndexCode(source, edbData.EdbCode),
  379. Value: fmt.Sprint(edbData.Value),
  380. BusinessDate: edbData.DataTime,
  381. CreateTime: edbData.CreateTime,
  382. UpdateTime: edbData.ModifyTime,
  383. Status: "1",
  384. }
  385. return
  386. }
  387. // 上面都没有匹配到的话,那就是数据源的
  388. return handleUpdateDataSource(edbUpdateLog)
  389. }
  390. // handleUpdateDataSource
  391. // @Description: 更新数据处理(数据源的基础数据)
  392. // @author: Roc
  393. // @datetime 2024-03-11 14:53:35
  394. // @param edbUpdateLog *data_manage.EdbUpdateLog
  395. // @return pushIndexData *PushIndexParamDataReq
  396. // @return pushEdbClassify *PushEdbClassifyItemReq
  397. // @return pushIndexValue *PushIndexValueItemReq
  398. // @return err error
  399. func handleUpdateDataSource(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  400. oldData := edbUpdateLog.OldData
  401. newData := edbUpdateLog.NewData
  402. isUpdateIndexInfo := false
  403. indexName := ``
  404. indexSourceName := ``
  405. source := 0
  406. edbCode := ``
  407. // 钢联
  408. if edbUpdateLog.OpTableName == "base_from_mysteel_chemical_index" {
  409. var oldEdbInfo *data_manage.BaseFromMysteelChemicalIndexItem
  410. err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
  411. if err != nil {
  412. return
  413. }
  414. var newEdbInfo *data_manage.BaseFromMysteelChemicalIndexItem
  415. err = json.Unmarshal([]byte(newData), &newEdbInfo)
  416. if err != nil {
  417. return
  418. }
  419. if oldEdbInfo.IndexName != newEdbInfo.IndexName {
  420. isUpdateIndexInfo = true
  421. } else if oldEdbInfo.Source != newEdbInfo.Source {
  422. isUpdateIndexInfo = true
  423. }
  424. if isUpdateIndexInfo {
  425. indexName = newEdbInfo.IndexName
  426. indexSourceName = newEdbInfo.Source
  427. edbCode = newEdbInfo.IndexCode
  428. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  429. }
  430. } else if edbUpdateLog.OpTableName == "base_from_smm_index" {
  431. // 有色
  432. var oldEdbInfo *data_manage.BaseFromSmmIndexItem
  433. err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
  434. if err != nil {
  435. return
  436. }
  437. var newEdbInfo *data_manage.BaseFromSmmIndexItem
  438. err = json.Unmarshal([]byte(newData), &newEdbInfo)
  439. if err != nil {
  440. return
  441. }
  442. if oldEdbInfo.IndexName != newEdbInfo.IndexName {
  443. isUpdateIndexInfo = true
  444. } else if oldEdbInfo.Interface != newEdbInfo.Interface {
  445. isUpdateIndexInfo = true
  446. }
  447. if isUpdateIndexInfo {
  448. indexName = newEdbInfo.IndexName
  449. indexSourceName = newEdbInfo.Interface
  450. edbCode = newEdbInfo.IndexCode
  451. source = utils.DATA_SOURCE_YS
  452. }
  453. }
  454. // 数据源的指标信息变更了
  455. if isUpdateIndexInfo {
  456. newEdbInfo, tmpErr := data_manage.GetEdbInfoItemByCodeAndSource(source, edbCode)
  457. if tmpErr != nil {
  458. if tmpErr.Error() != utils.ErrNoRow() {
  459. err = tmpErr
  460. return
  461. }
  462. return
  463. }
  464. pushIndexData = &PushIndexParamDataReq{
  465. SourceIndexCode: newEdbInfo.EdbCode,
  466. IndexCode: getIndexCode(newEdbInfo.Source, newEdbInfo.EdbCode),
  467. IndexName: indexName,
  468. IndexShortName: newEdbInfo.EdbName,
  469. FrequenceName: newEdbInfo.Frequency,
  470. UnitName: newEdbInfo.Unit,
  471. AssetBeginDate: newEdbInfo.StartDate,
  472. AssetEndDate: newEdbInfo.EndDate,
  473. CreateUser: newEdbInfo.SysUserRealName,
  474. IndexCreateTime: newEdbInfo.CreateTime,
  475. UpdateUser: newEdbInfo.SysUserRealName,
  476. DetailUpdateTime: getMaxModifyTime(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
  477. IndexUpdateTime: newEdbInfo.ModifyTime,
  478. OrginSource: newEdbInfo.SourceName,
  479. OrginSysSource: indexSourceName,
  480. SysSource: "产研平台",
  481. SourceType: getSourceType(newEdbInfo.Source),
  482. Status: 1,
  483. }
  484. }
  485. return
  486. }
  487. // getSourceType
  488. // @Description: 获取指标来源类型
  489. // @author: Roc
  490. // @datetime 2024-03-01 13:40:03
  491. // @param source int
  492. // @return string
  493. func getSourceType(source int) string {
  494. switch source {
  495. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS, utils.DATA_SOURCE_BAIINFO, utils.DATA_SOURCE_SCI: //钢联,有色,百川盈孚,红桃3
  496. return "RPA"
  497. case utils.DATA_SOURCE_MANUAL:
  498. return "手工"
  499. default:
  500. return "接口"
  501. }
  502. }
  503. // checkUpdateType
  504. // @Description: 检查指标更新状态
  505. // @author: Roc
  506. // @datetime 2024-03-11 16:35:22
  507. // @param oldEdbInfo *data_manage.EdbInfoItem
  508. // @param newEdbInfo *data_manage.EdbInfoItem
  509. // @return isUpdateEdbInfo bool
  510. func checkUpdateType(oldEdbInfo, newEdbInfo *data_manage.EdbInfoItem) (isUpdateEdbInfo bool) {
  511. // eta内部名称
  512. if oldEdbInfo.EdbName != newEdbInfo.EdbName {
  513. isUpdateEdbInfo = true
  514. return
  515. }
  516. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  517. isUpdateEdbInfo = true
  518. return
  519. }
  520. if oldEdbInfo.Unit != newEdbInfo.Unit {
  521. isUpdateEdbInfo = true
  522. return
  523. }
  524. //if oldEdbInfo.StartDate != newEdbInfo.StartDate {
  525. // isUpdateEdbInfo = true
  526. // return
  527. //}
  528. //if oldEdbInfo.EndDate != newEdbInfo.EndDate {
  529. // isUpdateEdbInfo = true
  530. // return
  531. //}
  532. //if oldEdbInfo.SysUserId != newEdbInfo.SysUserId {
  533. // isUpdateEdbInfo = true
  534. // return
  535. //}
  536. //if oldEdbInfo.SysUserRealName != newEdbInfo.SysUserRealName {
  537. // isUpdateEdbInfo = true
  538. // return
  539. //}
  540. return
  541. }
  542. // OrigInfo
  543. // @Description: 数据源中的指标基础信息
  544. type OrigInfo struct {
  545. EdbName string
  546. SourceName string
  547. }
  548. // getOrigInfo
  549. // @Description: 获取数据源中的指标基础信息
  550. // @author: Roc
  551. // @datetime 2024-03-11 16:45:34
  552. // @param source int
  553. // @param subSource int
  554. // @param edbCode string
  555. // @param edbName string
  556. // @return origInfo OrigInfo
  557. func getOrigInfo(source, subSource int, edbCode, edbName string) (origInfo OrigInfo) {
  558. switch source {
  559. case utils.DATA_SOURCE_THS, utils.DATA_SOURCE_WIND: // 同花顺、wind
  560. origInfo.SourceName = "经济数据库"
  561. if subSource == utils.DATA_SUB_SOURCE_DATE {
  562. origInfo.SourceName = "日期序列"
  563. }
  564. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  565. edbInfo, err := data_manage.GetBaseFromMysteelChemicalIndexItemByCode(edbCode)
  566. if err != nil {
  567. return
  568. }
  569. origInfo.EdbName = edbInfo.IndexName
  570. origInfo.SourceName = edbInfo.Source
  571. // 钢联化工
  572. case utils.DATA_SOURCE_YS: // 有色
  573. edbInfo, err := data_manage.GetBaseFromSmmIndexItemItemByCode(edbCode)
  574. if err != nil {
  575. return
  576. }
  577. origInfo.EdbName = edbInfo.IndexName
  578. origInfo.SourceName = edbInfo.Interface
  579. }
  580. // 如果原始名称为空,则使用ETA指标库的名称作为原始名称
  581. if origInfo.EdbName == `` {
  582. origInfo.EdbName = edbName
  583. }
  584. return
  585. }
  586. // getMaxModifyTime
  587. // @Description: 获取eta指标明细中的指标最大修改时间
  588. // @author: Roc
  589. // @datetime 2024-03-11 17:10:28
  590. // @param source int
  591. // @param edbCode string
  592. // @param addUpdateTime string
  593. // @return modifyTime string
  594. func getMaxModifyTime(source, subSource int, edbCode, addUpdateTime string) (modifyTime string) {
  595. modifyTime, err := data_manage.GetEdbInfoMaxModifyTime(source, subSource, edbCode)
  596. if err != nil {
  597. modifyTime = addUpdateTime
  598. return
  599. }
  600. return
  601. }
  602. // getIndexCode
  603. // @Description: 指标编码生成
  604. // @author: Roc
  605. // @datetime 2024-03-20 17:29:27
  606. // @param source int
  607. // @param edbCode string
  608. // @return string
  609. func getIndexCode(source int, edbCode string) string {
  610. return fmt.Sprint(source, "_", edbCode)
  611. }
  612. // getIndexDataId
  613. // @Description: 获取数据id
  614. // @author: Roc
  615. // @datetime 2024-03-20 17:36:53
  616. // @param source int
  617. // @param subSource int
  618. // @param edbDataId int
  619. // @return string
  620. func getIndexDataId(source, subSource int, edbDataId int32) string {
  621. return utils.MD5(fmt.Sprint(source, "_", subSource, "_", edbDataId))
  622. }