Browse Source

Merge branch 'fix/2023-8-9' into debug

Roc 1 year ago
parent
commit
ca73be8729

+ 137 - 0
controllers/edb_info.go

@@ -116,3 +116,140 @@ func (this *EdbInfoController) Add() {
 	br.Msg = "新增成功"
 	br.Data = edbInfo
 }
+
+// @Title 获取基础指标详情
+// @Description 获取基础指标详情
+// @Param	request	body models.EdbInfoDetailReq true "type json string"
+// @Success 200 {object} models.EdbInfo
+// @router /detail [post]
+func (this *EdbInfoController) EdbIndexDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.EdbInfoDetailReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		return
+	}
+	detail, err := models.GetEdbInfoOnlyByEdbCode(req.EdbCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "指标数据不存在!"
+			br.ErrMsg = "指标数据不存在,Err:" + err.Error()
+			br.ErrCode = "400"
+			return
+		}
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = detail
+}
+
+// @Title 复制新增来自弘则的指标接口
+// @Description  复制新增来自弘则的指标接口
+// @Success 200 {object} models.EdbInfo
+// @router /copy/from/hz [post]
+func (this *EdbInfoController) CopyFromHz() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	req := new(models.EdbInfo)
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	deleteCache := true
+	cacheKey = "CACHE_EDB_INFO_COPY_FROM_HZ_" + req.EdbCode
+	defer func() {
+		if deleteCache {
+			utils.Rc.Delete(cacheKey)
+		}
+	}()
+	if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
+		deleteCache = false
+		br.Msg = "系统处理中,请稍后重试!"
+		br.ErrMsg = "系统处理中,请稍后重试!"
+		return
+	}
+
+	if req.ClassifyId <= 0 {
+		br.Msg = "请输入指标分类!"
+		br.ErrMsg = "请输入指标分类"
+		return
+	}
+	if req.Source <= 0 {
+		br.Msg = "请输入指标来源!"
+		br.ErrMsg = "请输入指标来源"
+		return
+	}
+	if req.EdbName == "" {
+		br.Msg = "请输入指标名称!"
+		br.ErrMsg = "请输入指标名称"
+		return
+	}
+	if req.Frequency == "" {
+		br.Msg = "请输入指标频度!"
+		br.ErrMsg = "请输入指标频度"
+		return
+	}
+	if req.Unit == "" {
+		br.Msg = "请输入指标单位!"
+		br.ErrMsg = "请输入指标单位"
+		return
+	}
+	var isAdd bool
+	item, err := models.GetEdbInfoByEdbCode(req.Source, req.EdbCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			isAdd = true
+		} else {
+			br.Msg = "判断指标是否存在失败!"
+			br.ErrMsg = "判断指标是否存在失败"
+			return
+		}
+	}
+	if item != nil && item.EdbInfoId <= 0 {
+		isAdd = true
+	}
+	if isAdd {
+		req.EdbInfoId = 0
+		req.StartDate = "1990-01-01"
+		err = req.Add()
+		if err != nil {
+			br.Msg = "新增指标失败!"
+			br.ErrMsg = "新增指标失败"
+			return
+		}
+	}
+	edbInfo, err := models.GetEdbInfoOnlyByEdbCode(req.EdbCode)
+	// 更新ES
+	go logic.UpdateEs(edbInfo.EdbInfoId)
+	br.Ret = 200
+	br.Msg = "新增成功"
+	br.Data = edbInfo
+}

+ 79 - 0
controllers/edb_info_calculate_mapping.go

@@ -0,0 +1,79 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_edb_lib/models"
+	"hongze/hongze_edb_lib/utils"
+	"time"
+)
+
+// 计算指标
+type EdbInfoCalculateController struct {
+	BaseAuthController
+}
+
+// @Title 复制新增来自弘则的计算指标接口
+// @Description  复制新增来自弘则的计算指标接口
+// @Success 200 {object} models.EdbInfoCalculateMapping
+// @router /copy/calculate/from/hz [post]
+func (this *EdbInfoController) CopyCalculateFromHz() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	req := new(models.EdbInfoCalculateMapping)
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	deleteCache := true
+	cacheKey = "CACHE_EDB_INFO_COPY_CALCULATE_FROM_HZ_" + req.EdbCode
+	defer func() {
+		if deleteCache {
+			utils.Rc.Delete(cacheKey)
+		}
+	}()
+	if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
+		deleteCache = false
+		br.Msg = "系统处理中,请稍后重试!"
+		br.ErrMsg = "系统处理中,请稍后重试!"
+		return
+	}
+
+	var isAdd bool
+	item, err := models.GetEdbInfoCalculateByEdbCode(req.EdbCode, req.FromEdbCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			isAdd = true
+		} else {
+			br.Msg = "判断指标是否存在失败!"
+			br.ErrMsg = "判断指标是否存在失败"
+			return
+		}
+	}
+	if item != nil && item.EdbInfoId <= 0 {
+		isAdd = true
+	}
+	if isAdd {
+		req.EdbInfoCalculateMappingId = 0
+		err = req.Add()
+		if err != nil {
+			br.Msg = "新增指标失败!"
+			br.ErrMsg = "新增指标失败"
+			return
+		}
+	}
+	br.Ret = 200
+	br.Msg = "新增成功"
+}

+ 15 - 8
models/edb_info.go

