正在显示
19 个修改的文件
包含
534 行增加
和
471 行删除
@@ -12,3 +12,11 @@ func CreateAdminUserkDao(options map[string]interface{}) (*dao.AdminUserDao, err | @@ -12,3 +12,11 @@ func CreateAdminUserkDao(options map[string]interface{}) (*dao.AdminUserDao, err | ||
12 | } | 12 | } |
13 | return dao.NewAdminUserDao(transactionContext) | 13 | return dao.NewAdminUserDao(transactionContext) |
14 | } | 14 | } |
15 | + | ||
16 | +func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, error) { | ||
17 | + var transactionContext *transaction.TransactionContext | ||
18 | + if value, ok := options["transactionContext"]; ok { | ||
19 | + transactionContext = value.(*transaction.TransactionContext) | ||
20 | + } | ||
21 | + return dao.NewPartnerInfoDao(transactionContext) | ||
22 | +} |
@@ -7,13 +7,13 @@ import ( | @@ -7,13 +7,13 @@ import ( | ||
7 | ) | 7 | ) |
8 | 8 | ||
9 | //CreatePartnerInfoRepository 合伙人信息 | 9 | //CreatePartnerInfoRepository 合伙人信息 |
10 | -// func CreatePartnerInfoRepository(options map[string]interface{}) (domain.PartnerInfoRepository, error) { | ||
11 | -// var transactionContext *transaction.TransactionContext | ||
12 | -// if value, ok := options["transactionContext"]; ok { | ||
13 | -// transactionContext = value.(*transaction.TransactionContext) | ||
14 | -// } | ||
15 | -// return repository.NewPartnerInfoRepository(transactionContext) | ||
16 | -// } | 10 | +func CreatePartnerInfoRepository(options map[string]interface{}) (domain.PartnerInfoRepository, error) { |
11 | + var transactionContext *transaction.TransactionContext | ||
12 | + if value, ok := options["transactionContext"]; ok { | ||
13 | + transactionContext = value.(*transaction.TransactionContext) | ||
14 | + } | ||
15 | + return repository.NewPartnerInfoRepository(transactionContext) | ||
16 | +} | ||
17 | 17 | ||
18 | //CreateAdminUserRepository 管理员信息 | 18 | //CreateAdminUserRepository 管理员信息 |
19 | func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) { | 19 | func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) { |
@@ -24,7 +24,7 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | @@ -24,7 +24,7 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | ||
24 | return repository.NewAdminUserRepository(transactionContext) | 24 | return repository.NewAdminUserRepository(transactionContext) |
25 | } | 25 | } |
26 | 26 | ||
27 | -//CreateAdminUserRepository 管理员信息 | 27 | +//CreateAdminUserRepository 管理员权限信息 |
28 | func CreateAdminPermissionRepository(options map[string]interface{}) (domain.AdminPermissionRepository, error) { | 28 | func CreateAdminPermissionRepository(options map[string]interface{}) (domain.AdminPermissionRepository, error) { |
29 | var transactionContext *transaction.TransactionContext | 29 | var transactionContext *transaction.TransactionContext |
30 | if value, ok := options["transactionContext"]; ok { | 30 | if value, ok := options["transactionContext"]; ok { |
1 | package command | 1 | package command |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "fmt" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 4 | + "time" |
6 | 5 | ||
7 | - "github.com/astaxie/beego/validation" | 6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
8 | ) | 7 | ) |
9 | 8 | ||
10 | type CreatePartnerInfoCommand struct { | 9 | type CreatePartnerInfoCommand struct { |
11 | - domain.PartnerInfo | 10 | + // 合伙人姓名 |
11 | + PartnerName string `json:"partnerName,omitempty"` | ||
12 | + // 登录账号 | ||
13 | + Account string `json:"account,omitempty"` | ||
14 | + // 登录密码 | ||
15 | + Password string `json:"password,omitempty"` | ||
16 | + // 状态(1:启用或者0:禁用) | ||
17 | + Status int `json:"status"` | ||
18 | + // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | ||
19 | + PartnerCategory int `json:"partnerCategory,omitempty"` | ||
20 | + //合作时间 | ||
21 | + CooperateTime time.Time `json:"cooperateTime"` | ||
22 | + // 区域 | ||
23 | + RegionInfo *domain.RegionInfo `json:"regionInfo"` | ||
24 | + //关联业务员 | ||
25 | + Salesman []*domain.Salesman `json:"salesman,omitempty"` | ||
12 | } | 26 | } |
13 | 27 | ||
14 | -func (c *CreatePartnerInfoCommand) ValidateCommand() error { | ||
15 | - valid := validation.Validation{} | ||
16 | - b, err := valid.Valid(c) | ||
17 | - if err != nil { | ||
18 | - return err | ||
19 | - } | ||
20 | - if !b { | ||
21 | - for _, validErr := range valid.Errors { | ||
22 | - return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | - } | ||
24 | - } | 28 | +func (command CreatePartnerInfoCommand) ValidateCommand() error { |
25 | return nil | 29 | return nil |
26 | } | 30 | } |
1 | -package command | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "github.com/astaxie/beego/validation" | ||
7 | -) | ||
8 | - | ||
9 | -type RemovePartnerInfoCommand struct { | ||
10 | - // 合伙人ID | ||
11 | - Id int `json:"id" valid:"Required"` | ||
12 | -} | ||
13 | - | ||
14 | -func (c *RemovePartnerInfoCommand) ValidateCommand() error { | ||
15 | - valid := validation.Validation{} | ||
16 | - b, err := valid.Valid(c) | ||
17 | - if err != nil { | ||
18 | - return err | ||
19 | - } | ||
20 | - if !b { | ||
21 | - for _, validErr := range valid.Errors { | ||
22 | - return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | - } | ||
24 | - } | ||
25 | - return nil | ||
26 | -} |
1 | package command | 1 | package command |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "fmt" | ||
5 | - "github.com/astaxie/beego/validation" | ||
6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
7 | ) | 5 | ) |
8 | 6 | ||
9 | type UpdatePartnerInfoCommand struct { | 7 | type UpdatePartnerInfoCommand struct { |
10 | // 合伙人Id | 8 | // 合伙人Id |
11 | - Id int `json:"id,omitempty"` | ||
12 | - | ||
13 | - // 合伙人姓名 | ||
14 | - PartnerName string `json:"partnerName,omitempty"` | ||
15 | - // 登录账号 | ||
16 | - Account string `json:"account,omitempty"` | ||
17 | - // 登录密码 | ||
18 | - Password string `json:"password,omitempty"` | 9 | + Id int64 `json:"id,omitempty"` |
19 | // 状态(1:启用或者0:禁用) | 10 | // 状态(1:启用或者0:禁用) |
20 | Status int `json:"status"` | 11 | Status int `json:"status"` |
21 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | 12 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) |
22 | PartnerCategory int `json:"partnerCategory,omitempty"` | 13 | PartnerCategory int `json:"partnerCategory,omitempty"` |
23 | - | 14 | + // 区域 |
15 | + RegionInfo *domain.RegionInfo `json:"regionInfo"` | ||
24 | //关联业务员 | 16 | //关联业务员 |
25 | Salesman []*domain.Salesman `json:"salesman,omitempty"` | 17 | Salesman []*domain.Salesman `json:"salesman,omitempty"` |
26 | } | 18 | } |
27 | 19 | ||
28 | func (c *UpdatePartnerInfoCommand) ValidateCommand() error { | 20 | func (c *UpdatePartnerInfoCommand) ValidateCommand() error { |
29 | - valid := validation.Validation{} | ||
30 | - b, err := valid.Valid(c) | ||
31 | - if err != nil { | ||
32 | - return err | ||
33 | - } | ||
34 | - if !b { | ||
35 | - for _, validErr := range valid.Errors { | ||
36 | - return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
37 | - } | ||
38 | - } | ||
39 | return nil | 21 | return nil |
40 | } | 22 | } |
1 | package query | 1 | package query |
2 | 2 | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "github.com/astaxie/beego/validation" | ||
7 | -) | ||
8 | - | ||
9 | type GetPartnerInfoQuery struct { | 3 | type GetPartnerInfoQuery struct { |
10 | // 合伙人ID | 4 | // 合伙人ID |
11 | - Id int `json:"id" valid:"Required"` | 5 | + Id int64 `json:"id" ` |
12 | } | 6 | } |
13 | 7 | ||
14 | func (q *GetPartnerInfoQuery) ValidateQuery() error { | 8 | func (q *GetPartnerInfoQuery) ValidateQuery() error { |
15 | - valid := validation.Validation{} | ||
16 | - b, err := valid.Valid(q) | ||
17 | - if err != nil { | ||
18 | - return err | ||
19 | - } | ||
20 | - if !b { | ||
21 | - for _, validErr := range valid.Errors { | ||
22 | - return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | - } | ||
24 | - } | ||
25 | return nil | 9 | return nil |
26 | } | 10 | } |
1 | package query | 1 | package query |
2 | 2 | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "github.com/astaxie/beego/validation" | ||
7 | -) | ||
8 | - | ||
9 | type ListPartnerInfoQuery struct { | 3 | type ListPartnerInfoQuery struct { |
10 | - //状态 | ||
11 | - Status int `json:"status,omitempty"` | ||
12 | // 合伙人类别 | 4 | // 合伙人类别 |
13 | - PartnerCategory int `json:"partnerCategory,omitempty"` | ||
14 | - //按创建任务时间排序(ASC,DESC) | ||
15 | - SortByCreateTime string `json:"sortByCreateTime,omitempty"` | ||
16 | - //按创建任务时间排序(ASC,DESC) | ||
17 | - SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | 5 | + Partnertype int `json:"partnerType"` |
6 | + RegionInfo string `json:"regionInfo"` | ||
7 | + PartnerName string `json:"partnerName"` | ||
18 | // 查询偏离量 | 8 | // 查询偏离量 |
19 | - Offset int `json:"offset,omitempty"` | 9 | + Offset int `json:"offset"` |
20 | // 查询限制 | 10 | // 查询限制 |
21 | - Limit int `json:"limit,omitempty"` | 11 | + Limit int `json:"limit"` |
22 | } | 12 | } |
23 | 13 | ||
24 | func (q *ListPartnerInfoQuery) ValidateQuery() error { | 14 | func (q *ListPartnerInfoQuery) ValidateQuery() error { |
25 | - valid := validation.Validation{} | ||
26 | - b, err := valid.Valid(q) | ||
27 | - if err != nil { | ||
28 | - return err | ||
29 | - } | ||
30 | - if !b { | ||
31 | - for _, validErr := range valid.Errors { | ||
32 | - return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
33 | - } | ||
34 | - } | 15 | + |
35 | return nil | 16 | return nil |
36 | } | 17 | } |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
11 | +) | ||
12 | + | ||
13 | +// 客户价值服务 | ||
14 | +type PartnerInfoService struct { | ||
15 | +} | ||
16 | + | ||
17 | +func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { | ||
18 | + newPartnerInfoService := &PartnerInfoService{} | ||
19 | + return newPartnerInfoService | ||
20 | +} | ||
21 | + | ||
22 | +// 创建客户价值 | ||
23 | +func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) { | ||
24 | + var ( | ||
25 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
26 | + ) | ||
27 | + if err = command.ValidateCommand(); err != nil { | ||
28 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
29 | + } | ||
30 | + if err = transactionContext.StartTransaction(); err != nil { | ||
31 | + return nil, err | ||
32 | + } | ||
33 | + defer func() { | ||
34 | + transactionContext.RollbackTransaction() | ||
35 | + }() | ||
36 | + //检查账号是否存在 | ||
37 | + var ( | ||
38 | + partnerinfoDao *dao.PartnerInfoDao | ||
39 | + ) | ||
40 | + if v, err := factory.CreatePartnerInfoDao(map[string]interface{}{ | ||
41 | + "transactionContext": transactionContext, | ||
42 | + }); err != nil { | ||
43 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
44 | + } else { | ||
45 | + partnerinfoDao = v | ||
46 | + } | ||
47 | + ok, err := partnerinfoDao.PartnerAccountExist(command.Account) | ||
48 | + if err != nil { | ||
49 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
50 | + } | ||
51 | + if ok { | ||
52 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") | ||
53 | + } | ||
54 | + | ||
55 | + var PartnerInfoRepository domain.PartnerInfoRepository | ||
56 | + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
57 | + "transactionContext": transactionContext, | ||
58 | + }); err != nil { | ||
59 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
60 | + } | ||
61 | + newPartnerInfo := &domain.PartnerInfo{ | ||
62 | + Account: command.Account, | ||
63 | + PartnerName: command.PartnerName, | ||
64 | + Password: command.Password, | ||
65 | + Status: command.Status, | ||
66 | + PartnerCategory: command.PartnerCategory, | ||
67 | + RegionInfo: command.RegionInfo, | ||
68 | + Salesman: command.Salesman, | ||
69 | + CooperateTime: command.CooperateTime, | ||
70 | + } | ||
71 | + if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil { | ||
72 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
73 | + } | ||
74 | + err = transactionContext.CommitTransaction() | ||
75 | + return | ||
76 | +} | ||
77 | + | ||
78 | +// GetPartnerInfo 返回合伙人 | ||
79 | +func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) { | ||
80 | + var ( | ||
81 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
82 | + ) | ||
83 | + if err = command.ValidateQuery(); err != nil { | ||
84 | + return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
85 | + } | ||
86 | + if err := transactionContext.StartTransaction(); err != nil { | ||
87 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
88 | + } | ||
89 | + defer func() { | ||
90 | + transactionContext.RollbackTransaction() | ||
91 | + }() | ||
92 | + var PartnerInfoRepository domain.PartnerInfoRepository | ||
93 | + if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
94 | + "transactionContext": transactionContext, | ||
95 | + }); err != nil { | ||
96 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
97 | + } | ||
98 | + data, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id}) | ||
99 | + if err != nil { | ||
100 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
101 | + } | ||
102 | + err = transactionContext.CommitTransaction() | ||
103 | + return | ||
104 | +} | ||
105 | + | ||
106 | +// 更新客户价值 | ||
107 | +func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (err error) { | ||
108 | + var ( | ||
109 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
110 | + ) | ||
111 | + if err = updatePartnerInfoCommand.ValidateCommand(); err != nil { | ||
112 | + return application.ThrowError(application.ARG_ERROR, err.Error()) | ||
113 | + } | ||
114 | + if err := transactionContext.StartTransaction(); err != nil { | ||
115 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
116 | + } | ||
117 | + defer func() { | ||
118 | + transactionContext.RollbackTransaction() | ||
119 | + }() | ||
120 | + var partnerInfoRepository domain.PartnerInfoRepository | ||
121 | + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
122 | + "transactionContext": transactionContext, | ||
123 | + }); err != nil { | ||
124 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
125 | + } | ||
126 | + partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ | ||
127 | + UserId: updatePartnerInfoCommand.Id, | ||
128 | + }) | ||
129 | + if err != nil { | ||
130 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
131 | + } | ||
132 | + partnerInfo.PartnerCategory = updatePartnerInfoCommand.PartnerCategory | ||
133 | + partnerInfo.Salesman = updatePartnerInfoCommand.Salesman | ||
134 | + partnerInfo.Status = updatePartnerInfoCommand.Status | ||
135 | + partnerInfo.RegionInfo = updatePartnerInfoCommand.RegionInfo | ||
136 | + if _, err = partnerInfoRepository.Save(partnerInfo); err != nil { | ||
137 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
138 | + } | ||
139 | + transactionContext.CommitTransaction() | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// 返回客户价值列表 | ||
144 | +func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) { | ||
145 | + var ( | ||
146 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
147 | + partnerInfos []domain.PartnerInfo | ||
148 | + count int | ||
149 | + err error | ||
150 | + ) | ||
151 | + if err = listPartnerInfoQuery.ValidateQuery(); err != nil { | ||
152 | + return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
153 | + } | ||
154 | + if err := transactionContext.StartTransaction(); err != nil { | ||
155 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
156 | + } | ||
157 | + defer func() { | ||
158 | + if err != nil { | ||
159 | + transactionContext.RollbackTransaction() | ||
160 | + } | ||
161 | + }() | ||
162 | + var partnerInfoRepository domain.PartnerInfoRepository | ||
163 | + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
164 | + "transactionContext": transactionContext, | ||
165 | + }); err != nil { | ||
166 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
167 | + } | ||
168 | + queryOption := domain.PartnerFindQuery{ | ||
169 | + Offset: listPartnerInfoQuery.Offset, | ||
170 | + Limit: listPartnerInfoQuery.Limit, | ||
171 | + PartnerCategory: []int{listPartnerInfoQuery.Partnertype}, | ||
172 | + PartnerName: listPartnerInfoQuery.PartnerName, | ||
173 | + } | ||
174 | + // RegionInfo | ||
175 | + if len(listPartnerInfoQuery.RegionInfo) > 0 { | ||
176 | + queryOption.RegionInfo = &domain.RegionInfo{RegionName: listPartnerInfoQuery.RegionInfo} | ||
177 | + } | ||
178 | + if partnerInfos, err = partnerInfoRepository.Find(queryOption); err != nil { | ||
179 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
180 | + } | ||
181 | + if count, err = partnerInfoRepository.CountAll(queryOption); err != nil { | ||
182 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
183 | + } | ||
184 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
185 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
186 | + } | ||
187 | + return count, partnerInfos, nil | ||
188 | +} | ||
189 | + | ||
190 | +func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.StatusPartnerInfoCommand) (err error) { | ||
191 | + var ( | ||
192 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
193 | + ) | ||
194 | + if err = command.ValidateCommand(); err != nil { | ||
195 | + return application.ThrowError(application.ARG_ERROR, err.Error()) | ||
196 | + } | ||
197 | + if err := transactionContext.StartTransaction(); err != nil { | ||
198 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
199 | + } | ||
200 | + defer func() { | ||
201 | + transactionContext.RollbackTransaction() | ||
202 | + }() | ||
203 | + var partnerInfoRepository domain.PartnerInfoRepository | ||
204 | + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
205 | + "transactionContext": transactionContext, | ||
206 | + }); err != nil { | ||
207 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
208 | + } | ||
209 | + partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ | ||
210 | + UserId: command.Id, | ||
211 | + }) | ||
212 | + if err != nil { | ||
213 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
214 | + } | ||
215 | + partnerInfo.Status = command.Status | ||
216 | + if _, err = partnerInfoRepository.Save(partnerInfo); err != nil { | ||
217 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
218 | + } | ||
219 | + transactionContext.CommitTransaction() | ||
220 | + return | ||
221 | +} |
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/mmm-go/partnermg/pkg/application/factory" | ||
8 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command" | ||
9 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query" | ||
10 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
11 | - "time" | ||
12 | -) | ||
13 | - | ||
14 | -// 客户价值服务 | ||
15 | -type PartnerInfoService struct { | ||
16 | -} | ||
17 | - | ||
18 | -// 创建客户价值 | ||
19 | -func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) { | ||
20 | - var ( | ||
21 | - count int64 | ||
22 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
23 | - ) | ||
24 | - if err = command.ValidateCommand(); err != nil { | ||
25 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
26 | - } | ||
27 | - if err = transactionContext.StartTransaction(); err != nil { | ||
28 | - return nil, err | ||
29 | - } | ||
30 | - defer func() { | ||
31 | - if err != nil { | ||
32 | - transactionContext.RollbackTransaction() | ||
33 | - } | ||
34 | - }() | ||
35 | - | ||
36 | - newPartnerInfo := &command.PartnerInfo | ||
37 | - newPartnerInfo.CreateAt = time.Now() | ||
38 | - newPartnerInfo.UpdateAt = time.Now() | ||
39 | - | ||
40 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
41 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { | ||
42 | - return nil, err | ||
43 | - } | ||
44 | - if count, _, err = PartnerInfoRepository.Find(map[string]interface{}{"account": command.Account}); err != nil { | ||
45 | - return nil, err | ||
46 | - } | ||
47 | - if count > 0 { | ||
48 | - return nil, fmt.Errorf("标签不可重复名称") | ||
49 | - } | ||
50 | - | ||
51 | - if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil { | ||
52 | - return | ||
53 | - } | ||
54 | - err = transactionContext.CommitTransaction() | ||
55 | - return | ||
56 | -} | ||
57 | - | ||
58 | -// 返回客户价值 | ||
59 | -func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetPartnerInfoQuery) (data interface{}, err error) { | ||
60 | - var ( | ||
61 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
62 | - ) | ||
63 | - if err = command.ValidateQuery(); err != nil { | ||
64 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
65 | - } | ||
66 | - if err := transactionContext.StartTransaction(); err != nil { | ||
67 | - return nil, err | ||
68 | - } | ||
69 | - defer func() { | ||
70 | - if err != nil { | ||
71 | - transactionContext.RollbackTransaction() | ||
72 | - } | ||
73 | - }() | ||
74 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
75 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { | ||
76 | - return nil, err | ||
77 | - } | ||
78 | - data, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": command.Id}) | ||
79 | - if err != nil { | ||
80 | - return nil, err | ||
81 | - } | ||
82 | - if data == nil { | ||
83 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(command.Id))) | ||
84 | - } | ||
85 | - err = transactionContext.CommitTransaction() | ||
86 | - return | ||
87 | -} | ||
88 | - | ||
89 | -// 更新客户价值 | ||
90 | -func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (data interface{}, err error) { | ||
91 | - var ( | ||
92 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
93 | - PartnerInfo *domain.PartnerInfo | ||
94 | - ) | ||
95 | - if err = updatePartnerInfoCommand.ValidateCommand(); err != nil { | ||
96 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
97 | - } | ||
98 | - if err := transactionContext.StartTransaction(); err != nil { | ||
99 | - return nil, err | ||
100 | - } | ||
101 | - defer func() { | ||
102 | - if err != nil { | ||
103 | - transactionContext.RollbackTransaction() | ||
104 | - } | ||
105 | - }() | ||
106 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
107 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { | ||
108 | - return nil, err | ||
109 | - } | ||
110 | - PartnerInfo, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": updatePartnerInfoCommand.Id}) | ||
111 | - if err != nil { | ||
112 | - return nil, err | ||
113 | - } | ||
114 | - if PartnerInfo == nil { | ||
115 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updatePartnerInfoCommand.Id))) | ||
116 | - } | ||
117 | - //if count, PartnerInfos, err := PartnerInfoRepository.Find(map[string]interface{}{ | ||
118 | - // "PartnerInfoName": updatePartnerInfoCommand.PartnerInfoName, | ||
119 | - // "companyId": PartnerInfo.CompanyId, | ||
120 | - //}); err != nil { | ||
121 | - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
122 | - //} else { | ||
123 | - // if count > 0 && PartnerInfos[0].PartnerInfoId != PartnerInfo.PartnerInfoId { | ||
124 | - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称") | ||
125 | - // } | ||
126 | - //} | ||
127 | - if err := PartnerInfo.Update(tool_funs.SimpleStructToMap(updatePartnerInfoCommand)); err != nil { | ||
128 | - return nil, err | ||
129 | - } | ||
130 | - | ||
131 | - if data, err = PartnerInfoRepository.Save(PartnerInfo); err != nil { | ||
132 | - return nil, err | ||
133 | - } | ||
134 | - err = transactionContext.CommitTransaction() | ||
135 | - return | ||
136 | -} | ||
137 | - | ||
138 | -// 移除客户价值 | ||
139 | -func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(removePartnerInfoCommand *command.RemovePartnerInfoCommand) (data interface{}, err error) { | ||
140 | - var ( | ||
141 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
142 | - PartnerInfo *domain.PartnerInfo | ||
143 | - ) | ||
144 | - if err = removePartnerInfoCommand.ValidateCommand(); err != nil { | ||
145 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
146 | - } | ||
147 | - if err = transactionContext.StartTransaction(); err != nil { | ||
148 | - return nil, err | ||
149 | - } | ||
150 | - defer func() { | ||
151 | - if err != nil { | ||
152 | - transactionContext.RollbackTransaction() | ||
153 | - } | ||
154 | - }() | ||
155 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
156 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { | ||
157 | - return nil, err | ||
158 | - } | ||
159 | - PartnerInfo, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": removePartnerInfoCommand.Id}) | ||
160 | - if err != nil { | ||
161 | - return nil, err | ||
162 | - } | ||
163 | - if PartnerInfo == nil { | ||
164 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removePartnerInfoCommand.Id))) | ||
165 | - } | ||
166 | - if data, err = PartnerInfoRepository.Remove(PartnerInfo); err != nil { | ||
167 | - return nil, err | ||
168 | - } | ||
169 | - err = transactionContext.CommitTransaction() | ||
170 | - return | ||
171 | -} | ||
172 | - | ||
173 | -// 返回客户价值列表 | ||
174 | -func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (data interface{}, err error) { | ||
175 | - var ( | ||
176 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
177 | - PartnerInfos []*domain.PartnerInfo | ||
178 | - count int64 | ||
179 | - ) | ||
180 | - if err = listPartnerInfoQuery.ValidateQuery(); err != nil { | ||
181 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
182 | - } | ||
183 | - if err := transactionContext.StartTransaction(); err != nil { | ||
184 | - return nil, err | ||
185 | - } | ||
186 | - defer func() { | ||
187 | - if err != nil { | ||
188 | - transactionContext.RollbackTransaction() | ||
189 | - } | ||
190 | - }() | ||
191 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
192 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { | ||
193 | - return nil, err | ||
194 | - } | ||
195 | - if count, PartnerInfos, err = PartnerInfoRepository.Find(tool_funs.SimpleStructToMap(listPartnerInfoQuery)); err != nil { | ||
196 | - return nil, err | ||
197 | - } | ||
198 | - if err = transactionContext.CommitTransaction(); err != nil { | ||
199 | - return nil, err | ||
200 | - } | ||
201 | - return map[string]interface{}{ | ||
202 | - "count": count, | ||
203 | - "partnerInfos": PartnerInfos, | ||
204 | - }, nil | ||
205 | -} | ||
206 | - | ||
207 | -func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { | ||
208 | - newPartnerInfoService := &PartnerInfoService{} | ||
209 | - return newPartnerInfoService | ||
210 | -} |
@@ -2,13 +2,6 @@ package domain | @@ -2,13 +2,6 @@ package domain | ||
2 | 2 | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | -type PartnerInfoRepository interface { | ||
6 | - Save(dm *PartnerInfo) (*PartnerInfo, error) | ||
7 | - Remove(dm *PartnerInfo) (*PartnerInfo, error) | ||
8 | - FindOne(queryOptions map[string]interface{}) (*PartnerInfo, error) | ||
9 | - Find(queryOptions map[string]interface{}) (int64, []*PartnerInfo, error) | ||
10 | -} | ||
11 | - | ||
12 | type PartnerInfo struct { | 5 | type PartnerInfo struct { |
13 | // 合伙人ID | 6 | // 合伙人ID |
14 | Id int64 `json:"id"` | 7 | Id int64 `json:"id"` |
@@ -27,37 +20,29 @@ type PartnerInfo struct { | @@ -27,37 +20,29 @@ type PartnerInfo struct { | ||
27 | CreateAt time.Time `json:"createAt"` | 20 | CreateAt time.Time `json:"createAt"` |
28 | //更新时间 | 21 | //更新时间 |
29 | UpdateAt time.Time `json:"updateAt"` | 22 | UpdateAt time.Time `json:"updateAt"` |
23 | + //合作时间 | ||
24 | + CooperateTime time.Time `json:"cooperateTime"` | ||
25 | + //关联业务员//所属区域信息 | ||
26 | + RegionInfo *RegionInfo `json:"regionInfo"` | ||
30 | 27 | ||
31 | - //关联业务员 | ||
32 | Salesman []*Salesman `json:"salesman"` | 28 | Salesman []*Salesman `json:"salesman"` |
33 | } | 29 | } |
34 | 30 | ||
35 | -func (m *PartnerInfo) Identify() interface{} { | ||
36 | - if m.Id == 0 { | ||
37 | - return nil | ||
38 | - } | ||
39 | - return m.Id | 31 | +type PartnerFindOneQuery struct { |
32 | + UserId int64 | ||
33 | + AccountEqual string | ||
34 | +} | ||
35 | +type PartnerFindQuery struct { | ||
36 | + Offset int | ||
37 | + Limit int | ||
38 | + PartnerCategory []int //合伙人类型 | ||
39 | + RegionInfo *RegionInfo //区域 | ||
40 | + PartnerName string //合伙人姓名 | ||
40 | } | 41 | } |
41 | 42 | ||
42 | -func (m *PartnerInfo) Update(data map[string]interface{}) error { | ||
43 | - if partnerName, ok := data["partnerName"]; ok && partnerName != "" { | ||
44 | - m.PartnerName = partnerName.(string) | ||
45 | - } | ||
46 | - if account, ok := data["account"]; ok && account != "" { | ||
47 | - m.Account = account.(string) | ||
48 | - } | ||
49 | - if password, ok := data["account"]; ok && password != "" { | ||
50 | - m.Password = password.(string) | ||
51 | - } | ||
52 | - if status, ok := data["status"]; ok && status != 0 { | ||
53 | - m.Status = status.(int) | ||
54 | - } | ||
55 | - if partnerCategory, ok := data["partnerCategory"]; ok && partnerCategory != 0 { | ||
56 | - m.PartnerCategory = partnerCategory.(int) | ||
57 | - } | ||
58 | - if salesman, ok := data["salesman"]; ok { | ||
59 | - m.Salesman = salesman.([]*Salesman) | ||
60 | - } | ||
61 | - m.UpdateAt = time.Now() | ||
62 | - return nil | 43 | +type PartnerInfoRepository interface { |
44 | + Save(dm *PartnerInfo) (*PartnerInfo, error) | ||
45 | + FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error) | ||
46 | + Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error) | ||
47 | + CountAll(queryOptions PartnerFindQuery) (int, error) | ||
63 | } | 48 | } |
pkg/domain/region_info.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +type PartnerInfoDao struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*PartnerInfoDao, error) { | ||
15 | + if transactionContext == nil { | ||
16 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
17 | + } else { | ||
18 | + return &PartnerInfoDao{ | ||
19 | + transactionContext: transactionContext, | ||
20 | + }, nil | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +func (dao PartnerInfoDao) PartnerAccountExist(account string) (bool, error) { | ||
25 | + tx := dao.transactionContext.PgDd | ||
26 | + m := &models.PartnerInfo{} | ||
27 | + ok, err := tx.Model(m). | ||
28 | + Where("account=?", account). | ||
29 | + Exists() | ||
30 | + | ||
31 | + return ok, err | ||
32 | +} |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type PartnerInfo struct { | 11 | type PartnerInfo struct { |
12 | - tableName struct{} `pg:"partner_infos,alias:partner_info"` | 12 | + tableName struct{} `pg:"partner_info"` |
13 | // 合伙人ID | 13 | // 合伙人ID |
14 | Id int64 `pg:",pk"` | 14 | Id int64 `pg:",pk"` |
15 | // 合伙人姓名 | 15 | // 合伙人姓名 |
@@ -22,12 +22,14 @@ type PartnerInfo struct { | @@ -22,12 +22,14 @@ type PartnerInfo struct { | ||
22 | Status int `pg:",notnull,default:1"` | 22 | Status int `pg:",notnull,default:1"` |
23 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | 23 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) |
24 | PartnerCategory int `pg:",notnull,default:1"` | 24 | PartnerCategory int `pg:",notnull,default:1"` |
25 | - | 25 | + //所属区域信息 |
26 | + RegionInfo *domain.RegionInfo | ||
26 | //创建时间 | 27 | //创建时间 |
27 | CreateAt time.Time | 28 | CreateAt time.Time |
28 | //更新时间 | 29 | //更新时间 |
29 | UpdateAt time.Time | 30 | UpdateAt time.Time |
30 | - | 31 | + //合作时间 |
32 | + CooperateTime time.Time | ||
31 | //关联业务员 | 33 | //关联业务员 |
32 | Salesman []*domain.Salesman | 34 | Salesman []*domain.Salesman |
33 | } | 35 | } |
@@ -138,7 +138,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | @@ -138,7 +138,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | ||
138 | 138 | ||
139 | func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFindQuery) (int, error) { | 139 | func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFindQuery) (int, error) { |
140 | db := reponsitory.transactionContext.PgDd | 140 | db := reponsitory.transactionContext.PgDd |
141 | - adminuserModels := []models.AdminUser{} | 141 | + adminuserModels := models.AdminUser{} |
142 | query := db.Model(&adminuserModels) | 142 | query := db.Model(&adminuserModels) |
143 | if len(queryOption.AccountLike) > 0 { | 143 | if len(queryOption.AccountLike) > 0 { |
144 | query = query.Where("account like ?", "%"+queryOption.AccountLike+"%") | 144 | query = query.Where("account like ?", "%"+queryOption.AccountLike+"%") |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
9 | +) | ||
10 | + | ||
11 | +type PartnerInfoRepository struct { | ||
12 | + transactionContext *transaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +var ( | ||
16 | + _ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil) | ||
17 | +) | ||
18 | + | ||
19 | +func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) { | ||
20 | + m := domain.PartnerInfo{ | ||
21 | + Id: partnerInfoModel.Id, | ||
22 | + PartnerName: partnerInfoModel.PartnerName, | ||
23 | + Account: partnerInfoModel.Account, | ||
24 | + Password: partnerInfoModel.Password, | ||
25 | + Status: partnerInfoModel.Status, | ||
26 | + PartnerCategory: partnerInfoModel.PartnerCategory, | ||
27 | + CreateAt: partnerInfoModel.CreateAt, | ||
28 | + Salesman: partnerInfoModel.Salesman, | ||
29 | + RegionInfo: partnerInfoModel.RegionInfo, | ||
30 | + CooperateTime: partnerInfoModel.CooperateTime, | ||
31 | + } | ||
32 | + return m, nil | ||
33 | +} | ||
34 | + | ||
35 | +func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) { | ||
36 | + if transactionContext == nil { | ||
37 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
38 | + } | ||
39 | + return &PartnerInfoRepository{transactionContext: transactionContext}, nil | ||
40 | +} | ||
41 | + | ||
42 | +func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) (*domain.PartnerInfo, error) { | ||
43 | + var ( | ||
44 | + err error | ||
45 | + tx = repository.transactionContext.PgTx | ||
46 | + ) | ||
47 | + m := &models.PartnerInfo{ | ||
48 | + Id: dm.Id, | ||
49 | + PartnerName: dm.PartnerName, | ||
50 | + Account: dm.Account, | ||
51 | + Password: dm.Password, | ||
52 | + Status: dm.Status, | ||
53 | + PartnerCategory: dm.PartnerCategory, | ||
54 | + Salesman: dm.Salesman, | ||
55 | + RegionInfo: dm.RegionInfo, | ||
56 | + CooperateTime: dm.CooperateTime, | ||
57 | + } | ||
58 | + if m.Id == 0 { | ||
59 | + err = tx.Insert(m) | ||
60 | + dm.Id = m.Id | ||
61 | + if err != nil { | ||
62 | + return nil, err | ||
63 | + } | ||
64 | + } else { | ||
65 | + err = tx.Update(m) | ||
66 | + if err != nil { | ||
67 | + return nil, err | ||
68 | + } | ||
69 | + } | ||
70 | + return dm, nil | ||
71 | +} | ||
72 | + | ||
73 | +func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFindOneQuery) (*domain.PartnerInfo, error) { | ||
74 | + tx := repository.transactionContext.PgDd | ||
75 | + PartnerInfoModel := new(models.PartnerInfo) | ||
76 | + query := tx.Model(PartnerInfoModel) | ||
77 | + if len(queryOptions.AccountEqual) > 0 { | ||
78 | + query = query.Where("account=?", queryOptions.AccountEqual) | ||
79 | + } | ||
80 | + if queryOptions.UserId > 0 { | ||
81 | + query = query.Where("id=?", queryOptions.UserId) | ||
82 | + } | ||
83 | + if err := query.First(); err != nil { | ||
84 | + return nil, err | ||
85 | + } | ||
86 | + result, err := repository.transformPgModelToDomainModel(PartnerInfoModel) | ||
87 | + return &result, err | ||
88 | +} | ||
89 | + | ||
90 | +func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) { | ||
91 | + db := repository.transactionContext.PgDd | ||
92 | + partnerModels := []models.PartnerInfo{} | ||
93 | + query := db.Model(&partnerModels) | ||
94 | + if len(queryOption.PartnerName) > 0 { | ||
95 | + query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | ||
96 | + } | ||
97 | + if queryOption.RegionInfo != nil { | ||
98 | + query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") | ||
99 | + } | ||
100 | + if len(queryOption.PartnerCategory) > 0 { | ||
101 | + query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) | ||
102 | + } | ||
103 | + if queryOption.Offset > -1 { | ||
104 | + query = query.Offset(queryOption.Offset) | ||
105 | + } | ||
106 | + if queryOption.Limit > 0 { | ||
107 | + query = query.Limit(queryOption.Limit) | ||
108 | + } else { | ||
109 | + query = query.Limit(20) | ||
110 | + } | ||
111 | + var ( | ||
112 | + err error | ||
113 | + partnerReturn = make([]domain.PartnerInfo, 0) | ||
114 | + ) | ||
115 | + err = query.Select() | ||
116 | + if err != nil { | ||
117 | + return partnerReturn, err | ||
118 | + } | ||
119 | + for i := range partnerModels { | ||
120 | + domainPartner, err := repository.transformPgModelToDomainModel(&partnerModels[i]) | ||
121 | + if err != nil { | ||
122 | + return partnerReturn, err | ||
123 | + } | ||
124 | + partnerReturn = append(partnerReturn, domainPartner) | ||
125 | + } | ||
126 | + return partnerReturn, nil | ||
127 | +} | ||
128 | + | ||
129 | +func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) { | ||
130 | + db := repository.transactionContext.PgDd | ||
131 | + adminuserModels := models.AdminUser{} | ||
132 | + query := db.Model(&adminuserModels) | ||
133 | + if len(queryOption.PartnerName) > 0 { | ||
134 | + query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | ||
135 | + } | ||
136 | + if queryOption.RegionInfo != nil { | ||
137 | + query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") | ||
138 | + } | ||
139 | + if len(queryOption.PartnerCategory) > 0 { | ||
140 | + query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) | ||
141 | + } | ||
142 | + cnt, err := query.Count() | ||
143 | + return cnt, err | ||
144 | +} |
1 | -package repository | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
8 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
9 | -) | ||
10 | - | ||
11 | -type PartnerInfoRepository struct { | ||
12 | - transactionContext *transaction.TransactionContext | ||
13 | -} | ||
14 | - | ||
15 | -func (repository *PartnerInfoRepository) transformPgModelToDomainModel(PartnerInfoModel *models.PartnerInfo) (*domain.PartnerInfo, error) { | ||
16 | - m := &domain.PartnerInfo{} | ||
17 | - return m, nil | ||
18 | -} | ||
19 | - | ||
20 | -func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) { | ||
21 | - if transactionContext == nil { | ||
22 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | - } | ||
24 | - return &PartnerInfoRepository{transactionContext: transactionContext}, nil | ||
25 | -} | ||
26 | - | ||
27 | -func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) (*domain.PartnerInfo, error) { | ||
28 | - var ( | ||
29 | - err error | ||
30 | - m = &models.PartnerInfo{} | ||
31 | - tx = repository.transactionContext.PgTx | ||
32 | - ) | ||
33 | - if err = GobModelTransform(m, dm); err != nil { | ||
34 | - return nil, err | ||
35 | - } | ||
36 | - if dm.Identify() == nil { | ||
37 | - if dm.Id, err = NewSnowflakeId(); err != nil { | ||
38 | - return dm, err | ||
39 | - } | ||
40 | - m.Id = dm.Id | ||
41 | - if err = tx.Insert(m); err != nil { | ||
42 | - return nil, err | ||
43 | - } | ||
44 | - return dm, nil | ||
45 | - } | ||
46 | - if err = tx.Update(m); err != nil { | ||
47 | - return nil, err | ||
48 | - } | ||
49 | - return dm, nil | ||
50 | -} | ||
51 | - | ||
52 | -// func (repository *PartnerInfoRepository) Remove(PartnerInfo *domain.PartnerInfo) (*domain.PartnerInfo, error) { | ||
53 | -// var ( | ||
54 | -// tx = repository.transactionContext.PgTx | ||
55 | -// PartnerInfoModel = &models.PartnerInfo{Id: PartnerInfo.Identify().(int64)} | ||
56 | -// ) | ||
57 | -// if _, err := tx.Model(PartnerInfoModel).Where("id = ?", PartnerInfo.Id).Delete(); err != nil { | ||
58 | -// return PartnerInfo, err | ||
59 | -// } | ||
60 | -// return PartnerInfo, nil | ||
61 | -// } | ||
62 | - | ||
63 | -// func (repository *PartnerInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.PartnerInfo, error) { | ||
64 | -// tx := repository.transactionContext.PgTx | ||
65 | -// PartnerInfoModel := new(models.PartnerInfo) | ||
66 | -// query := NewQuery(tx.Model(PartnerInfoModel), queryOptions) | ||
67 | -// query.SetWhere("partner_info.id = ?", "id") | ||
68 | -// if err := query.First(); err != nil { | ||
69 | -// return nil, query.HandleError(err, "没有此合伙人") | ||
70 | -// } | ||
71 | -// if PartnerInfoModel.Id == 0 { | ||
72 | -// return nil, nil | ||
73 | -// } | ||
74 | -// return repository.transformPgModelToDomainModel(PartnerInfoModel) | ||
75 | -// } | ||
76 | - | ||
77 | -// func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.PartnerInfo, error) { | ||
78 | -// tx := repository.transactionContext.PgTx | ||
79 | -// var PartnerInfoModels []*models.PartnerInfo | ||
80 | -// PartnerInfos := make([]*domain.PartnerInfo, 0) | ||
81 | -// query := NewQuery(tx.Model(&PartnerInfoModels), queryOptions) | ||
82 | -// query. | ||
83 | -// SetWhere("partner_info.account = ?", "account"). | ||
84 | -// SetWhere(`partner_info.status = ?`, "status"). | ||
85 | -// SetWhere(`partner_info.partner_category = ?`, "partnerCategory"). | ||
86 | -// SetLimit(). | ||
87 | -// SetOrder("partner_info.create_at", "sortByCreateTime"). | ||
88 | -// SetOrder("partner_info.update_at", "sortByUpdateTime") | ||
89 | -// var err error | ||
90 | -// if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
91 | -// return 0, PartnerInfos, err | ||
92 | -// } | ||
93 | -// for _, PartnerInfoModel := range PartnerInfoModels { | ||
94 | -// if PartnerInfo, err := repository.transformPgModelToDomainModel(PartnerInfoModel); err != nil { | ||
95 | -// return 0, PartnerInfos, err | ||
96 | -// } else { | ||
97 | -// PartnerInfos = append(PartnerInfos, PartnerInfo) | ||
98 | -// } | ||
99 | -// } | ||
100 | -// return int64(query.AffectRow), PartnerInfos, nil | ||
101 | -// } |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/logs" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
8 | + | ||
9 | + partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command" | ||
10 | + partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service" | ||
11 | +) | ||
12 | + | ||
3 | type PartnerInfoController struct { | 13 | type PartnerInfoController struct { |
4 | BaseController | 14 | BaseController |
5 | } | 15 | } |
6 | 16 | ||
17 | +////Prepare 重写 BaseController 的Prepare方法 | ||
18 | +func (c *PartnerInfoController) Prepare() { | ||
19 | + c.BaseController.Prepare() | ||
20 | + if ok := c.ValidJWTToken(); !ok { | ||
21 | + return | ||
22 | + } | ||
23 | + if ok := c.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok { | ||
24 | + return | ||
25 | + } | ||
26 | +} | ||
27 | + | ||
7 | //CreatePartnerInfo 创建合伙人 | 28 | //CreatePartnerInfo 创建合伙人 |
8 | -func (controller *PartnerInfoController) CreatePartnerInfo() { | ||
9 | - // var ( | ||
10 | - // service = service.NewPartnerInfoService(nil) | ||
11 | - // command = &command.CreatePartnerInfoCommand{} | ||
12 | - // ) | ||
13 | - // controller.JsonUnmarshal(command) | ||
14 | - // controller.HandlerResponse(service.CreatePartnerInfo(command)) | 29 | +func (c *PartnerInfoController) CreatePartnerInfo() { |
30 | + //用与适配前端定义的数据结构 | ||
31 | + type Parameter struct { | ||
32 | + PartnerName string `json:"partnerName"` | ||
33 | + PartnerType int `json:"partnerType"` | ||
34 | + Area string `json:"area"` | ||
35 | + Account string `json:"account"` | ||
36 | + State string `json:"state"` | ||
37 | + CooperationTime string `json:"cooperationTime"` | ||
38 | + SalesmanName string `json:"salesmanName"` | ||
39 | + Phone string `json:"phone"` | ||
40 | + } | ||
41 | + var ( | ||
42 | + param Parameter | ||
43 | + err error | ||
44 | + ) | ||
45 | + if err = c.BindJsonData(¶m); err != nil { | ||
46 | + logs.Error(err) | ||
47 | + c.ResponseError(errors.New("json数据解析失败")) | ||
48 | + return | ||
49 | + } | ||
50 | + cmd := partnerInfoCmd.CreatePartnerInfoCommand{} | ||
51 | + serve := partnerInfoService.NewPartnerInfoService(nil) | ||
52 | + serve.CreatePartnerInfo(&cmd) | ||
53 | + c.ResponseData(nil) | ||
54 | + return | ||
15 | } | 55 | } |
16 | 56 | ||
17 | //UpdatePartnerInfo 更新合伙人 | 57 | //UpdatePartnerInfo 更新合伙人 |
18 | -func (controller *PartnerInfoController) UpdatePartnerInfo() { | 58 | +func (c *PartnerInfoController) UpdatePartnerInfo() { |
19 | // var ( | 59 | // var ( |
20 | // service = service.NewPartnerInfoService(nil) | 60 | // service = service.NewPartnerInfoService(nil) |
21 | // command = &command.UpdatePartnerInfoCommand{} | 61 | // command = &command.UpdatePartnerInfoCommand{} |
@@ -27,7 +67,7 @@ func (controller *PartnerInfoController) UpdatePartnerInfo() { | @@ -27,7 +67,7 @@ func (controller *PartnerInfoController) UpdatePartnerInfo() { | ||
27 | } | 67 | } |
28 | 68 | ||
29 | //GetPartnerInfo 获取合伙人 | 69 | //GetPartnerInfo 获取合伙人 |
30 | -func (controller *PartnerInfoController) GetPartnerInfo() { | 70 | +func (c *PartnerInfoController) GetPartnerInfo() { |
31 | // var ( | 71 | // var ( |
32 | // service = service.NewPartnerInfoService(nil) | 72 | // service = service.NewPartnerInfoService(nil) |
33 | // command = &query.GetPartnerInfoQuery{} | 73 | // command = &query.GetPartnerInfoQuery{} |
-
请 注册 或 登录 后发表评论