作者 郑周

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

... ... @@ -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) {
}
... ...
... ... @@ -100,10 +100,11 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
// 周期模板数据表中插入数据
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
... ... @@ -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, // 模板创建时间
})
}
... ... @@ -188,10 +189,11 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
... ... @@ -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 {
... ...
... ... @@ -5,13 +5,14 @@ import (
)
type EvaluationCycleTemplate struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
Template *EvaluationTemplate `json:"template" comment:"模板数据"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
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:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type EvaluationCycleTemplateRepository interface {
... ...
... ... @@ -6,12 +6,13 @@ import (
)
type EvaluationCycleTemplate struct {
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
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:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -22,25 +22,27 @@ func NewEvaluationCycleTemplateRepository(transactionContext *pgTransaction.Tran
func (repo *EvaluationCycleTemplateRepository) TransformToDomain(m *models.EvaluationCycleTemplate) domain.EvaluationCycleTemplate {
return domain.EvaluationCycleTemplate{
Id: m.Id,
Name: m.Name,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
Id: m.Id,
Name: m.Name,
TemplateCreatedAt: m.TemplateCreatedAt,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
}
}
func (repo *EvaluationCycleTemplateRepository) TransformToModel(d *domain.EvaluationCycleTemplate) models.EvaluationCycleTemplate {
return models.EvaluationCycleTemplate{
Id: d.Id,
Name: d.Name,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
Name: d.Name,
TemplateCreatedAt: d.TemplateCreatedAt,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
... ...
... ... @@ -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)
}
... ...