Pārlūkot izejas kodu

fix:添加到指标库的接口统一掉,钢联、有色的跟同花顺走同一个接口;
模板文件统一掉

Roc 1 gadu atpakaļ
vecāks
revīzija
d2c0a0e34a

+ 35 - 3
controllers/data_init.go

@@ -7,11 +7,13 @@ import (
 	beego "github.com/beego/beego/v2/server/web"
 )
 
+// DataInitController
 // Operations about Users
 type DataInitController struct {
 	beego.Controller
 }
 
+// Base
 // @Title 初始化基础指标数据-不包含钢联化工的基础指标初始化
 // @Description 初始化基础指标数据-不包含钢联化工的基础指标初始化
 // @Param   FileName    query   string true       "文件名称"
@@ -37,12 +39,13 @@ func (this *DataInitController) Base() {
 	br.Msg = "初始化成功"
 }
 
-// @Title 初始化联化工指标
-// @Description 初始化联化工指标
+// MySteelChemicalToSource
+// @Title 初始化联化工指标(添加到数据源)
+// @Description 初始化联化工指标(添加到数据源)
 // @Param   FileName    query   string true       "文件名称"
 // @Success Ret=200
 // @router /mysteel_chemical [get]
-func (this *DataInitController) MySteelChemical() {
+func (this *DataInitController) MySteelChemicalToSource() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -62,6 +65,7 @@ func (this *DataInitController) MySteelChemical() {
 	br.Msg = "初始化成功"
 }
 
+// MySteelChemicalBase
 // @Title 初始化钢联化工数据-由数据源批量初始化到指标库
 // @Description 初始化钢联化工数据-由数据源批量初始化到指标库
 // @Param   FileName    query   string true       "文件名称"
@@ -87,6 +91,7 @@ func (this *DataInitController) MySteelChemicalBase() {
 	br.Msg = "初始化成功"
 }
 
+// SmmToDataSource
 // @Title 初始化有色指标到数据源
 // @Description 初始化有色指标到数据源
 // @Param   FileName    query   string true       "文件名称"
@@ -112,6 +117,7 @@ func (this *DataInitController) SmmToDataSource() {
 	br.Msg = "初始化成功"
 }
 
+// SmmToIndexLib
 // @Title 初始化有色指标-由数据源批量初始化到指标库
 // @Description 初始化有色指标-由数据源批量初始化到指标库
 // @Param   FileName    query   string true       "文件名称"
@@ -162,3 +168,29 @@ func (this *DataInitController) BaseJiaYue() {
 	br.Ret = 200
 	br.Msg = "初始化成功"
 }
+
+// AddToEdbInfo
+// @Title 初始化指标到指标库-(如果需要添加数据源的指标(钢联、有色),那么需要先执行到添加到数据源,再添加到指标库)
+// @Description 初始化指标到指标库-(如果需要添加数据源的指标(钢联、有色),那么需要先执行到添加到数据源,再添加到指标库)
+// @Param   FileName    query   string true       "文件名称"
+// @Success Ret=200
+// @router /base/edb_info/add [get]
+func (this *DataInitController) AddToEdbInfo() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	fileName := this.GetString("FileName")
+	if fileName == "" {
+		br.Msg = "文件名称不能为空"
+		return
+	}
+
+	filePath := "/docs/" + fileName
+	fmt.Println("filePath:" + filePath)
+	services.InitDataToEdbInfo(filePath)
+	br.Ret = 200
+	br.Msg = "初始化成功"
+}

BIN
docs/ETA基础指标0821整理.xlsx


BIN
docs/ETA数据库目录配置.xlsx


BIN
docs/ETA计算指标0821整理.xlsx


BIN
docs/数据录入到数据源(有色).xlsx


BIN
docs/数据录入到数据源(钢联).xlsx


BIN
docs/数据录入指标库.xlsx


BIN
docs/逸诺Wind数据录入.xlsx


BIN
docs/逸诺初始化数据示例.xlsx


BIN
docs/逸诺指标库(基础).xlsx


BIN
docs/逸诺新增钢联数据列表.xlsx


BIN
docs/逸诺钢联数据录入.xlsx


+ 10 - 1
routers/commentsRouter.go

@@ -25,6 +25,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"] = append(beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"],
+        beego.ControllerComments{
+            Method: "AddToEdbInfo",
+            Router: `/base/edb_info/add`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"] = append(beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"],
         beego.ControllerComments{
             Method: "BaseJiaYue",
@@ -36,7 +45,7 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"] = append(beego.GlobalControllerRouter["eta/eta_data_init/controllers:DataInitController"],
         beego.ControllerComments{
-            Method: "MySteelChemical",
+            Method: "MySteelChemicalToSource",
             Router: `/mysteel_chemical`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),

+ 428 - 10
services/init_base_index.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"encoding/json"
+	"errors"
 	"eta/eta_data_init/models"
 	"eta/eta_data_init/utils"
 	"fmt"
@@ -974,23 +975,440 @@ func InitBaseIndexDataFromDataSourceSmm(filePath string) {
 	}
 }
 
-/*
-// PostEdbLib 调用指标接口
-func PostEdbLib(param map[string]interface{}, method string) (resp *models.BaseResponse, err error) {
-	postUrl := utils.EDB_LIB_URL + method
-	postData, err := json.Marshal(param)
+// 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 {
-		return
+		fmt.Println(err)
 	}
-	result, err := HttpPost(postUrl, string(postData), "application/json")
+
+	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
 	}
-	err = json.Unmarshal(result, &resp)
+	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
 	}
-	return resp, nil
+	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
+}

+ 2 - 1
services/init_mysteel_index.go

@@ -11,7 +11,8 @@ import (
 	"strings"
 )
 
-// InitMysteelIndex 初始化钢联化工指标数据
+// InitMysteelChemicalIndex
+// 初始化钢联化工指标数据(添加到数据源)
 func InitMysteelChemicalIndex(filePath string) {
 	var err error
 

+ 11 - 0
services/task.go

@@ -7,6 +7,16 @@ import (
 
 var IndexSourceMap map[string]int
 
+// IndexSourceRefreshMap 指标刷新地址的map
+var IndexSourceRefreshMap = map[int]string{
+	utils.DATA_SOURCE_THS:              "ths/refresh",
+	utils.DATA_SOURCE_WIND:             "wind/refresh",
+	utils.DATA_SOURCE_PB:               "pb/refresh",
+	utils.DATA_SOURCE_LT:               "lt/refresh",
+	utils.DATA_SOURCE_MYSTEEL_CHEMICAL: "mysteel_chemical/refresh",
+	utils.DATA_SOURCE_YS:               "smm/refresh",
+}
+
 func Task() {
 	fmt.Println("task start")
 	//path, err := filepath.Abs(os.Args[0])
@@ -21,6 +31,7 @@ func Task() {
 	IndexSourceMap["ths"] = utils.DATA_SOURCE_THS
 	IndexSourceMap["同花顺"] = utils.DATA_SOURCE_THS
 	IndexSourceMap["wind"] = utils.DATA_SOURCE_WIND
+	IndexSourceMap["万得"] = utils.DATA_SOURCE_WIND
 	IndexSourceMap["钢联"] = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
 	IndexSourceMap["彭博"] = utils.DATA_SOURCE_PB
 	IndexSourceMap["SMM"] = utils.DATA_SOURCE_YS