Browse Source

Merge branch 'debug' of http://8.136.199.33:3000/eta_server/eta_chart_lib into bzq/6825_seasonal_cf

zqbao 2 months ago
parent
commit
0705474012

+ 69 - 9
controllers/chart.go

@@ -2,10 +2,12 @@ package controllers
 
 import (
 	"encoding/json"
+	"eta/eta_chart_lib/facade"
 	"eta/eta_chart_lib/models"
 	"eta/eta_chart_lib/models/data_manage"
 	"eta/eta_chart_lib/models/data_manage/cross_variety/request"
 	"eta/eta_chart_lib/models/data_manage/excel"
+	requestDTO "eta/eta_chart_lib/models/request"
 	"eta/eta_chart_lib/services/data"
 	"eta/eta_chart_lib/services/data/cross_variety"
 	"eta/eta_chart_lib/services/data/range_analysis"
@@ -37,6 +39,7 @@ func (this *ChartController) ChartInfoDetail() {
 	uniqueCode := this.GetString("UniqueCode")
 	token := this.GetString("Token")
 	source, _ := this.GetInt("Source")
+	miniSource := this.GetString("MiniSource")
 	if uniqueCode == "" {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误,uniqueCode is empty"
@@ -53,16 +56,24 @@ func (this *ChartController) ChartInfoDetail() {
 		return
 	}
 	var isCollect bool
-	if source == utils.CHART_SOURCE_DW && token != "" {
-		tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取收藏状态失败,Err:" + err.Error()
-			return
+	if miniSource != "" {
+		auth := this.Ctx.Request.Header.Get("Authorization")
+		param := facade.BaseRequest{
+			Auth:       auth,
+			UniqueCode: uniqueCode,
+		}
+		isCollect = facade.FacadeClient.Deal(param).IsCollect(facade.GetInstance(miniSource))
+	} else {
+		if source == utils.CHART_SOURCE_DW && token != "" {
+			tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取收藏状态失败,Err:" + err.Error()
+				return
+			}
+			isCollect = tmpIsCollect
 		}
-		isCollect = tmpIsCollect
 	}
-
 	//判断是否有缓存
 	if utils.Re == nil {
 		if utils.Re == nil && utils.Rc.IsExist(key) {
@@ -147,7 +158,6 @@ func (this *ChartController) ChartInfoDetail() {
 	if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
 		resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
 	}
-
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -256,6 +266,50 @@ func (this *ChartController) ChartInfoRefresh() {
 	br.Msg = "刷新成功"
 }
 
+// MiniBookMark
+// @Title 小程序收藏/取消收藏通用接口
+// @Description 小程序收藏/取消收藏通用接口
+// @Param	request	body models.ChartCollectReq true "type json string"
+// @Success Ret=200 取消收藏成功
+// @router /mini/bookMark [post]
+func (this *ChartController) MiniBookMark() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req requestDTO.ChartCollectReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		return
+	}
+	if req.UniqueCode == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,UniqueCode is empty"
+		return
+	}
+	if req.Source == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Source is empty"
+		return
+	}
+	auth := this.Ctx.Request.Header.Get("Authorization")
+	param := facade.BaseRequest{
+		Auth:       auth,
+		UniqueCode: req.UniqueCode,
+	}
+	action, err := facade.FacadeClient.Deal(param).HandleAction(req.Action, facade.GetInstance(req.Source))
+	if err != nil {
+		br.Msg = action + "失败"
+		br.ErrMsg = action + "失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = action + "成功"
+}
+
 // CollectCancel
 // @Title 东吴小程序图表取消收藏接口
 // @Description 东吴小程序图表取消收藏接口
@@ -509,6 +563,12 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (
 	chartInfo.ChartSource = strings.Join(sourceNameList, ",")
 	chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
 
+	// 单位
+	if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
+		chartInfo.Unit = yDataList[0].Unit
+		chartInfo.UnitEn = yDataList[0].UnitEn
+	}
+
 	resp.ChartInfo = chartInfo
 	resp.EdbInfoList = edbList
 	resp.XEdbIdValue = xEdbIdValue

+ 23 - 0
controllers/chart_common.go

@@ -265,6 +265,29 @@ func GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key
 				}
 			}
 		}
+		if v.Source == 0 {
+			name := strings.Split(v.EdbName, "(")
+			if barConfig.FutureGoodEdbName != "" {
+				name[0] = barConfig.FutureGoodEdbName
+			}
+			v.EdbName = name[0]
+			if len(name) > 1 {
+				v.EdbName = v.EdbName + "(" + name[1]
+			}
+			//英文
+			// 编译正则表达式,匹配一个或多个数字
+
+			if v.EdbNameEn != "" {
+				name = strings.Split(v.EdbNameEn, "(")
+				if barConfig.FutureGoodEdbNameEn != "" {
+					name[0] = barConfig.FutureGoodEdbNameEn
+				}
+				v.EdbNameEn = name[0]
+				if len(name) > 1 {
+					v.EdbNameEn = v.EdbNameEn + "(" + name[1]
+				}
+			}
+		}
 	}
 	chartInfo.UnitEn = baseEdbInfo.UnitEn
 

