excel_sheet.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // ExcelSheet excel表格详情表
  9. type ExcelSheet struct {
  10. ExcelSheetId int `orm:"column(excel_sheet_id);pk" gorm:"primaryKey" `
  11. ExcelInfoId int `description:"excel的id"`
  12. SheetName string `description:"sheet名称"`
  13. PageNum int `description:"总页码数"`
  14. Index string `description:"excel数据中的index"`
  15. Sort int `description:"排序"`
  16. Config string `description:"配置信息"`
  17. CalcChain string `description:"计算公式"`
  18. ModifyTime time.Time `description:"最近修改日期"`
  19. CreateTime time.Time `description:"创建日期"`
  20. }
  21. // Update 更新 excel表格的sheet基础信息
  22. func (excelSheet *ExcelSheet) Update(cols []string) (err error) {
  23. err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(excelSheet).Error
  24. return
  25. }
  26. // AddExcelSheet 新增excel表格的sheet基础信息
  27. func AddExcelSheet(excelInfo *ExcelSheet) (err error) {
  28. o := orm.NewOrmUsingDB("data")
  29. // 表格信息入库
  30. lastId, err := o.Insert(excelInfo)
  31. if err != nil {
  32. return
  33. }
  34. excelInfo.ExcelInfoId = int(lastId)
  35. return
  36. }
  37. // GetAllSheetList 根据excel_id获取所有的sheet
  38. func GetAllSheetList(excelInfoId int) (item []*ExcelSheet, err error) {
  39. sql := ` SELECT *
  40. FROM excel_sheet WHERE 1=1 AND excel_info_id = ? `
  41. sql += " ORDER BY sort asc "
  42. err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).Find(&item).Error
  43. return
  44. }
  45. // SheetItem excel表格详情表
  46. type SheetItem struct {
  47. ExcelSheetId int `orm:"column(excel_sheet_id);pk" gorm:"primaryKey" json:"-"`
  48. ExcelInfoId int `description:"excel的id" json:"-"`
  49. SheetName string `description:"sheet名称"`
  50. PageNum int `description:"数据总页码数"`
  51. Index string `description:"excel数据中的index"`
  52. Sort int `description:"排序"`
  53. Config string `description:"sheet配置"`
  54. CalcChain string `description:"计算公式"`
  55. ModifyTime time.Time `description:"最近修改日期" json:"-"`
  56. CreateTime time.Time `description:"创建日期"`
  57. Data *ExcelSheetData `gorm:"-" description:"excel的数据"`
  58. }
  59. // GetAllSheetItemList 根据excel_id获取所有的sheet详情
  60. func GetAllSheetItemList(excelInfoId int) (item []*SheetItem, err error) {
  61. sql := ` SELECT *
  62. FROM excel_sheet WHERE 1=1 AND excel_info_id = ? `
  63. sql += " ORDER BY sort asc "
  64. err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).Find(&item).Error
  65. return
  66. }
  67. // GetAllNoConfigSheetItemList 根据excel_id获取所有的sheet详情
  68. func GetAllNoConfigSheetItemList(excelInfoId int) (item []*SheetItem, err error) {
  69. sql := ` SELECT excel_sheet_id,excel_info_id,sheet_name,sort,page_num,create_time
  70. FROM excel_sheet WHERE 1=1 AND excel_info_id = ? `
  71. sql += " ORDER BY sort asc "
  72. err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).Find(&item).Error
  73. return
  74. }
  75. // AddExcelSheetParams excel表格详情表
  76. type AddExcelSheetParams struct {
  77. ExcelSheetId int `orm:"column(excel_sheet_id);pk" gorm:"primaryKey" `
  78. ExcelInfoId int `description:"excel的id"`
  79. SheetName string `description:"sheet名称"`
  80. Index string `description:"excel数据中的index"`
  81. Sort int `description:"排序"`
  82. Config string `description:"配置信息"`
  83. CalcChain string `description:"计算公式"`
  84. DataList []*ExcelSheetData `description:"excel的数据"`
  85. }