123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package eta_bridge
- import (
- "context"
- "eta/eta_task/models/data_manage"
- "eta/eta_task/services/alarm_msg"
- "eta/eta_task/utils"
- "fmt"
- )
- // SyncIndexList
- // @Description: 定时同步ETA指标信息变更数据至第三方
- // @author: Roc
- // @datetime 2024-02-28 14:00:45
- // @param cont context.Context
- // @return err error
- func SyncIndexList(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- var condition string
- var pars []interface{}
- condition += " AND update_type in (?,?) "
- pars = append(pars, 1, 2)
- list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- dataList := make([]PushIndexParamDataReq, 0)
- for _, v := range list {
- dataList = append(dataList, PushIndexParamDataReq{
- SourceIndexCode: v.EdbCode,
- IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
- IndexName: v.EdbName, //todo
- IndexShortName: v.EdbName,
- FrequenceName: v.Frequency,
- UnitName: v.Unit,
- AssetBeginDate: v.StartDate,
- AssetEndDate: v.EndDate,
- CreateUser: v.SysUserRealName,
- IndexCreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
- UpdateUser: v.UpdateSysUserRealName,
- DetailUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
- IndexUpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
- OrginSource: v.SourceName,
- OrginSysSource: v.SourceName, // todo
- SysSource: "产研平台", //todo
- SourceType: "RPA", //TODO
- Status: 1,
- })
- }
- lenData := len(dataList)
- if lenData <= 0 {
- return
- }
- req := PushBaseParamReq{
- SerialID: utils.GetRandString(32), //todo
- TableCode: "",
- Total: lenData,
- IsEmailWarn: 0,
- Data: dataList,
- }
- uri := "/xy/index/pushIndexData"
- _, e, errMsg := HttpEtaBridgePost(uri, req)
- if e != nil {
- err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
- fmt.Println(err)
- return
- }
- fmt.Println(errMsg)
- //if res != nil && res.Ret != 200 {
- // err = fmt.Errorf("postRefreshEdbData fail")
- // return
- //}
- return
- }
- // SyncIndexValueList
- // @Description: 定时同步ETA指标日期值的变更数据至第三方
- // @author: Roc
- // @datetime 2024-02-28 14:00:45
- // @param cont context.Context
- // @return err error
- func SyncIndexValueList(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- var condition string
- var pars []interface{}
- condition += " AND update_type = ? "
- pars = append(pars, 0)
- list, err := data_manage.GetEdbInfoUpdateLogByCondition(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- dataList := make([]PushIndexValueItemReq, 0)
- for _, v := range list {
- dataList = append(dataList, PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(v.Source, "_", v.SourceName, "_", v.Id)),
- IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
- Value: fmt.Sprint(v.LatestValue),
- BusinessDate: v.LatestDate,
- CreateTime: v.EdbModifyTime,
- UpdateTime: v.CreateTime.Format(utils.FormatDateTime), //todo,
- Status: "1",
- })
- }
- lenData := len(dataList)
- if lenData <= 0 {
- return
- }
- req := PushBaseParamReq{
- SerialID: utils.GetRandString(32), //todo
- TableCode: "",
- Total: lenData,
- IsEmailWarn: 0,
- Data: dataList,
- }
- uri := "/xy/index/pushIndexValue"
- _, e, errMsg := HttpEtaBridgePost(uri, req)
- if e != nil {
- err = fmt.Errorf("postRefreshEdbData err: %s", e.Error())
- fmt.Println(err)
- return
- }
- fmt.Println(errMsg)
- //if res != nil && res.Ret != 200 {
- // err = fmt.Errorf("postRefreshEdbData fail")
- // return
- //}
- return
- }
- // SyncEdbClassifyList
- // @Description: 定时同步ETA指标与分类的关系至第三方
- // @author: Roc
- // @datetime 2024-02-28 14:00:45
- // @param cont context.Context
- // @return err error
- func SyncEdbClassifyList(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "SyncIndexList-定时同步ETA指标信息变更数据至第三方失败, ErrMsg:\n" + err.Error()
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- var condition string
- var pars []interface{}
- list, err := data_manage.GetAllEdbInfoClassifyListByCondition(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- dataLimitList := make([][]PushEdbClassifyItemReq, 0)
- dataList := make([]PushEdbClassifyItemReq, 0)
- for _, v := range list {
- dataList = append(dataList, PushEdbClassifyItemReq{
- Id: fmt.Sprint(v.EdbInfoId),
- ClassifyId: v.ClassifyId,
- IndexCode: fmt.Sprint(v.Source, "_", v.EdbCode),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime), //todo
- CreateUser: v.SysUserRealName,
- UpdateTime: v.ModifyTime.Format(utils.FormatDateTime), //todo
- UpdateUser: v.SysUserRealName,
- })
- if len(dataList) >= 100 {
- dataLimitList = append(dataLimitList, dataList)
- dataList = make([]PushEdbClassifyItemReq, 0)
- }
- }
- lenData := len(dataList)
- if lenData > 0 {
- dataLimitList = append(dataLimitList, dataList)
- }
- if len(dataLimitList) < 0 {
- fmt.Println("无分类数据推送")
- return
- }
- uri := utils.SyncIndexPath + "/pushEdbClassify"
- for k, tmpDataList := range dataLimitList {
- req := PushBaseParamReq{
- SerialID: utils.GetRandString(32), //todo
- TableCode: "",
- Total: len(tmpDataList),
- IsEmailWarn: 0,
- Data: tmpDataList,
- }
- _, e, _ := HttpEtaBridgePost(uri, req)
- if e != nil {
- err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
- fmt.Println(err)
- continue
- }
- }
- return
- }
|