+ 85 - 42
controllers/excel_info.go

@@ -177,6 +177,49 @@ func (this *ExcelInfoController) GetTableDetail() {
 		}
 		resp.ExcelSource = strings.Join(sourceNameList, ",")
 		resp.ExcelSourceEn = strings.Join(sourceNameEnList, ",")
+	case utils.BALANCE_TABLE:
+		var result request.MixedTableReq
+		err = json.Unmarshal([]byte(excelInfo.Content), &result)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
+			return
+		}
+		newResult, tmpErr, tmpErrMsg := excel2.GetMixedTableCellData(result, this.Lang)
+		if tmpErr != nil {
+			br.Msg = "获取失败"
+			if tmpErrMsg != `` {
+				br.Msg = tmpErrMsg
+			}
+			br.ErrMsg = "获取最新的数据失败,Err:" + tmpErr.Error()
+			return
+		}
+		tableData, err = excel.GetTableDataByMixedTableData(newResult, true, excelInfo.ExcelInfoId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "转换成table失败,Err:" + err.Error()
+			return
+		}
+		edbInfoIds := make([]int, 0)
+		edbInfoIdExist := make(map[int]bool)
+		if len(newResult) > 0 {
+			for _, t := range newResult {
+				for _, v := range t {
+					if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
+						edbInfoIdExist[v.EdbInfoId] = true
+						edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+					}
+				}
+			}
+		}
+		sourceNameList, sourceNameEnList, err := data.GetEdbSourceByEdbInfoIdListForExcel(edbInfoIds)
+		if err != nil {
+			br.Msg = "自定义表格数据获取失败"
+			br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
+			return
+		}
+		resp.ExcelSource = strings.Join(sourceNameList, ",")
+		resp.ExcelSourceEn = strings.Join(sourceNameEnList, ",")
 	}
 
 	tableData = excel.HandleTableCell(tableData)
@@ -229,48 +272,6 @@ func (this *ExcelInfoController) GetTableDetail() {
 	br.Data = resp
 }
 
-func refreshBalanceTable(excelDetail *excel3.ExcelInfo, lang string) (err error) {
-
-	edbInfoIds := make([]int, 0)
-	edbInfoIdExist := make(map[int]bool)
-	var result request.MixedTableReq
-	err = json.Unmarshal([]byte(excelDetail.Content), &result)
-	if err != nil {
-		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
-		return
-	}
-	newData, tmpErr, _ := excel2.GetMixedTableCellData(result, lang)
-	if tmpErr != nil {
-		err = tmpErr
-		return
-	}
-	if len(newData) > 0 {
-		for _, t := range newData {
-			for _, v := range t {
-				if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
-					edbInfoIdExist[v.EdbInfoId] = true
-					edbInfoIds = append(edbInfoIds, v.EdbInfoId)
-				}
-			}
-		}
-	}
-
-	// 清除缓存
-	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
-	if utils.Re == nil {
-		_ = utils.Rc.Delete(key)
-	}
-
-	if len(edbInfoIds) > 0 {
-		err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIds, false)
-		if err != nil {
-			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
-			return
-		}
-	}
-	return
-}
-
 // Refresh
 // @Title 刷新
 // @Description 刷新接口
@@ -386,3 +387,45 @@ func (this *ExcelInfoController) Refresh() {
 	br.Success = true
 	br.Msg = "刷新成功"
 }
+
+func refreshBalanceTable(excelDetail *excel3.ExcelInfo, lang string) (err error) {
+
+	edbInfoIds := make([]int, 0)
+	edbInfoIdExist := make(map[int]bool)
+	var result request.MixedTableReq
+	err = json.Unmarshal([]byte(excelDetail.Content), &result)
+	if err != nil {
+		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	newData, tmpErr, _ := excel2.GetMixedTableCellData(result, lang)
+	if tmpErr != nil {
+		err = tmpErr
+		return
+	}
+	if len(newData) > 0 {
+		for _, t := range newData {
+			for _, v := range t {
+				if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
+					edbInfoIdExist[v.EdbInfoId] = true
+					edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+				}
+			}
+		}
+	}
+
+	// 清除缓存
+	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
+	if utils.Re == nil {
+		_ = utils.Rc.Delete(key)
+	}
+
+	if len(edbInfoIds) > 0 {
+		err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIds, false)
+		if err != nil {
+			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
+			return
+		}
+	}
+	return
+}

