cooperation_contract.go 6.0 KB
package domain

import (
	"time"
)

const (
	TYPE_DIVIDNEDS_INCENTIVES = iota + 1
	TYPE_MONEY_INCENTIVES
)

type IncentivesType int32

const (
	DividendsIncentives IncentivesType = 1
	MoneyIncentives     IncentivesType = 2
)

func (p IncentivesType) String() string {
	switch p {
	case DividendsIncentives:
		return "业绩分红"
	case MoneyIncentives:
		return "金额激励"
	default:
		return "未知类型"
	}
}

func (cooperationContract *CooperationContract) ReturnIncentivesName(p IncentivesType) string {
	return p.String()
}

// CooperationContract 共创项目合约实体
type CooperationContract struct {
	// 共创合约ID
	CooperationContractId int64 `json:"cooperationContractId,string"`
	// 共创合约描述
	CooperationContractDescription string `json:"cooperationContractDescription"`
	// 共创合约名称
	CooperationContractName string `json:"cooperationContractName"`
	// 共创合约编号
	CooperationContractNumber string `json:"cooperationContractNumber"`
	// 共创项目编号
	CooperationProjectNumber string `json:"cooperationProjectNumber"`
	// 共创合约承接对象,1员工,2共创用户,3公开
	CooperationContractUndertakerTypes []int32 `json:"cooperationContractUndertakerTypes"`
	// 共创合约发起人
	CooperationContractSponsor *User `json:"cooperationContractSponsor"`
	// 共创模式或者合伙模式
	CooperationMode *CooperationMode `json:"cooperationMode"`
	// 合约状态,1恢复,2暂停
	Status int32 `json:"status"`
	// 数据所属组织机构
	Org *Org `json:"org"`
	// 公司
	Company *Company `json:"company"`
	// 共创合约发起部门
	Department *Department `json:"department"`
	// 操作人
	Operator *User `json:"operator"`
	// 分红激励规则
	DividendsIncentivesRules []*DividendsIncentivesRule `json:"dividendsIncentivesRules"`
	// 金额激励规则
	MoneyIncentivesRules []*MoneyIncentivesRule `json:"moneyIncentivesRules"`
	// 激励方式,1业绩分红激励,2金额激励
	IncentivesType int32 `json:"incentivesType"`
	// 共创承接人列表
	Undertakers []*Undertaker `json:"undertakers"`
	// 共创合约相关人列表
	RelevantPeople []*Relevant `json:"relevantPeople"`
	// 操作时间
	OperateTime time.Time `json:"operateTime"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 共创项目编号
	CooperationProjectId int64 `json:"cooperationProjectId"`
}

type CooperationContractRepository interface {
	Save(cooperationContract *CooperationContract) (*CooperationContract, error)
	UpdateOne(cooperationContract *CooperationContract) (*CooperationContract, error)
	UpdateMany(cooperationContracts []*CooperationContract) ([]*CooperationContract, error)
	Remove(cooperationContract *CooperationContract) (*CooperationContract, error)
	BatchRemove(cooperationContracts []*CooperationContract) ([]*CooperationContract, error)
	FindOne(queryOptions map[string]interface{}) (*CooperationContract, error)
	Find(queryOptions map[string]interface{}) (int64, []*CooperationContract, error)
}

func (cooperationContract *CooperationContract) Identify() interface{} {
	if cooperationContract.CooperationContractId == 0 {
		return nil
	}
	return cooperationContract.CooperationContractId
}

func (cooperationContract *CooperationContract) Update(data map[string]interface{}) error {
	if cooperationContractDescription, ok := data["cooperationContractDescription"]; ok {
		cooperationContract.CooperationContractDescription = cooperationContractDescription.(string)
	}
	if cooperationContractName, ok := data["cooperationContractName"]; ok {
		cooperationContract.CooperationContractName = cooperationContractName.(string)
	}
	if cooperationProjectNumber, ok := data["cooperationProjectNumber"]; ok {
		cooperationContract.CooperationProjectNumber = cooperationProjectNumber.(string)
	}
	if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
		cooperationContract.CooperationContractNumber = cooperationContractNumber.(string)
	}
	if cooperationContractUndertakerTypes, ok := data["cooperationContractUndertakerTypes"]; ok {
		cooperationContract.CooperationContractUndertakerTypes = cooperationContractUndertakerTypes.([]int32)
	}
	if status, ok := data["status"]; ok {
		cooperationContract.Status = status.(int32)
	}
	if action, ok := data["action"]; ok {
		cooperationContract.Status = action.(int32)
	}
	if operateTime, ok := data["operateTime"]; ok {
		cooperationContract.OperateTime = operateTime.(time.Time)
	}
	cooperationContract.UpdatedAt = time.Now()
	return nil
}

// UndertakerSliceEqualBCE 判断承接人Slice是否一样
func (cooperationContract *CooperationContract) UndertakerSliceEqualBCE(a, b []*Undertaker) bool {
	if len(a) != len(b) {
		return false
	}
	if (a == nil) != (b == nil) {
		return false
	}
	b = b[:len(a)]
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

// DividendsIncentivesRuleSliceEqualBCE 判断业绩分红激励规则Slice是否一样
func (cooperationContract *CooperationContract) DividendsIncentivesRuleSliceEqualBCE(a, b []*DividendsIncentivesRule) bool {
	if len(a) != len(b) {
		return false
	}
	if (a == nil) != (b == nil) {
		return false
	}
	b = b[:len(a)]
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

// MoneyIncentivesRuleSliceEqualBCE 判断金额激励规则Slice是否一样
func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE(a, b []*MoneyIncentivesRule) bool {
	if len(a) != len(b) {
		return false
	}
	if (a == nil) != (b == nil) {
		return false
	}
	b = b[:len(a)]
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

func CooperationContractsToProjectIds(contracts []*CooperationContract) []int64 {
	var projectIds = make([]int64, 0)
	for i := range contracts {
		var exist = false
		for j := range projectIds {
			if contracts[i].CooperationProjectId == projectIds[j] {
				exist = true
				break
			}
		}
		if !exist {
			projectIds = append(projectIds, contracts[i].CooperationProjectId)
		}
	}
	return projectIds
}