正在显示
14 个修改的文件
包含
1118 行增加
和
12 行删除
| @@ -39,3 +39,27 @@ func CreateContractUndertakerFeedbackRepository(options map[string]interface{}) | @@ -39,3 +39,27 @@ func CreateContractUndertakerFeedbackRepository(options map[string]interface{}) | ||
| 39 | } | 39 | } |
| 40 | return repository.NewContractUndertakerFeedbackRepository(transactionContext) | 40 | return repository.NewContractUndertakerFeedbackRepository(transactionContext) |
| 41 | } | 41 | } |
| 42 | + | ||
| 43 | +func CreateDividendsEstimateRepository(options map[string]interface{}) (domain.DividendsEstimateRepository, error) { | ||
| 44 | + var transactionContext *pg.TransactionContext | ||
| 45 | + if value, ok := options["transactionContext"]; ok { | ||
| 46 | + transactionContext = value.(*pg.TransactionContext) | ||
| 47 | + } | ||
| 48 | + return repository.NewDividendsEstimateRepository(transactionContext) | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +func CreateDividendsIncentivesRuleRepository(options map[string]interface{}) (domain.DividendsIncentivesRuleRepository, error) { | ||
| 52 | + var transactionContext *pg.TransactionContext | ||
| 53 | + if value, ok := options["transactionContext"]; ok { | ||
| 54 | + transactionContext = value.(*pg.TransactionContext) | ||
| 55 | + } | ||
| 56 | + return repository.NewDividendsIncentivesRuleRepository(transactionContext) | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +func CreateMoneyIncentivesRuleRepository(options map[string]interface{}) (domain.MoneyIncentivesRuleRepository, error) { | ||
| 60 | + var transactionContext *pg.TransactionContext | ||
| 61 | + if value, ok := options["transactionContext"]; ok { | ||
| 62 | + transactionContext = value.(*pg.TransactionContext) | ||
| 63 | + } | ||
| 64 | + return repository.NewMoneyIncentivesRuleRepository(transactionContext) | ||
| 65 | +} |
| @@ -130,17 +130,5 @@ func (contractUndertakerFeedback *ContractUndertakerFeedback) Update(data map[st | @@ -130,17 +130,5 @@ func (contractUndertakerFeedback *ContractUndertakerFeedback) Update(data map[st | ||
| 130 | if remarks, ok := data["remarks"]; ok { | 130 | if remarks, ok := data["remarks"]; ok { |
| 131 | contractUndertakerFeedback.CooperationMode.Remarks = remarks.(string) | 131 | contractUndertakerFeedback.CooperationMode.Remarks = remarks.(string) |
| 132 | } | 132 | } |
| 133 | - if operateTime, ok := data["operateTime"]; ok { | ||
| 134 | - contractUndertakerFeedback.CooperationMode.OperateTime = operateTime.(time.Time) | ||
| 135 | - } | ||
| 136 | - if updatedAt, ok := data["updatedAt"]; ok { | ||
| 137 | - contractUndertakerFeedback.CooperationMode.UpdatedAt = updatedAt.(time.Time) | ||
| 138 | - } | ||
| 139 | - if deletedAt, ok := data["deletedAt"]; ok { | ||
| 140 | - contractUndertakerFeedback.CooperationMode.DeletedAt = deletedAt.(time.Time) | ||
| 141 | - } | ||
| 142 | - if createdAt, ok := data["createdAt"]; ok { | ||
| 143 | - contractUndertakerFeedback.CooperationMode.CreatedAt = createdAt.(time.Time) | ||
| 144 | - } | ||
| 145 | return nil | 133 | return nil |
| 146 | } | 134 | } |
pkg/domain/dividends_estimate.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 分红预算实体 | ||
| 6 | +type DividendsEstimate struct { | ||
| 7 | + // 承接人分红预算记录ID | ||
| 8 | + DividendsEstimateId int64 `json:"dividendsEstimateId,string"` | ||
| 9 | + // 分红结算状态 | ||
| 10 | + DividendsAccountStatus int32 `json:"dividendsAccountStatus"` | ||
| 11 | + // 分红金额 | ||
| 12 | + DividendsAmount float64 `json:"dividendsAmount"` | ||
| 13 | + // 承接人分红预算单号 | ||
| 14 | + DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"` | ||
| 15 | + // 分红预算时间 | ||
| 16 | + DividendsEstimateTime time.Time `json:"dividendsEstimateTime"` | ||
| 17 | + // 参与分红类型,1承接人,2推荐人,3关联业务员 | ||
| 18 | + DividendsParticipateType int32 `json:"dividendsParticipateType"` | ||
| 19 | + // 分红类型,1订单分红,2退货冲销,3金额激励 | ||
| 20 | + DividendsType int32 `json:"dividendsType"` | ||
| 21 | + // 分红订单号或退货单号 | ||
| 22 | + OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` | ||
| 23 | + // 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 | ||
| 24 | + CooperationProjectNumber string `json:"cooperationProjectNumber"` | ||
| 25 | + // 分红用户 | ||
| 26 | + DividendsUser *User `json:"dividendsUser"` | ||
| 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 DividendsEstimateRepository interface { | ||
| 44 | + Save(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) | ||
| 45 | + Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error) | ||
| 46 | + FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error) | ||
| 47 | + Find(queryOptions map[string]interface{}) (int64, []*DividendsEstimate, error) | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +func (dividendsEstimate *DividendsEstimate) Identify() interface{} { | ||
| 51 | + if dividendsEstimate.DividendsEstimateId == 0 { | ||
| 52 | + return nil | ||
| 53 | + } | ||
| 54 | + return dividendsEstimate.DividendsEstimateId | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +func (dividendsEstimate *DividendsEstimate) Update(data map[string]interface{}) error { | ||
| 58 | + if dividendsEstimateId, ok := data["dividendsEstimateId"]; ok { | ||
| 59 | + dividendsEstimate.DividendsEstimateId = dividendsEstimateId.(int64) | ||
| 60 | + } | ||
| 61 | + if dividendsAccountStatus, ok := data["dividendsAccountStatus"]; ok { | ||
| 62 | + dividendsEstimate.DividendsAccountStatus = dividendsAccountStatus.(int32) | ||
| 63 | + } | ||
| 64 | + if dividendsAmount, ok := data["dividendsAmount"]; ok { | ||
| 65 | + dividendsEstimate.DividendsAmount = dividendsAmount.(float64) | ||
| 66 | + } | ||
| 67 | + if dividendsEstimateOrderNumber, ok := data["dividendsEstimateOrderNumber"]; ok { | ||
| 68 | + dividendsEstimate.DividendsEstimateOrderNumber = dividendsEstimateOrderNumber.(string) | ||
| 69 | + } | ||
| 70 | + if dividendsEstimateTime, ok := data["dividendsEstimateTime"]; ok { | ||
| 71 | + dividendsEstimate.DividendsEstimateTime = dividendsEstimateTime.(time.Time) | ||
| 72 | + } | ||
| 73 | + if dividendsParticipateType, ok := data["dividendsParticipateType"]; ok { | ||
| 74 | + dividendsEstimate.DividendsParticipateType = dividendsParticipateType.(int32) | ||
| 75 | + } | ||
| 76 | + if dividendsType, ok := data["dividendsType"]; ok { | ||
| 77 | + dividendsEstimate.DividendsType = dividendsType.(int32) | ||
| 78 | + } | ||
| 79 | + if orderOrReturnedOrderNum, ok := data["orderOrReturnedOrderNum"]; ok { | ||
| 80 | + dividendsEstimate.OrderOrReturnedOrderNum = orderOrReturnedOrderNum.(string) | ||
| 81 | + } | ||
| 82 | + if cooperationProjectNumber, ok := data["cooperationProjectNumber"]; ok { | ||
| 83 | + dividendsEstimate.CooperationProjectNumber = cooperationProjectNumber.(string) | ||
| 84 | + } | ||
| 85 | + if userId, ok := data["userId"]; ok { | ||
| 86 | + dividendsEstimate.DividendsUser.UserId = userId.(int64) | ||
| 87 | + } | ||
| 88 | + if userBaseId, ok := data["userBaseId"]; ok { | ||
| 89 | + dividendsEstimate.DividendsUser.UserBaseId = userBaseId.(int64) | ||
| 90 | + } | ||
| 91 | + if orgId, ok := data["orgId"]; ok { | ||
| 92 | + dividendsEstimate.DividendsUser.Org.OrgId = orgId.(int64) | ||
| 93 | + } | ||
| 94 | + if orgName, ok := data["orgName"]; ok { | ||
| 95 | + dividendsEstimate.DividendsUser.Org.OrgName = orgName.(string) | ||
| 96 | + } | ||
| 97 | + if companyId, ok := data["companyId"]; ok { | ||
| 98 | + dividendsEstimate.DividendsUser.Org.Company.CompanyId = companyId.(int64) | ||
| 99 | + } | ||
| 100 | + if companyLogo, ok := data["companyLogo"]; ok { | ||
| 101 | + dividendsEstimate.DividendsUser.Org.Company.CompanyLogo = companyLogo.(string) | ||
| 102 | + } | ||
| 103 | + if companyName, ok := data["companyName"]; ok { | ||
| 104 | + dividendsEstimate.DividendsUser.Org.Company.CompanyName = companyName.(string) | ||
| 105 | + } | ||
| 106 | + if orgs, ok := data["orgs"]; ok { | ||
| 107 | + dividendsEstimate.DividendsUser.Orgs = orgs.([]*Org) | ||
| 108 | + } | ||
| 109 | + if departmentId, ok := data["departmentId"]; ok { | ||
| 110 | + dividendsEstimate.DividendsUser.Department.DepartmentId = departmentId.(int64) | ||
| 111 | + } | ||
| 112 | + if departmentName, ok := data["departmentName"]; ok { | ||
| 113 | + dividendsEstimate.DividendsUser.Department.DepartmentName = departmentName.(string) | ||
| 114 | + } | ||
| 115 | + if departmentNumber, ok := data["departmentNumber"]; ok { | ||
| 116 | + dividendsEstimate.DividendsUser.Department.DepartmentNumber = departmentNumber.(string) | ||
| 117 | + } | ||
| 118 | + if isOrganization, ok := data["isOrganization"]; ok { | ||
| 119 | + dividendsEstimate.DividendsUser.Department.IsOrganization = isOrganization.(bool) | ||
| 120 | + } | ||
| 121 | + if roleId, ok := data["roleId"]; ok { | ||
| 122 | + dividendsEstimate.DividendsUser.Role.RoleId = roleId.(int64) | ||
| 123 | + } | ||
| 124 | + if roleName, ok := data["roleName"]; ok { | ||
| 125 | + dividendsEstimate.DividendsUser.Role.RoleName = roleName.(string) | ||
| 126 | + } | ||
| 127 | + if userAvatar, ok := data["userAvatar"]; ok { | ||
| 128 | + dividendsEstimate.DividendsUser.UserInfo.UserAvatar = userAvatar.(string) | ||
| 129 | + } | ||
| 130 | + if userEmail, ok := data["userEmail"]; ok { | ||
| 131 | + dividendsEstimate.DividendsUser.UserInfo.UserEmail = userEmail.(string) | ||
| 132 | + } | ||
| 133 | + if userName, ok := data["userName"]; ok { | ||
| 134 | + dividendsEstimate.DividendsUser.UserInfo.UserName = userName.(string) | ||
| 135 | + } | ||
| 136 | + if userPhone, ok := data["userPhone"]; ok { | ||
| 137 | + dividendsEstimate.DividendsUser.UserInfo.UserPhone = userPhone.(string) | ||
| 138 | + } | ||
| 139 | + if userAccount, ok := data["userAccount"]; ok { | ||
| 140 | + dividendsEstimate.DividendsUser.UserInfo.UserAccount = userAccount.(string) | ||
| 141 | + } | ||
| 142 | + if userType, ok := data["userType"]; ok { | ||
| 143 | + dividendsEstimate.DividendsUser.UserType = userType.(int32) | ||
| 144 | + } | ||
| 145 | + if status, ok := data["status"]; ok { | ||
| 146 | + dividendsEstimate.DividendsUser.Status = status.(int32) | ||
| 147 | + } | ||
| 148 | + return nil | ||
| 149 | +} |
pkg/domain/dividends_incentives_rule.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 金额激励规则实体 | ||
| 6 | +type DividendsIncentivesRule struct { | ||
| 7 | + // 分红规则ID | ||
| 8 | + DividendsIncentivesRuleId int64 `json:"dividendsIncentivesRuleId,string"` | ||
| 9 | + // 关联的项目合约编号 | ||
| 10 | + CooperationContractNumber string `json:"cooperationContractNumber"` | ||
| 11 | + // 推荐人抽成比例 | ||
| 12 | + ReferrerPercentage float64 `json:"referrerPercentage"` | ||
| 13 | + // 业务员抽成比例 | ||
| 14 | + SalesmanPercentage float64 `json:"salesmanPercentage"` | ||
| 15 | + // 分红规则激励百分点 | ||
| 16 | + DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"` | ||
| 17 | + // 分红规则激励阶段,阶段返回时需要转换为中文数字 | ||
| 18 | + DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string"` | ||
| 19 | + // 分红规则激励阶段结束 | ||
| 20 | + DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"` | ||
| 21 | + // 分红规则激励阶段开始 | ||
| 22 | + DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"` | ||
| 23 | + // 数据所属组织机构 | ||
| 24 | + Org *Org `json:"org"` | ||
| 25 | + // 公司 | ||
| 26 | + Company *Company `json:"company"` | ||
| 27 | + // 更新时间 | ||
| 28 | + UpdatedAt time.Time `json:"updatedAt"` | ||
| 29 | + // 删除时间 | ||
| 30 | + DeletedAt time.Time `json:"deletedAt"` | ||
| 31 | + // 创建时间 | ||
| 32 | + CreatedAt time.Time `json:"createdAt"` | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type DividendsIncentivesRuleRepository interface { | ||
| 36 | + Save(dividendsIncentivesRule *DividendsIncentivesRule) (*DividendsIncentivesRule, error) | ||
| 37 | + Remove(dividendsIncentivesRule *DividendsIncentivesRule) (*DividendsIncentivesRule, error) | ||
| 38 | + FindOne(queryOptions map[string]interface{}) (*DividendsIncentivesRule, error) | ||
| 39 | + Find(queryOptions map[string]interface{}) (int64, []*DividendsIncentivesRule, error) | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (dividendsIncentivesRule *DividendsIncentivesRule) Identify() interface{} { | ||
| 43 | + if dividendsIncentivesRule.DividendsIncentivesRuleId == 0 { | ||
| 44 | + return nil | ||
| 45 | + } | ||
| 46 | + return dividendsIncentivesRule.DividendsIncentivesRuleId | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]interface{}) error { | ||
| 50 | + if dividendsIncentivesRuleId, ok := data["dividendsIncentivesRuleId"]; ok { | ||
| 51 | + dividendsIncentivesRule.DividendsIncentivesRuleId = dividendsIncentivesRuleId.(int64) | ||
| 52 | + } | ||
| 53 | + if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { | ||
| 54 | + dividendsIncentivesRule.CooperationContractNumber = cooperationContractNumber.(string) | ||
| 55 | + } | ||
| 56 | + if referrerPercentage, ok := data["referrerPercentage"]; ok { | ||
| 57 | + dividendsIncentivesRule.ReferrerPercentage = referrerPercentage.(float64) | ||
| 58 | + } | ||
| 59 | + if salesmanPercentage, ok := data["salesmanPercentage"]; ok { | ||
| 60 | + dividendsIncentivesRule.SalesmanPercentage = salesmanPercentage.(float64) | ||
| 61 | + } | ||
| 62 | + if dividendsIncentivesPercentage, ok := data["dividendsIncentivesPercentage"]; ok { | ||
| 63 | + dividendsIncentivesRule.DividendsIncentivesPercentage = dividendsIncentivesPercentage.(float64) | ||
| 64 | + } | ||
| 65 | + if dividendsIncentivesStage, ok := data["dividendsIncentivesStage"]; ok { | ||
| 66 | + dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int64) | ||
| 67 | + } | ||
| 68 | + if dividendsIncentivesStageEnd, ok := data["dividendsIncentivesStageEnd"]; ok { | ||
| 69 | + dividendsIncentivesRule.DividendsIncentivesStageEnd = dividendsIncentivesStageEnd.(time.Time) | ||
| 70 | + } | ||
| 71 | + if dividendsIncentivesStageStart, ok := data["dividendsIncentivesStageStart"]; ok { | ||
| 72 | + dividendsIncentivesRule.DividendsIncentivesStageStart = dividendsIncentivesStageStart.(time.Time) | ||
| 73 | + } | ||
| 74 | + if orgId, ok := data["orgId"]; ok { | ||
| 75 | + dividendsIncentivesRule.Org.OrgId = orgId.(int64) | ||
| 76 | + } | ||
| 77 | + if orgName, ok := data["orgName"]; ok { | ||
| 78 | + dividendsIncentivesRule.Org.OrgName = orgName.(string) | ||
| 79 | + } | ||
| 80 | + if companyId, ok := data["companyId"]; ok { | ||
| 81 | + dividendsIncentivesRule.Org.Company.CompanyId = companyId.(int64) | ||
| 82 | + } | ||
| 83 | + if companyLogo, ok := data["companyLogo"]; ok { | ||
| 84 | + dividendsIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string) | ||
| 85 | + } | ||
| 86 | + if companyName, ok := data["companyName"]; ok { | ||
| 87 | + dividendsIncentivesRule.Org.Company.CompanyName = companyName.(string) | ||
| 88 | + } | ||
| 89 | + return nil | ||
| 90 | +} |
pkg/domain/money_incentives_rule.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 金额激励规则实体 | ||
| 6 | +type MoneyIncentivesRule struct { | ||
| 7 | + // 金额激励规则ID | ||
| 8 | + MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string"` | ||
| 9 | + // 关联的共创合约编号 | ||
| 10 | + CooperationContractNumber string `json:"cooperationContractNumber"` | ||
| 11 | + // 激励金额 | ||
| 12 | + MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"` | ||
| 13 | + // 金额激励阶段,阶段返回时需要转换为中文数字 | ||
| 14 | + MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string"` | ||
| 15 | + // 金额激励阶段有效期结束 | ||
| 16 | + MoneyIncentivesStageEnd time.Time `json:"moneyIncentivesStageEnd"` | ||
| 17 | + // 金额激励阶段有效期开始 | ||
| 18 | + MoneyIncentivesStageStart time.Time `json:"moneyIncentivesStageStart"` | ||
| 19 | + // 金额激励规则时间 | ||
| 20 | + MoneyIncentivesTime time.Time `json:"moneyIncentivesTime"` | ||
| 21 | + // 推荐人抽成比例 | ||
| 22 | + ReferrerPercentage float64 `json:"referrerPercentage"` | ||
| 23 | + // 业务员抽成比例 | ||
| 24 | + SalesmanPercentage float64 `json:"salesmanPercentage"` | ||
| 25 | + // 数据所属组织机构 | ||
| 26 | + Org *Org `json:"org"` | ||
| 27 | + // 公司 | ||
| 28 | + Company *Company `json:"company"` | ||
| 29 | + // 更新时间 | ||
| 30 | + UpdatedAt time.Time `json:"updatedAt"` | ||
| 31 | + // 删除时间 | ||
| 32 | + DeletedAt time.Time `json:"deletedAt"` | ||
| 33 | + // 创建时间 | ||
| 34 | + CreatedAt time.Time `json:"createdAt"` | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +type MoneyIncentivesRuleRepository interface { | ||
| 38 | + Save(moneyIncentivesRule *MoneyIncentivesRule) (*MoneyIncentivesRule, error) | ||
| 39 | + Remove(moneyIncentivesRule *MoneyIncentivesRule) (*MoneyIncentivesRule, error) | ||
| 40 | + FindOne(queryOptions map[string]interface{}) (*MoneyIncentivesRule, error) | ||
| 41 | + Find(queryOptions map[string]interface{}) (int64, []*MoneyIncentivesRule, error) | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +func (moneyIncentivesRule *MoneyIncentivesRule) Identify() interface{} { | ||
| 45 | + if moneyIncentivesRule.MoneyIncentivesRuleId == 0 { | ||
| 46 | + return nil | ||
| 47 | + } | ||
| 48 | + return moneyIncentivesRule.MoneyIncentivesRuleId | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface{}) error { | ||
| 52 | + if moneyIncentivesRuleId, ok := data["moneyIncentivesRuleId"]; ok { | ||
| 53 | + moneyIncentivesRule.MoneyIncentivesRuleId = moneyIncentivesRuleId.(int64) | ||
| 54 | + } | ||
| 55 | + if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { | ||
| 56 | + moneyIncentivesRule.CooperationContractNumber = cooperationContractNumber.(string) | ||
| 57 | + } | ||
| 58 | + if moneyIncentivesAmount, ok := data["moneyIncentivesAmount"]; ok { | ||
| 59 | + moneyIncentivesRule.MoneyIncentivesAmount = moneyIncentivesAmount.(float64) | ||
| 60 | + } | ||
| 61 | + if moneyIncentivesStage, ok := data["moneyIncentivesStage"]; ok { | ||
| 62 | + moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int64) | ||
| 63 | + } | ||
| 64 | + if moneyIncentivesStageEnd, ok := data["moneyIncentivesStageEnd"]; ok { | ||
| 65 | + moneyIncentivesRule.MoneyIncentivesStageEnd = moneyIncentivesStageEnd.(time.Time) | ||
| 66 | + } | ||
| 67 | + if moneyIncentivesStageStart, ok := data["moneyIncentivesStageStart"]; ok { | ||
| 68 | + moneyIncentivesRule.MoneyIncentivesStageStart = moneyIncentivesStageStart.(time.Time) | ||
| 69 | + } | ||
| 70 | + if moneyIncentivesTime, ok := data["moneyIncentivesTime"]; ok { | ||
| 71 | + moneyIncentivesRule.MoneyIncentivesTime = moneyIncentivesTime.(time.Time) | ||
| 72 | + } | ||
| 73 | + if referrerPercentage, ok := data["referrerPercentage"]; ok { | ||
| 74 | + moneyIncentivesRule.ReferrerPercentage = referrerPercentage.(float64) | ||
| 75 | + } | ||
| 76 | + if salesmanPercentage, ok := data["salesmanPercentage"]; ok { | ||
| 77 | + moneyIncentivesRule.SalesmanPercentage = salesmanPercentage.(float64) | ||
| 78 | + } | ||
| 79 | + if orgId, ok := data["orgId"]; ok { | ||
| 80 | + moneyIncentivesRule.Org.OrgId = orgId.(int64) | ||
| 81 | + } | ||
| 82 | + if orgName, ok := data["orgName"]; ok { | ||
| 83 | + moneyIncentivesRule.Org.OrgName = orgName.(string) | ||
| 84 | + } | ||
| 85 | + if companyId, ok := data["companyId"]; ok { | ||
| 86 | + moneyIncentivesRule.Org.Company.CompanyId = companyId.(int64) | ||
| 87 | + } | ||
| 88 | + if companyLogo, ok := data["companyLogo"]; ok { | ||
| 89 | + moneyIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string) | ||
| 90 | + } | ||
| 91 | + if companyName, ok := data["companyName"]; ok { | ||
| 92 | + moneyIncentivesRule.Org.Company.CompanyName = companyName.(string) | ||
| 93 | + } | ||
| 94 | + return nil | ||
| 95 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type DividendsEstimate struct { | ||
| 9 | + tableName string `comment:"分红预算实体" pg:"dividends_estimates,alias:dividends_estimate"` | ||
| 10 | + // 承接人分红预算记录ID | ||
| 11 | + DividendsEstimateId int64 `comment:"承接人分红预算记录ID" pg:"pk:dividends_estimate_id"` | ||
| 12 | + // 分红结算状态 | ||
| 13 | + DividendsAccountStatus int32 `comment:"分红结算状态"` | ||
| 14 | + // 分红金额 | ||
| 15 | + DividendsAmount float64 `comment:"分红金额"` | ||
| 16 | + // 承接人分红预算单号 | ||
| 17 | + DividendsEstimateOrderNumber string `comment:"承接人分红预算单号"` | ||
| 18 | + // 分红预算时间 | ||
| 19 | + DividendsEstimateTime time.Time `comment:"分红预算时间"` | ||
| 20 | + // 参与分红类型,1承接人,2推荐人,3关联业务员 | ||
| 21 | + DividendsParticipateType int32 `comment:"参与分红类型,1承接人,2推荐人,3关联业务员"` | ||
| 22 | + // 分红类型,1订单分红,2退货冲销,3金额激励 | ||
| 23 | + DividendsType int32 `comment:"分红类型,1订单分红,2退货冲销,3金额激励"` | ||
| 24 | + // 分红订单号或退货单号 | ||
| 25 | + OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"` | ||
| 26 | + // 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 | ||
| 27 | + CooperationProjectNumber string `comment:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001"` | ||
| 28 | + // 分红用户 | ||
| 29 | + DividendsUser *domain.User `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 models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type DividendsIncentivesRule struct { | ||
| 9 | + tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"` | ||
| 10 | + // 分红规则ID | ||
| 11 | + DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:"pk:dividends_incentives_rule_id"` | ||
| 12 | + // 关联的项目合约编号 | ||
| 13 | + CooperationContractNumber string `comment:"关联的项目合约编号"` | ||
| 14 | + // 推荐人抽成比例 | ||
| 15 | + ReferrerPercentage float64 `comment:"推荐人抽成比例"` | ||
| 16 | + // 业务员抽成比例 | ||
| 17 | + SalesmanPercentage float64 `comment:"业务员抽成比例"` | ||
| 18 | + // 分红规则激励百分点 | ||
| 19 | + DividendsIncentivesPercentage float64 `comment:"分红规则激励百分点"` | ||
| 20 | + // 分红规则激励阶段,阶段返回时需要转换为中文数字 | ||
| 21 | + DividendsIncentivesStage int64 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"` | ||
| 22 | + // 分红规则激励阶段结束 | ||
| 23 | + DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"` | ||
| 24 | + // 分红规则激励阶段开始 | ||
| 25 | + DividendsIncentivesStageStart time.Time `comment:"分红规则激励阶段开始"` | ||
| 26 | + // 数据所属组织机构 | ||
| 27 | + Org *domain.Org `comment:"数据所属组织机构"` | ||
| 28 | + // 公司 | ||
| 29 | + Company *domain.Company `comment:"公司"` | ||
| 30 | + // 更新时间 | ||
| 31 | + UpdatedAt time.Time `comment:"更新时间"` | ||
| 32 | + // 删除时间 | ||
| 33 | + DeletedAt time.Time `comment:"删除时间"` | ||
| 34 | + // 创建时间 | ||
| 35 | + CreatedAt time.Time `comment:"创建时间"` | ||
| 36 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +type MoneyIncentivesRule struct { | ||
| 4 | + tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"` | ||
| 5 | + // 金额激励规则ID | ||
| 6 | + MoneyIcentivesRuleId int64 `comment:"金额激励规则ID"` | ||
| 7 | + // 关联的共创合约编号 | ||
| 8 | + CooperationContractNumber string `comment:"关联的共创合约编号"` | ||
| 9 | + // 激励金额 | ||
| 10 | + MoneyIncentivesAmount float64 `comment:"激励金额"` | ||
| 11 | + // 金额激励阶段,阶段返回时需要转换为中文数字 | ||
| 12 | + MoneyIncentivesStage int64 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"` | ||
| 13 | + // 金额激励阶段有效期结束 | ||
| 14 | + MoneyIncentivesStageEnd time.Time `comment:"金额激励阶段有效期结束"` | ||
| 15 | + // 金额激励阶段有效期开始 | ||
| 16 | + MoneyIncentivesStageStart time.Time `comment:"金额激励阶段有效期开始"` | ||
| 17 | + // 金额激励规则时间 | ||
| 18 | + MoneyIncentivesTime time.Time `comment:"金额激励规则时间"` | ||
| 19 | + // 推荐人抽成比例 | ||
| 20 | + ReferrerPercentage float64 `comment:"推荐人抽成比例"` | ||
| 21 | + // 业务员抽成比例 | ||
| 22 | + SalesmanPercentage float64 `comment:"业务员抽成比例"` | ||
| 23 | + // 数据所属组织机构 | ||
| 24 | + Org *Org `comment:"数据所属组织机构"` | ||
| 25 | + // 公司 | ||
| 26 | + Company *Company `comment:"公司"` | ||
| 27 | + // 更新时间 | ||
| 28 | + UpdatedAt time.Time `comment:"更新时间"` | ||
| 29 | + // 删除时间 | ||
| 30 | + DeletedAt time.Time `comment:"删除时间"` | ||
| 31 | + // 创建时间 | ||
| 32 | + CreatedAt time.Time `comment:"创建时间"` | ||
| 33 | +} |
| 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 TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel *models.DividendsEstimate) (*domain.DividendsEstimate, error) { | ||
| 9 | + return &domain.DividendsEstimate{ | ||
| 10 | + DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId, | ||
| 11 | + DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus, | ||
| 12 | + DividendsAmount: dividendsEstimateModel.DividendsAmount, | ||
| 13 | + DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber, | ||
| 14 | + DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime, | ||
| 15 | + DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType, | ||
| 16 | + DividendsType: dividendsEstimateModel.DividendsType, | ||
| 17 | + OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum, | ||
| 18 | + CooperationProjectNumber: dividendsEstimateModel.CooperationProjectNumber, | ||
| 19 | + DividendsUser: dividendsEstimateModel.DividendsUser, | ||
| 20 | + Org: dividendsEstimateModel.Org, | ||
| 21 | + Company: dividendsEstimateModel.Company, | ||
| 22 | + Operator: dividendsEstimateModel.Operator, | ||
| 23 | + OperateTime: dividendsEstimateModel.OperateTime, | ||
| 24 | + CreatedAt: dividendsEstimateModel.CreatedAt, | ||
| 25 | + DeletedAt: dividendsEstimateModel.DeletedAt, | ||
| 26 | + UpdatedAt: dividendsEstimateModel.UpdatedAt, | ||
| 27 | + }, nil | ||
| 28 | +} |
| 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 TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel *models.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) { | ||
| 9 | + return &domain.DividendsIncentivesRule{ | ||
| 10 | + DividendsIncentivesRuleId: dividendsIncentivesRuleModel.DividendsIncentivesRuleId, | ||
| 11 | + CooperationContractNumber: dividendsIncentivesRuleModel.CooperationContractNumber, | ||
| 12 | + ReferrerPercentage: dividendsIncentivesRuleModel.ReferrerPercentage, | ||
| 13 | + SalesmanPercentage: dividendsIncentivesRuleModel.SalesmanPercentage, | ||
| 14 | + DividendsIncentivesPercentage: dividendsIncentivesRuleModel.DividendsIncentivesPercentage, | ||
| 15 | + DividendsIncentivesStage: dividendsIncentivesRuleModel.DividendsIncentivesStage, | ||
| 16 | + DividendsIncentivesStageEnd: dividendsIncentivesRuleModel.DividendsIncentivesStageEnd, | ||
| 17 | + DividendsIncentivesStageStart: dividendsIncentivesRuleModel.DividendsIncentivesStageStart, | ||
| 18 | + Org: dividendsIncentivesRuleModel.Org, | ||
| 19 | + Company: dividendsIncentivesRuleModel.Company, | ||
| 20 | + UpdatedAt: dividendsIncentivesRuleModel.UpdatedAt, | ||
| 21 | + DeletedAt: dividendsIncentivesRuleModel.DeletedAt, | ||
| 22 | + CreatedAt: dividendsIncentivesRuleModel.CreatedAt, | ||
| 23 | + }, nil | ||
| 24 | +} |
| 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 TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel *models.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) { | ||
| 9 | + return &domain.MoneyIncentivesRule{ | ||
| 10 | + MoneyIcentivesRuleId: moneyIncentivesRuleModel.MoneyIcentivesRuleId, | ||
| 11 | + CooperationContractNumber: moneyIncentivesRuleModel.CooperationContractNumber, | ||
| 12 | + MoneyIncentivesAmount: moneyIncentivesRuleModel.MoneyIncentivesAmount, | ||
| 13 | + MoneyIncentivesStage: moneyIncentivesRuleModel.MoneyIncentivesStage, | ||
| 14 | + MoneyIncentivesStageEnd: moneyIncentivesRuleModel.MoneyIncentivesStageEnd, | ||
| 15 | + MoneyIncentivesStageStart: moneyIncentivesRuleModel.MoneyIncentivesStageStart, | ||
| 16 | + MoneyIncentivesTime: moneyIncentivesRuleModel.MoneyIncentivesTime, | ||
| 17 | + ReferrerPercentage: moneyIncentivesRuleModel.ReferrerPercentage, | ||
| 18 | + SalesmanPercentage: moneyIncentivesRuleModel.SalesmanPercentage, | ||
| 19 | + Org: moneyIncentivesRuleModel.Org, | ||
| 20 | + Company: moneyIncentivesRuleModel.Company, | ||
| 21 | + UpdatedAt: moneyIncentivesRuleModel.UpdatedAt, | ||
| 22 | + DeletedAt: moneyIncentivesRuleModel.DeletedAt, | ||
| 23 | + CreatedAt: moneyIncentivesRuleModel.CreatedAt, | ||
| 24 | + }, nil | ||
| 25 | +} |
| 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 DividendsEstimateRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *DividendsEstimateRepository) 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 *DividendsEstimateRepository) Save(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "dividends_estimate_id", | ||
| 30 | + "dividends_account_status", | ||
| 31 | + "dividends_amount", | ||
| 32 | + "dividends_estimate_order_number", | ||
| 33 | + "dividends_estimate_time", | ||
| 34 | + "dividends_participate_type", | ||
| 35 | + "dividends_type", | ||
| 36 | + "order_or_returned_order_num", | ||
| 37 | + "cooperation_project_number", | ||
| 38 | + "dividends_user", | ||
| 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, "dividendsEstimate_id") | ||
| 51 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 52 | + tx := repository.transactionContext.PgTx | ||
| 53 | + if dividendsEstimate.Identify() == nil { | ||
| 54 | + dividendsEstimateId, err := repository.nextIdentify() | ||
| 55 | + if err != nil { | ||
| 56 | + return dividendsEstimate, err | ||
| 57 | + } else { | ||
| 58 | + dividendsEstimate.DividendsEstimateId = dividendsEstimateId | ||
| 59 | + } | ||
| 60 | + if _, err := tx.QueryOne( | ||
| 61 | + pg.Scan( | ||
| 62 | + ÷ndsEstimate.DividendsEstimateId, | ||
| 63 | + ÷ndsEstimate.DividendsAccountStatus, | ||
| 64 | + ÷ndsEstimate.DividendsAmount, | ||
| 65 | + ÷ndsEstimate.DividendsEstimateOrderNumber, | ||
| 66 | + ÷ndsEstimate.DividendsEstimateTime, | ||
| 67 | + ÷ndsEstimate.DividendsParticipateType, | ||
| 68 | + ÷ndsEstimate.DividendsType, | ||
| 69 | + ÷ndsEstimate.OrderOrReturnedOrderNum, | ||
| 70 | + ÷ndsEstimate.CooperationProjectNumber, | ||
| 71 | + ÷ndsEstimate.DividendsUser, | ||
| 72 | + ÷ndsEstimate.Org, | ||
| 73 | + ÷ndsEstimate.Company, | ||
| 74 | + ÷ndsEstimate.Operator, | ||
| 75 | + ÷ndsEstimate.OperateTime, | ||
| 76 | + ÷ndsEstimate.CreatedAt, | ||
| 77 | + ÷ndsEstimate.DeletedAt, | ||
| 78 | + ÷ndsEstimate.UpdatedAt, | ||
| 79 | + ), | ||
| 80 | + fmt.Sprintf("INSERT INTO dividends_estimates (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 81 | + dividendsEstimate.DividendsEstimateId, | ||
| 82 | + dividendsEstimate.DividendsAccountStatus, | ||
| 83 | + dividendsEstimate.DividendsAmount, | ||
| 84 | + dividendsEstimate.DividendsEstimateOrderNumber, | ||
| 85 | + dividendsEstimate.DividendsEstimateTime, | ||
| 86 | + dividendsEstimate.DividendsParticipateType, | ||
| 87 | + dividendsEstimate.DividendsType, | ||
| 88 | + dividendsEstimate.OrderOrReturnedOrderNum, | ||
| 89 | + dividendsEstimate.CooperationProjectNumber, | ||
| 90 | + dividendsEstimate.DividendsUser, | ||
| 91 | + dividendsEstimate.Org, | ||
| 92 | + dividendsEstimate.Company, | ||
| 93 | + dividendsEstimate.Operator, | ||
| 94 | + dividendsEstimate.OperateTime, | ||
| 95 | + dividendsEstimate.CreatedAt, | ||
| 96 | + dividendsEstimate.DeletedAt, | ||
| 97 | + dividendsEstimate.UpdatedAt, | ||
| 98 | + ); err != nil { | ||
| 99 | + return dividendsEstimate, err | ||
| 100 | + } | ||
| 101 | + } else { | ||
| 102 | + if _, err := tx.QueryOne( | ||
| 103 | + pg.Scan( | ||
| 104 | + ÷ndsEstimate.DividendsEstimateId, | ||
| 105 | + ÷ndsEstimate.DividendsAccountStatus, | ||
| 106 | + ÷ndsEstimate.DividendsAmount, | ||
| 107 | + ÷ndsEstimate.DividendsEstimateOrderNumber, | ||
| 108 | + ÷ndsEstimate.DividendsEstimateTime, | ||
| 109 | + ÷ndsEstimate.DividendsParticipateType, | ||
| 110 | + ÷ndsEstimate.DividendsType, | ||
| 111 | + ÷ndsEstimate.OrderOrReturnedOrderNum, | ||
| 112 | + ÷ndsEstimate.CooperationProjectNumber, | ||
| 113 | + ÷ndsEstimate.DividendsUser, | ||
| 114 | + ÷ndsEstimate.Org, | ||
| 115 | + ÷ndsEstimate.Company, | ||
| 116 | + ÷ndsEstimate.Operator, | ||
| 117 | + ÷ndsEstimate.OperateTime, | ||
| 118 | + ÷ndsEstimate.CreatedAt, | ||
| 119 | + ÷ndsEstimate.DeletedAt, | ||
| 120 | + ÷ndsEstimate.UpdatedAt, | ||
| 121 | + ), | ||
| 122 | + fmt.Sprintf("UPDATE dividends_estimates SET %s WHERE dividends_estimate_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 123 | + dividendsEstimate.DividendsEstimateId, | ||
| 124 | + dividendsEstimate.DividendsAccountStatus, | ||
| 125 | + dividendsEstimate.DividendsAmount, | ||
| 126 | + dividendsEstimate.DividendsEstimateOrderNumber, | ||
| 127 | + dividendsEstimate.DividendsEstimateTime, | ||
| 128 | + dividendsEstimate.DividendsParticipateType, | ||
| 129 | + dividendsEstimate.DividendsType, | ||
| 130 | + dividendsEstimate.OrderOrReturnedOrderNum, | ||
| 131 | + dividendsEstimate.CooperationProjectNumber, | ||
| 132 | + dividendsEstimate.DividendsUser, | ||
| 133 | + dividendsEstimate.Org, | ||
| 134 | + dividendsEstimate.Company, | ||
| 135 | + dividendsEstimate.Operator, | ||
| 136 | + dividendsEstimate.OperateTime, | ||
| 137 | + dividendsEstimate.CreatedAt, | ||
| 138 | + dividendsEstimate.DeletedAt, | ||
| 139 | + dividendsEstimate.UpdatedAt, | ||
| 140 | + dividendsEstimate.Identify(), | ||
| 141 | + ); err != nil { | ||
| 142 | + return dividendsEstimate, err | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + return dividendsEstimate, nil | ||
| 146 | +} | ||
| 147 | +func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) { | ||
| 148 | + tx := repository.transactionContext.PgTx | ||
| 149 | + dividendsEstimateModel := new(models.DividendsEstimate) | ||
| 150 | + dividendsEstimateModel.DividendsEstimateId = dividendsEstimate.Identify().(int64) | ||
| 151 | + if _, err := tx.Model(dividendsEstimateModel).WherePK().Delete(); err != nil { | ||
| 152 | + return dividendsEstimate, err | ||
| 153 | + } | ||
| 154 | + return dividendsEstimate, nil | ||
| 155 | +} | ||
| 156 | +func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsEstimate, error) { | ||
| 157 | + tx := repository.transactionContext.PgTx | ||
| 158 | + dividendsEstimateModel := new(models.DividendsEstimate) | ||
| 159 | + query := sqlbuilder.BuildQuery(tx.Model(dividendsEstimateModel), queryOptions) | ||
| 160 | + query.SetWhereByQueryOption("dividends_estimate.dividends_estimate_id = ?", "dividendsEstimateId") | ||
| 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 dividendsEstimateModel.DividendsEstimateId == 0 { | ||
| 169 | + return nil, nil | ||
| 170 | + } else { | ||
| 171 | + return transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel) | ||
| 172 | + } | ||
| 173 | +} | ||
| 174 | +func (repository *DividendsEstimateRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsEstimate, error) { | ||
| 175 | + tx := repository.transactionContext.PgTx | ||
| 176 | + var dividendsEstimateModels []*models.DividendsEstimate | ||
| 177 | + dividendsEstimates := make([]*domain.DividendsEstimate, 0) | ||
| 178 | + query := sqlbuilder.BuildQuery(tx.Model(÷ndsEstimateModels), queryOptions) | ||
| 179 | + query.SetOffsetAndLimit(20) | ||
| 180 | + query.SetOrderDirect("dividends_estimate_id", "DESC") | ||
| 181 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 182 | + return 0, dividendsEstimates, err | ||
| 183 | + } else { | ||
| 184 | + for _, dividendsEstimateModel := range dividendsEstimateModels { | ||
| 185 | + if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil { | ||
| 186 | + return 0, dividendsEstimates, err | ||
| 187 | + } else { | ||
| 188 | + dividendsEstimates = append(dividendsEstimates, dividendsEstimate) | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + return int64(count), dividendsEstimates, nil | ||
| 192 | + } | ||
| 193 | +} | ||
| 194 | +func NewDividendsEstimateRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateRepository, error) { | ||
| 195 | + if transactionContext == nil { | ||
| 196 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 197 | + } else { | ||
| 198 | + return &DividendsEstimateRepository{ | ||
| 199 | + transactionContext: transactionContext, | ||
| 200 | + }, nil | ||
| 201 | + } | ||
| 202 | +} |
| 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 DividendsIncentivesRuleRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *DividendsIncentivesRuleRepository) 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 *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRule *domain.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "dividends_incentives_rule_id", | ||
| 30 | + "cooperation_contract_number", | ||
| 31 | + "referrer_percentage", | ||
| 32 | + "salesman_percentage", | ||
| 33 | + "dividends_incentives_percentage", | ||
| 34 | + "dividends_incentives_stage", | ||
| 35 | + "dividends_incentives_stage_end", | ||
| 36 | + "dividends_incentives_stage_start", | ||
| 37 | + "org", | ||
| 38 | + "company", | ||
| 39 | + "updated_at", | ||
| 40 | + "deleted_at", | ||
| 41 | + "created_at", | ||
| 42 | + } | ||
| 43 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 44 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 45 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 46 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsIncentivesRule_id") | ||
| 47 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 48 | + tx := repository.transactionContext.PgTx | ||
| 49 | + if dividendsIncentivesRule.Identify() == nil { | ||
| 50 | + dividendsIncentivesRuleId, err := repository.nextIdentify() | ||
| 51 | + if err != nil { | ||
| 52 | + return dividendsIncentivesRule, err | ||
| 53 | + } else { | ||
| 54 | + dividendsIncentivesRule.DividendsIncentivesRuleId = dividendsIncentivesRuleId | ||
| 55 | + } | ||
| 56 | + if _, err := tx.QueryOne( | ||
| 57 | + pg.Scan( | ||
| 58 | + ÷ndsIncentivesRule.DividendsIncentivesRuleId, | ||
| 59 | + ÷ndsIncentivesRule.CooperationContractNumber, | ||
| 60 | + ÷ndsIncentivesRule.ReferrerPercentage, | ||
| 61 | + ÷ndsIncentivesRule.SalesmanPercentage, | ||
| 62 | + ÷ndsIncentivesRule.DividendsIncentivesPercentage, | ||
| 63 | + ÷ndsIncentivesRule.DividendsIncentivesStage, | ||
| 64 | + ÷ndsIncentivesRule.DividendsIncentivesStageEnd, | ||
| 65 | + ÷ndsIncentivesRule.DividendsIncentivesStageStart, | ||
| 66 | + ÷ndsIncentivesRule.Org, | ||
| 67 | + ÷ndsIncentivesRule.Company, | ||
| 68 | + ÷ndsIncentivesRule.UpdatedAt, | ||
| 69 | + ÷ndsIncentivesRule.DeletedAt, | ||
| 70 | + ÷ndsIncentivesRule.CreatedAt, | ||
| 71 | + ), | ||
| 72 | + fmt.Sprintf("INSERT INTO dividends_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 73 | + dividendsIncentivesRule.DividendsIncentivesRuleId, | ||
| 74 | + dividendsIncentivesRule.CooperationContractNumber, | ||
| 75 | + dividendsIncentivesRule.ReferrerPercentage, | ||
| 76 | + dividendsIncentivesRule.SalesmanPercentage, | ||
| 77 | + dividendsIncentivesRule.DividendsIncentivesPercentage, | ||
| 78 | + dividendsIncentivesRule.DividendsIncentivesStage, | ||
| 79 | + dividendsIncentivesRule.DividendsIncentivesStageEnd, | ||
| 80 | + dividendsIncentivesRule.DividendsIncentivesStageStart, | ||
| 81 | + dividendsIncentivesRule.Org, | ||
| 82 | + dividendsIncentivesRule.Company, | ||
| 83 | + dividendsIncentivesRule.UpdatedAt, | ||
| 84 | + dividendsIncentivesRule.DeletedAt, | ||
| 85 | + dividendsIncentivesRule.CreatedAt, | ||
| 86 | + ); err != nil { | ||
| 87 | + return dividendsIncentivesRule, err | ||
| 88 | + } | ||
| 89 | + } else { | ||
| 90 | + if _, err := tx.QueryOne( | ||
| 91 | + pg.Scan( | ||
| 92 | + ÷ndsIncentivesRule.DividendsIncentivesRuleId, | ||
| 93 | + ÷ndsIncentivesRule.CooperationContractNumber, | ||
| 94 | + ÷ndsIncentivesRule.ReferrerPercentage, | ||
| 95 | + ÷ndsIncentivesRule.SalesmanPercentage, | ||
| 96 | + ÷ndsIncentivesRule.DividendsIncentivesPercentage, | ||
| 97 | + ÷ndsIncentivesRule.DividendsIncentivesStage, | ||
| 98 | + ÷ndsIncentivesRule.DividendsIncentivesStageEnd, | ||
| 99 | + ÷ndsIncentivesRule.DividendsIncentivesStageStart, | ||
| 100 | + ÷ndsIncentivesRule.Org, | ||
| 101 | + ÷ndsIncentivesRule.Company, | ||
| 102 | + ÷ndsIncentivesRule.UpdatedAt, | ||
| 103 | + ÷ndsIncentivesRule.DeletedAt, | ||
| 104 | + ÷ndsIncentivesRule.CreatedAt, | ||
| 105 | + ), | ||
| 106 | + fmt.Sprintf("UPDATE dividends_incentives_rules SET %s WHERE dividends_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 107 | + dividendsIncentivesRule.DividendsIncentivesRuleId, | ||
| 108 | + dividendsIncentivesRule.CooperationContractNumber, | ||
| 109 | + dividendsIncentivesRule.ReferrerPercentage, | ||
| 110 | + dividendsIncentivesRule.SalesmanPercentage, | ||
| 111 | + dividendsIncentivesRule.DividendsIncentivesPercentage, | ||
| 112 | + dividendsIncentivesRule.DividendsIncentivesStage, | ||
| 113 | + dividendsIncentivesRule.DividendsIncentivesStageEnd, | ||
| 114 | + dividendsIncentivesRule.DividendsIncentivesStageStart, | ||
| 115 | + dividendsIncentivesRule.Org, | ||
| 116 | + dividendsIncentivesRule.Company, | ||
| 117 | + dividendsIncentivesRule.UpdatedAt, | ||
| 118 | + dividendsIncentivesRule.DeletedAt, | ||
| 119 | + dividendsIncentivesRule.CreatedAt, | ||
| 120 | + dividendsIncentivesRule.Identify(), | ||
| 121 | + ); err != nil { | ||
| 122 | + return dividendsIncentivesRule, err | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + return dividendsIncentivesRule, nil | ||
| 126 | +} | ||
| 127 | +func (repository *DividendsIncentivesRuleRepository) Remove(dividendsIncentivesRule *domain.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) { | ||
| 128 | + tx := repository.transactionContext.PgTx | ||
| 129 | + dividendsIncentivesRuleModel := new(models.DividendsIncentivesRule) | ||
| 130 | + dividendsIncentivesRuleModel.DividendsIncentivesRuleId = dividendsIncentivesRule.Identify().(int64) | ||
| 131 | + if _, err := tx.Model(dividendsIncentivesRuleModel).WherePK().Delete(); err != nil { | ||
| 132 | + return dividendsIncentivesRule, err | ||
| 133 | + } | ||
| 134 | + return dividendsIncentivesRule, nil | ||
| 135 | +} | ||
| 136 | +func (repository *DividendsIncentivesRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsIncentivesRule, error) { | ||
| 137 | + tx := repository.transactionContext.PgTx | ||
| 138 | + dividendsIncentivesRuleModel := new(models.DividendsIncentivesRule) | ||
| 139 | + query := sqlbuilder.BuildQuery(tx.Model(dividendsIncentivesRuleModel), queryOptions) | ||
| 140 | + query.SetWhereByQueryOption("dividends_incentives_rule.dividends_incentives_rule_id = ?", "dividendsIncentivesRuleId") | ||
| 141 | + if err := query.First(); err != nil { | ||
| 142 | + if err.Error() == "pg: no rows in result set" { | ||
| 143 | + return nil, fmt.Errorf("没有此资源") | ||
| 144 | + } else { | ||
| 145 | + return nil, err | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == 0 { | ||
| 149 | + return nil, nil | ||
| 150 | + } else { | ||
| 151 | + return transform.TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel) | ||
| 152 | + } | ||
| 153 | +} | ||
| 154 | +func (repository *DividendsIncentivesRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsIncentivesRule, error) { | ||
| 155 | + tx := repository.transactionContext.PgTx | ||
| 156 | + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule | ||
| 157 | + dividendsIncentivesRules := make([]*domain.DividendsIncentivesRule, 0) | ||
| 158 | + query := sqlbuilder.BuildQuery(tx.Model(÷ndsIncentivesRuleModels), queryOptions) | ||
| 159 | + query.SetOffsetAndLimit(20) | ||
| 160 | + query.SetOrderDirect("dividends_incentives_rule_id", "DESC") | ||
| 161 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 162 | + return 0, dividendsIncentivesRules, err | ||
| 163 | + } else { | ||
| 164 | + for _, dividendsIncentivesRuleModel := range dividendsIncentivesRuleModels { | ||
| 165 | + if dividendsIncentivesRule, err := transform.TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel); err != nil { | ||
| 166 | + return 0, dividendsIncentivesRules, err | ||
| 167 | + } else { | ||
| 168 | + dividendsIncentivesRules = append(dividendsIncentivesRules, dividendsIncentivesRule) | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + return int64(count), dividendsIncentivesRules, nil | ||
| 172 | + } | ||
| 173 | +} | ||
| 174 | +func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsIncentivesRuleRepository, error) { | ||
| 175 | + if transactionContext == nil { | ||
| 176 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 177 | + } else { | ||
| 178 | + return &DividendsIncentivesRuleRepository{ | ||
| 179 | + transactionContext: transactionContext, | ||
| 180 | + }, nil | ||
| 181 | + } | ||
| 182 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + | ||
| 6 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 8 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type MoneyIncentivesRuleRepository struct { | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) { | ||
| 19 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 20 | + if err != nil { | ||
| 21 | + return 0, err | ||
| 22 | + } | ||
| 23 | + id, err := IdWorker.NextId() | ||
| 24 | + return id, err | ||
| 25 | +} | ||
| 26 | +func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domain.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) { | ||
| 27 | + sqlBuildFields := []string{ | ||
| 28 | + "money_icentives_rule_id", | ||
| 29 | + "cooperation_contract_number", | ||
| 30 | + "money_incentives_amount", | ||
| 31 | + "money_incentives_stage", | ||
| 32 | + "money_incentives_stage_end", | ||
| 33 | + "money_incentives_stage_start", | ||
| 34 | + "money_incentives_time", | ||
| 35 | + "referrer_percentage", | ||
| 36 | + "salesman_percentage", | ||
| 37 | + "org", | ||
| 38 | + "company", | ||
| 39 | + "updated_at", | ||
| 40 | + "deleted_at", | ||
| 41 | + "created_at", | ||
| 42 | + } | ||
| 43 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 44 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 45 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 46 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "moneyIncentivesRule_id") | ||
| 47 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 48 | + tx := repository.transactionContext.PgTx | ||
| 49 | + if moneyIncentivesRule.Identify() == nil { | ||
| 50 | + moneyIncentivesRuleId, err := repository.nextIdentify() | ||
| 51 | + if err != nil { | ||
| 52 | + return moneyIncentivesRule, err | ||
| 53 | + } else { | ||
| 54 | + moneyIncentivesRule.MoneyIncentivesRuleId = moneyIncentivesRuleId | ||
| 55 | + } | ||
| 56 | + if _, err := tx.QueryOne( | ||
| 57 | + pg.Scan( | ||
| 58 | + &moneyIncentivesRule.MoneyIcentivesRuleId, | ||
| 59 | + &moneyIncentivesRule.CooperationContractNumber, | ||
| 60 | + &moneyIncentivesRule.MoneyIncentivesAmount, | ||
| 61 | + &moneyIncentivesRule.MoneyIncentivesStage, | ||
| 62 | + &moneyIncentivesRule.MoneyIncentivesStageEnd, | ||
| 63 | + &moneyIncentivesRule.MoneyIncentivesStageStart, | ||
| 64 | + &moneyIncentivesRule.MoneyIncentivesTime, | ||
| 65 | + &moneyIncentivesRule.ReferrerPercentage, | ||
| 66 | + &moneyIncentivesRule.SalesmanPercentage, | ||
| 67 | + &moneyIncentivesRule.Org, | ||
| 68 | + &moneyIncentivesRule.Company, | ||
| 69 | + &moneyIncentivesRule.UpdatedAt, | ||
| 70 | + &moneyIncentivesRule.DeletedAt, | ||
| 71 | + &moneyIncentivesRule.CreatedAt, | ||
| 72 | + ), | ||
| 73 | + fmt.Sprintf("INSERT INTO money_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 74 | + moneyIncentivesRule.MoneyIcentivesRuleId, | ||
| 75 | + moneyIncentivesRule.CooperationContractNumber, | ||
| 76 | + moneyIncentivesRule.MoneyIncentivesAmount, | ||
| 77 | + moneyIncentivesRule.MoneyIncentivesStage, | ||
| 78 | + moneyIncentivesRule.MoneyIncentivesStageEnd, | ||
| 79 | + moneyIncentivesRule.MoneyIncentivesStageStart, | ||
| 80 | + moneyIncentivesRule.MoneyIncentivesTime, | ||
| 81 | + moneyIncentivesRule.ReferrerPercentage, | ||
| 82 | + moneyIncentivesRule.SalesmanPercentage, | ||
| 83 | + moneyIncentivesRule.Org, | ||
| 84 | + moneyIncentivesRule.Company, | ||
| 85 | + moneyIncentivesRule.UpdatedAt, | ||
| 86 | + moneyIncentivesRule.DeletedAt, | ||
| 87 | + moneyIncentivesRule.CreatedAt, | ||
| 88 | + ); err != nil { | ||
| 89 | + return moneyIncentivesRule, err | ||
| 90 | + } | ||
| 91 | + } else { | ||
| 92 | + if _, err := tx.QueryOne( | ||
| 93 | + pg.Scan( | ||
| 94 | + &moneyIncentivesRule.MoneyIcentivesRuleId, | ||
| 95 | + &moneyIncentivesRule.CooperationContractNumber, | ||
| 96 | + &moneyIncentivesRule.MoneyIncentivesAmount, | ||
| 97 | + &moneyIncentivesRule.MoneyIncentivesStage, | ||
| 98 | + &moneyIncentivesRule.MoneyIncentivesStageEnd, | ||
| 99 | + &moneyIncentivesRule.MoneyIncentivesStageStart, | ||
| 100 | + &moneyIncentivesRule.MoneyIncentivesTime, | ||
| 101 | + &moneyIncentivesRule.ReferrerPercentage, | ||
| 102 | + &moneyIncentivesRule.SalesmanPercentage, | ||
| 103 | + &moneyIncentivesRule.Org, | ||
| 104 | + &moneyIncentivesRule.Company, | ||
| 105 | + &moneyIncentivesRule.UpdatedAt, | ||
| 106 | + &moneyIncentivesRule.DeletedAt, | ||
| 107 | + &moneyIncentivesRule.CreatedAt, | ||
| 108 | + ), | ||
| 109 | + fmt.Sprintf("UPDATE money_incentives_rules SET %s WHERE money_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 110 | + moneyIncentivesRule.MoneyIcentivesRuleId, | ||
| 111 | + moneyIncentivesRule.CooperationContractNumber, | ||
| 112 | + moneyIncentivesRule.MoneyIncentivesAmount, | ||
| 113 | + moneyIncentivesRule.MoneyIncentivesStage, | ||
| 114 | + moneyIncentivesRule.MoneyIncentivesStageEnd, | ||
| 115 | + moneyIncentivesRule.MoneyIncentivesStageStart, | ||
| 116 | + moneyIncentivesRule.MoneyIncentivesTime, | ||
| 117 | + moneyIncentivesRule.ReferrerPercentage, | ||
| 118 | + moneyIncentivesRule.SalesmanPercentage, | ||
| 119 | + moneyIncentivesRule.Org, | ||
| 120 | + moneyIncentivesRule.Company, | ||
| 121 | + moneyIncentivesRule.UpdatedAt, | ||
| 122 | + moneyIncentivesRule.DeletedAt, | ||
| 123 | + moneyIncentivesRule.CreatedAt, | ||
| 124 | + moneyIncentivesRule.Identify(), | ||
| 125 | + ); err != nil { | ||
| 126 | + return moneyIncentivesRule, err | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + return moneyIncentivesRule, nil | ||
| 130 | +} | ||
| 131 | +func (repository *MoneyIncentivesRuleRepository) Remove(moneyIncentivesRule *domain.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) { | ||
| 132 | + tx := repository.transactionContext.PgTx | ||
| 133 | + moneyIncentivesRuleModel := new(models.MoneyIncentivesRule) | ||
| 134 | + moneyIncentivesRuleModel.MoneyIncentivesRuleId = moneyIncentivesRule.Identify().(int64) | ||
| 135 | + if _, err := tx.Model(moneyIncentivesRuleModel).WherePK().Delete(); err != nil { | ||
| 136 | + return moneyIncentivesRule, err | ||
| 137 | + } | ||
| 138 | + return moneyIncentivesRule, nil | ||
| 139 | +} | ||
| 140 | +func (repository *MoneyIncentivesRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.MoneyIncentivesRule, error) { | ||
| 141 | + tx := repository.transactionContext.PgTx | ||
| 142 | + moneyIncentivesRuleModel := new(models.MoneyIncentivesRule) | ||
| 143 | + query := sqlbuilder.BuildQuery(tx.Model(moneyIncentivesRuleModel), queryOptions) | ||
| 144 | + query.SetWhereByQueryOption("money_incentives_rule.money_incentives_rule_id = ?", "moneyIncentivesRuleId") | ||
| 145 | + if err := query.First(); err != nil { | ||
| 146 | + if err.Error() == "pg: no rows in result set" { | ||
| 147 | + return nil, fmt.Errorf("没有此资源") | ||
| 148 | + } else { | ||
| 149 | + return nil, err | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + if moneyIncentivesRuleModel.MoneyIncentivesRuleId == 0 { | ||
| 153 | + return nil, nil | ||
| 154 | + } else { | ||
| 155 | + return transform.TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel) | ||
| 156 | + } | ||
| 157 | +} | ||
| 158 | +func (repository *MoneyIncentivesRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.MoneyIncentivesRule, error) { | ||
| 159 | + tx := repository.transactionContext.PgTx | ||
| 160 | + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule | ||
| 161 | + moneyIncentivesRules := make([]*domain.MoneyIncentivesRule, 0) | ||
| 162 | + query := sqlbuilder.BuildQuery(tx.Model(&moneyIncentivesRuleModels), queryOptions) | ||
| 163 | + query.SetOffsetAndLimit(20) | ||
| 164 | + query.SetOrderDirect("money_incentives_rule_id", "DESC") | ||
| 165 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 166 | + return 0, moneyIncentivesRules, err | ||
| 167 | + } else { | ||
| 168 | + for _, moneyIncentivesRuleModel := range moneyIncentivesRuleModels { | ||
| 169 | + if moneyIncentivesRule, err := transform.TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel); err != nil { | ||
| 170 | + return 0, moneyIncentivesRules, err | ||
| 171 | + } else { | ||
| 172 | + moneyIncentivesRules = append(moneyIncentivesRules, moneyIncentivesRule) | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + return int64(count), moneyIncentivesRules, nil | ||
| 176 | + } | ||
| 177 | +} | ||
| 178 | +func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.TransactionContext) (*MoneyIncentivesRuleRepository, error) { | ||
| 179 | + if transactionContext == nil { | ||
| 180 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 181 | + } else { | ||
| 182 | + return &MoneyIncentivesRuleRepository{ | ||
| 183 | + transactionContext: transactionContext, | ||
| 184 | + }, nil | ||
| 185 | + } | ||
| 186 | +} |
-
请 注册 或 登录 后发表评论