作者 陈志颖

feat:新增返回兑换活动截止时间列表

package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListExchangeCashActivityDeadlineQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
}
func (listExchangeCashActivityDeadlineQuery *ListExchangeCashActivityDeadlineQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listExchangeCashActivityDeadlineQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
\ No newline at end of file
... ...
... ... @@ -243,6 +243,45 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
}
}
// 返回兑换现金活动截止时间列表
func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery *query.ListExchangeCashActivityDeadlineQuery) (interface{}, error) {
if err := listExchangeCashActivityDeadlineQuery.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 exchangeActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeActivityRepository = value
}
if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); 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())
}
var deadlines []interface{}
for _, activity := range activities {
deadlines = append(deadlines, activity.Deadline)
}
return map[string]interface{}{
"deadlines": deadlines,
}, nil
}
}
// 返回兑换现金活动列表
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
... ... @@ -470,7 +509,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
} else {
cashPoolDao = value
}
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.CompanyId)
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -999,6 +999,8 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 返回任务素币奖励范围
return taskDto, nil
}
}
... ...
... ... @@ -20,6 +20,7 @@ type ExchangeActivityRepository interface {
Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error)
Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
}
func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
... ...
... ... @@ -60,14 +60,14 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
tx := dao.transactionContext.PgTx
exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_lists.exchanged_su_money) AS activity_exchanged_su_money").
Where("exchange_cash_person_lists.activity_id = ?", activityId).
ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money").
Where("exchange_cash_person_list.activity_id = ?", activityId).
Select(&activityExchangedSuMoney); err !=nil {
return nil, err
}
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_lists.exchanged_cash) AS activity_exchanged_cash").
Where("exchange_cash_person_lists.activity_id = ?", activityId).
ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash").
Where("exchange_cash_person_list.activity_id = ?", activityId).
Select(&activityExchangedCash); err !=nil {
return nil, err
}
... ...
... ... @@ -227,14 +227,15 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_records.employee, (su_money_transaction_records.employee->>'employeeName')::text,").
ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.su_money) AS employee_su_money").
Column("su_money_transaction_record.employee").
Column("(su_money_transaction_record.employee->>'employeeName')::text").
ColumnExpr("(su_money_transaction_record.employee->>'uid') AS uid, (su_money_transaction_record.employee->>'employeeName') AS employeeName, sum(su_money_transaction_record.su_money) AS employee_su_money").
Where(`e.company_id = ?`, companyId).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employee_su_money DESC").
Select(&ret); err != nil {
return nil, err
... ... @@ -264,30 +265,30 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime
//var employeesContributions []struct{}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
Column("su_money_transaction_records.employee").
ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.su_money) AS employees_contributions_increase").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employees_contributions_increase").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Order("employees_contributions DESC").
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions_increase DESC").
Select(&ret); err != nil {
return nil, err
}
// 减少的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
Column("su_money_transaction_records.employee").
ColumnExpr("sum(su_money_transaction_records.su_money) AS employees_contributions_decrease").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions_decrease").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_records.record_type = ?`, 4).
Where(`su_money_transaction_record.record_type = ?`, 4).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_records.create_time > ?`, startTime).
Where(`su_money_transaction_records.create_time < ?`, endTime).
Group("su_money_transaction_records.employee").
Order("employees_contributions DESC").
Where(`su_money_transaction_record.create_time > ?`, startTime).
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions_decrease DESC").
Select(&retDecrease); err != nil {
return nil, err
}
... ...
... ... @@ -55,6 +55,28 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin
}
}
func (repository *ExchangeCashActivityRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
var exchangeCashActivityModels []*models.ExchangeCashActivity
exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
query := tx.Model(&exchangeCashActivityModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashActivities, err
} else {
for _, exchangeCashActivityModel := range exchangeCashActivityModels {
if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
return 0, exchangeCashActivities, err
} else {
exchangeCashActivities = append(exchangeCashActivities, taskNature)
}
}
return int64(count), exchangeCashActivities, nil
}
}
func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
tx := repository.transactionContext.PgTx
var exchangeCashActivityModels []*models.ExchangeCashActivity
... ...
... ... @@ -248,7 +248,7 @@ func (controller *SuMoneyController) ListExchangeList () {
controller.ServeJSON()
}
// 返回兑换素币清单
// 新增兑换素币清单
func (controller *SuMoneyController) CreateExchangeList () {
cashPoolService := service.NewCashPoolService(nil)
createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
... ... @@ -364,6 +364,23 @@ func (controller *SuMoneyController) ImportExchangeList () {
controller.ServeJSON()
}
// 返回兑换活动截止时间列表
func (controller *SuMoneyController) ListDeadline() {
cashPoolService := service.NewCashPoolService(nil)
listExchangeCashActivityDeadlineQuery := &query.ListExchangeCashActivityDeadlineQuery{}
companyId, _ := controller.GetInt64("companyId")
listExchangeCashActivityDeadlineQuery.CompanyId = companyId
data, err := cashPoolService.ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
// TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息
func (controller *SuMoneyController) ExportExchangeList() {
... ...
... ... @@ -24,6 +24,7 @@ func init() {
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Put:UpdateExchangeActivities") // 编辑兑换活动
beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "Post:CreateExchangeActivities") // 新增兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeActivities") // 删除兑换活动
beego.Router("/cash-pool/activity/deadline-list", &controllers.SuMoneyController{}, "Get:ListDeadline") // 返回兑换活动截止时间列表
/********************************************素币兑换清单*************************************/
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Get:ListExchangeList") // 返回素币兑换清单
... ...