|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
|
...
|
...
|
@@ -46,19 +48,22 @@ func (controller *ImportController) Import() { |
|
|
if err != nil {
|
|
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
|
|
|
}
|
|
|
list := controller.parseTemplateNodeContent(dimensions)
|
|
|
controller.Response(tool_funs.SimpleWrapGridMap(int64(len(list)), list), nil)
|
|
|
if err, list := controller.parseTemplateNodeContent(dimensions); err != nil {
|
|
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
|
|
|
} else {
|
|
|
controller.Response(tool_funs.SimpleWrapGridMap(int64(len(list)), list), nil)
|
|
|
}
|
|
|
default:
|
|
|
controller.Response(nil, application.ThrowError(application.ARG_ERROR, "请确认您导入的表单类型"))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (controller *ImportController) parseTemplateNodeContent(data []*domain.PerformanceDimension) []*domain.NodeContent {
|
|
|
func (controller *ImportController) parseTemplateNodeContent(data []*domain.PerformanceDimension) (error, []*domain.NodeContent) {
|
|
|
nodeContents := make([]*domain.NodeContent, 0)
|
|
|
|
|
|
transactionContext, err := factory.StartTransaction()
|
|
|
if err != nil {
|
|
|
return nodeContents
|
|
|
return err, nodeContents
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -70,18 +75,18 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, rules, err := ruleRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
|
|
|
if err != nil {
|
|
|
return nodeContents
|
|
|
return err, nodeContents
|
|
|
}
|
|
|
var ruleId = int64(0)
|
|
|
if len(rules) == 0 {
|
|
|
newRule := domain.GenerateSysRule(ua.CompanyId) // 生成一个系统默认规则
|
|
|
if rule, err := ruleRepository.Insert(newRule); err != nil {
|
|
|
return nodeContents
|
|
|
return err, nodeContents
|
|
|
} else {
|
|
|
ruleId = rule.Id
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nodeContents
|
|
|
return err, nodeContents
|
|
|
}
|
|
|
} else {
|
|
|
ruleId = rules[0].Id
|
...
|
...
|
@@ -91,6 +96,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
evaluatorNames := make([]string, 0)
|
|
|
evaluatorMap := map[string]string{}
|
|
|
|
|
|
weightTotal := 0.0
|
|
|
for i := range data {
|
|
|
dimension := data[i]
|
|
|
for i2 := range dimension.PerformanceModule {
|
...
|
...
|
@@ -107,6 +113,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
} else {
|
|
|
nc.Weight = 0
|
|
|
}
|
|
|
weightTotal += nc.Weight // 总权重
|
|
|
nc.PromptTitle = "" // 提示项标题
|
|
|
nc.PromptText = module.Standard // 提示项内容
|
|
|
nc.EntryItems = make([]*domain.EntryItem, 0) // 输入项
|
...
|
...
|
@@ -132,7 +139,6 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
if module.Evaluator == "HRBP" {
|
|
|
nc.EvaluatorId = -1
|
|
|
} else {
|
|
|
|
|
|
if len(module.Evaluator) > 0 {
|
|
|
evaluatorNames = append(evaluatorNames, module.Evaluator) // 项目评估人名称数组
|
|
|
evaluatorMap[nc.Category+nc.Name] = module.Evaluator // k,v = (类别+名称, 项目评估人名称)
|
...
|
...
|
@@ -143,11 +149,17 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 权重总数不等于100%,提示报错
|
|
|
if weightTotal != 100 {
|
|
|
sprintf := fmt.Sprintf("当前导入的总权重值为:%s%%(必须等于100%%)", utils.FormatFloatDecimal(weightTotal, 2))
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, sprintf), nodeContents
|
|
|
}
|
|
|
|
|
|
if len(evaluatorNames) > 0 {
|
|
|
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, users, err := userRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "names": evaluatorNames})
|
|
|
if err != nil {
|
|
|
return nodeContents
|
|
|
return err, nodeContents
|
|
|
}
|
|
|
nameIdMap := map[string]int64{}
|
|
|
for i := range users {
|
...
|
...
|
@@ -169,5 +181,5 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf |
|
|
}
|
|
|
}
|
|
|
|
|
|
return nodeContents
|
|
|
return nil, nodeContents
|
|
|
} |
...
|
...
|
|