eta_trial_manual.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package eta_trial
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // ETATrialManualClassify ETA试用-手工数据分类
  7. type ETATrialManualClassify struct {
  8. ClassifyId int `description:"分类ID"`
  9. ClassifyName string `description:"分类名称"`
  10. ParentId int `description:"父级ID"`
  11. }
  12. // GetETATrialManualClassify 获取ETA试用手工数据分类
  13. func GetETATrialManualClassify() (items []*ETATrialManualClassify, err error) {
  14. o := orm.NewOrmUsingDB("weekly_trial")
  15. sql := `SELECT classify_id, classify_name, parent_id FROM edb_trial_new.edbdata_classify WHERE is_show=1 ORDER BY sort ASC`
  16. _, err = o.Raw(sql).QueryRows(&items)
  17. return
  18. }
  19. // ETATrialUserAdmin ETA试用-试用客户
  20. type ETATrialUserAdmin struct {
  21. AdminId int `description:"用户ID"`
  22. RealName string `description:"用户姓名"`
  23. }
  24. // GetNoAuthTrialUserIds 查询未分配手工权限的试用客户
  25. func GetNoAuthTrialUserIds() (items []*ETATrialUserAdmin, err error) {
  26. o := orm.NewOrmUsingDB("weekly_trial")
  27. sql := `SELECT a.admin_id, a.real_name FROM weekly_report_trial.admin AS a
  28. WHERE a.admin_id NOT IN (
  29. SELECT DISTINCT b.admin_id FROM hz_data_trial_new.manual_user_classify AS b
  30. )
  31. AND a.department_id = 12 AND a.department_name = "ETA试用客户"`
  32. _, err = o.Raw(sql).QueryRows(&items)
  33. return
  34. }
  35. // InsertTrialUserManualAuth 新增试用客户手工录入权限
  36. func InsertTrialUserManualAuth(adminId int, adminRealName string, classifyIds []int) (err error) {
  37. o := orm.NewOrmUsingDB("weekly_trial")
  38. tx, err := o.Begin()
  39. if err != nil {
  40. return
  41. }
  42. defer func() {
  43. if err != nil {
  44. _ = tx.Rollback()
  45. } else {
  46. _ = tx.Commit()
  47. }
  48. }()
  49. // 新增权限用户
  50. sql := `INSERT INTO hz_data_trial_new.manual_user (admin_id, admin_real_name, sys_user_id, sys_user_real_name, create_time) VALUES ("%d", "%s", 0, "", NOW())`
  51. sql = fmt.Sprintf(sql, adminId, adminRealName)
  52. if _, err = tx.Raw(sql).Exec(); err != nil {
  53. return
  54. }
  55. // 新增权限分类
  56. for i := range classifyIds {
  57. sql = `INSERT INTO hz_data_trial_new.manual_user_classify (admin_id, classify_id, create_time) VALUES ("%d", "%d", NOW())`
  58. sql = fmt.Sprintf(sql, adminId, classifyIds[i])
  59. if _, err = tx.Raw(sql).Exec(); err != nil {
  60. return
  61. }
  62. }
  63. return
  64. }