+ 143 - 0
facade/instance/ht_mini_facade.go

@@ -0,0 +1,143 @@
+package instance
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_chart_lib/facade"
+	"eta/eta_chart_lib/models"
+	"eta/eta_chart_lib/utils"
+	"fmt"
+)
+
+const (
+	bookMarkUrl      = "user/bookMark"
+	unBookMarkUrl    = "user/unBookMark"
+	checkBookMarkUrl = "user/checkBookMark"
+	target           = "ht"
+)
+
+type HTCollectionReq struct {
+	UniqueCode string `json:"uniqueCode"`
+}
+type HTMiniFacade struct {
+	facade.BaseMiniFacade
+}
+type HTResponse struct {
+	Ret     int
+	Msg     string
+	Data    interface{} `json:"data"`
+	ErrMsg  string
+	ErrCode int
+	Success bool
+}
+type HTRequest struct {
+	facade.BaseRequest
+	ChartInfoId int
+	ChartName   string
+	ChartImage  string
+	SourceType  string
+	SourceId    int
+}
+
+func dealChartInfo(baseReq facade.BaseRequest) (request HTRequest, err error) {
+	chartInfo, err := models.GetChartInfoByUniqueCode(baseReq.UniqueCode)
+	if err != nil {
+		utils.FileLog.Error("收藏失败,获取图表信息失败:%v", err.Error())
+		return
+	}
+	request = HTRequest{
+		BaseRequest: baseReq,
+		ChartImage:  chartInfo.ChartImage,
+		ChartInfoId: chartInfo.ChartInfoId,
+		ChartName:   chartInfo.ChartName,
+		SourceType:  "chart",
+		SourceId:    chartInfo.ChartInfoId,
+	}
+	return
+}
+func parseResult(resp string) (response HTResponse, err error) {
+	err = json.Unmarshal([]byte(resp), &response)
+	if err != nil {
+		utils.FileLog.Error("收藏失败,解析应答失败:%v,应答结果:%s", err.Error(), resp)
+	}
+	if !response.Success {
+		utils.FileLog.Error("收藏失败,应答结果:%d[%s]", response.ErrCode, response.ErrMsg)
+		err = errors.New(response.ErrMsg)
+	}
+	return
+}
+func (ht *HTMiniFacade) Collect(req facade.BaseRequest) (err error) {
+	param, err := dealChartInfo(req)
+	if err != nil {
+		utils.FileLog.Error("收藏失败,获取图表信息失败:%v", err.Error())
+		return err
+	}
+	url, err := generateUrl(bookMarkUrl)
+	if err != nil {
+		return
+	}
+	resp, err := ht.Post(url, param, req.Auth)
+	if err != nil {
+		utils.FileLog.Error("收藏失败,err:%v,resp:%v", err, resp)
+	}
+	_, err = parseResult(resp)
+	return
+}
+func (ht *HTMiniFacade) UnCollect(req facade.BaseRequest) (err error) {
+	param, err := dealChartInfo(req)
+	if err != nil {
+		utils.FileLog.Error("收藏失败,获取图表信息失败:%v", err.Error())
+		return err
+	}
+	url, err := generateUrl(unBookMarkUrl)
+	if err != nil {
+		return
+	}
+	resp, err := ht.Post(url, param, req.Auth)
+	if err != nil {
+		utils.FileLog.Error("取消收藏失败,err:%v,resp:%v", err, resp)
+	}
+	_, err = parseResult(resp)
+	return
+}
+func generateUrl(path string) (url string, err error) {
+	configPath := utils.GetMiniUrl(target)
+	if configPath == "" {
+		utils.FileLog.Error("获取mini接口地址失败", err)
+		err = errors.New("获取mini接口地址失败")
+		return
+	}
+	url = fmt.Sprintf("%s%s", configPath, path)
+	return
+}
+func (ht *HTMiniFacade) IsCollect(req facade.BaseRequest) bool {
+	param, err := dealChartInfo(req)
+	if err != nil {
+		utils.FileLog.Error("获取是否收藏失败,获取图表信息失败:%v", err.Error())
+		return false
+	}
+	url, err := generateUrl(checkBookMarkUrl)
+	if err != nil {
+		return false
+	}
+	resp, err := ht.Post(url, param, req.Auth)
+	if err != nil {
+		utils.FileLog.Error("获取是否收藏失败,err:%v,resp:%v", err, resp)
+	}
+	response, err := parseResult(resp)
+	if err != nil {
+		utils.FileLog.Error("获取是否收藏失败,解析应答失败:%v,应答结果:%s", err, resp)
+		return false
+	}
+	var resMap = response.Data.(map[string]interface{})
+	bookMarked := resMap["isBookMarked"]
+	if bookMarked == nil {
+		return false
+	}
+	return bookMarked.(bool)
+}
+func init() {
+	facade.RegisterMiniFacade(target, &HTMiniFacade{
+		BaseMiniFacade: facade.FacadeClient,
+	})
+}

