作者 陈志颖

feat:完成排行榜管理增删改查

@@ -109,3 +109,11 @@ func CreateExchangeCashPersonListRepository(options map[string]interface{}) (dom @@ -109,3 +109,11 @@ func CreateExchangeCashPersonListRepository(options map[string]interface{}) (dom
109 } 109 }
110 return repository.NewExchangeCashPersonListRepository(transactionContext) 110 return repository.NewExchangeCashPersonListRepository(transactionContext)
111 } 111 }
  112 +
  113 +func CreateListIntervalRepository(options map[string]interface{}) (domain.ListIntervalRepository, error) {
  114 + var transactionContext *pg.TransactionContext
  115 + if value, ok := options["transactionContext"]; ok {
  116 + transactionContext = value.(*pg.TransactionContext)
  117 + }
  118 + return repository.NewListIntervalRepository(transactionContext)
  119 +}
@@ -9,7 +9,7 @@ type GetListIntervalQuery struct { @@ -9,7 +9,7 @@ type GetListIntervalQuery struct {
9 ListIntervalId int `json:"listIntervalId"` // 排行榜id 9 ListIntervalId int `json:"listIntervalId"` // 排行榜id
10 } 10 }
11 11
12 -func (getListIntervalQuery *GetListIntervalQuery) ValidateCommand() error { 12 +func (getListIntervalQuery *GetListIntervalQuery) ValidateQuery() error {
13 valid := validation.Validation{} 13 valid := validation.Validation{}
14 b, err := valid.Valid(getListIntervalQuery) 14 b, err := valid.Valid(getListIntervalQuery)
15 if err != nil { 15 if err != nil {
@@ -6,7 +6,9 @@ import ( @@ -6,7 +6,9 @@ import (
6 ) 6 )
7 7
8 type ListListIntervalQuery struct { 8 type ListListIntervalQuery struct {
9 - CompanyId int `json:"companyId"` // 公司id 9 + CompanyId int64 `json:"companyId"` // 公司id
  10 + Offset int `json:"offset,omitempty"` // 查询偏离量
  11 + Limit int `json:"limit,omitempty"` // 查询限制
10 } 12 }
11 13
12 func (listListIntervalQuery *ListListIntervalQuery) ValidateQuery() error { 14 func (listListIntervalQuery *ListListIntervalQuery) ValidateQuery() error {
1 -package service  
2 -  
3 -import (  
4 - "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"  
5 - "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"  
6 -)  
7 -  
8 -type ListIntervalService struct {  
9 -  
10 -}  
11 -  
12 -// TODO 创建排行榜时间  
13 -func (listIntervalService *ListIntervalService) CreateListInterval(createListIntervalComand *command.CreateListIntervalCommand) (interface{}, error) {  
14 - return nil, nil  
15 -}  
16 -  
17 -// TODO 返回排行榜时间列表  
18 -func (listIntervalService *ListIntervalService) ListListInterval(listListIntervalQuery *query.ListListIntervalQuery) (interface{}, error) {  
19 - return nil, nil  
20 -}  
21 -  
22 -// TODO 返回排行榜时间  
23 -func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQuery *query.GetListIntervalQuery) (interface{}, error) {  
24 - return nil, nil  
25 -}  
26 -  
27 -// TODO 更新排行榜时间  
28 -func (listIntervalService *ListIntervalService) UpdateListInterval(updateListIntervalCommand *command.UpdateListIntervalCommand) (interface{}, error) {  
29 - return nil, nil  
30 -}  
31 -  
32 -// TODO 移除排行榜时间  
33 -func (listIntervalService *ListIntervalService) RemoveListInterval(removeListIntervalCommand *command.RemoveListIntervalCommand) (interface{}, error) {  
34 - return nil, nil  
35 -}  
36 -  
37 -func NewListIntervalService(options map[string] interface{}) *ListIntervalService {  
38 - newListIntervalService := &ListIntervalService{}  
39 - return newListIntervalService  
40 -}  
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 +)
  12 +
  13 +type ListIntervalService struct {
  14 +}
  15 +
  16 +// 创建排行榜时间
  17 +func (listIntervalService *ListIntervalService) CreateListInterval(createListIntervalCommand *command.CreateListIntervalCommand) (interface{}, error) {
  18 + if err := createListIntervalCommand.ValidateCommand(); err != nil {
  19 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  20 + }
  21 + transactionContext, err := factory.CreateTransactionContext(nil)
  22 + if err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + if err := transactionContext.StartTransaction(); err != nil {
  26 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  27 + }
  28 + defer func() {
  29 + transactionContext.RollbackTransaction()
  30 + }()
  31 + newListInterval := &domain.ListInterval {
  32 + CompanyId: createListIntervalCommand.CompanyId,
  33 + IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
  34 + IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
  35 + }
  36 + var listIntervalRepository domain.ListIntervalRepository
  37 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + }); err != nil {
  40 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 + } else {
  42 + listIntervalRepository = value
  43 + }
  44 + if listInterval, err := listIntervalRepository.Save(newListInterval); err != nil {
  45 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 + } else {
  47 + if err := transactionContext.CommitTransaction(); err != nil {
  48 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  49 + }
  50 + return listInterval, nil
  51 + }
  52 +}
  53 +
  54 +// 返回排行榜时间列表
  55 +func (listIntervalService *ListIntervalService) ListListInterval(listListIntervalQuery *query.ListListIntervalQuery) (interface{}, error) {
  56 + if err := listListIntervalQuery.ValidateQuery(); err != nil {
  57 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  58 + }
  59 + transactionContext, err := factory.CreateTransactionContext(nil)
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  62 + }
  63 + if err := transactionContext.StartTransaction(); err != nil {
  64 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  65 + }
  66 + defer func() {
  67 + transactionContext.RollbackTransaction()
  68 + }()
  69 + var listIntervalRepository domain.ListIntervalRepository
  70 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  71 + "transactionContext": transactionContext,
  72 + }); err != nil {
  73 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  74 + } else {
  75 + listIntervalRepository = value
  76 + }
  77 + if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + } else {
  80 + if err := transactionContext.CommitTransaction(); err != nil {
  81 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  82 + }
  83 + return map[string]interface{}{
  84 + "count": count,
  85 + "taskNatures": listIntervals,
  86 + }, nil
  87 + }
  88 +}
  89 +
  90 +// 返回排行榜时间
  91 +func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQuery *query.GetListIntervalQuery) (interface{}, error) {
  92 + if err := getListIntervalQuery.ValidateQuery(); err != nil {
  93 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  94 + }
  95 + transactionContext, err := factory.CreateTransactionContext(nil)
  96 + if err != nil {
  97 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  98 + }
  99 + if err := transactionContext.StartTransaction(); err != nil {
  100 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  101 + }
  102 + defer func() {
  103 + transactionContext.RollbackTransaction()
  104 + }()
  105 + var listIntervalRepository domain.ListIntervalRepository
  106 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  107 + "transactionContext": transactionContext,
  108 + }); err != nil {
  109 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  110 + } else {
  111 + listIntervalRepository = value
  112 + }
  113 + listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId})
  114 + if err != nil {
  115 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + }
  117 + if listInterval == nil {
  118 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getListIntervalQuery.ListIntervalId)))
  119 + } else {
  120 + if err := transactionContext.CommitTransaction(); err != nil {
  121 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  122 + }
  123 + return listInterval, nil
  124 + }
  125 +}
  126 +
  127 +// 更新排行榜时间
  128 +func (listIntervalService *ListIntervalService) UpdateListInterval(updateListIntervalCommand *command.UpdateListIntervalCommand) (interface{}, error) {
  129 + if err := updateListIntervalCommand.ValidateCommand(); err != nil {
  130 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  131 + }
  132 + transactionContext, err := factory.CreateTransactionContext(nil)
  133 + if err != nil {
  134 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  135 + }
  136 + if err := transactionContext.StartTransaction(); err != nil {
  137 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  138 + }
  139 + defer func() {
  140 + transactionContext.RollbackTransaction()
  141 + }()
  142 + var listIntervalRepository domain.ListIntervalRepository
  143 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  144 + "transactionContext": transactionContext,
  145 + }); err != nil {
  146 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  147 + } else {
  148 + listIntervalRepository = value
  149 + }
  150 + listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
  151 + if err != nil {
  152 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  153 + }
  154 + if listInterval == nil {
  155 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
  156 + }
  157 + if err := listInterval.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
  158 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  159 + }
  160 + if listInterval, err := listIntervalRepository.Save(listInterval); err != nil {
  161 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  162 + } else {
  163 + if err := transactionContext.CommitTransaction(); err != nil {
  164 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  165 + }
  166 + return listInterval, nil
  167 + }
  168 +}
  169 +
  170 +// 移除排行榜时间
  171 +func (listIntervalService *ListIntervalService) RemoveListInterval(removeListIntervalCommand *command.RemoveListIntervalCommand) (interface{}, error) {
  172 + if err := removeListIntervalCommand.ValidateCommand(); err != nil {
  173 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  174 + }
  175 + transactionContext, err := factory.CreateTransactionContext(nil)
  176 + if err != nil {
  177 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + if err := transactionContext.StartTransaction(); err != nil {
  180 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  181 + }
  182 + defer func() {
  183 + transactionContext.RollbackTransaction()
  184 + }()
  185 + var listIntervalRepository domain.ListIntervalRepository
  186 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  187 + "transactionContext": transactionContext,
  188 + }); err != nil {
  189 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  190 + } else {
  191 + listIntervalRepository = value
  192 + }
  193 + listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId})
  194 + if err != nil {
  195 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  196 + }
  197 + if listInterval == nil {
  198 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId)))
  199 + }
  200 + if listInterval, err := listIntervalRepository.Remove(listInterval); err != nil {
  201 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  202 + } else {
  203 + if err := transactionContext.CommitTransaction(); err != nil {
  204 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  205 + }
  206 + return listInterval, nil
  207 + }
  208 +}
  209 +
  210 +func NewListIntervalService(options map[string] interface{}) *ListIntervalService {
  211 + newListIntervalService := &ListIntervalService{}
  212 + return newListIntervalService
  213 +}
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 8
9 type OperationSuMoneyCommand struct { 9 type OperationSuMoneyCommand struct {
10 Uid int64 `json:"uid" valid:"Required"` // 素币拥有者UID 10 Uid int64 `json:"uid" valid:"Required"` // 素币拥有者UID
11 - OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除) 11 + OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除, 3兑换物资, 4兑换现金
12 SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值 12 SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
13 Operator int64 `json:"operator,omitempty"` // 操作人UID 13 Operator int64 `json:"operator,omitempty"` // 操作人UID
14 OperationDescription string `json:"operationDescription" valid:"Required"` // 理由描述 14 OperationDescription string `json:"operationDescription" valid:"Required"` // 理由描述
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 // 移除兑换现金人员 8 // 移除兑换现金人员
9 type RemoveExchangeCashPersonCommand struct { 9 type RemoveExchangeCashPersonCommand struct {
10 ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号 10 ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
  11 + Operator int64 `json:"operator,omitempty"` // 操作人
11 } 12 }
12 13
13 func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error { 14 func (removeExchangeCashPersonCommand *RemoveExchangeCashPersonCommand) ValidateCommand() error {
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 type UpdateExchangeCashPersonCommand struct { 8 type UpdateExchangeCashPersonCommand struct {
9 ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号 9 ListId int64 `json:"listId" valid:"Required"` // 兑换现金人员编号
10 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录) 10 ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币(需要和当前的已兑换素币进行比较,少于当前已兑换素币则生成一条扣除素币记录,大于当前已兑换素币则生成一条增加素币记录)
  11 + Operator int64 `json:"operator,omitempty"` // 操作人
11 } 12 }
12 13
13 func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error { 14 func (updateExchangeCashPersonCommand *UpdateExchangeCashPersonCommand) ValidateCommand() error {
@@ -3,6 +3,9 @@ package service @@ -3,6 +3,9 @@ package service
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/utils/tool_funs" 5 "github.com/linmadan/egglib-go/utils/tool_funs"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  8 + "strconv"
6 "time" 9 "time"
7 10
8 "github.com/linmadan/egglib-go/core/application" 11 "github.com/linmadan/egglib-go/core/application"
@@ -32,29 +35,32 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -32,29 +35,32 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
32 transactionContext.RollbackTransaction() 35 transactionContext.RollbackTransaction()
33 }() 36 }()
34 37
35 - // TODO 判断公司是否存在  
36 -  
37 - //var cashPoolDao *dao.CashPoolDao  
38 - //if value, err := factory.CreateCashPoolDao(map[string]interface{}{  
39 - // "transactionContext": transactionContext,  
40 - //}); err != nil {  
41 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
42 - //} else {  
43 - // cashPoolDao = value  
44 - //}  
45 -  
46 - // TODO 统计系统已兑换现金、未兑换现金、已兑换素币、未兑换素币 38 + var employeeDao *dao.EmployeeDao
  39 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  40 + "transactionContext": transactionContext,
  41 + }); err != nil {
  42 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  43 + } else {
  44 + employeeDao = value
  45 + }
