作者 陈志颖

fix:修复悬赏任务数不一致问题

... ... @@ -28,6 +28,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
defer func() {
transactionContext.RollbackTransaction()
}()
var notificationRepository domain.NotificationRepository
if value, err := factory.CreateNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -36,6 +37,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
} else {
notificationRepository = value
}
var sentNotificationRepository domain.SentNotificationRepository
if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -44,6 +46,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
} else {
sentNotificationRepository = value
}
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -52,6 +55,13 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
} else {
taskDao = value
}
// 更新已过期竞标任务状态
if err := taskDao.UpdateExpiredPlannedCompletionTimeBidTask(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 返回快过期任务并发送消息
if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -88,6 +98,7 @@ func (notificationService *NotificationService) SystemNotificationNearThePlanned
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
... ... @@ -108,6 +119,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
defer func() {
transactionContext.RollbackTransaction()
}()
var notificationRepository domain.NotificationRepository
if value, err := factory.CreateNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -116,6 +128,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
} else {
notificationRepository = value
}
var sentNotificationRepository domain.SentNotificationRepository
if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -124,6 +137,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
} else {
sentNotificationRepository = value
}
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -132,6 +146,7 @@ func (notificationService *NotificationService) SystemNotificationNearBidEndTime
} else {
taskDao = value
}
if tasks, err := taskDao.ListNearBidEndTimeTask(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -24,6 +24,7 @@ const (
TASK_STATUS_COMPLETED //已完成
TASK_STATUS_CLOSED //关闭
TASK_STATUS_UNCONFIRMED //待确认
TASK_STATUS_EXPIRED //已过期
)
// 任务
... ...
... ... @@ -349,13 +349,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 财富值榜单
queryWealth := tx.Model(suMoneyTransactionRecordModel)
queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
queryWealth = queryWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
queryWealth = queryWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
queryWealth = queryWealth.Where(`e.status = ?`, 1)
queryWealth = queryWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
... ... @@ -368,6 +369,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
queryWealth = queryWealth.Group("su_money_transaction_record.employee")
queryWealth = queryWealth.Group("su_money_transaction_record.create_time")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -394,7 +396,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
queryEmployeeWealth = queryEmployeeWealth.Where(`e.status = ?`, 1)
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
... ... @@ -406,10 +408,11 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee")
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.create_time")
if uid, ok := queryOptions["uid"]; ok {
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
}
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee")
if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil {
return nil, err
}
... ... @@ -426,7 +429,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
}
... ... @@ -438,7 +441,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee")
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee").Group("su_money_transaction_record.create_time")
queryContributions := tx.Model()
queryContributions = queryContributions.With("t", contributionsDecrease)
... ... @@ -448,7 +451,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
queryContributions = queryContributions.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
queryContributions = queryContributions.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC,su_money_transaction_records.create_time) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
}
... ... @@ -462,6 +465,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
}
queryContributions = queryContributions.Group("su_money_transaction_records.employee")
queryContributions = queryContributions.Group("t.employee_contributions_decrease")
queryContributions = queryContributions.Group("su_money_transaction_records.create_time")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ...
... ... @@ -14,6 +14,7 @@ type TaskDao struct {
transactionContext *pgTransaction.TransactionContext
}
// 返回接近截止时间任务
func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, error) {
tx := dao.transactionContext.PgTx
var taskModels []*models.Task
... ... @@ -31,6 +32,23 @@ func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, erro
}
}
// 更新已过期的竞标任务的状态
func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error {
tx := dao.transactionContext.PgTx
var taskModels []*models.Task
currentTime := time.Now()
currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, time.Now().Location())
query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo").
Set("task.task_type = ", domain.TASK_STATUS_EXPIRED).
Where("task.planned_completion_time > ?", currentDay).
Where(`task.task_type =?`, domain.TASK_TYPE_BID)
if _, err := query.Update(); err != nil {
return err
}
return nil
}
// 返回接近竞标截止时间的竞标任务
func (dao *TaskDao) ListNearBidEndTimeTask() ([]*models.Task, error) {
tx := dao.transactionContext.PgTx
var taskModels []*models.Task
... ... @@ -146,6 +164,9 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}
}
if count, err := tx.Model(taskModel).
Where("task.company_id = ?", companyId).
Where("task.task_status <> ? ", domain.TASK_STATUS_CLOSED).
Where("task.task_status <> ?", domain.TASK_STATUS_UNRELEASED).
Where("task.task_status = ?", domain.TASK_STATUS_UNCLAIMED).
Where("task.is_reward_take = ?", true).
Count(); err != nil {
return nil, err
... ... @@ -300,14 +321,22 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro
completedAsParticipator = int64(count)
}
// 已过期任务统计(竞标时间过期的竞标任务,状态为待领取)
currentTime := time.Now()
currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location())
if count, err := tx.Model(taskModel).Relation("RobInfo").Relation("BidInfo").
//currentTime := time.Now()
//currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location())
//if count, err := tx.Model(taskModel).Relation("RobInfo").Relation("BidInfo").
// Where(`task.sponsor @> '{"uid":?}'`, uid).
// Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
// Where(`task.task_type = ?`, domain.TASK_TYPE_BID).
// Where("bid_info.bid_end_time >= ?", currentDay).
// Where("bid_info.bid_end_time < ?", currentDay).
// Count(); err != nil {
// return nil, err
//} else {
// expiredAsSponsor = int64(count)
//}
if count, err := tx.Model(taskModel).
Where(`task.sponsor @> '{"uid":?}'`, uid).
Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
Where(`task.task_type = ?`, domain.TASK_TYPE_BID).
Where("bid_info.bid_end_time >= ?", currentDay).
Where("bid_info.bid_end_time < ?", currentDay).
Where("task.task_status = ? ", domain.TASK_STATUS_EXPIRED).
Count(); err != nil {
return nil, err
} else {
... ...
... ... @@ -531,7 +531,7 @@ func (controller *SuMoneyController) ExportSuMoney() {
p := map[string]interface{} {
"name": record.Employee.EmployeeName,
"account": record.Employee.EmployeeAccount,
"current_su_money": record.SuMoney,
"current_su_money": record.CurrentSuMoney,
}
data = append(data, p)
}
... ... @@ -595,7 +595,7 @@ func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
for _, record := range records {
p := map[string]interface{} {
"name": record.Employee.EmployeeName,
"current_su_money": record.SuMoney,
"current_su_money": record.CurrentSuMoney,
"record": record.SuMoney,
"create_time": record.CreateTime,
"operator": record.Operator,
... ...