作者 陈志颖

fix:获取名称去除分页

@@ -477,7 +477,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -477,7 +477,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
477 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 477 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
478 } else { 478 } else {
479 uidName := map[int64]interface{}{} 479 uidName := map[int64]interface{}{}
480 - if _, employees, err := employeeRepository.Find(map[string]interface{}{ 480 + if _, employees, err := employeeRepository.FindAll(map[string]interface{}{
481 "companyId": contributionsWealthRankingQuery.CompanyId, 481 "companyId": contributionsWealthRankingQuery.CompanyId,
482 }); err != nil { 482 }); err != nil {
483 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 483 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -26,6 +26,7 @@ type EmployeeRepository interface { @@ -26,6 +26,7 @@ type EmployeeRepository interface {
26 FindOne(queryOptions map[string]interface{}) (*Employee, error) 26 FindOne(queryOptions map[string]interface{}) (*Employee, error)
27 Find(queryOptions map[string]interface{}) (int64, []*Employee, error) 27 Find(queryOptions map[string]interface{}) (int64, []*Employee, error)
28 FindByIds(queryOptions map[string]interface{}) (int64, []*Employee, error) 28 FindByIds(queryOptions map[string]interface{}) (int64, []*Employee, error)
  29 + FindAll(queryOptions map[string]interface{}) (int64, []*Employee, error)
29 } 30 }
30 31
31 func (employee *Employee) Identify() interface{} { 32 func (employee *Employee) Identify() interface{} {
@@ -177,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) @@ -177,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
177 } 177 }
178 } 178 }
179 179
  180 +func (repository *EmployeeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
  181 + tx := repository.transactionContext.PgTx
  182 + var employeeModels []*models.Employee
  183 + employees := make([]*domain.Employee, 0)
  184 + query := tx.Model(&employeeModels)
  185 + if companyId, ok := queryOptions["companyId"]; ok {
  186 + query = query.Where("employee.company_id = ?", companyId)
  187 + }
  188 + if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
  189 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
  190 + }
  191 + if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
  192 + query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
  193 + }
  194 + if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
  195 + if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
  196 + query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
  197 + }
  198 + if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
  199 + query = query.Where("employee.company_id = ?", companyId)
  200 + }
  201 + }
  202 + if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
  203 + query = query.Where(`employee.status = ?`, status)
  204 + }
  205 + if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
  206 + query = query.Where("employee.is_principal = ? ", isPrincipal)
  207 + }
  208 + if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
  209 + return 0, employees, err
  210 + } else {
  211 + for _, employeeModel := range employeeModels {
  212 + if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
  213 + return 0, employees, err
  214 + } else {
  215 + employees = append(employees, employee)
  216 + }
  217 + }
  218 + return int64(count), employees, nil
  219 + }
  220 +}
  221 +
180 func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) { 222 func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
181 return &domain.Employee{ 223 return &domain.Employee{
182 EmployeeId: employeeModel.Id, 224 EmployeeId: employeeModel.Id,