47 46
48 - var systemUnExchangeCash float64  
49 - //systemExchangedCash, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId)  
50 - //if err != nil {  
51 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
52 - //} 47 + // 统计系统素币
  48 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
  49 + if err != nil {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  51 + }
  52 + if systemSuMoneyStatistics == nil {
  53 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  54 + }
53 55
54 - //systemChangedSuMoney, systemUnChangeSuMoney, err := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)  
55 - //if err != nil {  
56 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
57 - //} 56 + // 统计系统现金
  57 + systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
  58 + if err != nil {
  59 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  60 + }
  61 + if systemCashStatistics == nil {
  62 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  63 + }
58 64
59 var cashPoolRepository domain.CashPoolRepository 65 var cashPoolRepository domain.CashPoolRepository
60 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 66 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
@@ -65,38 +71,25 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -65,38 +71,25 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
65 cashPoolRepository = value 71 cashPoolRepository = value
66 } 72 }
67 73
68 - // TODO 获取系统未兑换现金  
69 -  
70 - //count, cashPools, err := cashPoolRepository.Find(map[string]interface{}{  
71 - // "companyId": createCashPoolCommand.CompanyId,  
72 - //})  
73 - //if err != nil {  
74 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
75 - //}  
76 - //if count == 0 {  
77 - // systemUnExchangeCash = 0  
78 - //} else {  
79 - // systemUnExchangeCash = cashPools[0].UnExchangeCash  
80 - //} 74 + systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
  75 + systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
  76 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  77 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
