作者 陈志颖

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

  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ListExchangeCashActivityDeadlineQuery struct {
  9 + CompanyId int64 `json:"companyId"` // 公司id
  10 +}
  11 +
  12 +func (listExchangeCashActivityDeadlineQuery *ListExchangeCashActivityDeadlineQuery) ValidateQuery() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(listExchangeCashActivityDeadlineQuery)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
@@ -243,6 +243,45 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -243,6 +243,45 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
243 } 243 }
244 } 244 }
245 245
  246 +// 返回兑换现金活动截止时间列表
  247 +func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery *query.ListExchangeCashActivityDeadlineQuery) (interface{}, error) {
  248 + if err := listExchangeCashActivityDeadlineQuery.ValidateQuery(); err != nil {
  249 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  250 + }
  251 + transactionContext, err := factory.CreateTransactionContext(nil)
  252 + if err != nil {
  253 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  254 + }
  255 + if err := transactionContext.StartTransaction(); err != nil {
  256 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  257 + }
  258 + defer func() {
  259 + transactionContext.RollbackTransaction()
  260 + }()
  261 + var exchangeActivityRepository domain.ExchangeActivityRepository
  262 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  263 + "transactionContext": transactionContext,
  264 + }); err != nil {
  265 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  266 + } else {
  267 + exchangeActivityRepository = value
  268 + }
  269 + if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil {
  270 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  271 + } else {
  272 + if err := transactionContext.CommitTransaction(); err != nil {
  273 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  274 + }
  275 + var deadlines []interface{}
  276 + for _, activity := range activities {
  277 + deadlines = append(deadlines, activity.Deadline)
  278 + }
  279 + return map[string]interface{}{
  280 + "deadlines": deadlines,
  281 + }, nil
  282 + }
  283 +}
  284 +
246 // 返回兑换现金活动列表 285 // 返回兑换现金活动列表
247 func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) { 286 func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
248 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil { 287 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
@@ -470,7 +509,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -470,7 +509,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
470 } else { 509 } else {
471 cashPoolDao = value 510 cashPoolDao = value
472 } 511 }
473 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.CompanyId) 512 + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId)
474 if err != nil { 513 if err != nil {
475 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 514 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
476 } 515 }
@@ -999,6 +999,8 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -999,6 +999,8 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
999 if err := transactionContext.CommitTransaction(); err != nil { 999 if err := transactionContext.CommitTransaction(); err != nil {
1000 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1000 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1001 } 1001 }
  1002 + // TODO 返回任务素币奖励范围
  1003 +
1002 return taskDto, nil 1004 return taskDto, nil
1003 } 1005 }
1004 } 1006 }
@@ -20,6 +20,7 @@ type ExchangeActivityRepository interface { @@ -20,6 +20,7 @@ type ExchangeActivityRepository interface {
20 Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error) 20 Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
21 FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error) 21 FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error)
22 Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error) 22 Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
  23 + FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
23 } 24 }
24 25
25 func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} { 26 func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
@@ -60,14 +60,14 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map @@ -60,14 +60,14 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
60 tx := dao.transactionContext.PgTx 60 tx := dao.transactionContext.PgTx
61 exchangeCashPersonListModels := new(models.ExchangeCashPersonList) 61 exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
62 if err := tx.Model(exchangeCashPersonListModels). 62 if err := tx.Model(exchangeCashPersonListModels).
63 - ColumnExpr("sum(exchange_cash_person_lists.exchanged_su_money) AS activity_exchanged_su_money").  
64 - Where("exchange_cash_person_lists.activity_id = ?", activityId). 63 + ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money").
  64 + Where("exchange_cash_person_list.activity_id = ?", activityId).
65 Select(&activityExchangedSuMoney); err !=nil { 65 Select(&activityExchangedSuMoney); err !=nil {
66 return nil, err 66 return nil, err
67 } 67 }
68 if err := tx.Model(exchangeCashPersonListModels). 68 if err := tx.Model(exchangeCashPersonListModels).
69 - ColumnExpr("sum(exchange_cash_person_lists.exchanged_cash) AS activity_exchanged_cash").  
70 - Where("exchange_cash_person_lists.activity_id = ?", activityId). 69 + ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash").
  70 + Where("exchange_cash_person_list.activity_id = ?", activityId).
71 Select(&activityExchangedCash); err !=nil { 71 Select(&activityExchangedCash); err !=nil {
72 return nil, err 72 return nil, err
73 } 73 }
@@ -227,14 +227,15 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. @@ -227,14 +227,15 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
227 } 227 }
228 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 228 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
229 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). 229 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
230 - Column("su_money_transaction_records.employee, (su_money_transaction_records.employee->>'employeeName')::text,").  
231 - 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"). 230 + Column("su_money_transaction_record.employee").
  231 + Column("(su_money_transaction_record.employee->>'employeeName')::text").
  232 + 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").
