Răsfoiți Sursa

Merge branch 'feature/eta2.3.4_business_user' into debug

xyxie 6 zile în urmă
părinte
comite
f86b8268c4

+ 53 - 0
controllers/eta_forum_chart.go

@@ -0,0 +1,53 @@
+package controllers
+
+import (
+	"eta/eta_chart_lib/models"
+	"eta/eta_chart_lib/services/eta_forum"
+)
+
+type EtaForumChartController struct {
+	BaseCommonController
+}
+
+// CommonChartInfoDetailFromUniqueCode
+// @Title 根据编码获取图表详情
+// @Description 根据编码获取图表详情接口
+// @Param   UniqueCode   query   int  true       "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
+// @Param   IsCache   query   bool  true       "是否走缓存,默认false"
+// @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
+// @router /chart/common/detail [get]
+func (this *EtaForumChartController) CommonChartInfoDetailFromUniqueCode() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	uniqueCode := this.GetString("UniqueCode")
+	if uniqueCode == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,uniqueCode is empty"
+		return
+	}
+
+	resp := new(models.ChartInfoDetailResp)
+	//是否走缓存
+	isCache, _ := this.GetBool("IsCache")
+	forumResp, err, _ := eta_forum.GeChartFromUniqueCode(uniqueCode, isCache)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取图表信息失败, Err: " + err.Error()
+		return
+	}
+	chartInfo := forumResp.ChartInfo
+	resp.ChartInfo = chartInfo
+	resp.DataResp = forumResp.DataResp
+	resp.EdbInfoList = forumResp.EdbInfoList
+	resp.XDataList = forumResp.XDataList
+	resp.YDataList = forumResp.YDataList
+	resp.WaterMark = forumResp.WaterMark
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 9 - 0
routers/commentsRouter.go

@@ -88,6 +88,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:EtaForumChartController"] = append(beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:EtaForumChartController"],
+        beego.ControllerComments{
+            Method: "CommonChartInfoDetailFromUniqueCode",
+            Router: `/chart/common/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ExcelInfoController"] = append(beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ExcelInfoController"],
         beego.ControllerComments{
             Method: "GetTableDetail",

+ 5 - 0
routers/router.go

@@ -34,6 +34,11 @@ func init() {
 				&controllers.ExcelInfoController{},
 			),
 		),
+		web.NSNamespace("/eta_forum",
+			web.NSInclude(
+				&controllers.EtaForumChartController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 57 - 0
services/eta_forum/chart_collect.go

@@ -0,0 +1,57 @@
+package eta_forum
+
+import (
+	"eta/eta_chart_lib/models"
+	"eta/eta_chart_lib/services/alarm_msg"
+	"eta/eta_chart_lib/utils"
+	"fmt"
+)
+
+type ChartFromUniqueCodeResp struct {
+	Ret         int
+	Msg         string
+	ErrMsg      string
+	ErrCode     string
+	Data        *ChartFromUniqueCodeRespItem
+	Success     bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
+	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
+}
+
+type ChartFromUniqueCodeRespItem struct {
+	ChartInfo   *models.ChartInfo
+	EdbInfoList []*models.ChartEdbInfoMapping
+	XEdbIdValue []int          `description:"柱方图的x轴数据,指标id"`
+	YDataList   []models.YData `description:"柱方图的y轴数据"`
+	XDataList   []models.XData `description:"商品价格曲线的X轴数据"`
+	//BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
+	//CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
+	DataResp  interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
+	WaterMark string      `description:"水印"`
+}
+
+// GeChartFromUniqueCode 社区中根据唯一编码查询图表
+func GeChartFromUniqueCode(uniqueCode string, isCache bool) (resp ChartFromUniqueCodeRespItem, err error, errMsg string) {
+	defer func() {
+		if err != nil {
+			msg := fmt.Sprintf("查询社区中对用户可见的图表列表 GeChartFromUniqueCode:Err:%v,ErrMsg:%s", err, errMsg)
+			utils.FileLog.Info(msg)
+			go alarm_msg.SendAlarmMsg(msg, 3)
+		}
+	}()
+	urlQuery := fmt.Sprintf("UniqueCode=%s&isCache=%v", uniqueCode, isCache)
+	result, err := getChartFromUniqueCodeLib(urlQuery)
+	if err != nil {
+		errMsg = "查询失败"
+		err = fmt.Errorf("查询失败,Err:" + err.Error())
+		return
+	}
+	if result.Ret != 200 {
+		errMsg = "查询失败"
+		err = fmt.Errorf(result.Msg + result.ErrMsg)
+		return
+	}
+	resp = *result.Data
+
+	return
+}

+ 58 - 0
services/eta_forum/eta_forum_hub_lib.go

@@ -0,0 +1,58 @@
+package eta_forum
+
+import (
+	"encoding/json"
+	"eta/eta_chart_lib/models"
+	"eta/eta_chart_lib/utils"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+)
+
+// getChartFromUniqueCodeLib 根据唯一编码查询图表
+func getChartFromUniqueCodeLib(req string) (resp ChartFromUniqueCodeResp, err error) {
+	_, resultByte, err := get(req, "/v1/chart/common/from_unique_code")
+	err = json.Unmarshal(resultByte, &resp)
+	if err != nil {
+		return
+	}
+	return
+}
+
+// get
+func get(paramStr string, urlStr string) (resp *models.BaseResponse, result []byte, err error) {
+	if utils.ETA_FORUM_HUB_URL == "" {
+		err = fmt.Errorf("ETA社区桥接服务地址为空")
+		return
+	}
+	urlStr = urlStr + "?" + paramStr
+	getUrl := utils.ETA_FORUM_HUB_URL + urlStr
+	result, err = HttpGet(getUrl)
+	if err != nil {
+		err = fmt.Errorf("调用ETA社区桥接服务接口失败 error:%s", err.Error())
+		return
+	}
+	err = json.Unmarshal(result, &resp)
+	if err != nil {
+		return
+	}
+
+	return
+}
+
+func HttpGet(url string) ([]byte, error) {
+	client := &http.Client{}
+	req, err := http.NewRequest("GET", url, nil)
+	if err != nil {
+		return nil, err
+	}
+	req.Header.Set("authorization", utils.MD5(utils.ETA_FORUM_HUB_NAME_EN+utils.ETA_FORUM_HUB_MD5_KEY))
+	resp, err := client.Do(req)
+	if err != nil {
+		return nil, err
+	}
+	defer resp.Body.Close()
+	b, err := ioutil.ReadAll(resp.Body)
+	utils.FileLog.Debug("HttpPost:" + string(b))
+	return b, err
+}

+ 14 - 0
utils/config.go

@@ -66,6 +66,13 @@ var (
 	UseMongo bool // 是否使用mongo
 )
 
+// eta_forum_hub ETA社区桥接服务地址
+var (
+	ETA_FORUM_HUB_URL     string
+	ETA_FORUM_HUB_NAME_EN string
+	ETA_FORUM_HUB_MD5_KEY string
+)
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -155,6 +162,13 @@ func init() {
 		logMaxDaysStr := config["log_max_day"]
 		LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
 	}
+
+	// eta_forum_hub ETA社区桥接服务地址
+	{
+		ETA_FORUM_HUB_URL = config["eta_forum_hub_url"]
+		ETA_FORUM_HUB_NAME_EN = config["eta_forum_hub_name_en"]
+		ETA_FORUM_HUB_MD5_KEY = config["eta_forum_hub_md5_key"]
+	}
 }
 
 // FormatMixTableDataShowValue 格式化自定表格显示数据