@@ -13,13 +13,16 @@ import (
 
 type EdbInfo struct {
 	EdbInfoId        int    `orm:"column(edb_info_id);pk"`
+	EdbInfoType      int    `description:"指标类型,0:普通指标,1:预测指标"`
 	SourceName       string `description:"来源名称"`
 	Source           int    `description:"来源id"`
 	EdbCode          string `description:"指标编码"`
 	EdbName          string `description:"指标名称"`
+	EdbNameEn        string `description:"英文指标名称"`
 	EdbNameSource    string `description:"指标名称来源"`
 	Frequency        string `description:"频率"`
 	Unit             string `description:"单位"`
+	UnitEn           string `description:"英文单位"`
 	StartDate        string `description:"起始日期"`
 	EndDate          string `description:"终止日期"`
 	ClassifyId       int    `description:"分类id"`
@@ -32,20 +35,23 @@ type EdbInfo struct {
 	MaxValue         float64 `description:"指标最大值"`
 	CalculateFormula string  `description:"计算公式"`
 	EdbType          int     `description:"指标类型:1:基础指标,2:计算指标"`
+	IsUpdate         int     `description:"当天是否已更新,1:未更新,2:已更新"`
 	Sort             int     `description:"排序字段"`
+	LatestDate       string  `description:"数据最新日期"`
+	LatestValue      float64 `description:"数据最新值"`
 	MoveType         int     `description:"移动方式:1:领先(默认),2:滞后"`
 	MoveFrequency    string  `description:"移动频度"`
 	NoUpdate         int8    `description:"是否停止更新,0:继续更新;1:停止更新"`
 	ServerUrl        string  `description:"服务器地址"`
+	ChartImage       string  `description:"图表图片"`
+	Calendar         string  `description:"公历/农历" orm:"default(公历);"`
+	DataDateType     string  `orm:"column(data_date_type);size(255);null;default(交易日)"`
+}
 
-	EdbInfoType  int     `description:"指标类型,0:普通指标,1:预测指标"`
-	EdbNameEn    string  `description:"英文指标名称"`
-	UnitEn       string  `description:"英文单位"`
-	LatestDate   string  `description:"数据最新日期"`
-	LatestValue  float64 `description:"数据最新值"`
-	ChartImage   string  `description:"图表图片"`
-	Calendar     string  `description:"公历/农历"`
-	DataDateType string  `orm:"column(data_date_type);size(255);null;default(交易日)"`
+func (e *EdbInfo) Add() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(e)
+	return
 }
 
 // AddEdbInfo 添加指标
@@ -942,6 +948,7 @@ func GetEdbInfoItemByCondition(condition string, pars []interface{}) (item *EdbI
 // EdbInfoDetailReq 指标详情请求
 type EdbInfoDetailReq struct {
 	UniqueCode string `description:"指标唯一编码"`
+	EdbCode    string `description:"指标编码"`
 }
 
 // EdbInfoDetailResp 指标详情返回

+ 17 - 2
models/edb_info_calculate_mapping.go

@@ -17,17 +17,24 @@ type EdbInfoCalculateMapping struct {
 	FromEdbName               string    `description:"基础指标名称"`
 	FromSource                int       `description:"基础指标来源"`
 	FromSourceName            string    `description:"基础指标来源名称"`
-	FromTag                   string    `description:"来源指标标签"`
 	MoveValue                 int       `description:"移动的值,小于0是提前,0是不变,大于0是滞后"`
 	Sort                      int       `description:"计算指标名称排序"`
 	CreateTime                time.Time `description:"创建时间"`
 	ModifyTime                time.Time `description:"修改时间"`
+	FromTag                   string    `description:"来源指标标签"`
 }
 
 // AddEdbInfoCalculateMappingMulti 批量添加指标关系表
 func AddEdbInfoCalculateMappingMulti(items []*EdbInfoCalculateMapping) (err error) {
 	o := orm.NewOrm()
-	_, err = o.InsertMulti(1, items)
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+// AddEdbInfoCalculateMappingMulti 批量添加指标关系表
+func (e *EdbInfoCalculateMapping) Add() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(e)
 	return
 }
 
@@ -103,3 +110,11 @@ func GetEdbInfoCalculateDetailList(edbInfoId int) (list []*EdbInfoCalculateDetai
 	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)
 	return
 }
+
+// GetEdbInfoByEdbCode 根据指标code获取指标信息
+func GetEdbInfoCalculateByEdbCode(edbCode, fromEdbCode string) (item *EdbInfoCalculateMapping, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM edb_info_calculate_mapping WHERE edb_code=? AND from_edb_code=? `
+	err = o.Raw(sql, edbCode, fromEdbCode).QueryRow(&item)
+	return
+}

+ 27 - 0
routers/commentsRouter.go

@@ -223,6 +223,33 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "CopyCalculateFromHz",
+            Router: `/copy/calculate/from/hz`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "CopyFromHz",
+            Router: `/copy/from/hz`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "EdbIndexDetail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EiaSteoController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:EiaSteoController"],
         beego.ControllerComments{
             Method: "Add",

+ 5 - 0
routers/router.go

@@ -192,6 +192,11 @@ func init() {
 				&controllers.EdbInfoController{},
 			),
 		),
+		beego.NSNamespace("/edb_info_calculate",
+			beego.NSInclude(
+				&controllers.EdbInfoCalculateController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 1 - 0
utils/config.go

@@ -185,6 +185,7 @@ func init() {
 		ES_URL = config["es_url"]
 		ES_USERNAME = config["es_username"]
 		ES_PASSWORD = config["es_password"]
+		DATA_INDEX_NAME = config["data_index_name"]
 	}
 
 	// 数据指标库ES索引名称