浏览代码

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

xyxie 10 月之前
父节点
当前提交
d2a2dd0b6d

+ 5 - 0
controllers/data_manage/excel/excel_classify.go

@@ -755,8 +755,13 @@ func (this *ExcelClassifyController) DeleteExcelClassify() {
 			condition += " AND excel_classify_id=? "
 			pars = append(pars, excelInfo.ExcelClassifyId)
 
+			if excelInfo.Source == utils.BALANCE_TABLE {
+				condition += " AND parent_id=0 AND balance_type=0 "
+			}
+
 			condition += " AND (sort>? OR (sort=? AND excel_info_id<?) ) "
 			pars = append(pars, excelInfo.Sort, excelInfo.Sort, excelInfo.ExcelInfoId)
+
 			nextItem, err = excel.GetNextExcelInfoByCondition(condition, pars)
 			if err != nil && err.Error() != utils.ErrNoRow() {
 				br.Msg = "删除失败"

+ 62 - 0
models/data_manage/excel/excel_chart_edb.go

@@ -155,6 +155,10 @@ 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)) + `)`
 	_, err = o.Raw(sql, chartInfoId, updateIds).Exec()
+	if err != nil {
+		err = fmt.Errorf("更新图表id失败,AddChartEdbAndData: %v", err)
+		return
+	}
 
 	if len(edbInfoIdArrStr) > 0 {
 		edbInfoIdStr := strings.Join(edbInfoIdArrStr, ",")
@@ -243,6 +247,15 @@ func GetExcelChartEdbMappingByExcelInfoId(excelInfoId int) (list []*ExcelChartEd
 	return
 }
 
+func GetExcelChartEdbMappingByExcelInfoIds(excelInfoIds []int) (list []*ExcelChartEdb, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT *
+             FROM excel_chart_edb 
+			 WHERE excel_info_id in (` + utils.GetOrmInReplace(len(excelInfoIds)) + `)`
+	_, err = o.Raw(sql, excelInfoIds).QueryRows(&list)
+	return
+}
+
 func GetExcelChartEdbById(id int) (item *ExcelChartEdb, err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT * FROM excel_chart_edb WHERE excel_chart_edb_id=? `
@@ -259,3 +272,52 @@ func GetExcelChartEdbMappingByChartInfoId(chartInfoId int) (list []*ExcelChartEd
 	_, err = o.Raw(sql, chartInfoId).QueryRows(&list)
 	return
 }
+
+// 同时删除指标和指标数据
+func DeleteExcelChartEdbAndData(excelInfoIds []int, chartInfoIds []int) (err error) {
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+	// 把对应的表格状态改成删除状态
+	//更新图表id
+	sql := `update excel_info set is_delete = 1, modify_time = ? where excel_info_id in (` + utils.GetOrmInReplace(len(excelInfoIds)) + `)`
+	_, err = o.Raw(sql, time.Now(), excelInfoIds).Exec()
+	if err != nil {
+		err = fmt.Errorf("更新图表id失败,AddChartEdbAndData: %v", err)
+		return
+	}
+	// 把删除图表状态
+	if len(chartInfoIds) > 0 {
+		sql := `DELETE FROM chart_info WHERE  chart_info_id in (` + utils.GetOrmInReplace(len(chartInfoIds)) + `)`
+		_, err = o.Raw(sql, chartInfoIds).Exec()
+		if err != nil {
+			err = fmt.Errorf("删除原先的指标失败:%v", err)
+			return
+		}
+
+		// todo 如果加入到我的图库中,则删除我的图库中的数据
+	}
+	// 删除原先的绑定的指标
+	sql = `DELETE FROM excel_chart_edb WHERE  excel_info_id in (` + utils.GetOrmInReplace(len(excelInfoIds)) + `)`
+	_, err = o.Raw(sql, excelInfoIds).Exec()
+	if err != nil {
+		err = fmt.Errorf("删除原先的指标失败:%v", err)
+		return
+	}
+	// 删除指标数据
+	sql = `DELETE FROM excel_chart_data WHERE  excel_info_id in (` + utils.GetOrmInReplace(len(excelInfoIds)) + `)`
+	_, err = o.Raw(sql, excelInfoIds).Exec()
+	if err != nil {
+		err = fmt.Errorf("删除原先的指标失败:%v", err)
+		return
+	}
+	return
+}

+ 47 - 2
services/data/excel/excel_op.go

@@ -53,9 +53,54 @@ func Delete(excelInfo *excelModel.ExcelInfo, sysUser *system.Admin) (err error,
 			isSendEmail = false
 			return
 		}
-	}
+	} else if excelInfo.Source == utils.BALANCE_TABLE {
+		// todo 如果父级删除是否删除子表和静态表,同时删除图表和图表数据
+		excelIds := make([]int, 0)
+		//查询动态表所有的子表,并复制为静态表
+		condition := " AND source=?"
+		var pars []interface{}
+		pars = append(pars, utils.BALANCE_TABLE)
+		excelIds = append(excelIds, excelInfo.ExcelInfoId)
+		if excelInfo.ParentId == 0 {
+			if excelInfo.BalanceType == 0 {
+				condition += "  AND (parent_id = ? or rel_excel_info_id=?)"
+				pars = append(pars, excelInfo.ExcelInfoId, excelInfo.ExcelInfoId)
+			} else if excelInfo.BalanceType == 1 {
+				condition += " AND (parent_id = ?)"
+				pars = append(pars, excelInfo.ExcelInfoId)
+			}
+			excelList, e := excelModel.GetNoContentExcelInfoListByConditionNoPage(condition, pars)
+			if e != nil {
+				err = fmt.Errorf("获取子表失败 %s", err.Error())
+				errMsg = "获取子表失败"
+				return
+			}
+			for _, v := range excelList {
+				excelIds = append(excelIds, v.ExcelInfoId)
+			}
+		}
 
-	// todo 如果父级删除是否删除子表和静态表,同时删除图表和图表数据
+		// 相关联指标
+		mappingListTmp, e := excelModel.GetExcelChartEdbMappingByExcelInfoIds(excelIds)
+		if e != nil {
+			errMsg = "获取失败"
+			err = fmt.Errorf(" 获取图表,指标信息失败 Err:%s", e.Error())
+			return
+		}
+
+		charInfoIds := make([]int, 0)
+		for _, v := range mappingListTmp {
+			charInfoIds = append(charInfoIds, v.ChartInfoId)
+		}
+		err = excelModel.DeleteExcelChartEdbAndData(excelIds, charInfoIds)
+		if err != nil {
+			errMsg = "删除表格失败"
+			err = fmt.Errorf("删除图表,指标信息失败 Err:%s", err.Error())
+			return
+		}
+
+		return
+	}
 
 	// 标记删除
 	excelInfo.IsDelete = 1