1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414 |
- package services
- import (
- "encoding/json"
- "errors"
- "eta/eta_data_init/models"
- "eta/eta_data_init/utils"
- "fmt"
- "github.com/xuri/excelize/v2"
- "os"
- "path/filepath"
- "strings"
- )
- // InitBaseIndexData 初始化基础指标数据
- func InitBaseIndexData(dataPath string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("InitBaseIndexData Err:" + err.Error())
- utils.FileLog.Info("InitJiaYueIndexData Err: " + err.Error())
- }
- }()
- //读取excel
- path, err := filepath.Abs(os.Args[0])
- if err != nil {
- fmt.Println(err)
- }
- dir := filepath.Dir(path)
- fmt.Println("dir:" + dir)
- //dataPath := dir + "/docs/东吴ETA同花顺指标20230925.xlsx"
- dataPath = dir + dataPath
- fmt.Println("dataPath:" + dataPath)
- f, err := excelize.OpenFile(dataPath)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer func() {
- // Close the spreadsheet.
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
- rows, err := f.GetRows("Sheet1")
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("rows len:", len(rows))
- // 获取创建人信息
- mobileMap := make(map[string]*models.Admin)
- if utils.MYSQL_URL_ETA != "" {
- admins, e := models.GetSysAdminList(``, make([]interface{}, 0))
- if e != nil {
- err = fmt.Errorf("GetSysAdminList err: %s", e.Error())
- return
- }
- for _, v := range admins {
- if v.Mobile == "" {
- continue
- }
- mobileMap[v.Mobile] = v
- }
- }
- for rk, row := range rows {
- if rk > 0 {
- var classifyFirst, classifySecond, classifyThree, classifyFourth, classifyFifth, classifySixth, indexCode, indexName, frequency, unit, source, mobile, terminalCode string
- for ck, colCell := range row {
- colCell = strings.TrimSpace(colCell)
- switch ck {
- case 0:
- classifyFirst = colCell
- case 1:
- classifySecond = colCell
- case 2:
- classifyThree = colCell
- case 3:
- classifyFourth = colCell
- case 4:
- classifyFifth = colCell
- case 5:
- classifySixth = colCell
- case 6:
- indexCode = colCell
- case 7:
- indexName = colCell
- case 8:
- frequency = colCell
- case 9:
- unit = colCell
- case 10:
- source = colCell
- case 11:
- mobile = colCell
- case 12:
- terminalCode = colCell
- }
- }
- if classifyFirst != "" &&
- indexCode != "" &&
- indexName != "" &&
- unit != "" &&
- frequency != "" &&
- source != "" {
- var firstId, secondId, thirdId, fourthId, fifthId, lastId int
- method := "classify/get_or_add"
- classifyFirstMap := make(map[string]interface{})
- classifyFirstMap["ClassifyName"] = classifyFirst
- classifyFirstMap["ParentId"] = 0
- classifyFirstMap["Level"] = 0
- classifyFirstMap["ClassifyType"] = 0
- result, e := PostEdbLib(classifyFirstMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFirst PostEdbLib err: %s", e.Error())
- return
- }
- resp := new(models.ClassifyResp)
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("ClassifyFirst json unmarshal err: %s", e.Error())
- return
- }
- if resp.Ret != 200 {
- err = fmt.Errorf("ClassifyFirst resp msg: %s; errMsg: %s", resp.Msg, resp.ErrMsg)
- return
- }
- firstId = resp.Data.ClassifyId
- lastId = firstId
- // 二级分类
- if classifySecond != "" {
- classifySecondMap := make(map[string]interface{})
- classifySecondMap["ClassifyName"] = classifySecond
- classifySecondMap["ParentId"] = firstId
- classifySecondMap["Level"] = 1
- classifySecondMap["ClassifyType"] = 0
- res2, e := PostEdbLib(classifySecondMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySecond PostEdbLib err: %s", e.Error())
- return
- }
- resp2 := new(models.ClassifyResp)
- if e = json.Unmarshal(res2, &resp2); e != nil {
- err = fmt.Errorf("ClassifySecond json unmarshal err: %s", e.Error())
- return
- }
- if resp2.Ret != 200 {
- err = fmt.Errorf("ClassifySecond resp msg: %s; errMsg: %s", resp2.Msg, resp2.ErrMsg)
- return
- }
- secondId = resp2.Data.ClassifyId
- lastId = secondId
- }
- // 三级分类
- if classifyThree != "" {
- classifyThreeMap := make(map[string]interface{})
- classifyThreeMap["ClassifyName"] = classifyThree
- classifyThreeMap["ParentId"] = secondId
- classifyThreeMap["Level"] = 2
- classifyThreeMap["ClassifyType"] = 0
- res3, e := PostEdbLib(classifyThreeMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyThird PostEdbLib err: %s", e.Error())
- return
- }
- resp3 := new(models.ClassifyResp)
- if e = json.Unmarshal(res3, &resp3); e != nil {
- err = fmt.Errorf("ClassifyThird json unmarshal err: %s", e.Error())
- return
- }
- if resp3.Ret != 200 {
- err = fmt.Errorf("ClassifyThird resp msg: %s; errMsg: %s", resp3.Msg, resp3.ErrMsg)
- return
- }
- thirdId = resp3.Data.ClassifyId
- lastId = thirdId
- }
- // 四级分类
- if classifyFourth != "" {
- classifyFourthMap := make(map[string]interface{})
- classifyFourthMap["ClassifyName"] = classifyFourth
- classifyFourthMap["ParentId"] = thirdId
- classifyFourthMap["Level"] = 3
- classifyFourthMap["ClassifyType"] = 0
- res4, e := PostEdbLib(classifyFourthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFourth PostEdbLib err: %s", e.Error())
- return
- }
- resp4 := new(models.ClassifyResp)
- if e = json.Unmarshal(res4, &resp4); e != nil {
- err = fmt.Errorf("ClassifyFourth json unmarshal err: %s", e.Error())
- return
- }
- if resp4.Ret != 200 {
- err = fmt.Errorf("ClassifyFourth resp msg: %s; errMsg: %s", resp4.Msg, resp4.ErrMsg)
- return
- }
- fourthId = resp4.Data.ClassifyId
- lastId = fourthId
- }
- // 五级分类
- if classifyFifth != "" {
- classifyFifthMap := make(map[string]interface{})
- classifyFifthMap["ClassifyName"] = classifyFifth
- classifyFifthMap["ParentId"] = fourthId
- classifyFifthMap["Level"] = 4
- classifyFifthMap["ClassifyType"] = 0
- res5, e := PostEdbLib(classifyFifthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFifth PostEdbLib err: %s", e.Error())
- return
- }
- resp5 := new(models.ClassifyResp)
- if e = json.Unmarshal(res5, &resp5); e != nil {
- err = fmt.Errorf("ClassifyFifth json unmarshal err: %s", e.Error())
- return
- }
- if resp5.Ret != 200 {
- err = fmt.Errorf("ClassifyFifth resp msg: %s; errMsg: %s", resp5.Msg, resp5.ErrMsg)
- return
- }
- fifthId = resp5.Data.ClassifyId
- lastId = fifthId
- }
- // 六级分类
- if classifySixth != "" {
- classifySixthMap := make(map[string]interface{})
- classifySixthMap["ClassifyName"] = classifySixth
- classifySixthMap["ParentId"] = fifthId
- classifySixthMap["Level"] = 5
- classifySixthMap["ClassifyType"] = 0
- res6, e := PostEdbLib(classifySixthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySixth PostEdbLib err: %s", e.Error())
- return
- }
- resp6 := new(models.ClassifyResp)
- if e = json.Unmarshal(res6, &resp6); e != nil {
- err = fmt.Errorf("ClassifySixth json unmarshal err: %s", e.Error())
- return
- }
- if resp6.Ret != 200 {
- err = fmt.Errorf("ClassifySixth resp msg: %s; errMsg: %s", resp6.Msg, resp6.ErrMsg)
- return
- }
- lastId = resp6.Data.ClassifyId
- }
- method = "edb_info/add"
- sourceId, ok := IndexSourceMap[source]
- if !ok {
- fmt.Println("source is not defined")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- continue
- }
- indexMap := make(map[string]interface{})
- indexMap["Source"] = sourceId
- indexMap["EdbCode"] = indexCode
- indexMap["EdbName"] = indexName
- indexMap["Frequency"] = frequency
- indexMap["Unit"] = unit
- indexMap["ClassifyId"] = lastId
- indexMap["TerminalCode"] = terminalCode
- admin := mobileMap[mobile]
- if admin != nil {
- indexMap["AdminId"] = admin.AdminId
- indexMap["AdminName"] = admin.RealName
- }
- result, err = PostEdbLib(indexMap, method)
- if err != nil {
- utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
- return
- }
- indexResp := new(models.EdbInfoResp)
- err = json.Unmarshal(result, &indexResp)
- if err != nil {
- utils.FileLog.Info("初始化分类2失败:" + err.Error())
- return
- }
- if indexResp.Ret != 200 {
- if strings.Contains(indexResp.Msg, "新增指标失败") {
- continue
- } else {
- fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- return
- }
- }
- fmt.Println("add index success:" + indexCode)
- //刷新指标
- {
- switch source {
- case "wind", "万得":
- method = "wind/refresh"
- case "ths", "同花顺":
- method = "ths/refresh"
- case "彭博":
- method = "pb/refresh"
- case "路透":
- method = "lt/refresh"
- case "":
- }
- if method != `` {
- refreshMap := make(map[string]interface{})
- refreshMap["EdbInfoId"] = indexResp.Data.EdbInfoId
- refreshMap["EdbCode"] = indexCode
- refreshMap["StartDate"] = "1990-01-01"
- PostEdbLib(refreshMap, method)
- }
- }
- } else {
- fmt.Println("data is empty")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- }
- }
- }
- }
- // 初始化基础指标数据-钢联
- func InitBaseIndexDataFromMysteel(filePath string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("InitBaseIndexDataFromMysteel Err:" + err.Error())
- utils.FileLog.Info("InitBaseIndexDataFromMysteel Err:" + err.Error())
- }
- }()
- //读取excel
- path, err := filepath.Abs(os.Args[0])
- if err != nil {
- fmt.Println(err)
- }
- dir := filepath.Dir(path)
- fmt.Println("dir:" + dir)
- dataPath := dir + filePath
- fmt.Println("dataPath:" + dataPath)
- f, err := excelize.OpenFile(dataPath)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer func() {
- // Close the spreadsheet.
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
- rows, err := f.GetRows("Sheet1")
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("rows len:", len(rows))
- // 获取创建人信息
- mobileMap := make(map[string]*models.Admin)
- if utils.MYSQL_URL_ETA != "" {
- admins, e := models.GetSysAdminList(``, make([]interface{}, 0))
- if e != nil {
- err = fmt.Errorf("GetSysAdminList err: %s", e.Error())
- return
- }
- for _, v := range admins {
- if v.Mobile == "" {
- continue
- }
- mobileMap[v.Mobile] = v
- }
- }
- for rk, row := range rows {
- if rk > 0 {
- var classifyFirst, classifySecond, classifyThree, classifyFourth, classifyFifth, classifySixth, indexCode, indexName, frequency, unit, source, mobile string
- for ck, colCell := range row {
- colCell = strings.TrimSpace(colCell)
- switch ck {
- case 0:
- classifyFirst = colCell
- case 1:
- classifySecond = colCell
- case 2:
- classifyThree = colCell
- case 3:
- classifyFourth = colCell
- case 4:
- classifyFifth = colCell
- case 5:
- classifySixth = colCell
- case 6:
- indexCode = colCell
- case 7:
- indexName = colCell
- case 8:
- frequency = colCell
- case 9:
- unit = colCell
- case 10:
- source = colCell
- case 11:
- mobile = colCell
- }
- }
- if classifyFirst != "" &&
- indexCode != "" &&
- indexName != "" &&
- unit != "" &&
- frequency != "" &&
- source != "" {
- //判断指标是否存在
- method := "mysteel_chemical/index_detail"
- indexSearchMap := make(map[string]interface{})
- indexSearchMap["IndexCode"] = indexCode
- indexResult, e := PostEdbLib(indexSearchMap, method)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- mysteelIndexResp := new(models.MysteelIndexResp)
- e = json.Unmarshal(indexResult, &mysteelIndexResp)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- if mysteelIndexResp.Ret != 200 {
- fmt.Println("判断指标是否存在失败,Err:" + mysteelIndexResp.ErrMsg)
- //utils.FileLog.Info("判断指标是否存在失败:" + err.Error())
- //return
- continue
- }
- if mysteelIndexResp.Data.BaseFromMysteelChemicalIndexId <= 0 {
- fmt.Println("指标:" + indexCode + ";不存在")
- continue
- }
- var firstId, secondId, thirdId, fourthId, fifthId, lastId int
- method = "classify/get_or_add"
- classifyFirstMap := make(map[string]interface{})
- classifyFirstMap["ClassifyName"] = classifyFirst
- classifyFirstMap["ParentId"] = 0
- classifyFirstMap["Level"] = 0
- classifyFirstMap["ClassifyType"] = 0
- result, e := PostEdbLib(classifyFirstMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFirst PostEdbLib err: %s", e.Error())
- return
- }
- resp := new(models.ClassifyResp)
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("ClassifyFirst json unmarshal err: %s", e.Error())
- return
- }
- if resp.Ret != 200 {
- err = fmt.Errorf("ClassifyFirst resp msg: %s; errMsg: %s", resp.Msg, resp.ErrMsg)
- return
- }
- firstId = resp.Data.ClassifyId
- lastId = firstId
- // 二级分类
- if classifySecond != "" {
- classifySecondMap := make(map[string]interface{})
- classifySecondMap["ClassifyName"] = classifySecond
- classifySecondMap["ParentId"] = firstId
- classifySecondMap["Level"] = 1
- classifySecondMap["ClassifyType"] = 0
- res2, e := PostEdbLib(classifySecondMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySecond PostEdbLib err: %s", e.Error())
- return
- }
- resp2 := new(models.ClassifyResp)
- if e = json.Unmarshal(res2, &resp2); e != nil {
- err = fmt.Errorf("ClassifySecond json unmarshal err: %s", e.Error())
- return
- }
- if resp2.Ret != 200 {
- err = fmt.Errorf("ClassifySecond resp msg: %s; errMsg: %s", resp2.Msg, resp2.ErrMsg)
- return
- }
- secondId = resp2.Data.ClassifyId
- lastId = secondId
- }
- // 三级分类
- if classifyThree != "" {
- classifyThreeMap := make(map[string]interface{})
- classifyThreeMap["ClassifyName"] = classifyThree
- classifyThreeMap["ParentId"] = secondId
- classifyThreeMap["Level"] = 2
- classifyThreeMap["ClassifyType"] = 0
- res3, e := PostEdbLib(classifyThreeMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyThird PostEdbLib err: %s", e.Error())
- return
- }
- resp3 := new(models.ClassifyResp)
- if e = json.Unmarshal(res3, &resp3); e != nil {
- err = fmt.Errorf("ClassifyThird json unmarshal err: %s", e.Error())
- return
- }
- if resp3.Ret != 200 {
- err = fmt.Errorf("ClassifyThird resp msg: %s; errMsg: %s", resp3.Msg, resp3.ErrMsg)
- return
- }
- thirdId = resp3.Data.ClassifyId
- lastId = thirdId
- }
- // 四级分类
- if classifyFourth != "" {
- classifyFourthMap := make(map[string]interface{})
- classifyFourthMap["ClassifyName"] = classifyFourth
- classifyFourthMap["ParentId"] = thirdId
- classifyFourthMap["Level"] = 3
- classifyFourthMap["ClassifyType"] = 0
- res4, e := PostEdbLib(classifyFourthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFourth PostEdbLib err: %s", e.Error())
- return
- }
- resp4 := new(models.ClassifyResp)
- if e = json.Unmarshal(res4, &resp4); e != nil {
- err = fmt.Errorf("ClassifyFourth json unmarshal err: %s", e.Error())
- return
- }
- if resp4.Ret != 200 {
- err = fmt.Errorf("ClassifyFourth resp msg: %s; errMsg: %s", resp4.Msg, resp4.ErrMsg)
- return
- }
- fourthId = resp4.Data.ClassifyId
- lastId = fourthId
- }
- // 五级分类
- if classifyFifth != "" {
- classifyFifthMap := make(map[string]interface{})
- classifyFifthMap["ClassifyName"] = classifyFifth
- classifyFifthMap["ParentId"] = fourthId
- classifyFifthMap["Level"] = 4
- classifyFifthMap["ClassifyType"] = 0
- res5, e := PostEdbLib(classifyFifthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFifth PostEdbLib err: %s", e.Error())
- return
- }
- resp5 := new(models.ClassifyResp)
- if e = json.Unmarshal(res5, &resp5); e != nil {
- err = fmt.Errorf("ClassifyFifth json unmarshal err: %s", e.Error())
- return
- }
- if resp5.Ret != 200 {
- err = fmt.Errorf("ClassifyFifth resp msg: %s; errMsg: %s", resp5.Msg, resp5.ErrMsg)
- return
- }
- fifthId = resp5.Data.ClassifyId
- lastId = fifthId
- }
- // 六级分类
- if classifySixth != "" {
- classifySixthMap := make(map[string]interface{})
- classifySixthMap["ClassifyName"] = classifySixth
- classifySixthMap["ParentId"] = fifthId
- classifySixthMap["Level"] = 5
- classifySixthMap["ClassifyType"] = 0
- res6, e := PostEdbLib(classifySixthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySixth PostEdbLib err: %s", e.Error())
- return
- }
- resp6 := new(models.ClassifyResp)
- if e = json.Unmarshal(res6, &resp6); e != nil {
- err = fmt.Errorf("ClassifySixth json unmarshal err: %s", e.Error())
- return
- }
- if resp6.Ret != 200 {
- err = fmt.Errorf("ClassifySixth resp msg: %s; errMsg: %s", resp6.Msg, resp6.ErrMsg)
- return
- }
- lastId = resp6.Data.ClassifyId
- }
- method = "edb_info/add"
- indexMap := make(map[string]interface{})
- indexMap["Source"] = IndexSourceMap[source]
- indexMap["EdbCode"] = indexCode
- indexMap["EdbName"] = indexName
- indexMap["Frequency"] = frequency
- indexMap["Unit"] = unit
- indexMap["ClassifyId"] = lastId
- admin := mobileMap[mobile]
- if admin != nil {
- indexMap["AdminId"] = admin.AdminId
- indexMap["AdminName"] = admin.RealName
- }
- result, err = PostEdbLib(indexMap, method)
- if err != nil {
- utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
- return
- }
- indexResp := new(models.EdbInfoResp)
- err = json.Unmarshal(result, &indexResp)
- if err != nil {
- utils.FileLog.Info("初始化分类2失败:" + err.Error())
- return
- }
- if indexResp.Ret != 200 {
- if strings.Contains(indexResp.Msg, "新增指标失败") {
- continue
- } else {
- fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- return
- }
- }
- fmt.Println("add index success:" + indexCode)
- //刷新指标
- method = "mysteel_chemical/refresh"
- refreshMap := make(map[string]interface{})
- refreshMap["EdbInfoId"] = indexResp.Data.EdbInfoId
- refreshMap["EdbCode"] = indexCode
- refreshMap["StartDate"] = "1990-01-01"
- PostEdbLib(refreshMap, method)
- } else {
- fmt.Println("data is empty")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- }
- }
- }
- }
- // 初始化基础指标数据-有色
- func InitBaseIndexDataFromDataSourceSmm(filePath string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("InitBaseIndexDataFromDataSourceSmm Err:" + err.Error())
- utils.FileLog.Info("InitBaseIndexDataFromDataSourceSmm Err:" + err.Error())
- }
- }()
- //读取excel
- path, err := filepath.Abs(os.Args[0])
- if err != nil {
- fmt.Println(err)
- }
- dir := filepath.Dir(path)
- fmt.Println("dir:" + dir)
- dataPath := dir + filePath
- fmt.Println("dataPath:" + dataPath)
- f, err := excelize.OpenFile(dataPath)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer func() {
- // Close the spreadsheet.
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
- rows, err := f.GetRows("Sheet1")
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("rows len:", len(rows))
- // 获取创建人信息
- mobileMap := make(map[string]*models.Admin)
- if utils.MYSQL_URL_ETA != "" {
- admins, e := models.GetSysAdminList(``, make([]interface{}, 0))
- if e != nil {
- err = fmt.Errorf("GetSysAdminList err: %s", e.Error())
- return
- }
- for _, v := range admins {
- if v.Mobile == "" {
- continue
- }
- mobileMap[v.Mobile] = v
- }
- }
- for rk, row := range rows {
- if rk > 0 {
- var classifyFirst, classifySecond, classifyThree, classifyFourth, classifyFifth, classifySixth, indexCode, indexName, frequency, unit, source, mobile string
- for ck, colCell := range row {
- colCell = strings.TrimSpace(colCell)
- switch ck {
- case 0:
- classifyFirst = colCell
- case 1:
- classifySecond = colCell
- case 2:
- classifyThree = colCell
- case 3:
- classifyFourth = colCell
- case 4:
- classifyFifth = colCell
- case 5:
- classifySixth = colCell
- case 6:
- indexCode = colCell
- case 7:
- indexName = colCell
- case 8:
- frequency = colCell
- case 9:
- unit = colCell
- case 10:
- source = colCell
- case 11:
- mobile = colCell
- }
- }
- if classifyFirst != "" &&
- indexCode != "" &&
- indexName != "" &&
- unit != "" &&
- frequency != "" &&
- source != "" {
- //判断指标是否存在
- method := "smm/index_detail/from_data_source"
- indexSearchMap := make(map[string]interface{})
- indexSearchMap["IndexCode"] = indexCode
- indexResult, e := PostEdbLib(indexSearchMap, method)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- smmIndexResp := new(models.BaseFromSmmIndexResp)
- e = json.Unmarshal(indexResult, &smmIndexResp)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- if smmIndexResp.Ret != 200 {
- fmt.Println("判断指标是否存在失败,Err:" + smmIndexResp.ErrMsg)
- //utils.FileLog.Info("判断指标是否存在失败:" + err.Error())
- //return
- continue
- }
- if smmIndexResp.Data.BaseFromSmmIndexId <= 0 {
- fmt.Println("指标:" + indexCode + ";不存在")
- continue
- }
- var firstId, secondId, thirdId, fourthId, fifthId, lastId int
- method = "classify/get_or_add"
- classifyFirstMap := make(map[string]interface{})
- classifyFirstMap["ClassifyName"] = classifyFirst
- classifyFirstMap["ParentId"] = 0
- classifyFirstMap["Level"] = 0
- classifyFirstMap["ClassifyType"] = 0
- result, e := PostEdbLib(classifyFirstMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFirst PostEdbLib err: %s", e.Error())
- return
- }
- resp := new(models.ClassifyResp)
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("ClassifyFirst json unmarshal err: %s", e.Error())
- return
- }
- if resp.Ret != 200 {
- err = fmt.Errorf("ClassifyFirst resp msg: %s; errMsg: %s", resp.Msg, resp.ErrMsg)
- return
- }
- firstId = resp.Data.ClassifyId
- lastId = firstId
- // 二级分类
- if classifySecond != "" {
- classifySecondMap := make(map[string]interface{})
- classifySecondMap["ClassifyName"] = classifySecond
- classifySecondMap["ParentId"] = firstId
- classifySecondMap["Level"] = 1
- classifySecondMap["ClassifyType"] = 0
- res2, e := PostEdbLib(classifySecondMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySecond PostEdbLib err: %s", e.Error())
- return
- }
- resp2 := new(models.ClassifyResp)
- if e = json.Unmarshal(res2, &resp2); e != nil {
- err = fmt.Errorf("ClassifySecond json unmarshal err: %s", e.Error())
- return
- }
- if resp2.Ret != 200 {
- err = fmt.Errorf("ClassifySecond resp msg: %s; errMsg: %s", resp2.Msg, resp2.ErrMsg)
- return
- }
- secondId = resp2.Data.ClassifyId
- lastId = secondId
- }
- // 三级分类
- if classifyThree != "" {
- classifyThreeMap := make(map[string]interface{})
- classifyThreeMap["ClassifyName"] = classifyThree
- classifyThreeMap["ParentId"] = secondId
- classifyThreeMap["Level"] = 2
- classifyThreeMap["ClassifyType"] = 0
- res3, e := PostEdbLib(classifyThreeMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyThird PostEdbLib err: %s", e.Error())
- return
- }
- resp3 := new(models.ClassifyResp)
- if e = json.Unmarshal(res3, &resp3); e != nil {
- err = fmt.Errorf("ClassifyThird json unmarshal err: %s", e.Error())
- return
- }
- if resp3.Ret != 200 {
- err = fmt.Errorf("ClassifyThird resp msg: %s; errMsg: %s", resp3.Msg, resp3.ErrMsg)
- return
- }
- thirdId = resp3.Data.ClassifyId
- lastId = thirdId
- }
- // 四级分类
- if classifyFourth != "" {
- classifyFourthMap := make(map[string]interface{})
- classifyFourthMap["ClassifyName"] = classifyFourth
- classifyFourthMap["ParentId"] = thirdId
- classifyFourthMap["Level"] = 3
- classifyFourthMap["ClassifyType"] = 0
- res4, e := PostEdbLib(classifyFourthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFourth PostEdbLib err: %s", e.Error())
- return
- }
- resp4 := new(models.ClassifyResp)
- if e = json.Unmarshal(res4, &resp4); e != nil {
- err = fmt.Errorf("ClassifyFourth json unmarshal err: %s", e.Error())
- return
- }
- if resp4.Ret != 200 {
- err = fmt.Errorf("ClassifyFourth resp msg: %s; errMsg: %s", resp4.Msg, resp4.ErrMsg)
- return
- }
- fourthId = resp4.Data.ClassifyId
- lastId = fourthId
- }
- // 五级分类
- if classifyFifth != "" {
- classifyFifthMap := make(map[string]interface{})
- classifyFifthMap["ClassifyName"] = classifyFifth
- classifyFifthMap["ParentId"] = fourthId
- classifyFifthMap["Level"] = 4
- classifyFifthMap["ClassifyType"] = 0
- res5, e := PostEdbLib(classifyFifthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFifth PostEdbLib err: %s", e.Error())
- return
- }
- resp5 := new(models.ClassifyResp)
- if e = json.Unmarshal(res5, &resp5); e != nil {
- err = fmt.Errorf("ClassifyFifth json unmarshal err: %s", e.Error())
- return
- }
- if resp5.Ret != 200 {
- err = fmt.Errorf("ClassifyFifth resp msg: %s; errMsg: %s", resp5.Msg, resp5.ErrMsg)
- return
- }
- fifthId = resp5.Data.ClassifyId
- lastId = fifthId
- }
- // 六级分类
- if classifySixth != "" {
- classifySixthMap := make(map[string]interface{})
- classifySixthMap["ClassifyName"] = classifySixth
- classifySixthMap["ParentId"] = fifthId
- classifySixthMap["Level"] = 5
- classifySixthMap["ClassifyType"] = 0
- res6, e := PostEdbLib(classifySixthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySixth PostEdbLib err: %s", e.Error())
- return
- }
- resp6 := new(models.ClassifyResp)
- if e = json.Unmarshal(res6, &resp6); e != nil {
- err = fmt.Errorf("ClassifySixth json unmarshal err: %s", e.Error())
- return
- }
- if resp6.Ret != 200 {
- err = fmt.Errorf("ClassifySixth resp msg: %s; errMsg: %s", resp6.Msg, resp6.ErrMsg)
- return
- }
- lastId = resp6.Data.ClassifyId
- }
- method = "edb_info/add"
- indexMap := make(map[string]interface{})
- indexMap["Source"] = IndexSourceMap[source]
- indexMap["EdbCode"] = indexCode
- indexMap["EdbName"] = indexName
- indexMap["Frequency"] = frequency
- indexMap["Unit"] = unit
- indexMap["ClassifyId"] = lastId
- admin := mobileMap[mobile]
- if admin != nil {
- indexMap["AdminId"] = admin.AdminId
- indexMap["AdminName"] = admin.RealName
- }
- result, err = PostEdbLib(indexMap, method)
- if err != nil {
- utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
- return
- }
- indexResp := new(models.EdbInfoResp)
- err = json.Unmarshal(result, &indexResp)
- if err != nil {
- utils.FileLog.Info("初始化分类2失败:" + err.Error())
- return
- }
- if indexResp.Ret != 200 {
- if strings.Contains(indexResp.Msg, "新增指标失败") {
- continue
- } else {
- fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- return
- }
- }
- fmt.Println("add index success:" + indexCode)
- //刷新指标
- {
- refreshMethod := "smm/refresh"
- refreshMap := make(map[string]interface{})
- refreshMap["EdbInfoId"] = indexResp.Data.EdbInfoId
- refreshMap["EdbCode"] = indexCode
- refreshMap["StartDate"] = "1990-01-01"
- PostEdbLib(refreshMap, refreshMethod)
- }
- } else {
- fmt.Println("data is empty")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- }
- }
- }
- }
- // InitDataToEdbInfo
- // @Description: 添加指标到指标库
- // @author: Roc
- // @datetime 2024-01-15 14:12:12
- // @param filePath string
- func InitDataToEdbInfo(filePath string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("InitDataToEdbInfo Err:" + err.Error())
- utils.FileLog.Info("InitDataToEdbInfo Err:" + err.Error())
- }
- }()
- //读取excel
- path, err := filepath.Abs(os.Args[0])
- if err != nil {
- fmt.Println(err)
- }
- dir := filepath.Dir(path)
- fmt.Println("dir:" + dir)
- dataPath := dir + filePath
- fmt.Println("dataPath:" + dataPath)
- f, err := excelize.OpenFile(dataPath)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer func() {
- // Close the spreadsheet.
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
- rows, err := f.GetRows("Sheet1")
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("rows len:", len(rows))
- // 获取创建人信息
- mobileMap := make(map[string]*models.Admin)
- if utils.MYSQL_URL_ETA != "" {
- admins, e := models.GetSysAdminList(``, make([]interface{}, 0))
- if e != nil {
- err = fmt.Errorf("GetSysAdminList err: %s", e.Error())
- return
- }
- for _, v := range admins {
- if v.Mobile == "" {
- continue
- }
- mobileMap[v.Mobile] = v
- }
- }
- for rk, row := range rows {
- if rk > 0 {
- var classifyFirst, classifySecond, classifyThree, classifyFourth, classifyFifth, classifySixth, indexCode, indexName, frequency, unit, source, mobile, terminalCode string
- for ck, colCell := range row {
- colCell = strings.TrimSpace(colCell)
- switch ck {
- case 0:
- classifyFirst = colCell
- case 1:
- classifySecond = colCell
- case 2:
- classifyThree = colCell
- case 3:
- classifyFourth = colCell
- case 4:
- classifyFifth = colCell
- case 5:
- classifySixth = colCell
- case 6:
- indexCode = colCell
- case 7:
- indexName = colCell
- case 8:
- frequency = colCell
- case 9:
- unit = colCell
- case 10:
- source = colCell
- case 11:
- mobile = colCell
- case 12:
- terminalCode = colCell
- }
- }
- // 校验excel文件内容
- {
- errMsgList := make([]string, 0)
- if classifyFirst == "" {
- errMsgList = append(errMsgList, `一级目录不允许为空`)
- }
- if indexCode == "" {
- errMsgList = append(errMsgList, `指标编码不允许为空`)
- }
- if indexName == "" {
- errMsgList = append(errMsgList, `指标名称不允许为空`)
- }
- if frequency == "" {
- errMsgList = append(errMsgList, `频度不允许为空`)
- }
- if unit == "" {
- errMsgList = append(errMsgList, `单位不允许为空`)
- }
- if source == "" {
- errMsgList = append(errMsgList, `指标来源不允许为空`)
- }
- if terminalCode == "" {
- errMsgList = append(errMsgList, `终端号不允许为空`)
- }
- // 如果有错误信息,那么就不继续执行
- if len(errMsgList) > 0 {
- fmt.Println(strings.Join(errMsgList, ";"))
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source, terminalCode)
- continue
- }
- }
- // 开始入库
- {
- //判断指标是否存在
- switch source {
- case "钢联":
- ok, e := VerifyMysteelIndex(indexCode)
- if e != nil {
- fmt.Println(indexCode, ";判断指标是否存在失败,Err:"+e.Error())
- continue
- }
- if !ok {
- fmt.Println("指标:" + indexCode + ";不存在")
- continue
- }
- case "SMM":
- ok, e := VerifySmmIndex(indexCode)
- if e != nil {
- fmt.Println(indexCode, ";判断指标是否存在失败,Err:"+e.Error())
- continue
- }
- if !ok {
- fmt.Println("指标:" + indexCode + ";不存在")
- continue
- }
- }
- var firstId, secondId, thirdId, fourthId, fifthId, lastId int
- method := "classify/get_or_add"
- classifyFirstMap := make(map[string]interface{})
- classifyFirstMap["ClassifyName"] = classifyFirst
- classifyFirstMap["ParentId"] = 0
- classifyFirstMap["Level"] = 0
- classifyFirstMap["ClassifyType"] = 0
- result, e := PostEdbLib(classifyFirstMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFirst PostEdbLib err: %s", e.Error())
- return
- }
- resp := new(models.ClassifyResp)
- if e = json.Unmarshal(result, &resp); e != nil {
- err = fmt.Errorf("ClassifyFirst json unmarshal err: %s", e.Error())
- return
- }
- if resp.Ret != 200 {
- err = fmt.Errorf("ClassifyFirst resp msg: %s; errMsg: %s", resp.Msg, resp.ErrMsg)
- return
- }
- firstId = resp.Data.ClassifyId
- lastId = firstId
- // 二级分类
- if classifySecond != "" {
- classifySecondMap := make(map[string]interface{})
- classifySecondMap["ClassifyName"] = classifySecond
- classifySecondMap["ParentId"] = firstId
- classifySecondMap["Level"] = 1
- classifySecondMap["ClassifyType"] = 0
- res2, e := PostEdbLib(classifySecondMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySecond PostEdbLib err: %s", e.Error())
- return
- }
- resp2 := new(models.ClassifyResp)
- if e = json.Unmarshal(res2, &resp2); e != nil {
- err = fmt.Errorf("ClassifySecond json unmarshal err: %s", e.Error())
- return
- }
- if resp2.Ret != 200 {
- err = fmt.Errorf("ClassifySecond resp msg: %s; errMsg: %s", resp2.Msg, resp2.ErrMsg)
- return
- }
- secondId = resp2.Data.ClassifyId
- lastId = secondId
- }
- // 三级分类
- if classifyThree != "" {
- classifyThreeMap := make(map[string]interface{})
- classifyThreeMap["ClassifyName"] = classifyThree
- classifyThreeMap["ParentId"] = secondId
- classifyThreeMap["Level"] = 2
- classifyThreeMap["ClassifyType"] = 0
- res3, e := PostEdbLib(classifyThreeMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyThird PostEdbLib err: %s", e.Error())
- return
- }
- resp3 := new(models.ClassifyResp)
- if e = json.Unmarshal(res3, &resp3); e != nil {
- err = fmt.Errorf("ClassifyThird json unmarshal err: %s", e.Error())
- return
- }
- if resp3.Ret != 200 {
- err = fmt.Errorf("ClassifyThird resp msg: %s; errMsg: %s", resp3.Msg, resp3.ErrMsg)
- return
- }
- thirdId = resp3.Data.ClassifyId
- lastId = thirdId
- }
- // 四级分类
- if classifyFourth != "" {
- classifyFourthMap := make(map[string]interface{})
- classifyFourthMap["ClassifyName"] = classifyFourth
- classifyFourthMap["ParentId"] = thirdId
- classifyFourthMap["Level"] = 3
- classifyFourthMap["ClassifyType"] = 0
- res4, e := PostEdbLib(classifyFourthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFourth PostEdbLib err: %s", e.Error())
- return
- }
- resp4 := new(models.ClassifyResp)
- if e = json.Unmarshal(res4, &resp4); e != nil {
- err = fmt.Errorf("ClassifyFourth json unmarshal err: %s", e.Error())
- return
- }
- if resp4.Ret != 200 {
- err = fmt.Errorf("ClassifyFourth resp msg: %s; errMsg: %s", resp4.Msg, resp4.ErrMsg)
- return
- }
- fourthId = resp4.Data.ClassifyId
- lastId = fourthId
- }
- // 五级分类
- if classifyFifth != "" {
- classifyFifthMap := make(map[string]interface{})
- classifyFifthMap["ClassifyName"] = classifyFifth
- classifyFifthMap["ParentId"] = fourthId
- classifyFifthMap["Level"] = 4
- classifyFifthMap["ClassifyType"] = 0
- res5, e := PostEdbLib(classifyFifthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifyFifth PostEdbLib err: %s", e.Error())
- return
- }
- resp5 := new(models.ClassifyResp)
- if e = json.Unmarshal(res5, &resp5); e != nil {
- err = fmt.Errorf("ClassifyFifth json unmarshal err: %s", e.Error())
- return
- }
- if resp5.Ret != 200 {
- err = fmt.Errorf("ClassifyFifth resp msg: %s; errMsg: %s", resp5.Msg, resp5.ErrMsg)
- return
- }
- fifthId = resp5.Data.ClassifyId
- lastId = fifthId
- }
- // 六级分类
- if classifySixth != "" {
- classifySixthMap := make(map[string]interface{})
- classifySixthMap["ClassifyName"] = classifySixth
- classifySixthMap["ParentId"] = fifthId
- classifySixthMap["Level"] = 5
- classifySixthMap["ClassifyType"] = 0
- res6, e := PostEdbLib(classifySixthMap, method)
- if e != nil {
- err = fmt.Errorf("ClassifySixth PostEdbLib err: %s", e.Error())
- return
- }
- resp6 := new(models.ClassifyResp)
- if e = json.Unmarshal(res6, &resp6); e != nil {
- err = fmt.Errorf("ClassifySixth json unmarshal err: %s", e.Error())
- return
- }
- if resp6.Ret != 200 {
- err = fmt.Errorf("ClassifySixth resp msg: %s; errMsg: %s", resp6.Msg, resp6.ErrMsg)
- return
- }
- lastId = resp6.Data.ClassifyId
- }
- // 添加指标
- method = "edb_info/add"
- sourceId, ok := IndexSourceMap[source]
- if !ok {
- fmt.Println("source is not defined")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- continue
- }
- indexMap := make(map[string]interface{})
- indexMap["Source"] = sourceId
- indexMap["EdbCode"] = indexCode
- indexMap["EdbName"] = indexName
- indexMap["Frequency"] = frequency
- indexMap["Unit"] = unit
- indexMap["ClassifyId"] = lastId
- indexMap["TerminalCode"] = terminalCode
- admin := mobileMap[mobile]
- if admin != nil {
- indexMap["AdminId"] = admin.AdminId
- indexMap["AdminName"] = admin.RealName
- }
- result, err = PostEdbLib(indexMap, method)
- if err != nil {
- utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
- return
- }
- indexResp := new(models.EdbInfoResp)
- err = json.Unmarshal(result, &indexResp)
- if err != nil {
- utils.FileLog.Info("初始化分类2失败:" + err.Error())
- return
- }
- if indexResp.Ret != 200 {
- if strings.Contains(indexResp.Msg, "新增指标失败") {
- continue
- } else {
- fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- return
- }
- }
- fmt.Println("add index success:" + indexCode)
- //刷新指标
- method, ok = IndexSourceRefreshMap[sourceId]
- if !ok {
- fmt.Println("source refresh path is not defined")
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
- continue
- }
- refreshMap := make(map[string]interface{})
- refreshMap["EdbInfoId"] = indexResp.Data.EdbInfoId
- refreshMap["EdbCode"] = indexCode
- refreshMap["StartDate"] = "1990-01-01"
- PostEdbLib(refreshMap, method)
- }
- }
- }
- }
- // VerifyMysteelIndex
- // @Description: 判断钢联指标编码是否已经入库
- // @author: Roc
- // @datetime 2024-01-15 13:54:48
- // @param indexCode string
- // @return ok bool
- // @return err error
- func VerifyMysteelIndex(indexCode string) (ok bool, err error) {
- //判断指标是否存在
- method := "mysteel_chemical/index_detail"
- indexSearchMap := make(map[string]interface{})
- indexSearchMap["IndexCode"] = indexCode
- indexResult, e := PostEdbLib(indexSearchMap, method)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- mysteelIndexResp := new(models.MysteelIndexResp)
- e = json.Unmarshal(indexResult, &mysteelIndexResp)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- if mysteelIndexResp.Ret != 200 {
- err = errors.New("判断指标是否存在失败,Err:" + mysteelIndexResp.ErrMsg)
- return
- }
- if mysteelIndexResp.Data.BaseFromMysteelChemicalIndexId <= 0 {
- fmt.Println("指标:" + indexCode + ";不存在")
- return
- }
- ok = true
- return
- }
- // VerifySmmIndex
- // @Description: 判断有色指标编码是否已经入库
- // @author: Roc
- // @datetime 2024-01-15 13:54:48
- // @param indexCode string
- // @return ok bool
- // @return err error
- func VerifySmmIndex(indexCode string) (ok bool, err error) {
- //判断指标是否存在
- method := "smm/index_detail/from_data_source"
- indexSearchMap := make(map[string]interface{})
- indexSearchMap["IndexCode"] = indexCode
- indexResult, e := PostEdbLib(indexSearchMap, method)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- smmIndexResp := new(models.BaseFromSmmIndexResp)
- e = json.Unmarshal(indexResult, &smmIndexResp)
- if e != nil {
- err = fmt.Errorf("判断指标是否存在失败, Err: %s", e.Error())
- return
- }
- if smmIndexResp.Ret != 200 {
- err = errors.New("判断指标是否存在失败,Err:" + smmIndexResp.ErrMsg)
- return
- }
- if smmIndexResp.Data.BaseFromSmmIndexId <= 0 {
- //fmt.Println("指标:" + indexCode + ";不存在")
- return
- }
- ok = true
- return
- }
|