reward_rule.go
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}