Browse Source

刷新图表

xyxie 10 months ago
parent
commit
59566ec591
3 changed files with 71 additions and 0 deletions
  1. 15 0
      controllers/chart.go
  2. 45 0
      controllers/excel_info.go
  3. 11 0
      models/excel_info.go

+ 15 - 0
controllers/chart.go

@@ -5,6 +5,7 @@ import (
 	"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"
 	"eta/eta_chart_lib/services/data"
 	"eta/eta_chart_lib/services/data/cross_variety"
 	"eta/eta_chart_lib/utils"
@@ -187,6 +188,20 @@ func (this *ChartController) ChartInfoRefresh() {
 			return
 		}
 		err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIdList, false)
+	case utils.CHART_SOURCE_BALANCE_EXCEL:
+		excelDetail, err := excel.GetExcelInfoByChartInfoId(chartInfo.ChartInfoId)
+		if err != nil {
+			br.Msg = "图表数据异常"
+			br.ErrMsg = "未找到对应的表格" + err.Error()
+			br.IsSendEmail = false
+			return
+		}
+		err = refreshBalanceTable(excelDetail)
+		if err != nil {
+			br.Msg = "刷新失败"
+			br.ErrMsg = "刷新失败,Err:" + err.Error()
+			return
+		}
 	default:
 		err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
 	}

+ 45 - 0
controllers/excel_info.go

@@ -3,11 +3,14 @@ package controllers
 import (
 	"encoding/json"
 	"eta/eta_chart_lib/models"
+	excel3 "eta/eta_chart_lib/models/data_manage/excel"
 	"eta/eta_chart_lib/models/request"
 	"eta/eta_chart_lib/models/response"
+	"eta/eta_chart_lib/services/data"
 	excel2 "eta/eta_chart_lib/services/data/excel"
 	"eta/eta_chart_lib/services/excel"
 	"eta/eta_chart_lib/utils"
+	"fmt"
 	"github.com/shopspring/decimal"
 	"time"
 )
@@ -180,3 +183,45 @@ func (this *ExcelInfoController) GetTableDetail() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+func refreshBalanceTable(excelDetail *excel3.ExcelInfo) (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)
+	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
+}

+ 11 - 0
models/excel_info.go

@@ -245,3 +245,14 @@ func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
 	err = o.Raw(sql, classifyId).QueryRow(&total)
 	return
 }
+
+func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY sort asc, excel_info_id asc`
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}