作者 陈志颖

feat:新增榜单时间段管理

... ... @@ -199,12 +199,11 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
}
}
// TODO 获取系统素币统计
// 系统素币统计
func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
if err := systemSuMoneyStatisticsCommand.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())
... ... @@ -215,7 +214,6 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
defer func() {
transactionContext.RollbackTransaction()
}()
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -224,23 +222,47 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
} else {
cashPoolDao = value
}
if systemSuMoneyStatistics, err := cashPoolDao.CalculateSystemCash(systemSuMoneyStatisticsCommand.CompanyId); 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())
}
//systemSuMoneyStatistics["currentSuMoney"] = employee.SuMoney
return systemSuMoneyStatistics, nil
}
}
// TODO 获取系统现金统计
// 系统现金统计
func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
return nil, nil
if err := systemCashStatisticsCommand.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 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
}
if systemCashStatistics, err := cashPoolDao.CalculateSystemCash(systemCashStatisticsCommand.CompanyId); 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 systemCashStatistics, nil
}
}
func NewStatisticsService(options map[string]interface{}) *StatisticsService {
... ...
... ... @@ -156,15 +156,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
transactionContext.RollbackTransaction()
}()
var timeNow = time.Now()
var deadline = createExchangeCashActivityCommand.Deadline
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
CompanyId: createExchangeCashActivityCommand.CompanyId,
ExchangedCash: 0,
ExchangedSuMoney: 0,
Deadline: createExchangeCashActivityCommand.Deadline,
CountDown: 0,
Deadline: createExchangeCashActivityCommand.Deadline,
CountDown: int64(t2.Sub(t1).Hours() / 24),
Rate: createExchangeCashActivityCommand.ExchangeRate,
CreateTime: time.Now(),
CreateTime: timeNow,
}
var exchangeCashActivityRepository domain.ExchangeActivityRepository
... ... @@ -273,7 +278,6 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
if err := getExchangeCashActivityQuery.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())
... ... @@ -284,7 +288,6 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -340,25 +343,32 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if activity == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
//var cashPoolRepository domain.CashPoolRepository
//if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cashPoolRepository = value
//}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
return activityUpdated, nil
}
}
// 新兑换现金人员
// 新兑换现金人员
func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -375,15 +385,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
transactionContext.RollbackTransaction()
}()
// TODO 需要判断新增兑换现金人员的素币值是否合理(人员参与兑换的素币不得超过该人员还未兑换的素币总值)
var exchangeCashActivityRepository domain.ExchangeActivityRepository
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity.Rate == 0 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))
}
// TODO 判断活动的汇率是否为空,为空则不允许新建,提示:请设置汇率
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 获取参与的兑换活动的汇率,计算已兑换的现金值
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 新增兑换人员时,判断成员是否存在,判断素币值是否超过本人持有的素币,以手机账号为判断依据
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
newPerson := &domain.ExchangeCashPersonList{
EmployeeInfo: &domain.EmployeeInfo{
... ... @@ -392,7 +407,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
},
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activity.Rate,
}
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
... ... @@ -406,11 +421,12 @@ 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 更新活动已兑换素币值、已兑换现金值、兑换汇率
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
return person, nil
}
}
... ... @@ -572,13 +588,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if personUpdated, err := exchangeCashPersonListRepository.Save(person); 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())
}
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
// TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personUpdated, nil
}
}
... ...
... ... @@ -41,6 +41,8 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
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 {
// TODO 增加、扣除素币和个人贡献值关联,兑换物资不与贡献值关联
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -11,7 +11,6 @@ type CashPool struct {
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
//Operator *EmployeeInfo `json:"operator"` // 操作人
Rate float64 `json:"rate"` // 平均兑换汇率
CreateTime time.Time `json:"createTime"` // 现金投入现金池时间
}
... ... @@ -21,6 +20,25 @@ type CashPoolRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
}
func (cashPool *CashPool) Update(data map[string]interface{}) error {
if exchangedCash, ok := data["exchangedCash"]; ok {
cashPool.ExchangedCash = exchangedCash.(float64)
}
if unExchangeCash, ok := data["unExchangeCash"]; ok {
cashPool.UnExchangeCash = unExchangeCash.(float64)
}
if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
cashPool.ExchangedSuMoney = exchangedSuMoney.(float64)
}
if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64)
}
if rate, ok := data["rate"]; ok {
cashPool.Rate = rate.(float64)
}
return nil
}
func (cashPool *CashPool) Identity() interface{} {
if cashPool.CashPoolId == 0 {
return nil
... ...
package domain
... ...
package controllers
import "github.com/astaxie/beego"
type ListIntervalController struct {
beego.Controller
}
// TODO 新增榜单时间段
func (controller *ListIntervalController) CreateListInterval() {
}
// TODO 更新榜单时间段
func (controller *ListIntervalController) UpdateListInterval() {
}
// TODO 获取榜单时间段
func (controller *ListIntervalController) GetListInterval() {
}
// TODO 获取榜单时间段列表
func (controller *ListIntervalController) ListListInterval() {
}
// TODO 移除榜单时间段
func (controller *ListIntervalController) RemoveListInterval() {
}
... ...
... ... @@ -73,12 +73,32 @@ func (controller *StatisticsController) PersonNotificationStatistics() {
controller.ServeJSON()
}
// TODO 系统素币统计
func (controller *StatisticsController) SystemSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
systemSuMoneyStatisticsCommand := &command.SystemSuMoneyStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemSuMoneyStatisticsCommand)
data, err := statisticsService.SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand)
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 *StatisticsController) SystemCashStatistics() {
statisticsService := service.NewStatisticsService(nil)
systemCashStatisticsCommand := &command.SystemCashStatisticsCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemCashStatisticsCommand)
data, err := statisticsService.SystemCashStatistics(systemCashStatisticsCommand)
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()
}
\ No newline at end of file
... ...
... ... @@ -359,7 +359,6 @@ func (controller *SuMoneyController) ImportExchangeList () {
fmt.Println(err)
return
}
// TODO 判断活动汇率是否为空
var response utils.JsonResponse
dataList := make([]interface{}, 0)
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
)
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/", &controllers.ListIntervalController{}, "Get:ListListInterval")
}
\ No newline at end of file
... ...
... ... @@ -23,10 +23,10 @@ func init() {
beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "POST:CreateExchangeActivities") // 新增兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeActivities") // 删除兑换活动
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeCashPerson") // 删除素币兑换清单
beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单
beego.Router("/cash-pool/activity/exchange-listInterval", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单
beego.Router("/cash-pool/activity/exchange-listInterval/:listId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员
beego.Router("/cash-pool/activity/exchange-listInterval", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单
beego.Router("/cash-pool/activity/exchange-listInterval/:listId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
beego.Router("/cash-pool/activity/exchange-listInterval/:listId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeCashPerson") // 删除素币兑换清单
beego.Router("/cash-pool/activity/exchange-listInterval/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单
}
... ...