...
|
...
|
@@ -2,9 +2,14 @@ package controllers |
|
|
|
|
|
import (
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"github.com/linmadan/egglib-go/web/beego"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
type ImportController struct {
|
...
|
...
|
@@ -37,8 +42,82 @@ func (controller *ImportController) Import() { |
|
|
switch formType {
|
|
|
case "PerformanceDimension":
|
|
|
dimensions, _ := domain.LoadPerformanceDimensions(rows)
|
|
|
controller.Response(dimensions, nil)
|
|
|
list := controller.parseTemplateNodeContent(dimensions)
|
|
|
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 {
|
|
|
nodeContents := make([]*domain.NodeContent, 0)
|
|
|
|
|
|
transactionContext, err := factory.StartTransaction()
|
|
|
if err != nil {
|
|
|
return nodeContents
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// 获取当前公司下的默认规则
|
|
|
ua := middlewares.GetUser(controller.Ctx)
|
|
|
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
|
|
|
}
|
|
|
var ruleId = int64(0)
|
|
|
if len(rules) == 0 {
|
|
|
newRule := domain.GenerateSysRule(ua.CompanyId) // 生成一个系统默认规则
|
|
|
if rule, err := ruleRepository.Insert(newRule); err != nil {
|
|
|
return nodeContents
|
|
|
} else {
|
|
|
ruleId = rule.Id
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nodeContents
|
|
|
}
|
|
|
} else {
|
|
|
ruleId = rules[0].Id
|
|
|
}
|
|
|
|
|
|
for i := range data {
|
|
|
dimension := data[i]
|
|
|
for i2 := range dimension.PerformanceModule {
|
|
|
nc := &domain.NodeContent{}
|
|
|
nc.Category = dimension.Name // 类别
|
|
|
|
|
|
module := dimension.PerformanceModule[i2]
|
|
|
nc.Name = module.ModuleName // 名称
|
|
|
nc.RuleId = ruleId // 规则ID
|
|
|
sIndex := strings.Index(module.Weight, "%") // 权重
|
|
|
if sIndex != -1 {
|
|
|
iWeight, _ := strconv.Atoi(module.Weight[:sIndex])
|
|
|
nc.Weight = iWeight
|
|
|
} else {
|
|
|
nc.Weight = 0
|
|
|
}
|
|
|
nc.PromptTitle = "" // 提示项标题
|
|
|
nc.PromptText = module.Standard // 提示项内容
|
|
|
nc.EntryItems = make([]*domain.EntryItem, 0) // 输入项
|
|
|
for i3 := range module.Target {
|
|
|
target := module.Target[i3]
|
|
|
nc.EntryItems = append(nc.EntryItems, &domain.EntryItem{
|
|
|
Title: target.Task, // 输入型标题
|
|
|
HintText: "", // 输入项提示文本
|
|
|
})
|
|
|
}
|
|
|
// 没有任何输入项时,默认1个
|
|
|
if len(nc.EntryItems) == 0 {
|
|
|
nc.EntryItems = append(nc.EntryItems, &domain.EntryItem{
|
|
|
Title: "填写反馈",
|
|
|
HintText: "",
|
|
|
})
|
|
|
}
|
|
|
|
|
|
nodeContents = append(nodeContents, nc)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return nodeContents
|
|
|
} |
...
|
...
|
|