作者 陈志颖

fix:上期活动汇率

... ... @@ -64,3 +64,70 @@
BodyData:{}
2020/11/23 10:12:18.010 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20&isEnd=true.1606097537866014000 BodyData:{"code":0,"data":{"activities":[],"count":4},"msg":"ok"}
2020/11/23 10:12:18.010 [D] [server.go:1925] | 127.0.0.1| 200 | 144.184217ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 10:55:12.835 [I] [???:0] http server Running on http://:8082
2020/11/23 10:56:32.995 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100192992875000
Auth=
BodyData:{}
2020/11/23 10:56:33.201 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=358.1606100192992875000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":800,"companyId":358,"exchangedCash":4,"unExchangeCash":796,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":2,"createTime":"2020-11-17T11:02:21.013016+08:00"},"msg":"ok"}
2020/11/23 10:56:33.201 [D] [server.go:1925] | 127.0.0.1| 200 | 208.607749ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
2020/11/23 10:56:54.279 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100214279428000
Auth=
BodyData:{
"companyId": 358,
"cash": 2000
}
2020/11/23 10:56:54.426 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/input.1606100214279428000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2000,"companyId":358,"exchangedCash":4,"unExchangeCash":1996,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":2,"createTime":"2020-11-23T10:56:54.414718+08:00"},"msg":"ok"}
2020/11/23 10:56:54.426 [D] [server.go:1925] | 127.0.0.1| 200 | 147.217724ms| match| POST  /cash-pool/input r:/cash-pool/input
2020/11/23 11:00:29.717 [I] [???:0] http server Running on http://:8082
2020/11/23 11:00:45.293 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=false.1606100445292941000
Auth=
BodyData:{}
2020/11/23 11:00:45.654 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=false.1606100445292941000 BodyData:{"code":0,"data":{"activities":[{"activityId":41,"companyId":358,"countDown":7,"createTime":"2020-11-17T13:21:41.997891+08:00","deadline":1606665599001,"exchangeActivityName":"12","exchangedCash":0,"exchangedSuMoney":0,"rate":3}],"count":1},"msg":"ok"}
2020/11/23 11:00:45.654 [D] [server.go:1925] | 127.0.0.1| 200 | 361.818394ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 11:00:51.855 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20.1606100451855818000
Auth=
BodyData:{}
2020/11/23 11:00:51.883 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20.1606100451855818000 BodyData:{"code":0,"data":{"activities":[{"activityId":41,"companyId":358,"countDown":7,"createTime":"2020-11-17T13:21:41.997891+08:00","deadline":1606665599001,"exchangeActivityName":"12","exchangedCash":0,"exchangedSuMoney":0,"rate":3}],"count":1},"msg":"ok"}
2020/11/23 11:00:51.883 [D] [server.go:1925] | 127.0.0.1| 200 | 28.004377ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 11:01:00.011 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=true.1606100460011882000
Auth=
BodyData:{}
2020/11/23 11:01:00.120 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=true.1606100460011882000 BodyData:{"code":0,"data":{"activities":[],"count":3},"msg":"ok"}
2020/11/23 11:01:00.120 [D] [server.go:1925] | 127.0.0.1| 200 | 108.248877ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 11:01:05.464 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=false.1606100465463956000
Auth=
BodyData:{}
2020/11/23 11:01:05.530 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=358&offset=0&limit=20&isEnd=false.1606100465463956000 BodyData:{"code":0,"data":{"activities":[{"activityId":41,"companyId":358,"countDown":7,"createTime":"2020-11-17T13:21:41.997891+08:00","deadline":1606665599001,"exchangeActivityName":"12","exchangedCash":0,"exchangedSuMoney":0,"rate":3}],"count":1},"msg":"ok"}
2020/11/23 11:01:05.530 [D] [server.go:1925] | 127.0.0.1| 200 | 66.870162ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 11:01:11.482 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20&isEnd=false.1606100471482029000
Auth=
BodyData:{}
2020/11/23 11:01:11.718 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20&isEnd=false.1606100471482029000 BodyData:{"code":0,"data":{"activities":[{"activityId":81,"companyId":311,"countDown":1,"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":5,"createTime":"2020-11-22T04:57:40.071587+08:00","deadline":1606491456734,"exchangeActivityName":"这是更新后的公司10019的兑换活动,哈哈哈","exchangedCash":0,"exchangedSuMoney":0,"rate":100},{"activityId":82,"companyId":311,"countDown":5,"createTime":"2020-11-21T21:38:37.791621+08:00","deadline":1606492799000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":15,"exchangedSuMoney":3,"rate":5},{"activityId":84,"companyId":311,"countDown":6,"createTime":"2020-11-22T21:04:10.635284+08:00","deadline":1606579199000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":85,"companyId":311,"
2020/11/23 11:01:11.719 [D] [server.go:1925] | 127.0.0.1| 200 | 237.434699ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
2020/11/23 11:01:41.895 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100501895710000
Auth=
BodyData:{}
2020/11/23 11:01:42.078 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=358.1606100501895710000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2000,"companyId":358,"exchangedCash":4,"unExchangeCash":1996,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":2,"createTime":"2020-11-17T11:02:21.013016+08:00"},"msg":"ok"}
2020/11/23 11:01:42.079 [D] [server.go:1925] | 127.0.0.1| 200 | 183.376374ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
2020/11/23 11:01:48.118 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100508118806000
Auth=
BodyData:{
"companyId": 358,
"cash": 2001
}
2020/11/23 11:01:48.208 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/input.1606100508118806000 BodyData:{"code":501,"msg":"内部服务出错:pg: no rows in result set"}
2020/11/23 11:01:48.208 [D] [server.go:1925] | 127.0.0.1| 200 | 90.202556ms| match| POST  /cash-pool/input r:/cash-pool/input
2020/11/23 11:05:35.034 [I] [???:0] http server Running on http://:8082
2020/11/23 11:05:38.359 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100738359708000
Auth=
BodyData:{
"companyId": 358,
"cash": 2001
}
2020/11/23 11:05:38.629 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/input.1606100738359708000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2001,"companyId":358,"exchangedCash":4,"unExchangeCash":1997,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":2,"createTime":"2020-11-23T11:05:38.625629+08:00"},"msg":"ok"}
2020/11/23 11:05:38.629 [D] [server.go:1925] | 127.0.0.1| 200 | 269.677869ms| match| POST  /cash-pool/input r:/cash-pool/input
2020/11/23 11:06:28.340 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100788340467000
Auth=
BodyData:{}
2020/11/23 11:06:28.378 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=358.1606100788340467000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2001,"companyId":358,"exchangedCash":4,"unExchangeCash":1997,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":0,"createTime":"2020-11-17T11:02:21.013016+08:00"},"msg":"ok"}
2020/11/23 11:06:28.378 [D] [server.go:1925] | 127.0.0.1| 200 | 38.134513ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
... ...
... ... @@ -140,12 +140,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
var lastActivityRate float64
listExchangeCashActivityQuery := map[string]interface{}{
"companyId": createCashPoolCommand.CompanyId,
"order": "deadline DESC",
"offset": 1,
"limit": 1,
}
if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 1 {
lastActivityRate = activities[1].Rate
lastActivityRate = activities[0].Rate
} else { // 未查询到相关兑换活动
lastActivityRate = 0
}
... ... @@ -164,6 +167,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
LastRate: lastActivityRate,
CreateTime: time.Now().Local(),
}
// 保存现金池更新
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -252,12 +256,15 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
var lastActivityRate float64
listExchangeCashActivityQuery := map[string]interface{}{
"companyId": getCashPoolQuery.CompanyId,
"order": "deadline DESC",
"offset": 1,
"limit": 1,
}
if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 1 {
lastActivityRate = activities[1].Rate
lastActivityRate = activities[0].Rate
} else { // 未查询到相关兑换活动
lastActivityRate = 0
}
... ...
... ... @@ -17,16 +17,16 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C
fmt.Print(cashPool.Identity(), "\n")
if cashPool.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.CreateTime),
"INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, create_time",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.CreateTime); err != nil {
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate, &cashPool.CreateTime),
"INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate, create_time",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CreateTime); err != nil {
return cashPool, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate),
"UPDATE cash_pools SET cash=?, company_id=?, exchanged_cash=?, un_exchange_cash=?, exchanged_su_money=?, un_exchange_su_money=?, rate=? WHERE id=? RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.CashPoolId, cashPool.Identity()); err != nil {
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate),
"UPDATE cash_pools SET cash=?, company_id=?, exchanged_cash=?, un_exchange_cash=?, exchanged_su_money=?, un_exchange_su_money=?, rate=?, last_rate=? WHERE id=? RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, last_rate",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CashPoolId, cashPool.Identity()); err != nil {
return cashPool, err
}
}
... ...
... ... @@ -121,6 +121,20 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
} else {
query = query.Limit(20)
}
if order, ok := queryOptions["order"]; ok && order.(string) != "" {
if count, err := query.OrderExpr("deadline 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
}
}
if count, err := query.OrderExpr("deadline ASC").SelectAndCount(); err != nil {
return 0, exchangeCashActivities, err
} else {
... ...