+ 234 - 0
facade/mini_facde.go

@@ -0,0 +1,234 @@
+package facade
+
+import (
+	"context"
+	"encoding/json"
+	"errors"
+	"eta/eta_chart_lib/utils"
+	"fmt"
+	"io"
+	"net/http"
+	"strings"
+	"sync"
+	"time"
+)
+
+var (
+	once          sync.Once
+	miniFacadeMap = make(map[string]ChartCollect)
+
+	FacadeClient = BaseMiniFacade{
+		client: DefaultClient(),
+	}
+)
+
+const (
+	bookMark   = "bookMark"
+	unBookMark = "unBookMark"
+)
+
+func GetInstance(name string) ChartCollect {
+	return miniFacadeMap[name]
+}
+
+type ChartCollect interface {
+	Collect(data BaseRequest) (err error)
+	UnCollect(data BaseRequest) (err error)
+	IsCollect(data BaseRequest) bool
+}
+
+type BaseRequest struct {
+	Auth       string `json:"auth"`
+	UniqueCode string `json:"uniqueCode"`
+}
+
+func (bm *BaseMiniFacade) GetData() interface{} {
+	return bm.data
+}
+
+func (bm *BaseMiniFacade) Post(url string, data interface{}, auth string) (result string, err error) {
+	resp, err := bm.client.Post(url, data, auth)
+	if err != nil {
+		return
+	}
+	respBody, respErr := io.ReadAll(resp.Body)
+	if respErr != nil {
+		utils.FileLog.Error("读取body失败,err:%v", err)
+		return
+	}
+	result = string(respBody)
+	return
+}
+func (bm *BaseMiniFacade) Deal(data BaseRequest) *BaseMiniFacade {
+	bm.data = data
+	return bm
+}
+func (bm *BaseMiniFacade) HandleAction(action string, handler ChartCollect) (actionMsg string, err error) {
+	if handler == nil {
+		return "", errors.New("不支持的操作类型")
+	}
+	switch action {
+	case bookMark:
+		err = handler.Collect(bm.data)
+		actionMsg = "收藏"
+	case unBookMark:
+		err = handler.UnCollect(bm.data)
+		actionMsg = "取消收藏"
+	default:
+		err = errors.New("不支持的操作")
+	}
+	return
+}
+
+func (bm *BaseMiniFacade) IsCollect(handler ChartCollect) bool {
+	return handler.IsCollect(bm.data)
+}
+
+type BaseMiniFacade struct {
+	client *HttpClient
+	data   BaseRequest //返回参数
+}
+
+type HttpClient struct {
+	*http.Client
+	maxRetries     int
+	retryDelayFunc RetryDelayFunc
+}
+
+// NewClient 构造函数,其中 delayFunc 参数是可选的
+func NewClient(timeout time.Duration, maxRetries int, delayFunc ...RetryDelayFunc) *HttpClient {
+	var df RetryDelayFunc
+	if len(delayFunc) > 0 {
+		df = delayFunc[0]
+	} else {
+		df = defaultRetryDelayFunc
+	}
+	return &HttpClient{
+		Client:         &http.Client{Timeout: timeout},
+		maxRetries:     maxRetries,
+		retryDelayFunc: df,
+	}
+}
+
+func DefaultClient() *HttpClient {
+	return NewClient(time.Second*10, 3)
+}
+func defaultRetryDelayFunc(attempt int) time.Duration {
+	delay := time.Duration(attempt) * time.Second
+	if attempt > 0 {
+		delay *= 2
+	}
+	return delay
+}
+
+type RetryDelayFunc func(attempt int) time.Duration
+
+func retryErr(err error) bool {
+	return errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)
+}
+
+// DoWithRetry 发送带有重试机制的HTTP请求,允许用户自定义重试延迟逻辑
+func (hc *HttpClient) DoWithRetry(ctx context.Context, req *http.Request) (resp *http.Response, err error) {
+	attempt := 0
+	for {
+		resp, err = hc.Do(req.WithContext(ctx))
+		if err != nil && retryErr(err) {
+			if attempt >= hc.maxRetries {
+
+				return nil, fmt.Errorf("请求失败: %w", err)
+			}
+			attempt++
+			delay := hc.retryDelayFunc(attempt)
+			time.Sleep(delay)
+			continue
+		}
+		return
+	}
+}
+
+func (hc *HttpClient) Post(url string, data interface{}, auth string) (resp *http.Response, err error) {
+	dataStr, err := json.Marshal(data)
+	if err != nil {
+		utils.FileLog.Error("请求data json序列化失败,err:" + err.Error())
+	}
+	body := io.NopCloser(strings.NewReader(string(dataStr)))
+	req, err := http.NewRequest(http.MethodPost, url, body)
+	req.Header.Set("Content-Type", "application/json")
+	req.Header.Set("Authorization", auth)
+	if err != nil {
+		utils.FileLog.Error("创建POST请求失败: %v", err.Error())
+	}
+	resp, err = hc.DoWithRetry(req.Context(), req)
+	if err == nil {
+		code := resp.StatusCode
+		if code != 200 {
+			utils.FileLog.Error("请求错误应答,状态码:%d", code)
+			errMsg := fmt.Sprintf("请求状态码异常,StatusCode:[%d]", code)
+			respBody, respErr := io.ReadAll(resp.Body)
+			if respErr != nil {
+				utils.FileLog.Error("读取body失败,err:%v", err)
+				err = errors.New(errMsg)
+				return
+			}
+			utils.FileLog.Error("请求错误应答,body:%s", string(respBody))
+			errMsg = fmt.Sprintf("%s,body:%s", errMsg, string(respBody))
+			err = errors.New(errMsg)
+			return
+		}
+	} else {
+		utils.FileLog.Error("未知的应答错误,获取第三方授权信息失败", err.Error())
+	}
+	return
+}
+func (hc *HttpClient) PostWithAuth(url string, data interface{}, token string) (resp *http.Response, err error) {
+	dataStr, err := json.Marshal(data)
+	if err != nil {
+		utils.FileLog.Error("请求data json序列化失败,err:" + err.Error())
+	}
+	body := io.NopCloser(strings.NewReader(string(dataStr)))
+	req, err := http.NewRequest(http.MethodPost, url, body)
+	req.Header.Set("Content-Type", "application/json")
+	req.Header.Set("Authorization", token)
+	if err != nil {
+		utils.FileLog.Error("创建POST请求失败: %v", err)
+	}
+	resp, err = hc.DoWithRetry(req.Context(), req)
+	code := resp.StatusCode
+	if code != 200 {
+		utils.FileLog.Error("请求错误应答,状态码:%d", code)
+		errMsg := fmt.Sprintf("请求状态码异常,StatusCode:[%d]", code)
+		respBody, respErr := io.ReadAll(resp.Body)
+		if respErr != nil {
+			utils.FileLog.Error("读取body失败,err:%v", err)
+			err = errors.New(errMsg)
+			return
+		}
+		utils.FileLog.Error("请求错误应答,body:%s", string(respBody))
+		errMsg = fmt.Sprintf("%s,body:%s", errMsg, string(respBody))
+		err = errors.New(errMsg)
+		return
+	}
+	return
+}
+func (hc *HttpClient) Get(url string) (resp *http.Response, err error) {
+	req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
+	if err != nil {
+		utils.FileLog.Error("创建请求失败: %v", err)
+	}
+	resp, err = hc.DoWithRetry(req.Context(), req)
+	return
+}
+
+func RegisterMiniFacade(name string, facade ChartCollect) {
+	if facade == nil {
+		panic("实例不存在,无法注册")
+	}
+	if _, ok := miniFacadeMap[name]; ok {
+		utils.FileLog.Error("请勿重复注册小程序插件:" + name)
+	}
+	miniFacadeMap[name] = facade
+}
+
+func init() {
+
+}