232 Where(`e.company_id = ?`, companyId). 233 Where(`e.company_id = ?`, companyId).
233 Where(`e.status = ?`, 1). 234 Where(`e.status = ?`, 1).
234 - Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的  
235 - Where(`su_money_transaction_records.create_time > ?`, startTime).  
236 - Where(`su_money_transaction_records.create_time < ?`, endTime).  
237 - Group("su_money_transaction_records.employee"). 235 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
  236 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  237 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  238 + Group("su_money_transaction_record.employee").
238 Order("employee_su_money DESC"). 239 Order("employee_su_money DESC").
239 Select(&ret); err != nil { 240 Select(&ret); err != nil {
240 return nil, err 241 return nil, err
@@ -264,30 +265,30 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime @@ -264,30 +265,30 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime
264 //var employeesContributions []struct{} 265 //var employeesContributions []struct{}
265 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 266 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
266 // 增加的贡献值 267 // 增加的贡献值
267 - if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").  
268 - Column("su_money_transaction_records.employee").  
269 - 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"). 268 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  269 + Column("su_money_transaction_record.employee").
  270 + 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").
270 Where(`e.company_id = ?`, companyId). 271 Where(`e.company_id = ?`, companyId).
271 - Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})). 272 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
272 Where(`e.status = ?`, 1). 273 Where(`e.status = ?`, 1).
273 - Where(`su_money_transaction_records.create_time > ?`, startTime).  
274 - Where(`su_money_transaction_records.create_time < ?`, endTime).  
275 - Group("su_money_transaction_records.employee").  
276 - Order("employees_contributions DESC"). 274 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  275 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  276 + Group("su_money_transaction_record.employee").
  277 + Order("employees_contributions_increase DESC").
277 Select(&ret); err != nil { 278 Select(&ret); err != nil {
278 return nil, err 279 return nil, err
279 } 280 }
280 // 减少的贡献值 281 // 减少的贡献值
281 - if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").  
282 - Column("su_money_transaction_records.employee").  
283 - ColumnExpr("sum(su_money_transaction_records.su_money) AS employees_contributions_decrease"). 282 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  283 + Column("su_money_transaction_record.employee").
  284 + ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions_decrease").
284 Where(`e.company_id = ?`, companyId). 285 Where(`e.company_id = ?`, companyId).
285 - Where(`su_money_transaction_records.record_type = ?`, 4). 286 + Where(`su_money_transaction_record.record_type = ?`, 4).
286 Where(`e.status = ?`, 1). 287 Where(`e.status = ?`, 1).
287 - Where(`su_money_transaction_records.create_time > ?`, startTime).  
288 - Where(`su_money_transaction_records.create_time < ?`, endTime).  
289 - Group("su_money_transaction_records.employee").  
290 - Order("employees_contributions DESC"). 288 + Where(`su_money_transaction_record.create_time > ?`, startTime).
  289 + Where(`su_money_transaction_record.create_time < ?`, endTime).
  290 + Group("su_money_transaction_record.employee").
  291 + Order("employees_contributions_decrease DESC").
