正在显示
29 个修改的文件
包含
1457 行增加
和
14 行删除
@@ -29,22 +29,31 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | @@ -29,22 +29,31 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | ||
29 | defer func() { | 29 | defer func() { |
30 | transactionContext.RollbackTransaction() | 30 | transactionContext.RollbackTransaction() |
31 | }() | 31 | }() |
32 | + | ||
33 | + userServiceGateway, err := factory.CreateUserServiceGateway(nil) | ||
34 | + if err != nil { | ||
35 | + fmt.Println(err.Error()) | ||
36 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
37 | + } | ||
38 | + | ||
39 | + //userServiceGateway.GetUser(createCooperationContractCommand.SponsorUid) | ||
40 | + | ||
32 | newCooperationContract := &domain.CooperationContract{ | 41 | newCooperationContract := &domain.CooperationContract{ |
33 | CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription, | 42 | CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription, |
34 | CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, | 43 | CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, |
35 | - CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber, | ||
36 | - DepartmentNumber: createCooperationContractCommand.DepartmentNumber, | 44 | + //CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber, |
45 | + //DepartmentNumber: createCooperationContractCommand.DepartmentNumber, | ||
37 | CooperationContractUndertakerType: createCooperationContractCommand.CooperationContractUndertakerType, | 46 | CooperationContractUndertakerType: createCooperationContractCommand.CooperationContractUndertakerType, |
38 | CooperationContractName: createCooperationContractCommand.CooperationContractName, | 47 | CooperationContractName: createCooperationContractCommand.CooperationContractName, |
39 | - CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber, | ||
40 | - SponsorUid: createCooperationContractCommand.SponsorUid, | ||
41 | - DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules, | ||
42 | - MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules, | ||
43 | - Undertakers: createCooperationContractCommand.Undertakers, | ||
44 | - Relevants: createCooperationContractCommand.Relevants, | ||
45 | - CompanyId: createCooperationContractCommand.CompanyId, | ||
46 | - OrgId: createCooperationContractCommand.OrgId, | ||
47 | - UserId: createCooperationContractCommand.UserId, | 48 | + //CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber, |
49 | + //SponsorUid: createCooperationContractCommand.SponsorUid, | ||
50 | + //DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules, | ||
51 | + //MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules, | ||
52 | + //Undertakers: createCooperationContractCommand.Undertakers, | ||
53 | + //Relevants: createCooperationContractCommand.Relevants, | ||
54 | + //CompanyId: createCooperationContractCommand.CompanyId, | ||
55 | + //OrgId: createCooperationContractCommand.OrgId, | ||
56 | + //UserId: createCooperationContractCommand.UserId, | ||
48 | } | 57 | } |
49 | var cooperationContractRepository domain.CooperationContractRepository | 58 | var cooperationContractRepository domain.CooperationContractRepository |
50 | if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ | 59 | if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type CreateCreditAccountCommand struct { | ||
12 | + // 公司ID,通过集成REST上下文获取 | ||
13 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
14 | + // 组织机构ID | ||
15 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
16 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
17 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
18 | +} | ||
19 | + | ||
20 | +func (createCreditAccountCommand *CreateCreditAccountCommand) Valid(validation *validation.Validation) { | ||
21 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
22 | +} | ||
23 | + | ||
24 | +func (createCreditAccountCommand *CreateCreditAccountCommand) ValidateCommand() error { | ||
25 | + valid := validation.Validation{} | ||
26 | + b, err := valid.Valid(createCreditAccountCommand) | ||
27 | + if err != nil { | ||
28 | + return err | ||
29 | + } | ||
30 | + if !b { | ||
31 | + elem := reflect.TypeOf(createCreditAccountCommand).Elem() | ||
32 | + for _, validErr := range valid.Errors { | ||
33 | + field, isExist := elem.FieldByName(validErr.Field) | ||
34 | + if isExist { | ||
35 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
36 | + } else { | ||
37 | + return fmt.Errorf(validErr.Message) | ||
38 | + } | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type PayCreditAccountCommand struct { | ||
12 | + // 账期结算实付金额 | ||
13 | + ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"` | ||
14 | + // 备注 | ||
15 | + Remarks string `cname:"备注" json:"remarks" valid:"Required"` | ||
16 | + // 公司ID,通过集成REST上下文获取 | ||
17 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
18 | + // 组织机构ID | ||
19 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
20 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
21 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) { | ||
25 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(payCreditAccountCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(payCreditAccountCommand).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type RemoveCreditAccountCommand struct { | ||
12 | + // 账期结算单ID | ||
13 | + CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,string" valid:"Required"` | ||
14 | + // 公司ID,通过集成REST上下文获取 | ||
15 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
16 | + // 组织机构ID | ||
17 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
18 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
19 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
20 | +} | ||
21 | + | ||
22 | +func (removeCreditAccountCommand *RemoveCreditAccountCommand) Valid(validation *validation.Validation) { | ||
23 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (removeCreditAccountCommand *RemoveCreditAccountCommand) ValidateCommand() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(removeCreditAccountCommand) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(removeCreditAccountCommand).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateCreditAccountCommand struct { | ||
12 | + // 账期结算单ID | ||
13 | + CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,string" valid:"Required"` | ||
14 | + // 公司ID,通过集成REST上下文获取 | ||
15 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
16 | + // 组织机构ID | ||
17 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
18 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
19 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
20 | +} | ||
21 | + | ||
22 | +func (updateCreditAccountCommand *UpdateCreditAccountCommand) Valid(validation *validation.Validation) { | ||
23 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (updateCreditAccountCommand *UpdateCreditAccountCommand) ValidateCommand() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(updateCreditAccountCommand) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(updateCreditAccountCommand).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type CreditAccountRankingQuery struct { | ||
12 | + // 公司ID,通过集成REST上下文获取 | ||
13 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
14 | + // 组织机构ID | ||
15 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
16 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
17 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
18 | + // 统计周期 | ||
19 | + Period string `cname:"统计周期" json:"period,omitempty"` | ||
20 | +} | ||
21 | + | ||
22 | +func (creditAccountRankingQuery *CreditAccountRankingQuery) Valid(validation *validation.Validation) { | ||
23 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (creditAccountRankingQuery *CreditAccountRankingQuery) ValidateQuery() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(creditAccountRankingQuery) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(creditAccountRankingQuery).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetCreditAccountQuery struct { | ||
12 | + // 账期结算单ID | ||
13 | + CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId,string" valid:"Required"` | ||
14 | + // 公司ID,通过集成REST上下文获取 | ||
15 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
16 | + // 组织机构ID | ||
17 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
18 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
19 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
20 | +} | ||
21 | + | ||
22 | +func (getCreditAccountQuery *GetCreditAccountQuery) Valid(validation *validation.Validation) { | ||
23 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (getCreditAccountQuery *GetCreditAccountQuery) ValidateQuery() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(getCreditAccountQuery) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(getCreditAccountQuery).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type ListCreditAccountQuery struct { | ||
12 | + // 查询偏离量 | ||
13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
14 | + // 查询限制 | ||
15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
16 | + // 公司ID,通过集成REST上下文获取 | ||
17 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
18 | + // 组织机构ID | ||
19 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
20 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
21 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (listCreditAccountQuery *ListCreditAccountQuery) Valid(validation *validation.Validation) { | ||
25 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (listCreditAccountQuery *ListCreditAccountQuery) ValidateQuery() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(listCreditAccountQuery) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(listCreditAccountQuery).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type SearchCreditAccountQuery struct { | ||
13 | + // 账期结算单号 | ||
14 | + CreditAccountOrderNum string `cname:"账期结算单号" json:"creditAccountOrderNum" valid:"Required"` | ||
15 | + // 参与人姓名 | ||
16 | + ParticipatorName string `cname:"参与人姓名" json:"participatorName,omitempty"` | ||
17 | + // 公司ID,通过集成REST上下文获取 | ||
18 | + CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` | ||
19 | + // 组织机构ID | ||
20 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
21 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
22 | + UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"` | ||
23 | + // 账期结算支付状态,1待支付,2已支付,APP端结算记录返回已结算的账期结算单 | ||
24 | + PaymentStatus int32 `cname:"账期结算支付状态,1待支付,2已支付,APP端结算记录返回已结算的账期结算单" json:"paymentStatus" valid:"Required"` | ||
25 | + // 结算周期,按年“2021”或者按月结算”2021-07“ | ||
26 | + Period time.Time `cname:"结算周期,按年“2021”或者按月结算”2021-07“" json:"period,omitempty"` | ||
27 | +} | ||
28 | + | ||
29 | +func (searchCreditAccountQuery *SearchCreditAccountQuery) Valid(validation *validation.Validation) { | ||
30 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
31 | +} | ||
32 | + | ||
33 | +func (searchCreditAccountQuery *SearchCreditAccountQuery) ValidateQuery() error { | ||
34 | + valid := validation.Validation{} | ||
35 | + b, err := valid.Valid(searchCreditAccountQuery) | ||
36 | + if err != nil { | ||
37 | + return err | ||
38 | + } | ||
39 | + if !b { | ||
40 | + elem := reflect.TypeOf(searchCreditAccountQuery).Elem() | ||
41 | + for _, validErr := range valid.Errors { | ||
42 | + field, isExist := elem.FieldByName(validErr.Field) | ||
43 | + if isExist { | ||
44 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
45 | + } else { | ||
46 | + return fmt.Errorf(validErr.Message) | ||
47 | + } | ||
48 | + } | ||
49 | + } | ||
50 | + return nil | ||
51 | +} |
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/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/command" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/query" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 账期结算单服务 | ||
14 | +type CreditAccountService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 创建账期结算单服务 | ||
18 | +func (creditAccountService *CreditAccountService) CreateCreditAccount(createCreditAccountCommand *command.CreateCreditAccountCommand) (interface{}, error) { | ||
19 | + if err := createCreditAccountCommand.ValidateCommand(); err != nil { | ||
20 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
21 | + } | ||
22 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
23 | + if err != nil { | ||
24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
25 | + } | ||
26 | + if err := transactionContext.StartTransaction(); err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + defer func() { | ||
30 | + transactionContext.RollbackTransaction() | ||
31 | + }() | ||
32 | + newCreditAccount := &domain.CreditAccount{ | ||
33 | + //CompanyId: createCreditAccountCommand.CompanyId, | ||
34 | + //OrgId: createCreditAccountCommand.OrgId, | ||
35 | + //UserId: createCreditAccountCommand.UserId, | ||
36 | + } | ||
37 | + var creditAccountRepository domain.CreditAccountRepository | ||
38 | + if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ | ||
39 | + "transactionContext": transactionContext, | ||
40 | + }); err != nil { | ||
41 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
42 | + } else { | ||
43 | + creditAccountRepository = value | ||
44 | + } | ||
45 | + if creditAccount, err := creditAccountRepository.Save(newCreditAccount); err != nil { | ||
46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | + } else { | ||
48 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
49 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
50 | + } | ||
51 | + return creditAccount, nil | ||
52 | + } | ||
53 | +} | ||
54 | + | ||
55 | +// 账期结算单排名 | ||
56 | +func (creditAccountService *CreditAccountService) CreditAccountRanking(creditAccountRankingQuery *query.CreditAccountRankingQuery) (interface{}, error) { | ||
57 | + if err := creditAccountRankingQuery.ValidateQuery(); err != nil { | ||
58 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
59 | + } | ||
60 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
61 | + if err != nil { | ||
62 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
63 | + } | ||
64 | + if err := transactionContext.StartTransaction(); err != nil { | ||
65 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
66 | + } | ||
67 | + defer func() { | ||
68 | + transactionContext.RollbackTransaction() | ||
69 | + }() | ||
70 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | + } | ||
73 | + return nil, nil | ||
74 | +} | ||
75 | + | ||
76 | +// 返回账期结算单服务 | ||
77 | +func (creditAccountService *CreditAccountService) GetCreditAccount(getCreditAccountQuery *query.GetCreditAccountQuery) (interface{}, error) { | ||
78 | + if err := getCreditAccountQuery.ValidateQuery(); err != nil { | ||
79 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
80 | + } | ||
81 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
82 | + if err != nil { | ||
83 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
84 | + } | ||
85 | + if err := transactionContext.StartTransaction(); err != nil { | ||
86 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
87 | + } | ||
88 | + defer func() { | ||
89 | + transactionContext.RollbackTransaction() | ||
90 | + }() | ||
91 | + var creditAccountRepository domain.CreditAccountRepository | ||
92 | + if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ | ||
93 | + "transactionContext": transactionContext, | ||
94 | + }); err != nil { | ||
95 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
96 | + } else { | ||
97 | + creditAccountRepository = value | ||
98 | + } | ||
99 | + creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": getCreditAccountQuery.CreditAccountId}) | ||
100 | + if err != nil { | ||
101 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
102 | + } | ||
103 | + if creditAccount == nil { | ||
104 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCreditAccountQuery.CreditAccountId))) | ||
105 | + } else { | ||
106 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
107 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
108 | + } | ||
109 | + return creditAccount, nil | ||
110 | + } | ||
111 | +} | ||
112 | + | ||
113 | +// 返回账期结算单服务列表 | ||
114 | +func (creditAccountService *CreditAccountService) ListCreditAccount(listCreditAccountQuery *query.ListCreditAccountQuery) (interface{}, error) { | ||
115 | + if err := listCreditAccountQuery.ValidateQuery(); err != nil { | ||
116 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
117 | + } | ||
118 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
119 | + if err != nil { | ||
120 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
121 | + } | ||
122 | + if err := transactionContext.StartTransaction(); err != nil { | ||
123 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
124 | + } | ||
125 | + defer func() { | ||
126 | + transactionContext.RollbackTransaction() | ||
127 | + }() | ||
128 | + var creditAccountRepository domain.CreditAccountRepository | ||
129 | + if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ | ||
130 | + "transactionContext": transactionContext, | ||
131 | + }); err != nil { | ||
132 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
133 | + } else { | ||
134 | + creditAccountRepository = value | ||
135 | + } | ||
136 | + if count, creditAccounts, err := creditAccountRepository.Find(tool_funs.SimpleStructToMap(listCreditAccountQuery)); err != nil { | ||
137 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
138 | + } else { | ||
139 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
140 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
141 | + } | ||
142 | + return map[string]interface{}{ | ||
143 | + "count": count, | ||
144 | + "creditAccounts": creditAccounts, | ||
145 | + }, nil | ||
146 | + } | ||
147 | +} | ||
148 | + | ||
149 | +// 支付账期结算(支付分红) | ||
150 | +func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAccountCommand *command.PayCreditAccountCommand) (interface{}, error) { | ||
151 | + if err := payCreditAccountCommand.ValidateCommand(); err != nil { | ||
152 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
153 | + } | ||
154 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
155 | + if err != nil { | ||
156 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
157 | + } | ||
158 | + if err := transactionContext.StartTransaction(); err != nil { | ||
159 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
160 | + } | ||
161 | + defer func() { | ||
162 | + transactionContext.RollbackTransaction() | ||
163 | + }() | ||
164 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
165 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
166 | + } | ||
167 | + return nil, nil | ||
168 | +} | ||
169 | + | ||
170 | +// 移除账期结算单服务 | ||
171 | +func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCreditAccountCommand *command.RemoveCreditAccountCommand) (interface{}, error) { | ||
172 | + if err := removeCreditAccountCommand.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 creditAccountRepository domain.CreditAccountRepository | ||
186 | + if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ | ||
187 | + "transactionContext": transactionContext, | ||
188 | + }); err != nil { | ||
189 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
190 | + } else { | ||
191 | + creditAccountRepository = value | ||
192 | + } | ||
193 | + creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": removeCreditAccountCommand.CreditAccountId}) | ||
194 | + if err != nil { | ||
195 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
196 | + } | ||
197 | + if creditAccount == nil { | ||
198 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCreditAccountCommand.CreditAccountId))) | ||
199 | + } | ||
200 | + if creditAccount, err := creditAccountRepository.Remove(creditAccount); 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 creditAccount, nil | ||
207 | + } | ||
208 | +} | ||
209 | + | ||
210 | +// 查询账期结算单 | ||
211 | +func (creditAccountService *CreditAccountService) SearchCreditAccount(searchCreditAccountQuery *query.SearchCreditAccountQuery) (interface{}, error) { | ||
212 | + if err := searchCreditAccountQuery.ValidateQuery(); err != nil { | ||
213 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
214 | + } | ||
215 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
216 | + if err != nil { | ||
217 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
218 | + } | ||
219 | + if err := transactionContext.StartTransaction(); err != nil { | ||
220 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
221 | + } | ||
222 | + defer func() { | ||
223 | + transactionContext.RollbackTransaction() | ||
224 | + }() | ||
225 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
226 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
227 | + } | ||
228 | + return nil, nil | ||
229 | +} | ||
230 | + | ||
231 | +// 更新账期结算单服务 | ||
232 | +func (creditAccountService *CreditAccountService) UpdateCreditAccount(updateCreditAccountCommand *command.UpdateCreditAccountCommand) (interface{}, error) { | ||
233 | + if err := updateCreditAccountCommand.ValidateCommand(); err != nil { | ||
234 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
235 | + } | ||
236 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
237 | + if err != nil { | ||
238 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
239 | + } | ||
240 | + if err := transactionContext.StartTransaction(); err != nil { | ||
241 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
242 | + } | ||
243 | + defer func() { | ||
244 | + transactionContext.RollbackTransaction() | ||
245 | + }() | ||
246 | + var creditAccountRepository domain.CreditAccountRepository | ||
247 | + if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ | ||
248 | + "transactionContext": transactionContext, | ||
249 | + }); err != nil { | ||
250 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
251 | + } else { | ||
252 | + creditAccountRepository = value | ||
253 | + } | ||
254 | + creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": updateCreditAccountCommand.CreditAccountId}) | ||
255 | + if err != nil { | ||
256 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
257 | + } | ||
258 | + if creditAccount == nil { | ||
259 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCreditAccountCommand.CreditAccountId))) | ||
260 | + } | ||
261 | + if err := creditAccount.Update(tool_funs.SimpleStructToMap(updateCreditAccountCommand)); err != nil { | ||
262 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
263 | + } | ||
264 | + if creditAccount, err := creditAccountRepository.Save(creditAccount); err != nil { | ||
265 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
266 | + } else { | ||
267 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
268 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
269 | + } | ||
270 | + return creditAccount, nil | ||
271 | + } | ||
272 | +} | ||
273 | + | ||
274 | +func NewCreditAccountService(options map[string]interface{}) *CreditAccountService { | ||
275 | + newCreditAccountService := &CreditAccountService{} | ||
276 | + return newCreditAccountService | ||
277 | +} |
@@ -77,3 +77,11 @@ func CreateCooperationContractChangeLogRepository(options map[string]interface{} | @@ -77,3 +77,11 @@ func CreateCooperationContractChangeLogRepository(options map[string]interface{} | ||
77 | } | 77 | } |
78 | return repository.NewCooperationContractChangeLogRepository(transactionContext) | 78 | return repository.NewCooperationContractChangeLogRepository(transactionContext) |
79 | } | 79 | } |
80 | + | ||
81 | +func CreateCreditAccountRepository(options map[string]interface{}) (domain.CreditAccountRepository, error) { | ||
82 | + var transactionContext *pg.TransactionContext | ||
83 | + if value, ok := options["transactionContext"]; ok { | ||
84 | + transactionContext = value.(*pg.TransactionContext) | ||
85 | + } | ||
86 | + return repository.NewCreditAccountRepository(transactionContext) | ||
87 | +} |
pkg/application/factory/service_gateway.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import serviceGateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway" | ||
4 | + | ||
5 | +func CreateUserServiceGateway(options map[string]interface{}) (serviceGateway.UserServiceGateway, error) { | ||
6 | + return serviceGateway.NewHttplibUserServiceGateway(), nil | ||
7 | +} |
pkg/domain/credit_account.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 账期结算单实体 | ||
6 | +type CreditAccount struct { | ||
7 | + // 账期结算单ID | ||
8 | + CreditAccountId int64 `json:"creditAccountId,string"` | ||
9 | + // 账期结算实付金额 | ||
10 | + ActuallyPaidAmount float64 `json:"actuallyPaidAmount"` | ||
11 | + // 账期结算单号 | ||
12 | + CreditAccountOrderNum string `json:"creditAccountOrderNum"` | ||
13 | + // 账期结算支付状态,1待支付,2已支付 | ||
14 | + PaymentStatus int32 `json:"paymentStatus"` | ||
15 | + // 共创账期结算支付时间 | ||
16 | + PaymentTime time.Time `json:"paymentTime"` | ||
17 | + // 账期结算金额 | ||
18 | + SettlementAmount float64 `json:"settlementAmount"` | ||
19 | + // 共创账期结算时间 | ||
20 | + SettlementTime time.Time `json:"settlementTime"` | ||
21 | + // 共创合约编号 | ||
22 | + CooperationContractNumber string `json:"cooperationContractNumber"` | ||
23 | + // 参与人uid,包括承接人、推荐人、关联业务员 | ||
24 | + Participator []int64 `json:"participator"` | ||
25 | + // 支付凭证附件 | ||
26 | + PaymentDocumentAttachment *Attachment `json:"paymentDocumentAttachment"` | ||
27 | + // 数据所属组织机构 | ||
28 | + Org *Org `json:"org"` | ||
29 | + // 公司 | ||
30 | + Company *Company `json:"company"` | ||
31 | + // 操作人 | ||
32 | + Operator *User `json:"operator"` | ||
33 | + // 操作时间 | ||
34 | + OperateTime time.Time `json:"operateTime"` | ||
35 | + // 创建时间 | ||
36 | + CreatedAt time.Time `json:"createdAt"` | ||
37 | + // 删除时间 | ||
38 | + DeletedAt time.Time `json:"deletedAt"` | ||
39 | + // 更新时间 | ||
40 | + UpdatedAt time.Time `json:"updatedAt"` | ||
41 | +} | ||
42 | + | ||
43 | +type CreditAccountRepository interface { | ||
44 | + Save(creditAccount *CreditAccount) (*CreditAccount, error) | ||
45 | + Remove(creditAccount *CreditAccount) (*CreditAccount, error) | ||
46 | + FindOne(queryOptions map[string]interface{}) (*CreditAccount, error) | ||
47 | + Find(queryOptions map[string]interface{}) (int64, []*CreditAccount, error) | ||
48 | +} | ||
49 | + | ||
50 | +func (creditAccount *CreditAccount) Identify() interface{} { | ||
51 | + if creditAccount.CreditAccountId == 0 { | ||
52 | + return nil | ||
53 | + } | ||
54 | + return creditAccount.CreditAccountId | ||
55 | +} | ||
56 | + | ||
57 | +func (creditAccount *CreditAccount) Update(data map[string]interface{}) error { | ||
58 | + if actuallyPaidAmount, ok := data["actuallyPaidAmount"]; ok { | ||
59 | + creditAccount.ActuallyPaidAmount = actuallyPaidAmount.(float64) | ||
60 | + } | ||
61 | + if creditAccountOrderNum, ok := data["creditAccountOrderNum"]; ok { | ||
62 | + creditAccount.CreditAccountOrderNum = creditAccountOrderNum.(string) | ||
63 | + } | ||
64 | + if paymentStatus, ok := data["paymentStatus"]; ok { | ||
65 | + creditAccount.PaymentStatus = paymentStatus.(int32) | ||
66 | + } | ||
67 | + return nil | ||
68 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type CreditAccount struct { | ||
9 | + tableName string `comment:"账期结算单实体" pg:"credit_accounts,alias:credit_account"` | ||
10 | + // 账期结算单ID | ||
11 | + CreditAccountId int64 `comment:"账期结算单ID" pg:"pk:credit_account_id"` | ||
12 | + // 账期结算实付金额 | ||
13 | + ActuallyPaidAmount float64 `comment:"账期结算实付金额"` | ||
14 | + // 账期结算单号 | ||
15 | + CreditAccountOrderNum string `comment:"账期结算单号"` | ||
16 | + // 账期结算支付状态,1待支付,2已支付 | ||
17 | + PaymentStatus int32 `comment:"账期结算支付状态,1待支付,2已支付"` | ||
18 | + // 共创账期结算支付时间 | ||
19 | + PaymentTime time.Time `comment:"共创账期结算支付时间"` | ||
20 | + // 账期结算金额 | ||
21 | + SettlementAmount float64 `comment:"账期结算金额"` | ||
22 | + // 共创账期结算时间 | ||
23 | + SettlementTime time.Time `comment:"共创账期结算时间"` | ||
24 | + // 共创合约编号 | ||
25 | + CooperationContractNumber string `comment:"共创合约编号"` | ||
26 | + // 参与人uid,包括承接人、推荐人、关联业务员 | ||
27 | + Participator []int64 `comment:"参与人uid,包括承接人、推荐人、关联业务员" pg:",array"` | ||
28 | + // 支付凭证附件 | ||
29 | + PaymentDocumentAttachment *domain.Attachment `comment:"支付凭证附件"` | ||
30 | + // 数据所属组织机构 | ||
31 | + Org *domain.Org `comment:"数据所属组织机构"` | ||
32 | + // 公司 | ||
33 | + Company *domain.Company `comment:"公司"` | ||
34 | + // 操作人 | ||
35 | + Operator *domain.User `comment:"操作人"` | ||
36 | + // 操作时间 | ||
37 | + OperateTime time.Time `comment:"操作时间"` | ||
38 | + // 创建时间 | ||
39 | + CreatedAt time.Time `comment:"创建时间"` | ||
40 | + // 删除时间 | ||
41 | + DeletedAt time.Time `comment:"删除时间"` | ||
42 | + // 更新时间 | ||
43 | + UpdatedAt time.Time `comment:"更新时间"` | ||
44 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToCreditAccountDomainModelFromPgModels(creditAccountModel *models.CreditAccount) (*domain.CreditAccount, error) { | ||
9 | + return &domain.CreditAccount{ | ||
10 | + CreditAccountId: creditAccountModel.CreditAccountId, | ||
11 | + ActuallyPaidAmount: creditAccountModel.ActuallyPaidAmount, | ||
12 | + CreditAccountOrderNum: creditAccountModel.CreditAccountOrderNum, | ||
13 | + PaymentStatus: creditAccountModel.PaymentStatus, | ||
14 | + PaymentTime: creditAccountModel.PaymentTime, | ||
15 | + SettlementAmount: creditAccountModel.SettlementAmount, | ||
16 | + SettlementTime: creditAccountModel.SettlementTime, | ||
17 | + CooperationContractNumber: creditAccountModel.CooperationContractNumber, | ||
18 | + Participator: creditAccountModel.Participator, | ||
19 | + PaymentDocumentAttachment: creditAccountModel.PaymentDocumentAttachment, | ||
20 | + Org: creditAccountModel.Org, | ||
21 | + Company: creditAccountModel.Company, | ||
22 | + Operator: creditAccountModel.Operator, | ||
23 | + OperateTime: creditAccountModel.OperateTime, | ||
24 | + CreatedAt: creditAccountModel.CreatedAt, | ||
25 | + DeletedAt: creditAccountModel.DeletedAt, | ||
26 | + UpdatedAt: creditAccountModel.UpdatedAt, | ||
27 | + }, nil | ||
28 | +} |
@@ -2,6 +2,7 @@ package repository | @@ -2,6 +2,7 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/go-pg/pg/v10" | ||
5 | 6 | ||
6 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -48,7 +49,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF | @@ -48,7 +49,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF | ||
48 | if err != nil { | 49 | if err != nil { |
49 | return contractUndertakerFeedback, err | 50 | return contractUndertakerFeedback, err |
50 | } else { | 51 | } else { |
51 | - contractUndertakerFeedback.ContractUndertakerFeedbackId = contractUndertakerFeedbackId | 52 | + contractUndertakerFeedback.FeedbackId = contractUndertakerFeedbackId |
52 | } | 53 | } |
53 | if _, err := tx.QueryOne( | 54 | if _, err := tx.QueryOne( |
54 | pg.Scan( | 55 | pg.Scan( |
@@ -116,7 +117,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF | @@ -116,7 +117,7 @@ func (repository *ContractUndertakerFeedbackRepository) Save(contractUndertakerF | ||
116 | func (repository *ContractUndertakerFeedbackRepository) Remove(contractUndertakerFeedback *domain.ContractUndertakerFeedback) (*domain.ContractUndertakerFeedback, error) { | 117 | func (repository *ContractUndertakerFeedbackRepository) Remove(contractUndertakerFeedback *domain.ContractUndertakerFeedback) (*domain.ContractUndertakerFeedback, error) { |
117 | tx := repository.transactionContext.PgTx | 118 | tx := repository.transactionContext.PgTx |
118 | contractUndertakerFeedbackModel := new(models.ContractUndertakerFeedback) | 119 | contractUndertakerFeedbackModel := new(models.ContractUndertakerFeedback) |
119 | - contractUndertakerFeedbackModel.ContractUndertakerFeedbackId = contractUndertakerFeedback.Identify().(int64) | 120 | + contractUndertakerFeedbackModel.FeedbackId = contractUndertakerFeedback.Identify().(int64) |
120 | if _, err := tx.Model(contractUndertakerFeedbackModel).WherePK().Delete(); err != nil { | 121 | if _, err := tx.Model(contractUndertakerFeedbackModel).WherePK().Delete(); err != nil { |
121 | return contractUndertakerFeedback, err | 122 | return contractUndertakerFeedback, err |
122 | } | 123 | } |
@@ -134,7 +135,7 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map | @@ -134,7 +135,7 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map | ||
134 | return nil, err | 135 | return nil, err |
135 | } | 136 | } |
136 | } | 137 | } |
137 | - if contractUndertakerFeedbackModel.ContractUndertakerFeedbackId == 0 { | 138 | + if contractUndertakerFeedbackModel.FeedbackId == 0 { |
138 | return nil, nil | 139 | return nil, nil |
139 | } else { | 140 | } else { |
140 | return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel) | 141 | return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel) |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type CreditAccountRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *CreditAccountRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAccount) (*domain.CreditAccount, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "credit_account_id", | ||
30 | + "actually_paid_amount", | ||
31 | + "credit_account_order_num", | ||
32 | + "payment_status", | ||
33 | + "payment_time", | ||
34 | + "settlement_amount", | ||
35 | + "settlement_time", | ||
36 | + "cooperation_contract_number", | ||
37 | + "participator", | ||
38 | + "payment_document_attachment", | ||
39 | + "org", | ||
40 | + "company", | ||
41 | + "operator", | ||
42 | + "operate_time", | ||
43 | + "created_at", | ||
44 | + "deleted_at", | ||
45 | + "updated_at", | ||
46 | + } | ||
47 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
48 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
49 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
50 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "creditAccount_id") | ||
51 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
52 | + tx := repository.transactionContext.PgTx | ||
53 | + if creditAccount.Identify() == nil { | ||
54 | + creditAccountId, err := repository.nextIdentify() | ||
55 | + if err != nil { | ||
56 | + return creditAccount, err | ||
57 | + } else { | ||
58 | + creditAccount.CreditAccountId = creditAccountId | ||
59 | + } | ||
60 | + if _, err := tx.QueryOne( | ||
61 | + pg.Scan( | ||
62 | + &creditAccount.CreditAccountId, | ||
63 | + &creditAccount.ActuallyPaidAmount, | ||
64 | + &creditAccount.CreditAccountOrderNum, | ||
65 | + &creditAccount.PaymentStatus, | ||
66 | + &creditAccount.PaymentTime, | ||
67 | + &creditAccount.SettlementAmount, | ||
68 | + &creditAccount.SettlementTime, | ||
69 | + &creditAccount.CooperationContractNumber, | ||
70 | + pg.Array(&creditAccount.Participator), | ||
71 | + &creditAccount.PaymentDocumentAttachment, | ||
72 | + &creditAccount.Org, | ||
73 | + &creditAccount.Company, | ||
74 | + &creditAccount.Operator, | ||
75 | + &creditAccount.OperateTime, | ||
76 | + &creditAccount.CreatedAt, | ||
77 | + &creditAccount.DeletedAt, | ||
78 | + &creditAccount.UpdatedAt, | ||
79 | + ), | ||
80 | + fmt.Sprintf("INSERT INTO credit_accounts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
81 | + creditAccount.CreditAccountId, | ||
82 | + creditAccount.ActuallyPaidAmount, | ||
83 | + creditAccount.CreditAccountOrderNum, | ||
84 | + creditAccount.PaymentStatus, | ||
85 | + creditAccount.PaymentTime, | ||
86 | + creditAccount.SettlementAmount, | ||
87 | + creditAccount.SettlementTime, | ||
88 | + creditAccount.CooperationContractNumber, | ||
89 | + pg.Array(creditAccount.Participator), | ||
90 | + creditAccount.PaymentDocumentAttachment, | ||
91 | + creditAccount.Org, | ||
92 | + creditAccount.Company, | ||
93 | + creditAccount.Operator, | ||
94 | + creditAccount.OperateTime, | ||
95 | + creditAccount.CreatedAt, | ||
96 | + creditAccount.DeletedAt, | ||
97 | + creditAccount.UpdatedAt, | ||
98 | + ); err != nil { | ||
99 | + return creditAccount, err | ||
100 | + } | ||
101 | + } else { | ||
102 | + if _, err := tx.QueryOne( | ||
103 | + pg.Scan( | ||
104 | + &creditAccount.CreditAccountId, | ||
105 | + &creditAccount.ActuallyPaidAmount, | ||
106 | + &creditAccount.CreditAccountOrderNum, | ||
107 | + &creditAccount.PaymentStatus, | ||
108 | + &creditAccount.PaymentTime, | ||
109 | + &creditAccount.SettlementAmount, | ||
110 | + &creditAccount.SettlementTime, | ||
111 | + &creditAccount.CooperationContractNumber, | ||
112 | + pg.Array(&creditAccount.Participator), | ||
113 | + &creditAccount.PaymentDocumentAttachment, | ||
114 | + &creditAccount.Org, | ||
115 | + &creditAccount.Company, | ||
116 | + &creditAccount.Operator, | ||
117 | + &creditAccount.OperateTime, | ||
118 | + &creditAccount.CreatedAt, | ||
119 | + &creditAccount.DeletedAt, | ||
120 | + &creditAccount.UpdatedAt, | ||
121 | + ), | ||
122 | + fmt.Sprintf("UPDATE credit_accounts SET %s WHERE credit_account_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
123 | + creditAccount.CreditAccountId, | ||
124 | + creditAccount.ActuallyPaidAmount, | ||
125 | + creditAccount.CreditAccountOrderNum, | ||
126 | + creditAccount.PaymentStatus, | ||
127 | + creditAccount.PaymentTime, | ||
128 | + creditAccount.SettlementAmount, | ||
129 | + creditAccount.SettlementTime, | ||
130 | + creditAccount.CooperationContractNumber, | ||
131 | + pg.Array(creditAccount.Participator), | ||
132 | + creditAccount.PaymentDocumentAttachment, | ||
133 | + creditAccount.Org, | ||
134 | + creditAccount.Company, | ||
135 | + creditAccount.Operator, | ||
136 | + creditAccount.OperateTime, | ||
137 | + creditAccount.CreatedAt, | ||
138 | + creditAccount.DeletedAt, | ||
139 | + creditAccount.UpdatedAt, | ||
140 | + creditAccount.Identify(), | ||
141 | + ); err != nil { | ||
142 | + return creditAccount, err | ||
143 | + } | ||
144 | + } | ||
145 | + return creditAccount, nil | ||
146 | +} | ||
147 | +func (repository *CreditAccountRepository) Remove(creditAccount *domain.CreditAccount) (*domain.CreditAccount, error) { | ||
148 | + tx := repository.transactionContext.PgTx | ||
149 | + creditAccountModel := new(models.CreditAccount) | ||
150 | + creditAccountModel.CreditAccountId = creditAccount.Identify().(int64) | ||
151 | + if _, err := tx.Model(creditAccountModel).WherePK().Delete(); err != nil { | ||
152 | + return creditAccount, err | ||
153 | + } | ||
154 | + return creditAccount, nil | ||
155 | +} | ||
156 | +func (repository *CreditAccountRepository) FindOne(queryOptions map[string]interface{}) (*domain.CreditAccount, error) { | ||
157 | + tx := repository.transactionContext.PgTx | ||
158 | + creditAccountModel := new(models.CreditAccount) | ||
159 | + query := sqlbuilder.BuildQuery(tx.Model(creditAccountModel), queryOptions) | ||
160 | + query.SetWhereByQueryOption("credit_account.credit_account_id = ?", "creditAccountId") | ||
161 | + if err := query.First(); err != nil { | ||
162 | + if err.Error() == "pg: no rows in result set" { | ||
163 | + return nil, fmt.Errorf("没有此资源") | ||
164 | + } else { | ||
165 | + return nil, err | ||
166 | + } | ||
167 | + } | ||
168 | + if creditAccountModel.CreditAccountId == 0 { | ||
169 | + return nil, nil | ||
170 | + } else { | ||
171 | + return transform.TransformToCreditAccountDomainModelFromPgModels(creditAccountModel) | ||
172 | + } | ||
173 | +} | ||
174 | +func (repository *CreditAccountRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CreditAccount, error) { | ||
175 | + tx := repository.transactionContext.PgTx | ||
176 | + var creditAccountModels []*models.CreditAccount | ||
177 | + creditAccounts := make([]*domain.CreditAccount, 0) | ||
178 | + query := sqlbuilder.BuildQuery(tx.Model(&creditAccountModels), queryOptions) | ||
179 | + query.SetOffsetAndLimit(20) | ||
180 | + query.SetOrderDirect("credit_account_id", "DESC") | ||
181 | + if count, err := query.SelectAndCount(); err != nil { | ||
182 | + return 0, creditAccounts, err | ||
183 | + } else { | ||
184 | + for _, creditAccountModel := range creditAccountModels { | ||
185 | + if creditAccount, err := transform.TransformToCreditAccountDomainModelFromPgModels(creditAccountModel); err != nil { | ||
186 | + return 0, creditAccounts, err | ||
187 | + } else { | ||
188 | + creditAccounts = append(creditAccounts, creditAccount) | ||
189 | + } | ||
190 | + } | ||
191 | + return int64(count), creditAccounts, nil | ||
192 | + } | ||
193 | +} | ||
194 | +func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionContext) (*CreditAccountRepository, error) { | ||
195 | + if transactionContext == nil { | ||
196 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
197 | + } else { | ||
198 | + return &CreditAccountRepository{ | ||
199 | + transactionContext: transactionContext, | ||
200 | + }, nil | ||
201 | + } | ||
202 | +} |
@@ -19,6 +19,7 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string] | @@ -19,6 +19,7 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string] | ||
19 | response := make(map[string]interface{}) | 19 | response := make(map[string]interface{}) |
20 | request.ToJSON(&response) | 20 | request.ToJSON(&response) |
21 | data, err := serviceGateway.responseHandle(response) | 21 | data, err := serviceGateway.responseHandle(response) |
22 | + | ||
22 | return data, err | 23 | return data, err |
23 | } | 24 | } |
24 | 25 |
1 | +package translator |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/creditAccount/service" | ||
8 | +) | ||
9 | + | ||
10 | +type CreditAccountController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *CreditAccountController) CreateCreditAccount() { | ||
15 | + creditAccountService := service.NewCreditAccountService(nil) | ||
16 | + createCreditAccountCommand := &command.CreateCreditAccountCommand{} | ||
17 | + controller.Unmarshal(createCreditAccountCommand) | ||
18 | + data, err := creditAccountService.CreateCreditAccount(createCreditAccountCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *CreditAccountController) UpdateCreditAccount() { | ||
23 | + creditAccountService := service.NewCreditAccountService(nil) | ||
24 | + updateCreditAccountCommand := &command.UpdateCreditAccountCommand{} | ||
25 | + controller.Unmarshal(updateCreditAccountCommand) | ||
26 | + creditAccountId, _ := controller.GetInt64(":creditAccountId") | ||
27 | + updateCreditAccountCommand.CreditAccountId = creditAccountId | ||
28 | + data, err := creditAccountService.UpdateCreditAccount(updateCreditAccountCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *CreditAccountController) GetCreditAccount() { | ||
33 | + creditAccountService := service.NewCreditAccountService(nil) | ||
34 | + getCreditAccountQuery := &query.GetCreditAccountQuery{} | ||
35 | + creditAccountId, _ := controller.GetInt64(":creditAccountId") | ||
36 | + getCreditAccountQuery.CreditAccountId = creditAccountId | ||
37 | + data, err := creditAccountService.GetCreditAccount(getCreditAccountQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *CreditAccountController) RemoveCreditAccount() { | ||
42 | + creditAccountService := service.NewCreditAccountService(nil) | ||
43 | + removeCreditAccountCommand := &command.RemoveCreditAccountCommand{} | ||
44 | + controller.Unmarshal(removeCreditAccountCommand) | ||
45 | + creditAccountId, _ := controller.GetInt64(":creditAccountId") | ||
46 | + removeCreditAccountCommand.CreditAccountId = creditAccountId | ||
47 | + data, err := creditAccountService.RemoveCreditAccount(removeCreditAccountCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *CreditAccountController) SearchCreditAccount() { | ||
52 | + creditAccountService := service.NewCreditAccountService(nil) | ||
53 | + searchCreditAccountQuery := &query.SearchCreditAccountQuery{} | ||
54 | + data, err := creditAccountService.SearchCreditAccount(searchCreditAccountQuery) | ||
55 | + controller.Response(data, err) | ||
56 | +} | ||
57 | + | ||
58 | +func (controller *CreditAccountController) PayCreditAccount() { | ||
59 | + creditAccountService := service.NewCreditAccountService(nil) | ||
60 | + payCreditAccountCommand := &command.PayCreditAccountCommand{} | ||
61 | + controller.Unmarshal(payCreditAccountCommand) | ||
62 | + data, err := creditAccountService.PayCreditAccount(payCreditAccountCommand) | ||
63 | + controller.Response(data, err) | ||
64 | +} | ||
65 | + | ||
66 | +func (controller *CreditAccountController) ListCreditAccount() { | ||
67 | + creditAccountService := service.NewCreditAccountService(nil) | ||
68 | + listCreditAccountQuery := &query.ListCreditAccountQuery{} | ||
69 | + offset, _ := controller.GetInt("offset") | ||
70 | + listCreditAccountQuery.Offset = offset | ||
71 | + limit, _ := controller.GetInt("limit") | ||
72 | + listCreditAccountQuery.Limit = limit | ||
73 | + data, err := creditAccountService.ListCreditAccount(listCreditAccountQuery) | ||
74 | + controller.Response(data, err) | ||
75 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/credit-accounts/", &controllers.CreditAccountController{}, "Post:CreateCreditAccount") | ||
10 | + web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Put:UpdateCreditAccount") | ||
11 | + web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Get:GetCreditAccount") | ||
12 | + web.Router("/credit-accounts/:creditAccountId", &controllers.CreditAccountController{}, "Delete:RemoveCreditAccount") | ||
13 | + web.Router("/credit-accounts/search", &controllers.CreditAccountController{}, "Post:SearchCreditAccount") | ||
14 | + web.Router("/credit-accounts/pay", &controllers.CreditAccountController{}, "Post:PayCreditAccount") | ||
15 | + web.Router("/credit-accounts/", &controllers.CreditAccountController{}, "Get:ListCreditAccount") | ||
16 | +} |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建账期结算单服务", func() { | ||
13 | + Describe("提交数据创建账期结算单服务", func() { | ||
14 | + Context("提交正确的新账期结算单实体数据", func() { | ||
15 | + It("返回账期结算单实体数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "companyId": "int64", | ||
19 | + "orgId": "int64", | ||
20 | + "userId": "int64", | ||
21 | + } | ||
22 | + httpExpect.POST("/credit-accounts/"). | ||
23 | + WithJSON(body). | ||
24 | + Expect(). | ||
25 | + Status(http.StatusOK). | ||
26 | + JSON(). | ||
27 | + Object(). | ||
28 | + ContainsKey("code").ValueEqual("code", 0). | ||
29 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
30 | + ContainsKey("data").Value("data").Object(). | ||
31 | + ContainsKey("creditAccountId").ValueNotEqual("creditAccountId", BeZero()) | ||
32 | + }) | ||
33 | + }) | ||
34 | + }) | ||
35 | + AfterEach(func() { | ||
36 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
37 | + Expect(err).NotTo(HaveOccurred()) | ||
38 | + }) | ||
39 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application" | ||
12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
13 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego" | ||
14 | +) | ||
15 | + | ||
16 | +func TestCreditAccount(t *testing.T) { | ||
17 | + RegisterFailHandler(Fail) | ||
18 | + RunSpecs(t, "Beego Port CreditAccount Correlations Test Case Suite") | ||
19 | +} | ||
20 | + | ||
21 | +var handler http.Handler | ||
22 | +var server *httptest.Server | ||
23 | + | ||
24 | +var _ = BeforeSuite(func() { | ||
25 | + handler = web.BeeApp.Handlers | ||
26 | + server = httptest.NewServer(handler) | ||
27 | +}) | ||
28 | + | ||
29 | +var _ = AfterSuite(func() { | ||
30 | + server.Close() | ||
31 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回账期结算单服务", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据creditAccountId参数返回账期结算单实体", func() { | ||
23 | + Context("传入有效的creditAccountId", func() { | ||
24 | + It("返回账期结算单实体数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/credit-accounts/{creditAccountId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回账期结算单服务列表", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回账期结算单实体列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回账期结算单实体数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/credit-accounts/"). | ||
27 | + WithQuery("offset", "int"). | ||
28 | + WithQuery("limit", "int"). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("count").ValueEqual("count", 1). | ||
37 | + ContainsKey("creditAccounts").Value("creditAccounts").Array() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("支付账期结算(支付分红)", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("支付账期结算(支付分红)", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "actuallyPaidAmount": "float64", | ||
28 | + "remarks": "string", | ||
29 | + "companyId": "int64", | ||
30 | + "orgId": "int64", | ||
31 | + "userId": "int64", | ||
32 | + } | ||
33 | + httpExpect.POST("/credit-accounts/pay"). | ||
34 | + WithJSON(body). | ||
35 | + Expect(). | ||
36 | + Status(http.StatusOK). | ||
37 | + JSON(). | ||
38 | + Object(). | ||
39 | + ContainsKey("code").ValueEqual("code", 0). | ||
40 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
41 | + ContainsKey("data").Value("data").Object() | ||
42 | + }) | ||
43 | + }) | ||
44 | + }) | ||
45 | + AfterEach(func() { | ||
46 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
47 | + Expect(err).NotTo(HaveOccurred()) | ||
48 | + }) | ||
49 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除账期结算单服务", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除账期结算单服务", func() { | ||
23 | + Context("传入有效的creditAccountId", func() { | ||
24 | + It("返回被移除账期结算单实体的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/credit-accounts/{creditAccountId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("查询账期结算单", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("查询账期结算单", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "creditAccountOrderNum": "string", | ||
28 | + "participatorName": "string", | ||
29 | + "companyId": "int64", | ||
30 | + "orgId": "int64", | ||
31 | + "userId": "int64", | ||
32 | + "paymentStatus": "int32", | ||
33 | + "period": "datetime", | ||
34 | + } | ||
35 | + httpExpect.POST("/credit-accounts/search"). | ||
36 | + WithJSON(body). | ||
37 | + Expect(). | ||
38 | + Status(http.StatusOK). | ||
39 | + JSON(). | ||
40 | + Object(). | ||
41 | + ContainsKey("code").ValueEqual("code", 0). | ||
42 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
43 | + ContainsKey("data").Value("data").Object() | ||
44 | + }) | ||
45 | + }) | ||
46 | + }) | ||
47 | + AfterEach(func() { | ||
48 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
49 | + Expect(err).NotTo(HaveOccurred()) | ||
50 | + }) | ||
51 | +}) |
1 | +package credit_account | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新账期结算单服务", func() { | ||
14 | + var creditAccountId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&creditAccountId), | ||
18 | + "INSERT INTO credit_accounts (credit_account_id, actually_paid_amount, credit_account_order_num, payment_status, payment_time, settlement_amount, settlement_time, cooperation_contract_number, participator, payment_document_attachment, org, company, operator, operate_time, created_at, deleted_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING credit_account_id", | ||
19 | + "testCreditAccountId", "testActuallyPaidAmount", "testCreditAccountOrderNum", "testPaymentStatus", "testPaymentTime", "testSettlementAmount", "testSettlementTime", "testCooperationContractNumber", "testParticipator", "testPaymentDocumentAttachment", "testOrg", "testCompany", "testOperator", "testOperateTime", "testCreatedAt", "testDeletedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新账期结算单服务", func() { | ||
23 | + Context("提交正确的账期结算单实体数据", func() { | ||
24 | + It("返回更新后的账期结算单实体数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "companyId": "int64", | ||
28 | + "orgId": "int64", | ||
29 | + "userId": "int64", | ||
30 | + } | ||
31 | + httpExpect.PUT("/credit-accounts/{creditAccountId}"). | ||
32 | + WithJSON(body). | ||
33 | + Expect(). | ||
34 | + Status(http.StatusOK). | ||
35 | + JSON(). | ||
36 | + Object(). | ||
37 | + ContainsKey("code").ValueEqual("code", 0). | ||
38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
39 | + ContainsKey("data").Value("data").Object(). | ||
40 | + ContainsKey("creditAccountId").ValueEqual("creditAccountId", creditAccountId) | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM credit_accounts WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
-
请 注册 或 登录 后发表评论