+ 3 - 3
main.go

@@ -2,16 +2,16 @@ package main
 
 import (
 	"eta/eta_chart_lib/controllers"
+	_ "eta/eta_chart_lib/facade/instance"
 	_ "eta/eta_chart_lib/routers"
 	"eta/eta_chart_lib/services/alarm_msg"
 	"eta/eta_chart_lib/utils"
 	"fmt"
-	"runtime"
-	"time"
-
 	"github.com/beego/beego/v2/adapter/logs"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/beego/beego/v2/server/web/context"
+	"runtime"
+	"time"
 )
 
 func main() {

+ 4 - 2
models/chart.go

@@ -45,8 +45,8 @@ type ChartInfo struct {
 	Right2Max         string    `description:"图表右侧2最大值"`
 	MinMaxSave        int       `description:"是否手动保存过上下限:0-否;1-是"`
 	Source            int       `description:"1:ETA图库;2:商品价格曲线"`
-	Unit              string    `description:"中文单位名称"`
-	UnitEn            string    `description:"英文单位名称"`
+	UnitEn            string    `description:"英文图表单位"`
+	Unit              string    `description:"图表单位"`
 	ExtraConfig       string    `description:"图表额外配置,json数据" json:"-"`
 	ChartSource       string    `description:"图表来源str"`
 	ChartSourceEn     string    `description:"图表来源(英文)"`
@@ -311,6 +311,8 @@ type YData struct {
 	M              []int           `description:"对应开始日期的间隔值" json:"-"`
 	NameList       []string        `description:"每个值对应的名称"`
 	EnNameList     []string        `description:"每个值对应的英文名称"`
+	Unit           string          `description:"中文单位名称"`
+	UnitEn         string          `description:"英文单位名称"`
 	SeriesEdb      struct {
 		SeriesId  int `description:"因子指标系列ID"`
 		EdbInfoId int `description:"指标ID"`

+ 8 - 4
models/data_manage/chart_info.go

@@ -62,13 +62,17 @@ type BarChartInfoReq struct {
 	EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
 	DateList      []BarChartInfoDateReq    `description:"日期配置"`
 	Sort          BarChartInfoSortReq      `description:"排序"`
+	Unit          string                   `description:"中文单位名称"`
+	UnitEn        string                   `description:"英文单位名称"`
 }
 
 type FutureGoodBarChartInfoReq struct {
-	EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
-	DateList      []BarChartInfoDateReq    `description:"日期配置"`
-	XDataList     []XData                  `description:"横轴配置"`
-	BaseEdbInfoId int                      `description:"日期基准指标id"`
+	EdbInfoIdList       []BarChartInfoEdbItemReq `description:"指标信息"`
+	DateList            []BarChartInfoDateReq    `description:"日期配置"`
+	XDataList           []XData                  `description:"横轴配置"`
+	BaseEdbInfoId       int                      `description:"日期基准指标id"`
+	FutureGoodEdbName   string                   `description:"期货名称"`
+	FutureGoodEdbNameEn string                   `description:"期货英文名称"`
 }
 
 // XData 商品价格曲线的的x轴数据

+ 8 - 0
models/request/mini.go

@@ -0,0 +1,8 @@
+package request
+
+type ChartCollectReq struct {
+	UniqueCode string `json:"uniqueCode"`
+	Source     string `json:"source"`
+	Action     string `json:"action"`
+	ExtraInfo  string `json:"extraInfo"` //通用额外信息传输需要的扩展信息
+}

+ 0 - 1
models/request/mixed_table.go

@@ -167,7 +167,6 @@ type MixCellShowStyle struct {
 	Last            string      `description:"起始操作:nt|decimal" json:"last"`
 	Color           string      `description:"颜色值,#RRG" json:"color"`
 	BackgroundColor string      `description:"背景颜色值,#RRG" json:"background-color"`
-	Width           float64     `description:"单元格宽度" json:"width"`
 	Align           string      `description:"对齐方式:left|center|right" json:"align"`
 }
 

+ 9 - 0
routers/commentsRouter.go

@@ -70,6 +70,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ChartController"] = append(beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "MiniBookMark",
+            Router: `/mini/bookMark`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ChartController"] = append(beego.GlobalControllerRouter["eta/eta_chart_lib/controllers:ChartController"],
         beego.ControllerComments{
             Method: "ChartInfoRefresh",

+ 6 - 0
services/data/chart_info.go

@@ -326,6 +326,12 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
 				}
 			}
 		}
+
+		for k := range yDataList {
+			yDataList[k].Unit = barChartConf.Unit
+			yDataList[k].UnitEn = barChartConf.UnitEn
+		}
+
 	case 10: // 截面散点图
 		sectionScatterConf := extraConfig.(data_manage.SectionScatterReq)
 		xEdbIdValue, dataResp, err = GetSectionScatterChartData(mappingList, edbDataListMap, sectionScatterConf)

+ 2 - 0
services/data/correlation/chart_info.go

@@ -277,6 +277,8 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
 				return
 			}
 			changeDataList = tmpNewChangeDataList
+
+			// 那么A指标不管是高频,或者同频,那么就直接赋值A指标吧
 			baseDataList = aDataList
 			for _, v := range baseDataList {
 				baseDataMap[v.DataTime] = v.Value

+ 2 - 2
services/data/future_good/base_future_good_lib.go

@@ -31,9 +31,9 @@ func RefreshEdbData(futureGoodEdbInfoId int, futureGoodEdbCode, startDate string
 }
 
 // RefreshEdbRelation 刷新商品期货指标相关的数据
-func RefreshEdbRelation(futureGoodEdbInfoId int) (resp *models.BaseResponse, err error) {
+func RefreshEdbRelation(chartInfoId int) (resp *models.BaseResponse, err error) {
 	param := make(map[string]interface{})
-	param["FutureGoodEdbInfoId"] = futureGoodEdbInfoId
+	param["ChartInfoId"] = chartInfoId
 	urlStr := `future_good/relation/refresh`
 	resp, err = postRefreshEdbData(param, urlStr)
 	return

+ 8 - 0
services/data/future_good/chart_info.go

@@ -1072,5 +1072,13 @@ func FutureGoodChartInfoRefresh(chartInfoId int) (err error) {
 		return
 	}
 
+	resp, err := RefreshEdbRelation(chartInfoId)
+	if err != nil {
+		return
+	}
+	if resp.Ret != 200 {
+		err = fmt.Errorf("刷新利润曲线图表数据失败:Err:%s", resp.Msg)
+		return
+	}
 	return
 }

+ 0 - 8
services/data/future_good/future_edb_info.go

@@ -53,13 +53,5 @@ func FutureGoodEdbInfoRefreshAllFromBase(futureGoodEdbInfoList []*future_good.Fu
 			return fmt.Errorf("刷新失败, err:%s", errMsg)
 		}
 	}
-
-	// 刷新商品期货指标相关的数据
-	for _, bv := range futureGoodEdbInfoList {
-		if bv.ParentId == 0 {
-			RefreshEdbRelation(bv.FutureGoodEdbInfoId)
-		}
-	}
-
 	return err
 }

+ 2 - 0
services/dw_mini/dw_mini.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"errors"
 	"eta/eta_chart_lib/models"
+	"eta/eta_chart_lib/services/alarm_msg"
 	"eta/eta_chart_lib/utils"
 )
 
