作者 陈志颖

fix:增加删除兑换素币

@@ -443,3 +443,37 @@ @@ -443,3 +443,37 @@
443 2020/11/22 14:35:34.993 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20.1606026934804518000 BodyData:{"code":0,"data":{"activities":[{"activityId":77,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:10:52.822645+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":78,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:36.794075+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":79,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:38.434336+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":81,"companyId":311,"countDown":2,"createTime":"2020-11-21T02:28:44.157965+08:00","deadline":1606147200000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":65,"exchangedSuMoney":13,"rate":5},{"activityId":83,"companyId":311,"countDown":6,"createTime":"2 443 2020/11/22 14:35:34.993 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20.1606026934804518000 BodyData:{"code":0,"data":{"activities":[{"activityId":77,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:10:52.822645+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":78,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:36.794075+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":79,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:38.434336+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":81,"companyId":311,"countDown":2,"createTime":"2020-11-21T02:28:44.157965+08:00","deadline":1606147200000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":65,"exchangedSuMoney":13,"rate":5},{"activityId":83,"companyId":311,"countDown":6,"createTime":"2
444 2020/11/22 14:35:34.993 [D] [server.go:1925] | 127.0.0.1| 200 | 189.433845ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/ 444 2020/11/22 14:35:34.993 [D] [server.go:1925] | 127.0.0.1| 200 | 189.433845ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
445 2020/11/22 15:22:03.137 [I] [???:0] http server Running on http://:8082 445 2020/11/22 15:22:03.137 [I] [???:0] http server Running on http://:8082
  446 +2020/11/22 15:35:27.716 [I] [???:0] http server Running on http://:8082
  447 +2020/11/22 15:35:51.784 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606030551783990000
  448 + Auth=
  449 + BodyData:{
  450 + "companyId": 381,
  451 + "uid": 3259769336174592,
  452 + "rankingType": 1,
  453 + "offset": 0,
  454 + "limit": 20
  455 +}
  456 +2020/11/22 15:35:52.314 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606030551783990000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":15917.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},"employeesContributions":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeesContributions":77800,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":15917.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeesContributions":-3068,"Ranking":3},{"Uid":3259769336070144,"EmployeeName":"杜迁","EmployeesContributions":-6665,"Ranking":4},{"Uid":3259769336037376,"EmployeeName":"朱贵2","EmployeesContributions":-6975,"Ranking":5},{"Uid":3259769336137728,"EmployeeName":"杨志358","EmployeesContributions":-6990.2,"Ranking":6},{"Uid":3288265494991872,"EmployeeName":"李四","EmployeesContributions":-10289.5,"Ranking":7},{"Uid":3259769336317952,"EmployeeName":"陈达","EmployeesContribu
  457 +2020/11/22 15:35:52.314 [D] [server.go:1925] | 127.0.0.1| 200 | 531.106924ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  458 +2020/11/22 15:57:26.837 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606031846837842000
  459 + Auth=
  460 + BodyData:{
  461 + "companyId": 358,
  462 + "uid": 3259769336174592,
  463 + "rankingType": 1,
  464 + "offset": 0,
  465 + "limit": 20
  466 +}
  467 +2020/11/22 15:57:26.937 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606031846837842000 BodyData:{"code":0,"data":{"currentEmployeeContributions":null,"currentEmployeeWealth":null,"employeesContributions":null,"employeesWealth":null},"msg":"ok"}
  468 +2020/11/22 15:57:26.937 [D] [server.go:1925] | 127.0.0.1| 200 | 101.813122ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  469 +2020/11/22 15:57:29.174 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606031849174719000
  470 + Auth=
  471 + BodyData:{
  472 + "companyId": 358,
  473 + "uid": 3259769336174592,
  474 + "rankingType": 1,
  475 + "offset": 0,
  476 + "limit": 20
  477 +}
  478 +2020/11/22 15:57:29.242 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606031849174719000 BodyData:{"code":0,"data":{"currentEmployeeContributions":null,"currentEmployeeWealth":null,"employeesContributions":null,"employeesWealth":null},"msg":"ok"}
  479 +2020/11/22 15:57:29.242 [D] [server.go:1925] | 127.0.0.1| 200 | 67.591516ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
@@ -2147,6 +2147,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -2147,6 +2147,16 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
2147 cashPoolRepository = value 2147 cashPoolRepository = value
2148 } 2148 }
2149 2149
  2150 + // 员工仓储初始化
  2151 + var employeeRepository domain.EmployeeRepository
  2152 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  2153 + "transactionContext": transactionContext,
  2154 + }); err != nil {
  2155 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  2156 + } else {
  2157 + employeeRepository = value
  2158 + }
  2159 +
