package excel import ( "eta_gn/eta_api/global" "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/utils" "fmt" "time" ) type ExcelChartData struct { ExcelChartDataId int `orm:"column(excel_chart_data_id);pk" gorm:"primaryKey" ` ExcelInfoId int `description:"表格id"` ExcelChartEdbId int `description:"指标ID"` ChartInfoId int `description:"图表id"` DataTime string Value float64 ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` DataTimestamp int64 } func (e *ExcelChartData) TableName() string { return "excel_chart_data" } // 新增 func (e *ExcelChartData) Add() (err error) { err = global.DmSQL["data"].Create(e).Error return } // 修改 func (e *ExcelChartData) Update(cols []string) (err error) { err = global.DmSQL["data"].Select(cols).Updates(e).Error return } // 删除 func (e *ExcelChartData) Delete() (err error) { sql := ` DELETE FROM excel_chart_data WHERE excel_chart_data_id=? ` err = global.DmSQL["data"].Exec(sql, e.ExcelChartDataId).Error return } // 查询 func GetExcelChartDataByExcelInfoId(excelInfoId int) (list []*ExcelChartData, err error) { sql := ` SELECT * FROM excel_chart_data WHERE excel_info_id=? ORDER BY excel_chart_edb_id ASC, data_time desc, excel_chart_data_id ASC ` err = global.DmSQL["data"].Raw(sql, excelInfoId).Find(&list).Error return } func BatchUpdateChartEdbData(excelInfoId int, excelEdbMap map[int]*ExcelChartEdb, excelDataMap map[int][]*data_manage.EdbDataList) (err error) { to := global.DmSQL["data"].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := `delete from excel_chart_data where excel_info_id = ?` err = to.Exec(sql, excelInfoId).Error if err != nil { return } // 图表指标数据入库 addList := make([]*ExcelChartData, 0) for chartEdbId, dataList := range excelDataMap { chartEdb, ok := excelEdbMap[chartEdbId] if !ok { err = fmt.Errorf("chartEdbId:%d not exist", chartEdbId) return } for _, v := range dataList { chartData := &ExcelChartData{ ExcelInfoId: chartEdb.ExcelInfoId, ExcelChartEdbId: chartEdb.ExcelChartEdbId, ChartInfoId: chartEdb.ChartInfoId, DataTime: v.DataTime, Value: v.Value, DataTimestamp: v.DataTimestamp, ModifyTime: time.Now(), CreateTime: time.Now(), } addList = append(addList, chartData) // data信息入库 if len(addList) > 1000 { err = to.CreateInBatches(addList, utils.MultiAddNum).Error if err != nil { return } addList = addList[:0] } } } // data信息入库 if len(addList) > 0 { err = to.CreateInBatches(addList, utils.MultiAddNum).Error if err != nil { return } } return } func GetExcelChartDataByChartInfoId(chartInfoId int) (list []*ExcelChartData, err error) { sql := ` SELECT * FROM excel_chart_Data WHERE chart_info_id=? ORDER BY excel_chart_edb_id ASC ` err = global.DmSQL["data"].Raw(sql, chartInfoId).Find(&list).Error return }