@@ -67,6 +68,7 @@ func MyChartCollect(token, uniqueCode, chartName, chartImage string, chartInfoId
 	if err != nil {
 		return
 	}
+	alarm_msg.SendAlarmMsg(string(reqBody), 1)
 	if err = json.Unmarshal(result, &resp); err != nil {
 		return
 	}

+ 32 - 36
services/excel/lucky_sheet.go

@@ -196,7 +196,7 @@ type LuckySheetDataValue struct {
 	VerticalType   int                    ` description:"垂直对齐,	0 中间、1 上、2下"`
 	Fs             interface{}            `json:"fs" description:"字体大小,14"`
 	Cl             interface{}            `json:"cl" description:"删除线,	0 常规 、 1 删除线"`
-	Ht             interface{}            `json:"ht" description:"水平对齐,	0 居中、1 左、2右"`
+	Ht             interface{}            `json:"instance" description:"水平对齐,	0 居中、1 左、2右"`
 	Vt             interface{}            `json:"vt" description:"垂直对齐,	0 中间、1 上、2下"`
 	//TextRotate     string                    `json:"tr" description:"竖排文字,	3"`
 	//RotateText     string                    `json:"rt" description:"文字旋转角度,	介于0~180之间的整数,包含0和180"`
@@ -221,7 +221,7 @@ type LuckySheetDataCellType struct {
 		VerticalType   int         `description:"垂直对齐,	0 中间、1 上、2下"`
 		Fs             interface{} `json:"fs" description:"字体大小,14"`
 		Cl             interface{} `json:"cl" description:"删除线,	0 常规 、 1 删除线"`
-		Ht             interface{} `json:"ht" description:"水平对齐,	0 居中、1 左、2右"`
+		Ht             interface{} `json:"instance" description:"水平对齐,	0 居中、1 左、2右"`
 		Vt             interface{} `json:"vt" description:"垂直对齐,	0 中间、1 上、2下"`
 		Un             interface{} `json:"un" description:""`
 		Bold           interface{} `json:"bl" description:"粗体,0 常规 、 1加粗	"`
@@ -464,23 +464,21 @@ func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataCo
 		flag = false
 		//尾部
 		deleteBottomRowIndexList := make([]int, 0)
-		if len(tableDataList) > 1 {
-			for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
-				isDelete := true
-				for _, v := range tableDataList[rowIndex] {
-					if v.Monitor != `` {
-						isDelete = false
-						flag = true
-						break
-					}
-				}
-				if flag {
+		for rowIndex := lenRow - 1; rowIndex > removeTopRow; rowIndex-- {
+			isDelete := true
+			for _, v := range tableDataList[rowIndex] {
+				if v.Monitor != `` {
+					isDelete = false
+					flag = true
 					break
 				}
-				if isDelete {
-					deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
-					removeBottomRow++
-				}
+			}
+			if flag {
+				break
+			}
+			if isDelete {
+				deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
+				removeBottomRow++
 			}
 		}
 
@@ -532,28 +530,26 @@ func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataCo
 		flag = false
 		//右边
 		deleteTailColumnIndexList := make([]int, 0)
-		// 数据要大于1列才会处理
-		if lenColumn > 1 {
-			for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
-				isDelete := true
-				for _, v := range tableDataList {
-					//如果一列都没有,说明是上面几行是空行,没有数据
-					if len(v) <= 0 {
-						continue
-					}
-					if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
-						isDelete = false
-						flag = true
-						break
-					}
+		// 数据第1列不处理
+		for columnIndex := lenColumn - 1; columnIndex > removeLeftColumn; columnIndex-- {
+			isDelete := true
+			for _, v := range tableDataList {
+				//如果一列都没有,说明是上面几行是空行,没有数据
+				if len(v) <= 0 {
+					continue
 				}
-				if flag {
+				if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
+					isDelete = false
+					flag = true
 					break
 				}
-				if isDelete {
-					deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
-					removeRightColumn++
-				}
+			}
+			if flag {
+				break
+			}
+			if isDelete {
+				deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
+				removeRightColumn++
 			}
 		}
 

+ 45 - 8
utils/common.go

@@ -4,8 +4,10 @@ import (
 	"bufio"
 	"crypto/cipher"
 	"crypto/des"
+	"crypto/hmac"
 	"crypto/md5"
 	"crypto/sha1"
+	"crypto/sha256"
 	"encoding/base64"
 	"encoding/hex"
 	"encoding/json"
@@ -22,6 +24,7 @@ import (
 	"os/exec"
 	"path"
 	"regexp"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -1177,6 +1180,48 @@ func DateConvMysqlConvMongo(dateCon string) string {
 	return cond
 }
 
+// HmacSha256 计算HmacSha256
+// key 是加密所使用的key
+// data 是加密的内容
+func HmacSha256(key string, data string) []byte {
+	mac := hmac.New(sha256.New, []byte(key))
+	_, _ = mac.Write([]byte(data))
+	return mac.Sum(nil)
+}
+
+// HmacSha256ToBase64 将加密后的二进制转Base64字符串
+func HmacSha256ToBase64(key string, data string) string {
+	return base64.URLEncoding.EncodeToString(HmacSha256(key, data))
+}
+func GetSign(nonce, timestamp, appId, secret string) (sign string) {
+	signStrMap := map[string]string{
+		"nonce":     nonce,
+		"timestamp": timestamp,
+		"appid":     appId,
+	}
+	keys := make([]string, 0, len(signStrMap))
+	for k := range signStrMap {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+	var signStr string
+	for _, k := range keys {
+		signStr += k + "=" + signStrMap[k] + "&"
+	}
+	signStr = strings.Trim(signStr, "&")
+	fmt.Println("signStr:" + signStr)
+	sign = HmacSha256ToBase64(secret, signStr)
+	return
+}
+
+func TimeTransferString(format string, t time.Time) string {
+	str := t.Format(format)
+	if t.IsZero() {
+		return ""
+	}
+	return str
+}
+
 func DesBase64Decrypt(crypted []byte, desKey string) []byte {
 	result, _ := base64.StdEncoding.DecodeString(string(crypted))
 	remain := len(result) % 8
@@ -1215,14 +1260,6 @@ func PKCS5UnPadding(origData []byte) []byte {
 	return origData[:(length - unpadding)]
 }
 
-func TimeTransferString(format string, t time.Time) string {
-	str := t.Format(format)
-	if t.IsZero() {
-		return ""
-	}
-	return str
-}
-
 // handleSystemAppointDateT
 // @Description: 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
 // @author: Roc

+ 9 - 0
utils/config.go

@@ -231,3 +231,12 @@ func FormatTableDataShowValue(x float64) (res string) {
 	}
 	return
 }
+
+func GetMiniUrl(source string) string {
+	config, err := web.AppConfig.GetSection(RunMode)
+	if err != nil {
+		panic("配置文件读取错误 " + err.Error())
+	}
+	urlName := fmt.Sprintf("mini_url_%s", source)
+	return config[urlName]
+}

+ 3 - 2
utils/constants.go

@@ -57,7 +57,7 @@ const (
 	DATA_SOURCE_PREDICT_CALCULATE                               //预测指标运算->31
 	DATA_SOURCE_PREDICT_CALCULATE_TBZ                           //预测指标同比值->32
 	DATA_SOURCE_PREDICT_CALCULATE_TCZ                           //预测指标同差值->33
-	DATA_SOURCE_MYSTEEL_CHEMICAL                                //钢联化工->34
+	DATA_SOURCE_MYSTEEL_CHEMICAL                                //上海钢联->34
 	DATA_SOURCE_CALCULATE_CJJX                                  //超季节性->35
 	DATA_SOURCE_EIA_STEO                                        //eia steo报告->36
 	DATA_SOURCE_CALCULATE_NHCC                                  //计算指标(拟合残差)->37
@@ -145,7 +145,7 @@ const (
 	CHART_SOURCE_RANGE_ANALYSIS                  = 12 // 	区间分析图表
 )
 
-// 图表来源
+// 图表查询来源
 const (
 	CHART_SOURCE_DW = 1 // 东吴
 )
@@ -156,6 +156,7 @@ const (
 	TIME_TABLE            = 2 // 时间序列表格
 	MIXED_TABLE           = 3 // 混合表格
 	CUSTOM_ANALYSIS_TABLE = 4 // 自定义分析表格
+	BALANCE_TABLE         = 5 // 平衡表
 )
 
 // 图表样式类型