1
|
package controllers
|
1
|
package controllers
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
|
4
|
"strconv"
|
6
|
"strconv"
|
5
|
"strings"
|
7
|
"strings"
|
6
|
|
8
|
|
|
@@ -46,19 +48,22 @@ func (controller *ImportController) Import() { |
|
@@ -46,19 +48,22 @@ func (controller *ImportController) Import() { |
46
|
if err != nil {
|
48
|
if err != nil {
|
47
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
|
49
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
|
48
|
}
|
50
|
}
|
49
|
- list := controller.parseTemplateNodeContent(dimensions)
|
|
|
50
|
- controller.Response(tool_funs.SimpleWrapGridMap(int64(len(list)), list), nil)
|
51
|
+ if err, list := controller.parseTemplateNodeContent(dimensions); err != nil {
|
|
|
52
|
+ controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
|
|
|
53
|
+ } else {
|
|
|
54
|
+ controller.Response(tool_funs.SimpleWrapGridMap(int64(len(list)), list), nil)
|
|
|
55
|
+ }
|
51
|
default:
|
56
|
default:
|
52
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, "请确认您导入的表单类型"))
|
57
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, "请确认您导入的表单类型"))
|
53
|
}
|
58
|
}
|
54
|
}
|
59
|
}
|
55
|
|
60
|
|
56
|
-func (controller *ImportController) parseTemplateNodeContent(data []*domain.PerformanceDimension) []*domain.NodeContent {
|
61
|
+func (controller *ImportController) parseTemplateNodeContent(data []*domain.PerformanceDimension) (error, []*domain.NodeContent) {
|
57
|
nodeContents := make([]*domain.NodeContent, 0)
|
62
|
nodeContents := make([]*domain.NodeContent, 0)
|
58
|
|
63
|
|
59
|
transactionContext, err := factory.StartTransaction()
|
64
|
transactionContext, err := factory.StartTransaction()
|
60
|
if err != nil {
|
65
|
if err != nil {
|
61
|
- return nodeContents
|
66
|
+ return err, nodeContents
|
62
|
}
|
67
|
}
|
63
|
defer func() {
|
68
|
defer func() {
|
64
|
transactionContext.RollbackTransaction()
|
69
|
transactionContext.RollbackTransaction()
|
|
@@ -70,18 +75,18 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -70,18 +75,18 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
70
|
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
75
|
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
71
|
_, rules, err := ruleRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
|
76
|
_, rules, err := ruleRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
|
72
|
if err != nil {
|
77
|
if err != nil {
|
73
|
- return nodeContents
|
78
|
+ return err, nodeContents
|
74
|
}
|
79
|
}
|
75
|
var ruleId = int64(0)
|
80
|
var ruleId = int64(0)
|
76
|
if len(rules) == 0 {
|
81
|
if len(rules) == 0 {
|
77
|
newRule := domain.GenerateSysRule(ua.CompanyId) // 生成一个系统默认规则
|
82
|
newRule := domain.GenerateSysRule(ua.CompanyId) // 生成一个系统默认规则
|
78
|
if rule, err := ruleRepository.Insert(newRule); err != nil {
|
83
|
if rule, err := ruleRepository.Insert(newRule); err != nil {
|
79
|
- return nodeContents
|
84
|
+ return err, nodeContents
|
80
|
} else {
|
85
|
} else {
|
81
|
ruleId = rule.Id
|
86
|
ruleId = rule.Id
|
82
|
}
|
87
|
}
|
83
|
if err := transactionContext.CommitTransaction(); err != nil {
|
88
|
if err := transactionContext.CommitTransaction(); err != nil {
|
84
|
- return nodeContents
|
89
|
+ return err, nodeContents
|
85
|
}
|
90
|
}
|
86
|
} else {
|
91
|
} else {
|
87
|
ruleId = rules[0].Id
|
92
|
ruleId = rules[0].Id
|
|
@@ -91,6 +96,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -91,6 +96,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
91
|
evaluatorNames := make([]string, 0)
|
96
|
evaluatorNames := make([]string, 0)
|
92
|
evaluatorMap := map[string]string{}
|
97
|
evaluatorMap := map[string]string{}
|
93
|
|
98
|
|
|
|
99
|
+ weightTotal := 0.0
|
94
|
for i := range data {
|
100
|
for i := range data {
|
95
|
dimension := data[i]
|
101
|
dimension := data[i]
|
96
|
for i2 := range dimension.PerformanceModule {
|
102
|
for i2 := range dimension.PerformanceModule {
|
|
@@ -107,6 +113,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -107,6 +113,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
107
|
} else {
|
113
|
} else {
|
108
|
nc.Weight = 0
|
114
|
nc.Weight = 0
|
109
|
}
|
115
|
}
|
|
|
116
|
+ weightTotal += nc.Weight // 总权重
|
110
|
nc.PromptTitle = "" // 提示项标题
|
117
|
nc.PromptTitle = "" // 提示项标题
|
111
|
nc.PromptText = module.Standard // 提示项内容
|
118
|
nc.PromptText = module.Standard // 提示项内容
|
112
|
nc.EntryItems = make([]*domain.EntryItem, 0) // 输入项
|
119
|
nc.EntryItems = make([]*domain.EntryItem, 0) // 输入项
|
|
@@ -132,7 +139,6 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -132,7 +139,6 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
132
|
if module.Evaluator == "HRBP" {
|
139
|
if module.Evaluator == "HRBP" {
|
133
|
nc.EvaluatorId = -1
|
140
|
nc.EvaluatorId = -1
|
134
|
} else {
|
141
|
} else {
|
135
|
-
|
|
|
136
|
if len(module.Evaluator) > 0 {
|
142
|
if len(module.Evaluator) > 0 {
|
137
|
evaluatorNames = append(evaluatorNames, module.Evaluator) // 项目评估人名称数组
|
143
|
evaluatorNames = append(evaluatorNames, module.Evaluator) // 项目评估人名称数组
|
138
|
evaluatorMap[nc.Category+nc.Name] = module.Evaluator // k,v = (类别+名称, 项目评估人名称)
|
144
|
evaluatorMap[nc.Category+nc.Name] = module.Evaluator // k,v = (类别+名称, 项目评估人名称)
|
|
@@ -143,11 +149,17 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -143,11 +149,17 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
143
|
}
|
149
|
}
|
144
|
}
|
150
|
}
|
145
|
|
151
|
|
|
|
152
|
+ // 权重总数不等于100%,提示报错
|
|
|
153
|
+ if weightTotal != 100 {
|
|
|
154
|
+ sprintf := fmt.Sprintf("当前导入的总权重值为:%s%%(必须等于100%%)", utils.FormatFloatDecimal(weightTotal, 2))
|
|
|
155
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, sprintf), nodeContents
|
|
|
156
|
+ }
|
|
|
157
|
+
|
146
|
if len(evaluatorNames) > 0 {
|
158
|
if len(evaluatorNames) > 0 {
|
147
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
159
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
148
|
_, users, err := userRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "names": evaluatorNames})
|
160
|
_, users, err := userRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "names": evaluatorNames})
|
149
|
if err != nil {
|
161
|
if err != nil {
|
150
|
- return nodeContents
|
162
|
+ return err, nodeContents
|
151
|
}
|
163
|
}
|
152
|
nameIdMap := map[string]int64{}
|
164
|
nameIdMap := map[string]int64{}
|
153
|
for i := range users {
|
165
|
for i := range users {
|
|
@@ -169,5 +181,5 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
@@ -169,5 +181,5 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
169
|
}
|
181
|
}
|
170
|
}
|
182
|
}
|
171
|
|
183
|
|
172
|
- return nodeContents
|
184
|
+ return nil, nodeContents
|
173
|
} |
185
|
} |