sys_user.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package wx_crm
  2. import (
  3. "eta/eta_bridge/global"
  4. "gorm.io/gorm/clause"
  5. "time"
  6. )
  7. type SysUser struct {
  8. SysUserId int `orm:"pk" description:"系统用户id"`
  9. SysUserName string `description:"账号"`
  10. SysRealName string `description:"姓名"`
  11. Password string `description:"密码"`
  12. Email string `description:"邮箱"`
  13. Phone string `description:"手机号"`
  14. AreaCode string `description:"手机区号"`
  15. SysRoleId int `description:"角色id"`
  16. SysRoleName string `description:"角色名称"`
  17. SysDepartmentId int `description:"所属部门id"`
  18. SysDepartmentId1 int `description:"所属部门一级id"`
  19. SysDepartmentId2 int `description:"所属部门二级id"`
  20. SysDepartmentId3 int `description:"所属部门三级id"`
  21. SysDepartmentId4 int `description:"所属部门四级id"`
  22. Province string `description:"省"`
  23. City string `description:"市"`
  24. PositionName string `description:"职位名称"`
  25. PositionCode int `description:"职位编码"`
  26. IsEnabled bool `description:"是否启用"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"更新时间"`
  29. }
  30. func (s *SysUser) TableName() string {
  31. return "sys_user"
  32. }
  33. func BatchInsertOrUpdateUser(users []SysUser) (err error) {
  34. db := global.MYSQL["ht_crm"]
  35. OnConflictFunc := clause.OnConflict{
  36. Columns: []clause.Column{{Name: "sys_user_name"}},
  37. DoUpdates: clause.AssignmentColumns([]string{"sys_real_name", "email", "phone", "position_name", "position_code", "sys_department_id", "sys_department_id1", "sys_department_id2", "sys_department_id3", "sys_department_id4"}),
  38. }
  39. // 执行批量插入或更新操作
  40. err = db.Clauses(OnConflictFunc).Create(&users).Error
  41. return
  42. }