作者 陈志颖

feat:添加领域代码

... ... @@ -39,3 +39,27 @@ func CreateContractUndertakerFeedbackRepository(options map[string]interface{})
}
return repository.NewContractUndertakerFeedbackRepository(transactionContext)
}
func CreateDividendsEstimateRepository(options map[string]interface{}) (domain.DividendsEstimateRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDividendsEstimateRepository(transactionContext)
}
func CreateDividendsIncentivesRuleRepository(options map[string]interface{}) (domain.DividendsIncentivesRuleRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDividendsIncentivesRuleRepository(transactionContext)
}
func CreateMoneyIncentivesRuleRepository(options map[string]interface{}) (domain.MoneyIncentivesRuleRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewMoneyIncentivesRuleRepository(transactionContext)
}
... ...
... ... @@ -130,17 +130,5 @@ func (contractUndertakerFeedback *ContractUndertakerFeedback) Update(data map[st
if remarks, ok := data["remarks"]; ok {
contractUndertakerFeedback.CooperationMode.Remarks = remarks.(string)
}
if operateTime, ok := data["operateTime"]; ok {
contractUndertakerFeedback.CooperationMode.OperateTime = operateTime.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
contractUndertakerFeedback.CooperationMode.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
contractUndertakerFeedback.CooperationMode.DeletedAt = deletedAt.(time.Time)
}
if createdAt, ok := data["createdAt"]; ok {
contractUndertakerFeedback.CooperationMode.CreatedAt = createdAt.(time.Time)
}
return nil
}
... ...
package domain
import "time"
// 分红预算实体
type DividendsEstimate struct {
// 承接人分红预算记录ID
DividendsEstimateId int64 `json:"dividendsEstimateId,string"`
// 分红结算状态
DividendsAccountStatus int32 `json:"dividendsAccountStatus"`
// 分红金额
DividendsAmount float64 `json:"dividendsAmount"`
// 承接人分红预算单号
DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"`
// 分红预算时间
DividendsEstimateTime time.Time `json:"dividendsEstimateTime"`
// 参与分红类型,1承接人,2推荐人,3关联业务员
DividendsParticipateType int32 `json:"dividendsParticipateType"`
// 分红类型,1订单分红,2退货冲销,3金额激励
DividendsType int32 `json:"dividendsType"`
// 分红订单号或退货单号
OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `json:"cooperationProjectNumber"`
// 分红用户
DividendsUser *User `json:"dividendsUser"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 操作人
Operator *User `json:"operator"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
}
type DividendsEstimateRepository interface {
Save(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error)
Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error)
FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsEstimate, error)
}
func (dividendsEstimate *DividendsEstimate) Identify() interface{} {
if dividendsEstimate.DividendsEstimateId == 0 {
return nil
}
return dividendsEstimate.DividendsEstimateId
}
func (dividendsEstimate *DividendsEstimate) Update(data map[string]interface{}) error {
if dividendsEstimateId, ok := data["dividendsEstimateId"]; ok {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId.(int64)
}
if dividendsAccountStatus, ok := data["dividendsAccountStatus"]; ok {
dividendsEstimate.DividendsAccountStatus = dividendsAccountStatus.(int32)
}
if dividendsAmount, ok := data["dividendsAmount"]; ok {
dividendsEstimate.DividendsAmount = dividendsAmount.(float64)
}
if dividendsEstimateOrderNumber, ok := data["dividendsEstimateOrderNumber"]; ok {
dividendsEstimate.DividendsEstimateOrderNumber = dividendsEstimateOrderNumber.(string)
}
if dividendsEstimateTime, ok := data["dividendsEstimateTime"]; ok {
dividendsEstimate.DividendsEstimateTime = dividendsEstimateTime.(time.Time)
}
if dividendsParticipateType, ok := data["dividendsParticipateType"]; ok {
dividendsEstimate.DividendsParticipateType = dividendsParticipateType.(int32)
}
if dividendsType, ok := data["dividendsType"]; ok {
dividendsEstimate.DividendsType = dividendsType.(int32)
}
if orderOrReturnedOrderNum, ok := data["orderOrReturnedOrderNum"]; ok {
dividendsEstimate.OrderOrReturnedOrderNum = orderOrReturnedOrderNum.(string)
}
if cooperationProjectNumber, ok := data["cooperationProjectNumber"]; ok {
dividendsEstimate.CooperationProjectNumber = cooperationProjectNumber.(string)
}
if userId, ok := data["userId"]; ok {
dividendsEstimate.DividendsUser.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
dividendsEstimate.DividendsUser.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
dividendsEstimate.DividendsUser.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
dividendsEstimate.DividendsUser.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
dividendsEstimate.DividendsUser.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
dividendsEstimate.DividendsUser.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
dividendsEstimate.DividendsUser.Org.Company.CompanyName = companyName.(string)
}
if orgs, ok := data["orgs"]; ok {
dividendsEstimate.DividendsUser.Orgs = orgs.([]*Org)
}
if departmentId, ok := data["departmentId"]; ok {
dividendsEstimate.DividendsUser.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
dividendsEstimate.DividendsUser.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
dividendsEstimate.DividendsUser.Department.DepartmentNumber = departmentNumber.(string)
}
if isOrganization, ok := data["isOrganization"]; ok {
dividendsEstimate.DividendsUser.Department.IsOrganization = isOrganization.(bool)
}
if roleId, ok := data["roleId"]; ok {
dividendsEstimate.DividendsUser.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
dividendsEstimate.DividendsUser.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
dividendsEstimate.DividendsUser.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
dividendsEstimate.DividendsUser.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
dividendsEstimate.DividendsUser.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
dividendsEstimate.DividendsUser.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
dividendsEstimate.DividendsUser.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
dividendsEstimate.DividendsUser.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
dividendsEstimate.DividendsUser.Status = status.(int32)
}
return nil
}
... ...
package domain
import "time"
// 金额激励规则实体
type DividendsIncentivesRule struct {
// 分红规则ID
DividendsIncentivesRuleId int64 `json:"dividendsIncentivesRuleId,string"`
// 关联的项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
}
type DividendsIncentivesRuleRepository interface {
Save(dividendsIncentivesRule *DividendsIncentivesRule) (*DividendsIncentivesRule, error)
Remove(dividendsIncentivesRule *DividendsIncentivesRule) (*DividendsIncentivesRule, error)
FindOne(queryOptions map[string]interface{}) (*DividendsIncentivesRule, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsIncentivesRule, error)
}
func (dividendsIncentivesRule *DividendsIncentivesRule) Identify() interface{} {
if dividendsIncentivesRule.DividendsIncentivesRuleId == 0 {
return nil
}
return dividendsIncentivesRule.DividendsIncentivesRuleId
}
func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]interface{}) error {
if dividendsIncentivesRuleId, ok := data["dividendsIncentivesRuleId"]; ok {
dividendsIncentivesRule.DividendsIncentivesRuleId = dividendsIncentivesRuleId.(int64)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
dividendsIncentivesRule.CooperationContractNumber = cooperationContractNumber.(string)
}
if referrerPercentage, ok := data["referrerPercentage"]; ok {
dividendsIncentivesRule.ReferrerPercentage = referrerPercentage.(float64)
}
if salesmanPercentage, ok := data["salesmanPercentage"]; ok {
dividendsIncentivesRule.SalesmanPercentage = salesmanPercentage.(float64)
}
if dividendsIncentivesPercentage, ok := data["dividendsIncentivesPercentage"]; ok {
dividendsIncentivesRule.DividendsIncentivesPercentage = dividendsIncentivesPercentage.(float64)
}
if dividendsIncentivesStage, ok := data["dividendsIncentivesStage"]; ok {
dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int64)
}
if dividendsIncentivesStageEnd, ok := data["dividendsIncentivesStageEnd"]; ok {
dividendsIncentivesRule.DividendsIncentivesStageEnd = dividendsIncentivesStageEnd.(time.Time)
}
if dividendsIncentivesStageStart, ok := data["dividendsIncentivesStageStart"]; ok {
dividendsIncentivesRule.DividendsIncentivesStageStart = dividendsIncentivesStageStart.(time.Time)
}
if orgId, ok := data["orgId"]; ok {
dividendsIncentivesRule.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
dividendsIncentivesRule.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
dividendsIncentivesRule.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
dividendsIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
dividendsIncentivesRule.Org.Company.CompanyName = companyName.(string)
}
return nil
}
... ...
package domain
import "time"
// 金额激励规则实体
type MoneyIncentivesRule struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string"`
// 金额激励阶段有效期结束
MoneyIncentivesStageEnd time.Time `json:"moneyIncentivesStageEnd"`
// 金额激励阶段有效期开始
MoneyIncentivesStageStart time.Time `json:"moneyIncentivesStageStart"`
// 金额激励规则时间
MoneyIncentivesTime time.Time `json:"moneyIncentivesTime"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
}
type MoneyIncentivesRuleRepository interface {
Save(moneyIncentivesRule *MoneyIncentivesRule) (*MoneyIncentivesRule, error)
Remove(moneyIncentivesRule *MoneyIncentivesRule) (*MoneyIncentivesRule, error)
FindOne(queryOptions map[string]interface{}) (*MoneyIncentivesRule, error)
Find(queryOptions map[string]interface{}) (int64, []*MoneyIncentivesRule, error)
}
func (moneyIncentivesRule *MoneyIncentivesRule) Identify() interface{} {
if moneyIncentivesRule.MoneyIncentivesRuleId == 0 {
return nil
}
return moneyIncentivesRule.MoneyIncentivesRuleId
}
func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface{}) error {
if moneyIncentivesRuleId, ok := data["moneyIncentivesRuleId"]; ok {
moneyIncentivesRule.MoneyIncentivesRuleId = moneyIncentivesRuleId.(int64)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
moneyIncentivesRule.CooperationContractNumber = cooperationContractNumber.(string)
}
if moneyIncentivesAmount, ok := data["moneyIncentivesAmount"]; ok {
moneyIncentivesRule.MoneyIncentivesAmount = moneyIncentivesAmount.(float64)
}
if moneyIncentivesStage, ok := data["moneyIncentivesStage"]; ok {
moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int64)
}
if moneyIncentivesStageEnd, ok := data["moneyIncentivesStageEnd"]; ok {
moneyIncentivesRule.MoneyIncentivesStageEnd = moneyIncentivesStageEnd.(time.Time)
}
if moneyIncentivesStageStart, ok := data["moneyIncentivesStageStart"]; ok {
moneyIncentivesRule.MoneyIncentivesStageStart = moneyIncentivesStageStart.(time.Time)
}
if moneyIncentivesTime, ok := data["moneyIncentivesTime"]; ok {
moneyIncentivesRule.MoneyIncentivesTime = moneyIncentivesTime.(time.Time)
}
if referrerPercentage, ok := data["referrerPercentage"]; ok {
moneyIncentivesRule.ReferrerPercentage = referrerPercentage.(float64)
}
if salesmanPercentage, ok := data["salesmanPercentage"]; ok {
moneyIncentivesRule.SalesmanPercentage = salesmanPercentage.(float64)
}
if orgId, ok := data["orgId"]; ok {
moneyIncentivesRule.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
moneyIncentivesRule.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
moneyIncentivesRule.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
moneyIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
moneyIncentivesRule.Org.Company.CompanyName = companyName.(string)
}
return nil
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DividendsEstimate struct {
tableName string `comment:"分红预算实体" pg:"dividends_estimates,alias:dividends_estimate"`
// 承接人分红预算记录ID
DividendsEstimateId int64 `comment:"承接人分红预算记录ID" pg:"pk:dividends_estimate_id"`
// 分红结算状态
DividendsAccountStatus int32 `comment:"分红结算状态"`
// 分红金额
DividendsAmount float64 `comment:"分红金额"`
// 承接人分红预算单号
DividendsEstimateOrderNumber string `comment:"承接人分红预算单号"`
// 分红预算时间
DividendsEstimateTime time.Time `comment:"分红预算时间"`
// 参与分红类型,1承接人,2推荐人,3关联业务员
DividendsParticipateType int32 `comment:"参与分红类型,1承接人,2推荐人,3关联业务员"`
// 分红类型,1订单分红,2退货冲销,3金额激励
DividendsType int32 `comment:"分红类型,1订单分红,2退货冲销,3金额激励"`
// 分红订单号或退货单号
OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `comment:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001"`
// 分红用户
DividendsUser *domain.User `comment:"分红用户"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
Company *domain.Company `comment:"公司"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DividendsIncentivesRule struct {
tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"`
// 分红规则ID
DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:"pk:dividends_incentives_rule_id"`
// 关联的项目合约编号
CooperationContractNumber string `comment:"关联的项目合约编号"`
// 推荐人抽成比例
ReferrerPercentage float64 `comment:"推荐人抽成比例"`
// 业务员抽成比例
SalesmanPercentage float64 `comment:"业务员抽成比例"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `comment:"分红规则激励百分点"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `comment:"分红规则激励阶段开始"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
Company *domain.Company `comment:"公司"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
}
... ...
package models
type MoneyIncentivesRule struct {
tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"`
// 金额激励规则ID
MoneyIcentivesRuleId int64 `comment:"金额激励规则ID"`
// 关联的共创合约编号
CooperationContractNumber string `comment:"关联的共创合约编号"`
// 激励金额
MoneyIncentivesAmount float64 `comment:"激励金额"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"`
// 金额激励阶段有效期结束
MoneyIncentivesStageEnd time.Time `comment:"金额激励阶段有效期结束"`
// 金额激励阶段有效期开始
MoneyIncentivesStageStart time.Time `comment:"金额激励阶段有效期开始"`
// 金额激励规则时间
MoneyIncentivesTime time.Time `comment:"金额激励规则时间"`
// 推荐人抽成比例
ReferrerPercentage float64 `comment:"推荐人抽成比例"`
// 业务员抽成比例
SalesmanPercentage float64 `comment:"业务员抽成比例"`
// 数据所属组织机构
Org *Org `comment:"数据所属组织机构"`
// 公司
Company *Company `comment:"公司"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel *models.DividendsEstimate) (*domain.DividendsEstimate, error) {
return &domain.DividendsEstimate{
DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,
DividendsAmount: dividendsEstimateModel.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType,
DividendsType: dividendsEstimateModel.DividendsType,
OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,
CooperationProjectNumber: dividendsEstimateModel.CooperationProjectNumber,
DividendsUser: dividendsEstimateModel.DividendsUser,
Org: dividendsEstimateModel.Org,
Company: dividendsEstimateModel.Company,
Operator: dividendsEstimateModel.Operator,
OperateTime: dividendsEstimateModel.OperateTime,
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel *models.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) {
return &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleModel.DividendsIncentivesRuleId,
CooperationContractNumber: dividendsIncentivesRuleModel.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRuleModel.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRuleModel.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRuleModel.DividendsIncentivesPercentage,
DividendsIncentivesStage: dividendsIncentivesRuleModel.DividendsIncentivesStage,
DividendsIncentivesStageEnd: dividendsIncentivesRuleModel.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRuleModel.DividendsIncentivesStageStart,
Org: dividendsIncentivesRuleModel.Org,
Company: dividendsIncentivesRuleModel.Company,
UpdatedAt: dividendsIncentivesRuleModel.UpdatedAt,
DeletedAt: dividendsIncentivesRuleModel.DeletedAt,
CreatedAt: dividendsIncentivesRuleModel.CreatedAt,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel *models.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) {
return &domain.MoneyIncentivesRule{
MoneyIcentivesRuleId: moneyIncentivesRuleModel.MoneyIcentivesRuleId,
CooperationContractNumber: moneyIncentivesRuleModel.CooperationContractNumber,
MoneyIncentivesAmount: moneyIncentivesRuleModel.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRuleModel.MoneyIncentivesStage,
MoneyIncentivesStageEnd: moneyIncentivesRuleModel.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRuleModel.MoneyIncentivesStageStart,
MoneyIncentivesTime: moneyIncentivesRuleModel.MoneyIncentivesTime,
ReferrerPercentage: moneyIncentivesRuleModel.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRuleModel.SalesmanPercentage,
Org: moneyIncentivesRuleModel.Org,
Company: moneyIncentivesRuleModel.Company,
UpdatedAt: moneyIncentivesRuleModel.UpdatedAt,
DeletedAt: moneyIncentivesRuleModel.DeletedAt,
CreatedAt: moneyIncentivesRuleModel.CreatedAt,
}, nil
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type DividendsEstimateRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) {
sqlBuildFields := []string{
"dividends_estimate_id",
"dividends_account_status",
"dividends_amount",
"dividends_estimate_order_number",
"dividends_estimate_time",
"dividends_participate_type",
"dividends_type",
"order_or_returned_order_num",
"cooperation_project_number",
"dividends_user",
"org",
"company",
"operator",
"operate_time",
"created_at",
"deleted_at",
"updated_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsEstimate_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsEstimate.Identify() == nil {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return dividendsEstimate, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
if _, err := tx.QueryOne(
pg.Scan(
&dividendsEstimate.DividendsEstimateId,
&dividendsEstimate.DividendsAccountStatus,
&dividendsEstimate.DividendsAmount,
&dividendsEstimate.DividendsEstimateOrderNumber,
&dividendsEstimate.DividendsEstimateTime,
&dividendsEstimate.DividendsParticipateType,
&dividendsEstimate.DividendsType,
&dividendsEstimate.OrderOrReturnedOrderNum,
&dividendsEstimate.CooperationProjectNumber,
&dividendsEstimate.DividendsUser,
&dividendsEstimate.Org,
&dividendsEstimate.Company,
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
),
fmt.Sprintf("INSERT INTO dividends_estimates (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
dividendsEstimate.DividendsAccountStatus,
dividendsEstimate.DividendsAmount,
dividendsEstimate.DividendsEstimateOrderNumber,
dividendsEstimate.DividendsEstimateTime,
dividendsEstimate.DividendsParticipateType,
dividendsEstimate.DividendsType,
dividendsEstimate.OrderOrReturnedOrderNum,
dividendsEstimate.CooperationProjectNumber,
dividendsEstimate.DividendsUser,
dividendsEstimate.Org,
dividendsEstimate.Company,
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.CreatedAt,
dividendsEstimate.DeletedAt,
dividendsEstimate.UpdatedAt,
); err != nil {
return dividendsEstimate, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&dividendsEstimate.DividendsEstimateId,
&dividendsEstimate.DividendsAccountStatus,
&dividendsEstimate.DividendsAmount,
&dividendsEstimate.DividendsEstimateOrderNumber,
&dividendsEstimate.DividendsEstimateTime,
&dividendsEstimate.DividendsParticipateType,
&dividendsEstimate.DividendsType,
&dividendsEstimate.OrderOrReturnedOrderNum,
&dividendsEstimate.CooperationProjectNumber,
&dividendsEstimate.DividendsUser,
&dividendsEstimate.Org,
&dividendsEstimate.Company,
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
),
fmt.Sprintf("UPDATE dividends_estimates SET %s WHERE dividends_estimate_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
dividendsEstimate.DividendsAccountStatus,
dividendsEstimate.DividendsAmount,
dividendsEstimate.DividendsEstimateOrderNumber,
dividendsEstimate.DividendsEstimateTime,
dividendsEstimate.DividendsParticipateType,
dividendsEstimate.DividendsType,
dividendsEstimate.OrderOrReturnedOrderNum,
dividendsEstimate.CooperationProjectNumber,
dividendsEstimate.DividendsUser,
dividendsEstimate.Org,
dividendsEstimate.Company,
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.CreatedAt,
dividendsEstimate.DeletedAt,
dividendsEstimate.UpdatedAt,
dividendsEstimate.Identify(),
); err != nil {
return dividendsEstimate, err
}
}
return dividendsEstimate, nil
}
func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
dividendsEstimateModel := new(models.DividendsEstimate)
dividendsEstimateModel.DividendsEstimateId = dividendsEstimate.Identify().(int64)
if _, err := tx.Model(dividendsEstimateModel).WherePK().Delete(); err != nil {
return dividendsEstimate, err
}
return dividendsEstimate, nil
}
func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
dividendsEstimateModel := new(models.DividendsEstimate)
query := sqlbuilder.BuildQuery(tx.Model(dividendsEstimateModel), queryOptions)
query.SetWhereByQueryOption("dividends_estimate.dividends_estimate_id = ?", "dividendsEstimateId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if dividendsEstimateModel.DividendsEstimateId == 0 {
return nil, nil
} else {
return transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel)
}
}
func (repository *DividendsEstimateRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsEstimateModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("dividends_estimate_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsEstimates, err
} else {
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return 0, dividendsEstimates, err
} else {
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
}
return int64(count), dividendsEstimates, nil
}
}
func NewDividendsEstimateRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DividendsEstimateRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type DividendsIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRule *domain.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) {
sqlBuildFields := []string{
"dividends_incentives_rule_id",
"cooperation_contract_number",
"referrer_percentage",
"salesman_percentage",
"dividends_incentives_percentage",
"dividends_incentives_stage",
"dividends_incentives_stage_end",
"dividends_incentives_stage_start",
"org",
"company",
"updated_at",
"deleted_at",
"created_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsIncentivesRule_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsIncentivesRule.Identify() == nil {
dividendsIncentivesRuleId, err := repository.nextIdentify()
if err != nil {
return dividendsIncentivesRule, err
} else {
dividendsIncentivesRule.DividendsIncentivesRuleId = dividendsIncentivesRuleId
}
if _, err := tx.QueryOne(
pg.Scan(
&dividendsIncentivesRule.DividendsIncentivesRuleId,
&dividendsIncentivesRule.CooperationContractNumber,
&dividendsIncentivesRule.ReferrerPercentage,
&dividendsIncentivesRule.SalesmanPercentage,
&dividendsIncentivesRule.DividendsIncentivesPercentage,
&dividendsIncentivesRule.DividendsIncentivesStage,
&dividendsIncentivesRule.DividendsIncentivesStageEnd,
&dividendsIncentivesRule.DividendsIncentivesStageStart,
&dividendsIncentivesRule.Org,
&dividendsIncentivesRule.Company,
&dividendsIncentivesRule.UpdatedAt,
&dividendsIncentivesRule.DeletedAt,
&dividendsIncentivesRule.CreatedAt,
),
fmt.Sprintf("INSERT INTO dividends_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsIncentivesRule.DividendsIncentivesRuleId,
dividendsIncentivesRule.CooperationContractNumber,
dividendsIncentivesRule.ReferrerPercentage,
dividendsIncentivesRule.SalesmanPercentage,
dividendsIncentivesRule.DividendsIncentivesPercentage,
dividendsIncentivesRule.DividendsIncentivesStage,
dividendsIncentivesRule.DividendsIncentivesStageEnd,
dividendsIncentivesRule.DividendsIncentivesStageStart,
dividendsIncentivesRule.Org,
dividendsIncentivesRule.Company,
dividendsIncentivesRule.UpdatedAt,
dividendsIncentivesRule.DeletedAt,
dividendsIncentivesRule.CreatedAt,
); err != nil {
return dividendsIncentivesRule, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&dividendsIncentivesRule.DividendsIncentivesRuleId,
&dividendsIncentivesRule.CooperationContractNumber,
&dividendsIncentivesRule.ReferrerPercentage,
&dividendsIncentivesRule.SalesmanPercentage,
&dividendsIncentivesRule.DividendsIncentivesPercentage,
&dividendsIncentivesRule.DividendsIncentivesStage,
&dividendsIncentivesRule.DividendsIncentivesStageEnd,
&dividendsIncentivesRule.DividendsIncentivesStageStart,
&dividendsIncentivesRule.Org,
&dividendsIncentivesRule.Company,
&dividendsIncentivesRule.UpdatedAt,
&dividendsIncentivesRule.DeletedAt,
&dividendsIncentivesRule.CreatedAt,
),
fmt.Sprintf("UPDATE dividends_incentives_rules SET %s WHERE dividends_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsIncentivesRule.DividendsIncentivesRuleId,
dividendsIncentivesRule.CooperationContractNumber,
dividendsIncentivesRule.ReferrerPercentage,
dividendsIncentivesRule.SalesmanPercentage,
dividendsIncentivesRule.DividendsIncentivesPercentage,
dividendsIncentivesRule.DividendsIncentivesStage,
dividendsIncentivesRule.DividendsIncentivesStageEnd,
dividendsIncentivesRule.DividendsIncentivesStageStart,
dividendsIncentivesRule.Org,
dividendsIncentivesRule.Company,
dividendsIncentivesRule.UpdatedAt,
dividendsIncentivesRule.DeletedAt,
dividendsIncentivesRule.CreatedAt,
dividendsIncentivesRule.Identify(),
); err != nil {
return dividendsIncentivesRule, err
}
}
return dividendsIncentivesRule, nil
}
func (repository *DividendsIncentivesRuleRepository) Remove(dividendsIncentivesRule *domain.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) {
tx := repository.transactionContext.PgTx
dividendsIncentivesRuleModel := new(models.DividendsIncentivesRule)
dividendsIncentivesRuleModel.DividendsIncentivesRuleId = dividendsIncentivesRule.Identify().(int64)
if _, err := tx.Model(dividendsIncentivesRuleModel).WherePK().Delete(); err != nil {
return dividendsIncentivesRule, err
}
return dividendsIncentivesRule, nil
}
func (repository *DividendsIncentivesRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsIncentivesRule, error) {
tx := repository.transactionContext.PgTx
dividendsIncentivesRuleModel := new(models.DividendsIncentivesRule)
query := sqlbuilder.BuildQuery(tx.Model(dividendsIncentivesRuleModel), queryOptions)
query.SetWhereByQueryOption("dividends_incentives_rule.dividends_incentives_rule_id = ?", "dividendsIncentivesRuleId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == 0 {
return nil, nil
} else {
return transform.TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel)
}
}
func (repository *DividendsIncentivesRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsIncentivesRule, error) {
tx := repository.transactionContext.PgTx
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRules := make([]*domain.DividendsIncentivesRule, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsIncentivesRuleModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("dividends_incentives_rule_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsIncentivesRules, err
} else {
for _, dividendsIncentivesRuleModel := range dividendsIncentivesRuleModels {
if dividendsIncentivesRule, err := transform.TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel); err != nil {
return 0, dividendsIncentivesRules, err
} else {
dividendsIncentivesRules = append(dividendsIncentivesRules, dividendsIncentivesRule)
}
}
return int64(count), dividendsIncentivesRules, nil
}
}
func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsIncentivesRuleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DividendsIncentivesRuleRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type MoneyIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domain.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) {
sqlBuildFields := []string{
"money_icentives_rule_id",
"cooperation_contract_number",
"money_incentives_amount",
"money_incentives_stage",
"money_incentives_stage_end",
"money_incentives_stage_start",
"money_incentives_time",
"referrer_percentage",
"salesman_percentage",
"org",
"company",
"updated_at",
"deleted_at",
"created_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "moneyIncentivesRule_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if moneyIncentivesRule.Identify() == nil {
moneyIncentivesRuleId, err := repository.nextIdentify()
if err != nil {
return moneyIncentivesRule, err
} else {
moneyIncentivesRule.MoneyIncentivesRuleId = moneyIncentivesRuleId
}
if _, err := tx.QueryOne(
pg.Scan(
&moneyIncentivesRule.MoneyIcentivesRuleId,
&moneyIncentivesRule.CooperationContractNumber,
&moneyIncentivesRule.MoneyIncentivesAmount,
&moneyIncentivesRule.MoneyIncentivesStage,
&moneyIncentivesRule.MoneyIncentivesStageEnd,
&moneyIncentivesRule.MoneyIncentivesStageStart,
&moneyIncentivesRule.MoneyIncentivesTime,
&moneyIncentivesRule.ReferrerPercentage,
&moneyIncentivesRule.SalesmanPercentage,
&moneyIncentivesRule.Org,
&moneyIncentivesRule.Company,
&moneyIncentivesRule.UpdatedAt,
&moneyIncentivesRule.DeletedAt,
&moneyIncentivesRule.CreatedAt,
),
fmt.Sprintf("INSERT INTO money_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
moneyIncentivesRule.MoneyIcentivesRuleId,
moneyIncentivesRule.CooperationContractNumber,
moneyIncentivesRule.MoneyIncentivesAmount,
moneyIncentivesRule.MoneyIncentivesStage,
moneyIncentivesRule.MoneyIncentivesStageEnd,
moneyIncentivesRule.MoneyIncentivesStageStart,
moneyIncentivesRule.MoneyIncentivesTime,
moneyIncentivesRule.ReferrerPercentage,
moneyIncentivesRule.SalesmanPercentage,
moneyIncentivesRule.Org,
moneyIncentivesRule.Company,
moneyIncentivesRule.UpdatedAt,
moneyIncentivesRule.DeletedAt,
moneyIncentivesRule.CreatedAt,
); err != nil {
return moneyIncentivesRule, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&moneyIncentivesRule.MoneyIcentivesRuleId,
&moneyIncentivesRule.CooperationContractNumber,
&moneyIncentivesRule.MoneyIncentivesAmount,
&moneyIncentivesRule.MoneyIncentivesStage,
&moneyIncentivesRule.MoneyIncentivesStageEnd,
&moneyIncentivesRule.MoneyIncentivesStageStart,
&moneyIncentivesRule.MoneyIncentivesTime,
&moneyIncentivesRule.ReferrerPercentage,
&moneyIncentivesRule.SalesmanPercentage,
&moneyIncentivesRule.Org,
&moneyIncentivesRule.Company,
&moneyIncentivesRule.UpdatedAt,
&moneyIncentivesRule.DeletedAt,
&moneyIncentivesRule.CreatedAt,
),
fmt.Sprintf("UPDATE money_incentives_rules SET %s WHERE money_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
moneyIncentivesRule.MoneyIcentivesRuleId,
moneyIncentivesRule.CooperationContractNumber,
moneyIncentivesRule.MoneyIncentivesAmount,
moneyIncentivesRule.MoneyIncentivesStage,
moneyIncentivesRule.MoneyIncentivesStageEnd,
moneyIncentivesRule.MoneyIncentivesStageStart,
moneyIncentivesRule.MoneyIncentivesTime,
moneyIncentivesRule.ReferrerPercentage,
moneyIncentivesRule.SalesmanPercentage,
moneyIncentivesRule.Org,
moneyIncentivesRule.Company,
moneyIncentivesRule.UpdatedAt,
moneyIncentivesRule.DeletedAt,
moneyIncentivesRule.CreatedAt,
moneyIncentivesRule.Identify(),
); err != nil {
return moneyIncentivesRule, err
}
}
return moneyIncentivesRule, nil
}
func (repository *MoneyIncentivesRuleRepository) Remove(moneyIncentivesRule *domain.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) {
tx := repository.transactionContext.PgTx
moneyIncentivesRuleModel := new(models.MoneyIncentivesRule)
moneyIncentivesRuleModel.MoneyIncentivesRuleId = moneyIncentivesRule.Identify().(int64)
if _, err := tx.Model(moneyIncentivesRuleModel).WherePK().Delete(); err != nil {
return moneyIncentivesRule, err
}
return moneyIncentivesRule, nil
}
func (repository *MoneyIncentivesRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.MoneyIncentivesRule, error) {
tx := repository.transactionContext.PgTx
moneyIncentivesRuleModel := new(models.MoneyIncentivesRule)
query := sqlbuilder.BuildQuery(tx.Model(moneyIncentivesRuleModel), queryOptions)
query.SetWhereByQueryOption("money_incentives_rule.money_incentives_rule_id = ?", "moneyIncentivesRuleId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if moneyIncentivesRuleModel.MoneyIncentivesRuleId == 0 {
return nil, nil
} else {
return transform.TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel)
}
}
func (repository *MoneyIncentivesRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.MoneyIncentivesRule, error) {
tx := repository.transactionContext.PgTx
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRules := make([]*domain.MoneyIncentivesRule, 0)
query := sqlbuilder.BuildQuery(tx.Model(&moneyIncentivesRuleModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("money_incentives_rule_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, moneyIncentivesRules, err
} else {
for _, moneyIncentivesRuleModel := range moneyIncentivesRuleModels {
if moneyIncentivesRule, err := transform.TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel); err != nil {
return 0, moneyIncentivesRules, err
} else {
moneyIncentivesRules = append(moneyIncentivesRules, moneyIncentivesRule)
}
}
return int64(count), moneyIncentivesRules, nil
}
}
func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.TransactionContext) (*MoneyIncentivesRuleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &MoneyIncentivesRuleRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...