user.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package eta_trial
  2. import (
  3. "eta/eta_forum_hub/models/eta_trial"
  4. "fmt"
  5. "time"
  6. )
  7. func EtaTrialManualUserAddAuth(adminId int, adminName string) (err error) {
  8. if adminId <= 0 {
  9. err = fmt.Errorf("CreateManualAuth参数有误, AdminId: %d", adminId)
  10. return
  11. }
  12. // 从ETA试用平台的edb库中读取手工数据分类
  13. classifyIds := make([]int, 0)
  14. {
  15. classifyOb := new(eta_trial.EdbdataClassify)
  16. cond := `is_show = 1`
  17. pars := make([]interface{}, 0)
  18. list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "")
  19. if e != nil {
  20. err = fmt.Errorf("操作失败", "获取手工数据分类失败, Err: "+e.Error())
  21. return
  22. }
  23. for _, v := range list {
  24. classifyIds = append(classifyIds, v.ClassifyId)
  25. }
  26. }
  27. // 新增用户及权限
  28. manualUser := new(eta_trial.ManualUser)
  29. manualUser.AdminId = adminId
  30. manualUser.AdminRealName = adminName
  31. manualUser.CreateTime = time.Now().Local()
  32. if e := manualUser.Create(); e != nil {
  33. err = fmt.Errorf("操作失败", "新增权限用户失败, Err: "+e.Error())
  34. return
  35. }
  36. userClassifies := make([]*eta_trial.ManualUserClassify, 0)
  37. for _, v := range classifyIds {
  38. userClassifies = append(userClassifies, &eta_trial.ManualUserClassify{
  39. AdminId: adminId,
  40. ClassifyId: v,
  41. CreateTime: time.Now().Local(),
  42. })
  43. }
  44. userClassifyOb := new(eta_trial.ManualUserClassify)
  45. if e := userClassifyOb.BatchCreate(userClassifies); e != nil {
  46. err = fmt.Errorf("操作失败", "批量新增权限用户分类失败, Err: "+e.Error())
  47. return
  48. }
  49. return
  50. }