81 78
82 // TODO 计算系统平均兑换汇率 79 // TODO 计算系统平均兑换汇率
83 - //rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率 80 + rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
84 81
  82 + // 新建现金池
85 newCashPool := &domain.CashPool{ 83 newCashPool := &domain.CashPool{
86 CompanyId: createCashPoolCommand.CompanyId, 84 CompanyId: createCashPoolCommand.CompanyId,
87 Cash: createCashPoolCommand.Cash, 85 Cash: createCashPoolCommand.Cash,
88 - //ExchangedCash: systemExchangedCash,  
89 - ExchangedCash: 0, 86 + ExchangedCash: systemExchangedCash,
90 UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash, 87 UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash,
91 - //ExchangedSuMoney: systemChangedSuMoney,  
92 - ExchangedSuMoney: 0,  
93 - //UnExchangeSuMoney: systemUnChangeSuMoney,  
94 - UnExchangeSuMoney: 0,  
95 - //Rate: rate,  
96 - Rate: 0, 88 + ExchangedSuMoney: systemExchangedSuMoney,
  89 + UnExchangeSuMoney: systemUnExchangeSuMoney,
  90 + Rate: rate,
97 CreateTime: time.Now(), 91 CreateTime: time.Now(),
98 } 92 }
99 -  
100 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 93 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
101 "transactionContext": transactionContext, 94 "transactionContext": transactionContext,
102 }); err != nil { 95 }); err != nil {
@@ -104,7 +97,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -104,7 +97,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
104 } else { 97 } else {
105 cashPoolRepository = value 98 cashPoolRepository = value
106 } 99 }
107 -  
108 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { 100 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
109 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 101 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
110 } else { 102 } else {
@@ -130,6 +122,28 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -130,6 +122,28 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
130 defer func() { 122 defer func() {
131 transactionContext.RollbackTransaction() 123 transactionContext.RollbackTransaction()
132 }() 124 }()
  125 +
  126 + var employeeDao *dao.EmployeeDao
  127 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  128 + "transactionContext": transactionContext,
  129 + }); err != nil {
  130 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  131 + } else {
  132 + employeeDao = value
  133 + }
  134 +
  135 + // 统计系统素币
  136 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
  137 + if err != nil {
  138 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  139 + }
  140 + if systemSuMoneyStatistics == nil {
  141 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  142 + }
  143 +
  144 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  145 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
  146 +
