作者 郑周

1. 新增 检测模板ID是否有任务指标

... ... @@ -35,6 +35,11 @@ type CheckRecipientCommand struct {
Recipients []string `cname:"被评估人ID" json:"recipients"`
}
// CheckTaskTemplateCommand 检测选中的模板是否含有任务指标
type CheckTaskTemplateCommand struct {
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
... ...
... ... @@ -910,3 +910,41 @@ func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContex
}
return nil
}
func (rs *EvaluationProjectService) CheckTaskTemplate(in *command.CheckTaskTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cycleTemplate == nil || cycleTemplate.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到模板")
}
// 指标任务的项目(存在一项类型为任务指标),必须添加项目负责人
var indicatorTypeTask = 0
outerLoop:
for i := range cycleTemplate.Template.LinkNodes {
var node = cycleTemplate.Template.LinkNodes[i]
for j := range node.NodeContents {
if node.NodeContents[j].IndicatorType == domain.IndicatorTypeTask {
indicatorTypeTask = 1
break outerLoop
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"indicatorTypeTask": indicatorTypeTask}, nil
}
... ...
... ... @@ -139,3 +139,13 @@ func (controller *ProjectController) CheckRecipients() {
controller.Response(ruService.CheckRecipients(in))
}
}
func (controller *ProjectController) CheckTaskTemplate() {
ruService := service.NewEvaluationProjectService()
in := &command.CheckTaskTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.CheckTaskTemplate(in))
}
}
... ...
... ... @@ -17,6 +17,7 @@ func init() {
web.NSRouter("/list", &controllers.ProjectController{}, "Post:ListProject"),
web.NSRouter("/detail", &controllers.ProjectController{}, "Put:UpdateProjectForTemplate"),
web.NSRouter("/check-recipients", &controllers.ProjectController{}, "Post:CheckRecipients"),
web.NSRouter("/check-template", &controllers.ProjectController{}, "Post:CheckTaskTemplate"),
web.NSRouter("/copy", &controllers.ProjectController{}, "Post:CopyProject"),
web.NSRouter("/activate", &controllers.ProjectController{}, "Post:ActivateProject"),
web.NSRouter("/pause", &controllers.ProjectController{}, "Post:PauseProject"),
... ...