|
@@ -168,7 +168,11 @@ func DisabledUser(ctx context.Context, user string) (string, error) {
|
|
func GetEnterpriseUserList(ctx context.Context, pageSize, pageNum int32, conditions *common_model.EnterpriseUserConditions) ([]*http_model.EnterpriseUserPreview, int64, error) {
|
|
func GetEnterpriseUserList(ctx context.Context, pageSize, pageNum int32, conditions *common_model.EnterpriseUserConditions) ([]*http_model.EnterpriseUserPreview, int64, error) {
|
|
db := GetReadDB(ctx)
|
|
db := GetReadDB(ctx)
|
|
// 查询user表信息,筛选出企业用户
|
|
// 查询user表信息,筛选出企业用户
|
|
- db = db.Debug().Model([]gorm_model.YounggeeUser{}).Where("role = ? ", "3")
|
|
|
|
|
|
+ db = db.Model([]gorm_model.YounggeeUser{}).Where("role = ? ", "3")
|
|
|
|
+ if conditions.User != "" {
|
|
|
|
+ userId := GetUserIDByEnterpriseID(ctx, conditions.User)
|
|
|
|
+ db = db.Where("id = ?", userId)
|
|
|
|
+ }
|
|
// 根据 查询条件过滤
|
|
// 根据 查询条件过滤
|
|
conditionType := reflect.TypeOf(conditions).Elem()
|
|
conditionType := reflect.TypeOf(conditions).Elem()
|
|
conditionValue := reflect.ValueOf(conditions).Elem()
|
|
conditionValue := reflect.ValueOf(conditions).Elem()
|
|
@@ -177,23 +181,28 @@ func GetEnterpriseUserList(ctx context.Context, pageSize, pageNum int32, conditi
|
|
tag := field.Tag.Get("condition")
|
|
tag := field.Tag.Get("condition")
|
|
value := conditionValue.FieldByName(field.Name)
|
|
value := conditionValue.FieldByName(field.Name)
|
|
if !util.IsBlank(value) && tag != "created_at" && tag != "username" && tag != "user" {
|
|
if !util.IsBlank(value) && tag != "created_at" && tag != "username" && tag != "user" {
|
|
- db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
|
|
+ db = db.Debug().Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
} else if tag == "created_at" && value.Interface() != nil {
|
|
} else if tag == "created_at" && value.Interface() != nil {
|
|
db = db.Where(fmt.Sprintf("created_at like '%s%%'", value.Interface()))
|
|
db = db.Where(fmt.Sprintf("created_at like '%s%%'", value.Interface()))
|
|
- } else if (tag == "username" || tag == "user") && value.Interface() != nil {
|
|
|
|
- db = db.Where(fmt.Sprintf("username like '%%%s%%'", value.Interface()))
|
|
|
|
- } else if tag == "user" && value.Interface() != nil {
|
|
|
|
- db = db.Where(fmt.Sprintf("user like '%%%s%%'", value.Interface()))
|
|
|
|
|
|
+ } else if tag == "username" && value.Interface() != nil {
|
|
|
|
+ db = db.Debug().Where(fmt.Sprintf("username like '%%%s%%'", value.Interface()))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- var users []gorm_model.YounggeeUser
|
|
|
|
var totalUser int64
|
|
var totalUser int64
|
|
if err := db.Count(&totalUser).Error; err != nil {
|
|
if err := db.Count(&totalUser).Error; err != nil {
|
|
logrus.WithContext(ctx).Errorf("[GetEnterpriseUserList] error query mysql total, err:%+v", err)
|
|
logrus.WithContext(ctx).Errorf("[GetEnterpriseUserList] error query mysql total, err:%+v", err)
|
|
return nil, 0, err
|
|
return nil, 0, err
|
|
}
|
|
}
|
|
- db.Order("created_at desc").Find(&users)
|
|
|
|
|
|
|
|
|
|
+ var users []gorm_model.YounggeeUser
|
|
|
|
+ // 查询该页数据
|
|
|
|
+ limit := pageSize
|
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
|
+ err := db.Order("created_at desc").Limit(int(limit)).Offset(int(offset)).Find(&users).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetEnterpriseUserList] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
// 查询 用户自增的id
|
|
// 查询 用户自增的id
|
|
var userIds []int64
|
|
var userIds []int64
|
|
userMap := make(map[int64]gorm_model.YounggeeUser)
|
|
userMap := make(map[int64]gorm_model.YounggeeUser)
|
|
@@ -204,16 +213,8 @@ func GetEnterpriseUserList(ctx context.Context, pageSize, pageNum int32, conditi
|
|
|
|
|
|
db1 := GetReadDB(ctx)
|
|
db1 := GetReadDB(ctx)
|
|
var enterprises []gorm_model.Enterprise
|
|
var enterprises []gorm_model.Enterprise
|
|
- db1 = db1.Debug().Model(gorm_model.Enterprise{}).Where("user_id IN ?", userIds).Find(&enterprises)
|
|
|
|
|
|
+ db1 = db1.Model(gorm_model.Enterprise{}).Where("user_id IN ?", userIds).Find(&enterprises)
|
|
|
|
|
|
- // 查询该页数据
|
|
|
|
- limit := pageSize
|
|
|
|
- offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
|
- err := db.Order("created_at desc").Limit(int(limit)).Offset(int(offset)).Error
|
|
|
|
- if err != nil {
|
|
|
|
- logrus.WithContext(ctx).Errorf("[GetEnterpriseUserList] error query mysql total, err:%+v", err)
|
|
|
|
- return nil, 0, err
|
|
|
|
- }
|
|
|
|
enterpriseMap := make(map[int64]gorm_model.Enterprise)
|
|
enterpriseMap := make(map[int64]gorm_model.Enterprise)
|
|
for _, enterprise := range enterprises {
|
|
for _, enterprise := range enterprises {
|
|
enterpriseMap[enterprise.UserID] = enterprise
|
|
enterpriseMap[enterprise.UserID] = enterprise
|
|
@@ -246,12 +247,14 @@ func GetCreatorList(ctx context.Context, pageSize, pageNum int32, conditions *co
|
|
field := conditionType.Field(i)
|
|
field := conditionType.Field(i)
|
|
tag := field.Tag.Get("condition")
|
|
tag := field.Tag.Get("condition")
|
|
value := conditionValue.FieldByName(field.Name)
|
|
value := conditionValue.FieldByName(field.Name)
|
|
- if !util.IsBlank(value) && tag != "create_date" && tag != "talent_wx_nickname" {
|
|
|
|
- db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
|
|
+ if !util.IsBlank(value) && tag != "create_date" && tag != "talent_wx_nickname" && tag != "id" {
|
|
|
|
+ db = db.Debug().Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
} else if tag == "create_date" && value.Interface() != nil {
|
|
} else if tag == "create_date" && value.Interface() != nil {
|
|
db = db.Where(fmt.Sprintf("create_date like '%s%%'", value.Interface()))
|
|
db = db.Where(fmt.Sprintf("create_date like '%s%%'", value.Interface()))
|
|
} else if tag == "talent_wx_nickname" && value.Interface() != nil {
|
|
} else if tag == "talent_wx_nickname" && value.Interface() != nil {
|
|
db = db.Where(fmt.Sprintf("talent_wx_nickname like '%%%s%%'", value.Interface()))
|
|
db = db.Where(fmt.Sprintf("talent_wx_nickname like '%%%s%%'", value.Interface()))
|
|
|
|
+ } else if tag == "id" && value.Interface() != nil {
|
|
|
|
+ db = db.Where(fmt.Sprintf("id like '%%%s%%'", value.Interface()))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|