作者 陈志颖

test:测试接口,修复返回数据问题

正在显示 24 个修改的文件 包含 100 行增加129 行删除
@@ -8,15 +8,8 @@ import ( @@ -8,15 +8,8 @@ import (
8 8
9 // 创建现金池 9 // 创建现金池
10 type CreateCashPoolCommand struct { 10 type CreateCashPoolCommand struct {
11 - //Uid int64 `json:"uid"` // 统一用户id  
12 - //CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID  
13 CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID 11 CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
14 Cash float64 `json:"cash" valid:"Required"` // 投入的现金值 12 Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
15 - //ExchangedCash float64 `json:"exchangedCash,omitempty"` // 现金池已兑换现金值  
16 - //UnExchangeCash float64 `json:"unExchangeCash,omitempty"` // 现金池未兑换现金值  
17 - //ExchangedSuMoney float64 `json:"exchangedSuMoney,omitempty"` // 现金池已兑换素币值  
18 - //UnExchangeSuMoney float64 `json:"unExchangeSuMoney,omitempty"` // 现金池未兑换素币值  
19 - //Operator int64 `json:"operator,omitempty"` // 操作人UID  
20 } 13 }
21 14
22 func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error { 15 func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error {
@@ -10,14 +10,9 @@ import ( @@ -10,14 +10,9 @@ import (
10 type CreateExchangeCashActivityCommand struct { 10 type CreateExchangeCashActivityCommand struct {
11 CompanyId int64 `json:"companyId" valid:"Required"` // 公司id 11 CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
12 ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称 12 ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
13 - //CashPool *domain.CashPool `json:"cashPool"` // 兑换现金活动关联的现金池,最新的现金池  
14 Deadline time.Time `json:"deadline"` // 活动截止时间 13 Deadline time.Time `json:"deadline"` // 活动截止时间
15 - CountDown int64 `json:"countDown"` // 活动倒计时  
16 - ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币  
17 - ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金  
18 ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率 14 ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
19 CreateTime time.Time `json:"createTime"` // 创建时间 15 CreateTime time.Time `json:"createTime"` // 创建时间
20 - //ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeList"` // 兑换活动清单  
21 } 16 }
22 17
23 func (createExchangeActivityCommand *CreateExchangeCashActivityCommand) ValidateCommand() error { 18 func (createExchangeActivityCommand *CreateExchangeCashActivityCommand) ValidateCommand() error {
@@ -6,12 +6,10 @@ import ( @@ -6,12 +6,10 @@ import (
6 ) 6 )
7 7
8 type CreateExchangeCashPersonCommand struct { 8 type CreateExchangeCashPersonCommand struct {
9 - PersonId int64 `json:"personId" valid:"Required"` // 兑换现金人员uid  
10 PersonName string `json:"personName,omitempty"` // 兑换现金人员名称 9 PersonName string `json:"personName,omitempty"` // 兑换现金人员名称
11 PersonAccount string `json:"personAccount,omitempty"` // 手机账号 10 PersonAccount string `json:"personAccount,omitempty"` // 手机账号
12 ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id 11 ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
13 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值 12 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
14 - //ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金值  
15 } 13 }
16 14
17 func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error { 15 func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
@@ -2,12 +2,13 @@ package command @@ -2,12 +2,13 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 +
5 "github.com/astaxie/beego/validation" 6 "github.com/astaxie/beego/validation"
6 ) 7 )
7 8
8 // 删除兑换现金活动 9 // 删除兑换现金活动
9 type RemoveExchangeCashActivityCommand struct { 10 type RemoveExchangeCashActivityCommand struct {
10 - ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` 11 + ActivityId int64 `json:"activityId" valid:"Required"`
11 } 12 }
12 13
13 func (removeExchangeCashActivityCommand *RemoveExchangeCashActivityCommand) ValidateCommand() error { 14 func (removeExchangeCashActivityCommand *RemoveExchangeCashActivityCommand) ValidateCommand() error {
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 7
8 // 移除兑换现金人员 8 // 移除兑换现金人员
9 type RemoveExchangeCashPersonCommand struct { 9 type RemoveExchangeCashPersonCommand struct {
10 - ExchangeCashPersonId int64 `json:"exchangeCashId" valid:"Required"` // 兑换现金人员编号 10 + ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
11 } 11 }
12 12
13 func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error { 13 func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type SearchExchangeCashActivityCommand struct { 8 type SearchExchangeCashActivityCommand struct {
9 - ExchangeCashActivityName string `json:"exchangeCashActivityName"` // 兑换现金活动名称 9 + ActivityName string `json:"activityName"` // 兑换现金活动名称
10 } 10 }
11 11
12 func (searchExchangeCashActivityCommand *SearchExchangeCashActivityCommand) ValidateCommand() error { 12 func (searchExchangeCashActivityCommand *SearchExchangeCashActivityCommand) ValidateCommand() error {
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type SearchExchangeCashPersonCommand struct { 8 type SearchExchangeCashPersonCommand struct {
9 - ExchangeCashPersonName string `json:"exchangeCashPersonName"` // 兑换素币人员名称 9 + ListName string `json:"listName"` // 兑换素币人员名称
10 } 10 }
11 11
12 func (searchExchangeCashPersonCommand *SearchExchangeCashPersonCommand) ValidateCommand() error { 12 func (searchExchangeCashPersonCommand *SearchExchangeCashPersonCommand) ValidateCommand() error {
@@ -8,14 +8,12 @@ import ( @@ -8,14 +8,12 @@ import (
8 8
9 type UpdateExchangeCashActivityCommand struct { 9 type UpdateExchangeCashActivityCommand struct {
10 ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id 10 ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
11 - //CompanyId int64 `json:"companyId" valid:"Required"` // 公司id  
12 ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称 11 ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
13 Deadline time.Time `json:"deadline"` // 活动截止时间 12 Deadline time.Time `json:"deadline"` // 活动截止时间
14 CountDown int64 `json:"countDown"` // 活动倒计时 13 CountDown int64 `json:"countDown"` // 活动倒计时
15 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币 14 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
16 ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金 15 ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
17 ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率 16 ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
18 - //ExchangeCashPeople []*domain.ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换活动清单  
19 } 17 }
20 18
21 func (updateExchangeCashActivity *UpdateExchangeCashActivityCommand) ValidateCommand() error { 19 func (updateExchangeCashActivity *UpdateExchangeCashActivityCommand) ValidateCommand() error {
@@ -6,9 +6,8 @@ import ( @@ -6,9 +6,8 @@ import (
6 ) 6 )
7 7
8 type UpdateExchangeCashPersonCommand struct { 8 type UpdateExchangeCashPersonCommand struct {
9 - ExchangeCashPersonId int64 `json:"exchangeCashPersonId" valid:"Required"` // 兑换现金人员编号 9 + ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
10 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录) 10 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
11 - ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金  
12 } 11 }
13 12
14 func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error { 13 func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
@@ -2,7 +2,9 @@ package service @@ -2,7 +2,9 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/astaxie/beego"
5 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "strconv"
6 "time" 8 "time"
7 9
8 "github.com/linmadan/egglib-go/core/application" 10 "github.com/linmadan/egglib-go/core/application"
@@ -17,14 +19,11 @@ import ( @@ -17,14 +19,11 @@ import (
17 type CashPoolService struct { 19 type CashPoolService struct {
18 } 20 }
19 21
20 -// 投入现金池 22 +// 新增现金池
21 func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) { 23 func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
22 - // 校验命令  
23 if err := createCashPoolCommand.ValidateCommand(); err != nil { 24 if err := createCashPoolCommand.ValidateCommand(); err != nil {
24 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 25 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
25 } 26 }
26 -  
27 - // 新建现金池事务  
28 transactionContext, err := factory.CreateTransactionContext(nil) 27 transactionContext, err := factory.CreateTransactionContext(nil)
29 if err != nil { 28 if err != nil {
30 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 29 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -35,8 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -35,8 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
35 defer func() { 34 defer func() {
36 transactionContext.RollbackTransaction() 35 transactionContext.RollbackTransaction()
37 }() 36 }()
38 -  
39 - // 新建现金池数据访问对象  
40 var cashPoolDao *dao.CashPoolDao 37 var cashPoolDao *dao.CashPoolDao
41 if value, err := factory.CreateCashPoolDao(map[string]interface{}{ 38 if value, err := factory.CreateCashPoolDao(map[string]interface{}{
42 "transactionContext": transactionContext, 39 "transactionContext": transactionContext,
@@ -45,16 +42,12 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -45,16 +42,12 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
45 } else { 42 } else {
46 cashPoolDao = value 43 cashPoolDao = value
47 } 44 }
48 -  
49 - // 获取系统已兑换现金值  
50 var systemExchangedCash float64 45 var systemExchangedCash float64
51 if value, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil { 46 if value, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 47 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
53 } else { 48 } else {
54 systemExchangedCash = value 49 systemExchangedCash = value
55 } 50 }
56 -  
57 - // 获取系统素币兑换情况  
58 var ( 51 var (
59 systemChangedSuMoney float64 52 systemChangedSuMoney float64
60 systemUnChangeSuMoney float64 53 systemUnChangeSuMoney float64
@@ -66,16 +59,18 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -66,16 +59,18 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
66 systemUnChangeSuMoney = value2 59 systemUnChangeSuMoney = value2
67 } 60 }
68 61
69 - fmt.Print("1234567", createCashPoolCommand) 62 + // TODO 获取上一个现金池现金值
  63 +
  64 + rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64)
70 65
71 newCashPool := &domain.CashPool{ 66 newCashPool := &domain.CashPool{
72 CompanyId: createCashPoolCommand.CompanyId, 67 CompanyId: createCashPoolCommand.CompanyId,
73 Cash: createCashPoolCommand.Cash, 68 Cash: createCashPoolCommand.Cash,
74 ExchangedCash: systemExchangedCash, 69 ExchangedCash: systemExchangedCash,
75 - UnExchangeCash: 0, 70 + UnExchangeCash: createCashPoolCommand.Cash, // TODO 投入的现金 + 系统未兑换的现金
76 ExchangedSuMoney: systemChangedSuMoney, 71 ExchangedSuMoney: systemChangedSuMoney,
77 UnExchangeSuMoney: systemUnChangeSuMoney, 72 UnExchangeSuMoney: systemUnChangeSuMoney,
78 - Rate: 0, 73 + Rate: rate,
79 CreateTime: time.Now(), 74 CreateTime: time.Now(),
80 } 75 }
81 76
@@ -88,7 +83,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -88,7 +83,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
88 cashPoolRepository = value 83 cashPoolRepository = value
89 } 84 }
90 85
91 - // 每个公司一个现金池  
92 if activity, err := cashPoolRepository.Save(newCashPool); err != nil { 86 if activity, err := cashPoolRepository.Save(newCashPool); err != nil {
93 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 87 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
94 } else { 88 } else {
@@ -104,8 +98,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -104,8 +98,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
104 if err := getCashPoolQuery.ValidateQuery(); err != nil { 98 if err := getCashPoolQuery.ValidateQuery(); err != nil {
105 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 99 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
106 } 100 }
107 -  
108 - // 新建事务  
109 transactionContext, err := factory.CreateTransactionContext(nil) 101 transactionContext, err := factory.CreateTransactionContext(nil)
110 if err != nil { 102 if err != nil {
111 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 103 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -116,8 +108,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -116,8 +108,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
116 defer func() { 108 defer func() {
117 transactionContext.RollbackTransaction() 109 transactionContext.RollbackTransaction()
118 }() 110 }()
119 -  
120 - // 现金池资源库  
121 var cashPoolRepository domain.CashPoolRepository 111 var cashPoolRepository domain.CashPoolRepository
122 if value, err := factory.CreateCashPoolRepository(map[string]interface{}{ 112 if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
123 "transactionContext": transactionContext, 113 "transactionContext": transactionContext,
@@ -162,11 +152,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -162,11 +152,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
162 newActivity := &domain.ExchangeCashActivity{ 152 newActivity := &domain.ExchangeCashActivity{
163 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName, 153 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
164 CompanyId: createExchangeCashActivityCommand.CompanyId, 154 CompanyId: createExchangeCashActivityCommand.CompanyId,
165 - ExchangedCash: createExchangeCashActivityCommand.ExchangedCash,  
166 - ExchangedSuMoney: createExchangeCashActivityCommand.ExchangedSuMoney, 155 + ExchangedCash: 0,
  156 + ExchangedSuMoney: 0,
167 Deadline: createExchangeCashActivityCommand.Deadline, 157 Deadline: createExchangeCashActivityCommand.Deadline,
168 - CountDown: createExchangeCashActivityCommand.CountDown, 158 + CountDown: 0,
169 Rate: createExchangeCashActivityCommand.ExchangeRate, 159 Rate: createExchangeCashActivityCommand.ExchangeRate,
  160 + CreateTime: time.Now(),
170 } 161 }
171 162
172 // 兑换活动资源库 163 // 兑换活动资源库
@@ -254,12 +245,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang @@ -254,12 +245,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang
254 exchangeCashActivityRepository = value 245 exchangeCashActivityRepository = value
255 } 246 }
256 247
257 - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ExchangeCashActivityId}) 248 + activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
258 if err != nil { 249 if err != nil {
259 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 250 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
260 } 251 }
261 if activity == nil { 252 if activity == nil {
262 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ExchangeCashActivityId))) 253 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
263 } 254 }
264 255
265 if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil { 256 if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
@@ -359,6 +350,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -359,6 +350,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
359 if err := transactionContext.CommitTransaction(); err != nil { 350 if err := transactionContext.CommitTransaction(); err != nil {
360 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 351 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
361 } 352 }
  353 + // TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
  354 +
362 return activityUpdated, nil 355 return activityUpdated, nil
363 } 356 }
364 } 357 }
@@ -380,18 +373,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -380,18 +373,27 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
380 transactionContext.RollbackTransaction() 373 transactionContext.RollbackTransaction()
381 }() 374 }()
382 375
  376 + // TODO 需要判断新增兑换现金人员的素币值是否合理(人员参与兑换的素币不得超过该人员还未兑换的素币总值)
  377 +
  378 + // TODO 判断活动的汇率是否为空,为空则不允许新建,提示:请设置汇率
  379 +
  380 + // TODO 获取参与的兑换活动的汇率,计算已兑换的现金值
  381 +
  382 + // TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
  383 +
  384 + // TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
  385 +
383 // 创建兑换清单 386 // 创建兑换清单
384 newPerson := &domain.ExchangeCashPersonList{ 387 newPerson := &domain.ExchangeCashPersonList{
385 EmployeeInfo: &domain.EmployeeInfo{ 388 EmployeeInfo: &domain.EmployeeInfo{
386 - Uid: createExchangeCashPersonCommand.PersonId,  
387 EmployeeName: createExchangeCashPersonCommand.PersonName, 389 EmployeeName: createExchangeCashPersonCommand.PersonName,
388 EmployeeAccount: createExchangeCashPersonCommand.PersonAccount, 390 EmployeeAccount: createExchangeCashPersonCommand.PersonAccount,
389 }, 391 },
390 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId, 392 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
391 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney, 393 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  394 +
392 } 395 }
393 396
394 - // 兑换活动资源库  
395 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 397 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
396 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 398 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
397 "transactionContext": transactionContext, 399 "transactionContext": transactionContext,
@@ -407,6 +409,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -407,6 +409,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
407 if err := transactionContext.CommitTransaction(); err != nil { 409 if err := transactionContext.CommitTransaction(); err != nil {
408 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 410 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
409 } 411 }
  412 + // TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
  413 +
410 return person, nil 414 return person, nil
411 } 415 }
412 } 416 }
@@ -455,7 +459,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -455,7 +459,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
455 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { 459 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil {
456 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 460 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
457 } 461 }
458 -  
459 transactionContext, err := factory.CreateTransactionContext(nil) 462 transactionContext, err := factory.CreateTransactionContext(nil)
460 if err != nil { 463 if err != nil {
461 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 464 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -466,7 +469,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -466,7 +469,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
466 defer func() { 469 defer func() {
467 transactionContext.RollbackTransaction() 470 transactionContext.RollbackTransaction()
468 }() 471 }()
469 -  
470 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 472 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
471 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 473 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
472 "transactionContext": transactionContext, 474 "transactionContext": transactionContext,
@@ -515,20 +517,24 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -515,20 +517,24 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
515 exchangeCashPersonListRepository = value 517 exchangeCashPersonListRepository = value
516 } 518 }
517 519
518 - person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": removeExchangeCashPersonCommand.ExchangeCashPersonId}) 520 + person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
519 if err != nil { 521 if err != nil {
520 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 522 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
521 } 523 }
522 if person == nil { 524 if person == nil {
523 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ExchangeCashPersonId))) 525 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
524 } 526 }
525 527
  528 + beego.Info(person)
  529 +
526 if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil { 530 if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
527 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 531 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
528 } else { 532 } else {
529 if err := transactionContext.CommitTransaction(); err != nil { 533 if err := transactionContext.CommitTransaction(); err != nil {
530 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 534 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
531 } 535 }
  536 + // TODO 个人素币值需要还原,理由:素币兑换现金调整
  537 +
532 return personDeleted, nil 538 return personDeleted, nil
533 } 539 }
534 } 540 }
@@ -538,7 +544,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -538,7 +544,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
538 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil { 544 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
539 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 545 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
540 } 546 }
541 -  
542 transactionContext, err := factory.CreateTransactionContext(nil) 547 transactionContext, err := factory.CreateTransactionContext(nil)
543 if err != nil { 548 if err != nil {
544 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 549 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -549,9 +554,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -549,9 +554,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
549 defer func() { 554 defer func() {
550 transactionContext.RollbackTransaction() 555 transactionContext.RollbackTransaction()
551 }() 556 }()
552 -  
553 - // TODO 新增流水记录  
554 -  
555 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 557 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
556 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 558 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
557 "transactionContext": transactionContext, 559 "transactionContext": transactionContext,
@@ -560,13 +562,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -560,13 +562,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
560 } else { 562 } else {
561 exchangeCashPersonListRepository = value 563 exchangeCashPersonListRepository = value
562 } 564 }
563 -  
564 - person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": updateExchangeCashPersonCommand.ExchangeCashPersonId}) 565 + person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
565 if err != nil { 566 if err != nil {
566 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 567 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
567 } 568 }
568 if person == nil { 569 if person == nil {
569 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ExchangeCashPersonId))) 570 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
570 } 571 }
571 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 572 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
572 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 573 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -577,6 +578,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -577,6 +578,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
577 if err := transactionContext.CommitTransaction(); err != nil { 578 if err := transactionContext.CommitTransaction(); err != nil {
578 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 579 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
579 } 580 }
  581 + // TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
  582 +
  583 + // TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率
  584 +
580 return personUpdated, nil 585 return personUpdated, nil
581 } 586 }
582 } 587 }
@@ -13,9 +13,6 @@ type ExchangeCashActivity struct { @@ -13,9 +13,6 @@ type ExchangeCashActivity struct {
13 Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间 13 Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间
14 CountDown int64 `json:"countDown"` // 兑换现金活动结束倒计时 14 CountDown int64 `json:"countDown"` // 兑换现金活动结束倒计时
15 Rate float64 `json:"rate"` // 兑换汇率 15 Rate float64 `json:"rate"` // 兑换汇率
16 - //LastRate float64 `json:"lastRate"` // 上期兑换汇率  
17 - //Operator *EmployeeInfo `json:"operator"` // 活动发布人  
18 - //ExchangeCashPeople []*ExchangeCashPersonList `json:"exchangeCashPeople"` // 兑换现金人员清单  
19 } 16 }
20 17
21 type ExchangeActivityRepository interface { 18 type ExchangeActivityRepository interface {
@@ -2,11 +2,8 @@ package domain @@ -2,11 +2,8 @@ package domain
2 2
3 // 参与兑换现金人员 3 // 参与兑换现金人员
4 type ExchangeCashPersonList struct { 4 type ExchangeCashPersonList struct {
5 - ExchangeCashPersonListId int64 `json:"exchangeCashPersonListId"` // 兑换人员ID  
6 - //CompanyId int64 `json:"companyId"` // 公司id  
7 - EmployeeInfo *EmployeeInfo `json:"employeeInfo"`  
8 - //PersonId int64 `json:"personId"` // 兑换人员uid  
9 - //ExchangeCashPersonName string `json:"exchangeCashPersonName"` // 兑换人员名称 5 + ListId int64 `json:"listId"` // 清单id
  6 + EmployeeInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人信息
10 ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 参与的兑换活动id 7 ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 参与的兑换活动id
11 ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币 8 ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
12 ExchangedCash float64 `json:"cash"` // 已兑换的现金 9 ExchangedCash float64 `json:"cash"` // 已兑换的现金
@@ -20,10 +17,10 @@ type ExchangeCashPersonListRepository interface { @@ -20,10 +17,10 @@ type ExchangeCashPersonListRepository interface {
20 } 17 }
21 18
22 func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { 19 func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
23 - if exchangeCashPersonList.ExchangeCashPersonListId == 0 { 20 + if exchangeCashPersonList.ListId == 0 {
24 return nil 21 return nil
25 } 22 }
26 - return exchangeCashPersonList.ExchangeCashPersonListId 23 + return exchangeCashPersonList.ListId
27 } 24 }
28 25
29 func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]interface{}) error { 26 func (exchangeCashPersonList *ExchangeCashPersonList) Update(data map[string]interface{}) error {
@@ -19,16 +19,16 @@ func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float @@ -19,16 +19,16 @@ func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float
19 19
20 employeeModel := new(models.Employee) 20 employeeModel := new(models.Employee)
21 if err := tx.Model(employeeModel). 21 if err := tx.Model(employeeModel).
22 - ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").  
23 - Where("employee.company_id = ?", companyId). 22 + ColumnExpr("sum(employees.su_money) AS system_unExchange_su_money").
  23 + Where("employees.company_id = ?", companyId).
24 Select(&systemUnExchangeSuMoney); err != nil { 24 Select(&systemUnExchangeSuMoney); err != nil {
25 return 0, 0, err 25 return 0, 0, err
26 } 26 }
27 27
28 exchangeCashActivityModel := new(models.ExchangeCashActivity) 28 exchangeCashActivityModel := new(models.ExchangeCashActivity)
29 if err := tx.Model(exchangeCashActivityModel). 29 if err := tx.Model(exchangeCashActivityModel).
30 - ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").  
31 - Where("exchange_cash_activity.company_id = ?", companyId). 30 + ColumnExpr("sum(exchange_cash_activities.exchanged_su_money) AS system_changed_su_money").
  31 + Where("exchange_cash_activities.company_id = ?", companyId).
32 Select(&systemExchangedSuMoney); err != nil { 32 Select(&systemExchangedSuMoney); err != nil {
33 return 0, 0, err 33 return 0, 0, err
34 } 34 }
@@ -44,8 +44,8 @@ func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) { @@ -44,8 +44,8 @@ func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {
44 exchangeCashActivityModel := new(models.ExchangeCashActivity) 44 exchangeCashActivityModel := new(models.ExchangeCashActivity)
45 45
46 if err := tx.Model(exchangeCashActivityModel). 46 if err := tx.Model(exchangeCashActivityModel).
47 - ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").  
48 - Where("exchange_cash_activity.company_id = ?", companyId). 47 + ColumnExpr("sum(exchange_cash_activities.exchanged_cash) AS system_exchanged_cash").
  48 + Where("exchange_cash_activities.company_id = ?", companyId).
49 Select(&systemExchangedCash) ; err != nil { 49 Select(&systemExchangedCash) ; err != nil {
50 return 0, err 50 return 0, err
51 } 51 }
1 package models 1 package models
2 2
  3 +import "time"
  4 +
3 type CashPool struct { 5 type CashPool struct {
4 TableName string `pg:"cash_pools,alias:cash_pool"` 6 TableName string `pg:"cash_pools,alias:cash_pool"`
5 Id int64 `pg:",pk"` // 现金池id 7 Id int64 `pg:",pk"` // 现金池id
@@ -10,4 +12,5 @@ type CashPool struct { @@ -10,4 +12,5 @@ type CashPool struct {
10 ExchangedSuMoney float64 // 系统已兑换素币 12 ExchangedSuMoney float64 // 系统已兑换素币
11 UnExchangeSuMoney float64 // 系统未兑换素币 13 UnExchangeSuMoney float64 // 系统未兑换素币
12 Rate float64 // 兑换汇率 14 Rate float64 // 兑换汇率
  15 + CreateTime time.Time
13 } 16 }
@@ -39,7 +39,7 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin @@ -39,7 +39,7 @@ func (repository *ExchangeCashActivityRepository) FindOne(queryOptions map[strin
39 exchangeCashActivityModel := new(models.ExchangeCashActivity) 39 exchangeCashActivityModel := new(models.ExchangeCashActivity)
40 query := tx.Model(exchangeCashActivityModel) 40 query := tx.Model(exchangeCashActivityModel)
41 if exchangeCashActivityId, ok := queryOptions["exchangeCashActivityId"]; ok { 41 if exchangeCashActivityId, ok := queryOptions["exchangeCashActivityId"]; ok {
42 - query = query.Where("exchange_cash_list.id = ?", exchangeCashActivityId) 42 + query = query.Where("exchange_cash_activities.id = ?", exchangeCashActivityId)
43 } 43 }
44 if err := query.First(); err != nil { 44 if err := query.First(); err != nil {
45 if err.Error() == "pg: no rows in result set" { 45 if err.Error() == "pg: no rows in result set" {
@@ -123,9 +123,6 @@ func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel( @@ -123,9 +123,6 @@ func (repository *ExchangeCashActivityRepository) transformPgModelToDomainModel(
123 Deadline: exchangeCashActivity.Deadline, 123 Deadline: exchangeCashActivity.Deadline,
124 CountDown: exchangeCashActivity.CountDown, 124 CountDown: exchangeCashActivity.CountDown,
125 Rate: exchangeCashActivity.ExchangeRate, 125 Rate: exchangeCashActivity.ExchangeRate,
126 - //LastRate: exchangeCashActivity.LastExchangeRate,  
127 - //Operator: exchangeCashActivity.Sponsor,  
128 - //ExchangeCashPeople: exchangeCashActivity.ExchangeSuMoneyList,  
129 }, nil 126 }, nil
130 } 127 }
131 func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashActivityRepository, error) { 128 func NewExchangeCashActivityRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashActivityRepository, error) {
@@ -17,16 +17,16 @@ func (repository *ExchangeCashPersonListRepository) Save(exchangeCashList *domai @@ -17,16 +17,16 @@ func (repository *ExchangeCashPersonListRepository) Save(exchangeCashList *domai
17 tx := repository.transactionContext.PgTx 17 tx := repository.transactionContext.PgTx
18 if exchangeCashList.Identity() == nil { 18 if exchangeCashList.Identity() == nil {
19 if _, err := tx.QueryOne( 19 if _, err := tx.QueryOne(
20 - pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash), 20 + pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
21 "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash", 21 "INSERT INTO exchange_cash_person_lists (activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
22 exchangeCashList.ExchangeCashActivityId, exchangeCashList.EmployeeInfo.Uid, exchangeCashList.EmployeeInfo.EmployeeName, exchangeCashList.EmployeeInfo.EmployeeAccount, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil { 22 exchangeCashList.ExchangeCashActivityId, exchangeCashList.EmployeeInfo.Uid, exchangeCashList.EmployeeInfo.EmployeeName, exchangeCashList.EmployeeInfo.EmployeeAccount, exchangeCashList.ExchangedSuMoney, exchangeCashList.ExchangedCash); err != nil {
23 return exchangeCashList, err 23 return exchangeCashList, err
24 } 24 }
25 } else { 25 } else {
26 if _, err := tx.QueryOne( 26 if _, err := tx.QueryOne(
27 - pg.Scan(&exchangeCashList.ExchangeCashPersonListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),  
28 - "UPDATE exchange_cash_person_lists SET exchanged_su_money=? WHERE uid=? RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",  
29 - exchangeCashList.ExchangedSuMoney, exchangeCashList.EmployeeInfo.Uid); err != nil { 27 + pg.Scan(&exchangeCashList.ListId, &exchangeCashList.ExchangeCashActivityId, &exchangeCashList.EmployeeInfo.Uid, &exchangeCashList.EmployeeInfo.EmployeeName, &exchangeCashList.EmployeeInfo.EmployeeAccount, &exchangeCashList.ExchangedSuMoney, &exchangeCashList.ExchangedCash),
  28 + "UPDATE exchange_cash_person_lists SET exchanged_su_money=? WHERE id=? RETURNING id, activity_id, uid, employee_name, employee_account, exchanged_su_money, exchanged_cash",
  29 + exchangeCashList.ExchangedSuMoney, exchangeCashList.ListId); err != nil {
30 return exchangeCashList, err 30 return exchangeCashList, err
31 } 31 }
32 } 32 }
@@ -59,15 +59,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string @@ -59,15 +59,9 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
59 var exchangeCashListModels []*models.ExchangeCashPersonList 59 var exchangeCashListModels []*models.ExchangeCashPersonList
60 exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0) 60 exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
61 query := tx.Model(&exchangeCashListModels) 61 query := tx.Model(&exchangeCashListModels)
62 - // 根据公司id查找兑换现金人员清单  
63 - //if companyId, ok := queryOptions["companyId"]; ok {  
64 - // query = query.Where("exchange_cash_person_lists.company_id = ?", companyId)  
65 - //}  
66 - // 根据活动id查找兑换现金人员清单  
67 if exchangeCashActivityId, ok := queryOptions["activityId"]; ok { 62 if exchangeCashActivityId, ok := queryOptions["activityId"]; ok {
68 query = query.Where("exchange_cash_person_lists.activity_id = ?", exchangeCashActivityId) 63 query = query.Where("exchange_cash_person_lists.activity_id = ?", exchangeCashActivityId)
69 } 64 }
70 - // 根据兑换现金人员名称搜索人员清单  
71 if personNameMatch, ok := queryOptions["personNameMatch"]; ok && (personNameMatch != ""){ 65 if personNameMatch, ok := queryOptions["personNameMatch"]; ok && (personNameMatch != ""){
72 query = query.Where("exchange_cash_person_lists.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string))) 66 query = query.Where("exchange_cash_person_lists.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
73 } 67 }
@@ -104,7 +98,7 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string @@ -104,7 +98,7 @@ func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string
104 func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) { 98 func (repository *ExchangeCashPersonListRepository) Remove(exchangeCashList *domain.ExchangeCashPersonList) (*domain.ExchangeCashPersonList, error) {
105 tx := repository.transactionContext.PgTx 99 tx := repository.transactionContext.PgTx
106 exchangeCashListModel := new(models.ExchangeCashPersonList) 100 exchangeCashListModel := new(models.ExchangeCashPersonList)
107 - exchangeCashList.ExchangeCashPersonListId = exchangeCashList.Identity().(int64) 101 + exchangeCashList.ListId = exchangeCashList.Identity().(int64)
108 if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil { 102 if _, err := tx.Model(exchangeCashListModel).WherePK().Delete(); err != nil {
109 return exchangeCashList, err 103 return exchangeCashList, err
110 } 104 }
@@ -115,6 +109,15 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode @@ -115,6 +109,15 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode
115 return &domain.ExchangeCashPersonList{ 109 return &domain.ExchangeCashPersonList{
116 ExchangedCash: exchangeCashList.ExchangedCash, 110 ExchangedCash: exchangeCashList.ExchangedCash,
117 ExchangedSuMoney: exchangeCashList.ExchangedSuMoney, 111 ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
  112 + ListId: exchangeCashList.Id,
  113 + ExchangeCashActivityId: exchangeCashList.ActivityId,
  114 + EmployeeInfo: &domain.EmployeeInfo{
  115 + Uid: exchangeCashList.Uid,
  116 + EmployeeName: exchangeCashList.EmployeeName,
  117 + EmployeeAccount: exchangeCashList.EmployeeAccount,
  118 + EmployeeAvatarUrl: exchangeCashList.EmployeeAvatarUrl,
  119 + IsPrincipal: exchangeCashList.IsPrincipal,
  120 + },
118 }, nil 121 }, nil
119 } 122 }
120 func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) { 123 func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
@@ -76,8 +76,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -76,8 +76,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
76 // TODO 姓名模糊查询 76 // TODO 姓名模糊查询
77 if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") { 77 if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") {
78 //query = query.Where(`su_money_transaction_record.employee @> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string))) 78 //query = query.Where(`su_money_transaction_record.employee @> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
79 - //query = query.Where(`su_money_transaction_record.employee :json->> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))  
80 - query = query.Where(`su_money_transaction_record.employee @> '{"employeeName":?}'`, employeeMatchName.(string)) 79 + query = query.Where(`su_money_transaction_record.employee :json->> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
81 } 80 }
82 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { 81 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
83 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType) 82 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
@@ -2,6 +2,7 @@ package controllers @@ -2,6 +2,7 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
5 6
6 "github.com/astaxie/beego" 7 "github.com/astaxie/beego"
7 "github.com/linmadan/egglib-go/web/beego/utils" 8 "github.com/linmadan/egglib-go/web/beego/utils"
@@ -89,6 +90,7 @@ func (controller *EmployeeController) ListEmployee() { @@ -89,6 +90,7 @@ func (controller *EmployeeController) ListEmployee() {
89 listEmployeeQuery.Offset = offset 90 listEmployeeQuery.Offset = offset
90 limit, _ := controller.GetInt("limit") 91 limit, _ := controller.GetInt("limit")
91 listEmployeeQuery.Limit = limit 92 listEmployeeQuery.Limit = limit
  93 + fmt.Print(listEmployeeQuery)
92 data, err := employeeService.ListEmployee(listEmployeeQuery) 94 data, err := employeeService.ListEmployee(listEmployeeQuery)
93 var response utils.JsonResponse 95 var response utils.JsonResponse
94 if err != nil { 96 if err != nil {
@@ -81,28 +81,20 @@ func (controller *SuMoneyController) ExchangeSuMoney() { @@ -81,28 +81,20 @@ func (controller *SuMoneyController) ExchangeSuMoney() {
81 func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() { 81 func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
82 suMoneyService := service.NewSuMoneyService(nil) 82 suMoneyService := service.NewSuMoneyService(nil)
83 searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{} 83 searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{}
84 -  
85 - //employeeMatchName := controller.GetString("employeeMatchName")  
86 - //searchSuMoneyTransactionRecordCommand.EmployeeMatchName = employeeMatchName  
87 - 84 + employeeMatchName := controller.GetString("employeeMatchName")
  85 + searchSuMoneyTransactionRecordCommand.EmployeeMatchName = employeeMatchName
88 offset, _ := controller.GetInt("offset") 86 offset, _ := controller.GetInt("offset")
89 searchSuMoneyTransactionRecordCommand.Offset = offset 87 searchSuMoneyTransactionRecordCommand.Offset = offset
90 -  
91 limit, _ := controller.GetInt("limit") 88 limit, _ := controller.GetInt("limit")
92 searchSuMoneyTransactionRecordCommand.Limit = limit 89 searchSuMoneyTransactionRecordCommand.Limit = limit
93 -  
94 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand) 90 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand)
95 -  
96 data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand) 91 data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand)
97 -  
98 var response utils.JsonResponse 92 var response utils.JsonResponse
99 -  
100 if err != nil { 93 if err != nil {
101 response = utils.ResponseError(controller.Ctx, err) 94 response = utils.ResponseError(controller.Ctx, err)
102 } else { 95 } else {
103 response = utils.ResponseData(controller.Ctx, data) 96 response = utils.ResponseData(controller.Ctx, data)
104 } 97 }
105 -  
106 controller.Data["json"] = response 98 controller.Data["json"] = response
107 controller.ServeJSON() 99 controller.ServeJSON()
108 } 100 }
@@ -147,21 +139,16 @@ func (controller *SuMoneyController) CashInput() { @@ -147,21 +139,16 @@ func (controller *SuMoneyController) CashInput() {
147 func (controller *SuMoneyController) GetCashPool() { 139 func (controller *SuMoneyController) GetCashPool() {
148 cashPoolService := service.NewCashPoolService(nil) 140 cashPoolService := service.NewCashPoolService(nil)
149 getCashPoolQuery := &query.GetCashPoolQuery{} 141 getCashPoolQuery := &query.GetCashPoolQuery{}
150 -  
151 //json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery) 142 //json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery)
152 companyId, _ := controller.GetInt64("companyId") 143 companyId, _ := controller.GetInt64("companyId")
153 getCashPoolQuery.CompanyId = companyId 144 getCashPoolQuery.CompanyId = companyId
154 -  
155 data, err := cashPoolService.GetCashPool(getCashPoolQuery) 145 data, err := cashPoolService.GetCashPool(getCashPoolQuery)
156 -  
157 var response utils.JsonResponse 146 var response utils.JsonResponse
158 -  
159 if err != nil { 147 if err != nil {
160 response = utils.ResponseError(controller.Ctx, err) 148 response = utils.ResponseError(controller.Ctx, err)
161 } else { 149 } else {
162 response = utils.ResponseData(controller.Ctx, data) 150 response = utils.ResponseData(controller.Ctx, data)
163 } 151 }
164 -  
165 controller.Data["json"] = response 152 controller.Data["json"] = response
166 controller.ServeJSON() 153 controller.ServeJSON()
167 } 154 }
@@ -170,29 +157,21 @@ func (controller *SuMoneyController) GetCashPool() { @@ -170,29 +157,21 @@ func (controller *SuMoneyController) GetCashPool() {
170 func (controller *SuMoneyController) ListExchangeActivities () { 157 func (controller *SuMoneyController) ListExchangeActivities () {
171 cashPoolService := service.NewCashPoolService(nil) 158 cashPoolService := service.NewCashPoolService(nil)
172 listExchangeCashActivityQuery := &query.ListExchangeCashActivityQuery{} 159 listExchangeCashActivityQuery := &query.ListExchangeCashActivityQuery{}
173 -  
174 companyId, _ := controller.GetInt64("companyId") 160 companyId, _ := controller.GetInt64("companyId")
175 listExchangeCashActivityQuery.CompanyId = companyId 161 listExchangeCashActivityQuery.CompanyId = companyId
176 -  
177 exchangeCashActivityNameMatch := controller.GetString("activityNameMatch") 162 exchangeCashActivityNameMatch := controller.GetString("activityNameMatch")
178 listExchangeCashActivityQuery.ExchangeCashActivityNameMatch = exchangeCashActivityNameMatch 163 listExchangeCashActivityQuery.ExchangeCashActivityNameMatch = exchangeCashActivityNameMatch
179 -  
180 offset, _ := controller.GetInt("offset") 164 offset, _ := controller.GetInt("offset")
181 listExchangeCashActivityQuery.Offset = offset 165 listExchangeCashActivityQuery.Offset = offset
182 -  
183 limit, _ := controller.GetInt("limit") 166 limit, _ := controller.GetInt("limit")
184 listExchangeCashActivityQuery.Limit = limit 167 listExchangeCashActivityQuery.Limit = limit
185 -  
186 data, err := cashPoolService.ListExchangeCashActivity(listExchangeCashActivityQuery) 168 data, err := cashPoolService.ListExchangeCashActivity(listExchangeCashActivityQuery)
187 -  
188 var response utils.JsonResponse 169 var response utils.JsonResponse
189 -  
190 if err != nil { 170 if err != nil {
191 response = utils.ResponseError(controller.Ctx, err) 171 response = utils.ResponseError(controller.Ctx, err)
192 } else { 172 } else {
193 response = utils.ResponseData(controller.Ctx, data) 173 response = utils.ResponseData(controller.Ctx, data)
194 } 174 }
195 -  
196 controller.Data["json"] = response 175 controller.Data["json"] = response
197 controller.ServeJSON() 176 controller.ServeJSON()
198 } 177 }
@@ -236,7 +215,8 @@ func (controller *SuMoneyController) RemoveExchangeActivities () { @@ -236,7 +215,8 @@ func (controller *SuMoneyController) RemoveExchangeActivities () {
236 cashPoolService := service.NewCashPoolService(nil) 215 cashPoolService := service.NewCashPoolService(nil)
237 removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{} 216 removeExchangeCashActivityCommand := &command.RemoveExchangeCashActivityCommand{}
238 activityId, _ := controller.GetInt64(":activityId") 217 activityId, _ := controller.GetInt64(":activityId")
239 - removeExchangeCashActivityCommand. ExchangeCashActivityId = activityId 218 + beego.Info(activityId)
  219 + removeExchangeCashActivityCommand.ActivityId = activityId
240 data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand) 220 data, err := cashPoolService.RemoveExchangeCashActivity(removeExchangeCashActivityCommand)
241 var response utils.JsonResponse 221 var response utils.JsonResponse
242 if err != nil { 222 if err != nil {
@@ -277,6 +257,9 @@ func (controller *SuMoneyController) ListExchangeList () { @@ -277,6 +257,9 @@ func (controller *SuMoneyController) ListExchangeList () {
277 listExchangeCashListQuery.Offset = offset 257 listExchangeCashListQuery.Offset = offset
278 limit, _ := controller.GetInt("limit") 258 limit, _ := controller.GetInt("limit")
279 listExchangeCashListQuery.Limit = limit 259 listExchangeCashListQuery.Limit = limit
  260 +
  261 + fmt.Println("hahahhah", listExchangeCashListQuery)
  262 +
280 data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery) 263 data, err := cashPoolService.ListExchangeCashPerson(listExchangeCashListQuery)
281 var response utils.JsonResponse 264 var response utils.JsonResponse
282 if err != nil { 265 if err != nil {
@@ -310,7 +293,7 @@ func (controller *SuMoneyController) UpdateExchangeList () { @@ -310,7 +293,7 @@ func (controller *SuMoneyController) UpdateExchangeList () {
310 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{} 293 updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{}
311 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand) 294 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateExchangeCashPersonCommand)
312 personId, _ := controller.GetInt64(":personId") 295 personId, _ := controller.GetInt64(":personId")
313 - updateExchangeCashPersonCommand. ExchangeCashPersonId = personId 296 + updateExchangeCashPersonCommand.ListId = personId
314 data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand) 297 data, err := cashPoolService.UpdateExchangeCashPerson(updateExchangeCashPersonCommand)
315 var response utils.JsonResponse 298 var response utils.JsonResponse
316 if err != nil { 299 if err != nil {
@@ -323,11 +306,11 @@ func (controller *SuMoneyController) UpdateExchangeList () { @@ -323,11 +306,11 @@ func (controller *SuMoneyController) UpdateExchangeList () {
323 } 306 }
324 307
325 // 移除兑换现金人员 308 // 移除兑换现金人员
326 -func (controller *SuMoneyController) RemoveExchangeList () { 309 +func (controller *SuMoneyController) RemoveExchangeCashPerson() {
327 cashPoolService := service.NewCashPoolService(nil) 310 cashPoolService := service.NewCashPoolService(nil)
328 removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{} 311 removeExchangeCashPersonCommand := &command.RemoveExchangeCashPersonCommand{}
329 - personId, _ := controller.GetInt64(":personId")  
330 - removeExchangeCashPersonCommand.ExchangeCashPersonId = personId 312 + personId, _ := controller.GetInt64(":listId")
  313 + removeExchangeCashPersonCommand.ListId = personId
331 data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand) 314 data, err := cashPoolService.RemoveExchangeCashPerson(removeExchangeCashPersonCommand)
332 var response utils.JsonResponse 315 var response utils.JsonResponse
333 if err != nil { 316 if err != nil {
@@ -343,8 +326,8 @@ func (controller *SuMoneyController) RemoveExchangeList () { @@ -343,8 +326,8 @@ func (controller *SuMoneyController) RemoveExchangeList () {
343 func (controller *SuMoneyController) GetExchangeCashPerson () { 326 func (controller *SuMoneyController) GetExchangeCashPerson () {
344 cashPoolService := service.NewCashPoolService(nil) 327 cashPoolService := service.NewCashPoolService(nil)
345 getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{} 328 getExchangeCashPersonQuery := &query.GetExchangeCashPersonQuery{}
346 - personId, _ := controller.GetInt64(":personId")  
347 - getExchangeCashPersonQuery.ExchangeCashPersonId = personId 329 + listId, _ := controller.GetInt64(":listId")
  330 + getExchangeCashPersonQuery.ExchangeCashPersonId = listId
348 data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery) 331 data, err := cashPoolService.GetExchangeCashPerson(getExchangeCashPersonQuery)
349 var response utils.JsonResponse 332 var response utils.JsonResponse
350 if err != nil { 333 if err != nil {
@@ -376,6 +359,8 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -376,6 +359,8 @@ func (controller *SuMoneyController) ImportExchangeList () {
376 fmt.Println(err) 359 fmt.Println(err)
377 return 360 return
378 } 361 }
  362 + // TODO 判断活动汇率是否为空
  363 +
379 var response utils.JsonResponse 364 var response utils.JsonResponse
380 dataList := make([]interface{}, 0) 365 dataList := make([]interface{}, 0)
381 rows, _ := xlsx.GetRows("Sheet1") 366 rows, _ := xlsx.GetRows("Sheet1")
@@ -383,10 +368,9 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -383,10 +368,9 @@ func (controller *SuMoneyController) ImportExchangeList () {
383 if i > 0 { 368 if i > 0 {
384 for _, _ = range row { 369 for _, _ = range row {
385 createExchangeCashPersonCommand.ExchangeCashActivityId = activityId 370 createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
386 - createExchangeCashPersonCommand.PersonId, _ = strconv.ParseInt(row[0], 10, 32)  
387 - createExchangeCashPersonCommand.PersonName = row[1]  
388 - createExchangeCashPersonCommand.PersonAccount = row[2]  
389 - createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[3], 64) 371 + createExchangeCashPersonCommand.PersonName = row[0]
  372 + createExchangeCashPersonCommand.PersonAccount = row[1]
  373 + createExchangeCashPersonCommand.ExchangedSuMoney, _ = strconv.ParseFloat(row[2], 64)
390 } 374 }
391 fmt.Print(createExchangeCashPersonCommand) 375 fmt.Print(createExchangeCashPersonCommand)
392 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand) 376 data, err := cashPoolService.CreateExchangeCashPerson(createExchangeCashPersonCommand)
@@ -18,15 +18,15 @@ func init() { @@ -18,15 +18,15 @@ func init() {
18 beego.Router("/cash-pool/cash-pool", &controllers.SuMoneyController{}, "GET:GetCashPool") // 返回现金池统计 18 beego.Router("/cash-pool/cash-pool", &controllers.SuMoneyController{}, "GET:GetCashPool") // 返回现金池统计
19 19
20 beego.Router("/cash-pool/activity/", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动列表 20 beego.Router("/cash-pool/activity/", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
21 - beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "GET:ListExchangeActivities") // 返回兑换活动 21 + beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "GET:GetExchangeCashActivity") // 返回兑换活动
22 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动 22 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动
23 beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "POST:CreateExchangeActivities") // 新增兑换活动 23 beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "POST:CreateExchangeActivities") // 新增兑换活动
24 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeActivities") // 删除兑换活动 24 beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeActivities") // 删除兑换活动
25 25
26 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单 26 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "GET:ListExchangeList") // 返回素币兑换清单
27 - beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员 27 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "GET:GetExchangeCashPerson") // 返回素币兑换人员
28 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单 28 beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "POST:CreateExchangeList") // 新增素币兑换清单
29 - beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单  
30 - beego.Router("/cash-pool/activity/exchange-list/:personId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单 29 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
  30 + beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "DELETE:RemoveExchangeCashPerson") // 删除素币兑换清单
31 beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单 31 beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "POST:ImportExchangeList") // 导入素币兑换清单
32 } 32 }