作者 陈志颖

refactor:导入素币兑换清单

@@ -1319,7 +1319,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1319,7 +1319,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1319 1319
1320 // 导入新增兑换素币清单 1320 // 导入新增兑换素币清单
1321 func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand, failureDataList []interface{}) ([]interface{}, error) { 1321 func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand, failureDataList []interface{}) ([]interface{}, error) {
1322 - // 批量校验 1322 + // 新增素币兑换清单命令校验
1323 for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands { 1323 for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands {
1324 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil { 1324 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
1325 row := []interface{}{ 1325 row := []interface{}{
@@ -1332,7 +1332,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1332,7 +1332,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1332 continue 1332 continue
1333 } 1333 }
1334 } 1334 }
1335 -  
1336 if len(failureDataList) > 0 { 1335 if len(failureDataList) > 0 {
1337 return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, "校验失败") 1336 return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, "校验失败")
1338 } 1337 }
@@ -1432,12 +1431,11 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1432,12 +1431,11 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1432 failureDataList = append(failureDataList, row) 1431 failureDataList = append(failureDataList, row)
1433 continue 1432 continue
1434 } 1433 }
1435 -  
1436 - activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney  
1437 - activityFoundExchangedCash := activityFound.ExchangedCash 1434 + activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前兑换活动未兑换素币
  1435 + activityFoundExchangedCash := activityFound.ExchangedCash // 当前兑换活动已兑换素币