2150 // 员工DAO初始化 2160 // 员工DAO初始化
2151 var employeeDao *dao.EmployeeDao 2161 var employeeDao *dao.EmployeeDao
2152 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 2162 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
@@ -2168,7 +2178,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -2168,7 +2178,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
2168 } 2178 }
2169 2179
2170 // 获取待删除兑换清单人员 2180 // 获取待删除兑换清单人员
2171 - personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId}) 2181 + personFound, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{
  2182 + "listId": removeExchangeCashPersonCommand.ListId,
  2183 + })
2172 if err != nil { 2184 if err != nil {
2173 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2185 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
2174 } 2186 }
@@ -2189,6 +2201,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -2189,6 +2201,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
2189 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId))) 2201 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
2190 } 2202 }
2191 2203
  2204 + // 判断当前人员状态
  2205 + getEmployee := map[string]interface{}{
  2206 + "uid": personFound.EmployeeInfo.Uid,
  2207 + "companyId": activityFound.CompanyId,
  2208 + "status": 1,
  2209 + }
  2210 +
  2211 + // 判断当前员工是否有效
  2212 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  2213 + if err != nil {
  2214 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  2215 + }
  2216 + if employeeFound == nil {
  2217 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  2218 + }
  2219 +
2192 // 更新兑换素币活动命令 2220 // 更新兑换素币活动命令
2193 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 2221 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
2194 ExchangeCashActivityId: personFound.ExchangeCashActivityId, 2222 ExchangeCashActivityId: personFound.ExchangeCashActivityId,
@@ -89,10 +89,11 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string @@ -89,10 +89,11 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
89 }, nil 89 }, nil
90 } 90 }
91 91
92 -// 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金 92 +// 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金 TODO
93 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { 93 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
94 var incomeSuMoney float64 94 var incomeSuMoney float64
95 var incomeSuMoneyOfYesterday float64 95 var incomeSuMoneyOfYesterday float64
  96 + var expendSuMoneyOfYesterday float64
96 tx := dao.transactionContext.PgTx 97 tx := dao.transactionContext.PgTx
97 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 98 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
98 yesterday := time.Now().Local().AddDate(0, 0, -1) 99 yesterday := time.Now().Local().AddDate(0, 0, -1)
@@ -100,12 +101,21 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -100,12 +101,21 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
100 if err := tx.Model(suMoneyTransactionRecordModel). 101 if err := tx.Model(suMoneyTransactionRecordModel).
101 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 102 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
102 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 103 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
103 - Where(`su_money_transaction_record.record_type = ?`, 2). 104 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
104 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, time.Local)). 105 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, time.Local)).
105 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, time.Local)). 106 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, time.Local)).
106 Select(&incomeSuMoneyOfYesterday); err != nil { 107 Select(&incomeSuMoneyOfYesterday); err != nil {
107 return nil, err 108 return nil, err
108 } 109 }
  110 + if err := tx.Model(suMoneyTransactionRecordModel).
  111 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  112 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  113 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
  114 + Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, time.Local)).
  115 + Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, time.Local)).
  116 + Select(&expendSuMoneyOfYesterday); err != nil {
  117 + return nil, err
  118 + }
109 // 收益 119 // 收益
110 if err := tx.Model(suMoneyTransactionRecordModel). 120 if err := tx.Model(suMoneyTransactionRecordModel).
111 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 121 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").