xyxie 9 bulan lalu
induk
melakukan
087a3c84b1

+ 47 - 25
controllers/data_manage/excel/balance_table.go

@@ -166,30 +166,11 @@ func (c *ExcelInfoController) DeleteBalanceChart() {
 }
 
 func refreshBalanceTable(excelDetail response.ExcelInfoDetail, lang string) (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, lang)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
+	if excelDetail.ParentId > 0 {
+		newResult := excelDetail.TableData.(request.MixedTableReq)
+		newData := newResult.Data
 		if len(newData) > 0 {
 			for _, t := range newData {
 				for _, v := range t {
@@ -202,15 +183,56 @@ func refreshBalanceTable(excelDetail response.ExcelInfoDetail, lang string) (err
 		}
 
 		// 清除缓存
-		key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + child.UniqueCode
+		key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
 		if utils.Re == nil {
 			_ = utils.Rc.Delete(key)
 		}
+	} else {
+		//查询父表和子表
+		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
+		}
+		// 遍历
+		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
+			}
+			var newData [][]request.MixedTableCellDataReq
+			newData, err, _ = excelService.GetMixedTableCellData(result, lang)
+			if err != nil {
+				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, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
+		if err != nil {
 			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
 			return
 		}

+ 26 - 21
models/data_manage/excel/response/excel_info.go

@@ -56,27 +56,32 @@ type TableDetailResp struct {
 
 // ExcelInfoDetail excel表格详情(前端使用)
 type ExcelInfoDetail struct {
-	ExcelInfoId      int                          `orm:"column(excel_info_id);pk"`
-	Source           int                          `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
-	ExcelType        int                          `description:"表格类型,1:指标列,2:日期列,默认:1"`
-	ExcelName        string                       `description:"表格名称"`
-	UniqueCode       string                       `description:"表格唯一编码"`
-	ExcelClassifyId  int                          `description:"表格分类id"`
-	SysUserId        int                          `description:"操作人id"`
-	SysUserRealName  string                       `description:"操作人真实姓名"`
-	Content          string                       `description:"表格内容"`
-	ExcelImage       string                       `description:"表格图片"`
-	FileUrl          string                       `description:"表格下载地址"`
-	Sort             int                          `description:"排序字段,数字越小越排前面"`
-	IsDelete         int                          `description:"是否删除,0:未删除,1:已删除"`
-	ModifyTime       time.Time                    `description:"最近修改日期"`
-	CreateTime       time.Time                    `description:"创建日期"`
-	TableData        interface{}                  `description:"表格内容"`
-	Button           excel2.ExcelInfoDetailButton `description:"操作权限"`
-	CanEdit          bool                         `description:"是否可编辑"`
-	Editor           string                       `description:"编辑人"`
-	IsJoinPermission int                          `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
-	HaveOperaAuth    bool                         `description:"是否有数据权限"`
+	ExcelInfoId        int                          `orm:"column(excel_info_id);pk"`
+	Source             int                          `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
+	ExcelType          int                          `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName          string                       `description:"表格名称"`
+	UniqueCode         string                       `description:"表格唯一编码"`
+	ExcelClassifyId    int                          `description:"表格分类id"`
+	SysUserId          int                          `description:"操作人id"`
+	SysUserRealName    string                       `description:"操作人真实姓名"`
+	Content            string                       `description:"表格内容"`
+	ExcelImage         string                       `description:"表格图片"`
+	FileUrl            string                       `description:"表格下载地址"`
+	Sort               int                          `description:"排序字段,数字越小越排前面"`
+	IsDelete           int                          `description:"是否删除,0:未删除,1:已删除"`
+	ModifyTime         time.Time                    `description:"最近修改日期"`
+	CreateTime         time.Time                    `description:"创建日期"`
+	TableData          interface{}                  `description:"表格内容"`
+	Button             excel2.ExcelInfoDetailButton `description:"操作权限"`
+	CanEdit            bool                         `description:"是否可编辑"`
+	Editor             string                       `description:"编辑人"`
+	IsJoinPermission   int                          `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
+	HaveOperaAuth      bool                         `description:"是否有数据权限"`
+	ParentId           int                          `description:"表格的父级id"`
+	BalanceType        int                          `description:"平衡表类型:0 动态表,1静态表"`
+	UpdateUserId       int                          `description:"更新人id"`
+	UpdateUserRealName string                       `description:"更新人真实姓名"`
+	RelExcelInfoId     int                          `description:"平衡表里静态表关联的动态表excel id"`
 }
 
 // ExcelInfoDetailButton 操作按钮