excel_sheet_data.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package excel
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ExcelSheetData excel表格详情表
  8. type ExcelSheetData struct {
  9. ExcelDataId int `orm:"column(excel_data_id);pk"`
  10. ExcelInfoId int `description:"数据归属的excel_info的id"`
  11. ExcelSheetId int `description:"数据归属sheet"`
  12. Sort int `description:"数据排序"`
  13. Data string `description:"数据,分页存储"`
  14. ModifyTime time.Time `description:"最近修改日期"`
  15. CreateTime time.Time `description:"创建日期"`
  16. }
  17. // Update 更新 excel表格的sheet基础信息
  18. func (ExcelSheetData *ExcelSheetData) Update(cols []string) (err error) {
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.Update(ExcelSheetData, cols...)
  21. return
  22. }
  23. // AddExcelSheetData 新增excel表格的sheet基础信息
  24. func AddExcelSheetData(excelInfo *ExcelSheetData) (err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. // 表格信息入库
  27. lastId, err := o.Insert(excelInfo)
  28. if err != nil {
  29. return
  30. }
  31. excelInfo.ExcelInfoId = int(lastId)
  32. return
  33. }
  34. // GetSheetDataListBySheetIdListAndPage 根据sheet_id列表和页码获取所有的sheet数据详情
  35. func GetSheetDataListBySheetIdListAndPage(excelSheetIdList []int, page int) (items []*ExcelSheetData, err error) {
  36. num := len(excelSheetIdList)
  37. if num <= 0 {
  38. return
  39. }
  40. o := orm.NewOrmUsingDB("data")
  41. sql := ` SELECT *
  42. FROM excel_sheet_data WHERE 1=1 AND excel_sheet_id in (` + utils.GetOrmInReplace(num) + `) AND sort = ? `
  43. _, err = o.Raw(sql, excelSheetIdList, page).QueryRows(&items)
  44. return
  45. }
  46. // GetAllSheetDataListByExcelInfoId 根据表格id获取所有的sheet的所有数据详情
  47. func GetAllSheetDataListByExcelInfoId(excelInfoId int) (items []*ExcelSheetData, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := ` SELECT *
  50. FROM excel_sheet_data WHERE 1=1 AND excel_info_id = ? ORDER BY sort ASC `
  51. _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  52. return
  53. }