291 Select(&retDecrease); err != nil { 292 Select(&retDecrease); err != nil {
292 return nil, err 293 return nil, err
293 } 294 }
@@ -55,6 +55,28 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin @@ -55,6 +55,28 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin
55 } 55 }
56 } 56 }
57 57
  58 +func (repository *ExchangeCashActivityRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
  59 + tx := repository.transactionContext.PgTx
  60 + var exchangeCashActivityModels []*models.ExchangeCashActivity
  61 + exchangeCashActivities := make([]*domain.ExchangeCashActivity, 0)
  62 + query := tx.Model(&exchangeCashActivityModels)
  63 + if companyId, ok := queryOptions["companyId"]; ok {
  64 + query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
  65 + }
  66 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  67 + return 0, exchangeCashActivities, err
  68 + } else {
  69 + for _, exchangeCashActivityModel := range exchangeCashActivityModels {
  70 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
  71 + return 0, exchangeCashActivities, err
  72 + } else {
  73 + exchangeCashActivities = append(exchangeCashActivities, taskNature)
  74 + }
  75 + }
  76 + return int64(count), exchangeCashActivities, nil
  77 + }
  78 +}
  79 +
58 func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) { 80 func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashActivity, error) {
59 tx := repository.transactionContext.PgTx 81 tx := repository.transactionContext.PgTx
60 var exchangeCashActivityModels []*models.ExchangeCashActivity 82 var exchangeCashActivityModels []*models.ExchangeCashActivity
@@ -248,7 +248,7 @@ func (controller *SuMoneyController) ListExchangeList () { @@ -248,7 +248,7 @@ func (controller *SuMoneyController) ListExchangeList () {
248 controller.ServeJSON() 248 controller.ServeJSON()
249 } 249 }
250 250
251 -// 返回兑换素币清单 251 +// 新增兑换素币清单
252 func (controller *SuMoneyController) CreateExchangeList () { 252 func (controller *SuMoneyController) CreateExchangeList () {
253 cashPoolService := service.NewCashPoolService(nil) 253 cashPoolService := service.NewCashPoolService(nil)
254 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{} 254 createExchangeCashPersonCommand := &command.CreateExchangeCashPersonCommand{}
@@ -364,6 +364,23 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -364,6 +364,23 @@ func (controller *SuMoneyController) ImportExchangeList () {
364 controller.ServeJSON() 364 controller.ServeJSON()
365 } 365 }
366 366
  367 +// 返回兑换活动截止时间列表
  368 +func (controller *SuMoneyController) ListDeadline() {
  369 + cashPoolService := service.NewCashPoolService(nil)
  370 + listExchangeCashActivityDeadlineQuery := &query.ListExchangeCashActivityDeadlineQuery{}
  371 + companyId, _ := controller.GetInt64("companyId")
  372 + listExchangeCashActivityDeadlineQuery.CompanyId = companyId
  373 + data, err := cashPoolService.ListExchangeCashActivityDeadline(listExchangeCashActivityDeadlineQuery)
  374 + var response utils.JsonResponse
  375 + if err != nil {
  376 + response = utils.ResponseError(controller.Ctx, err)
  377 + } else {
  378 + response = utils.ResponseData(controller.Ctx, data)
  379 + }
  380 + controller.Data["json"] = response
  381 + controller.ServeJSON()
  382 +}
  383 +
367 // TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息 384 // TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息
368 func (controller *SuMoneyController) ExportExchangeList() { 385 func (controller *SuMoneyController) ExportExchangeList() {
369 386
@@ -24,6 +24,7 @@ func init() { @@ -24,6 +24,7 @@ func init() {
24 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Put:UpdateExchangeActivities") // 编辑兑换活动 24 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Put:UpdateExchangeActivities") // 编辑兑换活动
25 beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "Post:CreateExchangeActivities") // 新增兑换活动 25 beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "Post:CreateExchangeActivities") // 新增兑换活动
26 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeActivities") // 删除兑换活动 26 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeActivities") // 删除兑换活动
  27 + beego.Router("/cash-pool/activity/deadline-list", &controllers.SuMoneyController{}, "Get:ListDeadline") // 返回兑换活动截止时间列表
27 28
28 /********************************************素币兑换清单*************************************/ 29 /********************************************素币兑换清单*************************************/
29 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Get:ListExchangeList") // 返回素币兑换清单 30 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Get:ListExchangeList") // 返回素币兑换清单