作者 郑周

创建周期 接口

@@ -25,9 +25,14 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) { @@ -25,9 +25,14 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
25 return 25 return
26 } 26 }
27 if len(in.Name) > 40 { 27 if len(in.Name) > 40 {
28 - validation.SetError("name", "角色名称最大长度40个字符") 28 + validation.SetError("name", "名称最大长度40个字符")
29 return 29 return
30 } 30 }
  31 + if in.KpiCycle == 0 {
  32 + validation.SetError("kpiCycle", "请选择考核周期")
  33 + return
  34 + }
  35 +
31 if in.TimeStart == nil { 36 if in.TimeStart == nil {
32 validation.SetError("timeStart", "请选择考核周期的开始时间") 37 validation.SetError("timeStart", "请选择考核周期的开始时间")
33 return 38 return
@@ -37,7 +42,7 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) { @@ -37,7 +42,7 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
37 return 42 return
38 } 43 }
39 if len(in.TemplateIds) == 0 { 44 if len(in.TemplateIds) == 0 {
40 - validation.SetError("templates", "请选择周期内使用的评估模板") 45 + validation.SetError("templates", "请添加评估模板")
41 return 46 return
42 } 47 }
43 } 48 }
@@ -38,7 +38,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -38,7 +38,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
38 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 38 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
39 } 39 }
40 if count > 0 { 40 if count > 0 {
41 - return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在") 41 + return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的周期")
42 } 42 }
43 43
44 _, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds}) 44 _, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds})
@@ -65,19 +65,27 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf @@ -65,19 +65,27 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
65 } 65 }
66 66
67 // 获取所有模板中的规则对象数据 67 // 获取所有模板中的规则对象数据
68 - ruleIds := make([]int64, 0)  
69 - ruleMap := map[int64]*domain.EvaluationRule{} 68 + ruleIdsMap := map[int64]int64{}
70 for i := range templates { 69 for i := range templates {
71 v := templates[i] 70 v := templates[i]
72 for j := range v.LinkNodes { 71 for j := range v.LinkNodes {
73 node := v.LinkNodes[j] 72 node := v.LinkNodes[j]
74 for k := range node.NodeContents { 73 for k := range node.NodeContents {
75 nodeContent := node.NodeContents[k] 74 nodeContent := node.NodeContents[k]
76 - ruleIds = append(ruleIds, nodeContent.RuleId) 75 + if nodeContent.RuleId != 0 {
  76 + ruleIdsMap[nodeContent.RuleId] = nodeContent.RuleId
  77 + }
77 } 78 }
78 } 79 }
79 } 80 }
  81 + ruleIds := make([]int64, 0)
  82 + for k := range ruleIdsMap {
  83 + ruleIds = append(ruleIds, k)
  84 + }
  85 +
80 _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId}) 86 _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
  87 +
  88 + ruleMap := map[int64]*domain.EvaluationRule{}
81 for i := range rules { 89 for i := range rules {
82 ruleMap[rules[i].Id] = rules[i] 90 ruleMap[rules[i].Id] = rules[i]
83 } 91 }
@@ -21,8 +21,6 @@ func (controller *CycleController) CreateCycle() { @@ -21,8 +21,6 @@ func (controller *CycleController) CreateCycle() {
21 ua := middlewares.GetUser(controller.Ctx) 21 ua := middlewares.GetUser(controller.Ctx)
22 in.CompanyId = ua.CompanyId 22 in.CompanyId = ua.CompanyId
23 in.CreatorId = ua.UserId 23 in.CreatorId = ua.UserId
24 - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx)  
25 - //in.CreatorId = middlewares.GetUserId(controller.Ctx)  
26 controller.Response(ruService.Create(in)) 24 controller.Response(ruService.Create(in))
27 } 25 }
28 } 26 }