作者 郑周

创建周期 接口

... ... @@ -25,9 +25,14 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if in.KpiCycle == 0 {
validation.SetError("kpiCycle", "请选择考核周期")
return
}
if in.TimeStart == nil {
validation.SetError("timeStart", "请选择考核周期的开始时间")
return
... ... @@ -37,7 +42,7 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.TemplateIds) == 0 {
validation.SetError("templates", "请选择周期内使用的评估模板")
validation.SetError("templates", "请添加评估模板")
return
}
}
... ...
... ... @@ -38,7 +38,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的周期")
}
_, 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
}
// 获取所有模板中的规则对象数据
ruleIds := make([]int64, 0)
ruleMap := map[int64]*domain.EvaluationRule{}
ruleIdsMap := map[int64]int64{}
for i := range templates {
v := templates[i]
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
ruleIds = append(ruleIds, nodeContent.RuleId)
if nodeContent.RuleId != 0 {
ruleIdsMap[nodeContent.RuleId] = nodeContent.RuleId
}
}
}
}
ruleIds := make([]int64, 0)
for k := range ruleIdsMap {
ruleIds = append(ruleIds, k)
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
... ...
... ... @@ -21,8 +21,6 @@ func (controller *CycleController) CreateCycle() {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ...