作者 陈志颖

fix:修复获取现金池时未兑换素币重新计算问题

... ... @@ -190,6 +190,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -198,6 +199,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li
} else {
employeeRepository = value
}
if count, employees, err := employeeRepository.Find(tool_funs.SimpleStructToMap(listEmployeeQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ExportSuMoneyCommand struct {
IDs []int `json:"ids"`
Where map[string]interface{} `json:"where"`
}
func (exportSuMoneyCommand *ExportSuMoneyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(exportSuMoneyCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -259,6 +259,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
cashPools[0].LastRate = lastActivityRate
cashPools[0].ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedCash), 64)
cashPools[0].ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedSuMoney), 64)
cashPools[0].UnExchangeSuMoney, _= strconv.ParseFloat(fmt.Sprintf("%.2f", systemUnExchangeSuMoney), 64)
return cashPools[0], nil
}
}
... ...
... ... @@ -9,7 +9,6 @@ import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/utils"
)
// 素币服务
... ... @@ -31,6 +30,7 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
defer func() {
transactionContext.RollbackTransaction()
}()
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -39,6 +39,7 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
} else {
operationSuMoneyService = value
}
if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -64,6 +65,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran
defer func() {
transactionContext.RollbackTransaction()
}()
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -72,6 +74,7 @@ func (suMoneyService *SuMoneyService) GetSuMoneyTransactionRecord(getSuMoneyTran
} else {
suMoneyTransactionRecordRepository = value
}
if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.FindOne(map[string]interface{}{"suMoneyTransactionRecordId": getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -97,6 +100,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeSuMoneyService service.ExchangeSuMoneyService
if value, err := factory.CreateExchangeSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -105,6 +109,7 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
} else {
exchangeSuMoneyService = value
}
if task, err := exchangeSuMoneyService.Exchange(exchangeSuMoneyCommand.Uid, exchangeSuMoneyCommand.Operator, exchangeSuMoneyCommand.SuMoney, exchangeSuMoneyCommand.ExchangeDescription); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -131,6 +136,7 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
transactionContext.RollbackTransaction()
}()
// 素币事务记录仓储初始化
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
if value, err := factory.CreateSuMoneyTransactionRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -140,43 +146,43 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
suMoneyTransactionRecordRepository = value
}
// 获取素币兑换事务记录
if count, suMoneyTransactionRecords, err := suMoneyTransactionRecordRepository.Find(tool_funs.SimpleStructToMap(searchSuMoneyTransactionRecordCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for _, suMoneyTransactionRecord := range suMoneyTransactionRecords {
contributions := []int{2,3,4}
suMoney := []int{1,2,3,4,5}
// 查询贡献值时规范描述
if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, contributions) {
switch suMoneyTransactionRecord.RecordType {
case 2: // 任务奖励
suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
case 3: // 增加
suMoneyTransactionRecord.RecordDescription = "增加贡献"
case 4: // 扣除
suMoneyTransactionRecord.RecordDescription = "扣除贡献"
}
}
// 查询素币值时规范描述
if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, suMoney) {
switch suMoneyTransactionRecord.RecordType {
case 1: // 兑换物资
suMoneyTransactionRecord.RecordDescription = "兑换物资"
case 2: // 任务奖励
suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
case 3: // 增加
suMoneyTransactionRecord.RecordDescription = "增加素币"
case 4: // 扣除
suMoneyTransactionRecord.RecordDescription = "扣除素币"
case 5: // 兑换现金
suMoneyTransactionRecord.RecordDescription = "素币兑换现金"
}
}
}
//for _, suMoneyTransactionRecord := range suMoneyTransactionRecords {
// contributions := []int{2,3,4}
// suMoney := []int{1,2,3,4,5}
// // 查询贡献值时规范描述
// if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, contributions) {
// switch suMoneyTransactionRecord.RecordType {
// case 2: // 任务奖励
// suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
// case 3: // 增加
// suMoneyTransactionRecord.RecordDescription = "增加贡献"
// case 4: // 扣除
// suMoneyTransactionRecord.RecordDescription = "扣除贡献"
// }
// }
// // 查询素币值时规范描述
// if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, suMoney) {
// switch suMoneyTransactionRecord.RecordType {
// case 1: // 兑换物资
// suMoneyTransactionRecord.RecordDescription = "兑换物资"
// case 2: // 任务奖励
// suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
// case 3: // 增加
// suMoneyTransactionRecord.RecordDescription = "增加素币"
// case 4: // 扣除
// suMoneyTransactionRecord.RecordDescription = "扣除素币"
// case 5: // 兑换现金
// suMoneyTransactionRecord.RecordDescription = "素币兑换现金"
// }
// }
//}
return map[string]interface{}{
"count": count,
"suMoneyTransactionRecords": suMoneyTransactionRecords,
... ... @@ -200,6 +206,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
transactionContext.RollbackTransaction()
}()
// 员工DAO初始化
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -254,7 +261,47 @@ func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(c
}
}
// 根据id获取事务记录
// 根据uid获取员工素币(导出素币流水)
func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]*domain.Employee, error) {
if err := exportSuMoneyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if len(exportSuMoneyCommand.IDs) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
}
// 员工仓储初始化
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeRepository = value
}
if _, employees, err := employeeRepository.Find(tool_funs.SimpleStructToMap(exportSuMoneyCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return employees, nil
}
}
// 根据id获取事务记录(导出素币流水记录)
func (suMoneyService *SuMoneyService) ListSuMoneyTransactionRecordById(exportSuMoneyTransactionRecordCommand *command.ExportTransactionRecordCommand) ([]*domain.SuMoneyTransactionRecord, error) {
if err := exportSuMoneyTransactionRecordCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ...
... ... @@ -537,8 +537,8 @@ func (controller *SuMoneyController) ExportExchangeList() {
// 导出素币流水
func (controller *SuMoneyController) ExportSuMoney() {
suMoneyService := service.NewSuMoneyService(nil)
exportTransactionRecordCommand := &command.ExportTransactionRecordCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportTransactionRecordCommand)
exportSuMoneyCommand := &command.ExportSuMoneyCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand)
// 列标题
titles := []string{
"员工姓名","手机账号","当前素币",
... ... @@ -549,12 +549,12 @@ func (controller *SuMoneyController) ExportSuMoney() {
}
var response utils.JsonResponse
var data []map[string]interface{}
records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand)
for _, record := range records {
p := map[string]interface{} {
"name": record.Employee.EmployeeName,
"account": record.Employee.EmployeeAccount,
"current_su_money": record.CurrentSuMoney,
"name": record.EmployeeInfo.EmployeeName,
"account": record.EmployeeInfo.EmployeeAccount,
"current_su_money": record.SuMoney,
}
data = append(data, p)
}
... ...
... ... @@ -13,8 +13,8 @@ func init() {
beego.Router("/su-money/search-su-money-transaction-record", &controllers.SuMoneyController{}, "Post:SearchSuMoneyTransactionRecord") // 搜索素币事务记录
beego.Router("/su-money/su-money-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:SuMoneyTransactionRecordStatistics") // 返回素币事务记录统计(个人素币收支)
beego.Router("/su-money/contributions-transaction-record-statistics", &controllers.SuMoneyController{}, "Post:ContributionsTransactionRecordStatistics") // 返回贡献值事务记录统计(个人贡献值收支)
beego.Router("/su-money/su-money-transaction-records/export-records", &controllers.SuMoneyController{}, "Post:ExportSuMoneyTransactionRecord") // 导出素币事务记录(流水)
beego.Router("/su-money/su-money-transaction-records/export-su-money", &controllers.SuMoneyController{}, "Post:ExportSuMoney") // 导出员工素币
beego.Router("/su-money/su-money-transaction-records/export-records", &controllers.SuMoneyController{}, "Post:ExportSuMoneyTransactionRecord") // 导出素币事务记录(素币流水记录)
beego.Router("/su-money/su-money-transaction-records/export-su-money", &controllers.SuMoneyController{}, "Post:ExportSuMoney") // 导出员工素币流水
/**********************************************现金池*******************************************/
beego.Router("/cash-pool/input", &controllers.SuMoneyController{}, "Post:CashInput") // 现金池投入
... ...