excel_worker.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package excel
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type ExcelWorker struct {
  8. ExcelWorkerId int `orm:"column(excel_worker_id);pk" gorm:"primaryKey" `
  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. to := global.DmSQL["data"].Begin()
  21. defer func() {
  22. if err != nil {
  23. _ = to.Rollback()
  24. } else {
  25. _ = to.Commit()
  26. }
  27. }()
  28. if len(notDeleteWorkers) > 0 {
  29. sql := `delete from excel_worker where excel_info_id = ? and sys_user_id not in (` + utils.GetOrmInReplace(len(notDeleteWorkers)) + `)`
  30. err = to.Exec(sql, excelInfoId, notDeleteWorkers).Error
  31. if err != nil {
  32. return
  33. }
  34. } else if len(notDeleteWorkers) == 0 { // 清空协作人
  35. sql := `delete from excel_worker where excel_info_id = ? `
  36. err = to.Exec(sql, excelInfoId).Error
  37. if err != nil {
  38. return
  39. }
  40. }
  41. if len(addWorkers) > 0 {
  42. //_, err = o.InsertMulti(len(addWorkers), addWorkers)
  43. err = to.CreateInBatches(addWorkers, utils.MultiAddNum).Error
  44. }
  45. return
  46. }
  47. // 修改
  48. func (e *ExcelWorker) Update(cols []string) (err error) {
  49. err = global.DmSQL["data"].Select(cols).Updates(e).Error
  50. return
  51. }
  52. // 删除
  53. func (e *ExcelWorker) Delete() (err error) {
  54. sql := ` DELETE FROM excel_worker WHERE excel_worker_id=? `
  55. err = global.DmSQL["data"].Exec(sql, e.ExcelWorkerId).Error
  56. return
  57. }
  58. // 查询
  59. func (e *ExcelWorker) GetByExcelInfoId(excelInfoId int) (items []*ExcelWorker, err error) {
  60. sql := `select * from excel_worker where excel_info_id = ? `
  61. err = global.DmSQL["data"].Raw(sql, excelInfoId).Find(&items).Error
  62. return
  63. }
  64. // 查询
  65. func (e *ExcelWorker) GetBySysUserId(sysUserId int) (items []*ExcelWorker, err error) {
  66. sql := `select * from excel_worker where sys_user_id = ? `
  67. err = global.DmSQL["data"].Raw(sql, sysUserId).Find(&items).Error
  68. return
  69. }