作者 陈志颖

fix:上期活动汇率

@@ -64,3 +64,70 @@ @@ -64,3 +64,70 @@
64 BodyData:{} 64 BodyData:{}
65 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"} 65 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"}
66 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/ 66 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/
  67 +2020/11/23 10:55:12.835 [I] [???:0] http server Running on http://:8082
  68 +2020/11/23 10:56:32.995 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100192992875000
  69 + Auth=
  70 + BodyData:{}
  71 +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"}
  72 +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
  73 +2020/11/23 10:56:54.279 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100214279428000
  74 + Auth=
  75 + BodyData:{
  76 + "companyId": 358,
  77 + "cash": 2000
  78 +}
  79 +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"}
  80 +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
  81 +2020/11/23 11:00:29.717 [I] [???:0] http server Running on http://:8082
  82 +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
  83 + Auth=
  84 + BodyData:{}
  85 +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"}
  86 +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/
  87 +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
  88 + Auth=
  89 + BodyData:{}
  90 +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"}
  91 +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/
  92 +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
  93 + Auth=
  94 + BodyData:{}
  95 +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"}
  96 +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/
  97 +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
  98 + Auth=
  99 + BodyData:{}
  100 +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"}
  101 +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/
  102 +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
  103 + Auth=
  104 + BodyData:{}
  105 +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,"
  106 +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/
  107 +2020/11/23 11:01:41.895 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100501895710000
  108 + Auth=
  109 + BodyData:{}
  110 +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"}
  111 +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
  112 +2020/11/23 11:01:48.118 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100508118806000
  113 + Auth=
  114 + BodyData:{
  115 + "companyId": 358,
  116 + "cash": 2001
  117 +}
  118 +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"}
  119 +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
  120 +2020/11/23 11:05:35.034 [I] [???:0] http server Running on http://:8082
  121 +2020/11/23 11:05:38.359 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/input.1606100738359708000
  122 + Auth=
  123 + BodyData:{
  124 + "companyId": 358,
  125 + "cash": 2001
  126 +}
  127 +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"}
  128 +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
  129 +2020/11/23 11:06:28.340 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=358.1606100788340467000
  130 + Auth=
  131 + BodyData:{}
  132 +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"}
  133 +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 @@ -140,12 +140,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
140 var lastActivityRate float64 140 var lastActivityRate float64
141 listExchangeCashActivityQuery := map[string]interface{}{ 141 listExchangeCashActivityQuery := map[string]interface{}{
142 "companyId": createCashPoolCommand.CompanyId, 142 "companyId": createCashPoolCommand.CompanyId,
  143 + "order": "deadline DESC",
  144 + "offset": 1,
  145 + "limit": 1,
143 } 146 }
144 if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil { 147 if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
145 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 148 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
146 } else { 149 } else {
147 if count > 1 { 150 if count > 1 {
148 - lastActivityRate = activities[1].Rate 151 + lastActivityRate = activities[0].Rate
149 } else { // 未查询到相关兑换活动 152 } else { // 未查询到相关兑换活动
150 lastActivityRate = 0 153 lastActivityRate = 0
151 } 154 }
@@ -164,6 +167,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -164,6 +167,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
164 LastRate: lastActivityRate, 167 LastRate: lastActivityRate,
165 CreateTime: time.Now().Local(), 168 CreateTime: time.Now().Local(),
166 } 169 }
  170 +
167 // 保存现金池更新 171 // 保存现金池更新
168 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { 172 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 173 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -252,12 +256,15 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -252,12 +256,15 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
252 var lastActivityRate float64 256 var lastActivityRate float64
253 listExchangeCashActivityQuery := map[string]interface{}{ 257 listExchangeCashActivityQuery := map[string]interface{}{
254 "companyId": getCashPoolQuery.CompanyId, 258 "companyId": getCashPoolQuery.CompanyId,
  259 + "order": "deadline DESC",
  260 + "offset": 1,
  261 + "limit": 1,
255 } 262 }
256 if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil { 263 if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
257 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 264 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
258 } else { 265 } else {
259 if count > 1 { 266 if count > 1 {
260 - lastActivityRate = activities[1].Rate 267 + lastActivityRate = activities[0].Rate
261 } else { // 未查询到相关兑换活动 268 } else { // 未查询到相关兑换活动
262 lastActivityRate = 0 269 lastActivityRate = 0
263 } 270 }
@@ -17,16 +17,16 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C @@ -17,16 +17,16 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C
17 fmt.Print(cashPool.Identity(), "\n") 17 fmt.Print(cashPool.Identity(), "\n")
18 if cashPool.Identity() == nil { 18 if cashPool.Identity() == nil {
19 if _, err := tx.QueryOne( 19 if _, err := tx.QueryOne(
20 - pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.CreateTime),  
21 - "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",  
22 - cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.CreateTime); err != nil { 20 + pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate, &cashPool.CreateTime),
  21 + "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",
  22 + cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CreateTime); err != nil {
23 return cashPool, err 23 return cashPool, err
24 } 24 }
25 } else { 25 } else {
26 if _, err := tx.QueryOne( 26 if _, err := tx.QueryOne(
27 - pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate),  
28 - "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",  
29 - cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.CashPoolId, cashPool.Identity()); err != nil { 27 + pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.LastRate),
  28 + "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",
  29 + cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.LastRate, cashPool.CashPoolId, cashPool.Identity()); err != nil {
30 return cashPool, err 30 return cashPool, err
31 } 31 }
32 } 32 }
@@ -121,6 +121,20 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i @@ -121,6 +121,20 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
121 } else { 121 } else {
122 query = query.Limit(20) 122 query = query.Limit(20)
123 } 123 }
  124 + if order, ok := queryOptions["order"]; ok && order.(string) != "" {
  125 + if count, err := query.OrderExpr("deadline DESC").SelectAndCount(); err != nil {
  126 + return 0, exchangeCashActivities, err
  127 + } else {
  128 + for _, exchangeCashActivityModel := range exchangeCashActivityModels {
  129 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashActivityModel); err != nil {
  130 + return 0, exchangeCashActivities, err
  131 + } else {
  132 + exchangeCashActivities = append(exchangeCashActivities, taskNature)
  133 + }
  134 + }
  135 + return int64(count), exchangeCashActivities, nil
  136 + }
  137 + }
124 if count, err := query.OrderExpr("deadline ASC").SelectAndCount(); err != nil { 138 if count, err := query.OrderExpr("deadline ASC").SelectAndCount(); err != nil {
125 return 0, exchangeCashActivities, err 139 return 0, exchangeCashActivities, err
126 } else { 140 } else {