审查视图

pkg/port/beego/controllers/evaluation_cycle_controller.go 3.6 KB
郑周 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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_cycle"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

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

func (controller *CycleController) UpdateCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.UpdateCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
34 35 36
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
郑周 authored
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 65 66 67 68 69 70
		controller.Response(ruService.Update(in))
	}
}

func (controller *CycleController) GetCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.GetCycleCommand{}
	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 *CycleController) RemoveCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.DeleteCycleCommand{}
	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 *CycleController) ListCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.QueryCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		if len(in.Name) > 0 {
			in.Name = "%" + in.Name + "%"
		}
郑周 authored
71 72
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
73 74 75
		controller.Response(ruService.List(in))
	}
}
郑周 authored
76 77 78 79 80 81 82 83 84 85 86 87

func (controller *CycleController) StatisticCycleUser() {
	ruService := service.NewEvaluationCycleService()
	in := &command.StatisticCycleProjectUserCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		controller.Response(ruService.StatisticCycleUser(in))
	}
}
88 89 90

func (controller *CycleController) CycleTemplateList() {
	ruService := service.NewEvaluationCycleService()
91
	in := &command.CycleTemplateListCommand{}
92 93 94 95 96 97
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.CycleTemplateList(in))
	}
}
98 99 100 101

func (controller *CycleController) CycleTemplate() {
	ruService := service.NewEvaluationCycleService()
	in := &command.CycleTemplateCommand{}
郑周 authored
102
	if id, err := controller.GetInt64(":Id"); err != nil {
103 104
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
105
		in.Id = id
106 107 108
		controller.Response(ruService.CycleTemplate(in))
	}
}