reward_rule.go 1.4 KB
package domain

import (
	"strconv"
	"time"
)

// RewardStandard 奖惩规则
type RewardRule struct {
	Id           int    `json:"id"`        //奖惩规则id
	CompanyId    int    `json:"companyId"` //企业id
	OrgId        int    `json:"orgId"`     //组织ID
	RewardTag    string `json:"rewardTag"`
	RewardNum    int    `json:"rewardNum"`
	RewardAmount string `json:"rewardAmount"`
	FaultTag     string `json:"faultTag"`
	FaultNum     int    `json:"faultNum"`
	FaultAmount  string `json:"faultAmount"`
	Remark       string `json:"remark"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type RewardRuleRepository interface {
	Save(param *RewardRule) (*RewardRule, error)
	FindOne(queryOptions map[string]interface{}) (*RewardRule, error)
	Find(queryOptions map[string]interface{}) (int64, []*RewardRule, error)
}

func (m *RewardRule) ValidRewardTag() bool {
	switch m.RewardTag {
	case ">":
	default:
		return false
	}
	return true
}

func (m *RewardRule) ValidFaultTag() bool {
	switch m.FaultTag {
	case ">":
	default:
		return false
	}
	return true
}

// 计算奖惩 的金额
func (m *RewardRule) SumRewardAmount(rewardNum int, faultNum int) float64 {
	result := float64(0)
	rewardAmount, _ := strconv.ParseFloat(m.RewardAmount, 64)
	faultAmount, _ := strconv.ParseFloat(m.FaultAmount, 64)
	if rewardNum > m.RewardNum {
		result += rewardAmount
	}
	if faultNum > m.FaultNum {
		result -= faultAmount
	}
	return result
}