excel_sheet_data.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package excel
  2. import (
  3. "eta/eta_chart_lib/global"
  4. "eta/eta_chart_lib/utils"
  5. "time"
  6. )
  7. // ExcelSheetData excel表格详情表
  8. type ExcelSheetData struct {
  9. //ExcelDataId int `orm:"column(excel_data_id);pk"`
  10. ExcelDataId int `gorm:"column:excel_data_id;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. err = global.DbMap[utils.DbNameIndex].Model(&ExcelSheetData).Select(cols).Updates(&ExcelSheetData).Error
  23. return
  24. }
  25. // AddExcelSheetData 新增excel表格的sheet基础信息
  26. func AddExcelSheetData(excelInfo *ExcelSheetData) (err error) {
  27. //o := orm.NewOrmUsingDB("data")
  28. // 表格信息入库
  29. //lastId, err := o.Insert(excelInfo)
  30. err = global.DbMap[utils.DbNameIndex].Create(&excelInfo).Error
  31. if err != nil {
  32. return
  33. }
  34. //excelInfo.ExcelInfoId = int(lastId)
  35. return
  36. }
  37. // GetSheetDataListBySheetIdListAndPage 根据sheet_id列表和页码获取所有的sheet数据详情
  38. func GetSheetDataListBySheetIdListAndPage(excelSheetIdList []int, page int) (items []*ExcelSheetData, err error) {
  39. num := len(excelSheetIdList)
  40. if num <= 0 {
  41. return
  42. }
  43. //o := orm.NewOrmUsingDB("data")
  44. // sql := ` SELECT *
  45. //FROM excel_sheet_data WHERE 1=1 AND excel_sheet_id in (` + utils.GetOrmInReplace(num) + `) AND sort = ? `
  46. sql := ` SELECT *
  47. FROM excel_sheet_data WHERE 1=1 AND excel_sheet_id in ? AND sort = ? `
  48. //_, err = o.Raw(sql, excelSheetIdList, page).QueryRows(&items)
  49. err = global.DbMap[utils.DbNameIndex].Raw(sql, excelSheetIdList, page).Find(&items).Error
  50. return
  51. }
  52. // GetAllSheetDataListByExcelInfoId 根据表格id获取所有的sheet的所有数据详情
  53. func GetAllSheetDataListByExcelInfoId(excelInfoId int) (items []*ExcelSheetData, err error) {
  54. //o := orm.NewOrmUsingDB("data")
  55. sql := ` SELECT *
  56. FROM excel_sheet_data WHERE 1=1 AND excel_info_id = ? ORDER BY sort ASC `
  57. //_, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  58. err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).Find(&items).Error
  59. return
  60. }