作者 郑周

增加 获取 周期下的模板列表

... ... @@ -24,3 +24,11 @@ type StatisticCycleProjectUserCommand struct {
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
type CycleTemplateCommand struct {
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
}
func (in *CycleTemplateCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -102,6 +102,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
... ... @@ -114,7 +115,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplate.Id,
Name: cycleTemplate.Name,
CreatedAt: cycleTemplate.CreatedAt,
CreatedAt: cycleTemplate.TemplateCreatedAt, // 模板创建时间
})
}
... ... @@ -190,6 +191,7 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
... ... @@ -220,7 +222,7 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
... ... @@ -257,7 +259,7 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{},
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
... ... @@ -361,3 +363,30 @@ func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleP
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
}
func (rs *EvaluationCycleService) CycleTemplateList(in *command.CycleTemplateCommand) (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})
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": in.CycleId}, "template")
list := make([]*domain.TemplateSimple, 0)
for i := range cycleTemplates {
list = append(list, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"list": list}, nil
}
... ...
... ... @@ -17,7 +17,7 @@ const (
type TemplateSimple struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
CreatedAt time.Time `json:"createdAt" comment:"模板创建时间"`
}
type EvaluationCycle struct {
... ...
... ... @@ -7,6 +7,7 @@ import (
type EvaluationCycleTemplate struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
TemplateCreatedAt time.Time `json:"templateCreatedAt" comment:"模板创建时间"`
Template *EvaluationTemplate `json:"template" comment:"模板数据"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
... ...
... ... @@ -9,6 +9,7 @@ type EvaluationCycleTemplate struct {
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
TemplateCreatedAt time.Time `comment:"模板创建时间"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
... ...
... ... @@ -24,6 +24,7 @@ func (repo *EvaluationCycleTemplateRepository) TransformToDomain(m *models.Evalu
return domain.EvaluationCycleTemplate{
Id: m.Id,
Name: m.Name,
TemplateCreatedAt: m.TemplateCreatedAt,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
... ... @@ -36,6 +37,7 @@ func (repo *EvaluationCycleTemplateRepository) TransformToModel(d *domain.Evalua
return models.EvaluationCycleTemplate{
Id: d.Id,
Name: d.Name,
TemplateCreatedAt: d.TemplateCreatedAt,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
... ...
... ... @@ -87,3 +87,13 @@ func (controller *CycleController) StatisticCycleUser() {
controller.Response(ruService.StatisticCycleUser(in))
}
}
func (controller *CycleController) CycleTemplateList() {
ruService := service.NewEvaluationCycleService()
in := &command.CycleTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.CycleTemplateList(in))
}
}
... ...
... ... @@ -16,6 +16,7 @@ func init() {
web.NSRouter("/:Id", &controllers.CycleController{}, "Get:GetCycle"),
web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"),
web.NSRouter("/statistic", &controllers.CycleController{}, "Post:StatisticCycleUser"),
web.NSRouter("/templates", &controllers.CycleController{}, "Post:CycleTemplateList"),
)
web.AddNamespace(ns)
}
... ...