reward_summary.go 4.3 KB
package domain

import (
	"time"
)

// RewardSummary 功过奖惩明细
type RewardSummary struct {
	Id                 int         `json:"id"`
	CompanyId          int         `json:"companyId"`
	OrgId              int         `json:"orgId"`
	RecordDate         time.Time   `json:"recordDate"`         //日期
	RecordDateStr      string      `json:"recordDateStr"`      //
	WorkStation        WorkStation `json:"workStation"`        //工作位置
	Worker             User        `json:"user"`               //员工
	UpToStandard       float64     `json:"upToStandard"`       //合格率
	UpToStandardResult int         `json:"upToStandardResult"` //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
	Yield              float64     `json:"yield"`              //产能
	YieldResult        int         `json:"yieldResult"`        //产能 功过评定结果  1`功` -1 `过` 0 `不奖不惩`
	AccidentNum1       int         `json:"accidentNum1"`       //质量事故 次数
	AccidentAmount1    float64     `json:"accidentAmount1"`    //质量事故 损失金额
	AccidentResult1    int         `json:"accidentResult1"`    //质量事故 功过评定结果  1`功` -1 `过` 0 `不奖不惩`
	AccidentNum2       int         `json:"accidentNum2"`       //安全事故 次数
	AccidentAmount2    float64     `json:"accidentAmount2"`    //安全事故 损失金额
	AccidentResult2    int         `json:"accidentResult2"`    //安全事故 功过评定结果  1`功` -1 `过` 0 `不奖不惩`
	AccidentNum3       int         `json:"accidentNum3"`       //异物金属事故 次数
	AccidentResult3    int         `json:"accidentResult3"`    //异物金属事故 功过评定结果  1`功` -1 `过` 0 `不奖不惩`
	AccidentNum4       int         `json:"accidentNum4"`       //异物非金属事故 次数
	AccidentResult4    int         `json:"accidentResult4"`    //异物非金属事故 功过评定结果  1`功` -1 `过` 0 `不奖不惩`
	SummaryResult      float64     `json:"summaryResult"`      //奖惩金额计算结果(元)
	CreatedAt          time.Time   `json:"createdAt"`          //
	UpdatedAt          time.Time   `json:"UpdatedAt"`          //
}

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

// SummaryAccident 汇总事故数据
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)

}