demo.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package eta_bridge
  2. import (
  3. "context"
  4. "eta/eta_task/models/data_manage"
  5. "eta/eta_task/services/alarm_msg"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. )
  9. // SyncIndexList
  10. // @Description: 定时同步ETA指标信息变更数据至第三方
  11. // @author: Roc
  12. // @datetime 2024-02-28 14:00:45
  13. // @param cont context.Context
  14. // @return err error
  15. func SyncIndexList(cont context.Context) (err error) {
  16. defer func() {
  17. if err != nil {
  18. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  19. utils.FileLog.Info(tips)
  20. go alarm_msg.SendAlarmMsg(tips, 3)
  21. }
  22. }()
  23. var condition string
  24. var pars []interface{}
  25. condition += " AND update_type in (?,?) "
  26. pars = append(pars, 1, 2)
  27. list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
  28. if err != nil {
  29. fmt.Println(err)
  30. return
  31. }
  32. dataList := make([]PushIndexParamDataReq, 0)
  33. for _, v := range list {
  34. dataList = append(dataList, PushIndexParamDataReq{
  35. SourceIndexCode: v.EdbCode,
  36. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  37. IndexName: v.EdbName, //todo
  38. IndexShortName: v.EdbName,
  39. FrequenceName: v.Frequency,
  40. UnitName: v.Unit,
  41. AssetBeginDate: v.StartDate,
  42. AssetEndDate: v.EndDate,
  43. CreateUser: v.SysUserRealName,
  44. IndexCreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  45. UpdateUser: v.UpdateSysUserRealName,
  46. DetailUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  47. IndexUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  48. OrginSource: v.SourceName,
  49. OrginSysSource: v.SourceName, // todo
  50. SysSource: "产研平台", //todo
  51. SourceType: "RPA", //TODO
  52. Status: 1,
  53. })
  54. }
  55. lenData := len(dataList)
  56. if lenData <= 0 {
  57. return
  58. }
  59. req := PushBaseParamReq{
  60. SerialID: utils.GetRandString(32), //todo
  61. TableCode: "",
  62. Total: lenData,
  63. IsEmailWarn: 0,
  64. Data: dataList,
  65. }
  66. uri := "/xy/index/pushIndexData"
  67. _, e, errMsg := HttpEtaBridgePost(uri, req)
  68. if e != nil {
  69. err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
  70. fmt.Println(err)
  71. return
  72. }
  73. fmt.Println(errMsg)
  74. //if res != nil && res.Ret != 200 {
  75. // err = fmt.Errorf("postRefreshEdbData fail")
  76. // return
  77. //}
  78. return
  79. }
  80. // SyncIndexValueList
  81. // @Description: 定时同步ETA指标日期值的变更数据至第三方
  82. // @author: Roc
  83. // @datetime 2024-02-28 14:00:45
  84. // @param cont context.Context
  85. // @return err error
  86. func SyncIndexValueList(cont context.Context) (err error) {
  87. defer func() {
  88. if err != nil {
  89. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  90. utils.FileLog.Info(tips)
  91. go alarm_msg.SendAlarmMsg(tips, 3)
  92. }
  93. }()
  94. var condition string
  95. var pars []interface{}
  96. condition += " AND update_type = ? "
  97. pars = append(pars, 0)
  98. list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
  99. if err != nil {
  100. fmt.Println(err)
  101. return
  102. }
  103. dataList := make([]PushIndexValueItemReq, 0)
  104. for _, v := range list {
  105. dataList = append(dataList, PushIndexValueItemReq{
  106. Id: utils.MD5(fmt.Sprint(v.Source, "_", v.SourceName, "_", v.Id)),
  107. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  108. Value: fmt.Sprint(v.LatestValue),
  109. BusinessDate: v.LatestDate,
  110. CreateTime: v.EdbModifyTime,
  111. UpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo,
  112. Status: "1",
  113. })
  114. }
  115. lenData := len(dataList)
  116. if lenData <= 0 {
  117. return
  118. }
  119. req := PushBaseParamReq{
  120. SerialID: utils.GetRandString(32), //todo
  121. TableCode: "",
  122. Total: lenData,
  123. IsEmailWarn: 0,
  124. Data: dataList,
  125. }
  126. uri := "/xy/index/pushIndexValue"
  127. _, e, errMsg := HttpEtaBridgePost(uri, req)
  128. if e != nil {
  129. err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
  130. fmt.Println(err)
  131. return
  132. }
  133. fmt.Println(errMsg)
  134. //if res != nil && res.Ret != 200 {
  135. // err = fmt.Errorf("postRefreshEdbData fail")
  136. // return
  137. //}
  138. return
  139. }
  140. // SyncEdbClassifyList
  141. // @Description: 定时同步ETA指标与分类的关系至第三方
  142. // @author: Roc
  143. // @datetime 2024-02-28 14:00:45
  144. // @param cont context.Context
  145. // @return err error
  146. func SyncEdbClassifyList(cont context.Context) (err error) {
  147. defer func() {
  148. if err != nil {
  149. tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
  150. utils.FileLog.Info(tips)
  151. go alarm_msg.SendAlarmMsg(tips, 3)
  152. }
  153. }()
  154. var condition string
  155. var pars []interface{}
  156. list, err := data_manage.GetAllEdbInfoClassifyListByCondition(condition, pars)
  157. if err != nil {
  158. fmt.Println(err)
  159. return
  160. }
  161. dataLimitList := make([][]PushEdbClassifyItemReq, 0)
  162. dataList := make([]PushEdbClassifyItemReq, 0)
  163. for _, v := range list {
  164. dataList = append(dataList, PushEdbClassifyItemReq{
  165. Id: fmt.Sprint(v.EdbInfoId),
  166. ClassifyId: v.ClassifyId,
  167. IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
  168. CreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
  169. CreateUser: v.SysUserRealName,
  170. UpdateTime: v.ModifyTime.Format(utils.FormatDateTime), //todo
  171. UpdateUser: v.SysUserRealName,
  172. })
  173. if len(dataList) >= 100 {
  174. dataLimitList = append(dataLimitList, dataList)
  175. dataList = make([]PushEdbClassifyItemReq, 0)
  176. }
  177. }
  178. lenData := len(dataList)
  179. if lenData > 0 {
  180. dataLimitList = append(dataLimitList, dataList)
  181. }
  182. if len(dataLimitList) < 0 {
  183. fmt.Println("无分类数据推送")
  184. return
  185. }
  186. uri := utils.SyncIndexPath + "/pushEdbClassify"
  187. for k, tmpDataList := range dataLimitList {
  188. req := PushBaseParamReq{
  189. SerialID: utils.GetRandString(32), //todo
  190. TableCode: "",
  191. Total: len(tmpDataList),
  192. IsEmailWarn: 0,
  193. Data: tmpDataList,
  194. }
  195. _, e, _ := HttpEtaBridgePost(uri, req)
  196. if e != nil {
  197. err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
  198. fmt.Println(err)
  199. continue
  200. }
  201. }
  202. return
  203. }