|
@@ -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
|
|
|
+}
|