133 var cashPoolRepository domain.CashPoolRepository 147 var cashPoolRepository domain.CashPoolRepository
134 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 148 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
135 "transactionContext": transactionContext, 149 "transactionContext": transactionContext,
@@ -144,7 +158,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -144,7 +158,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
144 if err := transactionContext.CommitTransaction(); err != nil { 158 if err := transactionContext.CommitTransaction(); err != nil {
145 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 159 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
146 } 160 }
147 - // TODO 初始状态下,现金池返回默认值 161 + // 初始状态下,现金池返回默认值
148 if count == 0 { 162 if count == 0 {
149 return map[string] interface{} { 163 return map[string] interface{} {
150 "cashPoolId": 0, 164 "cashPoolId": 0,
@@ -152,8 +166,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -152,8 +166,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
152 "companyId": getCashPoolQuery.CompanyId, 166 "companyId": getCashPoolQuery.CompanyId,
153 "exchangedCash": 0, 167 "exchangedCash": 0,
154 "unExchangeCash": 0, 168 "unExchangeCash": 0,
155 - "exchangedSuMoney": 0,  
156 - "unExchangeSuMoney": 0, 169 + "exchangedSuMoney": systemExchangedSuMoney,
  170 + "unExchangeSuMoney": systemUnExchangeSuMoney,
157 "rate": 0, 171 "rate": 0,
158 "createTime": time.Now(), 172 "createTime": time.Now(),
159 }, nil 173 }, nil
@@ -345,6 +359,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -345,6 +359,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
345 defer func() { 359 defer func() {
346 transactionContext.RollbackTransaction() 360 transactionContext.RollbackTransaction()
347 }() 361 }()
  362 +
  363 + // TODO 更新汇率处理:
  364 +
348 var exchangeCashActivityRepository domain.ExchangeActivityRepository 365 var exchangeCashActivityRepository domain.ExchangeActivityRepository
349 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 366 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
350 "transactionContext": transactionContext, 367 "transactionContext": transactionContext,
@@ -440,7 +457,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -440,7 +457,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
440 if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil { 457 if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
441 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 458 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
442 } else { 459 } else {
443 - // TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率 460 + // TODO 更新个人素币
  461 +
  462 + // TODO 更新活动数据
  463 +
  464 + // TODO 更新现金池数据
444 465
445 if err := transactionContext.CommitTransaction(); err != nil { 466 if err := transactionContext.CommitTransaction(); err != nil {
446 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 467 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -537,6 +558,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -537,6 +558,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
537 defer func() { 558 defer func() {
538 transactionContext.RollbackTransaction() 559 transactionContext.RollbackTransaction()
539 }() 560 }()
  561 + var operationSuMoneyService service.OperationSuMoneyService
  562 + if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
  563 + "transactionContext": transactionContext,
  564 + }); err != nil {
  565 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  566 + } else {
  567 + operationSuMoneyService = value
  568 + }
540 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 569 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
541 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 570 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
542 "transactionContext": transactionContext, 571 "transactionContext": transactionContext,
@@ -555,11 +584,29 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -555,11 +584,29 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
555 if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil { 584 if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
556 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 585 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
557 } else { 586 } else {
  587 + // TODO 更新个人素币,个人素币值需要还原,理由:素币兑换现金调整
  588 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  589 + Uid: person.EmployeeInfo.Uid,
  590 + Operator: removeExchangeCashPersonCommand.Operator,
  591 + SuMoney: 0,
  592 + OperationType: 5,
  593 + OperationDescription: "素币兑换现金调整",
  594 + }
  595 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  596 + if err != nil {
  597 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  598 + }
  599 + if task == nil {
  600 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
  601 + }
  602 +
  603 + // TODO 更新兑换活动数据
  604 +
  605 + // TODO 更新现金池数据
  606 +
558 if err := transactionContext.CommitTransaction(); err != nil { 607 if err := transactionContext.CommitTransaction(); err != nil {
559 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 608 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
560 } 609 }
561 - // TODO 个人素币值需要还原,理由:素币兑换现金调整  
562 -  
563 return personDeleted, nil 610 return personDeleted, nil
564 } 611 }
565 } 612 }
@@ -579,6 +626,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -579,6 +626,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
579 defer func() { 626 defer func() {
580 transactionContext.RollbackTransaction() 627 transactionContext.RollbackTransaction()
581 }() 628 }()
  629 + var operationSuMoneyService service.OperationSuMoneyService
  630 + if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
  631 + "transactionContext": transactionContext,
  632 + }); err != nil {
  633 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  634 + } else {
  635 + operationSuMoneyService = value
  636 + }
  637 +
