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_rule" "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command" "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares" ) type RuleController struct { beego.BaseController } func (controller *RuleController) CreateRule() { ruService := service.NewEvaluationRuleService() in := &command.CreateRuleCommand{} 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 in.CreatorId = ua.UserId controller.Response(ruService.Create(in)) } } func (controller *RuleController) UpdateRule() { ruService := service.NewEvaluationRuleService() in := &command.UpdateRuleCommand{} 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.Update(in)) } } func (controller *RuleController) GetRule() { ruService := service.NewEvaluationRuleService() in := &command.GetRuleCommand{} 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 *RuleController) RemoveRule() { ruService := service.NewEvaluationRuleService() in := &command.DeleteRuleCommand{} 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 *RuleController) ListRule() { // ruService := service.NewEvaluationRuleService() // in := &command.QueryRuleCommand{} // in.Type = -1 // if err := controller.Unmarshal(in); err != nil { // controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) // } else { // if len(in.NameOrRemark) > 0 { // in.NameOrRemark = "%" + in.NameOrRemark + "%" // } // in.CompanyId = middlewares.GetCompanyId(controller.Ctx) // controller.Response(ruService.List(in)) // } //} func (controller *RuleController) ListRuleRelCreator() { ruService := service.NewEvaluationRuleService() in := &command.QueryRuleCommand{} in.Type = -1 if err := controller.Unmarshal(in); err != nil { controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) } else { if len(in.NameOrRemark) > 0 { in.NameOrRemark = "%" + in.NameOrRemark + "%" } ua := middlewares.GetUser(controller.Ctx) in.CompanyId = ua.CompanyId controller.Response(ruService.ListRelCreator(in)) } } func (controller *RuleController) ListCreator() { ruService := service.NewEvaluationRuleService() in := &command.QueryCreatorCommand{} 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.ListCreator(in)) } }