审查视图

pkg/port/beego/controllers/evaluation_template_controller.go 3.9 KB
1 2 3 4 5 6 7
package controllers

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/web/beego"
	service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
8
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
9 10 11 12 13 14 15
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type TemplateController struct {
	beego.BaseController
}
郑周 authored
16
func (controller *TemplateController) CreateTemplate() {
17 18 19 20 21
	ruService := service.NewEvaluationTemplateService()
	in := &command.CreateTemplateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
22 23 24
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		in.CreatorId = ua.UserId
25 26 27 28 29 30 31 32 33 34
		controller.Response(ruService.Create(in))
	}
}

func (controller *TemplateController) UpdateTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.UpdateTemplateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
35 36
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
		controller.Response(ruService.Update(in))
	}
}

func (controller *TemplateController) GetTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.GetTemplateCommand{}
	if id, err := controller.GetInt64(":Id"); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.Id = id
		controller.Response(ruService.Get(in))
	}
}

func (controller *TemplateController) RemoveTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.DeleteTemplateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.Remove(in))
	}
}

func (controller *TemplateController) ListTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.QueryTemplateCommand{}
65
	in.State = -1
66 67 68
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
69 70 71
		if len(in.Name) > 0 {
			in.Name = "%" + in.Name + "%"
		}
郑周 authored
72 73
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
74 75 76 77 78 79
		controller.Response(ruService.List(in))
	}
}

func (controller *TemplateController) ListEnableTemplate() {
	ruService := service.NewEvaluationTemplateService()
80 81 82 83
	in := &command.QueryTemplateCommand{}
	in.State = domain.TemplateStateEnable
	in.PageNumber = 1
	in.PageSize = 999999
84 85 86
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
87 88
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
89
		controller.Response(ruService.List(in))
90 91 92 93 94 95 96 97 98
	}
}

func (controller *TemplateController) StateTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.StateTemplateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
99 100
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
101 102 103 104 105 106 107 108 109 110
		controller.Response(ruService.State(in))
	}
}

func (controller *TemplateController) CopyTemplate() {
	ruService := service.NewEvaluationTemplateService()
	in := &command.CopyTemplateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
111 112 113
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		in.CreatorId = ua.UserId
114 115 116
		controller.Response(ruService.Copy(in))
	}
}