作者 陈志颖

test:测试删除用户

@@ -142,7 +142,10 @@ func (columnSettingService *ColumnSettingService) ListColumnSetting(listColumnSe @@ -142,7 +142,10 @@ func (columnSettingService *ColumnSettingService) ListColumnSetting(listColumnSe
142 } else { 142 } else {
143 columnSettingRepository = value 143 columnSettingRepository = value
144 } 144 }
145 - if count, columnSettings, err := columnSettingRepository.Find(tool_funs.SimpleStructToMap(listColumnSettingQuery)); err != nil { 145 + if count, columnSettings, err := columnSettingRepository.Find(domain.ColumnSettingFindQuery{
  146 + Offset: listColumnSettingQuery.Offset,
  147 + Limit: listColumnSettingQuery.Limit,
  148 + }); err != nil {
146 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 149 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
147 } else { 150 } else {
148 if err := transactionContext.CommitTransaction(); err != nil { 151 if err := transactionContext.CommitTransaction(); err != nil {
@@ -361,7 +361,10 @@ func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error @@ -361,7 +361,10 @@ func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error
361 } else { 361 } else {
362 columnSettingRepository = value 362 columnSettingRepository = value
363 } 363 }
364 - _, columnSettingsFound, err := columnSettingRepository.Find(map[string]interface{}{"ids": data.Ids, "companyId": data.CompanyId}) 364 + _, columnSettingsFound, err := columnSettingRepository.Find(domain.ColumnSettingFindQuery{
  365 + Ids: data.Ids,
  366 + CompanyId: int(data.CompanyId),
  367 + })
365 if err != nil { 368 if err != nil {
366 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 369 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
367 } 370 }
@@ -92,11 +92,20 @@ type ColumnSetting struct { @@ -92,11 +92,20 @@ type ColumnSetting struct {
92 InvalidValue []Column `json:"invalidValue"` 92 InvalidValue []Column `json:"invalidValue"`
93 } 93 }
94 94
  95 +type ColumnSettingFindQuery struct {
  96 + Ids []int64
  97 + Uid int64
  98 + CompanyId int
  99 + Offset int
  100 + Limit int
  101 +}
  102 +
95 type ColumnSettingRepository interface { 103 type ColumnSettingRepository interface {
96 Save(columnSetting *ColumnSetting) (*ColumnSetting, error) 104 Save(columnSetting *ColumnSetting) (*ColumnSetting, error)
97 Remove(columnSetting *ColumnSetting, columnSettings []*ColumnSetting) (*ColumnSetting, []*ColumnSetting, error) 105 Remove(columnSetting *ColumnSetting, columnSettings []*ColumnSetting) (*ColumnSetting, []*ColumnSetting, error)
98 FindOne(queryOptions map[string]interface{}) (*ColumnSetting, error) 106 FindOne(queryOptions map[string]interface{}) (*ColumnSetting, error)
99 - Find(queryOptions map[string]interface{}) (int64, []*ColumnSetting, error) 107 + //Find(queryOptions map[string]interface{}) (int64, []*ColumnSetting, error)
  108 + Find(ColumnSettingFindQuery) (int64, []*ColumnSetting, error)
100 } 109 }
101 110
102 func (columnSetting *ColumnSetting) Identify() interface{} { 111 func (columnSetting *ColumnSetting) Identify() interface{} {
@@ -118,36 +118,53 @@ func (repository *ColumnSettingRepository) FindOne(queryOptions map[string]inter @@ -118,36 +118,53 @@ func (repository *ColumnSettingRepository) FindOne(queryOptions map[string]inter
118 } 118 }
119 } 119 }
120 120
121 -func (repository *ColumnSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ColumnSetting, error) { 121 +func (repository *ColumnSettingRepository) Find(queryOptions domain.ColumnSettingFindQuery) (int64, []*domain.ColumnSetting, error) {
122 tx := repository.transactionContext.PgTx 122 tx := repository.transactionContext.PgTx
123 var columnSettingModels []*models.ColumnSetting 123 var columnSettingModels []*models.ColumnSetting
124 columnSettings := make([]*domain.ColumnSetting, 0) 124 columnSettings := make([]*domain.ColumnSetting, 0)
125 query := tx.Model(&columnSettingModels) 125 query := tx.Model(&columnSettingModels)
126 - if ids, ok := queryOptions["ids"]; ok && len(ids.([]int64)) != 0 {  
127 - query = query.Where("column_setting.uid in(?)", ids) 126 + if len(queryOptions.Ids) > 0 {
  127 + query = query.Where("column_setting.uid in(?)", queryOptions.Ids)
128 } 128 }
129 - if uid, ok := queryOptions["uid"]; ok {  
130 - query = query.Where("column_setting.uid = ?", uid)  
131 - }  
132 - if companyId, ok := queryOptions["companyId"]; ok {  
133 - query = query.Where("column_setting.company_id = ?", companyId)  
134 - }  
135 - if offset, ok := queryOptions["offset"]; ok {  
136 - queryOffset := offset.(int)  
137 - if queryOffset > -1 {  
138 - query = query.Offset(queryOffset) 129 + if queryOptions.Uid > 0 {
  130 + query = query.Where("column_setting.uid = ?", queryOptions.Uid)
139 } 131 }
140 - } else {  
141 - query = query.Offset(0) 132 + if queryOptions.CompanyId > 0 {
  133 + query = query.Where("column_setting.company_id = ?", queryOptions.CompanyId)
142 } 134 }
143 - if limit, ok := queryOptions["limit"]; ok {  
144 - queryLimit := limit.(int)  
145 - if queryLimit > -1 {  
146 - query = query.Limit(queryLimit) 135 + if queryOptions.Offset > -1 {
  136 + query = query.Offset(queryOptions.Offset)
147 } 137 }
  138 + if queryOptions.Limit > 0 {
  139 + query = query.Limit(queryOptions.Limit)
148 } else { 140 } else {
149 query = query.Limit(20) 141 query = query.Limit(20)
150 } 142 }
  143 + //if ids, ok := queryOptions["ids"]; ok && len(ids.([]int64)) != 0 {
  144 + // query = query.Where("column_setting.uid in(?)", ids)
  145 + //}
  146 + //if uid, ok := queryOptions["uid"]; ok {
  147 + // query = query.Where("column_setting.uid = ?", uid)
  148 + //}
  149 + //if companyId, ok := queryOptions["companyId"]; ok {
  150 + // query = query.Where("column_setting.company_id = ?", companyId)
  151 + //}
  152 + //if offset, ok := queryOptions["offset"]; ok {
  153 + // queryOffset := offset.(int)
  154 + // if queryOffset > -1 {
  155 + // query = query.Offset(queryOffset)
  156 + // }
  157 + //} else {
  158 + // query = query.Offset(0)
  159 + //}
  160 + //if limit, ok := queryOptions["limit"]; ok {
  161 + // queryLimit := limit.(int)
  162 + // if queryLimit > -1 {
  163 + // query = query.Limit(queryLimit)
  164 + // }
  165 + //} else {
  166 + // query = query.Limit(20)
  167 + //}
151 if count, err := query.Order("id DESC").SelectAndCount(); err != nil { 168 if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
152 return 0, columnSettings, err 169 return 0, columnSettings, err
153 } else { 170 } else {