1438 1436
1439 // 获取当前公司现金池 1437 // 获取当前公司现金池
1440 - _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 1438 + cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
1441 "companyId": activityFound.CompanyId, 1439 "companyId": activityFound.CompanyId,
1442 }) 1440 })
1443 if err != nil { 1441 if err != nil {
@@ -1450,7 +1448,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1450,7 +1448,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1450 failureDataList = append(failureDataList, row) 1448 failureDataList = append(failureDataList, row)
1451 continue 1449 continue
1452 } 1450 }
1453 - if len(cashPoolsFound) == 0 { 1451 + if cashPoolFound == nil {
1454 row := []interface{}{ 1452 row := []interface{}{
1455 createExchangeCashPersonCommand.PersonName, 1453 createExchangeCashPersonCommand.PersonName,
1456 createExchangeCashPersonCommand.PersonAccount, 1454 createExchangeCashPersonCommand.PersonAccount,
@@ -1460,17 +1458,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1460,17 +1458,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1460 failureDataList = append(failureDataList, row) 1458 failureDataList = append(failureDataList, row)
1461 continue 1459 continue
1462 } 1460 }
  1461 + cashPoolFoundUnExchangeCash := cashPoolFound.UnExchangeCash // 当前公司现金池未兑换现金
  1462 + cashPoolFoundExchangedCash := cashPoolFound.ExchangedCash // 当前公司现金池已兑换现金
1463 1463
1464 - cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash  
1465 - cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash  
1466 -  
1467 - // 获取员工查询条件 1464 + // 判断当前员工是否有效
1468 getEmployee := map[string]interface{}{ 1465 getEmployee := map[string]interface{}{
1469 "account": createExchangeCashPersonCommand.PersonAccount, 1466 "account": createExchangeCashPersonCommand.PersonAccount,
1470 "companyId": activityFound.CompanyId, 1467 "companyId": activityFound.CompanyId,
1471 } 1468 }
1472 -  
1473 - // 判断当前员工是否有效  
1474 employeeFound, err := employeeRepository.FindOne(getEmployee) 1469 employeeFound, err := employeeRepository.FindOne(getEmployee)
1475 if err != nil { 1470 if err != nil {
1476 row := []interface{}{ 1471 row := []interface{}{
@@ -1491,29 +1486,46 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1491,29 +1486,46 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1491 } 1486 }
1492 failureDataList = append(failureDataList, row) 1487 failureDataList = append(failureDataList, row)
1493 continue 1488 continue
1494 - } else {  
1495 - employeeFoundSuMoney := employeeFound.SuMoney  
1496 - // 判断该员工兑换的素币是否超过本人持有的素币  
1497 - if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - employeeFoundSuMoney) {  
1498 - row := []interface{}{  
1499 - createExchangeCashPersonCommand.PersonName,  
1500 - createExchangeCashPersonCommand.PersonAccount,  
1501 - createExchangeCashPersonCommand.ExchangedSuMoney,  
1502 - "当前兑换素币超过本人持有的素币值",  
1503 - }  
1504 - failureDataList = append(failureDataList, row)  
1505 - continue  
1506 - }  
1507 } 1489 }
  1490 + employeeFoundSuMoney := employeeFound.SuMoney // 当前导入员工持有的素币值
  1491 +
  1492 + //else {
  1493 + // employeeFoundSuMoney := employeeFound.SuMoney
  1494 + // // 判断该员工兑换的素币是否超过本人持有的素币
  1495 + // if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - employeeFoundSuMoney) {
  1496 + // row := []interface{}{
  1497 + // createExchangeCashPersonCommand.PersonName,
  1498 + // createExchangeCashPersonCommand.PersonAccount,
  1499 + // createExchangeCashPersonCommand.ExchangedSuMoney,
  1500 + // "当前兑换素币超过本人持有的素币值",
  1501 + // }
  1502 + // failureDataList = append(failureDataList, row)
  1503 + // continue
  1504 + // }
  1505 + //}
1508 1506
1509 - employeeFoundSuMoney := employeeFound.SuMoney 1507 + //// 判断当前员工是否已经在素币兑换清单中
  1508 + //_, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
  1509 + // "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
  1510 + // "exchangeCashActivityId": activityFound.ActivityId,
  1511 + // "offset": 0,
  1512 + // "limit": 1,
  1513 + //})
  1514 + //if err != nil {
  1515 + // row := []interface{}{
  1516 + // createExchangeCashPersonCommand.PersonName,
  1517 + // createExchangeCashPersonCommand.PersonAccount,
  1518 + // createExchangeCashPersonCommand.ExchangedSuMoney,
  1519 + // err.Error(),
  1520 + // }
  1521 + // failureDataList = append(failureDataList, row)
  1522 + // continue
  1523 + //}
1510 1524
1511 // 判断当前员工是否已经在素币兑换清单中 1525 // 判断当前员工是否已经在素币兑换清单中
1512 - _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{ 1526 + personFound, _ := exchangeCashPersonListRepository.FindOne(map[string]interface{}{
1513 "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount, 1527 "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
1514 - "exchangeCashActivityId": activityFound.ActivityId,  
1515 - "offset": 0,  
1516 - "limit": 1, 1528 + "activityId": activityFound.ActivityId,
1517 }) 1529 })
1518 if err != nil { 1530 if err != nil {
1519 row := []interface{}{ 1531 row := []interface{}{
@@ -1525,29 +1537,213 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1525,29 +1537,213 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1525 failureDataList = append(failureDataList, row) 1537 failureDataList = append(failureDataList, row)
1526 continue 1538 continue
1527 } 1539 }
1528 - //if len(peopleFound) != 0 {  
1529 - // peopleFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney  
1530 - // // 判断该员工兑换的素币是否超过本人持有的素币  
1531 - // if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFoundExchangedSuMoney {  
1532 - // if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - peopleFoundExchangedSuMoney) {  
1533 - // row := []interface{}{  
1534 - // createExchangeCashPersonCommand.PersonName,  
1535 - // createExchangeCashPersonCommand.PersonAccount,  
1536 - // createExchangeCashPersonCommand.ExchangedSuMoney,  
1537 - // "当前兑换素币超过本人持有的素币值",  
1538 - // }  
1539 - // failureDataList = append(failureDataList, row)  
1540 - // continue  
1541 - // }  
1542 - // }  
1543 - //}  
1544 - if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换  
1545 - // 获取当前员工已兑换素币  
1546 - personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney 1540 + if personFound == nil { // 当前人员不在兑换素币清单中,新增兑换素币清单
  1541 + // 判断该员工兑换的素币是否超过本人持有的素币
  1542 + if (createExchangeCashPersonCommand.ExchangedSuMoney - employeeFoundSuMoney) > employeeFoundSuMoney {
  1543 + row := []interface{}{
  1544 + createExchangeCashPersonCommand.PersonName,
  1545 + createExchangeCashPersonCommand.PersonAccount,
  1546 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1547 + "当前兑换素币超过本人持有的素币值",
  1548 + }
  1549 + failureDataList = append(failureDataList, row)
  1550 + continue
  1551 + }
  1552 +
  1553 + // 新增兑换素币清单
  1554 + newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
  1555 + newPerson := &domain.ExchangeCashPersonList{
  1556 + EmployeeInfo: &domain.EmployeeInfo{
  1557 + Uid: employeeFound.EmployeeInfo.Uid,
  1558 + EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
  1559 + EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
  1560 + },
  1561 + ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
  1562 + ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1563 + ExchangedCash: newPersonExchangedCash,
  1564 + }
  1565 + personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
  1566 + if err != nil {
  1567 + row := []interface{}{
  1568 + createExchangeCashPersonCommand.PersonName,
  1569 + createExchangeCashPersonCommand.PersonAccount,
  1570 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1571 + err.Error(),
  1572 + }
  1573 + failureDataList = append(failureDataList, row)
  1574 + continue
  1575 + }
  1576 + if personSaved == nil {
  1577 + row := []interface{}{
  1578 + createExchangeCashPersonCommand.PersonName,
  1579 + createExchangeCashPersonCommand.PersonAccount,
  1580 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1581 + "保存到兑换素币清单失败",
  1582 + }
  1583 + failureDataList = append(failureDataList, row)
  1584 + continue
  1585 + }
1547 1586
1548 - // 获取当前兑换员工已兑换现金  
1549 - //personFoundExchangedCash := peopleFound[0].ExchangedCash 1587 + // 操作素币,生成素币流水
  1588 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  1589 + Uid: employeeFound.EmployeeInfo.Uid,
  1590 + Operator: createExchangeCashPersonCommand.Operator,
  1591 + SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1592 + OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1593 + OperationDescription: "参与" + activityFound.ExchangeActivityName,
  1594 + }
  1595 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  1596 + if err != nil {
  1597 + row := []interface{}{
  1598 + createExchangeCashPersonCommand.PersonName,
  1599 + createExchangeCashPersonCommand.PersonAccount,
  1600 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1601 + "内部业务错误" + err.Error(),
  1602 + }
  1603 + failureDataList = append(failureDataList, row)
  1604 + continue
  1605 + }
  1606 + if task == nil {
  1607 + row := []interface{}{
  1608 + createExchangeCashPersonCommand.PersonName,
  1609 + createExchangeCashPersonCommand.PersonAccount,
  1610 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1611 + "操作素币失败",
  1612 + }
  1613 + failureDataList = append(failureDataList, row)
  1614 + continue
  1615 + }
1550 1616
  1617 + // 更新兑换活动
  1618 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  1619 + ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
  1620 + ExchangeActivityName: activityFound.ExchangeActivityName,
  1621 + ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
  1622 + ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
  1623 + Deadline: activityFound.Deadline,
  1624 + CountDown: activityFound.CountDown,
  1625 + ExchangeRate: activityFound.Rate,
  1626 + }
  1627 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  1628 + row := []interface{}{
  1629 + createExchangeCashPersonCommand.PersonName,
  1630 + createExchangeCashPersonCommand.PersonAccount,
  1631 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1632 + err.Error(),
  1633 + }
  1634 + failureDataList = append(failureDataList, row)
  1635 + continue
  1636 + }
  1637 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  1638 + if err != nil {
  1639 + row := []interface{}{
  1640 + createExchangeCashPersonCommand.PersonName,
  1641 + createExchangeCashPersonCommand.PersonAccount,
  1642 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1643 + err.Error(),
  1644 + }
  1645 + failureDataList = append(failureDataList, row)
  1646 + continue
  1647 + }
  1648 + if activityUpdated == nil {
  1649 + row := []interface{}{
  1650 + createExchangeCashPersonCommand.PersonName,
  1651 + createExchangeCashPersonCommand.PersonAccount,
  1652 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1653 + "更新兑换活动失败",
  1654 + }
  1655 + failureDataList = append(failureDataList, row)
  1656 + continue
  1657 + }
  1658 +
  1659 + // 判断是否超过平台未兑换现金
  1660 + if createExchangeCashPersonCommand.ExchangedSuMoney * activityUpdated.Rate > cashPoolFoundUnExchangeCash {
  1661 + row := []interface{}{
  1662 + createExchangeCashPersonCommand.PersonName,
  1663 + createExchangeCashPersonCommand.PersonAccount,
  1664 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1665 + "已超过投入现金池的未兑换现金",
  1666 + }
  1667 + failureDataList = append(failureDataList, row)
  1668 + continue
  1669 + }
  1670 +
  1671 + // 获取平台素币兑换情况
  1672 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
  1673 + if err != nil {
  1674 + row := []interface{}{
  1675 + createExchangeCashPersonCommand.PersonName,
  1676 + createExchangeCashPersonCommand.PersonAccount,
  1677 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1678 + err.Error(),
  1679 + }
  1680 + failureDataList = append(failureDataList, row)
  1681 + continue
  1682 + }
  1683 + if systemSuMoneyStatistics == nil {
  1684 + row := []interface{}{
  1685 + createExchangeCashPersonCommand.PersonName,
  1686 + createExchangeCashPersonCommand.PersonAccount,
  1687 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1688 + "获取公司素币兑换情况失败",
  1689 + }
  1690 + failureDataList = append(failureDataList, row)
  1691 + continue
  1692 + }
  1693 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 公司已兑换素币
  1694 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
  1695 +
  1696 + // 更新现金池
  1697 + var newRate float64
  1698 + if systemExchangedSuMoney == 0 {
  1699 + newRate = 0
  1700 + } else {
  1701 + newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
  1702 + }
  1703 + updateCashPoolCommand := &command.UpdateCashPoolCommand{
  1704 + CashPoolId: cashPoolFound.CashPoolId,
  1705 + Cash: cashPoolFound.Cash,
  1706 + ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
  1707 + UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
  1708 + ExchangedSuMoney: systemExchangedSuMoney,
  1709 + UnExchangeSuMoney: systemUnExchangeSuMoney,
  1710 + Rate: newRate,
  1711 + LastRate: cashPoolFound.LastRate,
  1712 + }
  1713 + if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
  1714 + row := []interface{}{
  1715 + createExchangeCashPersonCommand.PersonName,
  1716 + createExchangeCashPersonCommand.PersonAccount,
  1717 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1718 + err.Error(),
  1719 + }
  1720 + failureDataList = append(failureDataList, row)
  1721 + continue
  1722 + }
  1723 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolFound)
  1724 + if err != nil {
  1725 + row := []interface{}{
  1726 + createExchangeCashPersonCommand.PersonName,
  1727 + createExchangeCashPersonCommand.PersonAccount,
  1728 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1729 + err.Error(),
  1730 + }
  1731 + failureDataList = append(failureDataList, row)
  1732 + continue
  1733 + }
  1734 + if cashPoolUpdated == nil {
  1735 + row := []interface{}{
  1736 + createExchangeCashPersonCommand.PersonName,
  1737 + createExchangeCashPersonCommand.PersonAccount,
  1738 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1739 + err.Error(),
  1740 + }
  1741 + failureDataList = append(failureDataList, row)
  1742 + continue
  1743 + }
  1744 + } else { // 当前人员存在兑换素币清单中
  1745 + personFoundExchangedSuMoney := personFound.ExchangedSuMoney // 当前素币清单已兑换素币
  1746 + personFoundExchangedCash := personFound.ExchangedCash // 当前素币清单已兑换现金
1551 if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币 1747 if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
1552 // 素币减量 1748 // 素币减量
1553 suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney 1749 suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
@@ -1555,16 +1751,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1555,16 +1751,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1555 // 现金减量 1751 // 现金减量
1556 cashDecrement := suMoneyDecrement * activityFound.Rate 1752 cashDecrement := suMoneyDecrement * activityFound.Rate
1557 1753
1558 - // 更新兑换素币清单命令 1754 + // 更新兑换素币清单
1559 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{ 1755 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
1560 - ListId: peopleFound[0].ListId, 1756 + ListId: personFound.ListId,
1561 ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement, 1757 ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,
1562 - ExchangedCash: (personFoundExchangedSuMoney - suMoneyDecrement) * activityFound.Rate, 1758 + ExchangedCash: personFoundExchangedCash - cashDecrement,
1563 Operator: createExchangeCashPersonCommand.Operator, 1759 Operator: createExchangeCashPersonCommand.Operator,
1564 } 1760 }
1565 -  
1566 - // 更新兑换素币清单  
1567 - if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 1761 + if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
1568 row := []interface{}{ 1762 row := []interface{}{
1569 createExchangeCashPersonCommand.PersonName, 1763 createExchangeCashPersonCommand.PersonName,
1570 createExchangeCashPersonCommand.PersonAccount, 1764 createExchangeCashPersonCommand.PersonAccount,
@@ -1574,9 +1768,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1574,9 +1768,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1574 failureDataList = append(failureDataList, row) 1768 failureDataList = append(failureDataList, row)
1575 continue 1769 continue
1576 } 1770 }
1577 -  
1578 - // 保存兑换素币清单更新  
1579 - _, err := exchangeCashPersonListRepository.Save(peopleFound[0]) 1771 + exchangeCashPersonListUpdated, err := exchangeCashPersonListRepository.Save(personFound)
1580 if err != nil { 1772 if err != nil {
1581 row := []interface{}{ 1773 row := []interface{}{
1582 createExchangeCashPersonCommand.PersonName, 1774 createExchangeCashPersonCommand.PersonName,
@@ -1587,18 +1779,26 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1587,18 +1779,26 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1587 failureDataList = append(failureDataList, row) 1779 failureDataList = append(failureDataList, row)
1588 continue 1780 continue
1589 } 1781 }
  1782 + if exchangeCashPersonListUpdated == nil {
  1783 + row := []interface{}{
  1784 + createExchangeCashPersonCommand.PersonName,
  1785 + createExchangeCashPersonCommand.PersonAccount,
  1786 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1787 + "保存到兑换素币清单失败",
  1788 + }
  1789 + failureDataList = append(failureDataList, row)
  1790 + continue
  1791 + }
1590 1792
1591 - // 更新素币兑换活动命令 1793 + // 更新素币兑换活动
1592 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1794 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1593 - ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId, 1795 + ExchangeCashActivityId: personFound.ExchangeCashActivityId,
1594 ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement, 1796 ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement,
1595 ExchangedCash: activityFoundExchangedCash - cashDecrement, 1797 ExchangedCash: activityFoundExchangedCash - cashDecrement,
1596 Deadline: activityFound.Deadline, 1798 Deadline: activityFound.Deadline,
1597 CountDown: activityFound.CountDown, 1799 CountDown: activityFound.CountDown,
1598 ExchangeRate: activityFound.Rate, 1800 ExchangeRate: activityFound.Rate,
1599 } 1801 }
1600 -  
1601 - // 更新兑换活动  
1602 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 1802 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
1603 row := []interface{}{ 1803 row := []interface{}{
1604 createExchangeCashPersonCommand.PersonName, 1804 createExchangeCashPersonCommand.PersonName,
@@ -1609,8 +1809,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1609,8 +1809,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1609 failureDataList = append(failureDataList, row) 1809 failureDataList = append(failureDataList, row)
1610 continue 1810 continue
1611 } 1811 }
1612 -  
1613 - // 保存兑换现金活动更新  
1614 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 1812 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
1615 if err != nil { 1813 if err != nil {
1616 row := []interface{}{ 1814 row := []interface{}{
@@ -1633,25 +1831,21 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1633,25 +1831,21 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1633 continue 1831 continue
1634 } 1832 }
1635 1833
1636 - // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励  
1637 -  
1638 - // 个人素币操作命令 1834 + // 操作个人素币,生成素币流水记录
1639 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1835 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1640 Uid: employeeFound.EmployeeInfo.Uid, 1836 Uid: employeeFound.EmployeeInfo.Uid,
1641 Operator: createExchangeCashPersonCommand.Operator, 1837 Operator: createExchangeCashPersonCommand.Operator,
1642 SuMoney: suMoneyDecrement, 1838 SuMoney: suMoneyDecrement,
1643 - OperationType: 41, 1839 + OperationType: 41, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
1644 OperationDescription: activityFound.ExchangeActivityName + "调整", 1840 OperationDescription: activityFound.ExchangeActivityName + "调整",
1645 } 1841 }
1646 -  
1647 - // 操作个人素币,生成素币流水记录  
1648 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 1842 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
1649 if err != nil { 1843 if err != nil {
1650 row := []interface{}{ 1844 row := []interface{}{
1651 createExchangeCashPersonCommand.PersonName, 1845 createExchangeCashPersonCommand.PersonName,
1652 createExchangeCashPersonCommand.PersonAccount, 1846 createExchangeCashPersonCommand.PersonAccount,
1653 createExchangeCashPersonCommand.ExchangedSuMoney, 1847 createExchangeCashPersonCommand.ExchangedSuMoney,
1654 - "操作个人素币失败", 1848 + err.Error(),
1655 } 1849 }
1656 failureDataList = append(failureDataList, row) 1850 failureDataList = append(failureDataList, row)
1657 continue 1851 continue
@@ -1667,20 +1861,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1667,20 +1861,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1667 continue 1861 continue
1668 } 1862 }
1669 1863
1670 - // 判断是否超过平台未兑换现金  
1671 - if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {  
1672 - if (activityUpdated.ExchangedSuMoney - activityFoundExchangedSuMoney) * activityUpdated.Rate > cashPoolFoundUnExchangeCash {  
1673 - row := []interface{}{  
1674 - createExchangeCashPersonCommand.PersonName,  
1675 - createExchangeCashPersonCommand.PersonAccount,  
1676 - createExchangeCashPersonCommand.ExchangedSuMoney,  
1677 - "已超过现金池未兑换现金",  
1678 - }  
1679 - failureDataList = append(failureDataList, row)  
1680 - continue  
1681 - }  
1682 - }  
1683 -  
1684 // 获取平台素币兑换情况 1864 // 获取平台素币兑换情况
1685 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId) 1865 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
1686 if err != nil { 1866 if err != nil {
@@ -1698,36 +1878,32 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1698,36 +1878,32 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1698 createExchangeCashPersonCommand.PersonName, 1878 createExchangeCashPersonCommand.PersonName,
1699 createExchangeCashPersonCommand.PersonAccount, 1879 createExchangeCashPersonCommand.PersonAccount,
1700 createExchangeCashPersonCommand.ExchangedSuMoney, 1880 createExchangeCashPersonCommand.ExchangedSuMoney,
1701 - "无效的公司", 1881 + "获取公司素币兑换情况失败",
1702 } 1882 }
1703 failureDataList = append(failureDataList, row) 1883 failureDataList = append(failureDataList, row)
1704 continue 1884 continue
1705 } 1885 }
1706 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)  
1707 - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1886 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 公司已兑换素币
  1887 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 公司未兑换素币
