作者 陈志颖

feat:修改导入兑换清单功能,增加用户uid

@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
11 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service" 11 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
12 "path" 12 "path"
  13 + "strconv"
13 ) 14 )
14 15
15 type SuMoneyController struct { 16 type SuMoneyController struct {
@@ -200,22 +201,16 @@ func (controller *SuMoneyController) ListExchangeActivities () { @@ -200,22 +201,16 @@ func (controller *SuMoneyController) ListExchangeActivities () {
200 func (controller *SuMoneyController) UpdateExchangeActivities () { 201 func (controller *SuMoneyController) UpdateExchangeActivities () {
201 cashPoolService := service.NewCashPoolService(nil) 202 cashPoolService := service.NewCashPoolService(nil)
202 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{} 203 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{}
203 -  
204 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashActivityCommand) 204 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashActivityCommand)
205 -  
206 activityId, _ := controller.GetInt64(":activityId") 205 activityId, _ := controller.GetInt64(":activityId")
207 updateExchangeCashActivityCommand.ExchangeCashActivityId = activityId 206 updateExchangeCashActivityCommand.ExchangeCashActivityId = activityId
208 -  
209 data, err := cashPoolService.UpdateExchangeCashActivity(updateExchangeCashActivityCommand) 207 data, err := cashPoolService.UpdateExchangeCashActivity(updateExchangeCashActivityCommand)
210 -  
211 var response utils.JsonResponse 208 var response utils.JsonResponse
212 -  
213 if err != nil { 209 if err != nil {
214 response = utils.ResponseError(controller.Ctx, err) 210 response = utils.ResponseError(controller.Ctx, err)
215 } else { 211 } else {
216 response = utils.ResponseData(controller.Ctx, data) 212 response = utils.ResponseData(controller.Ctx, data)
217 } 213 }
218 -  
219 controller.Data["json"] = response 214 controller.Data["json"] = response
220 controller.ServeJSON() 215 controller.ServeJSON()
221 } 216 }
@@ -224,19 +219,14 @@ func (controller *SuMoneyController) UpdateExchangeActivities () { @@ -224,19 +219,14 @@ func (controller *SuMoneyController) UpdateExchangeActivities () {
224 func (controller *SuMoneyController) CreateExchangeActivities () { 219 func (controller *SuMoneyController) CreateExchangeActivities () {
225 cashPoolService := service.NewCashPoolService(nil) 220 cashPoolService := service.NewCashPoolService(nil)
226 createExchangeCashActivityCommand := &command.CreateExchangeCashActivityCommand{} 221 createExchangeCashActivityCommand := &command.CreateExchangeCashActivityCommand{}
227 -  
228 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashActivityCommand) 222 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashActivityCommand)
229 -  
230 data, err := cashPoolService.CreateExchangeCashActivity(createExchangeCashActivityCommand) 223 data, err := cashPoolService.CreateExchangeCashActivity(createExchangeCashActivityCommand)
231 -  
232 var response utils.JsonResponse 224 var response utils.JsonResponse
233 -  
234 if err != nil { 225 if err != nil {
235 response = utils.ResponseError(controller.Ctx, err) 226 response = utils.ResponseError(controller.Ctx, err)
236 } else { 227 } else {
237 response = utils.ResponseData(controller.Ctx, data) 228 response = utils.ResponseData(controller.Ctx, data)
238 } 229 }
239 -  
240 controller.Data["json"] = response 230 controller.Data["json"] = response
241 controller.ServeJSON() 231 controller.ServeJSON()
242 } 232 }
@@ -245,20 +235,15 @@ func (controller *SuMoneyController) CreateExchangeActivities () { @@ -245,20 +235,15 @@ func (controller *SuMoneyController) CreateExchangeActivities () {
245 func (controller *SuMoneyController) RemoveExchangeActivities () { 235 func (controller *SuMoneyController) RemoveExchangeActivities () {
246 cashPoolService := service.NewCashPoolService(nil) 236 cashPoolService := service.NewCashPoolService(nil)
247 removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{} 237 removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{}
248 -  
249 activityId, _ := controller.GetInt64(":activityId") 238 activityId, _ := controller.GetInt64(":activityId")
250 removeExchangeCashActivityCommand. ExchangeCashActivityId = activityId 239 removeExchangeCashActivityCommand. ExchangeCashActivityId = activityId
251 -  
252 data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand) 240 data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand)
253 -  
254 var response utils.JsonResponse 241 var response utils.JsonResponse
255 -  
256 if err != nil { 242 if err != nil {
257 response = utils.ResponseError(controller.Ctx, err) 243 response = utils.ResponseError(controller.Ctx, err)
258 } else { 244 } else {
259 response = utils.ResponseData(controller.Ctx, data) 245 response = utils.ResponseData(controller.Ctx, data)
260 } 246 }
261 -  
262 controller.Data["json"] = response 247 controller.Data["json"] = response
263 controller.ServeJSON() 248 controller.ServeJSON()
264 } 249 }
@@ -267,20 +252,15 @@ func (controller *SuMoneyController) RemoveExchangeActivities () { @@ -267,20 +252,15 @@ func (controller *SuMoneyController) RemoveExchangeActivities () {
267 func (controller *SuMoneyController) GetExchangeCashActivity () { 252 func (controller *SuMoneyController) GetExchangeCashActivity () {
268 cashPoolService := service.NewCashPoolService(nil) 253 cashPoolService := service.NewCashPoolService(nil)
269 getExchangeCashActivityQuery := &query.GetExchangeCashActivityQuery{} 254 getExchangeCashActivityQuery := &query.GetExchangeCashActivityQuery{}
270 -  
271 activityId, _ := controller.GetInt64(":activityId") 255 activityId, _ := controller.GetInt64(":activityId")
272 getExchangeCashActivityQuery.ExchangeCashActivityId = activityId 256 getExchangeCashActivityQuery.ExchangeCashActivityId = activityId
273 -  
274 data, err := cashPoolService.GetExchangeCashActivity(getExchangeCashActivityQuery) 257 data, err := cashPoolService.GetExchangeCashActivity(getExchangeCashActivityQuery)
275 -  
276 var response utils.JsonResponse 258 var response utils.JsonResponse
277 -  
278 if err != nil { 259 if err != nil {
279 response = utils.ResponseError(controller.Ctx, err) 260 response = utils.ResponseError(controller.Ctx, err)
280 } else { 261 } else {
281 response = utils.ResponseData(controller.Ctx, data) 262 response = utils.ResponseData(controller.Ctx, data)
282 } 263 }
283 -  
284 controller.Data["json"] = response 264 controller.Data["json"] = response
285 controller.ServeJSON() 265 controller.ServeJSON()
286 } 266 }
@@ -289,29 +269,21 @@ func (controller *SuMoneyController) GetExchangeCashActivity () { @@ -289,29 +269,21 @@ func (controller *SuMoneyController) GetExchangeCashActivity () {
289 func (controller *SuMoneyController) ListExchangeList () { 269 func (controller *SuMoneyController) ListExchangeList () {
290 cashPoolService := service.NewCashPoolService(nil) 270 cashPoolService := service.NewCashPoolService(nil)
291 listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{} 271 listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{}
292 -  
293 activityId, _ := controller.GetInt64("activityId") 272 activityId, _ := controller.GetInt64("activityId")
294 listExchangeCashListQuery.ExchangeCashActivityId = activityId 273 listExchangeCashListQuery.ExchangeCashActivityId = activityId
295 -  
296 exchangeCashPersonNameMatch := controller.GetString("personNameMatch") 274 exchangeCashPersonNameMatch := controller.GetString("personNameMatch")
297 listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch 275 listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch
298 -  
299 offset, _ := controller.GetInt("offset") 276 offset, _ := controller.GetInt("offset")
300 listExchangeCashListQuery.Offset = offset 277 listExchangeCashListQuery.Offset = offset
301 -  
302 limit, _ := controller.GetInt("limit") 278 limit, _ := controller.GetInt("limit")
303 listExchangeCashListQuery.Limit = limit 279 listExchangeCashListQuery.Limit = limit
304 -  
305 data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery) 280 data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery)
306 -  
307 var response utils.JsonResponse 281 var response utils.JsonResponse
308 -  
309 if err != nil { 282 if err != nil {
310 response = utils.ResponseError(controller.Ctx, err) 283 response = utils.ResponseError(controller.Ctx, err)
311 } else { 284 } else {
312 response = utils.ResponseData(controller.Ctx, data) 285 response = utils.ResponseData(controller.Ctx, data)
313 } 286 }
314 -  
315 controller.Data["json"] = response 287 controller.Data["json"] = response
316 controller.ServeJSON() 288 controller.ServeJSON()
317 } 289 }
@@ -320,19 +292,14 @@ func (controller *SuMoneyController) ListExchangeList () { @@ -320,19 +292,14 @@ func (controller *SuMoneyController) ListExchangeList () {
320 func (controller *SuMoneyController) CreateExchangeList () { 292 func (controller *SuMoneyController) CreateExchangeList () {
321 cashPoolService := service.NewCashPoolService(nil) 293 cashPoolService := service.NewCashPoolService(nil)
322 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{} 294 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
323 -  
324 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashPersonCommand) 295 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashPersonCommand)
325 -  
326 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand) 296 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
327 -  
328 var response utils.JsonResponse 297 var response utils.JsonResponse
329 -  
330 if err != nil { 298 if err != nil {
331 response = utils.ResponseError(controller.Ctx, err) 299 response = utils.ResponseError(controller.Ctx, err)
332 } else { 300 } else {
333 response = utils.ResponseData(controller.Ctx, data) 301 response = utils.ResponseData(controller.Ctx, data)
334 } 302 }
335 -  
336 controller.Data["json"] = response 303 controller.Data["json"] = response
337 controller.ServeJSON() 304 controller.ServeJSON()
338 } 305 }
@@ -341,22 +308,16 @@ func (controller *SuMoneyController) CreateExchangeList () { @@ -341,22 +308,16 @@ func (controller *SuMoneyController) CreateExchangeList () {
341 func (controller *SuMoneyController) UpdateExchangeList () { 308 func (controller *SuMoneyController) UpdateExchangeList () {
342 cashPoolService := service.NewCashPoolService(nil) 309 cashPoolService := service.NewCashPoolService(nil)
343 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{} 310 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{}
344 -  
345 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand) 311 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand)
346 -  
347 personId, _ := controller.GetInt64(":personId") 312 personId, _ := controller.GetInt64(":personId")
348 updateExchangeCashPersonCommand. ExchangeCashPersonId = personId 313 updateExchangeCashPersonCommand. ExchangeCashPersonId = personId
349 -  
350 data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand) 314 data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand)
351 -  
352 var response utils.JsonResponse 315 var response utils.JsonResponse
353 -  
354 if err != nil { 316 if err != nil {
355 response = utils.ResponseError(controller.Ctx, err) 317 response = utils.ResponseError(controller.Ctx, err)
356 } else { 318 } else {
357 response = utils.ResponseData(controller.Ctx, data) 319 response = utils.ResponseData(controller.Ctx, data)
358 } 320 }
359 -  
360 controller.Data["json"] = response 321 controller.Data["json"] = response
361 controller.ServeJSON() 322 controller.ServeJSON()
362 } 323 }
@@ -365,20 +326,15 @@ func (controller *SuMoneyController) UpdateExchangeList () { @@ -365,20 +326,15 @@ func (controller *SuMoneyController) UpdateExchangeList () {
365 func (controller *SuMoneyController) RemoveExchangeList () { 326 func (controller *SuMoneyController) RemoveExchangeList () {
366 cashPoolService := service.NewCashPoolService(nil) 327 cashPoolService := service.NewCashPoolService(nil)
367 removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{} 328 removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
368 -  
369 personId, _ := controller.GetInt64(":personId") 329 personId, _ := controller.GetInt64(":personId")
370 removeExchangeCashPersonCommand.ExchangeCashPersonId = personId 330 removeExchangeCashPersonCommand.ExchangeCashPersonId = personId
371 -  
372 data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand) 331 data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
373 -  
374 var response utils.JsonResponse 332 var response utils.JsonResponse
375 -  
376 if err != nil { 333 if err != nil {
377 response = utils.ResponseError(controller.Ctx, err) 334 response = utils.ResponseError(controller.Ctx, err)
378 } else { 335 } else {
379 response = utils.ResponseData(controller.Ctx, data) 336 response = utils.ResponseData(controller.Ctx, data)
380 } 337 }
381 -  
382 controller.Data["json"] = response 338 controller.Data["json"] = response
383 controller.ServeJSON() 339 controller.ServeJSON()
384 } 340 }
@@ -387,20 +343,15 @@ func (controller *SuMoneyController) RemoveExchangeList () { @@ -387,20 +343,15 @@ func (controller *SuMoneyController) RemoveExchangeList () {
387 func (controller *SuMoneyController) GetExchangeCashPerson () { 343 func (controller *SuMoneyController) GetExchangeCashPerson () {
388 cashPoolService := service.NewCashPoolService(nil) 344 cashPoolService := service.NewCashPoolService(nil)
389 getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{} 345 getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{}
390 -  
391 personId, _ := controller.GetInt64(":personId") 346 personId, _ := controller.GetInt64(":personId")
392 getExchangeCashPersonQuery.ExchangeCashPersonId = personId 347 getExchangeCashPersonQuery.ExchangeCashPersonId = personId
393 -  
394 data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery) 348 data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery)
395 -  
396 var response utils.JsonResponse 349 var response utils.JsonResponse
397 -  
398 if err != nil { 350 if err != nil {
399 response = utils.ResponseError(controller.Ctx, err) 351 response = utils.ResponseError(controller.Ctx, err)
400 } else { 352 } else {
401 response = utils.ResponseData(controller.Ctx, data) 353 response = utils.ResponseData(controller.Ctx, data)
402 } 354 }
403 -  
404 controller.Data["json"] = response 355 controller.Data["json"] = response
405 controller.ServeJSON() 356 controller.ServeJSON()
406 } 357 }
@@ -409,10 +360,9 @@ func (controller *SuMoneyController) GetExchangeCashPerson () { @@ -409,10 +360,9 @@ func (controller *SuMoneyController) GetExchangeCashPerson () {
409 func (controller *SuMoneyController) ImportExchangeList () { 360 func (controller *SuMoneyController) ImportExchangeList () {
410 cashPoolService := service.NewCashPoolService(nil) 361 cashPoolService := service.NewCashPoolService(nil)
411 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{} 362 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
412 - 363 + activityId, _ := controller.GetInt64("activityId")
413 file, h, _ := controller.GetFile("file") //获取上传的文件 364 file, h, _ := controller.GetFile("file") //获取上传的文件
414 ext := path.Ext(h.Filename) 365 ext := path.Ext(h.Filename)
415 -  
416 //验证后缀名是否符合要求 366 //验证后缀名是否符合要求
417 AllowExtMap := map[string]bool{ 367 AllowExtMap := map[string]bool{
418 ".xlsx":true, 368 ".xlsx":true,
@@ -421,36 +371,25 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -421,36 +371,25 @@ func (controller *SuMoneyController) ImportExchangeList () {
421 controller.Ctx.WriteString( "后缀名不符合上传要求" ) 371 controller.Ctx.WriteString( "后缀名不符合上传要求" )
422 return 372 return
423 } 373 }
424 -  
425 xlsx, err := excelize.OpenReader(file) 374 xlsx, err := excelize.OpenReader(file)
426 if err != nil { 375 if err != nil {
427 fmt.Println(err) 376 fmt.Println(err)
428 return 377 return
429 } 378 }
430 -  
431 var response utils.JsonResponse 379 var response utils.JsonResponse
432 -  
433 dataList := make([]interface{}, 0) 380 dataList := make([]interface{}, 0)
434 -  
435 rows, _ := xlsx.GetRows("Sheet1") 381 rows, _ := xlsx.GetRows("Sheet1")
436 -  
437 - fmt.Print(rows)  
438 -  
439 for i, row := range rows { 382 for i, row := range rows {
440 if i > 0 { 383 if i > 0 {
441 for _, _ = range row { 384 for _, _ = range row {
442 - //fmt.Print(row[0], "\t")  
443 - //fmt.Print(row[1], "\t")  
444 - //fmt.Print(row[2], "\t")  
445 - //fmt.Print(row[3], "\t")  
446 -  
447 - //createExchangeCashPersonCommand.ExchangeCashPerson.EmployeeInfo.EmployeeName = row[0]  
448 - //createExchangeCashPersonCommand.ExchangeCashPerson.EmployeeInfo.EmployeeAccount = row[1]  
449 - //createExchangeCashPersonCommand.ExchangedCash, _ = strconv.ParseFloat(row[2],64)  
450 - //createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[3], 64)  
451 - 385 + createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
  386 + createExchangeCashPersonCommand.PersonId, _ = strconv.ParseInt(row[0], 10, 32)
  387 + createExchangeCashPersonCommand.PersonName = row[1]
  388 + createExchangeCashPersonCommand.PersonAccount = row[2]
  389 + createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[3], 64)
  390 + }
  391 + fmt.Print(createExchangeCashPersonCommand)
452 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand) 392 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
453 -  
454 if err != nil { 393 if err != nil {
455 response = utils.ResponseError(controller.Ctx, err) 394 response = utils.ResponseError(controller.Ctx, err)
456 } else { 395 } else {
@@ -459,8 +398,6 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -459,8 +398,6 @@ func (controller *SuMoneyController) ImportExchangeList () {
459 } 398 }
460 } 399 }
461 } 400 }
462 - }  
463 -  
464 controller.Data["json"] = response 401 controller.Data["json"] = response
465 controller.ServeJSON() 402 controller.ServeJSON()
466 } 403 }