performance_application_form.go
5.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package domain
import (
"errors"
"strings"
)
type PerformanceApplicationForm struct {
DimensionName string //维度名称
ModuleName string //模块名称
Weight string //权重
Standard string //标准
Task string //任务、指标
Definition string //定义
}
type PerformanceDimension struct {
Name string `json:"name"` //维度名称
PerformanceModule []*PerformanceModule `json:"performanceModule"` //模块
}
type PerformanceModule struct {
ModuleName string `json:"moduleName"` //模块名称
Weight string `json:"weight"` //权重
Standard string `json:"standard"` //标准(结构化的成果描述)
Target []*PerformanceTarget `json:"performanceTarget"` //任务\指标
}
type PerformanceTarget struct {
Task string `json:"task"`
Definition string `json:"definition"`
}
func LoadPerformanceDimensions(rows [][]string) ([]*PerformanceDimension, error) {
formRows := make([]*PerformanceApplicationForm, 0)
var dimensionName, moduleName, taskName, weightName, standardName string
for key, item := range rows {
if key < 3 {
continue
}
if len(item) >= 1 {
if item[0] == "部门长审核" || strings.Contains(item[0], "审核") {
break
}
}
form := &PerformanceApplicationForm{}
//维度名称
if len(item) > 1 && item[1] != "" {
dimensionName = item[1]
}
form.DimensionName = dimensionName
//模块名称
if len(item) > 3 && item[3] != "" {
moduleName = item[3]
}
form.ModuleName = moduleName
//指标任务
if len(item) > 4 && item[4] != "" {
taskName = item[4]
} else {
taskName = "填写自评反馈"
}
form.Task = taskName
//定义
if len(item) > 5 {
form.Definition = strings.TrimSpace(item[5])
}
//权重
if len(item) > 6 && item[6] != "" {
weightName = item[6]
form.Weight = weightName
}
//标准
if len(item) > 7 && item[7] != "" {
standardName = item[7]
}
if key < len(rows)-1 {
if len(rows[key+1]) > 1 && rows[key+1][1] != "" {
standardName = ""
}
}
form.Standard = standardName
formRows = append(formRows, form)
}
dimensions := make([]*PerformanceDimension, 0)
//按维度分
mapData := make(map[string][]*PerformanceApplicationForm)
//维度顺序
sortBy := make([]string, 0)
for _, item := range formRows {
if _, ok := mapData[item.DimensionName]; !ok {
mapData[item.DimensionName] = make([]*PerformanceApplicationForm, 0)
sortBy = append(sortBy, item.DimensionName)
}
mapData[item.DimensionName] = append(mapData[item.DimensionName], item)
}
for dimensionName, item := range mapData {
dimension := &PerformanceDimension{
Name: dimensionName,
}
modules, err := loadPerformanceModule(item)
if err != nil {
return dimensions, err
}
dimension.PerformanceModule = modules
dimensions = append(dimensions, dimension)
}
result := make([]*PerformanceDimension, 0)
for _, name := range sortBy {
for _, item := range dimensions {
if name == item.Name {
result = append(result, item)
}
}
}
return result, nil
}
// 筛选出模块
func loadPerformanceModule(forms []*PerformanceApplicationForm) ([]*PerformanceModule, error) {
mapData := make(map[string][]*PerformanceApplicationForm)
sortBy := make([]string, 0)
for _, item := range forms {
if _, ok := mapData[item.ModuleName]; !ok {
mapData[item.ModuleName] = make([]*PerformanceApplicationForm, 0)
sortBy = append(sortBy, item.ModuleName)
}
mapData[item.ModuleName] = append(mapData[item.ModuleName], item)
}
modules := make([]*PerformanceModule, 0)
for moduleName, item := range mapData {
if moduleName == "" {
return modules, errors.New(item[0].DimensionName + "对应的模块不能为空")
}
weightName, err := getWeight(item)
if err != nil {
return modules, err
}
standardName, err := getStandard(item)
if err != nil {
return modules, err
}
tasks, err := getTasks(item)
if err != nil {
return modules, err
}
module := &PerformanceModule{
ModuleName: moduleName,
Weight: weightName,
Standard: standardName,
Target: tasks,
}
modules = append(modules, module)
}
result := make([]*PerformanceModule, 0)
for _, name := range sortBy {
for _, item := range modules {
if name == item.ModuleName {
result = append(result, item)
}
}
}
return result, nil
}
// 获取权重
func getWeight(items []*PerformanceApplicationForm) (string, error) {
if len(items) <= 0 {
return "", nil
}
var name string
for _, item := range items {
if name == "" {
name = item.Weight
}
if name != item.Weight {
return "", errors.New(item.ModuleName + " 对应的权重值不一致")
}
}
if name == "/" {
name = "0%"
}
return name, nil
}
// 获取标准
func getStandard(items []*PerformanceApplicationForm) (string, error) {
if len(items) <= 0 {
return "", nil
}
var name string
for _, item := range items {
if name == "" {
name = item.Standard
}
if name != item.Standard {
return "", errors.New(item.ModuleName + " 对应的标准值不一致")
}
}
return name, nil
}
// 获取任务
func getTasks(items []*PerformanceApplicationForm) ([]*PerformanceTarget, error) {
tasks := make([]*PerformanceTarget, 0)
for _, item := range items {
target := &PerformanceTarget{Task: item.Task, Definition: item.Definition}
tasks = append(tasks, target)
}
return tasks, nil
}