xy.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. package eta_bridge
  2. import (
  3. "context"
  4. "encoding/json"
  5. "eta/eta_task/models/data_manage"
  6. "eta/eta_task/services/alarm_msg"
  7. "eta/eta_task/utils"
  8. "fmt"
  9. "strings"
  10. )
  11. // SyncUser
  12. // @Description: 定时同步ETA指标信息变更数据至第三方
  13. // @author: Roc
  14. // @datetime 2024-02-28 14:00:45
  15. // @param cont context.Context
  16. // @return err error
  17. func SyncUser(cont context.Context) (err error) {
  18. defer func() {
  19. if err != nil {
  20. tips := "SyncUser-定时将第三方的用户数据同步到ETA失败, ErrMsg:\n" + err.Error()
  21. utils.FileLog.Info(tips)
  22. go alarm_msg.SendAlarmMsg(tips, 3)
  23. }
  24. }()
  25. uri := "/xy/user/pull"
  26. _, err, _ = HttpEtaBridgeGet(uri)
  27. if err != nil {
  28. return
  29. }
  30. return
  31. }
  32. // PushBaseParamReq
  33. // @Description: 业务报文
  34. type PushBaseParamReq struct {
  35. SerialID string `json:"serialID" description:"流水号"`
  36. TableCode string `json:"tableCode" description:"数据表编码"`
  37. Total int `json:"total" description:"本次落表数据总数"`
  38. IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
  39. Data interface{} `json:"data" description:"报文体"`
  40. }
  41. // PushIndexParamDataReq
  42. // @Description: 指标数据结构
  43. type PushIndexParamDataReq struct {
  44. SourceIndexCode string `json:"source_index_code" description:"上游来源指标ID"`
  45. IndexCode string `json:"index_code" description:""`
  46. IndexName string `json:"index_name" description:""`
  47. IndexShortName string `json:"index_short_name" description:""`
  48. FrequenceName string `json:"frequence_name" description:""`
  49. UnitName string `json:"unit_name" description:""`
  50. //CountryName string `json:"country_name" description:""`
  51. //ProvinceName string `json:"province_name" description:""`
  52. //AreaName string `json:"area_name" description:""`
  53. //CityName string `json:"city_name" description:""`
  54. //CountyName string `json:"county_name" description:""`
  55. //RegionName string `json:"region_name" description:""`
  56. //CompanyName string `json:"company_name" description:""`
  57. //BreedName string `json:"breed_name" description:""`
  58. //MaterialName string `json:"material_name" description:""`
  59. //SpecName string `json:"spec_name" description:""`
  60. //MarketName string `json:"market_name" description:""`
  61. //DerivativeType string `json:"derivative_type" description:""`
  62. //ContractName string `json:"contract_name" description:""`
  63. //AuthKindName string `json:"auth_kind_name" description:""`
  64. //CustomSmallClassName string `json:"custom_small_class_name" description:""`
  65. AssetBeginDate string `json:"asset_begin_date" description:""`
  66. AssetEndDate string `json:"asset_end_date" description:""`
  67. CreateUser string `json:"create_user" description:""`
  68. IndexCreateTime string `json:"index_create_time" description:""`
  69. UpdateUser string `json:"update_user" description:""`
  70. DetailUpdateTime string `json:"detail_update_time" description:""`
  71. IndexUpdateTime string `json:"index_update_time" description:""`
  72. //DutyDept string `json:"duty_dept" description:""`
  73. //BusinessDept string `json:"business_dept" description:""`
  74. OrginSource string `json:"orgin_source" description:""`
  75. OrginSysSource string `json:"orgin_sys_source" description:""`
  76. SysSource string `json:"sys_source" description:""`
  77. SourceType string `json:"source_type" description:""`
  78. //EtlTime string `json:"etl_time" description:""`
  79. Status int `json:"status" description:""`
  80. }
  81. // SyncIndexList
  82. // @Description: 定时同步ETA指标信息变更数据至第三方
  83. // @author: Roc
  84. // @datetime 2024-02-28 14:00:45
  85. // @param cont context.Context
  86. // @return err error
  87. func SyncIndexList(cont context.Context) (err error) {
  88. defer func() {
  89. if err != nil {
  90. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  91. utils.FileLog.Info(tips)
  92. go alarm_msg.SendAlarmMsg(tips, 3)
  93. }
  94. }()
  95. var condition string
  96. var pars []interface{}
  97. condition += " AND update_type in (?,?) "
  98. pars = append(pars, 1, 2)
  99. list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
  100. if err != nil {
  101. fmt.Println(err)
  102. return
  103. }
  104. dataList := make([]PushIndexParamDataReq, 0)
  105. for _, v := range list {
  106. dataList = append(dataList, PushIndexParamDataReq{
  107. SourceIndexCode: v.EdbCode,
  108. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  109. IndexName: v.EdbName,
  110. IndexShortName: v.EdbName, //todo
  111. FrequenceName: v.Frequency,
  112. UnitName: v.Unit,
  113. AssetBeginDate: v.StartDate,
  114. AssetEndDate: v.EndDate,
  115. CreateUser: v.SysUserRealName,
  116. IndexCreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  117. UpdateUser: v.UpdateSysUserRealName,
  118. DetailUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  119. IndexUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  120. OrginSource: v.SourceName, // todo
  121. OrginSysSource: v.SourceName,
  122. SysSource: "产研平台", //todo
  123. SourceType: "RPA", //TODO
  124. Status: 1,
  125. })
  126. }
  127. lenData := len(dataList)
  128. if lenData <= 0 {
  129. return
  130. }
  131. req := PushBaseParamReq{
  132. SerialID: utils.GetRandString(32), //todo
  133. TableCode: "",
  134. Total: lenData,
  135. IsEmailWarn: 0,
  136. Data: dataList,
  137. }
  138. uri := "/xy/index/pushIndexData"
  139. _, e, errMsg := HttpEtaBridgePost(uri, req)
  140. if e != nil {
  141. err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
  142. fmt.Println(err)
  143. return
  144. }
  145. fmt.Println(errMsg)
  146. //if res != nil && res.Ret != 200 {
  147. // err = fmt.Errorf("postRefreshEdbData fail")
  148. // return
  149. //}
  150. return
  151. }
  152. // PushIndexValueItemReq
  153. // @Description: 指标日期值数据结构
  154. type PushIndexValueItemReq struct {
  155. Id string `json:"id"`
  156. IndexCode string `json:"index_code" description:"指标代码"`
  157. Value string `json:"value" description:"数值"`
  158. BusinessDate string `json:"business_date" description:"业务日期(数据日期)"`
  159. CreateTime string `json:"create_time" description:"数据进入ETA的时间"`
  160. UpdateTime string `json:"update_time" description:"eta库中修改数据的时间"`
  161. Status string `json:"status" description:"逻辑删除使用,0-禁用,1-启用"`
  162. }
  163. // SyncIndexValueList
  164. // @Description: 定时同步ETA指标日期值的变更数据至第三方
  165. // @author: Roc
  166. // @datetime 2024-02-28 14:00:45
  167. // @param cont context.Context
  168. // @return err error
  169. func SyncIndexValueList(cont context.Context) (err error) {
  170. defer func() {
  171. if err != nil {
  172. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  173. utils.FileLog.Info(tips)
  174. go alarm_msg.SendAlarmMsg(tips, 3)
  175. }
  176. }()
  177. var condition string
  178. var pars []interface{}
  179. condition += " AND update_type = ? "
  180. pars = append(pars, 0)
  181. list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
  182. if err != nil {
  183. fmt.Println(err)
  184. return
  185. }
  186. dataList := make([]PushIndexValueItemReq, 0)
  187. for _, v := range list {
  188. dataList = append(dataList, PushIndexValueItemReq{
  189. Id: utils.MD5(fmt.Sprint(v.Source, "_", v.SourceName, "_", v.Id)),
  190. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  191. Value: fmt.Sprint(v.LatestValue),
  192. BusinessDate: v.LatestDate,
  193. CreateTime: v.EdbModifyTime,
  194. UpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo,
  195. Status: "1",
  196. })
  197. }
  198. lenData := len(dataList)
  199. if lenData <= 0 {
  200. return
  201. }
  202. req := PushBaseParamReq{
  203. SerialID: utils.GetRandString(32), //todo
  204. TableCode: "",
  205. Total: lenData,
  206. IsEmailWarn: 0,
  207. Data: dataList,
  208. }
  209. uri := "/xy/index/pushIndexValue"
  210. _, e, errMsg := HttpEtaBridgePost(uri, req)
  211. if e != nil {
  212. err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
  213. fmt.Println(err)
  214. return
  215. }
  216. fmt.Println(errMsg)
  217. //if res != nil && res.Ret != 200 {
  218. // err = fmt.Errorf("postRefreshEdbData fail")
  219. // return
  220. //}
  221. return
  222. }
  223. // PushClassifyItemReq
  224. // @Description: 指标分类数据结构
  225. type PushClassifyItemReq struct {
  226. ClassifyId int `json:"classify_id" description:"自增id"`
  227. ClassifyType int `json:"classify_type" description:"分类类型,0:普通指标分类,1:预测指标分类"`
  228. ClassifyName string `json:"classify_name" description:"分类名称"`
  229. ParentId int `json:"parent_id" description:"父级id"`
  230. HasData int `json:"has_data" description:"是否存在指标数据,1:有,2:无"`
  231. CreateTime string `json:"create_time" description:"创建时间"`
  232. UpdateTime string `json:"update_time" description:"修改时间"`
  233. SysUserId int `json:"sys_user_id" description:"创建人id"`
  234. SysUserRealName string `json:"sys_user_real_name" description:"创建人姓名"`
  235. Level int `json:"level" description:"层级"`
  236. UniqueCode string `json:"unique_code" description:"唯一编码"`
  237. SortColumn int `json:"sort_column" description:"排序字段,越小越靠前,默认值:10"`
  238. }
  239. // SyncClassifyList
  240. // @Description: 定时同步ETA分类数据至第三方
  241. // @author: Roc
  242. // @datetime 2024-02-28 14:00:45
  243. // @param cont context.Context
  244. // @return err error
  245. func SyncClassifyList(cont context.Context) (err error) {
  246. defer func() {
  247. if err != nil {
  248. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  249. utils.FileLog.Info(tips)
  250. go alarm_msg.SendAlarmMsg(tips, 3)
  251. }
  252. }()
  253. var condition string
  254. var pars []interface{}
  255. list, err := data_manage.GetAllEdbClassifyListByCondition(condition, pars)
  256. if err != nil {
  257. fmt.Println(err)
  258. return
  259. }
  260. dataLimitList := make([][]PushClassifyItemReq, 0)
  261. dataList := make([]PushClassifyItemReq, 0)
  262. for _, v := range list {
  263. dataList = append(dataList, PushClassifyItemReq{
  264. ClassifyId: int(v.ClassifyID),
  265. ClassifyType: int(v.ClassifyType),
  266. ClassifyName: v.ClassifyName,
  267. ParentId: int(v.ParentID),
  268. HasData: int(v.HasData),
  269. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  270. UpdateTime: v.ModifyTime.Format(utils.FormatDateTime),
  271. SysUserId: int(v.SysUserID),
  272. SysUserRealName: v.SysUserRealName,
  273. Level: int(v.Level),
  274. UniqueCode: v.UniqueCode,
  275. SortColumn: int(v.Sort),
  276. })
  277. if len(dataList) >= 100 {
  278. dataLimitList = append(dataLimitList, dataList)
  279. dataList = make([]PushClassifyItemReq, 0)
  280. }
  281. }
  282. lenData := len(dataList)
  283. if lenData > 0 {
  284. dataLimitList = append(dataLimitList, dataList)
  285. }
  286. if len(dataLimitList) < 0 {
  287. fmt.Println("无分类数据推送")
  288. return
  289. }
  290. for k, tmpDataList := range dataLimitList {
  291. req := PushBaseParamReq{
  292. SerialID: utils.GetRandString(32), //todo
  293. TableCode: "",
  294. Total: len(tmpDataList),
  295. IsEmailWarn: 0,
  296. Data: tmpDataList,
  297. }
  298. uri := "/xy/index/pushClassify"
  299. _, e, _ := HttpEtaBridgePost(uri, req)
  300. if e != nil {
  301. err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
  302. fmt.Println(err)
  303. continue
  304. }
  305. }
  306. return
  307. }
  308. // PushEdbClassifyItemReq
  309. // @Description: 指标与目录的关系请求结构
  310. type PushEdbClassifyItemReq struct {
  311. Id string `json:"id" description:"唯一主键"`
  312. ClassifyId int `json:"classify_id" description:"目录分类ID"`
  313. IndexCode string `json:"index_code" description:"指标ID"`
  314. CreateTime string `json:"create_time" description:"创建时间"`
  315. CreateUser string `json:"create_user" description:"创建人"`
  316. UpdateTime string `json:"update_time" description:"修改时间"`
  317. UpdateUser string `json:"update_user" description:"修改人"`
  318. }
  319. // SyncEdbClassifyList
  320. // @Description: 定时同步ETA指标与分类的关系至第三方
  321. // @author: Roc
  322. // @datetime 2024-02-28 14:00:45
  323. // @param cont context.Context
  324. // @return err error
  325. func SyncEdbClassifyList(cont context.Context) (err error) {
  326. defer func() {
  327. if err != nil {
  328. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  329. utils.FileLog.Info(tips)
  330. go alarm_msg.SendAlarmMsg(tips, 3)
  331. }
  332. }()
  333. var condition string
  334. var pars []interface{}
  335. list, err := data_manage.GetAllEdbInfoClassifyListByCondition(condition, pars)
  336. if err != nil {
  337. fmt.Println(err)
  338. return
  339. }
  340. dataLimitList := make([][]PushEdbClassifyItemReq, 0)
  341. dataList := make([]PushEdbClassifyItemReq, 0)
  342. for _, v := range list {
  343. dataList = append(dataList, PushEdbClassifyItemReq{
  344. Id: fmt.Sprint(v.EdbInfoId),
  345. ClassifyId: v.ClassifyId,
  346. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  347. CreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  348. CreateUser: v.SysUserRealName,
  349. UpdateTime: v.ModifyTime.Format(utils.FormatDateTime), //todo
  350. UpdateUser: v.SysUserRealName,
  351. })
  352. if len(dataList) >= 100 {
  353. dataLimitList = append(dataLimitList, dataList)
  354. dataList = make([]PushEdbClassifyItemReq, 0)
  355. }
  356. }
  357. lenData := len(dataList)
  358. if lenData > 0 {
  359. dataLimitList = append(dataLimitList, dataList)
  360. }
  361. if len(dataLimitList) < 0 {
  362. fmt.Println("无分类数据推送")
  363. return
  364. }
  365. for k, tmpDataList := range dataLimitList {
  366. req := PushBaseParamReq{
  367. SerialID: utils.GetRandString(32), //todo
  368. TableCode: "",
  369. Total: len(tmpDataList),
  370. IsEmailWarn: 0,
  371. Data: tmpDataList,
  372. }
  373. uri := "/xy/index/pushEdbClassify"
  374. _, e, _ := HttpEtaBridgePost(uri, req)
  375. if e != nil {
  376. err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
  377. fmt.Println(err)
  378. continue
  379. }
  380. }
  381. return
  382. }
  383. func SyncIndex(cont context.Context) (err error) {
  384. defer func() {
  385. if err != nil {
  386. tips := "SyncIndex-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  387. utils.FileLog.Info(tips)
  388. go alarm_msg.SendAlarmMsg(tips, 3)
  389. }
  390. }()
  391. var condition string
  392. var pars []interface{}
  393. //condition += " AND update_type in (?,?) "
  394. //pars = append(pars, 1, 2)
  395. condition += " AND id > ?"
  396. pars = append(pars, 50)
  397. list, err := data_manage.GetEdbUpdateLogByCondition(condition, pars)
  398. if err != nil {
  399. fmt.Println(err)
  400. return
  401. }
  402. //pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq
  403. pushIndexList := make([]*PushIndexParamDataReq, 0)
  404. pushEdbClassifyList := make([]*PushEdbClassifyItemReq, 0)
  405. pushIndexValueList := make([]*PushIndexValueItemReq, 0)
  406. for _, v := range list {
  407. pushIndexData, pushEdbClassify, pushIndexValue, err := handleData(v)
  408. if err != nil {
  409. continue
  410. }
  411. if pushIndexData != nil {
  412. pushIndexList = append(pushIndexList, pushIndexData)
  413. }
  414. if pushEdbClassify != nil {
  415. pushEdbClassifyList = append(pushEdbClassifyList, pushEdbClassify)
  416. }
  417. if pushIndexValue != nil {
  418. pushIndexValueList = append(pushIndexValueList, pushIndexValue)
  419. }
  420. }
  421. return
  422. }
  423. func handleData(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  424. switch edbUpdateLog.OpType {
  425. case "insert":
  426. return handleInsert(edbUpdateLog)
  427. case "update":
  428. return handleUpdate(edbUpdateLog)
  429. case "delete":
  430. return handleDelete(edbUpdateLog)
  431. }
  432. return
  433. }
  434. func handleInsert(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  435. data := edbUpdateLog.NewData
  436. //指标信息
  437. if edbUpdateLog.OpTableName == "edb_info" {
  438. var edbInfo *data_manage.EdbInfo
  439. err = json.Unmarshal([]byte(data), &edbInfo)
  440. if err != nil {
  441. return
  442. }
  443. // 指标信息
  444. pushIndexData = &PushIndexParamDataReq{
  445. SourceIndexCode: edbInfo.EdbCode,
  446. IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
  447. IndexName: edbInfo.EdbName,
  448. IndexShortName: edbInfo.EdbName, //todo
  449. FrequenceName: edbInfo.Frequency,
  450. UnitName: edbInfo.Unit,
  451. AssetBeginDate: edbInfo.StartDate,
  452. AssetEndDate: edbInfo.EndDate,
  453. CreateUser: edbInfo.SysUserRealName,
  454. IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
  455. UpdateUser: edbInfo.SysUserRealName, // todo
  456. DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
  457. IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
  458. OrginSource: edbInfo.SourceName, // todo
  459. OrginSysSource: edbInfo.SourceName,
  460. SysSource: "产研平台",
  461. SourceType: getSourceType(edbInfo.Source),
  462. Status: 1,
  463. }
  464. // 指标与分类的关系信息
  465. pushEdbClassify = &PushEdbClassifyItemReq{
  466. Id: fmt.Sprint(edbInfo.EdbInfoId),
  467. ClassifyId: edbInfo.ClassifyId,
  468. IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
  469. CreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
  470. CreateUser: edbInfo.SysUserRealName,
  471. UpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime),
  472. UpdateUser: edbInfo.SysUserRealName,
  473. }
  474. return
  475. }
  476. // 分类信息
  477. //if edbUpdateLog.OpTableName == "edb_classify" {
  478. // var edbClassify *data_manage.EdbClassify
  479. // err = json.Unmarshal([]byte(data), &edbClassify)
  480. // if err != nil {
  481. // return
  482. // }
  483. //
  484. // // 指标信息
  485. // pushClassify = PushClassifyItemReq{
  486. // ClassifyId: int(edbClassify.ClassifyID),
  487. // ClassifyType: int(edbClassify.ClassifyType),
  488. // ClassifyName: edbClassify.ClassifyName,
  489. // ParentId: int(edbClassify.ParentID),
  490. // HasData: int(edbClassify.HasData),
  491. // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
  492. // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
  493. // SysUserId: int(edbClassify.SysUserID),
  494. // SysUserRealName: edbClassify.SysUserRealName,
  495. // Level: int(edbClassify.Level),
  496. // UniqueCode: edbClassify.UniqueCode,
  497. // SortColumn: int(edbClassify.Sort),
  498. // }
  499. //
  500. // return
  501. //}
  502. // 数据信息
  503. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  504. var edbData *data_manage.EdbData
  505. err = json.Unmarshal([]byte(data), &edbData)
  506. if err != nil {
  507. return
  508. }
  509. edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
  510. if !ok {
  511. // 没有找到来源,那就过滤
  512. return
  513. }
  514. // 数据信息
  515. pushIndexValue = &PushIndexValueItemReq{
  516. Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
  517. IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
  518. Value: fmt.Sprint(edbData.Value),
  519. BusinessDate: edbData.DataTime.Format(utils.FormatDate),
  520. CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
  521. UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
  522. Status: "1",
  523. }
  524. return
  525. }
  526. return
  527. }
  528. func handleDelete(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  529. data := edbUpdateLog.OldData
  530. //指标信息
  531. if edbUpdateLog.OpTableName == "edb_info" {
  532. var edbInfo *data_manage.EdbInfo
  533. err = json.Unmarshal([]byte(data), &edbInfo)
  534. if err != nil {
  535. return
  536. }
  537. // 指标信息
  538. pushIndexData = &PushIndexParamDataReq{
  539. SourceIndexCode: edbInfo.EdbCode,
  540. IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
  541. IndexName: edbInfo.EdbName,
  542. IndexShortName: edbInfo.EdbName, //todo
  543. FrequenceName: edbInfo.Frequency,
  544. UnitName: edbInfo.Unit,
  545. AssetBeginDate: edbInfo.StartDate,
  546. AssetEndDate: edbInfo.EndDate,
  547. CreateUser: edbInfo.SysUserRealName,
  548. IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
  549. UpdateUser: edbInfo.SysUserRealName, // todo
  550. DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
  551. IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
  552. OrginSource: edbInfo.SourceName, // todo
  553. OrginSysSource: edbInfo.SourceName,
  554. SysSource: "产研平台",
  555. SourceType: getSourceType(edbInfo.Source),
  556. Status: 0,
  557. }
  558. // 指标与分类的关系信息
  559. pushEdbClassify = &PushEdbClassifyItemReq{
  560. Id: fmt.Sprint(edbInfo.EdbInfoId),
  561. ClassifyId: edbInfo.ClassifyId,
  562. IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
  563. CreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
  564. CreateUser: edbInfo.SysUserRealName,
  565. UpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime),
  566. UpdateUser: edbInfo.SysUserRealName,
  567. }
  568. return
  569. }
  570. // 分类信息
  571. //if edbUpdateLog.OpTableName == "edb_classify" {
  572. // var edbClassify *data_manage.EdbClassify
  573. // err = json.Unmarshal([]byte(data), &edbClassify)
  574. // if err != nil {
  575. // return
  576. // }
  577. //
  578. // // 指标信息
  579. // pushClassify = PushClassifyItemReq{
  580. // ClassifyId: int(edbClassify.ClassifyID),
  581. // ClassifyType: int(edbClassify.ClassifyType),
  582. // ClassifyName: edbClassify.ClassifyName,
  583. // ParentId: int(edbClassify.ParentID),
  584. // HasData: int(edbClassify.HasData),
  585. // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
  586. // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
  587. // SysUserId: int(edbClassify.SysUserID),
  588. // SysUserRealName: edbClassify.SysUserRealName,
  589. // Level: int(edbClassify.Level),
  590. // UniqueCode: edbClassify.UniqueCode,
  591. // SortColumn: int(edbClassify.Sort),
  592. // }
  593. //
  594. // return
  595. //}
  596. // 数据信息
  597. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  598. var edbData *data_manage.EdbData
  599. err = json.Unmarshal([]byte(data), &edbData)
  600. if err != nil {
  601. return
  602. }
  603. edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
  604. if !ok {
  605. // 没有找到来源,那就过滤
  606. return
  607. }
  608. // 数据信息
  609. pushIndexValue = &PushIndexValueItemReq{
  610. Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
  611. IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
  612. Value: fmt.Sprint(edbData.Value),
  613. BusinessDate: edbData.DataTime.Format(utils.FormatDate),
  614. CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
  615. UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
  616. Status: "0",
  617. }
  618. return
  619. }
  620. return
  621. }
  622. func handleUpdate(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
  623. oldData := edbUpdateLog.OldData
  624. newData := edbUpdateLog.NewData
  625. //指标信息
  626. if edbUpdateLog.OpTableName == "edb_info" {
  627. var oldEdbInfo *data_manage.EdbInfo
  628. err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
  629. if err != nil {
  630. return
  631. }
  632. var newEdbInfo *data_manage.EdbInfo
  633. err = json.Unmarshal([]byte(newData), &newEdbInfo)
  634. if err != nil {
  635. return
  636. }
  637. isUpdateEdbInfo := checkUpdateType(oldEdbInfo, newEdbInfo)
  638. // 指标信息
  639. if isUpdateEdbInfo {
  640. pushIndexData = &PushIndexParamDataReq{
  641. SourceIndexCode: newEdbInfo.EdbCode,
  642. IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
  643. IndexName: newEdbInfo.EdbName,
  644. IndexShortName: newEdbInfo.EdbName, //todo
  645. FrequenceName: newEdbInfo.Frequency,
  646. UnitName: newEdbInfo.Unit,
  647. AssetBeginDate: newEdbInfo.StartDate,
  648. AssetEndDate: newEdbInfo.EndDate,
  649. CreateUser: newEdbInfo.SysUserRealName,
  650. IndexCreateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime),
  651. UpdateUser: newEdbInfo.SysUserRealName, // todo
  652. DetailUpdateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime), //todo
  653. IndexUpdateTime: newEdbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
  654. OrginSource: newEdbInfo.SourceName, // todo
  655. OrginSysSource: newEdbInfo.SourceName,
  656. SysSource: "产研平台",
  657. SourceType: getSourceType(newEdbInfo.Source),
  658. Status: 1,
  659. }
  660. }
  661. // 指标与分类的关系信息
  662. if oldEdbInfo.ClassifyId != newEdbInfo.ClassifyId {
  663. pushEdbClassify = &PushEdbClassifyItemReq{
  664. Id: fmt.Sprint(newEdbInfo.EdbInfoId),
  665. ClassifyId: newEdbInfo.ClassifyId,
  666. IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
  667. CreateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime),
  668. CreateUser: newEdbInfo.SysUserRealName,
  669. UpdateTime: newEdbInfo.ModifyTime.Format(utils.FormatDateTime),
  670. UpdateUser: newEdbInfo.SysUserRealName,
  671. }
  672. }
  673. return
  674. }
  675. // 分类信息
  676. //if edbUpdateLog.OpTableName == "edb_classify" {
  677. // var edbClassify *data_manage.EdbClassify
  678. // err = json.Unmarshal([]byte(newData), &edbClassify)
  679. // if err != nil {
  680. // return
  681. // }
  682. //
  683. // // 指标信息
  684. // pushClassify = PushClassifyItemReq{
  685. // ClassifyId: int(edbClassify.ClassifyID),
  686. // ClassifyType: int(edbClassify.ClassifyType),
  687. // ClassifyName: edbClassify.ClassifyName,
  688. // ParentId: int(edbClassify.ParentID),
  689. // HasData: int(edbClassify.HasData),
  690. // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
  691. // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
  692. // SysUserId: int(edbClassify.SysUserID),
  693. // SysUserRealName: edbClassify.SysUserRealName,
  694. // Level: int(edbClassify.Level),
  695. // UniqueCode: edbClassify.UniqueCode,
  696. // SortColumn: int(edbClassify.Sort),
  697. // }
  698. //
  699. // return
  700. //}
  701. // 数据信息
  702. if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
  703. var edbData *data_manage.EdbData
  704. err = json.Unmarshal([]byte(newData), &edbData)
  705. if err != nil {
  706. return
  707. }
  708. edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
  709. if !ok {
  710. // 没有找到来源,那就过滤
  711. return
  712. }
  713. // 数据信息
  714. pushIndexValue = &PushIndexValueItemReq{
  715. Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
  716. IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
  717. Value: fmt.Sprint(edbData.Value),
  718. BusinessDate: edbData.DataTime.Format(utils.FormatDate),
  719. CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
  720. UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
  721. Status: "1",
  722. }
  723. return
  724. }
  725. return
  726. }
  727. //PushIndexParamDataReq{
  728. //SourceIndexCode: edbInfo.EdbCode,
  729. //IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
  730. //IndexName: edbInfo.EdbName,
  731. //IndexShortName: edbInfo.EdbName, //todo
  732. //FrequenceName: edbInfo.Frequency,
  733. //UnitName: edbInfo.Unit,
  734. //AssetBeginDate: edbInfo.StartDate,
  735. //AssetEndDate: edbInfo.EndDate,
  736. //CreateUser: edbInfo.SysUserRealName,
  737. //IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
  738. //UpdateUser: edbInfo.SysUserRealName, // todo
  739. //DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
  740. //IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
  741. //OrginSource: edbInfo.SourceName, // todo
  742. //OrginSysSource: edbInfo.SourceName,
  743. //SysSource: "产研平台",
  744. //SourceType: getSourceType(edbInfo.Source),
  745. //Status: 1,
  746. //}
  747. // getSourceType
  748. // @Description: 获取指标来源类型
  749. // @author: Roc
  750. // @datetime 2024-03-01 13:40:03
  751. // @param source int
  752. // @return string
  753. func getSourceType(source int) string {
  754. switch source {
  755. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS, utils.DATA_SOURCE_BAIINFO, utils.DATA_SOURCE_SCI: //钢联,有色,百川盈孚,红桃3
  756. return "RPA"
  757. case utils.DATA_SOURCE_MANUAL:
  758. return "手工"
  759. default:
  760. return "接口"
  761. }
  762. }
  763. func checkUpdateType(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (isUpdateEdbInfo bool) {
  764. //todo 外部来源名称需要处理;更新人姓名,指标更新时间
  765. // eta内部名称
  766. if oldEdbInfo.EdbName != newEdbInfo.EdbName {
  767. isUpdateEdbInfo = true
  768. return
  769. }
  770. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  771. isUpdateEdbInfo = true
  772. return
  773. }
  774. if oldEdbInfo.Unit != newEdbInfo.Unit {
  775. isUpdateEdbInfo = true
  776. return
  777. }
  778. if oldEdbInfo.StartDate != newEdbInfo.StartDate {
  779. isUpdateEdbInfo = true
  780. return
  781. }
  782. if oldEdbInfo.EndDate != newEdbInfo.EndDate {
  783. isUpdateEdbInfo = true
  784. return
  785. }
  786. if oldEdbInfo.SysUserId != newEdbInfo.SysUserId {
  787. isUpdateEdbInfo = true
  788. return
  789. }
  790. if oldEdbInfo.SysUserRealName != newEdbInfo.SysUserRealName {
  791. isUpdateEdbInfo = true
  792. return
  793. }
  794. return
  795. }
  796. //func pushIndex(pushIndexList []*PushIndexParamDataReq) {
  797. // if len(pushIndexList) <= 0 {
  798. // return
  799. // }
  800. //
  801. // uri := "/xy/index/pushIndexData"
  802. // req := PushBaseParamReq{
  803. // SerialID: utils.GetRandString(32), //todo
  804. // TableCode: "",
  805. // Total: lenData,
  806. // IsEmailWarn: 0,
  807. // Data: dataList,
  808. // }
  809. //
  810. // var pushIndexList []*PushIndexParamDataReq
  811. // dataLimitList := make([][]PushBaseParamReq, 0)
  812. //
  813. // _, e, errMsg := HttpEtaBridgePost(uri, req)
  814. //}