作者 陈志颖

feat:完成排行榜管理增删改查

... ... @@ -109,3 +109,11 @@ func CreateExchangeCashPersonListRepository(options map[string]interface{}) (dom
}
return repository.NewExchangeCashPersonListRepository(transactionContext)
}
func CreateListIntervalRepository(options map[string]interface{}) (domain.ListIntervalRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewListIntervalRepository(transactionContext)
}
... ...
... ... @@ -9,7 +9,7 @@ type GetListIntervalQuery struct {
ListIntervalId int `json:"listIntervalId"` // 排行榜id
}
func (getListIntervalQuery *GetListIntervalQuery) ValidateCommand() error {
func (getListIntervalQuery *GetListIntervalQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getListIntervalQuery)
if err != nil {
... ...
... ... @@ -6,7 +6,9 @@ import (
)
type ListListIntervalQuery struct {
CompanyId int `json:"companyId"` // 公司id
CompanyId int64 `json:"companyId"` // 公司id
Offset int `json:"offset,omitempty"` // 查询偏离量
Limit int `json:"limit,omitempty"` // 查询限制
}
func (listListIntervalQuery *ListListIntervalQuery) ValidateQuery() error {
... ...
package service
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
)
type ListIntervalService struct {
}
// TODO 创建排行榜时间
func (listIntervalService *ListIntervalService) CreateListInterval(createListIntervalComand *command.CreateListIntervalCommand) (interface{}, error) {
return nil, nil
}
// TODO 返回排行榜时间列表
func (listIntervalService *ListIntervalService) ListListInterval(listListIntervalQuery *query.ListListIntervalQuery) (interface{}, error) {
return nil, nil
}
// TODO 返回排行榜时间
func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQuery *query.GetListIntervalQuery) (interface{}, error) {
return nil, nil
}
// TODO 更新排行榜时间
func (listIntervalService *ListIntervalService) UpdateListInterval(updateListIntervalCommand *command.UpdateListIntervalCommand) (interface{}, error) {
return nil, nil
}
// TODO 移除排行榜时间
func (listIntervalService *ListIntervalService) RemoveListInterval(removeListIntervalCommand *command.RemoveListIntervalCommand) (interface{}, error) {
return nil, nil
}
func NewListIntervalService(options map[string] interface{}) *ListIntervalService {
newListIntervalService := &ListIntervalService{}
return newListIntervalService
}
\ No newline at end of file
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type ListIntervalService struct {
}
// 创建排行榜时间
func (listIntervalService *ListIntervalService) CreateListInterval(createListIntervalCommand *command.CreateListIntervalCommand) (interface{}, error) {
if err := createListIntervalCommand.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()
}()
newListInterval := &domain.ListInterval {
CompanyId: createListIntervalCommand.CompanyId,
IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
}
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
if listInterval, err := listIntervalRepository.Save(newListInterval); 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 listInterval, nil
}
}
// 返回排行榜时间列表
func (listIntervalService *ListIntervalService) ListListInterval(listListIntervalQuery *query.ListListIntervalQuery) (interface{}, error) {
if err := listListIntervalQuery.ValidateQuery(); 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()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); 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 map[string]interface{}{
"count": count,
"taskNatures": listIntervals,
}, nil
}
}
// 返回排行榜时间
func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQuery *query.GetListIntervalQuery) (interface{}, error) {
if err := getListIntervalQuery.ValidateQuery(); 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()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if listInterval == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getListIntervalQuery.ListIntervalId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return listInterval, nil
}
}
// 更新排行榜时间
func (listIntervalService *ListIntervalService) UpdateListInterval(updateListIntervalCommand *command.UpdateListIntervalCommand) (interface{}, error) {
if err := updateListIntervalCommand.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()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if listInterval == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
}
if err := listInterval.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if listInterval, err := listIntervalRepository.Save(listInterval); 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 listInterval, nil
}
}
// 移除排行榜时间
func (listIntervalService *ListIntervalService) RemoveListInterval(removeListIntervalCommand *command.RemoveListIntervalCommand) (interface{}, error) {
if err := removeListIntervalCommand.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()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if listInterval == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId)))
}
if listInterval, err := listIntervalRepository.Remove(listInterval); 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 listInterval, nil
}
}
func NewListIntervalService(options map[string] interface{}) *ListIntervalService {
newListIntervalService := &ListIntervalService{}
return newListIntervalService
}
\ No newline at end of file
... ...
... ... @@ -8,7 +8,7 @@ import (
type OperationSuMoneyCommand struct {
Uid int64 `json:"uid" valid:"Required"` // 素币拥有者UID
OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除)
OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除, 3兑换物资, 4兑换现金
SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
Operator int64 `json:"operator,omitempty"` // 操作人UID
OperationDescription string `json:"operationDescription" valid:"Required"` // 理由描述
... ...
... ... @@ -8,6 +8,7 @@ import (
// 移除兑换现金人员
type RemoveExchangeCashPersonCommand struct {
ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
Operator int64 `json:"operator,omitempty"` // 操作人
}
func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -8,6 +8,7 @@ import (
type UpdateExchangeCashPersonCommand struct {
ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
Operator int64 `json:"operator,omitempty"` // 操作人
}
func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
... ...
... ... @@ -3,6 +3,9 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -32,29 +35,32 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
transactionContext.RollbackTransaction()
}()
// TODO 判断公司是否存在
//var cashPoolDao *dao.CashPoolDao
//if value, err := factory.CreateCashPoolDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cashPoolDao = value
//}
// TODO 统计系统已兑换现金、未兑换现金、已兑换素币、未兑换素币
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
employeeDao = value
}
var systemUnExchangeCash float64
//systemExchangedCash, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
// 统计系统素币
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
//systemChangedSuMoney, systemUnChangeSuMoney, err := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
// 统计系统现金
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
... ... @@ -65,38 +71,25 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
// TODO 获取系统未兑换现金
//count, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
// "companyId": createCashPoolCommand.CompanyId,
//})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if count == 0 {
// systemUnExchangeCash = 0
//} else {
// systemUnExchangeCash = cashPools[0].UnExchangeCash
//}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// TODO 计算系统平均兑换汇率
//rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
// 新建现金池
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
//ExchangedCash: systemExchangedCash,
ExchangedCash: 0,
ExchangedCash: systemExchangedCash,
UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash,
//ExchangedSuMoney: systemChangedSuMoney,
ExchangedSuMoney: 0,
//UnExchangeSuMoney: systemUnChangeSuMoney,
UnExchangeSuMoney: 0,
//Rate: rate,
Rate: 0,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: rate,
CreateTime: time.Now(),
}
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -104,7 +97,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
} else {
cashPoolRepository = value
}
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -130,6 +122,28 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
defer func() {
transactionContext.RollbackTransaction()
}()
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
employeeDao = value
}
// 统计系统素币
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
... ... @@ -144,7 +158,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 初始状态下,现金池返回默认值
// 初始状态下,现金池返回默认值
if count == 0 {
return map[string] interface{} {
"cashPoolId": 0,
... ... @@ -152,8 +166,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
"companyId": getCashPoolQuery.CompanyId,
"exchangedCash": 0,
"unExchangeCash": 0,
"exchangedSuMoney": 0,
"unExchangeSuMoney": 0,
"exchangedSuMoney": systemExchangedSuMoney,
"unExchangeSuMoney": systemUnExchangeSuMoney,
"rate": 0,
"createTime": time.Now(),
}, nil
... ... @@ -345,6 +359,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
defer func() {
transactionContext.RollbackTransaction()
}()
// TODO 更新汇率处理:
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -440,7 +457,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
// TODO 更新个人素币
// TODO 更新活动数据
// TODO 更新现金池数据
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -537,6 +558,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyService = value
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -555,11 +584,29 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新个人素币,个人素币值需要还原,理由:素币兑换现金调整
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: removeExchangeCashPersonCommand.Operator,
SuMoney: 0,
OperationType: 5,
OperationDescription: "素币兑换现金调整",
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
// TODO 更新兑换活动数据
// TODO 更新现金池数据
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 个人素币值需要还原,理由:素币兑换现金调整
return personDeleted, nil
}
}
... ... @@ -579,6 +626,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
defer func() {
transactionContext.RollbackTransaction()
}()
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyService = value
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -600,9 +656,25 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: updateExchangeCashPersonCommand.Operator,
SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
OperationType: 5,
OperationDescription: "参与兑换素币活动",
}
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
}
// TODO 更新兑换活动数据
// TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率
// TODO 更新现金池
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
package domain
import "time"
// 排行榜时间
type ListInterval struct {
ListIntervalId int `json:"listIntervalId"` // 排行榜时间id
CompanyId int64 `json:"companyId"` // 公司id
IntervalStartTime time.Time `json:"intervalStartTime"` // 排行榜开始时间
IntervalEndTime time.Time `json:"intervalEndTime"` // 排行榜结束时间
}
type ListIntervalRepository interface {
Save(listInterval *ListInterval) (*ListInterval, error)
Remove(listInterval *ListInterval) (*ListInterval, error)
FindOne(queryOptions map[string]interface{}) (*ListInterval, error)
Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
}
func (listInterval *ListInterval) Identify() interface{} {
if listInterval.ListIntervalId == 0 {
return nil
}
return listInterval.ListIntervalId
}
func (listInterval *ListInterval) Update(data map[string]interface{}) error {
if intervalStartTime, ok := data["intervalStartTime"]; ok {
listInterval.IntervalStartTime = intervalStartTime.(time.Time)
}
if intervalEndTime, ok := data["intervalEndTime"]; ok {
listInterval.IntervalStartTime = intervalEndTime.(time.Time)
}
return nil
}
\ No newline at end of file
... ...
... ... @@ -3,10 +3,11 @@ package domain
import "time"
const (
SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换(物资、现金)
SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换物资
SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励
SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加
SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除
SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH //兑换现金
)
// 素币事务记录
... ... @@ -16,10 +17,10 @@ type SuMoneyTransactionRecord struct {
Employee *EmployeeInfo `json:"employee"` // 记录关联员工
SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"` // 事务处理前素币值
CurrentSuMoney float64 `json:"currentSuMoney"` // 当前素币值
//CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池,用于兑换现金操作
//CurrentCashPool *CashPool `json:"currentCashPool"` // 当前现金池,用于兑换现金操作
SuMoney float64 `json:"suMoney"` // 事务素币值
//Cash float64 `json:"cash"` // 事务现金值,用于兑换现金操作
CashBeforeTransaction float64 `json:"cashBeforeTransaction"` // 事务处理前现金值
CurrentCash float64 `json:"currentCash"` // 当前现金值
Cash float64 `json:"cash"` // 事务现金值
Operator *EmployeeInfo `json:"operator"` // 操作人
RecordDescription string `json:"recordDescription"` // 素币事务记录描述
CreateTime time.Time `json:"createTime"` // 创建时间
... ...
package models
import "time"
type ListInterval struct {
TableName string `pg:"list_interval,alias:list_intervals"`
Id int // 排行榜周期id
ListIntervalStartTime time.Time
ListIntervalEndTime time.Time
CompanyId int64
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type ListIntervalRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ListIntervalRepository) Save(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
if listInterval.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
"INSERT INTO list_intervals (list_interval_start_time, list_interval_end_time, company_id) VALUES (?, ?, ?) RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
listInterval.ListIntervalId, listInterval.CompanyId, listInterval.IntervalStartTime, listInterval.IntervalEndTime); err != nil {
return listInterval, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
"UPDATE list_intervals SET list_interval_start_time=?, list_interval_end_time=? WHERE id=? RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
listInterval.IntervalStartTime, listInterval.IntervalEndTime, listInterval.Identify()); err != nil {
return listInterval, err
}
}
return listInterval, nil
}
func (repository *ListIntervalRepository) Remove(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
listIntervalModel := new(models.ListInterval)
listIntervalModel.Id = listInterval.Identify().(int)
if _, err := tx.Model(listIntervalModel).WherePK().Delete(); err != nil {
return listInterval, err
}
return listInterval, nil
}
func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interface{}) (*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
listIntervalModel := new(models.ListInterval)
query := tx.Model(listIntervalModel)
if listIntervalId, ok := queryOptions["listId"]; ok {
query = query.Where("list_interval.id = ?", listIntervalId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if listIntervalModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(listIntervalModel)
}
}
func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
var listIntervalModels []*models.ListInterval
listIntervals := make([]*domain.ListInterval, 0)
query := tx.Model(&listIntervalModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("list_interval.company_id = ?", companyId)
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, listIntervals, err
} else {
for _, listIntervalModel := range listIntervalModels {
if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
return 0, listIntervals, err
} else {
listIntervals = append(listIntervals, listInterval)
}
}
return int64(count), listIntervals, nil
}
}
func (repository *ListIntervalRepository) transformPgModelToDomainModel(listIntervalModel *models.ListInterval) (*domain.ListInterval, error) {
return &domain.ListInterval{
ListIntervalId: listIntervalModel.Id,
CompanyId: listIntervalModel.CompanyId,
IntervalStartTime: listIntervalModel.ListIntervalStartTime,
IntervalEndTime: listIntervalModel.ListIntervalEndTime,
}, nil
}
func NewListIntervalRepository(transactionContext *pgTransaction.TransactionContext) (*ListIntervalRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ListIntervalRepository{
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
... ...
package controllers
import "github.com/astaxie/beego"
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/service"
)
type ListIntervalController struct {
beego.Controller
}
// TODO 新增榜单时间段
// 新增榜单时间段
func (controller *ListIntervalController) CreateListInterval() {
listIntervalService := service.NewListIntervalService(nil)
createListIntervalCommand := &command.CreateListIntervalCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createListIntervalCommand)
data, err := listIntervalService.CreateListInterval(createListIntervalCommand)
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()
}
// TODO 更新榜单时间段
// 更新榜单时间段
func (controller *ListIntervalController) UpdateListInterval() {
listIntervalService := service.NewListIntervalService(nil)
updateListIntervalCommand := &command.UpdateListIntervalCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateListIntervalCommand)
listId, _ := controller.GetInt(":listId")
updateListIntervalCommand.ListIntervalId = listId
data, err := listIntervalService.UpdateListInterval(updateListIntervalCommand)
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()
}
// TODO 获取榜单时间段
// 获取榜单时间段
func (controller *ListIntervalController) GetListInterval() {
listIntervalService := service.NewListIntervalService(nil)
getListIntervalQuery := &query.GetListIntervalQuery{}
listId, _ := controller.GetInt(":listId")
getListIntervalQuery.ListIntervalId = listId
data, err := listIntervalService.GetListInterval(getListIntervalQuery)
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()
}
// TODO 获取榜单时间段列表
// 获取榜单时间段列表
func (controller *ListIntervalController) ListListInterval() {
listIntervalService := service.NewListIntervalService(nil)
listListIntervalQuery := &query.ListListIntervalQuery{}
companyId, _ := controller.GetInt64(":companyID")
listListIntervalQuery.CompanyId = companyId
offset, _ := controller.GetInt("offset")
listListIntervalQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listListIntervalQuery.Limit = limit
data, err := listIntervalService.ListListInterval(listListIntervalQuery)
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()
}
// TODO 移除榜单时间段
// 移除榜单时间段
func (controller *ListIntervalController) RemoveListInterval() {
listIntervalService := service.NewListIntervalService(nil)
removeListIntervalQuery := &command.RemoveListIntervalCommand{}
listId, _ := controller.GetInt(":listId")
removeListIntervalQuery.ListIntervalId = listId
data, err := listIntervalService.RemoveListInterval(removeListIntervalQuery)
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()
}
... ...
... ... @@ -7,8 +7,8 @@ import (
func init() {
beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Post:CreateListInterval")
beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Put:UpdateListInterval")
beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Get:GetListInterval")
beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Delete:RemoveListInterval")
beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Put:UpdateListInterval")
beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Get:GetListInterval")
beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Delete:RemoveListInterval")
beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Get:ListListInterval")
}
\ No newline at end of file
... ...
... ... @@ -11,5 +11,5 @@ func init() {
beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")
beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics")
beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计
beego.Router("/statistics/system-cashPool", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
}
... ...