cooperation_contract.go 6.1 KB
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 TransformToCooperationContractDomainModelFromPgModels(
	cooperationContractModel *models.CooperationContract,
	cooperationMode *models.CooperationMode,
	dividendsIncentivesRules []*models.DividendsIncentivesRule,
	moneyIncentivesRules []*models.MoneyIncentivesRule,
	relevantPeople []*models.CooperationContractRelevant,
	undertakers []*models.CooperationContractUndertaker) (*domain.CooperationContract, error) {
	// 分红激励规则
	var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule
	for _, rule := range dividendsIncentivesRules {
		dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{
			DividendsIncentivesRuleId:     rule.DividendsIncentivesRuleId,
			CooperationContractNumber:     rule.CooperationContractNumber,
			ReferrerPercentage:            rule.ReferrerPercentage,
			SalesmanPercentage:            rule.SalesmanPercentage,
			DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
			DividendsIncentivesStage:      rule.DividendsIncentivesStage,
			DividendsIncentivesStageEnd:   rule.DividendsIncentivesStageEnd,
			DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
			Org:                           rule.Org,
			Company:                       rule.Company,
			UpdatedAt:                     rule.UpdatedAt,
			DeletedAt:                     rule.DeletedAt,
			CreatedAt:                     rule.CreatedAt,
		})
	}
	// 金额激励规则
	var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule
	for _, rule := range moneyIncentivesRules {
		moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{
			MoneyIncentivesRuleId:     rule.MoneyIncentivesRuleId,
			CooperationContractNumber: rule.CooperationContractNumber,
			MoneyIncentivesAmount:     rule.MoneyIncentivesAmount,
			MoneyIncentivesStage:      rule.MoneyIncentivesStage,
			MoneyIncentivesStageEnd:   rule.MoneyIncentivesStageEnd,
			MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
			MoneyIncentivesTime:       rule.MoneyIncentivesTime,
			ReferrerPercentage:        rule.ReferrerPercentage,
			SalesmanPercentage:        rule.SalesmanPercentage,
			Org:                       rule.Org,
			Company:                   rule.Company,
			UpdatedAt:                 rule.UpdatedAt,
			DeletedAt:                 rule.DeletedAt,
			CreatedAt:                 rule.CreatedAt,
		})
	}
	// 相关人列表
	var relevantPeopleDomain []*domain.Relevant
	for _, relevant := range relevantPeople {
		relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{
			UserId:     relevant.Relevant.UserId,
			UserBaseId: relevant.Relevant.UserBaseId,
			Org:        relevant.Relevant.Org,
			Orgs:       relevant.Relevant.Orgs,
			Department: relevant.Relevant.Department,
			Role:       relevant.Relevant.Role,
			UserInfo:   relevant.Relevant.UserInfo,
			UserType:   relevant.Relevant.UserType,
			Status:     relevant.Relevant.Status,
			Company:    relevant.Relevant.Company,
		})
	}
	// 承接人列表
	var undertakersDomain []*domain.Undertaker
	for _, undertaker := range undertakers {
		undertakersDomain = append(undertakersDomain, &domain.Undertaker{
			UserId:             undertaker.Undertaker.UserId,
			UserBaseId:         undertaker.Undertaker.UserBaseId,
			Org:                undertaker.Undertaker.Org,
			Orgs:               undertaker.Undertaker.Orgs,
			Department:         undertaker.Undertaker.Department,
			Role:               undertaker.Undertaker.Role,
			UserInfo:           undertaker.Undertaker.UserInfo,
			UserType:           undertaker.Undertaker.UserType,
			Status:             undertaker.Undertaker.Status,
			Company:            undertaker.Undertaker.Company,
			ContractAttachment: undertaker.Undertaker.ContractAttachment,
		})
	}
	return &domain.CooperationContract{
		CooperationContractId:             cooperationContractModel.CooperationContractId,
		CooperationContractDescription:    cooperationContractModel.CooperationContractDescription,
		CooperationContractName:           cooperationContractModel.CooperationContractName,
		CooperationContractNumber:         cooperationContractModel.CooperationContractNumber,
		CooperationContractReferrer:       cooperationContractModel.CooperationContractReferrer,
		CooperationContractSalesman:       cooperationContractModel.CooperationContractSalesman,
		CooperationContractUndertakerType: cooperationContractModel.CooperationContractUndertakerType,
		CooperationContractSponsor:        cooperationContractModel.CooperationContractSponsor,
		CooperationMode: &domain.CooperationMode{
			CooperationModeId:     cooperationMode.CooperationModeId,
			CooperationModeNumber: cooperationMode.CooperationModeNumber,
			CooperationModeName:   cooperationMode.CooperationModeName,
			Status:                cooperationMode.Status,
			Org:                   cooperationMode.Org,
			Company:               cooperationMode.Company,
			Remarks:               cooperationMode.Remarks,
			Operator:              cooperationMode.Operator,
			OperateTime:           cooperationMode.OperateTime,
			UpdatedAt:             cooperationMode.UpdatedAt,
			DeletedAt:             cooperationMode.DeletedAt,
			CreatedAt:             cooperationMode.CreatedAt,
		},
		DividendsIncentivesRules: dividendsIncentivesRulesDomain,
		MoneyIncentivesRules:     moneyIncentivesRulesDomain,
		RelevantPeople:           relevantPeopleDomain,
		Undertakers:              undertakersDomain,
		Status:                   cooperationContractModel.Status,
		Org:                      cooperationContractModel.Org,
		Company:                  cooperationContractModel.Company,
		Operator:                 cooperationContractModel.Operator,
		OperateTime:              cooperationContractModel.OperateTime,
		CreatedAt:                cooperationContractModel.CreatedAt,
		DeletedAt:                cooperationContractModel.DeletedAt,
		UpdatedAt:                cooperationContractModel.UpdatedAt,
	}, nil
}