审查视图

pkg/domain/evaluation_rule.go 3.9 KB
郑周 authored
1 2 3 4 5 6 7 8 9 10 11
package domain

import (
	"time"
)

const (
	EvaluationTypeRating int = 0 // 评估方式-评级
	EvaluationTypeScore  int = 1 // 评估方式-评分
)
郑周 authored
12 13 14 15 16
const (
	EvaluationSysTypeCommon int = 0 // 系统类型-系统添加
	EvaluationSysTypeSystem int = 1 // 系统类型-系统预制(不可删除、编辑)
)
郑周 authored
17
type Rating struct {
郑周 authored
18
	Levels []*RatingLevel `json:"levels" comment:"配置等级"`
郑周 authored
19 20 21 22 23 24 25 26 27 28
}

type RatingLevel struct {
	Code           string  `json:"code" comment:"等级代号"`
	Name           string  `json:"name" comment:"等级名称"`
	Color          int     `json:"color" comment:"等级颜色"`
	QuantizedValue float64 `json:"quantizedValue" comment:"等级量化值"`
}

type Score struct {
郑周 authored
29 30 31 32 33
	Min           float64       `json:"min" comment:"评分下限"`
	Max           float64       `json:"max" comment:"评分上限"`
	IntervalState int           `json:"intervalState" comment:"按分数子区间匹配等级(0关闭、1开启)"`
	DecimalPlaces int           `json:"decimalPlaces" comment:"保留小数点(0不保留、1保留一位、以此类推)"`
	Levels        []*ScoreLevel `json:"levels" comment:"配置等级区间"`
郑周 authored
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
}

type ScoreLevel struct {
	Code  string  `json:"code" comment:"等级代号"`
	Name  string  `json:"name" comment:"等级名称"`
	Start float64 `json:"start" comment:"分数区间开始值"`
	End   float64 `json:"end" comment:"分数区间结束值"`
}

type EvaluationRule struct {
	Id        int64      `json:"id,string" comment:"ID"`
	Name      string     `json:"name" comment:"名称"`
	Remark    string     `json:"remark" comment:"备注"`
	CompanyId int64      `json:"companyId,string" comment:"公司ID"`
	CreatorId int64      `json:"creatorId,string" comment:"创建人ID"`
	Type      int        `json:"type" comment:"评估方式(0评级、1评分)"`
郑周 authored
50
	SysType   int        `json:"sysType" comment:"系统类型(0普通、1系统固定)" pg:",use_zero"`
郑周 authored
51 52
	Rating    Rating     `json:"rating" comment:"评级"`
	Score     Score      `json:"score" comment:"评分"`
郑周 authored
53 54 55 56
	CreatedAt time.Time  `json:"createdAt" comment:"创建时间"`
	UpdatedAt time.Time  `json:"updatedAt" comment:"更新时间"`
	DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
57
郑周 authored
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 95
// GenerateSysRule 当前公司下的生成默认规则
func GenerateSysRule(companyId int64) *EvaluationRule {
	levels := make([]*RatingLevel, 0)
	levels = append(levels, &RatingLevel{
		Code:           "S",
		Name:           "SS",
		Color:          1,
		QuantizedValue: 90,
	})
	levels = append(levels, &RatingLevel{
		Code:           "A",
		Name:           "AA",
		Color:          2,
		QuantizedValue: 80,
	})
	levels = append(levels, &RatingLevel{
		Code:           "B",
		Name:           "BB",
		Color:          3,
		QuantizedValue: 70,
	})

	levels = append(levels, &RatingLevel{
		Code:           "C",
		Name:           "CC",
		Color:          4,
		QuantizedValue: 60,
	})

	levels = append(levels, &RatingLevel{
		Code:           "D",
		Name:           "DD",
		Color:          5,
		QuantizedValue: 50,
	})

	newRule := &EvaluationRule{
		Id:        0,
郑周 authored
96
		Name:      "评级",
郑周 authored
97 98 99 100 101 102 103 104 105 106 107 108 109
		Remark:    "",
		CompanyId: companyId,
		CreatorId: 0,
		Type:      EvaluationTypeRating,
		SysType:   EvaluationSysTypeSystem,
		Rating: Rating{
			Levels: levels,
		},
		Score: Score{},
	}
	return newRule
}
110 111 112 113 114 115 116
type EvaluationRuleRepository interface {
	Insert(rule *EvaluationRule) (*EvaluationRule, error)
	Remove(rule *EvaluationRule) (*EvaluationRule, error)
	FindOne(queryOptions map[string]interface{}) (*EvaluationRule, error)
	Find(queryOptions map[string]interface{}) (int64, []*EvaluationRule, error)
	Count(queryOptions map[string]interface{}) (int64, error)
}
tangxvhui authored
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

func (rule *EvaluationRule) GetLevelCodes() []string {
	codes := []string{}
	if rule.Type == EvaluationTypeRating {
		for _, v := range rule.Rating.Levels {
			codes = append(codes, v.Code)
		}
	}
	if rule.Type == EvaluationTypeScore {
		for _, v := range rule.Score.Levels {
			codes = append(codes, v.Code)
		}
	}
	return codes
}