582 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 638 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
583 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 639 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
584 "transactionContext": transactionContext, 640 "transactionContext": transactionContext,
@@ -600,9 +656,25 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -600,9 +656,25 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
600 if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil { 656 if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
601 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 657 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
602 } else { 658 } else {
  659 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  660 + Uid: person.EmployeeInfo.Uid,
  661 + Operator: updateExchangeCashPersonCommand.Operator,
  662 + SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
  663 + OperationType: 5,
  664 + OperationDescription: "参与兑换素币活动",
  665 + }
603 // TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称) 666 // TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
  667 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  668 + if err != nil {
  669 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  670 + }
  671 + if task == nil {
  672 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
  673 + }
  674 +
  675 + // TODO 更新兑换活动数据
604 676
605 - // TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率 677 + // TODO 更新现金池
606 678
607 if err := transactionContext.CommitTransaction(); err != nil { 679 if err := transactionContext.CommitTransaction(); err != nil {
608 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 680 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1 package domain 1 package domain
2 2
  3 +import "time"
  4 +
  5 +// 排行榜时间
  6 +type ListInterval struct {
  7 + ListIntervalId int `json:"listIntervalId"` // 排行榜时间id
  8 + CompanyId int64 `json:"companyId"` // 公司id
  9 + IntervalStartTime time.Time `json:"intervalStartTime"` // 排行榜开始时间
  10 + IntervalEndTime time.Time `json:"intervalEndTime"` // 排行榜结束时间
  11 +}
  12 +
  13 +type ListIntervalRepository interface {
  14 + Save(listInterval *ListInterval) (*ListInterval, error)
  15 + Remove(listInterval *ListInterval) (*ListInterval, error)
  16 + FindOne(queryOptions map[string]interface{}) (*ListInterval, error)
  17 + Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
  18 +}
  19 +
  20 +func (listInterval *ListInterval) Identify() interface{} {
  21 + if listInterval.ListIntervalId == 0 {
  22 + return nil
  23 + }
  24 + return listInterval.ListIntervalId
  25 +}
  26 +
  27 +func (listInterval *ListInterval) Update(data map[string]interface{}) error {
  28 + if intervalStartTime, ok := data["intervalStartTime"]; ok {
  29 + listInterval.IntervalStartTime = intervalStartTime.(time.Time)
  30 + }
  31 + if intervalEndTime, ok := data["intervalEndTime"]; ok {
  32 + listInterval.IntervalStartTime = intervalEndTime.(time.Time)
  33 + }
  34 + return nil
  35 +}
@@ -3,10 +3,11 @@ package domain @@ -3,10 +3,11 @@ package domain
3 import "time" 3 import "time"
4 4
5 const ( 5 const (
6 - SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换(物资、现金) 6 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换物资
7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励 7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励
8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加 8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加
9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除 9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除
  10 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH //兑换现金
10 ) 11 )
11 12
12 // 素币事务记录 13 // 素币事务记录
@@ -16,10 +17,10 @@ type SuMoneyTransactionRecord struct { @@ -16,10 +17,10 @@ type SuMoneyTransactionRecord struct {
16 Employee *EmployeeInfo `json:"employee"` // 记录关联员工 17 Employee *EmployeeInfo `json:"employee"` // 记录关联员工
17 SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"` // 事务处理前素币值 18 SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"` // 事务处理前素币值
18 CurrentSuMoney float64 `json:"currentSuMoney"` // 当前素币值 19 CurrentSuMoney float64 `json:"currentSuMoney"` // 当前素币值
19 - //CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池,用于兑换现金操作  
20 - //CurrentCashPool *CashPool `json:"currentCashPool"` // 当前现金池,用于兑换现金操作  
21 SuMoney float64 `json:"suMoney"` // 事务素币值 20 SuMoney float64 `json:"suMoney"` // 事务素币值
22 - //Cash float64 `json:"cash"` // 事务现金值,用于兑换现金操作 21 + CashBeforeTransaction float64 `json:"cashBeforeTransaction"` // 事务处理前现金值
  22 + CurrentCash float64 `json:"currentCash"` // 当前现金值
  23 + Cash float64 `json:"cash"` // 事务现金值
23 Operator *EmployeeInfo `json:"operator"` // 操作人 24 Operator *EmployeeInfo `json:"operator"` // 操作人
24 RecordDescription string `json:"recordDescription"` // 素币事务记录描述 25 RecordDescription string `json:"recordDescription"` // 素币事务记录描述
25 CreateTime time.Time `json:"createTime"` // 创建时间 26 CreateTime time.Time `json:"createTime"` // 创建时间
1 package models 1 package models
  2 +
  3 +import "time"
  4 +
  5 +type ListInterval struct {
  6 + TableName string `pg:"list_interval,alias:list_intervals"`
  7 + Id int // 排行榜周期id
  8 + ListIntervalStartTime time.Time
  9 + ListIntervalEndTime time.Time
  10 + CompanyId int64
  11 +}
1 package repository 1 package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  9 +)
  10 +
  11 +type ListIntervalRepository struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +func (repository *ListIntervalRepository) Save(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
  16 + tx := repository.transactionContext.PgTx
  17 + if listInterval.Identify() == nil {
  18 + if _, err := tx.QueryOne(
  19 + pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
  20 + "INSERT INTO list_intervals (list_interval_start_time, list_interval_end_time, company_id) VALUES (?, ?, ?) RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
  21 + listInterval.ListIntervalId, listInterval.CompanyId, listInterval.IntervalStartTime, listInterval.IntervalEndTime); err != nil {
  22 + return listInterval, err
  23 + }
  24 + } else {
  25 + if _, err := tx.QueryOne(
  26 + pg.Scan(&listInterval.ListIntervalId, &listInterval.CompanyId, &listInterval.IntervalStartTime, &listInterval.IntervalEndTime),
  27 + "UPDATE list_intervals SET list_interval_start_time=?, list_interval_end_time=? WHERE id=? RETURNING id, company_id, list_interval_start_time, list_interval_end_time",
  28 + listInterval.IntervalStartTime, listInterval.IntervalEndTime, listInterval.Identify()); err != nil {
  29 + return listInterval, err
  30 + }
  31 + }
  32 + return listInterval, nil
  33 +}
  34 +
  35 +func (repository *ListIntervalRepository) Remove(listInterval *domain.ListInterval) (*domain.ListInterval, error) {
  36 + tx := repository.transactionContext.PgTx
  37 + listIntervalModel := new(models.ListInterval)
  38 + listIntervalModel.Id = listInterval.Identify().(int)
  39 + if _, err := tx.Model(listIntervalModel).WherePK().Delete(); err != nil {
  40 + return listInterval, err
  41 + }
  42 + return listInterval, nil
  43 +}
  44 +
  45 +func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interface{}) (*domain.ListInterval, error) {
  46 + tx := repository.transactionContext.PgTx
  47 + listIntervalModel := new(models.ListInterval)
  48 + query := tx.Model(listIntervalModel)
  49 + if listIntervalId, ok := queryOptions["listId"]; ok {
  50 + query = query.Where("list_interval.id = ?", listIntervalId)
  51 + }
  52 + if err := query.First(); err != nil {
  53 + if err.Error() == "pg: no rows in result set" {
  54 + return nil, fmt.Errorf("没有此资源")
  55 + } else {
  56 + return nil, err
  57 + }
  58 + }
  59 + if listIntervalModel.Id == 0 {
  60 + return nil, nil
  61 + } else {
  62 + return repository.transformPgModelToDomainModel(listIntervalModel)
  63 + }
  64 +}
  65 +
  66 +func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
  67 + tx := repository.transactionContext.PgTx
  68 + var listIntervalModels []*models.ListInterval
  69 + listIntervals := make([]*domain.ListInterval, 0)
  70 + query := tx.Model(&listIntervalModels)
  71 + if companyId, ok := queryOptions["companyId"]; ok {
  72 + query = query.Where("list_interval.company_id = ?", companyId)
  73 + }
  74 + if offset, ok := queryOptions["offset"]; ok {
  75 + offset := offset.(int)
  76 + if offset > -1 {
  77 + query = query.Offset(offset)
  78 + }
  79 + } else {
  80 + query = query.Offset(0)
  81 + }
  82 + if limit, ok := queryOptions["limit"]; ok {
  83 + limit := limit.(int)
  84 + if limit > -1 {
  85 + query = query.Limit(limit)
  86 + }
  87 + } else {
  88 + query = query.Limit(20)
  89 + }
  90 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  91 + return 0, listIntervals, err
  92 + } else {
  93 + for _, listIntervalModel := range listIntervalModels {
  94 + if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
  95 + return 0, listIntervals, err
  96 + } else {
  97 + listIntervals = append(listIntervals, listInterval)
  98 + }
  99 + }
  100 + return int64(count), listIntervals, nil
  101 + }
  102 +}
  103 +
  104 +func (repository *ListIntervalRepository) transformPgModelToDomainModel(listIntervalModel *models.ListInterval) (*domain.ListInterval, error) {
  105 + return &domain.ListInterval{
  106 + ListIntervalId: listIntervalModel.Id,
  107 + CompanyId: listIntervalModel.CompanyId,
  108 + IntervalStartTime: listIntervalModel.ListIntervalStartTime,
  109 + IntervalEndTime: listIntervalModel.ListIntervalEndTime,
  110 + }, nil
  111 +}
  112 +
  113 +func NewListIntervalRepository(transactionContext *pgTransaction.TransactionContext) (*ListIntervalRepository, error) {
  114 + if transactionContext == nil {
  115 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  116 + } else {
  117 + return &ListIntervalRepository{
  118 + transactionContext: transactionContext,
  119 + }, nil
  120 + }
  121 +}
1 package controllers 1 package controllers
2 2
3 -import "github.com/astaxie/beego" 3 +import (
  4 + "encoding/json"
  5 + "github.com/astaxie/beego"
  6 + "github.com/linmadan/egglib-go/web/beego/utils"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/service"
  10 +)
4 11
5 type ListIntervalController struct { 12 type ListIntervalController struct {
6 beego.Controller 13 beego.Controller
7 } 14 }
8 15
9 -// TODO 新增榜单时间段 16 +// 新增榜单时间段
10 func (controller *ListIntervalController) CreateListInterval() { 17 func (controller *ListIntervalController) CreateListInterval() {
11 - 18 + listIntervalService := service.NewListIntervalService(nil)
  19 + createListIntervalCommand := &command.CreateListIntervalCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createListIntervalCommand)
  21 + data, err := listIntervalService.CreateListInterval(createListIntervalCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
12 } 30 }
13 31
14 -// TODO 更新榜单时间段 32 +// 更新榜单时间段
15 func (controller *ListIntervalController) UpdateListInterval() { 33 func (controller *ListIntervalController) UpdateListInterval() {
16 - 34 + listIntervalService := service.NewListIntervalService(nil)
  35 + updateListIntervalCommand := &command.UpdateListIntervalCommand{}
  36 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateListIntervalCommand)
  37 + listId, _ := controller.GetInt(":listId")
  38 + updateListIntervalCommand.ListIntervalId = listId
  39 + data, err := listIntervalService.UpdateListInterval(updateListIntervalCommand)
  40 + var response utils.JsonResponse
  41 + if err != nil {
  42 + response = utils.ResponseError(controller.Ctx, err)
  43 + } else {
  44 + response = utils.ResponseData(controller.Ctx, data)
  45 + }
  46 + controller.Data["json"] = response
  47 + controller.ServeJSON()
17 } 48 }
18 49
19 -// TODO 获取榜单时间段 50 +// 获取榜单时间段
20 func (controller *ListIntervalController) GetListInterval() { 51 func (controller *ListIntervalController) GetListInterval() {
21 - 52 + listIntervalService := service.NewListIntervalService(nil)
  53 + getListIntervalQuery := &query.GetListIntervalQuery{}
  54 + listId, _ := controller.GetInt(":listId")
  55 + getListIntervalQuery.ListIntervalId = listId
  56 + data, err := listIntervalService.GetListInterval(getListIntervalQuery)
  57 + var response utils.JsonResponse
  58 + if err != nil {
  59 + response = utils.ResponseError(controller.Ctx, err)
  60 + } else {
  61 + response = utils.ResponseData(controller.Ctx, data)
  62 + }
  63 + controller.Data["json"] = response
  64 + controller.ServeJSON()
22 } 65 }
23 66
24 -// TODO 获取榜单时间段列表 67 +// 获取榜单时间段列表
25 func (controller *ListIntervalController) ListListInterval() { 68 func (controller *ListIntervalController) ListListInterval() {
26 - 69 + listIntervalService := service.NewListIntervalService(nil)
  70 + listListIntervalQuery := &query.ListListIntervalQuery{}
  71 + companyId, _ := controller.GetInt64(":companyID")
  72 + listListIntervalQuery.CompanyId = companyId
  73 + offset, _ := controller.GetInt("offset")
  74 + listListIntervalQuery.Offset = offset
  75 + limit, _ := controller.GetInt("limit")
  76 + listListIntervalQuery.Limit = limit
  77 + data, err := listIntervalService.ListListInterval(listListIntervalQuery)
  78 + var response utils.JsonResponse
  79 + if err != nil {
  80 + response = utils.ResponseError(controller.Ctx, err)
  81 + } else {
  82 + response = utils.ResponseData(controller.Ctx, data)
  83 + }
  84 + controller.Data["json"] = response
  85 + controller.ServeJSON()
27 } 86 }
28 87
29 -// TODO 移除榜单时间段 88 +// 移除榜单时间段
30 func (controller *ListIntervalController) RemoveListInterval() { 89 func (controller *ListIntervalController) RemoveListInterval() {
31 - 90 + listIntervalService := service.NewListIntervalService(nil)
  91 + removeListIntervalQuery := &command.RemoveListIntervalCommand{}
  92 + listId, _ := controller.GetInt(":listId")
  93 + removeListIntervalQuery.ListIntervalId = listId
  94 + data, err := listIntervalService.RemoveListInterval(removeListIntervalQuery)
  95 + var response utils.JsonResponse
  96 + if err != nil {
  97 + response = utils.ResponseError(controller.Ctx, err)
  98 + } else {
  99 + response = utils.ResponseData(controller.Ctx, data)
  100 + }
  101 + controller.Data["json"] = response
  102 + controller.ServeJSON()
32 } 103 }
33 104
@@ -7,8 +7,8 @@ import ( @@ -7,8 +7,8 @@ import (
7 7
8 func init() { 8 func init() {
9 beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Post:CreateListInterval") 9 beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Post:CreateListInterval")
10 - beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Put:UpdateListInterval")  
11 - beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Get:GetListInterval")  
12 - beego.Router("/list-interval/:intervalId", &controllers.ListIntervalController{}, "Delete:RemoveListInterval") 10 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Put:UpdateListInterval")
  11 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Get:GetListInterval")
  12 + beego.Router("/list-interval/:listId", &controllers.ListIntervalController{}, "Delete:RemoveListInterval")
13 beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Get:ListListInterval") 13 beego.Router("/list-interval/", &controllers.ListIntervalController{}, "Get:ListListInterval")
14 } 14 }
@@ -11,5 +11,5 @@ func init() { @@ -11,5 +11,5 @@ func init() {
11 beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics") 11 beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")
12 beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics") 12 beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics")
13 beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计 13 beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计
14 - beego.Router("/statistics/system-cashPool", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计 14 + beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
15 } 15 }