su_money_controller.go 26.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
package controllers

import (
	"encoding/json"
	"fmt"
	"github.com/360EntSecGroup-Skylar/excelize/v2"
	"github.com/astaxie/beego"
	"github.com/linmadan/egglib-go/web/beego/utils"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
	"os"
	"path"
	"strconv"
)

type SuMoneyController struct {
	beego.Controller
}

// 操作素币
func (controller *SuMoneyController) OperationSuMoney() {
	suMoneyService := service.NewSuMoneyService(nil)
	operationSuMoneyCommand := &command.OperationSuMoneyCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), operationSuMoneyCommand)
	data, err := suMoneyService.OperationSuMoney(operationSuMoneyCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 获取素币事务记录
func (controller *SuMoneyController) GetSuMoneyTransactionRecord() {
	suMoneyService := service.NewSuMoneyService(nil)
	getSuMoneyTransactionRecordQuery := &query.GetSuMoneyTransactionRecordQuery{}
	suMoneyTransactionRecordId, _ := controller.GetInt64(":suMoneyTransactionRecordId")
	getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId = suMoneyTransactionRecordId
	data, err := suMoneyService.GetSuMoneyTransactionRecord(getSuMoneyTransactionRecordQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 兑换素币
func (controller *SuMoneyController) ExchangeSuMoney() {
	suMoneyService := service.NewSuMoneyService(nil)
	exchangeSuMoneyCommand := &command.ExchangeSuMoneyCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exchangeSuMoneyCommand)
	data, err := suMoneyService.ExchangeSuMoney(exchangeSuMoneyCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 搜索素币事务
func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
	suMoneyService := service.NewSuMoneyService(nil)
	searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{}
	employeeMatchName := controller.GetString("employeeMatchName")
	searchSuMoneyTransactionRecordCommand.EmployeeMatchName =  employeeMatchName
	offset, _ := controller.GetInt("offset")
	searchSuMoneyTransactionRecordCommand.Offset = offset
	limit, _ := controller.GetInt("limit")
	searchSuMoneyTransactionRecordCommand.Limit = limit
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand)
	data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 素币事务统计(个人素币收支)
func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
	suMoneyService := service.NewSuMoneyService(nil)
	suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), suMoneyTransactionRecordStatisticsCommand)
	data, err := suMoneyService.SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 贡献值事务统计(个人贡献值收支)
func (controller *SuMoneyController) ContributionsTransactionRecordStatistics() {
	suMoneyService := service.NewSuMoneyService(nil)
	contributionsTransactionRecordStatisticsCommand := &command.ContributionsTransactionRecordStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsTransactionRecordStatisticsCommand)
	data, err := suMoneyService.ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 投入现金池
func (controller *SuMoneyController) CashInput() {
	cashPoolService := service.NewCashPoolService(nil)
	createCashPoolCommand := &command.CreateCashPoolCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createCashPoolCommand)
	data, err := cashPoolService.CreateCashPool(createCashPoolCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回现金池
func (controller *SuMoneyController) GetCashPool() {
	cashPoolService := service.NewCashPoolService(nil)
	getCashPoolQuery := &query.GetCashPoolQuery{}
	companyId, _ := controller.GetInt64("companyId")
	getCashPoolQuery.CompanyId = companyId
	data, err := cashPoolService.GetCashPool(getCashPoolQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 新增兑换活动
func (controller *SuMoneyController) CreateExchangeActivities ()  {
	cashPoolService := service.NewCashPoolService(nil)
	createExchangeCashActivityCommand := &command.CreateExchangeCashActivityCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashActivityCommand)
	data, err := cashPoolService.CreateExchangeCashActivity(createExchangeCashActivityCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换活动列表
func (controller *SuMoneyController) ListExchangeActivities () {
	cashPoolService := service.NewCashPoolService(nil)
	listExchangeCashActivityQuery := &query.ListExchangeCashActivityQuery{}
	companyId, _ := controller.GetInt64("companyId")
	listExchangeCashActivityQuery.CompanyId = companyId
	exchangeCashActivityNameMatch := controller.GetString("activityNameMatch")
	listExchangeCashActivityQuery.ActivityNameMatch = exchangeCashActivityNameMatch
	offset, _ := controller.GetInt("offset")
	listExchangeCashActivityQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listExchangeCashActivityQuery.Limit = limit
	data, err := cashPoolService.ListExchangeCashActivity(listExchangeCashActivityQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 搜索返回兑换活动列表
func (controller *SuMoneyController) SearchExchangeActivities () {
	cashPoolService := service.NewCashPoolService(nil)
	searchExchangeCashActivityCommand := &command.SearchExchangeCashActivityCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchExchangeCashActivityCommand)
	fmt.Printf("命令:%+v\n", searchExchangeCashActivityCommand)
	data, err := cashPoolService.SearchExchangeCashActivity(searchExchangeCashActivityCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换现金活动
func (controller *SuMoneyController) GetExchangeCashActivity () {
	cashPoolService := service.NewCashPoolService(nil)
	getExchangeCashActivityQuery := &query.GetExchangeCashActivityQuery{}
	activityId, _ := controller.GetInt64(":activityId")
	getExchangeCashActivityQuery.ExchangeCashActivityId = activityId
	data, err := cashPoolService.GetExchangeCashActivity(getExchangeCashActivityQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 更新兑换活动信息
func (controller *SuMoneyController) UpdateExchangeActivities () {
	cashPoolService := service.NewCashPoolService(nil)
	updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashActivityCommand)
	activityId, _ := controller.GetInt64(":activityId")
	updateExchangeCashActivityCommand.ExchangeCashActivityId = activityId
	data, err := cashPoolService.UpdateExchangeCashActivity(updateExchangeCashActivityCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 移除兑换活动
func (controller *SuMoneyController) RemoveExchangeActivities () {
	cashPoolService := service.NewCashPoolService(nil)
	removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{}
	activityId, _ := controller.GetInt64(":activityId")
	beego.Info(activityId)
	removeExchangeCashActivityCommand.ActivityId = activityId
	data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换素币清单列表
func (controller *SuMoneyController) ListExchangeList () {
	cashPoolService := service.NewCashPoolService(nil)
	listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{}
	activityId, _ := controller.GetInt64("activityId")
	listExchangeCashListQuery.ExchangeCashActivityId = activityId
	companyId, _ := controller.GetInt64("companyId")
	listExchangeCashListQuery.CompanyId = companyId
	exchangeCashPersonNameMatch := controller.GetString("personNameMatch")
	listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch
	offset, _ := controller.GetInt("offset")
	listExchangeCashListQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listExchangeCashListQuery.Limit = limit
	data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 新增兑换素币清单
func (controller *SuMoneyController) CreateExchangeList () {
	cashPoolService := service.NewCashPoolService(nil)
	createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createExchangeCashPersonCommand)
	data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 更新兑换素币清单
func (controller *SuMoneyController) UpdateExchangeList ()  {
	cashPoolService := service.NewCashPoolService(nil)
	updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand)
	personId, _ := controller.GetInt64(":listId")
	updateExchangeCashPersonCommand.ListId = personId
	data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 移除兑换素币清单
func (controller *SuMoneyController) RemoveExchangeCashPerson() {
	cashPoolService := service.NewCashPoolService(nil)
	removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
	personId, _ := controller.GetInt64(":listId")
	operatorId, _ := controller.GetInt64("operator")
	removeExchangeCashPersonCommand.ListId = personId
	removeExchangeCashPersonCommand.Operator = operatorId
	data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换素币清单
func (controller *SuMoneyController) GetExchangeCashPerson () {
	cashPoolService := service.NewCashPoolService(nil)
	getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{}
	listId, _ := controller.GetInt64(":listId")
	getExchangeCashPersonQuery.ExchangeCashPersonId = listId
	data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换活动截止时间列表
func (controller *SuMoneyController) ListDeadline() {
	cashPoolService := service.NewCashPoolService(nil)
	listExchangeCashActivityDeadlineQuery := &query.ListExchangeCashActivityDeadlineQuery{}
	companyId, _ := controller.GetInt64("companyId")
	listExchangeCashActivityDeadlineQuery.CompanyId = companyId
	data, err := cashPoolService.ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 返回兑换素币清单排行榜
func (controller *SuMoneyController) ExchangeCashListRanking() {
	cashPoolService := service.NewCashPoolService(nil)
	exchangeListRankingQuery := &query.ExchangeListRankingQuery{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exchangeListRankingQuery)
	data, err := cashPoolService.ExchangeListRanking(exchangeListRankingQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 导入兑换素币清单
func (controller *SuMoneyController) ImportExchangeList () {
	cashPoolService := service.NewCashPoolService(nil)
	where := controller.GetString("where")
	file, h, _ := controller.GetFile("file")

	jsonMap := make(map[string]interface{})
	_ = json.Unmarshal([]byte(where), &jsonMap)

	// 错误信息返回
	var response utils.JsonResponse

	// 返回字段定义
	ret := map[string]interface{}{}

	// 返回信息表头定义
	var tableHeader = [...]string{"员工姓名", "手机号", "已兑换素币", "错误详情"}

	// 文件后缀名校验
	ext := path.Ext(h.Filename)
	AllowExtMap := map[string]bool{
		".xlsx":true,
	}
	if _,ok:=AllowExtMap[ext];!ok{
		err := fmt.Errorf("%s", "后缀名不符合上传要求")
		response = utils.ResponseError(controller.Ctx, err)
		controller.Data["json"] = response
		controller.ServeJSON()
		return
	}

	xlsx, err := excelize.OpenReader(file)
	if err != nil {
		fmt.Println(err)
		return
	}

	// 文件行数校验
	rows, _ := xlsx.GetRows("Sheet1")

	if len(rows) > 302 {
		err := fmt.Errorf("%s", "导入行数超过300行")
		response = utils.ResponseError(controller.Ctx, err)
		controller.Data["json"] = response
		controller.ServeJSON()
		return
	}

	//空行记录
	nullLine := make([]interface{}, 0)

	// 单元格非空校验
	for i, row := range rows {
		if i > 2 {
			if len(row) != 3 {
				row = append(row, "单元格包含空字符")
				nullLine = append(nullLine, row)
			}
		}
	}

	if len(nullLine) > 0 {
		ret = map[string]interface{}{
			"successCount": 0,
			"fail": map[string]interface{}{
				"tableHeader": tableHeader,
				"tableData": nullLine,
			},
		}
		response = utils.ResponseData(controller.Ctx, ret)
		controller.Data["json"] = response
		controller.ServeJSON()
		return
	}

	// 新增失败记录
	failureDataList := make([]interface{}, 0)

	// 新增成功计数
	var successDataCount int64

	//fmt.Print(len(rows), "\n")

	for i, row := range rows {
		//fmt.Printf("Row Number:%d, Row: %+v\n, Row Length: %d\n", i, row, len(row))
		if i > 2 && len(row) > 1 {
			// 创建兑换清单命令
			createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
			createExchangeCashPersonCommand.ExchangeCashActivityId, _ = strconv.ParseInt(jsonMap["activityId"].(string), 10, 64 )
			//createExchangeCashPersonCommand.ExchangeCashActivityId, _ = strconv.ParseInt(interface{}(importExchangeCashListCommand.Where).(map[string]interface{})["activityId"].(string), 10, 64)
			createExchangeCashPersonCommand.Operator  = int64(jsonMap["uid"].(float64))
			//createExchangeCashPersonCommand.Operator = int64(interface{}(importExchangeCashListCommand.Where).(map[string]interface{})["uid"].(float64))
			createExchangeCashPersonCommand.PersonName = row[0]
			createExchangeCashPersonCommand.PersonAccount = row[1]
			r2, _ := strconv.ParseFloat(row[2], 64)
			createExchangeCashPersonCommand.ExchangedSuMoney = r2

			// 创建兑换素币清单
			_, err := cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommand)
			if err != nil { // 导入失败处理
				rows[i] = append(rows[i], err.Error())
				failureDataList = append(failureDataList, rows[i])  // 导入失败的记录
			} else {   // 导入成功处理
				successDataCount += 1
			}
		}
	}

	ret = map[string]interface{}{
		"successCount": successDataCount,
		"fail": map[string]interface{}{
			"tableHeader": tableHeader,
			"tableData": failureDataList,
		},
	}

	if successDataCount == int64(len(rows) - 3) {
		ret = map[string]interface{}{
			"successCount": successDataCount,
			"fail": nil,
		}
	}

	response = utils.ResponseData(controller.Ctx, ret)
	controller.Data["json"] = response
	controller.ServeJSON()
	return
}

// 导出素币兑换清单,选择导出(ids),增加导出失败信息
func (controller *SuMoneyController) ExportExchangeList() {
	cashPoolService := service.NewCashPoolService(nil)
	exportExchangeCashListCommand := &command.ExportExchangeCashListCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportExchangeCashListCommand)
	// 列标题
	titles := []string{
		"姓名","手机账号","已兑换现金","已兑换素币",
	}
	// 列单元
	cells := []string{
		"A","B","C","D",
	}
	// 数据源
	var data []map[string]interface{}
	people, err := cashPoolService.ListExchangeCashPersonById(exportExchangeCashListCommand)
	for _, person := range people {
		p := map[string]interface{} {
			"name": person.EmployeeInfo.EmployeeName,
			"account": person.EmployeeInfo.EmployeeAccount,
			"exchanged_cash": person.ExchangedCash,
			"exchanged_su_money": person.ExchangedSuMoney,
		}
		data = append(data, p)
	}
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
		controller.Data["json"] = response
		controller.ServeJSON()
	} else {
		// 新建文件
		f := excelize.NewFile()
		// 新建工作簿
		index := f.NewSheet("Sheet1")
		//列标题赋值
		for column, v := range titles {
			f.SetCellValue("Sheet1", cells[column] + "1", v)
		}
		for lineNum, v := range data {   //行数 lineNum  行内容 v
			for columnNum := 0; columnNum < len(v); columnNum ++ {
				cell := cells[columnNum]
				row := strconv.Itoa(lineNum + 2)
				switch cell {
				case "A":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["name"])
					break
				case "B":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["account"])
					break
				case "C":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["exchanged_cash"])
					break
				case "D":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["exchanged_su_money"])
					break
				}
			}
		}

		f.SetActiveSheet(index)

		// 创建下载文件夹
		mkErr :=os.Mkdir("download", os.ModePerm)
		if err!=nil{
			fmt.Println(mkErr)
		}

		//保存为文件
		f.Path="download/素币兑换清单.xlsx"
		if err := f.Save(); err != nil {
			fmt.Println(err)
		}

		controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx")

		// 下载完成删除文件
		removeErr := os.Remove(f.Path)
		if err != nil {
			fmt.Println(removeErr)
		}
	}
}

// 导出素币流水
func (controller *SuMoneyController) ExportSuMoney() {
	suMoneyService := service.NewSuMoneyService(nil)
	exportSuMoneyCommand := &command.ExportSuMoneyCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand)
	// 列标题
	titles := []string{
		"员工姓名","手机账号","当前素币",
	}
	// 列单元
	cells := []string{
		"A","B","C",
	}
	var response utils.JsonResponse
	var data []map[string]interface{}
	records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand)
	for _, record := range records {
		p := map[string]interface{} {
			"name": record.EmployeeInfo.EmployeeName,
			"account": record.EmployeeInfo.EmployeeAccount,
			"current_su_money": record.SuMoney,
		}
		data = append(data, p)
	}
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
		controller.Data["json"] = response
		controller.ServeJSON()
	} else {
		// 新建文件
		f := excelize.NewFile()

		// 新建工作簿
		index := f.NewSheet("Sheet1")

		//列标题赋值
		for column, v := range titles {
			f.SetCellValue("Sheet1", cells[column]+"1", v)
		}

		for lineNum, v := range data {   //行数 lineNum  行内容 v
			for columnNum := 0; columnNum < len(v); columnNum ++ {
				cell := cells[columnNum]
				row := strconv.Itoa(lineNum + 2)
				switch cell {
				case "A":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["name"])
					break
				case "B":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["account"])
					break
				case "C":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
					break
				}
			}
		}

		f.SetActiveSheet(index)

		// 创建下载文件夹
		mkErr :=os.Mkdir("download", os.ModePerm)
		if err!=nil{
			fmt.Println(mkErr)
		}

		//保存为文件
		f.Path="download/素币流水.xlsx"
		if err := f.Save(); err != nil {
			fmt.Println(err)
		}

		controller.Ctx.Output.Download(f.Path,"素币流水.xlsx")

		// 下载完成删除文件
		removeErr := os.Remove(f.Path)
		if err != nil {
			fmt.Println(removeErr)
		}
	}
}

// 导出素币流水记录
func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
	suMoneyService := service.NewSuMoneyService(nil)
	exportTransactionRecordCommand := &command.ExportTransactionRecordCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportTransactionRecordCommand)
	// 列标题
	titles := []string{
		"员工姓名","当前素币","素币流水","操作时间","操作人",
	}
	// 列单元
	cells := []string{
		"A","B","C","D","E",
	}
	var response utils.JsonResponse
	var data []map[string]interface{}
	records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
	for _, record := range records {
		p := map[string]interface{}{}
		if record.RecordType == 2 || record.RecordType == 3 || record.RecordType == 6 {
			p = map[string]interface{} {
				"name": record.Employee.EmployeeName,
				"current_su_money": record.CurrentSuMoney,
				"record": "+" + fmt.Sprintf("%.2f", record.SuMoney),
				"create_time": record.CreateTime.Local().Format("2006/01/02 15:04:05"),
				"operator": record.Operator.EmployeeName,
			}
		} else {
			p = map[string]interface{} {
				"name": record.Employee.EmployeeName,
				"current_su_money": record.CurrentSuMoney,
				"record": "-" + fmt.Sprintf("%.2f", record.SuMoney),
				"create_time": record.CreateTime.Local().Format("2006/01/02 15:04:05"),
				"operator": record.Operator.EmployeeName,
			}
		}
		data = append(data, p)
	}
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
		controller.Data["json"] = response
		controller.ServeJSON()
	} else {
		// 新建文件
		f := excelize.NewFile()
		// 新建工作簿
		index := f.NewSheet("Sheet1")
		//列标题赋值
		for column, v := range titles {
			f.SetCellValue("Sheet1", cells[column]+"1", v)
		}
		for lineNum, v := range data {   //行数 lineNum  行内容 v
			for columnNum := 0; columnNum < len(v); columnNum ++ {
				cell := cells[columnNum]
				row := strconv.Itoa(lineNum + 2)
				switch cell {
				case "A":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["name"])
					break
				case "B":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
					break
				case "C":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["record"])
					break
				case "D":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["create_time"])
					break
				case "E":
					sheetPosition := cell + row
					f.SetCellValue("Sheet1", sheetPosition, v["operator"])
					break
				}
			}
		}
		f.SetActiveSheet(index)
		// 创建下载文件夹
		mkErr :=os.Mkdir("download", os.ModePerm)
		if err!=nil{
			fmt.Println(mkErr)
		}
		//保存为文件
		f.Path="download/素币流水记录.xlsx"
		if err := f.Save(); err != nil {
			fmt.Println(err)
		}
		controller.Ctx.Output.Download(f.Path,"素币流水记录.xlsx")
		// 下载完成删除文件
		removeErr := os.Remove(f.Path)
		if err != nil {
			fmt.Println(removeErr)
		}
	}
}