123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- package eta_bridge
- import (
- "context"
- "encoding/json"
- "eta/eta_task/models/data_manage"
- "eta/eta_task/services/alarm_msg"
- "eta/eta_task/utils"
- "fmt"
- "strings"
- )
- // SyncUser
- // @Description: 定时同步ETA指标信息变更数据至第三方
- // @author: Roc
- // @datetime 2024-02-28 14:00:45
- // @param cont context.Context
- // @return err error
- func SyncUser(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "SyncUser-定时将第三方的用户数据同步到ETA失败, ErrMsg:\n" + err.Error()
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- uri := "/xy/user/pull"
- _, err, _ = HttpEtaBridgeGet(uri)
- if err != nil {
- return
- }
- return
- }
- // PushBaseParamReq
- // @Description: 业务报文
- type PushBaseParamReq struct {
- SerialID string `json:"serialID" description:"流水号"`
- TableCode string `json:"tableCode" description:"数据表编码"`
- Total int `json:"total" description:"本次落表数据总数"`
- IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
- Data interface{} `json:"data" description:"报文体"`
- }
- // PushIndexParamDataReq
- // @Description: 指标数据结构
- type PushIndexParamDataReq struct {
- SourceIndexCode string `json:"source_index_code" description:"上游来源指标ID"`
- IndexCode string `json:"index_code" description:""`
- IndexName string `json:"index_name" description:""`
- IndexShortName string `json:"index_short_name" description:""`
- FrequenceName string `json:"frequence_name" description:""`
- UnitName string `json:"unit_name" description:""`
- //CountryName string `json:"country_name" description:""`
- //ProvinceName string `json:"province_name" description:""`
- //AreaName string `json:"area_name" description:""`
- //CityName string `json:"city_name" description:""`
- //CountyName string `json:"county_name" description:""`
- //RegionName string `json:"region_name" description:""`
- //CompanyName string `json:"company_name" description:""`
- //BreedName string `json:"breed_name" description:""`
- //MaterialName string `json:"material_name" description:""`
- //SpecName string `json:"spec_name" description:""`
- //MarketName string `json:"market_name" description:""`
- //DerivativeType string `json:"derivative_type" description:""`
- //ContractName string `json:"contract_name" description:""`
- //AuthKindName string `json:"auth_kind_name" description:""`
- //CustomSmallClassName string `json:"custom_small_class_name" description:""`
- AssetBeginDate string `json:"asset_begin_date" description:""`
- AssetEndDate string `json:"asset_end_date" description:""`
- CreateUser string `json:"create_user" description:""`
- IndexCreateTime string `json:"index_create_time" description:""`
- UpdateUser string `json:"update_user" description:""`
- DetailUpdateTime string `json:"detail_update_time" description:""`
- IndexUpdateTime string `json:"index_update_time" description:""`
- //DutyDept string `json:"duty_dept" description:""`
- //BusinessDept string `json:"business_dept" description:""`
- OrginSource string `json:"orgin_source" description:""`
- OrginSysSource string `json:"orgin_sys_source" description:""`
- SysSource string `json:"sys_source" description:""`
- SourceType string `json:"source_type" description:""`
- //EtlTime string `json:"etl_time" description:""`
- Status int `json:"status" description:""`
- }
- // 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,
- IndexShortName: v.EdbName, //todo
- 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, // todo
- OrginSysSource: v.SourceName,
- 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
- }
- // PushIndexValueItemReq
- // @Description: 指标日期值数据结构
- type PushIndexValueItemReq struct {
- Id string `json:"id"`
- IndexCode string `json:"index_code" description:"指标代码"`
- Value string `json:"value" description:"数值"`
- BusinessDate string `json:"business_date" description:"业务日期(数据日期)"`
- CreateTime string `json:"create_time" description:"数据进入ETA的时间"`
- UpdateTime string `json:"update_time" description:"eta库中修改数据的时间"`
- Status string `json:"status" description:"逻辑删除使用,0-禁用,1-启用"`
- }
- // 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
- }
- // PushClassifyItemReq
- // @Description: 指标分类数据结构
- type PushClassifyItemReq struct {
- ClassifyId int `json:"classify_id" description:"自增id"`
- ClassifyType int `json:"classify_type" description:"分类类型,0:普通指标分类,1:预测指标分类"`
- ClassifyName string `json:"classify_name" description:"分类名称"`
- ParentId int `json:"parent_id" description:"父级id"`
- HasData int `json:"has_data" description:"是否存在指标数据,1:有,2:无"`
- CreateTime string `json:"create_time" description:"创建时间"`
- UpdateTime string `json:"update_time" description:"修改时间"`
- SysUserId int `json:"sys_user_id" description:"创建人id"`
- SysUserRealName string `json:"sys_user_real_name" description:"创建人姓名"`
- Level int `json:"level" description:"层级"`
- UniqueCode string `json:"unique_code" description:"唯一编码"`
- SortColumn int `json:"sort_column" description:"排序字段,越小越靠前,默认值:10"`
- }
- // SyncClassifyList
- // @Description: 定时同步ETA分类数据至第三方
- // @author: Roc
- // @datetime 2024-02-28 14:00:45
- // @param cont context.Context
- // @return err error
- func SyncClassifyList(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.GetAllEdbClassifyListByCondition(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- dataLimitList := make([][]PushClassifyItemReq, 0)
- dataList := make([]PushClassifyItemReq, 0)
- for _, v := range list {
- dataList = append(dataList, PushClassifyItemReq{
- ClassifyId: int(v.ClassifyID),
- ClassifyType: int(v.ClassifyType),
- ClassifyName: v.ClassifyName,
- ParentId: int(v.ParentID),
- HasData: int(v.HasData),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- UpdateTime: v.ModifyTime.Format(utils.FormatDateTime),
- SysUserId: int(v.SysUserID),
- SysUserRealName: v.SysUserRealName,
- Level: int(v.Level),
- UniqueCode: v.UniqueCode,
- SortColumn: int(v.Sort),
- })
- if len(dataList) >= 100 {
- dataLimitList = append(dataLimitList, dataList)
- dataList = make([]PushClassifyItemReq, 0)
- }
- }
- lenData := len(dataList)
- if lenData > 0 {
- dataLimitList = append(dataLimitList, dataList)
- }
- if len(dataLimitList) < 0 {
- fmt.Println("无分类数据推送")
- return
- }
- for k, tmpDataList := range dataLimitList {
- req := PushBaseParamReq{
- SerialID: utils.GetRandString(32), //todo
- TableCode: "",
- Total: len(tmpDataList),
- IsEmailWarn: 0,
- Data: tmpDataList,
- }
- uri := "/xy/index/pushClassify"
- _, e, _ := HttpEtaBridgePost(uri, req)
- if e != nil {
- err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
- fmt.Println(err)
- continue
- }
- }
- return
- }
- // PushEdbClassifyItemReq
- // @Description: 指标与目录的关系请求结构
- type PushEdbClassifyItemReq struct {
- Id string `json:"id" description:"唯一主键"`
- ClassifyId int `json:"classify_id" description:"目录分类ID"`
- IndexCode string `json:"index_code" description:"指标ID"`
- CreateTime string `json:"create_time" description:"创建时间"`
- CreateUser string `json:"create_user" description:"创建人"`
- UpdateTime string `json:"update_time" description:"修改时间"`
- UpdateUser string `json:"update_user" description:"修改人"`
- }
- // 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
- }
- for k, tmpDataList := range dataLimitList {
- req := PushBaseParamReq{
- SerialID: utils.GetRandString(32), //todo
- TableCode: "",
- Total: len(tmpDataList),
- IsEmailWarn: 0,
- Data: tmpDataList,
- }
- uri := "/xy/index/pushEdbClassify"
- _, e, _ := HttpEtaBridgePost(uri, req)
- if e != nil {
- err = fmt.Errorf("第%d组分类数据推送失败,postRefreshEdbData err: %s", k+1, e.Error())
- fmt.Println(err)
- continue
- }
- }
- return
- }
- func SyncIndex(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "SyncIndex-定时同步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)
- condition += " AND id > ?"
- pars = append(pars, 50)
- list, err := data_manage.GetEdbUpdateLogByCondition(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- //pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq
- pushIndexList := make([]*PushIndexParamDataReq, 0)
- pushEdbClassifyList := make([]*PushEdbClassifyItemReq, 0)
- pushIndexValueList := make([]*PushIndexValueItemReq, 0)
- for _, v := range list {
- pushIndexData, pushEdbClassify, pushIndexValue, err := handleData(v)
- if err != nil {
- continue
- }
- if pushIndexData != nil {
- pushIndexList = append(pushIndexList, pushIndexData)
- }
- if pushEdbClassify != nil {
- pushEdbClassifyList = append(pushEdbClassifyList, pushEdbClassify)
- }
- if pushIndexValue != nil {
- pushIndexValueList = append(pushIndexValueList, pushIndexValue)
- }
- }
- return
- }
- func handleData(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
- switch edbUpdateLog.OpType {
- case "insert":
- return handleInsert(edbUpdateLog)
- case "update":
- return handleUpdate(edbUpdateLog)
- case "delete":
- return handleDelete(edbUpdateLog)
- }
- return
- }
- func handleInsert(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
- data := edbUpdateLog.NewData
- //指标信息
- if edbUpdateLog.OpTableName == "edb_info" {
- var edbInfo *data_manage.EdbInfo
- err = json.Unmarshal([]byte(data), &edbInfo)
- if err != nil {
- return
- }
- // 指标信息
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: edbInfo.EdbCode,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- IndexName: edbInfo.EdbName,
- IndexShortName: edbInfo.EdbName, //todo
- FrequenceName: edbInfo.Frequency,
- UnitName: edbInfo.Unit,
- AssetBeginDate: edbInfo.StartDate,
- AssetEndDate: edbInfo.EndDate,
- CreateUser: edbInfo.SysUserRealName,
- IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
- UpdateUser: edbInfo.SysUserRealName, // todo
- DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
- IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
- OrginSource: edbInfo.SourceName, // todo
- OrginSysSource: edbInfo.SourceName,
- SysSource: "产研平台",
- SourceType: getSourceType(edbInfo.Source),
- Status: 1,
- }
- // 指标与分类的关系信息
- pushEdbClassify = &PushEdbClassifyItemReq{
- Id: fmt.Sprint(edbInfo.EdbInfoId),
- ClassifyId: edbInfo.ClassifyId,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- CreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
- CreateUser: edbInfo.SysUserRealName,
- UpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime),
- UpdateUser: edbInfo.SysUserRealName,
- }
- return
- }
- // 分类信息
- //if edbUpdateLog.OpTableName == "edb_classify" {
- // var edbClassify *data_manage.EdbClassify
- // err = json.Unmarshal([]byte(data), &edbClassify)
- // if err != nil {
- // return
- // }
- //
- // // 指标信息
- // pushClassify = PushClassifyItemReq{
- // ClassifyId: int(edbClassify.ClassifyID),
- // ClassifyType: int(edbClassify.ClassifyType),
- // ClassifyName: edbClassify.ClassifyName,
- // ParentId: int(edbClassify.ParentID),
- // HasData: int(edbClassify.HasData),
- // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
- // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
- // SysUserId: int(edbClassify.SysUserID),
- // SysUserRealName: edbClassify.SysUserRealName,
- // Level: int(edbClassify.Level),
- // UniqueCode: edbClassify.UniqueCode,
- // SortColumn: int(edbClassify.Sort),
- // }
- //
- // return
- //}
- // 数据信息
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(data), &edbData)
- if err != nil {
- return
- }
- edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
- if !ok {
- // 没有找到来源,那就过滤
- return
- }
- // 数据信息
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime.Format(utils.FormatDate),
- CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
- UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
- Status: "1",
- }
- return
- }
- return
- }
- func handleDelete(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
- data := edbUpdateLog.OldData
- //指标信息
- if edbUpdateLog.OpTableName == "edb_info" {
- var edbInfo *data_manage.EdbInfo
- err = json.Unmarshal([]byte(data), &edbInfo)
- if err != nil {
- return
- }
- // 指标信息
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: edbInfo.EdbCode,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- IndexName: edbInfo.EdbName,
- IndexShortName: edbInfo.EdbName, //todo
- FrequenceName: edbInfo.Frequency,
- UnitName: edbInfo.Unit,
- AssetBeginDate: edbInfo.StartDate,
- AssetEndDate: edbInfo.EndDate,
- CreateUser: edbInfo.SysUserRealName,
- IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
- UpdateUser: edbInfo.SysUserRealName, // todo
- DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
- IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
- OrginSource: edbInfo.SourceName, // todo
- OrginSysSource: edbInfo.SourceName,
- SysSource: "产研平台",
- SourceType: getSourceType(edbInfo.Source),
- Status: 0,
- }
- // 指标与分类的关系信息
- pushEdbClassify = &PushEdbClassifyItemReq{
- Id: fmt.Sprint(edbInfo.EdbInfoId),
- ClassifyId: edbInfo.ClassifyId,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- CreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
- CreateUser: edbInfo.SysUserRealName,
- UpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime),
- UpdateUser: edbInfo.SysUserRealName,
- }
- return
- }
- // 分类信息
- //if edbUpdateLog.OpTableName == "edb_classify" {
- // var edbClassify *data_manage.EdbClassify
- // err = json.Unmarshal([]byte(data), &edbClassify)
- // if err != nil {
- // return
- // }
- //
- // // 指标信息
- // pushClassify = PushClassifyItemReq{
- // ClassifyId: int(edbClassify.ClassifyID),
- // ClassifyType: int(edbClassify.ClassifyType),
- // ClassifyName: edbClassify.ClassifyName,
- // ParentId: int(edbClassify.ParentID),
- // HasData: int(edbClassify.HasData),
- // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
- // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
- // SysUserId: int(edbClassify.SysUserID),
- // SysUserRealName: edbClassify.SysUserRealName,
- // Level: int(edbClassify.Level),
- // UniqueCode: edbClassify.UniqueCode,
- // SortColumn: int(edbClassify.Sort),
- // }
- //
- // return
- //}
- // 数据信息
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(data), &edbData)
- if err != nil {
- return
- }
- edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
- if !ok {
- // 没有找到来源,那就过滤
- return
- }
- // 数据信息
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime.Format(utils.FormatDate),
- CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
- UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
- Status: "0",
- }
- return
- }
- return
- }
- func handleUpdate(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
- oldData := edbUpdateLog.OldData
- newData := edbUpdateLog.NewData
- //指标信息
- if edbUpdateLog.OpTableName == "edb_info" {
- var oldEdbInfo *data_manage.EdbInfo
- err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
- if err != nil {
- return
- }
- var newEdbInfo *data_manage.EdbInfo
- err = json.Unmarshal([]byte(newData), &newEdbInfo)
- if err != nil {
- return
- }
- isUpdateEdbInfo := checkUpdateType(oldEdbInfo, newEdbInfo)
- // 指标信息
- if isUpdateEdbInfo {
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: newEdbInfo.EdbCode,
- IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
- IndexName: newEdbInfo.EdbName,
- IndexShortName: newEdbInfo.EdbName, //todo
- FrequenceName: newEdbInfo.Frequency,
- UnitName: newEdbInfo.Unit,
- AssetBeginDate: newEdbInfo.StartDate,
- AssetEndDate: newEdbInfo.EndDate,
- CreateUser: newEdbInfo.SysUserRealName,
- IndexCreateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime),
- UpdateUser: newEdbInfo.SysUserRealName, // todo
- DetailUpdateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime), //todo
- IndexUpdateTime: newEdbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
- OrginSource: newEdbInfo.SourceName, // todo
- OrginSysSource: newEdbInfo.SourceName,
- SysSource: "产研平台",
- SourceType: getSourceType(newEdbInfo.Source),
- Status: 1,
- }
- }
- // 指标与分类的关系信息
- if oldEdbInfo.ClassifyId != newEdbInfo.ClassifyId {
- pushEdbClassify = &PushEdbClassifyItemReq{
- Id: fmt.Sprint(newEdbInfo.EdbInfoId),
- ClassifyId: newEdbInfo.ClassifyId,
- IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
- CreateTime: newEdbInfo.CreateTime.Format(utils.FormatDateTime),
- CreateUser: newEdbInfo.SysUserRealName,
- UpdateTime: newEdbInfo.ModifyTime.Format(utils.FormatDateTime),
- UpdateUser: newEdbInfo.SysUserRealName,
- }
- }
- return
- }
- // 分类信息
- //if edbUpdateLog.OpTableName == "edb_classify" {
- // var edbClassify *data_manage.EdbClassify
- // err = json.Unmarshal([]byte(newData), &edbClassify)
- // if err != nil {
- // return
- // }
- //
- // // 指标信息
- // pushClassify = PushClassifyItemReq{
- // ClassifyId: int(edbClassify.ClassifyID),
- // ClassifyType: int(edbClassify.ClassifyType),
- // ClassifyName: edbClassify.ClassifyName,
- // ParentId: int(edbClassify.ParentID),
- // HasData: int(edbClassify.HasData),
- // CreateTime: edbClassify.CreateTime.Format(utils.FormatDateTime),
- // UpdateTime: edbClassify.ModifyTime.Format(utils.FormatDateTime),
- // SysUserId: int(edbClassify.SysUserID),
- // SysUserRealName: edbClassify.SysUserRealName,
- // Level: int(edbClassify.Level),
- // UniqueCode: edbClassify.UniqueCode,
- // SortColumn: int(edbClassify.Sort),
- // }
- //
- // return
- //}
- // 数据信息
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(newData), &edbData)
- if err != nil {
- return
- }
- edbSource, ok := data_manage.EdbTableNameSourceMap[edbUpdateLog.OpTableName]
- if !ok {
- // 没有找到来源,那就过滤
- return
- }
- // 数据信息
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(edbSource.EdbSourceId, "_", edbSource.SourceName, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(edbSource, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime.Format(utils.FormatDate),
- CreateTime: edbData.CreateTime.Format(utils.FormatDateTime),
- UpdateTime: edbData.ModifyTime.Format(utils.FormatDateTime),
- Status: "1",
- }
- return
- }
- return
- }
- //PushIndexParamDataReq{
- //SourceIndexCode: edbInfo.EdbCode,
- //IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- //IndexName: edbInfo.EdbName,
- //IndexShortName: edbInfo.EdbName, //todo
- //FrequenceName: edbInfo.Frequency,
- //UnitName: edbInfo.Unit,
- //AssetBeginDate: edbInfo.StartDate,
- //AssetEndDate: edbInfo.EndDate,
- //CreateUser: edbInfo.SysUserRealName,
- //IndexCreateTime: edbInfo.CreateTime.Format(utils.FormatDateTime),
- //UpdateUser: edbInfo.SysUserRealName, // todo
- //DetailUpdateTime: edbInfo.CreateTime.Format(utils.FormatDateTime), //todo
- //IndexUpdateTime: edbInfo.ModifyTime.Format(utils.FormatDateTime), //todo
- //OrginSource: edbInfo.SourceName, // todo
- //OrginSysSource: edbInfo.SourceName,
- //SysSource: "产研平台",
- //SourceType: getSourceType(edbInfo.Source),
- //Status: 1,
- //}
- // getSourceType
- // @Description: 获取指标来源类型
- // @author: Roc
- // @datetime 2024-03-01 13:40:03
- // @param source int
- // @return string
- func getSourceType(source int) string {
- switch source {
- case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS, utils.DATA_SOURCE_BAIINFO, utils.DATA_SOURCE_SCI: //钢联,有色,百川盈孚,红桃3
- return "RPA"
- case utils.DATA_SOURCE_MANUAL:
- return "手工"
- default:
- return "接口"
- }
- }
- func checkUpdateType(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (isUpdateEdbInfo bool) {
- //todo 外部来源名称需要处理;更新人姓名,指标更新时间
- // eta内部名称
- if oldEdbInfo.EdbName != newEdbInfo.EdbName {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.Frequency != newEdbInfo.Frequency {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.Unit != newEdbInfo.Unit {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.StartDate != newEdbInfo.StartDate {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.EndDate != newEdbInfo.EndDate {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.SysUserId != newEdbInfo.SysUserId {
- isUpdateEdbInfo = true
- return
- }
- if oldEdbInfo.SysUserRealName != newEdbInfo.SysUserRealName {
- isUpdateEdbInfo = true
- return
- }
- return
- }
- //func pushIndex(pushIndexList []*PushIndexParamDataReq) {
- // if len(pushIndexList) <= 0 {
- // return
- // }
- //
- // uri := "/xy/index/pushIndexData"
- // req := PushBaseParamReq{
- // SerialID: utils.GetRandString(32), //todo
- // TableCode: "",
- // Total: lenData,
- // IsEmailWarn: 0,
- // Data: dataList,
- // }
- //
- // var pushIndexList []*PushIndexParamDataReq
- // dataLimitList := make([][]PushBaseParamReq, 0)
- //
- // _, e, errMsg := HttpEtaBridgePost(uri, req)
- //}
|