excel_sheet_data.go 2.0 KB

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