审查视图

pkg/domain/staff_assess_content.go 3.6 KB
1 2
package domain
tangxvhui authored
3 4 5 6 7 8
import (
	"errors"
	"fmt"
	"strconv"
	"time"
)
9 10 11

//填写的评估内容
type StaffAssessContent struct {
Your Name authored
12 13 14 15 16 17 18 19 20
	Id            int                   `json:"id"`            //id
	StaffAssessId int                   `json:"staffAssessId"` //用户需要的评估项id
	SortBy        int                   `json:"sortBy"`        //排序
	Category      string                `json:"category"`      //类别
	Name          string                `json:"name"`          //名称
	PromptTitle   string                `json:"promptTitle"`   //提示项标题
	PromptText    string                `json:"promptText"`    //提示项正文
	Remark        []AssessContemtRemark `json:"remark"`        //填写的反馈
	Value         string                `json:"value"`         //评估填写的值
tangxvhui authored
21 22
	ScoreValue    float64               `json:"scoreValue"`    // 填写值按规则Rule转换为相应的量化值
	LevelValue    string                `json:"levelValue"`    // 填写值按规则Rule转换为相应的等级值
Your Name authored
23 24
	ReteResult    string                `json:"reteResult"`    //评估的结果
	Rule          EvaluationRule        `json:"rule"`          //评估的选项规则
Your Name authored
25
	Weight        int                   `json:"weight" `       //"权重"
Your Name authored
26 27 28
	CreatedAt     time.Time             `json:"createdAt"`     //数据创建时间
	UpdatedAt     time.Time             `json:"updatedAt"`     //数据更新时间
	DeletedAt     *time.Time            `json:"deletedAt"`
29 30
}
Your Name authored
31
type AssessContemtRemark struct {
Your Name authored
32 33
	Title      string `json:"title"`      //comment:"填写标题"
	HintText   string `json:"hintText"`   // comment:"文本内容提示"
34
	Definition string `json:"definition"` //comment:"定义"
Your Name authored
35
	RemarkText string `json:"remarkText"` // comment:"填写文本内容"
Your Name authored
36 37
}
tangxvhui authored
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
//TransformValue
//根据规则 rule 转换评填写的值
func (content *StaffAssessContent) TransformValue() error {
	switch content.Rule.Type {
	case EvaluationTypeRating:
		return content.ratingValue()
	case EvaluationTypeScore:
		return content.scoreValue()
	}
	return nil
}

// 规则是评级方式
func (content *StaffAssessContent) ratingValue() error {
	levels := content.Rule.Rating.Levels
	for _, v := range levels {
		if v.Code != content.Value {
			continue
		}
		content.LevelValue = v.Code
		content.ScoreValue = v.QuantizedValue
		content.ReteResult = v.Name
		return nil
	}
	return errors.New("评级填写的值错误")
}

// 规则是评分方式
func (content *StaffAssessContent) scoreValue() error {
	valueFloat, err := strconv.ParseFloat(content.Value, 64)
	if err != nil {
		return errors.New("评分填写的值错误")
	}
	rule := &content.Rule
	if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
		return fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
	}
	//保留小数处理
	fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
	valueStr := fmt.Sprintf(fStr, valueFloat)
	content.Value = valueStr
	if rule.Score.IntervalState == 0 {
		// 未开启按分数子区间匹配等级
		return nil
	}
	for _, v := range rule.Score.Levels {
		if valueFloat < v.Start || valueFloat > v.End {
			continue
		}
		content.LevelValue = v.Code
		content.ScoreValue = valueFloat
		content.ReteResult = v.Name
		return nil
	}
	return errors.New("评分填写的值错误")
}
95 96 97 98 99 100
type StaffAssessContentRepository interface {
	Save(param *StaffAssessContent) (*StaffAssessContent, error)
	Remove(id int) error
	FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error)
	Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error)
}