Browse Source

刷新图表

xyxie 9 months ago
parent
commit
4034a5a3c6

+ 56 - 2
controllers/data_manage/excel/balance_table.go

@@ -3,6 +3,7 @@ package excel
 import (
 	"archive/zip"
 	"encoding/json"
+	"errors"
 	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_manage/excel"
@@ -1281,7 +1282,7 @@ func (c *ExcelInfoController) ModifyBalanceExcelVersion() {
 	br.IsAddLog = true
 }
 
-func DownloadBalanceTable(excelInfo *excel.ExcelInfo) (savePath, zipName string, err error, errMsg string) {
+func downloadBalanceTable(excelInfo *excel.ExcelInfo) (savePath, zipName string, err error, errMsg string) {
 	dateDir := time.Now().Format("20060102")
 	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
 	uploadDir := "static/xls/" + dateDir + "/" + randStr + "/" + utils.GetRandString(6)
@@ -1357,7 +1358,7 @@ func DownloadBalanceTable(excelInfo *excel.ExcelInfo) (savePath, zipName string,
 	// 创建zip
 	zipName = excelInfo.ExcelName + ".zip"
 
-	savePath = uploadDir + "/" + zipName
+	savePath = zipName
 	zipFile, err := os.Create(zipName)
 	if err != nil {
 		return
@@ -1395,3 +1396,56 @@ func DownloadBalanceTable(excelInfo *excel.ExcelInfo) (savePath, zipName string,
 	//this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
 	return
 }
+
+func refreshBalanceTable(excelDetail response.ExcelInfoDetail) (err error) {
+	//查询所有子表
+	cCondition := " AND parent_id = ? AND balance_type=0"
+	var cPars []interface{}
+	cPars = append(cPars, excelDetail.ExcelInfoId)
+	childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars)
+	if e != nil {
+		err = fmt.Errorf("获取子表失败 %s", err.Error())
+		return
+	}
+	edbInfoIds := make([]int, 0)
+	edbInfoIdExist := make(map[int]bool)
+	// 遍历
+	for _, child := range childList {
+		var result request.MixedTableReq
+		err = json.Unmarshal([]byte(child.Content), &result)
+		if err != nil {
+			err = errors.New("表格json转结构体失败,Err:" + err.Error())
+			return
+		}
+		newData, tmpErr, _ := excelService.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 + ":" + child.UniqueCode
+		if utils.Re == nil {
+			_ = utils.Rc.Delete(key)
+		}
+	}
+
+	if len(edbInfoIds) > 0 {
+		e, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
+		if e != nil {
+			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
+			return
+		}
+	}
+	return
+}

+ 11 - 2
controllers/data_manage/excel/excel_info.go

@@ -2093,7 +2093,7 @@ func (c *ExcelInfoController) Refresh() {
 	}
 
 	// 数据刷新-混合表格
-	if excelDetail.Source == utils.MIXED_TABLE || excelDetail.Source == utils.BALANCE_TABLE {
+	if excelDetail.Source == utils.MIXED_TABLE {
 		// todo 刷新动态表的所有子表中关联的指标数据
 		jsonByte, e := json.Marshal(excelDetail.TableData)
 		if e != nil {
@@ -2129,6 +2129,15 @@ func (c *ExcelInfoController) Refresh() {
 		}
 	}
 
+	if excelDetail.Source == utils.BALANCE_TABLE {
+		err = refreshBalanceTable(excelDetail)
+		if err != nil {
+			br.Msg = "刷新失败"
+			br.ErrMsg = "刷新失败,Err:" + err.Error()
+			return
+		}
+	}
+
 	// 清除缓存
 	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
 	if utils.Re == nil {
@@ -2242,7 +2251,7 @@ func (c *ExcelInfoController) Download() {
 			return
 		}
 	case utils.BALANCE_TABLE: // 混合表格
-		savePath, fileName, err, errMsg := DownloadBalanceTable(excelInfo)
+		savePath, fileName, err, errMsg := downloadBalanceTable(excelInfo)
 		if err != nil {
 			br.Msg = "下载失败"
 			if errMsg != `` {