123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- package eta_bridge
- import (
- "encoding/json"
- "eta/eta_task/models/data_manage"
- "eta/eta_task/utils"
- "fmt"
- "strings"
- )
- 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.EdbInfoItem
- err = json.Unmarshal([]byte(data), &edbInfo)
- if err != nil {
- return
- }
-
- if edbInfo.EdbInfoType == 1 {
- return
- }
-
- if edbInfo.EdbType == 2 {
- return
- }
-
- origInfo := getOrigInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
-
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: edbInfo.EdbCode,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- IndexName: origInfo.EdbName,
- IndexShortName: edbInfo.EdbName,
- FrequenceName: edbInfo.Frequency,
- UnitName: edbInfo.Unit,
- AssetBeginDate: edbInfo.StartDate,
- AssetEndDate: edbInfo.EndDate,
- CreateUser: edbInfo.SysUserRealName,
- IndexCreateTime: edbInfo.CreateTime,
- UpdateUser: edbInfo.SysUserRealName,
- DetailUpdateTime: getMaxModifyTime(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
- IndexUpdateTime: edbInfo.ModifyTime,
- OrginSource: edbInfo.SourceName,
- OrginSysSource: origInfo.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,
- CreateUser: edbInfo.SysUserRealName,
- UpdateTime: edbInfo.ModifyTime,
- UpdateUser: edbInfo.SysUserRealName,
- }
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
- return
- }
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
- return
- }
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(data), &edbData)
- if err != nil {
- return
- }
- source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
- if source <= 0 {
-
- return
- }
-
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(source, "_", subSource, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(source, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime,
- CreateTime: edbData.CreateTime,
- UpdateTime: edbData.ModifyTime,
- 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.EdbInfoItem
- err = json.Unmarshal([]byte(data), &edbInfo)
- if err != nil {
- return
- }
-
- if edbInfo.EdbInfoType == 1 {
- return
- }
-
- if edbInfo.EdbType == 2 {
- return
- }
-
- origInfo := getOrigInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
-
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: edbInfo.EdbCode,
- IndexCode: fmt.Sprint(edbInfo.Source, "_", edbInfo.EdbCode),
- IndexName: origInfo.EdbName,
- IndexShortName: edbInfo.EdbName,
- FrequenceName: edbInfo.Frequency,
- UnitName: edbInfo.Unit,
- AssetBeginDate: edbInfo.StartDate,
- AssetEndDate: edbInfo.EndDate,
- CreateUser: edbInfo.SysUserRealName,
- IndexCreateTime: edbInfo.CreateTime,
- UpdateUser: edbInfo.SysUserRealName,
- DetailUpdateTime: edbUpdateLog.CreateTime.Format(utils.FormatDateTime),
- IndexUpdateTime: edbInfo.ModifyTime,
- OrginSource: edbInfo.SourceName,
- OrginSysSource: origInfo.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,
- CreateUser: edbInfo.SysUserRealName,
- UpdateTime: edbInfo.ModifyTime,
- UpdateUser: edbInfo.SysUserRealName,
- }
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
- return
- }
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
- return
- }
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(data), &edbData)
- if err != nil {
- return
- }
- source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
- if source <= 0 {
-
- return
- }
-
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(source, "_", subSource, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(source, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime,
- CreateTime: edbData.CreateTime,
- UpdateTime: edbData.ModifyTime,
- 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.EdbInfoItem
- err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
- if err != nil {
- return
- }
-
- if oldEdbInfo.EdbInfoType == 1 {
- return
- }
-
- if oldEdbInfo.EdbType == 2 {
- return
- }
- var newEdbInfo *data_manage.EdbInfoItem
- err = json.Unmarshal([]byte(newData), &newEdbInfo)
- if err != nil {
- return
- }
- isUpdateEdbInfo := checkUpdateType(oldEdbInfo, newEdbInfo)
-
- if isUpdateEdbInfo {
-
- origInfo := getOrigInfo(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode)
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: newEdbInfo.EdbCode,
- IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
- IndexName: origInfo.EdbName,
- IndexShortName: newEdbInfo.EdbName,
- FrequenceName: newEdbInfo.Frequency,
- UnitName: newEdbInfo.Unit,
- AssetBeginDate: newEdbInfo.StartDate,
- AssetEndDate: newEdbInfo.EndDate,
- CreateUser: newEdbInfo.SysUserRealName,
- IndexCreateTime: newEdbInfo.CreateTime,
- UpdateUser: newEdbInfo.SysUserRealName,
- DetailUpdateTime: getMaxModifyTime(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
- IndexUpdateTime: newEdbInfo.ModifyTime,
- OrginSource: newEdbInfo.SourceName,
- OrginSysSource: origInfo.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,
- CreateUser: newEdbInfo.SysUserRealName,
- UpdateTime: newEdbInfo.ModifyTime,
- UpdateUser: newEdbInfo.SysUserRealName,
- }
- }
- return
- }
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_") {
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_calculate") {
- return
- }
-
- if strings.HasPrefix(edbUpdateLog.OpTableName, "edb_data_predict") {
- return
- }
- var edbData *data_manage.EdbData
- err = json.Unmarshal([]byte(newData), &edbData)
- if err != nil {
- return
- }
- source, subSource := data_manage.GetSourceAndSubSourceTableName(edbUpdateLog.OpTableName, edbData.EdbCode)
- if source <= 0 {
-
- return
- }
-
- pushIndexValue = &PushIndexValueItemReq{
- Id: utils.MD5(fmt.Sprint(source, "_", subSource, "_", edbData.EdbDataId)),
- IndexCode: fmt.Sprint(source, "_", edbData.EdbCode),
- Value: fmt.Sprint(edbData.Value),
- BusinessDate: edbData.DataTime,
- CreateTime: edbData.CreateTime,
- UpdateTime: edbData.ModifyTime,
- Status: "1",
- }
- return
- }
-
- return handleUpdateDataSource(edbUpdateLog)
- }
- func handleUpdateDataSource(edbUpdateLog *data_manage.EdbUpdateLog) (pushIndexData *PushIndexParamDataReq, pushEdbClassify *PushEdbClassifyItemReq, pushIndexValue *PushIndexValueItemReq, err error) {
- oldData := edbUpdateLog.OldData
- newData := edbUpdateLog.NewData
- isUpdateIndexInfo := false
- indexName := ``
- indexSourceName := ``
- source := 0
- edbCode := ``
-
- if edbUpdateLog.OpTableName == "base_from_mysteel_chemical_index" {
- var oldEdbInfo *data_manage.BaseFromMysteelChemicalIndexItem
- err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
- if err != nil {
- return
- }
- var newEdbInfo *data_manage.BaseFromMysteelChemicalIndexItem
- err = json.Unmarshal([]byte(newData), &newEdbInfo)
- if err != nil {
- return
- }
- if oldEdbInfo.IndexName != newEdbInfo.IndexName {
- isUpdateIndexInfo = true
- } else if oldEdbInfo.Source != newEdbInfo.Source {
- isUpdateIndexInfo = true
- }
- if isUpdateIndexInfo {
- indexName = newEdbInfo.IndexName
- indexSourceName = newEdbInfo.Source
- edbCode = newEdbInfo.IndexCode
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- }
- } else if edbUpdateLog.OpTableName == "base_from_smm_index" {
-
- var oldEdbInfo *data_manage.BaseFromSmmIndexItem
- err = json.Unmarshal([]byte(oldData), &oldEdbInfo)
- if err != nil {
- return
- }
- var newEdbInfo *data_manage.BaseFromSmmIndexItem
- err = json.Unmarshal([]byte(newData), &newEdbInfo)
- if err != nil {
- return
- }
- if oldEdbInfo.IndexName != newEdbInfo.IndexName {
- isUpdateIndexInfo = true
- } else if oldEdbInfo.Interface != newEdbInfo.Interface {
- isUpdateIndexInfo = true
- }
- if isUpdateIndexInfo {
- indexName = newEdbInfo.IndexName
- indexSourceName = newEdbInfo.Interface
- edbCode = newEdbInfo.IndexCode
- source = utils.DATA_SOURCE_YS
- }
- }
-
- if isUpdateIndexInfo {
- newEdbInfo, tmpErr := data_manage.GetEdbInfoItemByCodeAndSource(source, edbCode)
- if tmpErr != nil {
- if tmpErr.Error() != utils.ErrNoRow() {
- err = tmpErr
- return
- }
- return
- }
- pushIndexData = &PushIndexParamDataReq{
- SourceIndexCode: newEdbInfo.EdbCode,
- IndexCode: fmt.Sprint(newEdbInfo.Source, "_", newEdbInfo.EdbCode),
- IndexName: indexName,
- IndexShortName: newEdbInfo.EdbName,
- FrequenceName: newEdbInfo.Frequency,
- UnitName: newEdbInfo.Unit,
- AssetBeginDate: newEdbInfo.StartDate,
- AssetEndDate: newEdbInfo.EndDate,
- CreateUser: newEdbInfo.SysUserRealName,
- IndexCreateTime: newEdbInfo.CreateTime,
- UpdateUser: newEdbInfo.SysUserRealName,
- DetailUpdateTime: getMaxModifyTime(newEdbInfo.Source, newEdbInfo.SubSource, newEdbInfo.EdbCode, edbUpdateLog.CreateTime.Format(utils.FormatDateTime)),
- IndexUpdateTime: newEdbInfo.ModifyTime,
- OrginSource: newEdbInfo.SourceName,
- OrginSysSource: indexSourceName,
- SysSource: "产研平台",
- SourceType: getSourceType(newEdbInfo.Source),
- Status: 1,
- }
- }
- return
- }
- 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:
- return "RPA"
- case utils.DATA_SOURCE_MANUAL:
- return "手工"
- default:
- return "接口"
- }
- }
- func checkUpdateType(oldEdbInfo, newEdbInfo *data_manage.EdbInfoItem) (isUpdateEdbInfo bool) {
-
- 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
- }
- type OrigInfo struct {
- EdbName string
- SourceName string
- }
- func getOrigInfo(source, subSource int, edbCode string) (origInfo OrigInfo) {
- switch source {
- case utils.DATA_SOURCE_THS, utils.DATA_SOURCE_WIND:
- origInfo.SourceName = "经济数据库"
- if subSource == utils.DATA_SUB_SOURCE_DATE {
- origInfo.SourceName = "日期序列"
- }
- case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
- edbInfo, err := data_manage.GetBaseFromMysteelChemicalIndexItemByCode(edbCode)
- if err != nil {
- return
- }
- origInfo.EdbName = edbInfo.IndexName
- origInfo.SourceName = edbInfo.Source
-
- case utils.DATA_SOURCE_YS:
- edbInfo, err := data_manage.GetBaseFromSmmIndexItemItemByCode(edbCode)
- if err != nil {
- return
- }
- origInfo.EdbName = edbInfo.IndexName
- origInfo.SourceName = edbInfo.Interface
- }
- return
- }
- func getMaxModifyTime(source, subSource int, edbCode, addUpdateTime string) (modifyTime string) {
- modifyTime, err := data_manage.GetEdbInfoMaxModifyTime(source, subSource, edbCode)
- if err != nil {
- modifyTime = addUpdateTime
- return
- }
- return
- }
|