소스 검색

Merge branch 'feature/eta1.8.5_excel_balance' into debug

xyxie 10 달 전
부모
커밋
87d42fcd8b

+ 1 - 13
controllers/data_manage/excel/balance_table.go

@@ -883,20 +883,8 @@ func (c *ExcelInfoController) DeleteBalanceChart() {
 			myIds = append(myIds, m.MyChartId)
 		}
 
-		// 查询图表相关联的数据
-		edbIds := make([]int, 0)
-		// 查询图表相关联的指标
-		edbList, e := excel.GetExcelChartEdbMappingByChartInfoId(req.ChartInfoId)
-		if e != nil {
-			br.Msg = "删除失败"
-			br.ErrMsg = "获取图表相关联的指标失败, Err: " + e.Error()
-			return
-		}
-		for _, v := range edbList {
-			edbIds = append(edbIds, v.ExcelChartEdbId)
-		}
 		//删除图表及关联指标
-		e = data_manage.DeleteBalanceExcelChartInfoAndData(req.ChartInfoId, edbIds)
+		e = excel.DeleteBalanceExcelChartInfoAndData(req.ChartInfoId)
 		if e != nil {
 			br.Msg = "删除失败"
 			br.ErrMsg = "删除失败,Err:" + e.Error()

+ 0 - 39
models/data_manage/chart_info.go

@@ -221,45 +221,6 @@ func DeleteChartInfoAndData(chartInfoId int) (err error) {
 	return
 }
 
-// 删除平衡表中的指标和数据
-func DeleteBalanceExcelChartInfoAndData(chartInfoId int, edbIds []int) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	to, err := o.Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = to.Rollback()
-		} else {
-			_ = to.Commit()
-		}
-	}()
-
-	sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
-	_, err = to.Raw(sql, chartInfoId).Exec()
-	if err != nil {
-		err = fmt.Errorf("删除平衡表图表失败 %s", err.Error())
-		return
-	}
-	sql = ` DELETE FROM  excel_chart_edb WHERE chart_info_id=? `
-	_, err = to.Raw(sql, chartInfoId).Exec()
-	if err != nil {
-		err = fmt.Errorf("删除平衡表图表指标失败 %s", err.Error())
-		return
-	}
-	// 删除表格里的数据
-	if len(edbIds) > 0 {
-		sql = ` DELETE FROM  excel_chart_data WHERE excel_chart_edb_id in (` + utils.GetOrmInReplace(len(edbIds)) + `)`
-		_, err = to.Raw(sql, edbIds).Exec()
-		if err != nil {
-			err = fmt.Errorf("删除平衡表图表指标数据失败 %s", err.Error())
-			return
-		}
-	}
-	return
-}
-
 func GetChartInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `

+ 38 - 1
models/data_manage/excel/excel_chart_edb.go

@@ -153,7 +153,7 @@ func (e *ExcelChartEdb) AddChartEdbAndData(list []*AddChartEdbAndDataItem, chart
 	}
 
 	//更新图表id
-	sql := `update excel_chart_edb set chart_info_id = ? where excel_chart_edb_id in (` + utils.GetOrmInReplace(len(updateIds)) + `)`
+	sql := `update excel_chart_edb set chart_info_id = ? where excel_chart_edb_id in (` + utils.GetOrmInReplace(len(updateIds)) + `) and chart_info_id=0`
 	_, err = o.Raw(sql, chartInfoId, updateIds).Exec()
 	if err != nil {
 		err = fmt.Errorf("更新图表id失败,AddChartEdbAndData: %v", err)
@@ -324,3 +324,40 @@ func DeleteExcelChartEdbAndData(excelInfoIds []int, chartInfoIds []int) (err err
 	}
 	return
 }
+
+// 删除平衡表中的指标和数据
+func DeleteBalanceExcelChartInfoAndData(chartInfoId int) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
+	_, err = to.Raw(sql, chartInfoId).Exec()
+	if err != nil {
+		err = fmt.Errorf("删除平衡表图表失败 %s", err.Error())
+		return
+	}
+	sql = ` DELETE FROM  excel_chart_edb WHERE chart_info_id=? `
+	_, err = to.Raw(sql, chartInfoId).Exec()
+	if err != nil {
+		err = fmt.Errorf("删除平衡表图表指标失败 %s", err.Error())
+		return
+	}
+	// 删除表格里的数据
+	sql = ` DELETE FROM  excel_chart_data WHERE chart_info_id=? `
+	_, err = to.Raw(sql, chartInfoId).Exec()
+	if err != nil {
+		err = fmt.Errorf("删除平衡表图表指标失败 %s", err.Error())
+		return
+	}
+	return
+}

+ 2 - 0
services/data/chart_info_excel_balance.go

@@ -347,6 +347,8 @@ func EditBalanceExcelChart(excelInfo *excelModel.ExcelInfo, req request.AddBalan
 				}
 			}
 		}
+
+		excelEdb.ExcelInfoId = excelInfo.ExcelInfoId
 		excelEdb.EdbName = chartEdb.EdbName
 		excelEdb.DateSequence = chartEdb.DateSequenceStr
 		excelEdb.DataSequence = chartEdb.DataSequenceStr