作者 Your Name

更新

package domain
import "time"
import (
"strconv"
"time"
)
// RewardStandard 奖惩规则
type RewardRule struct {
... ... @@ -25,7 +28,7 @@ type RewardRuleRepository interface {
}
func (m *RewardRule) ValidRewardTag() bool {
switch m.FaultTag {
switch m.RewardTag {
case ">":
default:
return false
... ... @@ -41,3 +44,17 @@ func (m *RewardRule) ValidFaultTag() bool {
}
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
}
... ...
... ... @@ -145,19 +145,109 @@ func (m *RewardStandard) ShowTargeFault() string {
show := ""
switch m.TargetType {
case TargetType1:
show = fmt.Sprintf("<%skg/小时", m.TargeVal1)
show = fmt.Sprintf("<%skg/小时", m.TargeVal2)
case TargetType2:
show = fmt.Sprintf("<%s%%", m.TargeVal1)
show = fmt.Sprintf("<%s%%", m.TargeVal2)
case TargetType3:
show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal1, m.TargeVal2)
show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal3, m.TargeVal4)
case TargetType4:
show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal1, m.TargeVal2)
show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal3, m.TargeVal4)
case TargetType5:
show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal1, m.TargeVal2)
show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal3, m.TargeVal4)
}
return show
}
func (m *RewardStandard) VerdictTarget(val1 int, val float64) int {
// 判定功过, 指标类别 1:产效
func (m *RewardStandard) VerdictTargetType1(val1 int, val float64) int {
return 0
}
// 判定功过, 指标类别 2:合格率
func (m *RewardStandard) VerdictTargetType2(val1 int, val float64) int {
return 0
}
// 判定功过, 指标类别 3:安全事故;
// param1 安全事故次数;
// param1 损失金额;
// 功过结果 0 无,1 功 ,-1 过;
func (m *RewardStandard) VerdictTargetType3(param1 int, param2 float64) int {
val1, _ := strconv.Atoi(m.TargeVal1)
val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
result := 0
//判定功
if param1 <= val1 {
result = 1
}
if param2 <= val2 {
result = 1
}
//判定过
val3, _ := strconv.Atoi(m.TargeVal3)
val4, _ := strconv.ParseFloat(m.TargeVal4, 64)
if param1 > val3 {
result = -1
}
if param2 > val4 {
result = -1
}
return result
}
// 判定功过, 指标类别 4:质量事故;
// param1 质量事故 次数;
// param1 损失金额;
// 功过结果 0 无,1 功 ,-1 过;
func (m *RewardStandard) VerdictTargetType4(param1 int, param2 float64) int {
val1, _ := strconv.Atoi(m.TargeVal1)
val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
result := 0
//判定功
if param1 <= val1 {
result = 1
}
if param2 <= val2 {
result = 1
}
//判定过
val3, _ := strconv.Atoi(m.TargeVal3)
val4, _ := strconv.ParseFloat(m.TargeVal4, 64)
if param1 > val3 {
result = -1
}
if param2 > val4 {
result = -1
}
return result
}
// 判定功过, 指标类别 5:异物次数;
// param1 金属异物 次数;
// param2 非金属 次数;
// 功过结果 0 无,1 功 ,-1 过;
func (m *RewardStandard) VerdictTargetType5(param1 int, param2 int) int {
val1, _ := strconv.Atoi(m.TargeVal1)
val2, _ := strconv.Atoi(m.TargeVal2)
result := 0
//判定功
if param1 <= val1 {
result = 1
}
if param2 <= val2 {
result = 1
}
//判定过
val3, _ := strconv.Atoi(m.TargeVal3)
val4, _ := strconv.Atoi(m.TargeVal4)
if param1 > val3 {
result = -1
}
if param2 > val4 {
result = -1
}
return result
}
... ...
... ... @@ -14,19 +14,19 @@ type RewardSummary struct {
WorkStation WorkStation `json:"workStation"` //工作位置
Worker User `json:"user"` //员工
UpToStandard float64 `json:"upToStandard"` //合格率
UpToStandardResult float64 `json:"upToStandardResult"` //合格率 功过评定结果 `功` `过` `不奖不惩`
UpToStandardResult int `json:"upToStandardResult"` //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
Yield float64 `json:"yield"` //产能
YieldResult float64 `json:"yieldResult"` //产能 功过评定结果
YieldResult int `json:"yieldResult"` //产能 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum1 int `json:"accidentNum1"` //质量事故 次数
AccidentAmount1 float64 `json:"accidentAmount1"` //质量事故 损失金额
AccidentResult1 string `json:"accidentResult1"` //质量事故 功过评定结果
AccidentResult1 int `json:"accidentResult1"` //质量事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum2 int `json:"accidentNum2"` //安全事故 次数
AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额
AccidentResult2 string `json:"accidentResult2"` //安全事故 功过评定结果
AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数
AccidentResult3 string `json:"accidentResult3"` //异物金属事故 功过评定结果
AccidentResult3 int `json:"accidentResult3"` //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数
AccidentResult4 string `json:"accidentResult4"` //异物非金属事故 功过评定结果
AccidentResult4 int `json:"accidentResult4"` //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元)
CreatedAt time.Time `json:"createdAt"` //
UpdatedAt time.Time `json:"UpdatedAt"` //
... ... @@ -39,17 +39,82 @@ type RewardSummaryRepository interface {
}
// SummaryAccident 汇总事故数据
func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble) {
func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard *RewardStandard) {
switch trouble.Types {
case TroubleType1:
c.AccidentNum2 = +1
c.AccidentAmount2 = +trouble.AmountLoss
if rewardStandard == nil {
c.AccidentResult2 = 0
} else {
r := rewardStandard.VerdictTargetType3(c.AccidentNum2, c.AccidentAmount2)
c.AccidentResult2 = r
}
case TroubleType2:
c.AccidentNum1 = +1
c.AccidentAmount1 = +trouble.AmountLoss
if rewardStandard == nil {
c.AccidentResult1 = 0
} else {
r := rewardStandard.VerdictTargetType4(c.AccidentNum1, c.AccidentAmount1)
c.AccidentResult2 = r
}
case TroubleType3:
c.AccidentNum3 = +1
if rewardStandard == nil {
c.AccidentResult3 = 0
} else {
r := rewardStandard.VerdictTargetType5(c.AccidentNum3, 0)
c.AccidentResult2 = r
}
case TroubleType4:
c.AccidentNum4 = +1
if rewardStandard == nil {
c.AccidentResult4 = 0
} else {
r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4)
c.AccidentResult2 = r
}
}
}
func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
rewardNum := 0
faultNum := 0
if c.AccidentResult1 < 0 {
faultNum = +1
} else if c.AccidentResult1 > 0 {
rewardNum = +1
}
if c.AccidentResult2 < 0 {
faultNum = +1
} else if c.AccidentResult2 > 0 {
rewardNum = +1
}
if c.AccidentResult3 < 0 {
faultNum = +1
} else if c.AccidentResult3 > 0 {
rewardNum = +1
}
if c.AccidentResult4 < 0 {
faultNum = +1
} else if c.AccidentResult4 > 0 {
rewardNum = +1
}
if c.YieldResult < 0 {
faultNum = +1
} else if c.YieldResult > 0 {
rewardNum = +1
}
if c.UpToStandardResult < 0 {
faultNum = +1
} else if c.UpToStandardResult > 0 {
rewardNum = +1
}
c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum)
}
... ...
... ... @@ -26,7 +26,7 @@ func NewPGRewardSummaryStaticService(transactionContext *pgTransaction.Transacti
}
}
// 根据
// 根据事故数据
func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.transactionContext)
//查询是否已经有汇总数据
... ... @@ -71,17 +71,51 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param
UpdatedAt: nowTime,
}
}
// 将审核过的事故放入汇总数据计算
summaryData.SummaryAccident(param)
//获取奖惩标准 按
var targetType int
switch param.Types {
case domain.TroubleType1:
targetType = domain.TargetType3
case domain.TroubleType2:
targetType = domain.TargetType4
case domain.TroubleType3:
targetType = domain.TargetType5
case domain.TroubleType4:
targetType = domain.TargetType5
}
//获取奖惩标准 按 车间 线别 工段 类型
rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
_, rewardStandardList, err := rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
"workshopId": param.WorkStation.WorkshopId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"targetType": targetType,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(rewardStandardList) > 0 {
summaryData.SummaryAccident(param, rewardStandardList[0])
} else {
summaryData.SummaryAccident(param, nil)
}
rewardStandardRepo.Find(map[string]interface{}{
//获取奖惩规则
rewardRuleRepo, _ := repository.NewRewardRuleRepository(c.transactionContext)
_, rewardRuleList, err := rewardRuleRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
}
if len(rewardRuleList) == 0 {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未设置奖惩规则")
}
summaryData.ApplySummaryResult(rewardRuleList[0])
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
... ...
... ... @@ -115,6 +115,9 @@ func (repo *RewardRuleRepository) Find(queryOptions map[string]interface{}) (int
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["orgId"]; ok {
query.Where("org_id=?", v)
}
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...