1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package excel
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "time"
- )
- type ExcelWorker struct {
- ExcelWorkerId int `orm:"column(excel_worker_id);pk" gorm:"primaryKey" `
- ExcelInfoId int `description:"表格id"`
- SysUserId int `description:"创建人"`
- SysUserRealName string `description:"创建人姓名"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- }
- func (e *ExcelWorker) TableName() string {
- return "excel_worker"
- }
- // 新增 协作人
- func (e *ExcelWorker) AddWorker(excelInfoId int, addWorkers []*ExcelWorker, notDeleteWorkers []string) (err error) {
- to := global.DmSQL["data"].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- if len(notDeleteWorkers) > 0 {
- sql := `delete from excel_worker where excel_info_id = ? and sys_user_id not in (` + utils.GetOrmInReplace(len(notDeleteWorkers)) + `)`
- err = to.Exec(sql, excelInfoId, notDeleteWorkers).Error
- if err != nil {
- return
- }
- } else if len(notDeleteWorkers) == 0 { // 清空协作人
- sql := `delete from excel_worker where excel_info_id = ? `
- err = to.Exec(sql, excelInfoId).Error
- if err != nil {
- return
- }
- }
- if len(addWorkers) > 0 {
- //_, err = o.InsertMulti(len(addWorkers), addWorkers)
- err = to.CreateInBatches(addWorkers, utils.MultiAddNum).Error
- }
- return
- }
- // 修改
- func (e *ExcelWorker) Update(cols []string) (err error) {
- err = global.DmSQL["data"].Select(cols).Updates(e).Error
- return
- }
- // 删除
- func (e *ExcelWorker) Delete() (err error) {
- sql := ` DELETE FROM excel_worker WHERE excel_worker_id=? `
- err = global.DmSQL["data"].Exec(sql, e.ExcelWorkerId).Error
- return
- }
- // 查询
- func (e *ExcelWorker) GetByExcelInfoId(excelInfoId int) (items []*ExcelWorker, err error) {
- sql := `select * from excel_worker where excel_info_id = ? `
- err = global.DmSQL["data"].Raw(sql, excelInfoId).Find(&items).Error
- return
- }
- // 查询
- func (e *ExcelWorker) GetBySysUserId(sysUserId int) (items []*ExcelWorker, err error) {
- sql := `select * from excel_worker where sys_user_id = ? `
- err = global.DmSQL["data"].Raw(sql, sysUserId).Find(&items).Error
- return
- }
|