作者 linmadan

添加统计功能,重构任务查询参数

  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type PersonSuMoneyStatisticsCommand struct {
  10 + // 统一用户UID
  11 + Uid int64 `json:"uid" valid:"Required"`
  12 +}
  13 +
  14 +func (personSuMoneyStatisticsCommand *PersonSuMoneyStatisticsCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(personSuMoneyStatisticsCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type PersonTaskStatisticsCommand struct {
  10 + // 统一用户UID
  11 + Uid int64 `json:"uid" valid:"Required"`
  12 +}
  13 +
  14 +func (personTaskStatisticsCommand *PersonTaskStatisticsCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(personTaskStatisticsCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type SystemTaskStatisticsCommand struct {
  10 + // 公司ID
  11 + CompanyId int64 `json:"companyId" valid:"Required"`
  12 +}
  13 +
  14 +func (systemTaskStatisticsCommand *SystemTaskStatisticsCommand) ValidateCommand() error {
  15 + valid := validation.Validation{}
  16 + b, err := valid.Valid(systemTaskStatisticsCommand)
  17 + if err != nil {
  18 + return err
  19 + }
  20 + if !b {
  21 + for _, validErr := range valid.Errors {
  22 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  23 + }
  24 + }
  25 + return nil
  26 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  9 +)
  10 +
  11 +// 数据统计服务
  12 +type StatisticsService struct {
  13 +}
  14 +
  15 +// 获取系统任务统计
  16 +func (statisticsService *StatisticsService) SystemTaskStatistics(systemTaskStatisticsCommand *command.SystemTaskStatisticsCommand) (interface{}, error) {
  17 + if err := systemTaskStatisticsCommand.ValidateCommand(); err != nil {
  18 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  19 + }
  20 + transactionContext, err := factory.CreateTransactionContext(nil)
  21 + if err != nil {
  22 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  23 + }
  24 + if err := transactionContext.StartTransaction(); err != nil {
  25 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 + }
  27 + defer func() {
  28 + transactionContext.RollbackTransaction()
  29 + }()
  30 + var taskDao *dao.TaskDao
  31 + if value, err := factory.CreateTaskDao(map[string]interface{}{
  32 + "transactionContext": transactionContext,
  33 + }); err != nil {
  34 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  35 + } else {
  36 + taskDao = value
  37 + }
  38 + if systemTaskStatistics, err := taskDao.CalculateSystemTask(systemTaskStatisticsCommand.CompanyId); err != nil {
  39 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  40 + } else {
  41 + if err := transactionContext.CommitTransaction(); err != nil {
  42 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  43 + }
  44 + return systemTaskStatistics, nil
  45 + }
  46 +}
  47 +
  48 +// 获取个人任务统计
  49 +func (statisticsService *StatisticsService) PersonTaskStatistics(personTaskStatisticsCommand *command.PersonTaskStatisticsCommand) (interface{}, error) {
  50 + if err := personTaskStatisticsCommand.ValidateCommand(); err != nil {
  51 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  52 + }
  53 + transactionContext, err := factory.CreateTransactionContext(nil)
  54 + if err != nil {
  55 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  56 + }
  57 + if err := transactionContext.StartTransaction(); err != nil {
  58 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  59 + }
  60 + defer func() {
  61 + transactionContext.RollbackTransaction()
  62 + }()
  63 + var taskDao *dao.TaskDao
  64 + if value, err := factory.CreateTaskDao(map[string]interface{}{
  65 + "transactionContext": transactionContext,
  66 + }); err != nil {
  67 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  68 + } else {
  69 + taskDao = value
  70 + }
  71 + var employeeRepository domain.EmployeeRepository
  72 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  73 + "transactionContext": transactionContext,
  74 + }); err != nil {
  75 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  76 + } else {
  77 + employeeRepository = value
  78 + }
  79 + employee, err := employeeRepository.FindOne(map[string]interface{}{
  80 + "uid": personTaskStatisticsCommand.Uid,
  81 + })
  82 + if err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + }
  85 + if employee == nil {
  86 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
  87 + }
  88 + if personTaskStatistics, err := taskDao.CalculatePersonTask(personTaskStatisticsCommand.Uid); err != nil {
  89 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  90 + } else {
  91 + if err := transactionContext.CommitTransaction(); err != nil {
  92 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  93 + }
  94 + return personTaskStatistics, nil
  95 + }
  96 +}
  97 +
  98 +// 获取个人素币统计
  99 +func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMoneyStatisticsCommand *command.PersonSuMoneyStatisticsCommand) (interface{}, error) {
  100 + if err := personSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
  101 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  102 + }
  103 + transactionContext, err := factory.CreateTransactionContext(nil)
  104 + if err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + if err := transactionContext.StartTransaction(); err != nil {
  108 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  109 + }
  110 + defer func() {
  111 + transactionContext.RollbackTransaction()
  112 + }()
  113 + var employeeDao *dao.EmployeeDao
  114 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  115 + "transactionContext": transactionContext,
  116 + }); err != nil {
  117 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  118 + } else {
  119 + employeeDao = value
  120 + }
  121 + var employeeRepository domain.EmployeeRepository
  122 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  123 + "transactionContext": transactionContext,
  124 + }); err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + } else {
  127 + employeeRepository = value
  128 + }
  129 + employee, err := employeeRepository.FindOne(map[string]interface{}{
  130 + "uid": personSuMoneyStatisticsCommand.Uid,
  131 + })
  132 + if err != nil {
  133 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  134 + }
  135 + if employee == nil {
  136 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
  137 + }
  138 + if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil {
  139 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  140 + } else {
  141 + if err := transactionContext.CommitTransaction(); err != nil {
  142 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  143 + }
  144 + personSuMoneyStatistics.CurrentSuMoney = employee.SuMoney
  145 + return personSuMoneyStatistics, nil
  146 + }
  147 +}
  148 +
  149 +func NewStatisticsService(options map[string]interface{}) *StatisticsService {
  150 + newStatisticsService := &StatisticsService{}
  151 + return newStatisticsService
  152 +}
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/astaxie/beego/validation" 7 "github.com/astaxie/beego/validation"
7 ) 8 )
@@ -12,6 +13,10 @@ type SearchSuMoneyTransactionRecordCommand struct { @@ -12,6 +13,10 @@ type SearchSuMoneyTransactionRecordCommand struct {
12 // 记录类型(1兑换,2任务奖励) 13 // 记录类型(1兑换,2任务奖励)
13 RecordType int `json:"recordType" valid:"Required"` 14 RecordType int `json:"recordType" valid:"Required"`
14 // 操作人UID 15 // 操作人UID
  16 + // 事务时间区间-开始时间
  17 + TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
  18 + // 事务时间区间-截止时间
  19 + TransactionEndTime time.Time `json:"transactionEndTime,omitempty"`
15 Operator int64 `json:"operator,omitempty"` 20 Operator int64 `json:"operator,omitempty"`
16 // 查询偏离量 21 // 查询偏离量
17 Offset int `json:"offset,omitempty"` 22 Offset int `json:"offset,omitempty"`
@@ -23,6 +23,8 @@ type SearchTaskCommand struct { @@ -23,6 +23,8 @@ type SearchTaskCommand struct {
23 TaskNature string `json:"taskNature,omitempty"` 23 TaskNature string `json:"taskNature,omitempty"`
24 // 是否悬赏任务 24 // 是否悬赏任务
25 IsRewardTake bool `json:"isRewardTake,omitempty"` 25 IsRewardTake bool `json:"isRewardTake,omitempty"`
  26 + // 竞标参与者UID
  27 + Bidder int64 `json:"bidder,omitempty"`
26 // 竞标时间(1全部,2已截止,3未截止) 28 // 竞标时间(1全部,2已截止,3未截止)
27 BidTimeMatch int `json:"bidTimeMatch,omitempty"` 29 BidTimeMatch int `json:"bidTimeMatch,omitempty"`
28 // 任务领取人 30 // 任务领取人
@@ -25,6 +25,8 @@ type ListTaskQuery struct { @@ -25,6 +25,8 @@ type ListTaskQuery struct {
25 TaskNature string `json:"taskNature,omitempty"` 25 TaskNature string `json:"taskNature,omitempty"`
26 // 是否悬赏任务 26 // 是否悬赏任务
27 IsRewardTake bool `json:"isRewardTake,omitempty"` 27 IsRewardTake bool `json:"isRewardTake,omitempty"`
  28 + // 竞标参与者UID
  29 + Bidder int64 `json:"bidder,omitempty"`
28 // 竞标时间(1全部,2已截止,3未截止) 30 // 竞标时间(1全部,2已截止,3未截止)
29 BidTimeMatch int `json:"bidTimeMatch,omitempty"` 31 BidTimeMatch int `json:"bidTimeMatch,omitempty"`
30 // 任务领取人 32 // 任务领取人
  1 +package domain
  2 +
  3 +// 个人素币统计
  4 +type PersonSuMoneyStatistics struct {
  5 + // 当前素币
  6 + CurrentSuMoney float64 `json:"currentSuMoney"`
  7 + // 昨日收益
  8 + IncomeSuMoneyOfYesterday float64 `json:"incomeSuMoneyOfYesterday"`
  9 +}
  1 +package domain
  2 +
  3 +// 个人任务统计
  4 +type PersonTaskStatistics struct {
  5 + // 个人领取的进行中任务
  6 + UnderwayAsReceiver int64 `json:"underwayAsReceiver"`
  7 + // 个人领取的待验收任务
  8 + UnAcceptanceAsReceiver int64 `json:"unAcceptanceAsReceiver"`
  9 + // 个人领取的已完成任务
  10 + CompletedAsReceiver int64 `json:"completedAsReceiver"`
  11 + // 个人发起的待发布任务
  12 + UnReleasedAsSponsor int64 `json:"unReleasedAsSponsor"`
  13 + // 个人发起的待领取任务
  14 + UnClaimedAsSponsor int64 `json:"unClaimedAsSponsor"`
  15 + // 个人发起的进行中任务
  16 + UnderwayAsSponsor int64 `json:"underwayAsSponsor"`
  17 + // 个人发起的待验收任务
  18 + UnAcceptanceAsSponsor int64 `json:"unAcceptanceAsSponsor"`
  19 + // 个人发起的已完成任务
  20 + CompletedAsSponsor int64 `json:"completedAsSponsor"`
  21 + // 个人参与的竞标中任务
  22 + BidAsParticipator int64 `json:"bidAsParticipator"`
  23 + // 个人参与的已完成任务
  24 + CompletedAsParticipator int64 `json:"completedAsParticipator"`
  25 +}
  1 +package domain
  2 +
  3 +// 系统任务统计
  4 +type SystemTaskStatistics struct {
  5 + // 系统已发布任务
  6 + Released int64 `json:"released"`
  7 + // 系统进行中任务
  8 + Underway int64 `json:"underway"`
  9 + // 系统已完成任务
  10 + Completed int64 `json:"completed"`
  11 +}
@@ -4,6 +4,9 @@ import ( @@ -4,6 +4,9 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  9 + "time"
7 ) 10 )
8 11
9 type EmployeeDao struct { 12 type EmployeeDao struct {
@@ -19,6 +22,24 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { @@ -19,6 +22,24 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
19 return err 22 return err
20 } 23 }
21 24
  25 +func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoneyStatistics, error) {
  26 + tx := dao.transactionContext.PgTx
  27 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  28 + personSuMoneyStatistics := &domain.PersonSuMoneyStatistics{}
  29 + yesterday := time.Now().AddDate(0, 0, -1)
  30 + if err := tx.Model(suMoneyTransactionRecordModel).
  31 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  32 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  33 + Where(`su_money_transaction_record.record_type = ?`, 2).
  34 + Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
  35 + Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
  36 + Select(&personSuMoneyStatistics.IncomeSuMoneyOfYesterday); err != nil {
  37 + return nil, err
  38 + } else {
  39 + return personSuMoneyStatistics, nil
  40 + }
  41 +}
  42 +
22 func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) { 43 func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
23 if transactionContext == nil { 44 if transactionContext == nil {
24 return nil, fmt.Errorf("transactionContext参数不能为nil") 45 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -2,6 +2,7 @@ package dao @@ -2,6 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
5 "time" 6 "time"
6 7
7 "github.com/go-pg/pg" 8 "github.com/go-pg/pg"
@@ -49,6 +50,124 @@ func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.E @@ -49,6 +50,124 @@ func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.E
49 return err 50 return err
50 } 51 }
51 52
  53 +func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStatistics, error) {
  54 + tx := dao.transactionContext.PgTx
  55 + taskModel := new(models.Task)
  56 + systemTaskStatistics := &domain.SystemTaskStatistics{}
  57 + if count, err := tx.Model(taskModel).
  58 + Where("task.company_id = ?", companyId).
  59 + Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
  60 + Count(); err != nil {
  61 + return nil, err
  62 + } else {
  63 + systemTaskStatistics.Released = int64(count)
  64 + }
  65 + if count, err := tx.Model(taskModel).
  66 + Where("task.company_id = ?", companyId).
  67 + Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  68 + Count(); err != nil {
  69 + return nil, err
  70 + } else {
  71 + systemTaskStatistics.Underway = int64(count)
  72 + }
  73 + if count, err := tx.Model(taskModel).
  74 + Where("task.company_id = ?", companyId).
  75 + Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  76 + Count(); err != nil {
  77 + return nil, err
  78 + } else {
  79 + systemTaskStatistics.Completed = int64(count)
  80 + }
  81 + return systemTaskStatistics, nil
  82 +}
  83 +
  84 +func (dao *TaskDao) CalculatePersonTask(uid int64) (*domain.PersonTaskStatistics, error) {
  85 + tx := dao.transactionContext.PgTx
  86 + taskModel := new(models.Task)
  87 + personTaskStatistics := &domain.PersonTaskStatistics{}
  88 + if count, err := tx.Model(taskModel).
  89 + Where("task.receiver_uid = ?", uid).
  90 + Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  91 + Count(); err != nil {
  92 + return nil, err
  93 + } else {
  94 + personTaskStatistics.UnderwayAsReceiver = int64(count)
  95 + }
  96 + if count, err := tx.Model(taskModel).
  97 + Where("task.receiver_uid = ?", uid).
  98 + Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE).
  99 + Count(); err != nil {
  100 + return nil, err
  101 + } else {
  102 + personTaskStatistics.UnAcceptanceAsReceiver = int64(count)
  103 + }
  104 + if count, err := tx.Model(taskModel).
  105 + Where("task.receiver_uid = ?", uid).
  106 + Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  107 + Count(); err != nil {
  108 + return nil, err
  109 + } else {
  110 + personTaskStatistics.CompletedAsReceiver = int64(count)
  111 + }
  112 + if count, err := tx.Model(taskModel).
  113 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  114 + Where("task.task_status = ? ", domain.TASK_STATUS_UNRELEASED).
  115 + Count(); err != nil {
  116 + return nil, err
  117 + } else {
  118 + personTaskStatistics.UnReleasedAsSponsor = int64(count)
  119 + }
  120 + if count, err := tx.Model(taskModel).
  121 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  122 + Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
  123 + Count(); err != nil {
  124 + return nil, err
  125 + } else {
  126 + personTaskStatistics.UnClaimedAsSponsor = int64(count)
  127 + }
  128 + if count, err := tx.Model(taskModel).
  129 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  130 + Where("task.task_status = ? ", domain.TASK_STATUS_UNDERWAY).
  131 + Count(); err != nil {
  132 + return nil, err
  133 + } else {
  134 + personTaskStatistics.UnderwayAsReceiver = int64(count)
  135 + }
  136 + if count, err := tx.Model(taskModel).
  137 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  138 + Where("task.task_status = ? ", domain.TASK_STATUS_UNACCEPTANCE).
  139 + Count(); err != nil {
  140 + return nil, err
  141 + } else {
  142 + personTaskStatistics.UnAcceptanceAsSponsor = int64(count)
  143 + }
  144 + if count, err := tx.Model(taskModel).
  145 + Where(`task.sponsor @> '{"uid":?}'`, uid).
  146 + Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  147 + Count(); err != nil {
  148 + return nil, err
  149 + } else {
  150 + personTaskStatistics.CompletedAsSponsor = int64(count)
  151 + }
  152 + if count, err := tx.Model(taskModel).Join("JOIN bidder_infos AS bidder_info ON bidder_info.task_id = task.id").
  153 + Where(`bidder_info.Bidder @> '{"uid":?}'`, uid).
  154 + Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
  155 + Count(); err != nil {
  156 + return nil, err
  157 + } else {
  158 + personTaskStatistics.BidAsParticipator = int64(count)
  159 + }
  160 + if count, err := tx.Model(taskModel).
  161 + Where(`task.participators @> '[{"uid":?}]'`, uid).
  162 + Where("task.task_status = ? ", domain.TASK_STATUS_COMPLETED).
  163 + Count(); err != nil {
  164 + return nil, err
  165 + } else {
  166 + personTaskStatistics.CompletedAsParticipator = int64(count)
  167 + }
  168 + return personTaskStatistics, nil
  169 +}
  170 +
52 func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) { 171 func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
53 if transactionContext == nil { 172 if transactionContext == nil {
54 return nil, fmt.Errorf("transactionContext参数不能为nil") 173 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/go-pg/pg" 7 "github.com/go-pg/pg"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -75,6 +76,12 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -75,6 +76,12 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
75 if operator, ok := queryOptions["operator"]; ok && (operator != int64(0)) { 76 if operator, ok := queryOptions["operator"]; ok && (operator != int64(0)) {
76 query = query.Where(`su_money_transaction_record.operator @> '{"uid":?}'`, operator) 77 query = query.Where(`su_money_transaction_record.operator @> '{"uid":?}'`, operator)
77 } 78 }
  79 + if transactionStartTime, ok := queryOptions["transactionStartTime"]; ok && !transactionStartTime.(time.Time).IsZero() {
  80 + query = query.Where(`su_money_transaction_record.create_time > ?`, transactionStartTime)
  81 + }
  82 + if transactionEndTime, ok := queryOptions["transactionEndTime"]; ok && !transactionEndTime.(time.Time).IsZero() {
  83 + query = query.Where(`su_money_transaction_record.create_time < ?`, transactionEndTime)
  84 + }
78 if offset, ok := queryOptions["offset"]; ok { 85 if offset, ok := queryOptions["offset"]; ok {
79 offset := offset.(int) 86 offset := offset.(int)
80 if offset > -1 { 87 if offset > -1 {
@@ -137,6 +137,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -137,6 +137,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
137 query = query.Where("bid_info.bid_end_time > ?", time.Now()) 137 query = query.Where("bid_info.bid_end_time > ?", time.Now())
138 } 138 }
139 } 139 }
  140 + if bidder, ok := queryOptions["bidder"]; ok && (bidder != int64(0)) {
  141 + query = query.Join("JOIN bidder_infos AS bidder_info ON bidder_info.task_id = task.id")
  142 + query = query.Where(`bidder_info.Bidder @> '{"uid":?}'`, bidder)
  143 + }
140 if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) { 144 if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) {
141 query = query.Where(`task.receiver_uid = ?`, receiver) 145 query = query.Where(`task.receiver_uid = ?`, receiver)
142 } 146 }
@@ -146,7 +150,6 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -146,7 +150,6 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
146 if taskIds, ok := queryOptions["taskIds"]; ok { 150 if taskIds, ok := queryOptions["taskIds"]; ok {
147 query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64))) 151 query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64)))
148 } 152 }
149 -  
150 if offRangTime, ok := queryOptions["offRangTime"]; ok { 153 if offRangTime, ok := queryOptions["offRangTime"]; ok {
151 query = query.Join("JOIN off_task_records ON off_task_record.task_id = task.id") 154 query = query.Join("JOIN off_task_records ON off_task_record.task_id = task.id")
152 if offStartTime, ok := offRangTime.(map[string]time.Time)["offStartTime"]; ok { 155 if offStartTime, ok := offRangTime.(map[string]time.Time)["offStartTime"]; ok {
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/service"
  10 +)
  11 +
  12 +type StatisticsController struct {
  13 + beego.Controller
  14 +}
  15 +
  16 +func (controller *StatisticsController) SystemTaskStatistics() {
  17 + statisticsService := service.NewStatisticsService(nil)
  18 + systemTaskStatisticsCommand := &command.SystemTaskStatisticsCommand{}
  19 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemTaskStatisticsCommand)
  20 + data, err := statisticsService.SystemTaskStatistics(systemTaskStatisticsCommand)
  21 + var response utils.JsonResponse
  22 + if err != nil {
  23 + response = utils.ResponseError(controller.Ctx, err)
  24 + } else {
  25 + response = utils.ResponseData(controller.Ctx, data)
  26 + }
  27 + controller.Data["json"] = response
  28 + controller.ServeJSON()
  29 +}
  30 +
  31 +func (controller *StatisticsController) PersonTaskStatistics() {
  32 + statisticsService := service.NewStatisticsService(nil)
  33 + personTaskStatisticsCommand := &command.PersonTaskStatisticsCommand{}
  34 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), personTaskStatisticsCommand)
  35 + data, err := statisticsService.PersonTaskStatistics(personTaskStatisticsCommand)
  36 + var response utils.JsonResponse
  37 + if err != nil {
  38 + response = utils.ResponseError(controller.Ctx, err)
  39 + } else {
  40 + response = utils.ResponseData(controller.Ctx, data)
  41 + }
  42 + controller.Data["json"] = response
  43 + controller.ServeJSON()
  44 +}
  45 +
  46 +func (controller *StatisticsController) PersonSuMoneyStatistics() {
  47 + statisticsService := service.NewStatisticsService(nil)
  48 + personSuMoneyStatisticsCommand := &command.PersonSuMoneyStatisticsCommand{}
  49 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), personSuMoneyStatisticsCommand)
  50 + data, err := statisticsService.PersonSuMoneyStatistics(personSuMoneyStatisticsCommand)
  51 + var response utils.JsonResponse
  52 + if err != nil {
  53 + response = utils.ResponseError(controller.Ctx, err)
  54 + } else {
  55 + response = utils.ResponseData(controller.Ctx, data)
  56 + }
  57 + controller.Data["json"] = response
  58 + controller.ServeJSON()
  59 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/statistics/system-task", &controllers.StatisticsController{}, "Post:SystemTaskStatistics")
  10 + beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics")
  11 + beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")
  12 +}
  1 +package statistics
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  5 + "net/http"
  6 + "time"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("获取个人素币统计", func() {
  16 + var suMoneyTransactionRecordId int64
  17 + BeforeEach(func() {
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(&suMoneyTransactionRecordId),
  20 + "INSERT INTO su_money_transaction_records (id, record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id",
  21 + 1, 2, &domain.EmployeeInfo{
  22 + Uid: 2499036607974745088,
  23 + }, 1000.00, &domain.EmployeeInfo{
  24 + Uid: 2499036607974745099,
  25 + }, "testRecordDescription", time.Now().AddDate(0, 0, -1))
  26 + Expect(err).NotTo(HaveOccurred())
  27 + _, err2 := pG.DB.QueryOne(
  28 + pg.Scan(),
  29 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
  30 + 2, 101, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 1000)
  31 + Expect(err2).NotTo(HaveOccurred())
  32 + })
  33 + Describe("获取个人素币统计", func() {
  34 + Context("请求获取个人素币统计", func() {
  35 + It("返回个人素币统计", func() {
  36 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  37 + body := map[string]interface{}{
  38 + "uid": 2499036607974745088,
  39 + }
  40 + httpExpect.POST("/statistics/person-su-money").
  41 + WithJSON(body).
  42 + Expect().
  43 + Status(http.StatusOK).
  44 + JSON().
  45 + Object().
  46 + ContainsKey("code").ValueEqual("code", 0).
  47 + ContainsKey("msg").ValueEqual("msg", "ok").
  48 + ContainsKey("data").Value("data").Object()
  49 + })
  50 + })
  51 + })
  52 + AfterEach(func() {
  53 + _, err := pG.DB.Exec("DELETE FROM su_money_transaction_records WHERE true")
  54 + Expect(err).NotTo(HaveOccurred())
  55 + _, err1 := pG.DB.Exec("DELETE FROM employees WHERE true")
  56 + Expect(err1).NotTo(HaveOccurred())
  57 + })
  58 +})
  1 +package statistics
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  5 + "net/http"
  6 + "time"
  7 +
  8 + "github.com/gavv/httpexpect"
  9 + "github.com/go-pg/pg"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("获取个人任务统计", func() {
  16 + BeforeEach(func() {
  17 + dayAfter, _ := time.ParseDuration("72h")
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(),
  20 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  21 + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
  22 + Uid: 2499036607974745088,
  23 + }, 2, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  24 + {
  25 + Uid: 2499036607974745077,
  26 + },
  27 + {
  28 + Uid: 2499036607974745066,
  29 + },
  30 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
  31 + Expect(err).NotTo(HaveOccurred())
  32 + _, err1 := pG.DB.QueryOne(
  33 + pg.Scan(),
  34 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  35 + 2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
  36 + Uid: 2499036607974745088,
  37 + }, 2, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  38 + Expect(err1).NotTo(HaveOccurred())
  39 + _, err2 := pG.DB.QueryOne(
  40 + pg.Scan(),
  41 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  42 + 3, 102, "竞标任务1", 2, &domain.EmployeeInfo{
  43 + Uid: 2499036607974745088,
  44 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  45 + Expect(err2).NotTo(HaveOccurred())
  46 + _, err3 := pG.DB.QueryOne(
  47 + pg.Scan(),
  48 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  49 + 4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
  50 + Uid: 2499036607974745099,
  51 + }, 2, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  52 + Expect(err3).NotTo(HaveOccurred())
  53 + _, err4 := pG.DB.QueryOne(
  54 + pg.Scan(),
  55 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  56 + 5, 303, "抢单任务1", 1, &domain.EmployeeInfo{
  57 + Uid: 2499036607974745088,
  58 + }, 6, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  59 + {
  60 + Uid: 2499036607974745077,
  61 + },
  62 + {
  63 + Uid: 2499036607974745066,
  64 + },
  65 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
  66 + Expect(err4).NotTo(HaveOccurred())
  67 + _, err5 := pG.DB.QueryOne(
  68 + pg.Scan(),
  69 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
  70 + 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0)
  71 + Expect(err5).NotTo(HaveOccurred())
  72 + _, err11 := pG.DB.QueryOne(
  73 + pg.Scan(),
  74 + "INSERT INTO bid_infos (id, task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?, ?)",
  75 + 1, 4, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Date(2020, time.Month(4), 10, 8, 0, 0, 0, time.Now().Location()))
  76 + Expect(err11).NotTo(HaveOccurred())
  77 + _, err22 := pG.DB.QueryOne(
  78 + pg.Scan(),
  79 + "INSERT INTO bidder_infos (id, bid_info_id, task_id, bidder) VALUES (?, ?, ?, ?)",
  80 + 1, 1, 4, &domain.EmployeeInfo{
  81 + Uid: 2499036607974745099,
  82 + })
  83 + Expect(err22).NotTo(HaveOccurred())
  84 + })
  85 + Describe("获取个人任务统计", func() {
  86 + Context("请求个人任务统计", func() {
  87 + It("返回个人任务统计", func() {
  88 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  89 + body := map[string]interface{}{
  90 + "uid": 2499036607974745099,
  91 + }
  92 + httpExpect.POST("/statistics/person-task").
  93 + WithJSON(body).
  94 + Expect().
  95 + Status(http.StatusOK).
  96 + JSON().
  97 + Object().
  98 + ContainsKey("code").ValueEqual("code", 0).
  99 + ContainsKey("msg").ValueEqual("msg", "ok").
  100 + ContainsKey("data").Value("data").Object()
  101 + })
  102 + })
  103 + })
  104 + AfterEach(func() {
  105 + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
  106 + Expect(err).NotTo(HaveOccurred())
  107 + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
  108 + Expect(err1).NotTo(HaveOccurred())
  109 + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
  110 + Expect(err2).NotTo(HaveOccurred())
  111 + _, err3 := pG.DB.Exec("DELETE FROM employees WHERE true")
  112 + Expect(err3).NotTo(HaveOccurred())
  113 + })
  114 +})
  1 +package statistics
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestStatistics(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port Statistics Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package statistics
  2 +
  3 +import (
  4 + "github.com/go-pg/pg"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 + "net/http"
  7 + "time"
  8 +
  9 + "github.com/gavv/httpexpect"
  10 + . "github.com/onsi/ginkgo"
  11 + . "github.com/onsi/gomega"
  12 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  13 +)
  14 +
  15 +var _ = Describe("获取系统任务统计", func() {
  16 + BeforeEach(func() {
  17 + dayAfter, _ := time.ParseDuration("72h")
  18 + _, err := pG.DB.QueryOne(
  19 + pg.Scan(),
  20 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  21 + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
  22 + Uid: 2499036607974745088,
  23 + }, 2, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  24 + {
  25 + Uid: 2499036607974745077,
  26 + },
  27 + {
  28 + Uid: 2499036607974745066,
  29 + },
  30 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
  31 + Expect(err).NotTo(HaveOccurred())
  32 + _, err1 := pG.DB.QueryOne(
  33 + pg.Scan(),
  34 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  35 + 2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
  36 + Uid: 2499036607974745088,
  37 + }, 2, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  38 + Expect(err1).NotTo(HaveOccurred())
  39 + _, err2 := pG.DB.QueryOne(
  40 + pg.Scan(),
  41 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  42 + 3, 102, "竞标任务1", 2, &domain.EmployeeInfo{
  43 + Uid: 2499036607974745088,
  44 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  45 + Expect(err2).NotTo(HaveOccurred())
  46 + _, err3 := pG.DB.QueryOne(
  47 + pg.Scan(),
  48 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  49 + 4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
  50 + Uid: 2499036607974745099,
  51 + }, 5, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
  52 + Expect(err3).NotTo(HaveOccurred())
  53 + _, err4 := pG.DB.QueryOne(
  54 + pg.Scan(),
  55 + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  56 + 5, 303, "抢单任务1", 1, &domain.EmployeeInfo{
  57 + Uid: 2499036607974745088,
  58 + }, 6, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  59 + {
  60 + Uid: 2499036607974745077,
  61 + },
  62 + {
  63 + Uid: 2499036607974745066,
  64 + },
  65 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
  66 + Expect(err4).NotTo(HaveOccurred())
  67 + _, err11 := pG.DB.QueryOne(
  68 + pg.Scan(),
  69 + "INSERT INTO bid_infos (id, task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?, ?)",
  70 + 1, 4, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Date(2020, time.Month(4), 10, 8, 0, 0, 0, time.Now().Location()))
  71 + Expect(err11).NotTo(HaveOccurred())
  72 + _, err22 := pG.DB.QueryOne(
  73 + pg.Scan(),
  74 + "INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)",
  75 + 1, 1, 4)
  76 + Expect(err22).NotTo(HaveOccurred())
  77 + })
  78 + Describe("获取系统任务统计", func() {
  79 + Context("请求系统任务统计", func() {
  80 + It("返回统计结果", func() {
  81 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  82 + body := map[string]interface{}{
  83 + "companyId": 101,
  84 + }
  85 + httpExpect.POST("/statistics/system-task").
  86 + WithJSON(body).
  87 + Expect().
  88 + Status(http.StatusOK).
  89 + JSON().
  90 + Object().
  91 + ContainsKey("code").ValueEqual("code", 0).
  92 + ContainsKey("msg").ValueEqual("msg", "ok").
  93 + ContainsKey("data").Value("data").Object()
  94 + })
  95 + })
  96 + })
  97 + AfterEach(func() {
  98 + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
  99 + Expect(err).NotTo(HaveOccurred())
  100 + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
  101 + Expect(err1).NotTo(HaveOccurred())
  102 + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
  103 + Expect(err2).NotTo(HaveOccurred())
  104 + })
  105 +})