正在显示
7 个修改的文件
包含
74 行增加
和
75 行删除
@@ -36,8 +36,8 @@ func (service CompanyService) AllowCompany(companyId int64) error { | @@ -36,8 +36,8 @@ func (service CompanyService) AllowCompany(companyId int64) error { | ||
36 | }); err != nil { | 36 | }); err != nil { |
37 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 37 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
38 | } | 38 | } |
39 | - oldCompanyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
40 | - "Id": companyId, | 39 | + oldCompanyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{ |
40 | + Id: companyId, | ||
41 | }) | 41 | }) |
42 | if err != nil { | 42 | if err != nil { |
43 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | 43 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) |
@@ -78,8 +78,8 @@ func (service CompanyService) ForbidCompany(companyId int64) error { | @@ -78,8 +78,8 @@ func (service CompanyService) ForbidCompany(companyId int64) error { | ||
78 | }); err != nil { | 78 | }); err != nil { |
79 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 79 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
80 | } | 80 | } |
81 | - oldCompanyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
82 | - "Id": companyId, | 81 | + oldCompanyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{ |
82 | + Id: companyId, | ||
83 | }) | 83 | }) |
84 | if err != nil { | 84 | if err != nil { |
85 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | 85 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) |
@@ -120,8 +120,8 @@ func (service CompanyService) GetCompanyData(companyId int64) (*domain.Company, | @@ -120,8 +120,8 @@ func (service CompanyService) GetCompanyData(companyId int64) (*domain.Company, | ||
120 | }); err != nil { | 120 | }); err != nil { |
121 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 121 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
122 | } | 122 | } |
123 | - companyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
124 | - "Id": companyId, | 123 | + companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{ |
124 | + Id: companyId, | ||
125 | }) | 125 | }) |
126 | if err != nil { | 126 | if err != nil { |
127 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | 127 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) |
@@ -170,11 +170,11 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { | @@ -170,11 +170,11 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { | ||
170 | }); err != nil { | 170 | }); err != nil { |
171 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 171 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
172 | } | 172 | } |
173 | - oldCompany, err = companyRespository.FindOne(map[string]interface{}{ | ||
174 | - "Id": data.Company.Id, | 173 | + oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{ |
174 | + Id: data.Company.Id, | ||
175 | }) | 175 | }) |
176 | - oldUser, err = userRespository.FindOne(map[string]interface{}{ | ||
177 | - "Id": data.User.Id, | 176 | + oldUser, err = userRespository.FindOne(domain.UsersFindOneQuery{ |
177 | + Id: data.User.Id, | ||
178 | }) | 178 | }) |
179 | oldCompany.Update(map[string]interface{}{ | 179 | oldCompany.Update(map[string]interface{}{ |
180 | "Name": data.Company.Name, | 180 | "Name": data.Company.Name, |
@@ -233,10 +233,10 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | @@ -233,10 +233,10 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | ||
233 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 233 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
234 | } | 234 | } |
235 | var oldUsers []domain.Users | 235 | var oldUsers []domain.Users |
236 | - _, oldUsers, err = userRespository.Find(map[string]interface{}{ | ||
237 | - "CompanyId": data.Id, | ||
238 | - "charge_status": domain.UserIsCompanyCharge, | ||
239 | - "Limit": -1, | 236 | + _, oldUsers, err = userRespository.Find(domain.UsersFindQuery{ |
237 | + CompanyId: data.Id, | ||
238 | + ChargeStatus: domain.UserIsCompanyCharge, | ||
239 | + Limit: -1, | ||
240 | }) | 240 | }) |
241 | for i := range oldUsers { | 241 | for i := range oldUsers { |
242 | _ = oldUsers[i].Update(map[string]interface{}{ | 242 | _ = oldUsers[i].Update(map[string]interface{}{ |
@@ -249,8 +249,8 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | @@ -249,8 +249,8 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | ||
249 | } | 249 | } |
250 | for _, v := range data.Charge { | 250 | for _, v := range data.Charge { |
251 | var userToUpdate domain.Users | 251 | var userToUpdate domain.Users |
252 | - userToUpdate, err := userRespository.FindOne(map[string]interface{}{ | ||
253 | - "Id": v, | 252 | + userToUpdate, err := userRespository.FindOne(domain.UsersFindOneQuery{ |
253 | + Id: v, | ||
254 | }) | 254 | }) |
255 | if err != nil { | 255 | if err != nil { |
256 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取用户(id=%d)的数据失败:%s", v, err.Error())) | 256 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取用户(id=%d)的数据失败:%s", v, err.Error())) |
@@ -222,8 +222,8 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro | @@ -222,8 +222,8 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro | ||
222 | for i := range datas { | 222 | for i := range datas { |
223 | data := datas[i] | 223 | data := datas[i] |
224 | var oldUser domain.Users | 224 | var oldUser domain.Users |
225 | - oldUser, err = usersRepository.FindOne(map[string]interface{}{ | ||
226 | - "Id": data.Id, | 225 | + oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{ |
226 | + Id: data.Id, | ||
227 | }) | 227 | }) |
228 | if err != nil { | 228 | if err != nil { |
229 | return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | 229 | return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) |
@@ -327,9 +327,9 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin | @@ -327,9 +327,9 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin | ||
327 | newSuperUser domain.Users | 327 | newSuperUser domain.Users |
328 | userList []domain.Users | 328 | userList []domain.Users |
329 | ) | 329 | ) |
330 | - _, userList, err = usersRepository.Find(map[string]interface{}{ | ||
331 | - "CompanyId": cmd.CompanyId, | ||
332 | - "AdminType": domain.UserIsAdmin, | 330 | + _, userList, err = usersRepository.Find(domain.UsersFindQuery{ |
331 | + CompanyId: cmd.CompanyId, | ||
332 | + AdminType: domain.UserIsAdmin, | ||
333 | }) | 333 | }) |
334 | if err != nil { | 334 | if err != nil { |
335 | e := fmt.Sprintf("获取用户(admin_type=%d;company_id=%d)数据失败:%s", | 335 | e := fmt.Sprintf("获取用户(admin_type=%d;company_id=%d)数据失败:%s", |
@@ -347,9 +347,9 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin | @@ -347,9 +347,9 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin | ||
347 | return lib.ThrowError(lib.BUSINESS_ERROR, e) | 347 | return lib.ThrowError(lib.BUSINESS_ERROR, e) |
348 | } | 348 | } |
349 | oldSuperUser = userList[0] | 349 | oldSuperUser = userList[0] |
350 | - newSuperUser, err = usersRepository.FindOne(map[string]interface{}{ | ||
351 | - "CompanyId": cmd.CompanyId, | ||
352 | - "Phone": cmd.Phone, | 350 | + newSuperUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{ |
351 | + CompanyId: cmd.CompanyId, | ||
352 | + Phone: cmd.Phone, | ||
353 | }) | 353 | }) |
354 | if err != nil { | 354 | if err != nil { |
355 | e := fmt.Sprintf("获取公司用户数据(phone=%s;company_id=%d)", | 355 | e := fmt.Sprintf("获取公司用户数据(phone=%s;company_id=%d)", |
@@ -79,9 +79,16 @@ func (c *Company) Update(m map[string]interface{}) error { | @@ -79,9 +79,16 @@ func (c *Company) Update(m map[string]interface{}) error { | ||
79 | return nil | 79 | return nil |
80 | } | 80 | } |
81 | 81 | ||
82 | +type CompanyFindOneOptions struct { | ||
83 | + Id int64 | ||
84 | +} | ||
85 | + | ||
86 | +type CompanyFindOptions struct { | ||
87 | +} | ||
88 | + | ||
82 | type CompanyRepository interface { | 89 | type CompanyRepository interface { |
83 | Add(*Company) error | 90 | Add(*Company) error |
84 | Edit(*Company) error | 91 | Edit(*Company) error |
85 | - FindOne(queryOptions map[string]interface{}) (Company, error) | ||
86 | - Find(queryOptions map[string]interface{}) (int64, []Company, error) | 92 | + FindOne(queryOptions CompanyFindOneOptions) (Company, error) |
93 | + Find(queryOptions CompanyFindOptions) (int64, []Company, error) | ||
87 | } | 94 | } |
@@ -117,20 +117,25 @@ func (u *Users) Update(m map[string]interface{}) error { | @@ -117,20 +117,25 @@ func (u *Users) Update(m map[string]interface{}) error { | ||
117 | return nil | 117 | return nil |
118 | } | 118 | } |
119 | 119 | ||
120 | -// type UsersFindOneQuery struct { | ||
121 | -// Id int64 | ||
122 | -// Phone string | ||
123 | -// } | 120 | +type UsersFindOneQuery struct { |
121 | + Id int64 | ||
122 | + Phone string | ||
123 | + CompanyId int64 | ||
124 | + OpenId int64 | ||
125 | +} | ||
124 | 126 | ||
125 | -// type UsersFindQuery struct { | ||
126 | -// Ids []int64 | ||
127 | -// Offset int | ||
128 | -// Limit int | ||
129 | -// } | 127 | +type UsersFindQuery struct { |
128 | + AdminType int8 | ||
129 | + ChargeStatus int8 | ||
130 | + CompanyId int64 | ||
131 | + Ids []int64 | ||
132 | + Offset int | ||
133 | + Limit int | ||
134 | +} | ||
130 | type UsersRepository interface { | 135 | type UsersRepository interface { |
131 | Add(*Users) error | 136 | Add(*Users) error |
132 | Edit(*Users) error | 137 | Edit(*Users) error |
133 | Remove([]int64) error | 138 | Remove([]int64) error |
134 | - FindOne(queryOptions map[string]interface{}) (Users, error) | ||
135 | - Find(queryOptions map[string]interface{}) (int, []Users, error) | 139 | + FindOne(queryOptions UsersFindOneQuery) (Users, error) |
140 | + Find(queryOptions UsersFindQuery) (int, []Users, error) | ||
136 | } | 141 | } |
1 | package repository | 1 | package repository |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | 5 | ||
7 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
@@ -82,11 +81,7 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error { | @@ -82,11 +81,7 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error { | ||
82 | return err | 81 | return err |
83 | } | 82 | } |
84 | 83 | ||
85 | -func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{}) (domain.Company, error) { | ||
86 | - | ||
87 | - if len(queryOptions) == 0 { | ||
88 | - return domain.Company{}, errors.New("queryOptions empty") | ||
89 | - } | 84 | +func (reponsitory CompanyRepository) FindOne(queryOptions domain.CompanyFindOneOptions) (domain.Company, error) { |
90 | var ( | 85 | var ( |
91 | err error | 86 | err error |
92 | tx = reponsitory.transactionContext.PgTx | 87 | tx = reponsitory.transactionContext.PgTx |
@@ -94,8 +89,8 @@ func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{} | @@ -94,8 +89,8 @@ func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{} | ||
94 | ) | 89 | ) |
95 | 90 | ||
96 | query := tx.Model(&m) | 91 | query := tx.Model(&m) |
97 | - if v, ok := queryOptions["Id"]; ok { | ||
98 | - query = query.Where("id=?", v) | 92 | + if queryOptions.Id > 0 { |
93 | + query = query.Where("id=?", queryOptions.Id) | ||
99 | } | 94 | } |
100 | err = query.First() | 95 | err = query.First() |
101 | if err != nil { | 96 | if err != nil { |
@@ -104,6 +99,6 @@ func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{} | @@ -104,6 +99,6 @@ func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{} | ||
104 | return reponsitory.transformPgModelToDomainModel(&m) | 99 | return reponsitory.transformPgModelToDomainModel(&m) |
105 | } | 100 | } |
106 | 101 | ||
107 | -func (reponsitory CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []domain.Company, error) { | 102 | +func (reponsitory CompanyRepository) Find(queryOptions domain.CompanyFindOptions) (int64, []domain.Company, error) { |
108 | return 0, nil, nil | 103 | return 0, nil, nil |
109 | } | 104 | } |
1 | package repository | 1 | package repository |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | "time" | 5 | "time" |
7 | 6 | ||
@@ -111,10 +110,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | @@ -111,10 +110,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | ||
111 | return err | 110 | return err |
112 | } | 111 | } |
113 | 112 | ||
114 | -func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) (domain.Users, error) { | ||
115 | - if len(queryOptions) == 0 { | ||
116 | - return domain.Users{}, errors.New("queryOptions is empty") | ||
117 | - } | 113 | +func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery) (domain.Users, error) { |
118 | var ( | 114 | var ( |
119 | err error | 115 | err error |
120 | tx = reponsitory.transactionContext.PgTx | 116 | tx = reponsitory.transactionContext.PgTx |
@@ -122,17 +118,17 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) | @@ -122,17 +118,17 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) | ||
122 | ) | 118 | ) |
123 | query := tx.Model(&m) | 119 | query := tx.Model(&m) |
124 | query.Where("deleted_at ISNULL") | 120 | query.Where("deleted_at ISNULL") |
125 | - if v, ok := queryOptions["Id"]; ok { | ||
126 | - query = query.Where("id=?", v) | 121 | + if queryOptions.Id > 0 { |
122 | + query = query.Where("id=?", queryOptions.Id) | ||
127 | } | 123 | } |
128 | - if v, ok := queryOptions["Phone"]; ok { | ||
129 | - query = query.Where("phone=?", v) | 124 | + if len(queryOptions.Phone) > 0 { |
125 | + query = query.Where("phone=?", queryOptions.Phone) | ||
130 | } | 126 | } |
131 | - if v, ok := queryOptions["CompanyId"]; ok { | ||
132 | - query = query.Where("company_id=?", v) | 127 | + if queryOptions.CompanyId > 0 { |
128 | + query = query.Where("company_id=?", queryOptions.CompanyId) | ||
133 | } | 129 | } |
134 | - if v, ok := queryOptions["OpenId"]; ok { | ||
135 | - query = query.Where("open_id=?", v) | 130 | + if queryOptions.OpenId > 0 { |
131 | + query = query.Where("open_id=?", queryOptions.OpenId) | ||
136 | } | 132 | } |
137 | err = query.First() | 133 | err = query.First() |
138 | if err != nil { | 134 | if err != nil { |
@@ -141,31 +137,27 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) | @@ -141,31 +137,27 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) | ||
141 | return reponsitory.transformPgModelToDomainModel(&m) | 137 | return reponsitory.transformPgModelToDomainModel(&m) |
142 | } | 138 | } |
143 | 139 | ||
144 | -func (reponsitory UsersRepository) Find(queryOption map[string]interface{}) (int, []domain.Users, error) { | 140 | +func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) { |
145 | db := reponsitory.transactionContext.PgTx | 141 | db := reponsitory.transactionContext.PgTx |
146 | usersModels := []models.Users{} | 142 | usersModels := []models.Users{} |
147 | query := db.Model(&usersModels) | 143 | query := db.Model(&usersModels) |
148 | query.Where("deleted_at ISNULL") | 144 | query.Where("deleted_at ISNULL") |
149 | - if v, ok := queryOption["CompanyId"]; ok { | ||
150 | - query = query.Where("company_id=?", v) | ||
151 | - } | ||
152 | - if v, ok := queryOption["ChargeStatus"]; ok { | ||
153 | - query = query.Where("charge_status=?", v) | 145 | + if queryOption.CompanyId > 0 { |
146 | + query = query.Where("company_id=?", queryOption.CompanyId) | ||
154 | } | 147 | } |
155 | - if v, ok := queryOption["AdminType"]; ok { | ||
156 | - query = query.Where("admin_type=?", v) | 148 | + if queryOption.ChargeStatus > 0 { |
149 | + query = query.Where("charge_status=?", queryOption.ChargeStatus) | ||
157 | } | 150 | } |
158 | - if v, ok := queryOption["Offset"]; ok { | ||
159 | - offset := v.(int) | ||
160 | - query = query.Offset(offset) | 151 | + if queryOption.AdminType > 0 { |
152 | + query = query.Where("admin_type=?", queryOption.AdminType) | ||
161 | } | 153 | } |
162 | - if v, ok := queryOption["Limit"]; ok { | ||
163 | - limit := v.(int) | ||
164 | - if limit > 0 { | ||
165 | - query = query.Limit(limit) | 154 | + if queryOption.Offset >= 0 { |
155 | + query = query.Offset(queryOption.Offset) | ||
166 | } | 156 | } |
157 | + if queryOption.Limit > 0 { | ||
158 | + query = query.Limit(queryOption.Limit) | ||
167 | } else { | 159 | } else { |
168 | - query = query.Limit(20) | 160 | + query = query.Limit(1000) |
169 | } | 161 | } |
170 | var ( | 162 | var ( |
171 | err error | 163 | err error |
-
请 注册 或 登录 后发表评论