detect.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package models
  2. import (
  3. "annual-lottery2/models/model"
  4. "annual-lottery2/utils"
  5. "strings"
  6. )
  7. // UserFilters 用户过滤
  8. func UserFilters(lvl string) ([]model.TaUser, string) {
  9. cf := "./conf/test.conf"
  10. usrs := make([]model.TaUser, 0)
  11. notIn := make([]string, 0)
  12. if !utils.FileExists(cf) {
  13. return usrs, ""
  14. }
  15. conf, err := utils.GetConfig(cf)
  16. if err != nil {
  17. return usrs, ""
  18. }
  19. pls := conf.String("conf")
  20. if pls == "" {
  21. return usrs, ""
  22. }
  23. for _, pl := range strings.Split(pls, ",") {
  24. for _, us := range strings.Split(conf.DefaultString(pl+"::us", ""), ",") {
  25. if us == "" {
  26. continue
  27. }
  28. usArr := strings.Split(us, "-")
  29. if pl == lvl {
  30. usrs = append(usrs, model.TaUser{
  31. UserName: usArr[1],
  32. UserOrg: usArr[0],
  33. })
  34. } else {
  35. notIn = append(notIn, "user_name = '"+usArr[1]+"' and user_org = '"+usArr[0]+"'")
  36. }
  37. }
  38. }
  39. notExists := ""
  40. if len(notIn) > 0 {
  41. notExists = "select * from ta_user o where o.user_id = t.user_id and ((" + strings.Join(notIn, ") or (") + "))"
  42. }
  43. return usrs, notExists
  44. }