1708 1888
1709 - // 计算平均兑换汇率 1889 + // 更新现金池
1710 var newRate float64 1890 var newRate float64
1711 if systemExchangedSuMoney == 0 { 1891 if systemExchangedSuMoney == 0 {
1712 newRate = 0 1892 newRate = 0
1713 } else { 1893 } else {
1714 newRate = (cashPoolFoundExchangedCash - cashDecrement) / systemExchangedSuMoney 1894 newRate = (cashPoolFoundExchangedCash - cashDecrement) / systemExchangedSuMoney
1715 } 1895 }
1716 -  
1717 - // 更新现金池命令  
1718 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1896 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1719 - CashPoolId: cashPoolsFound[0].CashPoolId,  
1720 - Cash: cashPoolsFound[0].Cash, 1897 + CashPoolId: cashPoolFound.CashPoolId,
  1898 + Cash: cashPoolFound.Cash,
1721 ExchangedCash: cashPoolFoundExchangedCash - cashDecrement, 1899 ExchangedCash: cashPoolFoundExchangedCash - cashDecrement,
1722 UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement, 1900 UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement,
1723 ExchangedSuMoney: systemExchangedSuMoney, 1901 ExchangedSuMoney: systemExchangedSuMoney,
1724 UnExchangeSuMoney: systemUnExchangeSuMoney, 1902 UnExchangeSuMoney: systemUnExchangeSuMoney,
1725 Rate: newRate, 1903 Rate: newRate,
1726 - LastRate: cashPoolsFound[0].LastRate, 1904 + LastRate: cashPoolFound.LastRate,
1727 } 1905 }
1728 -  
1729 - // 更新现金池  
1730 - if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 1906 + if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1731 row := []interface{}{ 1907 row := []interface{}{
1732 createExchangeCashPersonCommand.PersonName, 1908 createExchangeCashPersonCommand.PersonName,
1733 createExchangeCashPersonCommand.PersonAccount, 1909 createExchangeCashPersonCommand.PersonAccount,
@@ -1737,15 +1913,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1737,15 +1913,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1737 failureDataList = append(failureDataList, row) 1913 failureDataList = append(failureDataList, row)
1738 continue 1914 continue
1739 } 1915 }
1740 -  
1741 - // 保存现金池更新  
1742 - cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0]) 1916 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolFound)
1743 if err != nil { 1917 if err != nil {
1744 row := []interface{}{ 1918 row := []interface{}{
1745 createExchangeCashPersonCommand.PersonName, 1919 createExchangeCashPersonCommand.PersonName,
1746 createExchangeCashPersonCommand.PersonAccount, 1920 createExchangeCashPersonCommand.PersonAccount,
1747 createExchangeCashPersonCommand.ExchangedSuMoney, 1921 createExchangeCashPersonCommand.ExchangedSuMoney,
1748 - "内部业务错误" + err.Error(), 1922 + err.Error(),
1749 } 1923 }
1750 failureDataList = append(failureDataList, row) 1924 failureDataList = append(failureDataList, row)
1751 continue 1925 continue
@@ -1755,7 +1929,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1755,7 +1929,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1755 createExchangeCashPersonCommand.PersonName, 1929 createExchangeCashPersonCommand.PersonName,
1756 createExchangeCashPersonCommand.PersonAccount, 1930 createExchangeCashPersonCommand.PersonAccount,
1757 createExchangeCashPersonCommand.ExchangedSuMoney, 1931 createExchangeCashPersonCommand.ExchangedSuMoney,
1758 - "内部业务错误" + err.Error(), 1932 + "更新现金池失败",
1759 } 1933 }
1760 failureDataList = append(failureDataList, row) 1934 failureDataList = append(failureDataList, row)
1761 continue 1935 continue
@@ -1768,7 +1942,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1768,7 +1942,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1768 cashIncrement := suMoneyIncrement * activityFound.Rate 1942 cashIncrement := suMoneyIncrement * activityFound.Rate
1769 1943
1770 // 判断该员工兑换的素币是否超过本人持有的素币 1944 // 判断该员工兑换的素币是否超过本人持有的素币
1771 - if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - employeeFoundSuMoney) { 1945 + if suMoneyIncrement > employeeFoundSuMoney {
1772 row := []interface{}{ 1946 row := []interface{}{
1773 createExchangeCashPersonCommand.PersonName, 1947 createExchangeCashPersonCommand.PersonName,
1774 createExchangeCashPersonCommand.PersonAccount, 1948 createExchangeCashPersonCommand.PersonAccount,
@@ -1779,69 +1953,71 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1779,69 +1953,71 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1779 continue 1953 continue
1780 } 1954 }
1781 1955
1782 - // 更新兑换素币清单命令 1956 + // 更新兑换素币清单
1783 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{ 1957 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
1784 - ListId: peopleFound[0].ListId, 1958 + ListId: personFound.ListId,
1785 ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement, 1959 ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,
1786 - ExchangedCash: (personFoundExchangedSuMoney + suMoneyIncrement) * activityFound.Rate, 1960 + ExchangedCash: personFoundExchangedCash + cashIncrement,
1787 Operator: createExchangeCashPersonCommand.Operator, 1961 Operator: createExchangeCashPersonCommand.Operator,
1788 } 1962 }
1789 -  
1790 - // 更新兑换素币清单  
1791 - if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 1963 + if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
1792 row := []interface{}{ 1964 row := []interface{}{
1793 createExchangeCashPersonCommand.PersonName, 1965 createExchangeCashPersonCommand.PersonName,
1794 createExchangeCashPersonCommand.PersonAccount, 1966 createExchangeCashPersonCommand.PersonAccount,
1795 createExchangeCashPersonCommand.ExchangedSuMoney, 1967 createExchangeCashPersonCommand.ExchangedSuMoney,
1796 - "内部业务错误" + err.Error(), 1968 + err.Error(),
1797 } 1969 }
1798 failureDataList = append(failureDataList, row) 1970 failureDataList = append(failureDataList, row)
1799 continue 1971 continue
1800 } 1972 }
1801 -  
1802 - // 保存兑换素币清单更新  
1803 - _, err := exchangeCashPersonListRepository.Save(peopleFound[0]) 1973 + exchangeCashPersonListUpdated, err := exchangeCashPersonListRepository.Save(personFound)
1804 if err != nil { 1974 if err != nil {
1805 row := []interface{}{ 1975 row := []interface{}{
1806 createExchangeCashPersonCommand.PersonName, 1976 createExchangeCashPersonCommand.PersonName,
1807 createExchangeCashPersonCommand.PersonAccount, 1977 createExchangeCashPersonCommand.PersonAccount,
1808 createExchangeCashPersonCommand.ExchangedSuMoney, 1978 createExchangeCashPersonCommand.ExchangedSuMoney,
1809 - "内部业务错误" + err.Error(), 1979 + err.Error(),
  1980 + }
  1981 + failureDataList = append(failureDataList, row)
  1982 + continue
  1983 + }
  1984 + if exchangeCashPersonListUpdated == nil {
  1985 + row := []interface{}{
  1986 + createExchangeCashPersonCommand.PersonName,
  1987 + createExchangeCashPersonCommand.PersonAccount,
  1988 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1989 + "保存到兑换现金活动失败",
1810 } 1990 }
1811 failureDataList = append(failureDataList, row) 1991 failureDataList = append(failureDataList, row)
1812 continue 1992 continue
1813 } 1993 }
1814 1994
1815 - // 更新素币兑换活动命令 1995 + // 更新兑换活动
1816 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1996 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1817 - ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId, 1997 + ExchangeCashActivityId: personFound.ExchangeCashActivityId,
1818 ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement, 1998 ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement,
1819 ExchangedCash: activityFoundExchangedCash + cashIncrement, 1999 ExchangedCash: activityFoundExchangedCash + cashIncrement,
1820 Deadline: activityFound.Deadline, 2000 Deadline: activityFound.Deadline,
1821 CountDown: activityFound.CountDown, 2001 CountDown: activityFound.CountDown,
1822 ExchangeRate: activityFound.Rate, 2002 ExchangeRate: activityFound.Rate,
1823 } 2003 }
1824 -  
1825 - // 更新兑换活动  
1826 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 2004 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
1827 row := []interface{}{ 2005 row := []interface{}{
1828 createExchangeCashPersonCommand.PersonName, 2006 createExchangeCashPersonCommand.PersonName,
1829 createExchangeCashPersonCommand.PersonAccount, 2007 createExchangeCashPersonCommand.PersonAccount,
1830 createExchangeCashPersonCommand.ExchangedSuMoney, 2008 createExchangeCashPersonCommand.ExchangedSuMoney,
1831 - "内部业务错误" + err.Error(), 2009 + err.Error(),
1832 } 2010 }
1833 failureDataList = append(failureDataList, row) 2011 failureDataList = append(failureDataList, row)
1834 continue 2012 continue
1835 } 2013 }
1836 -  
1837 - // 保存兑换现金活动更新  
1838 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 2014 activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
1839 if err != nil { 2015 if err != nil {
1840 row := []interface{}{ 2016 row := []interface{}{
1841 createExchangeCashPersonCommand.PersonName, 2017 createExchangeCashPersonCommand.PersonName,
1842 createExchangeCashPersonCommand.PersonAccount, 2018 createExchangeCashPersonCommand.PersonAccount,
1843 createExchangeCashPersonCommand.ExchangedSuMoney, 2019 createExchangeCashPersonCommand.ExchangedSuMoney,
1844 - "内部业务错误" + err.Error(), 2020 + err.Error(),
1845 } 2021 }
1846 failureDataList = append(failureDataList, row) 2022 failureDataList = append(failureDataList, row)
1847 continue 2023 continue
@@ -1851,31 +2027,27 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1851,31 +2027,27 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1851 createExchangeCashPersonCommand.PersonName, 2027 createExchangeCashPersonCommand.PersonName,
1852 createExchangeCashPersonCommand.PersonAccount, 2028 createExchangeCashPersonCommand.PersonAccount,
1853 createExchangeCashPersonCommand.ExchangedSuMoney, 2029 createExchangeCashPersonCommand.ExchangedSuMoney,
1854 - "内部业务错误", 2030 + "保存到兑换现金活动失败",
1855 } 2031 }
1856 failureDataList = append(failureDataList, row) 2032 failureDataList = append(failureDataList, row)
1857 continue 2033 continue
1858 } 2034 }
1859 2035
1860 - // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励  
1861 -  
1862 - // 操作素币命令 2036 + // 操作素币,生成素币流水
1863 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 2037 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1864 Uid: employeeFound.EmployeeInfo.Uid, 2038 Uid: employeeFound.EmployeeInfo.Uid,
1865 Operator: createExchangeCashPersonCommand.Operator, 2039 Operator: createExchangeCashPersonCommand.Operator,
1866 SuMoney: suMoneyIncrement, 2040 SuMoney: suMoneyIncrement,
1867 - OperationType: 4, 2041 + OperationType: 4, // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
1868 OperationDescription: activityFound.ExchangeActivityName + "调整", 2042 OperationDescription: activityFound.ExchangeActivityName + "调整",
1869 } 2043 }
1870 -  
1871 - // 操作素币,生成素币流水  
1872 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 2044 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
1873 if err != nil { 2045 if err != nil {
1874 row := []interface{}{ 2046 row := []interface{}{
1875 createExchangeCashPersonCommand.PersonName, 2047 createExchangeCashPersonCommand.PersonName,
1876 createExchangeCashPersonCommand.PersonAccount, 2048 createExchangeCashPersonCommand.PersonAccount,
1877 createExchangeCashPersonCommand.ExchangedSuMoney, 2049 createExchangeCashPersonCommand.ExchangedSuMoney,
1878 - "内部业务错误" + err.Error(), 2050 + err.Error(),
1879 } 2051 }
1880 failureDataList = append(failureDataList, row) 2052 failureDataList = append(failureDataList, row)
1881 continue 2053 continue
@@ -1885,33 +2057,19 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1885,33 +2057,19 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1885 createExchangeCashPersonCommand.PersonName, 2057 createExchangeCashPersonCommand.PersonName,
1886 createExchangeCashPersonCommand.PersonAccount, 2058 createExchangeCashPersonCommand.PersonAccount,
1887 createExchangeCashPersonCommand.ExchangedSuMoney, 2059 createExchangeCashPersonCommand.ExchangedSuMoney,
1888 - "内部业务错误", 2060 + "操作素币错误",
1889 } 2061 }
1890 failureDataList = append(failureDataList, row) 2062 failureDataList = append(failureDataList, row)
1891 continue 2063 continue
1892 } 2064 }
1893 2065
1894 - //// 判断是否超过平台未兑换现金  
1895 - //if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {  
1896 - // if (activityUpdated.ExchangedSuMoney - activityFoundExchangedSuMoney) * activityUpdated.Rate > cashPoolFoundUnExchangeCash {  
1897 - // row := []interface{}{  
1898 - // createExchangeCashPersonCommand.PersonName,  
1899 - // createExchangeCashPersonCommand.PersonAccount,  
1900 - // createExchangeCashPersonCommand.ExchangedSuMoney,  
1901 - // "已超过现金池未兑换现金",  
1902 - // }  
1903 - // failureDataList = append(failureDataList, row)  
1904 - // continue  
1905 - // }  
1906 - //}  
1907 -  
1908 // 判断是否超过平台未兑换现金 2066 // 判断是否超过平台未兑换现金
1909 - if createExchangeCashPersonCommand.ExchangedSuMoney * activityUpdated.Rate > cashPoolFoundUnExchangeCash { 2067 + if personFoundExchangedCash > cashPoolFoundUnExchangeCash {
1910 row := []interface{}{ 2068 row := []interface{}{
1911 createExchangeCashPersonCommand.PersonName, 2069 createExchangeCashPersonCommand.PersonName,
1912 createExchangeCashPersonCommand.PersonAccount, 2070 createExchangeCashPersonCommand.PersonAccount,
1913 createExchangeCashPersonCommand.ExchangedSuMoney, 2071 createExchangeCashPersonCommand.ExchangedSuMoney,
1914 - "已超过现金池未兑换现金", 2072 + "已超过投入现金池的未兑换现金",
1915 } 2073 }
1916 failureDataList = append(failureDataList, row) 2074 failureDataList = append(failureDataList, row)
1917 continue 2075 continue
@@ -1942,46 +2100,40 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1942,46 +2100,40 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1942 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 2100 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1943 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 2101 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1944 2102
1945 - // 计算平均兑换汇率 2103 + // 更新现金池命令
1946 var newRate float64 2104 var newRate float64
1947 if systemExchangedSuMoney == 0 { 2105 if systemExchangedSuMoney == 0 {
1948 newRate = 0 2106 newRate = 0
1949 } else { 2107 } else {
1950 newRate = (cashPoolFoundExchangedCash + cashIncrement) / systemExchangedSuMoney 2108 newRate = (cashPoolFoundExchangedCash + cashIncrement) / systemExchangedSuMoney
1951 } 2109 }
1952 -  
1953 - // 更新现金池命令  
1954 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 2110 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1955 - CashPoolId: cashPoolsFound[0].CashPoolId,  
1956 - Cash: cashPoolsFound[0].Cash, 2111 + CashPoolId: cashPoolFound.CashPoolId,
  2112 + Cash: cashPoolFound.Cash,
1957 ExchangedCash: cashPoolFoundExchangedCash + cashIncrement, 2113 ExchangedCash: cashPoolFoundExchangedCash + cashIncrement,
1958 UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement, 2114 UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement,
1959 ExchangedSuMoney: systemExchangedSuMoney, 2115 ExchangedSuMoney: systemExchangedSuMoney,
1960 UnExchangeSuMoney: systemUnExchangeSuMoney, 2116 UnExchangeSuMoney: systemUnExchangeSuMoney,
1961 Rate: newRate, 2117 Rate: newRate,
1962 - LastRate: cashPoolsFound[0].LastRate, 2118 + LastRate: cashPoolFound.LastRate,
1963 } 2119 }
1964 -  
1965 - // 更新现金池  
1966 - if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 2120 + if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1967 row := []interface{}{ 2121 row := []interface{}{
1968 createExchangeCashPersonCommand.PersonName, 2122 createExchangeCashPersonCommand.PersonName,
1969 createExchangeCashPersonCommand.PersonAccount, 2123 createExchangeCashPersonCommand.PersonAccount,
1970 createExchangeCashPersonCommand.ExchangedSuMoney, 2124 createExchangeCashPersonCommand.ExchangedSuMoney,
1971 - "内部业务错误" + err.Error(), 2125 + err.Error(),
1972 } 2126 }
1973 failureDataList = append(failureDataList, row) 2127 failureDataList = append(failureDataList, row)
1974 continue 2128 continue
1975 } 2129 }
1976 -  
1977 - // 保存现金池更新  
1978 - cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0]) 2130 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolFound)
1979 if err != nil { 2131 if err != nil {
1980 row := []interface{}{ 2132 row := []interface{}{
1981 createExchangeCashPersonCommand.PersonName, 2133 createExchangeCashPersonCommand.PersonName,
1982 createExchangeCashPersonCommand.PersonAccount, 2134 createExchangeCashPersonCommand.PersonAccount,
1983 createExchangeCashPersonCommand.ExchangedSuMoney, 2135 createExchangeCashPersonCommand.ExchangedSuMoney,
1984 - "内务业务错误" + err.Error(), 2136 + err.Error(),
1985 } 2137 }
1986 failureDataList = append(failureDataList, row) 2138 failureDataList = append(failureDataList, row)
1987 continue 2139 continue
@@ -1991,247 +2143,49 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1991,247 +2143,49 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1991 createExchangeCashPersonCommand.PersonName, 2143 createExchangeCashPersonCommand.PersonName,
1992 createExchangeCashPersonCommand.PersonAccount, 2144 createExchangeCashPersonCommand.PersonAccount,
1993 createExchangeCashPersonCommand.ExchangedSuMoney, 2145 createExchangeCashPersonCommand.ExchangedSuMoney,
1994 - "内部业务错误" + err.Error(), 2146 + err.Error(),
1995 } 2147 }
1996 failureDataList = append(failureDataList, row) 2148 failureDataList = append(failureDataList, row)
1997 continue 2149 continue
1998 } 2150 }
1999 } 2151 }
2000 - } else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单  
2001 - // 判断该员工兑换的素币是否超过本人持有的素币  
2002 - if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - employeeFoundSuMoney) {  
2003 - row := []interface{}{  
2004 - createExchangeCashPersonCommand.PersonName,  
2005 - createExchangeCashPersonCommand.PersonAccount,  
2006 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2007 - "当前兑换素币超过本人持有的素币值",  
2008 - }  
2009 - failureDataList = append(failureDataList, row)  
2010 - continue  
2011 - }  
2012 -  
2013 - // 新增兑换素币清单命令  
2014 - newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)  
2015 - newPerson := &domain.ExchangeCashPersonList{  
2016 - EmployeeInfo: &domain.EmployeeInfo{  
2017 - Uid: employeeFound.EmployeeInfo.Uid,  
2018 - EmployeeName: employeeFound.EmployeeInfo.EmployeeName,  
2019 - EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,  
2020 - },  
2021 - ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,  
2022 - ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,  
2023 - ExchangedCash: newPersonExchangedCash,  
2024 - }  
2025 -  
2026 - // 保存兑换素币清单  
2027 - personSaved, err := exchangeCashPersonListRepository.Save(newPerson)  
2028 - if err != nil {  
2029 - row := []interface{}{  
2030 - createExchangeCashPersonCommand.PersonName,  
2031 - createExchangeCashPersonCommand.PersonAccount,  
2032 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2033 - "内务业务错误" + err.Error(),  
2034 - }  
2035 - failureDataList = append(failureDataList, row)  
2036 - continue  
2037 - }  
2038 -  
2039 - // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励  
2040 -  
2041 - // 操作素币命令  
2042 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{  
2043 - Uid: employeeFound.EmployeeInfo.Uid,  
2044 - Operator: createExchangeCashPersonCommand.Operator,  
2045 - SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,  
2046 - OperationType: 4,  
2047 - OperationDescription: "参与" + activityFound.ExchangeActivityName,  
2048 - }  
2049 -  
2050 - // 操作素币,生成素币流水  
2051 - task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)  
2052 - if err != nil {  
2053 - row := []interface{}{  
2054 - createExchangeCashPersonCommand.PersonName,  
2055 - createExchangeCashPersonCommand.PersonAccount,  
2056 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2057 - "内部业务错误" + err.Error(),  
2058 - }  
2059 - failureDataList = append(failureDataList, row)  
2060 - continue  
2061 - }  
2062 - if task == nil {  
2063 - row := []interface{}{  
2064 - createExchangeCashPersonCommand.PersonName,  
2065 - createExchangeCashPersonCommand.PersonAccount,  
2066 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2067 - "内部业务错误",  
2068 - }  
2069 - failureDataList = append(failureDataList, row)  
2070 - continue  
2071 - }  
2072 -  
2073 - // 更新兑换活动命令  
2074 - updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{  
2075 - ExchangeCashActivityId: personSaved.ExchangeCashActivityId,  
2076 - ExchangeActivityName: activityFound.ExchangeActivityName,  
2077 - ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,  
2078 - ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,  
2079 - Deadline: activityFound.Deadline,  
2080 - CountDown: activityFound.CountDown,  
2081 - ExchangeRate: activityFound.Rate,  
2082 - }  
2083 -  
2084 - // 更新兑换活动  
2085 - if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {  
2086 - row := []interface{}{  
2087 - createExchangeCashPersonCommand.PersonName,  
2088 - createExchangeCashPersonCommand.PersonAccount,  
2089 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2090 - "内部业务错误" + err.Error(),  
2091 - }  
2092 - failureDataList = append(failureDataList, row)  
2093 - continue  
2094 - }  
2095 -  
2096 - // 保存兑换现金活动更新  
2097 - activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)  
2098 - if err != nil {  
2099 - row := []interface{}{  
2100 - createExchangeCashPersonCommand.PersonName,  
2101 - createExchangeCashPersonCommand.PersonAccount,  
2102 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2103 - "内部业务错误" + err.Error(),  
2104 - }  
2105 - failureDataList = append(failureDataList, row)  
2106 - continue  
2107 - }  
2108 - if activityUpdated == nil {  
2109 - row := []interface{}{  
2110 - createExchangeCashPersonCommand.PersonName,  
2111 - createExchangeCashPersonCommand.PersonAccount,  
2112 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2113 - "内部业务错误",  
2114 - }  
2115 - failureDataList = append(failureDataList, row)  
2116 - continue  
2117 - }  
2118 -  
2119 - //// 判断是否超过平台未兑换现金  
2120 - //if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {  
2121 - // if (activityUpdated.ExchangedSuMoney - activityFoundExchangedSuMoney) * activityUpdated.Rate > cashPoolFoundUnExchangeCash {  
2122 - // row := []interface{}{  
2123 - // createExchangeCashPersonCommand.PersonName,  
2124 - // createExchangeCashPersonCommand.PersonAccount,  
2125 - // createExchangeCashPersonCommand.ExchangedSuMoney,  
2126 - // "已超过现金池未兑换现金",  
2127 - // }  
2128 - // failureDataList = append(failureDataList, row)  
2129 - // continue  
2130 - // }  
2131 - //}  
2132 -  
2133 - // 判断是否超过平台未兑换现金  
2134 - if createExchangeCashPersonCommand.ExchangedSuMoney * activityUpdated.Rate > cashPoolFoundUnExchangeCash {  
2135 - row := []interface{}{  
2136 - createExchangeCashPersonCommand.PersonName,  
2137 - createExchangeCashPersonCommand.PersonAccount,  
2138 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2139 - "已超过现金池未兑换现金",  
2140 - }  
2141 - failureDataList = append(failureDataList, row)  
2142 - continue  
2143 - //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")  
2144 - }  
2145 -  
2146 - // 获取平台素币兑换情况  
2147 - systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)  
2148 - if err != nil {  
2149 - row := []interface{}{  
2150 - createExchangeCashPersonCommand.PersonName,  
2151 - createExchangeCashPersonCommand.PersonAccount,  
2152 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2153 - "内部业务错误" + err.Error(),  
2154 - }  
2155 - failureDataList = append(failureDataList, row)  
2156 - continue  
2157 - }  
2158 - if systemSuMoneyStatistics == nil {  
2159 - row := []interface{}{  
2160 - createExchangeCashPersonCommand.PersonName,  
2161 - createExchangeCashPersonCommand.PersonAccount,  
2162 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2163 - "无效的公司员工",  
2164 - }  
2165 - failureDataList = append(failureDataList, row)  
2166 - continue  
2167 - }  
2168 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)  
2169 - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)  
2170 -  
2171 - // 重新计算现金池平均兑换汇率  
2172 - var newRate float64  
2173 - if systemExchangedSuMoney == 0 {  
2174 - newRate = 0  
2175 - } else {  
2176 - newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney  
2177 - }  
2178 -  
2179 - // 更新现金池命令  
2180 - updateCashPoolCommand := &command.UpdateCashPoolCommand{  
2181 - CashPoolId: cashPoolsFound[0].CashPoolId,  
2182 - Cash: cashPoolsFound[0].Cash,  
2183 - ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,  
2184 - UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,  
2185 - ExchangedSuMoney: systemExchangedSuMoney,  
2186 - UnExchangeSuMoney: systemUnExchangeSuMoney,  
2187 - Rate: newRate,  
2188 - LastRate: cashPoolsFound[0].LastRate,  
2189 - }  
2190 -  
2191 - // 更新现金池  
2192 - if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {  
2193 - row := []interface{}{  
2194 - createExchangeCashPersonCommand.PersonName,  
2195 - createExchangeCashPersonCommand.PersonAccount,  
2196 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2197 - "内部业务错误" + err.Error(),  
2198 - }  
2199 - failureDataList = append(failureDataList, row)  
2200 - continue  
2201 - }  
2202 -  
2203 - // 保存现金池更新  
2204 - cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])  
2205 - if err != nil {  
2206 - row := []interface{}{  
2207 - createExchangeCashPersonCommand.PersonName,  
2208 - createExchangeCashPersonCommand.PersonAccount,  
2209 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2210 - "内部业务错误" + err.Error(),  
2211 - }  
2212 - failureDataList = append(failureDataList, row)  
2213 - continue  
2214 - }  
2215 - if cashPoolUpdated == nil {  
2216 - row := []interface{}{  
2217 - createExchangeCashPersonCommand.PersonName,  
2218 - createExchangeCashPersonCommand.PersonAccount,  
2219 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2220 - "内部业务错误" + err.Error(),  
2221 - }  
2222 - failureDataList = append(failureDataList, row)  
2223 - continue  
2224 - }  
2225 - } else { // 未知情况  
2226 - row := []interface{}{  
2227 - createExchangeCashPersonCommand.PersonName,  
2228 - createExchangeCashPersonCommand.PersonAccount,  
2229 - createExchangeCashPersonCommand.ExchangedSuMoney,  
2230 - "未知错误",  
2231 - }  
2232 - failureDataList = append(failureDataList, row)  
2233 - continue  
2234 } 2152 }
  2153 + //if len(peopleFound) != 0 {
  2154 + // peopleFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
  2155 + // // 判断该员工兑换的素币是否超过本人持有的素币
  2156 + // if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFoundExchangedSuMoney {
  2157 + // if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - peopleFoundExchangedSuMoney) {
  2158 + // row := []interface{}{
  2159 + // createExchangeCashPersonCommand.PersonName,
  2160 + // createExchangeCashPersonCommand.PersonAccount,
  2161 + // createExchangeCashPersonCommand.ExchangedSuMoney,
  2162 + // "当前兑换素币超过本人持有的素币值",
  2163 + // }
  2164 + // failureDataList = append(failureDataList, row)
  2165 + // continue
  2166 + // }
  2167 + // }
  2168 + //}
  2169 + //if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换
  2170 + // // 获取当前员工已兑换素币
  2171 + // //personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
  2172 + //
  2173 + // // 获取当前兑换员工已兑换现金
  2174 + // //personFoundExchangedCash := peopleFound[0].ExchangedCash
  2175 + //
  2176 + //
  2177 + //} else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单
  2178 + //
  2179 + //} else { // 未知情况
  2180 + // row := []interface{}{
  2181 + // createExchangeCashPersonCommand.PersonName,
  2182 + // createExchangeCashPersonCommand.PersonAccount,
  2183 + // createExchangeCashPersonCommand.ExchangedSuMoney,
  2184 + // "未知错误",
  2185 + // }
  2186 + // failureDataList = append(failureDataList, row)
  2187 + // continue
  2188 + //}
2235 } 2189 }
2236 2190
2237 if len(failureDataList) == 0 { 2191 if len(failureDataList) == 0 {
@@ -47,6 +47,9 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str @@ -47,6 +47,9 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str
47 if activityId, ok := queryOptions["activityId"]; ok { 47 if activityId, ok := queryOptions["activityId"]; ok {
48 query = query.Where("exchange_cash_person_list.activity_id = ?", activityId) 48 query = query.Where("exchange_cash_person_list.activity_id = ?", activityId)
49 } 49 }
  50 + if employeeAccount, ok := queryOptions["employeeAccount"]; ok {
  51 + query = query.Where("exchange_cash_person_list.employee_account = ?", employeeAccount)
  52 + }
50 if err := query.First(); err != nil { 53 if err := query.First(); err != nil {
51 if err.Error() == "pg: no rows in result set" { 54 if err.Error() == "pg: no rows in result set" {
52 return nil, fmt.Errorf("没有此资源") 55 return nil, fmt.Errorf("没有此资源")