作者 陈志颖

fix:获取名称去除分页

... ... @@ -477,7 +477,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
uidName := map[int64]interface{}{}
if _, employees, err := employeeRepository.Find(map[string]interface{}{
if _, employees, err := employeeRepository.FindAll(map[string]interface{}{
"companyId": contributionsWealthRankingQuery.CompanyId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -26,6 +26,7 @@ type EmployeeRepository interface {
FindOne(queryOptions map[string]interface{}) (*Employee, error)
Find(queryOptions map[string]interface{}) (int64, []*Employee, error)
FindByIds(queryOptions map[string]interface{}) (int64, []*Employee, error)
FindAll(queryOptions map[string]interface{}) (int64, []*Employee, error)
}
func (employee *Employee) Identify() interface{} {
... ...
... ... @@ -177,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
}
}
func (repository *EmployeeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
tx := repository.transactionContext.PgTx
var employeeModels []*models.Employee
employees := make([]*domain.Employee, 0)
query := tx.Model(&employeeModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("employee.company_id = ?", companyId)
}
if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
}
if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
}
if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
}
if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
query = query.Where("employee.company_id = ?", companyId)
}
}
if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
query = query.Where(`employee.status = ?`, status)
}
if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
query = query.Where("employee.is_principal = ? ", isPrincipal)
}
if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
return 0, employees, err
} else {
for _, employeeModel := range employeeModels {
if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
return 0, employees, err
} else {
employees = append(employees, employee)
}
}
return int64(count), employees, nil
}
}
func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
return &domain.Employee{
EmployeeId: employeeModel.Id,
... ...