Browse Source

获取eta社区图表数据

xyxie 1 week ago
parent
commit
bb421e5353

+ 62 - 0
controllers/eta_forum/eta_forum.go

@@ -0,0 +1,62 @@
+package eta_forum
+
+import (
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/services/eta_forum"
+	"eta/eta_api/utils"
+)
+
+type EtaForumController struct {
+	controllers.BaseAuthController
+}
+
+// UserChartList
+// @Title 查询用户在eta社区中有权限查看的图表列表
+// @Description 查询用户在eta社区中有权限查看的图表列表
+// @Param	request	body data_manage.SetChartInfoImageReq true "type json string"
+// @Success Ret=200 保存成功
+// @router /eta_forum/chart_list [get]
+func (this *EtaForumController) UserChartList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	keyword := this.GetString("keyword")
+	businessCode := utils.BusinessCode
+	userMobile := sysUser.Mobile
+	telAreaCode := sysUser.TelAreaCode
+	if businessCode == "" {
+		br.Msg = "商户号未配置"
+		return
+	}
+
+	if userMobile == "" {
+		br.Msg = "请先绑定手机号"
+		return
+	}
+	if telAreaCode == "" {
+		telAreaCode = utils.TelAreaCodeHome
+	}
+
+	resp, err, errMsg := eta_forum.GetUserChartList(businessCode, userMobile, telAreaCode, keyword)
+	if err != nil {
+		br.Msg = errMsg
+		br.ErrMsg = err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+	br.Data = resp
+}

+ 58 - 0
services/eta_forum/chart_collect.go

@@ -0,0 +1,58 @@
+package eta_forum
+
+import (
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/services/alarm_msg"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type UserChartListReq struct {
+	Keyword         string `description:"搜索关键词"`
+	PageSize        int
+	CurrentIndex    int
+	UserMobile      string `description:"用户手机号"`
+	BusinessCode    string `description:"商户号"`
+	UserTelAreaCode string `description:"手机号区号"`
+}
+
+type UserChartListResp struct {
+	Ret         int
+	Msg         string
+	ErrMsg      string
+	ErrCode     string
+	Data        *UserChartListRespItem
+	Success     bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
+	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
+}
+
+type UserChartListRespItem struct {
+	ChartInfoList []*data_manage.ChartInfo
+	Paging        *paging.PagingItem `description:"分页数据"`
+}
+
+// GetUserChartList 查询社区中对用户可见的图表列表
+func GetUserChartList(businessCode, userMobile, telAreaCode, keyword string) (resp UserChartListRespItem, err error, errMsg string) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg(fmt.Sprintf("查询社区中对用户可见的图表列表 GetUserChartList:Err:%v,ErrMsg:%s", err, errMsg), 3)
+		}
+	}()
+	urlQuery := fmt.Sprintf("BusinessCode=%s&UserMobile=%s&TelAreaCode=%s&Keyword=%s", businessCode, userMobile, telAreaCode, keyword)
+	result, err := GetUserChartListLib(urlQuery)
+	if err != nil {
+		errMsg = "查询失败"
+		err = fmt.Errorf("查询失败,Err:" + err.Error())
+		return
+	}
+	if result.Ret != 200 {
+		errMsg = "查询失败"
+		err = fmt.Errorf(result.ErrMsg)
+		return
+	}
+	resp.Paging = result.Data.Paging
+	resp.ChartInfoList = result.Data.ChartInfoList
+
+	return
+}

+ 48 - 0
services/eta_forum/eta_forum_hub_lib.go

@@ -80,6 +80,16 @@ func ChartThemeTypeSaveLib(req string) (resp *models.BaseResponse, err error) {
 	return
 }
 
+// GetUserChartListLib 查询有权限的图表列表
+func GetUserChartListLib(req string) (resp *UserChartListResp, err error) {
+	_, resultByte, err := get(req, "/v1/chart/theme/type/save")
+	err = json.Unmarshal(resultByte, &resp)
+	if err != nil {
+		return
+	}
+	return
+}
+
 // post
 func post(paramStr string, urlStr string) (resp *models.BaseResponse, result []byte, err error) {
 	if utils.ETA_FORUM_HUB_URL == "" {
@@ -122,3 +132,41 @@ func HttpPost(url, postData string, params ...string) ([]byte, error) {
 	utils.FileLog.Debug("HttpPost:" + string(b))
 	return b, err
 }
+
+// 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
+}