excel_worker.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package excel
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type ExcelWorker struct {
  8. ExcelWorkerId int `orm:"column(excel_worker_id);pk"`
  9. ExcelInfoId int `description:"表格id"`
  10. SysUserId int `description:"创建人"`
  11. SysUserRealName string `description:"创建人姓名"`
  12. ModifyTime time.Time `description:"修改时间"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. func (e *ExcelWorker) TableName() string {
  16. return "excel_worker"
  17. }
  18. // 新增 协作人
  19. func (e *ExcelWorker) AddWorker(excelInfoId int, addWorkers []*ExcelWorker, notDeleteWorkers []string) (err error) {
  20. o, err := orm.NewOrmUsingDB("data").Begin()
  21. if err != nil {
  22. return
  23. }
  24. defer func() {
  25. if err != nil {
  26. _ = o.Rollback()
  27. } else {
  28. _ = o.Commit()
  29. }
  30. }()
  31. if len(notDeleteWorkers) > 0 {
  32. sql := `delete from excel_worker where excel_info_id = ? and sys_user_id not in (` + utils.GetOrmInReplace(len(notDeleteWorkers)) + `)`
  33. _, err = o.Raw(sql, excelInfoId, notDeleteWorkers).Exec()
  34. if err != nil {
  35. return
  36. }
  37. } else if len(notDeleteWorkers) == 0 { // 清空协作人
  38. sql := `delete from excel_worker where excel_info_id = ? `
  39. _, err = o.Raw(sql, excelInfoId).Exec()
  40. if err != nil {
  41. return
  42. }
  43. }
  44. if len(addWorkers) > 0 {
  45. _, err = o.InsertMulti(len(addWorkers), addWorkers)
  46. }
  47. return
  48. }
  49. // 修改
  50. func (e *ExcelWorker) Update(cols []string) (err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. _, err = o.Update(e, cols...)
  53. return
  54. }
  55. // 删除
  56. func (e *ExcelWorker) Delete() (err error) {
  57. o := orm.NewOrmUsingDB("data")
  58. _, err = o.Delete(e)
  59. return
  60. }
  61. // 查询
  62. func (e *ExcelWorker) GetByExcelInfoId(excelInfoId int) (items []*ExcelWorker, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := `select * from excel_worker where excel_info_id = ? `
  65. _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  66. return
  67. }
  68. // 查询
  69. func (e *ExcelWorker) GetBySysUserId(sysUserId int) (items []*ExcelWorker, err error) {
  70. o := orm.NewOrmUsingDB("data")
  71. sql := `select * from excel_worker where sys_user_id = ? `
  72. _, err = o.Raw(sql, sysUserId).QueryRows(&items)
  73. return
  74. }