增加:增加模型 users partner_category business_bonus
正在显示
18 个修改的文件
包含
574 行增加
和
104 行删除
pkg/domain/business_bonus.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 业务分红信息 | ||
6 | +type BusinessBonus struct { | ||
7 | + // 唯一标识 | ||
8 | + Id int64 `json:"id"` | ||
9 | + // 公司编号 | ||
10 | + CompanyId int64 `json:"companyId"` | ||
11 | + // 合伙人信息Id | ||
12 | + PartnerInfoId string `json:"partnerInfoId"` | ||
13 | + // 应收分红 | ||
14 | + Bonus float64 `json:"bonus"` | ||
15 | + // 未收分红 | ||
16 | + BonusNot float64 `json:"bonusNot"` | ||
17 | + // 分红支出 | ||
18 | + BonusExpense float64 `json:"bonusExpense"` | ||
19 | + // 是否关闭【0;否】【1:是】 | ||
20 | + IsDisable int8 `json:"isDisable"` | ||
21 | + // 分红状态 1:待支付分红 2:已支付分红 | ||
22 | + BonusStatus int8 `json:"bonusStatus"` | ||
23 | + // 创建时间 | ||
24 | + CreateAt time.Time `json:"createAt"` | ||
25 | + // 更新时间 | ||
26 | + UpdateAt time.Time `json:"updateAt"` | ||
27 | + // 删除时间 | ||
28 | + DeleteAt time.Time `json:"deleteAt"` | ||
29 | +} | ||
30 | + | ||
31 | +type BusinessBonusRepository interface { | ||
32 | + Save(dm *BusinessBonus) (*BusinessBonus, error) | ||
33 | + Remove(dm *BusinessBonus) (*BusinessBonus, error) | ||
34 | + FindOne(queryOptions map[string]interface{}) (*BusinessBonus, error) | ||
35 | + Find(queryOptions map[string]interface{}) (int64, []*BusinessBonus, error) | ||
36 | +} | ||
37 | + | ||
38 | +func (m *BusinessBonus) Identify() interface{} { | ||
39 | + if m.Id == 0 { | ||
40 | + return nil | ||
41 | + } | ||
42 | + return m.Id | ||
43 | +} |
pkg/domain/company.go
已删除
100644 → 0
1 | -package domain | ||
2 | - | ||
3 | -type Company struct { | ||
4 | - Id int64 `json:"id"` | ||
5 | - Name string `json:"name"` | ||
6 | - Phone string `json:"phone"` | ||
7 | -} | ||
8 | - | ||
9 | -type CompanyRepository interface { | ||
10 | - Save(dm *Company) (*Company, error) | ||
11 | - Remove(dm *Company) (*Company, error) | ||
12 | - FindOne(queryOptions map[string]interface{}) (*Company, error) | ||
13 | - Find(queryOptions map[string]interface{}) (int64, []*Company, error) | ||
14 | -} |
pkg/domain/compnay.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 公司信息 | ||
6 | +type Company struct { | ||
7 | + // 唯一标识 | ||
8 | + Id int64 `json:"id"` | ||
9 | + // 名称 | ||
10 | + Name string `json:"name"` | ||
11 | + // 手机号码 | ||
12 | + Phone string `json:"phone"` | ||
13 | + // 公司logo | ||
14 | + Logo string `json:"logo"` | ||
15 | + // 备注 | ||
16 | + Remarks string `json:"remarks"` | ||
17 | + // 总后台的公司id | ||
18 | + AdminCompanyId int `json:"adminCompanyId"` | ||
19 | + // 状态 1正常 2禁用 | ||
20 | + Status int8 `json:"status"` | ||
21 | + // 创建时间 | ||
22 | + CreateAt time.Time `json:"createAt"` | ||
23 | + // 更新时间 | ||
24 | + UpdateAt time.Time `json:"updateAt"` | ||
25 | + // 删除时间 | ||
26 | + DeleteAt time.Time `json:"deleteAt"` | ||
27 | +} | ||
28 | + | ||
29 | +type CompanyRepository interface { | ||
30 | + Save(dm *Company) (*Company, error) | ||
31 | + Remove(dm *Company) (*Company, error) | ||
32 | + FindOne(queryOptions map[string]interface{}) (*Company, error) | ||
33 | + Find(queryOptions map[string]interface{}) (int64, []*Company, error) | ||
34 | +} | ||
35 | + | ||
36 | +func (m *Company) Identify() interface{} { | ||
37 | + if m.Id == 0 { | ||
38 | + return nil | ||
39 | + } | ||
40 | + return m.Id | ||
41 | +} |
pkg/domain/partner_category_info.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 合伙人分类信息 | ||
4 | +type PartnerCategoryInfo struct { | ||
5 | + // 唯一标识 | ||
6 | + Id int64 `json:"id"` | ||
7 | + // 名称 | ||
8 | + Name string `json:"name"` | ||
9 | +} | ||
10 | + | ||
11 | +type PartnerCategoryInfoRepository interface { | ||
12 | + Save(dm *PartnerCategoryInfo) (*PartnerCategoryInfo, error) | ||
13 | + Remove(dm *PartnerCategoryInfo) (*PartnerCategoryInfo, error) | ||
14 | + FindOne(queryOptions map[string]interface{}) (*PartnerCategoryInfo, error) | ||
15 | + Find(queryOptions map[string]interface{}) (int64, []*PartnerCategoryInfo, error) | ||
16 | +} | ||
17 | + | ||
18 | +func (m *PartnerCategoryInfo) Identify() interface{} { | ||
19 | + if m.Id == 0 { | ||
20 | + return nil | ||
21 | + } | ||
22 | + return m.Id | ||
23 | +} |
@@ -34,6 +34,8 @@ type PartnerInfo struct { | @@ -34,6 +34,8 @@ type PartnerInfo struct { | ||
34 | 34 | ||
35 | //关联业务员 | 35 | //关联业务员 |
36 | Salesman []*Salesman `json:"salesman"` | 36 | Salesman []*Salesman `json:"salesman"` |
37 | + //合伙人分类信息 | ||
38 | + PartnerCategoryInfos []*PartnerCategoryInfo `partnerCategoryInfos` | ||
37 | } | 39 | } |
38 | 40 | ||
39 | func (m *PartnerInfo) Identify() interface{} { | 41 | func (m *PartnerInfo) Identify() interface{} { |
@@ -86,7 +88,7 @@ func (m *PartnerInfo) PartnerCategoryInfo() *PartnerCategoryInfo { | @@ -86,7 +88,7 @@ func (m *PartnerInfo) PartnerCategoryInfo() *PartnerCategoryInfo { | ||
86 | break | 88 | break |
87 | } | 89 | } |
88 | return &PartnerCategoryInfo{ | 90 | return &PartnerCategoryInfo{ |
89 | - Id: m.PartnerCategory, | 91 | + Id: int64(m.PartnerCategory), |
90 | Name: name, | 92 | Name: name, |
91 | } | 93 | } |
92 | } | 94 | } |
@@ -96,11 +98,6 @@ func (m *PartnerInfo) IsEnable() bool { | @@ -96,11 +98,6 @@ func (m *PartnerInfo) IsEnable() bool { | ||
96 | return m.Status == 1 | 98 | return m.Status == 1 |
97 | } | 99 | } |
98 | 100 | ||
99 | -type PartnerCategoryInfo struct { | ||
100 | - Id int `json:"id"` | ||
101 | - Name string `json:"name"` | ||
102 | -} | ||
103 | - | ||
104 | type RegionInfo struct { | 101 | type RegionInfo struct { |
105 | RegionId int `json:"regionId"` | 102 | RegionId int `json:"regionId"` |
106 | RegionName string `json:"regionName"` | 103 | RegionName string `json:"regionName"` |
pkg/domain/users.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 用户信息 | ||
6 | +type Users struct { | ||
7 | + // 唯一标识 | ||
8 | + Id int64 `json:"id"` | ||
9 | + // 公司id | ||
10 | + CompanyId int64 `json:"companyId"` | ||
11 | + // 统一用户中心 uid | ||
12 | + OpenId int64 `json:"openId"` | ||
13 | + // 名称 | ||
14 | + Name string `json:"name"` | ||
15 | + // 性别:0保密 1男 2女 | ||
16 | + Sex int8 `json:"sex"` | ||
17 | + // 员工工号 | ||
18 | + JobNum string `json:"jobNum"` | ||
19 | + // 手机号码 | ||
20 | + Phone string `json:"phone"` | ||
21 | + // 私人手机号码 | ||
22 | + PrivatePhone string `json:"privatePhone"` | ||
23 | + // 邮箱 | ||
24 | + Email string `json:"email"` | ||
25 | + // 分机号 | ||
26 | + ExtensionNum string `json:"extensionNum"` | ||
27 | + // 入职时间 | ||
28 | + EntryTime time.Time `json:"entryTime"` | ||
29 | + // 工作地点 | ||
30 | + Workspace string `json:"workspace"` | ||
31 | + // 状态 1正常 2禁用 | ||
32 | + Status int8 `json:"status"` | ||
33 | + // 手机号 | ||
34 | + Avatar string `json:"avatar"` | ||
35 | + // 备注 | ||
36 | + Remarks string `json:"remarks"` | ||
37 | + // 是否为当前公司主管 1 是2 否 | ||
38 | + ChargeStatus int8 `json:"chargeStatus"` | ||
39 | + // 创建时间 | ||
40 | + CreateAt time.Time `json:"createAt"` | ||
41 | + // 更新时间 | ||
42 | + UpdateAt time.Time `json:"updateAt"` | ||
43 | + // 删除时间 | ||
44 | + DeleteAt time.Time `json:"deleteAt"` | ||
45 | + // 可查看的合伙人信息 | ||
46 | + AccessPartners []*PartnerInfo | ||
47 | +} | ||
48 | + | ||
49 | +type UsersRepository interface { | ||
50 | + Save(dm *Users) (*Users, error) | ||
51 | + Remove(dm *Users) (*Users, error) | ||
52 | + FindOne(queryOptions map[string]interface{}) (*Users, error) | ||
53 | + Find(queryOptions map[string]interface{}) (int64, []*Users, error) | ||
54 | +} | ||
55 | + | ||
56 | +func (m *Users) Identify() interface{} { | ||
57 | + if m.Id == 0 { | ||
58 | + return nil | ||
59 | + } | ||
60 | + return m.Id | ||
61 | +} |
@@ -25,16 +25,16 @@ func init() { | @@ -25,16 +25,16 @@ func init() { | ||
25 | //orm.RegisterTable((*models.OrderGood)(nil)) | 25 | //orm.RegisterTable((*models.OrderGood)(nil)) |
26 | if !constant.DISABLE_CREATE_TABLE { | 26 | if !constant.DISABLE_CREATE_TABLE { |
27 | for _, model := range []interface{}{ | 27 | for _, model := range []interface{}{ |
28 | - //(*models.Employee)(nil), | ||
29 | (*models.PartnerInfo)(nil), | 28 | (*models.PartnerInfo)(nil), |
30 | - (*models.Order)(nil), | ||
31 | - (*models.OrderPayment)(nil), | ||
32 | (*models.PartnerSubAccount)(nil), | 29 | (*models.PartnerSubAccount)(nil), |
33 | (*models.Company)(nil), | 30 | (*models.Company)(nil), |
34 | (*models.OrderBase)(nil), | 31 | (*models.OrderBase)(nil), |
35 | (*models.OrderGood)(nil), | 32 | (*models.OrderGood)(nil), |
36 | (*models.ImInfo)(nil), | 33 | (*models.ImInfo)(nil), |
37 | (*models.ImCustomerService)(nil), | 34 | (*models.ImCustomerService)(nil), |
35 | + (*models.BusinessBonus)(nil), | ||
36 | + (*models.PartnerCategoryInfo)(nil), | ||
37 | + (*models.Users)(nil), | ||
38 | } { | 38 | } { |
39 | err := DB.CreateTable(model, &orm.CreateTableOptions{ | 39 | err := DB.CreateTable(model, &orm.CreateTableOptions{ |
40 | Temp: false, | 40 | Temp: false, |
pkg/infrastructure/pg/models/company.go
已删除
100644 → 0
pkg/infrastructure/pg/models/order.go
已删除
100644 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
5 | - "time" | ||
6 | -) | ||
7 | - | ||
8 | -type Order struct { | ||
9 | - tableName struct{} `pg:"order"` | ||
10 | - //id | ||
11 | - Id int64 `pg:",pk"` | ||
12 | - //订单类型 1:实际订单 2:意向订单 | ||
13 | - OrderType int `pg:",notnull,default:1"` | ||
14 | - //订单编号 | ||
15 | - OrderCode string `pg:",notnull` | ||
16 | - //订单名称 | ||
17 | - OrderName string | ||
18 | - //订单状态 | ||
19 | - OrderStatus int `pg:",notnull,default:1"` | ||
20 | - //订单数量 | ||
21 | - OrderCount int | ||
22 | - //实际订单数量 | ||
23 | - OrderActualCount int | ||
24 | - //订单金额 | ||
25 | - OrderAmount float64 | ||
26 | - //订单实际金额 | ||
27 | - OrderActualAmount float64 | ||
28 | - //订单已支付金额(货款) | ||
29 | - OrderPaymentAmount float64 `pg:",notnull,default:0"` | ||
30 | - //订单区域信息 | ||
31 | - OrderRegionInfo *domain.RegionInfo | ||
32 | - | ||
33 | - Buyer *domain.Buyer | ||
34 | - //合伙人编号 | ||
35 | - PartnerId int64 | ||
36 | - //合伙人分红百分比 | ||
37 | - PartnerBonusPercent float64 | ||
38 | - //业务员分红百分比 | ||
39 | - SalesmanBonusPercent float64 | ||
40 | - | ||
41 | - //创建时间 | ||
42 | - CreateAt time.Time | ||
43 | - //更新时间 | ||
44 | - UpdateAt time.Time | ||
45 | - | ||
46 | - //上一次查看时间 已读情况 | ||
47 | - LastViewTime time.Time | ||
48 | - //订单更新理由 | ||
49 | - Reason string | ||
50 | -} |
1 | -package models | ||
2 | - | ||
3 | -import "time" | ||
4 | - | ||
5 | -type OrderPayment struct { | ||
6 | - tableName struct{} `pg:"order_payment"` | ||
7 | - //编号 | ||
8 | - Id int64 `pg:",pk"` | ||
9 | - //订单编号 | ||
10 | - OrderId int64 | ||
11 | - //合伙人编号 | ||
12 | - PartnerId int64 | ||
13 | - //支付货款 | ||
14 | - PaymentAmount float64 `pg:",notnull,default:0"` | ||
15 | - //分红金额 | ||
16 | - BonusAmount float64 | ||
17 | - //分红状态 1.等待支付分红 2.已支付分红 | ||
18 | - BonusStatus int `pg:",notnull,default:1"` | ||
19 | - //创建时间 | ||
20 | - CreateAt time.Time | ||
21 | - //更新时间 | ||
22 | - UpdateAt time.Time | ||
23 | -} |
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 业务分红信息 | ||
6 | +type BusinessBonus struct { | ||
7 | + tableName struct{} `pg:"business_bonus"` | ||
8 | + // 唯一标识 | ||
9 | + Id int64 | ||
10 | + // 公司编号 | ||
11 | + CompanyId int64 | ||
12 | + // 合伙人信息Id | ||
13 | + PartnerInfoId string | ||
14 | + // 应收分红 | ||
15 | + Bonus float64 | ||
16 | + // 未收分红 | ||
17 | + BonusNot float64 | ||
18 | + // 分红支出 | ||
19 | + BonusExpense float64 | ||
20 | + // 是否关闭【0;否】【1:是】 | ||
21 | + IsDisable int8 | ||
22 | + // 分红状态 1:待支付分红 2:已支付分红 | ||
23 | + BonusStatus int8 | ||
24 | + // 创建时间 | ||
25 | + CreateAt time.Time | ||
26 | + // 更新时间 | ||
27 | + UpdateAt time.Time | ||
28 | + // 删除时间 | ||
29 | + DeleteAt time.Time | ||
30 | +} |
pkg/infrastructure/pg/models/pg_company.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 公司信息 | ||
6 | +type Company struct { | ||
7 | + tableName struct{} `pg:"Company"` | ||
8 | + // 唯一标识 | ||
9 | + Id int64 | ||
10 | + // 名称 | ||
11 | + Name string | ||
12 | + // 手机号码 | ||
13 | + Phone string | ||
14 | + // 公司logo | ||
15 | + Logo string | ||
16 | + // 备注 | ||
17 | + Remarks string | ||
18 | + // 总后台的公司id | ||
19 | + AdminCompanyId int | ||
20 | + // 状态 1正常 2禁用 | ||
21 | + Status int8 | ||
22 | + // 创建时间 | ||
23 | + CreateAt time.Time | ||
24 | + // 更新时间 | ||
25 | + UpdateAt time.Time | ||
26 | + // 删除时间 | ||
27 | + DeleteAt time.Time | ||
28 | +} |
pkg/infrastructure/pg/models/pg_users.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +// 用户信息 | ||
9 | +type Users struct { | ||
10 | + tableName struct{} `pg:"users"` | ||
11 | + // 唯一标识 | ||
12 | + Id int64 | ||
13 | + // 公司id | ||
14 | + CompanyId int64 | ||
15 | + // 统一用户中心 uid | ||
16 | + OpenId int64 | ||
17 | + // 名称 | ||
18 | + Name string | ||
19 | + // 性别:0保密 1男 2女 | ||
20 | + Sex int8 | ||
21 | + // 员工工号 | ||
22 | + JobNum string | ||
23 | + // 手机号码 | ||
24 | + Phone string | ||
25 | + // 私人手机号码 | ||
26 | + PrivatePhone string | ||
27 | + // 邮箱 | ||
28 | + Email string | ||
29 | + // 分机号 | ||
30 | + ExtensionNum string | ||
31 | + // 入职时间 | ||
32 | + EntryTime time.Time | ||
33 | + // 工作地点 | ||
34 | + Workspace string | ||
35 | + // 状态 1正常 2禁用 | ||
36 | + Status int8 | ||
37 | + // 手机号 | ||
38 | + Avatar string | ||
39 | + // 备注 | ||
40 | + Remarks string | ||
41 | + // 是否为当前公司主管 1 是2 否 | ||
42 | + ChargeStatus int8 | ||
43 | + // 创建时间 | ||
44 | + CreateAt time.Time | ||
45 | + // 更新时间 | ||
46 | + UpdateAt time.Time | ||
47 | + // 删除时间 | ||
48 | + DeleteAt time.Time | ||
49 | + // 可查看的合伙人信息 | ||
50 | + AccessPartners []*domain.PartnerInfo | ||
51 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
8 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
9 | +) | ||
10 | + | ||
11 | +type BusinessBonusRepository struct { | ||
12 | + transactionContext *transaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +func (repository *BusinessBonusRepository) Save(dm *domain.BusinessBonus) (*domain.BusinessBonus, error) { | ||
16 | + var ( | ||
17 | + err error | ||
18 | + m = &models.BusinessBonus{} | ||
19 | + tx = repository.transactionContext.PgTx | ||
20 | + ) | ||
21 | + if err = GobModelTransform(m, dm); err != nil { | ||
22 | + return nil, err | ||
23 | + } | ||
24 | + if dm.Identify() == nil { | ||
25 | + if err = tx.Insert(m); err != nil { | ||
26 | + return nil, err | ||
27 | + } | ||
28 | + return dm, nil | ||
29 | + } | ||
30 | + if err = tx.Update(m); err != nil { | ||
31 | + return nil, err | ||
32 | + } | ||
33 | + return dm, nil | ||
34 | +} | ||
35 | + | ||
36 | +func (repository *BusinessBonusRepository) Remove(BusinessBonus *domain.BusinessBonus) (*domain.BusinessBonus, error) { | ||
37 | + var ( | ||
38 | + tx = repository.transactionContext.PgTx | ||
39 | + BusinessBonusModel = &models.BusinessBonus{Id: BusinessBonus.Identify().(int64)} | ||
40 | + ) | ||
41 | + if _, err := tx.Model(BusinessBonusModel).Where("id = ?", BusinessBonus.Id).Delete(); err != nil { | ||
42 | + return BusinessBonus, err | ||
43 | + } | ||
44 | + return BusinessBonus, nil | ||
45 | +} | ||
46 | + | ||
47 | +func (repository *BusinessBonusRepository) FindOne(queryOptions map[string]interface{}) (*domain.BusinessBonus, error) { | ||
48 | + tx := repository.transactionContext.PgTx | ||
49 | + BusinessBonusModel := new(models.BusinessBonus) | ||
50 | + query := NewQuery(tx.Model(BusinessBonusModel), queryOptions) | ||
51 | + query.SetWhere("id = ?", "id") | ||
52 | + if err := query.First(); err != nil { | ||
53 | + return nil, fmt.Errorf("query row not found") | ||
54 | + } | ||
55 | + if BusinessBonusModel.Id == 0 { | ||
56 | + return nil, fmt.Errorf("query row not found") | ||
57 | + } | ||
58 | + return repository.transformPgModelToDomainModel(BusinessBonusModel) | ||
59 | +} | ||
60 | + | ||
61 | +func (repository *BusinessBonusRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.BusinessBonus, error) { | ||
62 | + tx := repository.transactionContext.PgTx | ||
63 | + var BusinessBonusModels []*models.BusinessBonus | ||
64 | + BusinessBonuss := make([]*domain.BusinessBonus, 0) | ||
65 | + query := NewQuery(tx.Model(&BusinessBonusModels), queryOptions). | ||
66 | + SetOrder("create_time", "sortByCreateTime"). | ||
67 | + SetOrder("update_time", "sortByUpdateTime") | ||
68 | + var err error | ||
69 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
70 | + return 0, BusinessBonuss, err | ||
71 | + } | ||
72 | + for _, BusinessBonusModel := range BusinessBonusModels { | ||
73 | + if BusinessBonus, err := repository.transformPgModelToDomainModel(BusinessBonusModel); err != nil { | ||
74 | + return 0, BusinessBonuss, err | ||
75 | + } else { | ||
76 | + BusinessBonuss = append(BusinessBonuss, BusinessBonus) | ||
77 | + } | ||
78 | + } | ||
79 | + return int64(query.AffectRow), BusinessBonuss, nil | ||
80 | +} | ||
81 | + | ||
82 | +func (repository *BusinessBonusRepository) transformPgModelToDomainModel(BusinessBonusModel *models.BusinessBonus) (*domain.BusinessBonus, error) { | ||
83 | + m := &domain.BusinessBonus{} | ||
84 | + err := GobModelTransform(m, BusinessBonusModel) | ||
85 | + return m, err | ||
86 | +} | ||
87 | + | ||
88 | +func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) { | ||
89 | + if transactionContext == nil { | ||
90 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
91 | + } | ||
92 | + return &BusinessBonusRepository{transactionContext: transactionContext}, nil | ||
93 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
8 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
9 | +) | ||
10 | + | ||
11 | +type PartnerCategoryInfoRepository struct { | ||
12 | + transactionContext *transaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +func (repository *PartnerCategoryInfoRepository) Save(dm *domain.PartnerCategoryInfo) (*domain.PartnerCategoryInfo, error) { | ||
16 | + var ( | ||
17 | + err error | ||
18 | + m = &models.PartnerCategoryInfo{} | ||
19 | + tx = repository.transactionContext.PgTx | ||
20 | + ) | ||
21 | + if err = GobModelTransform(m, dm); err != nil { | ||
22 | + return nil, err | ||
23 | + } | ||
24 | + if dm.Identify() == nil { | ||
25 | + if err = tx.Insert(m); err != nil { | ||
26 | + return nil, err | ||
27 | + } | ||
28 | + return dm, nil | ||
29 | + } | ||
30 | + if err = tx.Update(m); err != nil { | ||
31 | + return nil, err | ||
32 | + } | ||
33 | + return dm, nil | ||
34 | +} | ||
35 | + | ||
36 | +func (repository *PartnerCategoryInfoRepository) Remove(PartnerCategoryInfo *domain.PartnerCategoryInfo) (*domain.PartnerCategoryInfo, error) { | ||
37 | + var ( | ||
38 | + tx = repository.transactionContext.PgTx | ||
39 | + PartnerCategoryInfoModel = &models.PartnerCategoryInfo{Id: PartnerCategoryInfo.Identify().(int64)} | ||
40 | + ) | ||
41 | + if _, err := tx.Model(PartnerCategoryInfoModel).Where("id = ?", PartnerCategoryInfo.Id).Delete(); err != nil { | ||
42 | + return PartnerCategoryInfo, err | ||
43 | + } | ||
44 | + return PartnerCategoryInfo, nil | ||
45 | +} | ||
46 | + | ||
47 | +func (repository *PartnerCategoryInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.PartnerCategoryInfo, error) { | ||
48 | + tx := repository.transactionContext.PgTx | ||
49 | + PartnerCategoryInfoModel := new(models.PartnerCategoryInfo) | ||
50 | + query := NewQuery(tx.Model(PartnerCategoryInfoModel), queryOptions) | ||
51 | + query.SetWhere("id = ?", "id") | ||
52 | + if err := query.First(); err != nil { | ||
53 | + return nil, fmt.Errorf("query row not found") | ||
54 | + } | ||
55 | + if PartnerCategoryInfoModel.Id == 0 { | ||
56 | + return nil, fmt.Errorf("query row not found") | ||
57 | + } | ||
58 | + return repository.transformPgModelToDomainModel(PartnerCategoryInfoModel) | ||
59 | +} | ||
60 | + | ||
61 | +func (repository *PartnerCategoryInfoRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.PartnerCategoryInfo, error) { | ||
62 | + tx := repository.transactionContext.PgTx | ||
63 | + var PartnerCategoryInfoModels []*models.PartnerCategoryInfo | ||
64 | + PartnerCategoryInfos := make([]*domain.PartnerCategoryInfo, 0) | ||
65 | + query := NewQuery(tx.Model(&PartnerCategoryInfoModels), queryOptions). | ||
66 | + SetOrder("create_time", "sortByCreateTime"). | ||
67 | + SetOrder("update_time", "sortByUpdateTime") | ||
68 | + var err error | ||
69 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
70 | + return 0, PartnerCategoryInfos, err | ||
71 | + } | ||
72 | + for _, PartnerCategoryInfoModel := range PartnerCategoryInfoModels { | ||
73 | + if PartnerCategoryInfo, err := repository.transformPgModelToDomainModel(PartnerCategoryInfoModel); err != nil { | ||
74 | + return 0, PartnerCategoryInfos, err | ||
75 | + } else { | ||
76 | + PartnerCategoryInfos = append(PartnerCategoryInfos, PartnerCategoryInfo) | ||
77 | + } | ||
78 | + } | ||
79 | + return int64(query.AffectRow), PartnerCategoryInfos, nil | ||
80 | +} | ||
81 | + | ||
82 | +func (repository *PartnerCategoryInfoRepository) transformPgModelToDomainModel(PartnerCategoryInfoModel *models.PartnerCategoryInfo) (*domain.PartnerCategoryInfo, error) { | ||
83 | + m := &domain.PartnerCategoryInfo{} | ||
84 | + err := GobModelTransform(m, PartnerCategoryInfoModel) | ||
85 | + return m, err | ||
86 | +} | ||
87 | + | ||
88 | +func NewPartnerCategoryInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryInfoRepository, error) { | ||
89 | + if transactionContext == nil { | ||
90 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
91 | + } | ||
92 | + return &PartnerCategoryInfoRepository{transactionContext: transactionContext}, nil | ||
93 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
8 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
9 | +) | ||
10 | + | ||
11 | +type UsersRepository struct { | ||
12 | + transactionContext *transaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error) { | ||
16 | + var ( | ||
17 | + err error | ||
18 | + m = &models.Users{} | ||
19 | + tx = repository.transactionContext.PgTx | ||
20 | + ) | ||
21 | + if err = GobModelTransform(m, dm); err != nil { | ||
22 | + return nil, err | ||
23 | + } | ||
24 | + if dm.Identify() == nil { | ||
25 | + if err = tx.Insert(m); err != nil { | ||
26 | + return nil, err | ||
27 | + } | ||
28 | + return dm, nil | ||
29 | + } | ||
30 | + if err = tx.Update(m); err != nil { | ||
31 | + return nil, err | ||
32 | + } | ||
33 | + return dm, nil | ||
34 | +} | ||
35 | + | ||
36 | +func (repository *UsersRepository) Remove(Users *domain.Users) (*domain.Users, error) { | ||
37 | + var ( | ||
38 | + tx = repository.transactionContext.PgTx | ||
39 | + UsersModel = &models.Users{Id: Users.Identify().(int64)} | ||
40 | + ) | ||
41 | + if _, err := tx.Model(UsersModel).Where("id = ?", Users.Id).Delete(); err != nil { | ||
42 | + return Users, err | ||
43 | + } | ||
44 | + return Users, nil | ||
45 | +} | ||
46 | + | ||
47 | +func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*domain.Users, error) { | ||
48 | + tx := repository.transactionContext.PgTx | ||
49 | + UsersModel := new(models.Users) | ||
50 | + query := NewQuery(tx.Model(UsersModel), queryOptions) | ||
51 | + query.SetWhere("id = ?", "id") | ||
52 | + if err := query.First(); err != nil { | ||
53 | + return nil, fmt.Errorf("query row not found") | ||
54 | + } | ||
55 | + if UsersModel.Id == 0 { | ||
56 | + return nil, fmt.Errorf("query row not found") | ||
57 | + } | ||
58 | + return repository.transformPgModelToDomainModel(UsersModel) | ||
59 | +} | ||
60 | + | ||
61 | +func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Users, error) { | ||
62 | + tx := repository.transactionContext.PgTx | ||
63 | + var UsersModels []*models.Users | ||
64 | + Userss := make([]*domain.Users, 0) | ||
65 | + query := NewQuery(tx.Model(&UsersModels), queryOptions). | ||
66 | + SetOrder("create_time", "sortByCreateTime"). | ||
67 | + SetOrder("update_time", "sortByUpdateTime") | ||
68 | + var err error | ||
69 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
70 | + return 0, Userss, err | ||
71 | + } | ||
72 | + for _, UsersModel := range UsersModels { | ||
73 | + if Users, err := repository.transformPgModelToDomainModel(UsersModel); err != nil { | ||
74 | + return 0, Userss, err | ||
75 | + } else { | ||
76 | + Userss = append(Userss, Users) | ||
77 | + } | ||
78 | + } | ||
79 | + return int64(query.AffectRow), Userss, nil | ||
80 | +} | ||
81 | + | ||
82 | +func (repository *UsersRepository) transformPgModelToDomainModel(UsersModel *models.Users) (*domain.Users, error) { | ||
83 | + m := &domain.Users{} | ||
84 | + err := GobModelTransform(m, UsersModel) | ||
85 | + return m, err | ||
86 | +} | ||
87 | + | ||
88 | +func NewUsersRepository(transactionContext *transaction.TransactionContext) (*UsersRepository, error) { | ||
89 | + if transactionContext == nil { | ||
90 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
91 | + } | ||
92 | + return &UsersRepository{transactionContext: transactionContext}, nil | ||
93 | +} |
-
请 注册 或 登录 后发表评论