作者 庄敏学

增加导入字段是否必填

不能预览此文件类型
... ... @@ -12,6 +12,7 @@ type PerformanceApplicationForm struct {
Standard string //标准
Task string //任务、指标
Definition string //定义
Required string // 是否必填 是 否
}
type PerformanceDimension struct {
... ... @@ -24,6 +25,7 @@ type PerformanceModule struct {
Weight string `json:"weight"` //权重
Standard string `json:"standard"` //标准(结构化的成果描述)
Target []*PerformanceTarget `json:"performanceTarget"` //任务\指标
Required int `json:"required"` // 是否必填
}
type PerformanceTarget struct {
... ... @@ -34,6 +36,7 @@ type PerformanceTarget struct {
func LoadPerformanceDimensions(rows [][]string) ([]*PerformanceDimension, error) {
formRows := make([]*PerformanceApplicationForm, 0)
var dimensionName, moduleName, taskName, weightName, standardName string
required := "是"
for key, item := range rows {
if key < 3 {
continue
... ... @@ -80,6 +83,11 @@ func LoadPerformanceDimensions(rows [][]string) ([]*PerformanceDimension, error)
}
}
form.Standard = standardName
//是否必填
if len(item) > 9 && item[9] != "" {
required = strings.TrimSpace(item[9])
}
form.Required = required
formRows = append(formRows, form)
}
dimensions := make([]*PerformanceDimension, 0)
... ... @@ -144,11 +152,16 @@ func loadPerformanceModule(forms []*PerformanceApplicationForm) ([]*PerformanceM
if err != nil {
return modules, err
}
required, err := getRequired(item)
if err != nil {
return modules, err
}
module := &PerformanceModule{
ModuleName: moduleName,
Weight: weightName,
Standard: standardName,
Target: tasks,
Required: required,
}
modules = append(modules, module)
}
... ... @@ -201,6 +214,27 @@ func getStandard(items []*PerformanceApplicationForm) (string, error) {
return name, nil
}
// 获取是否必填
func getRequired(items []*PerformanceApplicationForm) (int, error) {
if len(items) <= 0 {
return NodeRequiredYes, nil
}
var name string
for _, item := range items {
if name == "" {
name = item.Required
}
if name != item.Required {
return NodeRequiredYes, errors.New(item.ModuleName + " 对应的是否必填不一致")
}
}
if name == "否" {
return NodeRequiredNo, nil
} else {
return NodeRequiredYes, nil
}
}
// 获取任务
func getTasks(items []*PerformanceApplicationForm) ([]*PerformanceTarget, error) {
tasks := make([]*PerformanceTarget, 0)
... ...
... ... @@ -121,7 +121,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf
}
// 必填项
nc.Required = domain.NodeRequiredYes
nc.Required = module.Required
nodeContents = append(nodeContents, nc)
}
}
... ...
不能预览此文件类型