合并分支 'dev' 到 'test'
Dev 查看合并请求 !10
正在显示
6 个修改的文件
包含
162 行增加
和
13 行删除
@@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | "reflect" | 6 | "reflect" |
6 | "strings" | 7 | "strings" |
7 | 8 | ||
@@ -23,6 +24,8 @@ type UpdateCooperationProjectCommand struct { | @@ -23,6 +24,8 @@ type UpdateCooperationProjectCommand struct { | ||
23 | PublisherUid string `cname:"共创项目发布人UID" json:"publisherUid" valid:"Required"` | 24 | PublisherUid string `cname:"共创项目发布人UID" json:"publisherUid" valid:"Required"` |
24 | // 共创项目描述 | 25 | // 共创项目描述 |
25 | CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,omitempty"` | 26 | CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,omitempty"` |
27 | + // 附件 | ||
28 | + Attachment []*domain.Attachment `cname:"共创项目附件" json:"attachment,omitempty"` | ||
26 | // 公司ID,通过集成REST上下文获取 | 29 | // 公司ID,通过集成REST上下文获取 |
27 | CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` | 30 | CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` |
28 | // 组织机构ID | 31 | // 组织机构ID |
@@ -34,7 +37,6 @@ type UpdateCooperationProjectCommand struct { | @@ -34,7 +37,6 @@ type UpdateCooperationProjectCommand struct { | ||
34 | } | 37 | } |
35 | 38 | ||
36 | func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) Valid(validation *validation.Validation) { | 39 | func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) Valid(validation *validation.Validation) { |
37 | - //validation.SetError("CustomValid", "未实现的自定义认证") | ||
38 | } | 40 | } |
39 | 41 | ||
40 | func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) ValidateCommand() error { | 42 | func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) ValidateCommand() error { |
@@ -83,5 +83,8 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{} | @@ -83,5 +83,8 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{} | ||
83 | if status, ok := data["status"]; ok { | 83 | if status, ok := data["status"]; ok { |
84 | cooperationProject.Status = status.(int32) | 84 | cooperationProject.Status = status.(int32) |
85 | } | 85 | } |
86 | + if attachment, ok := data["attachment"]; ok { | ||
87 | + cooperationProject.Attachment = attachment.([]*Attachment) | ||
88 | + } | ||
86 | return nil | 89 | return nil |
87 | } | 90 | } |
@@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" | ||
12 | "time" | 13 | "time" |
13 | ) | 14 | ) |
14 | 15 | ||
@@ -234,6 +235,61 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in | @@ -234,6 +235,61 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in | ||
234 | return int64(count), cooperationContracts, nil | 235 | return int64(count), cooperationContracts, nil |
235 | } | 236 | } |
236 | 237 | ||
238 | +func (dao *CooperationContractDao) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) { | ||
239 | + tx := dao.transactionContext.PgTx | ||
240 | + cooperationContractModel := new(models.CooperationContract) | ||
241 | + query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions) | ||
242 | + query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId") | ||
243 | + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { | ||
244 | + query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber) | ||
245 | + } | ||
246 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
247 | + query.Where("company->>'companyId' = '?'", companyId) | ||
248 | + } | ||
249 | + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { | ||
250 | + query.Where("org->>'orgId' = '?'", orgId) | ||
251 | + } | ||
252 | + if err := query.First(); err != nil { | ||
253 | + if err.Error() == "pg: no rows in result set" { | ||
254 | + return nil, fmt.Errorf("共创合约不存在") | ||
255 | + } else { | ||
256 | + return nil, err | ||
257 | + } | ||
258 | + } | ||
259 | + if cooperationContractModel.CooperationContractId == 0 { | ||
260 | + return nil, nil | ||
261 | + } else { | ||
262 | + var cooperationModeModels []*models.CooperationMode | ||
263 | + cooperationModeQuery := tx.Model(&cooperationModeModels) | ||
264 | + if countMode, err := cooperationModeQuery. | ||
265 | + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId). | ||
266 | + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId). | ||
267 | + Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber). | ||
268 | + Limit(1). | ||
269 | + SelectAndCount(); err != nil { | ||
270 | + log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{ | ||
271 | + "cooperationContractModel": cooperationContractModel, | ||
272 | + }) | ||
273 | + } else { | ||
274 | + if countMode > 0 { | ||
275 | + // 获取分红激励规则列表 | ||
276 | + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule | ||
277 | + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule | ||
278 | + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker | ||
279 | + var cooperationContractRelevantModels []*models.CooperationContractRelevant | ||
280 | + return transform.TransformToCooperationContractDomainModelFromPgModels( | ||
281 | + cooperationContractModel, | ||
282 | + cooperationModeModels[0], | ||
283 | + dividendsIncentivesRuleModels, | ||
284 | + moneyIncentivesRuleModels, | ||
285 | + cooperationContractRelevantModels, | ||
286 | + cooperationContractUndertakerModels) | ||
287 | + } | ||
288 | + } | ||
289 | + return nil, fmt.Errorf("共创合约不存在") | ||
290 | + } | ||
291 | +} | ||
292 | + | ||
237 | func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) { | 293 | func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) { |
238 | if transactionContext == nil { | 294 | if transactionContext == nil { |
239 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 295 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "github.com/go-pg/pg/v10/orm" | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | ||
13 | +) | ||
14 | + | ||
15 | +type CooperationContractUndertakerDao struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) { | ||
20 | + tx := repository.transactionContext.PgTx | ||
21 | + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker | ||
22 | + cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0) | ||
23 | + query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions) | ||
24 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
25 | + query.Where("company->>'companyId' = '?'", companyId) | ||
26 | + } | ||
27 | + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { | ||
28 | + query.Where("org->>'orgId' = '?'", orgId) | ||
29 | + } | ||
30 | + if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 { | ||
31 | + newOrgIds := utils.SliceItoa(orgIds.([]int64)) | ||
32 | + query.Where("org->>'orgId' in (?)", pg.In(newOrgIds)) | ||
33 | + } | ||
34 | + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { | ||
35 | + query.WhereGroup(func(query *orm.Query) (*orm.Query, error) { | ||
36 | + query.WhereOr("user_base_id = ? ", userBaseId) | ||
37 | + query.WhereOr("referrer->>'userBaseId' = '?' ", userBaseId) | ||
38 | + query.WhereOr("salesman->>'userBaseId' = '?' ", userBaseId) | ||
39 | + return query, nil | ||
40 | + }) | ||
41 | + } | ||
42 | + offsetLimitFlag := true | ||
43 | + if offsetLimit, ok := queryOptions["offsetLimit"]; ok { | ||
44 | + offsetLimitFlag = offsetLimit.(bool) | ||
45 | + } | ||
46 | + if offsetLimitFlag { | ||
47 | + query.SetOffsetAndLimit(20) | ||
48 | + } | ||
49 | + query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC") | ||
50 | + if count, err := query.SelectAndCount(); err != nil { | ||
51 | + return 0, cooperationContractUndertakers, err | ||
52 | + } else { | ||
53 | + for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels { | ||
54 | + if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil { | ||
55 | + return 0, cooperationContractUndertakers, err | ||
56 | + } else { | ||
57 | + cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker) | ||
58 | + } | ||
59 | + } | ||
60 | + return int64(count), cooperationContractUndertakers, nil | ||
61 | + } | ||
62 | +} | ||
63 | + | ||
64 | +func NewCooperationContractUndertakerDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerDao, error) { | ||
65 | + if transactionContext == nil { | ||
66 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
67 | + } else { | ||
68 | + return &CooperationContractUndertakerDao{ | ||
69 | + transactionContext: transactionContext, | ||
70 | + }, nil | ||
71 | + } | ||
72 | +} |
@@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId | @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId | ||
51 | } | 51 | } |
52 | 52 | ||
53 | // 2.相关合约统计 | 53 | // 2.相关合约统计 |
54 | - cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext) | 54 | + cooperationContractRelevantRepository, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext) |
55 | cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId, | 55 | cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId, |
56 | "limit": 1}) | 56 | "limit": 1}) |
57 | if err != nil { | 57 | if err != nil { |
@@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que | @@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que | ||
98 | return nil, err | 98 | return nil, err |
99 | } | 99 | } |
100 | queryOptions = tool_funs.SimpleStructToMap(&request) | 100 | queryOptions = tool_funs.SimpleStructToMap(&request) |
101 | - | ||
102 | - cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext) | 101 | + queryOptions["limit"] = 10000 //TODO:合约数大于10000时? |
102 | + cooperationContractUndertaker, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext) | ||
103 | _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions) | 103 | _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions) |
104 | if err != nil { | 104 | if err != nil { |
105 | return nil, nil | 105 | return nil, nil |
@@ -257,8 +257,23 @@ type searchContractDividendsResult struct { | @@ -257,8 +257,23 @@ type searchContractDividendsResult struct { | ||
257 | // | 257 | // |
258 | // queryOptions 查询参数 | 258 | // queryOptions 查询参数 |
259 | func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) { | 259 | func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) { |
260 | + var request = struct { | ||
261 | + //企业 | ||
262 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
263 | + //OrgId int64 `json:"orgId"` | ||
264 | + //UserId int64 `json:"userId"` | ||
265 | + //个人 | ||
266 | + //UserBaseId int64 `json:"userBaseId"` | ||
267 | + //Offset int `json:"offset"` | ||
268 | + //Limit int `json:"limit"` | ||
269 | + ContractId int `json:"contractId" valid:"Required"` | ||
270 | + }{} | ||
271 | + if err := LoadQueryObject(queryOptions, &request); err != nil { | ||
272 | + return nil, err | ||
273 | + } | ||
274 | + queryOptions = tool_funs.SimpleStructToMap(&request) | ||
260 | // 1.合约详情 | 275 | // 1.合约详情 |
261 | - contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext) | 276 | + contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) |
262 | if _, ok := queryOptions["contractId"]; !ok { | 277 | if _, ok := queryOptions["contractId"]; !ok { |
263 | return nil, fmt.Errorf("合约ID(contractId)不能为空") | 278 | return nil, fmt.Errorf("合约ID(contractId)不能为空") |
264 | } | 279 | } |
@@ -294,15 +309,16 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s | @@ -294,15 +309,16 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s | ||
294 | } | 309 | } |
295 | } | 310 | } |
296 | } | 311 | } |
297 | - | ||
298 | - orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext) | ||
299 | - _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds}) | ||
300 | - if err != nil { | ||
301 | - return res, err | ||
302 | - } | ||
303 | var mapOrderGoods = make(map[int64]*domain.OrderGood) | 312 | var mapOrderGoods = make(map[int64]*domain.OrderGood) |
304 | - for i := range orderGoods { | ||
305 | - mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i] | 313 | + if len(orderGoodIds) > 0 { |
314 | + orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext) | ||
315 | + _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds}) | ||
316 | + if err != nil { | ||
317 | + return res, err | ||
318 | + } | ||
319 | + for i := range orderGoods { | ||
320 | + mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i] | ||
321 | + } | ||
306 | } | 322 | } |
307 | 323 | ||
308 | var dividends = make([]interface{}, 0) | 324 | var dividends = make([]interface{}, 0) |
-
请 注册 或 登录 后发表评论