12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463 |
- 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)
- emailMap := 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 != "" {
- mobileMap[v.Mobile] = v
- }
- if v.Email != "" {
- emailMap[v.Email] = 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
- }
- // 先匹配下手机号, 没有则匹配下邮箱
- if admin == nil && emailMap[mobile] != nil {
- indexMap["AdminId"] = emailMap[mobile].AdminId
- indexMap["AdminName"] = emailMap[mobile].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)
- emailMap := 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 != "" {
- mobileMap[v.Mobile] = v
- }
- if v.Email != "" {
- emailMap[v.Email] = 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
- }
- // 先匹配下手机号, 没有则匹配下邮箱
- if admin == nil && emailMap[mobile] != nil {
- indexMap["AdminId"] = emailMap[mobile].AdminId
- indexMap["AdminName"] = emailMap[mobile].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)
- emailMap := 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 != "" {
- mobileMap[v.Mobile] = v
- }
- if v.Email != "" {
- emailMap[v.Email] = 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
- }
- // 先匹配下手机号, 没有则匹配下邮箱
- if admin == nil && emailMap[mobile] != nil {
- indexMap["AdminId"] = emailMap[mobile].AdminId
- indexMap["AdminName"] = emailMap[mobile].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)
- emailMap := 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 != "" {
- mobileMap[v.Mobile] = v
- }
- if v.Email != "" {
- emailMap[v.Email] = v
- }
- }
- }
- //successIndexList := make([]string, 0)
- errorIndexList := make([]string, 0)
- 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文件内容
- {
- tmpErrMsgList := make([]string, 0)
- if classifyFirst == "" {
- tmpErrMsgList = append(tmpErrMsgList, `一级目录不允许为空`)
- }
- if indexCode == "" {
- tmpErrMsgList = append(tmpErrMsgList, `指标编码不允许为空`)
- }
- if indexName == "" {
- tmpErrMsgList = append(tmpErrMsgList, `指标名称不允许为空`)
- }
- if frequency == "" {
- tmpErrMsgList = append(tmpErrMsgList, `频度不允许为空`)
- }
- if unit == "" {
- tmpErrMsgList = append(tmpErrMsgList, `单位不允许为空`)
- }
- if source == "" {
- tmpErrMsgList = append(tmpErrMsgList, `指标来源不允许为空`)
- }
- if terminalCode == "" {
- tmpErrMsgList = append(tmpErrMsgList, `终端号不允许为空`)
- }
- // 如果有错误信息,那么就不继续执行
- if len(tmpErrMsgList) > 0 {
- fmt.Println(strings.Join(tmpErrMsgList, ";"))
- fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source, terminalCode)
- continue
- }
- }
- // 开始入库
- {
- // 如果频度只有年月日这种,并没有度,那么需要补充
- if !strings.Contains(frequency, "度") {
- frequency = frequency + "度"
- }
- //判断指标是否存在
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst PostEdbLib err: %s", indexCode, e.Error()))
- continue
- }
- resp := new(models.ClassifyResp)
- if e = json.Unmarshal(result, &resp); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst resp msg: %s; errMsg: %s", indexCode, resp.Msg, resp.ErrMsg))
- continue
- }
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond PostEdbLib err: %s", indexCode, e.Error()))
- continue
- }
- resp2 := new(models.ClassifyResp)
- if e = json.Unmarshal(res2, &resp2); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp2.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond resp msg: %s; errMsg: %s", indexCode, resp2.Msg, resp2.ErrMsg))
- continue
- }
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond ClassifyThird err: %s", indexCode, e.Error()))
- continue
- }
- resp3 := new(models.ClassifyResp)
- if e = json.Unmarshal(res3, &resp3); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyThird json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp3.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyThird resp msg: %s; errMsg: %s", indexCode, resp3.Msg, resp3.ErrMsg))
- continue
- }
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth ClassifyThird err: %s", indexCode, e.Error()))
- continue
- }
- resp4 := new(models.ClassifyResp)
- if e = json.Unmarshal(res4, &resp4); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp4.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth resp msg: %s; errMsg: %s", indexCode, resp4.Msg, resp4.ErrMsg))
- continue
- }
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth ClassifyThird err: %s", indexCode, e.Error()))
- continue
- }
- resp5 := new(models.ClassifyResp)
- if e = json.Unmarshal(res5, &resp5); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp5.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth resp msg: %s; errMsg: %s", indexCode, resp5.Msg, resp5.ErrMsg))
- continue
- }
- 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 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth ClassifyThird err: %s", indexCode, e.Error()))
- continue
- }
- resp6 := new(models.ClassifyResp)
- if e = json.Unmarshal(res6, &resp6); e != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth json unmarshal err: %s", indexCode, e.Error()))
- continue
- }
- if resp6.Ret != 200 {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth resp msg: %s; errMsg: %s", indexCode, resp6.Msg, resp6.ErrMsg))
- continue
- }
- lastId = resp6.Data.ClassifyId
- }
- // 添加指标
- method = "edb_info/add"
- sourceId, ok := IndexSourceMap[source]
- if !ok {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,来源未定义:%s", indexCode, 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
- }
- // 先匹配下手机号, 没有则匹配下邮箱
- if admin == nil && emailMap[mobile] != nil {
- indexMap["AdminId"] = emailMap[mobile].AdminId
- indexMap["AdminName"] = emailMap[mobile].RealName
- }
- result, err = PostEdbLib(indexMap, method)
- if err != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标失败:%s ;result:%s", indexCode, err.Error(), string(result)))
- utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
- continue
- }
- indexResp := new(models.EdbInfoResp)
- err = json.Unmarshal(result, &indexResp)
- if err != nil {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标2失败:%s", indexCode, err.Error()))
- utils.FileLog.Info("初始化指标2失败:" + err.Error())
- continue
- }
- if indexResp.Ret != 200 {
- if strings.Contains(indexResp.Msg, "新增指标失败") {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标3失败:%s;%s", indexCode, indexResp.Msg, indexResp.ErrMsg))
- utils.FileLog.Info("初始化指标3失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- continue
- } else {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标3失败:%s;%s", indexCode, indexResp.Msg, indexResp.ErrMsg))
- utils.FileLog.Info("初始化指标3失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
- continue
- }
- }
- fmt.Println("add index success:" + indexCode)
- //刷新指标
- method, ok = IndexSourceRefreshMap[sourceId]
- if !ok {
- errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,刷新地址未定义:%s;", indexCode, source))
- //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)
- }
- }
- }
- if len(errorIndexList) > 0 {
- fmt.Println("初始化指标失败列表:\n" + strings.Join(errorIndexList, "\n"))
- utils.FileLog.Info("初始化指标失败列表:\n" + strings.Join(errorIndexList, "\n"))
- }
- }
- // 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
- }
|