作者 郑周

1.评估模板 业务代码逻辑编码

... ... @@ -3,13 +3,9 @@ package command
import "github.com/beego/beego/v2/core/validation"
type DeleteRuleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
}
func (in *DeleteRuleCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
func (in *DeleteRuleCommand) Valid(*validation.Validation) {
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type GetRuleCommand struct {
Id int64 `cname:"规则Id" json:"id,string" valid:"Required"`
}
func (in *GetRuleCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type EvaluationRuleService struct {
... ... @@ -98,6 +99,23 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
return rule, nil
}
func (rs *EvaluationRuleService) Get(in *command.GetRuleCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return rule, nil
}
func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
... ... @@ -132,9 +150,26 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, rules), nil
}
func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// Fixme 总数量是否使用Count获取一个总数量
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
)
type CreateTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"remark"`
}
func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
if in.CreatorId == 0 {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
validation.SetError("name", "模板名称最大长度40个字符")
return
}
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type DeleteTemplateCommand struct {
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
}
func (in *DeleteTemplateCommand) Valid(*validation.Validation) {
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type GetTemplateCommand struct {
Id int64 `cname:"模板Id" json:"id,string" valid:"Required"`
}
func (in *GetTemplateCommand) Valid(validation *validation.Validation) {
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StateTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
State int `cname:"模板状态" json:"state"`
}
type CopyTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateTemplateCommand) Valid(validation *validation.Validation) {
switch in.State {
case domain.TemplateStateWaitConfig, domain.TemplateStateWaitActive, domain.TemplateStateEnable, domain.TemplateStateDisable:
default:
validation.SetError("state", "状态设置错误")
return
}
}
func (in *CopyTemplateCommand) Valid(*validation.Validation) {
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
type QueryTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
// AllEnableTemplateCommand 查询所有已启用的模板
type AllEnableTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
}
func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type UpdateTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"remark"`
LinkNodes []domain.LinkNode `cname:"评估流程" json:"linkNodes"`
}
func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
if in.CreatorId == 0 {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
validation.SetError("name", "模板名称最大长度40个字符")
return
}
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "评估模板流程不能为空")
return
}
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type EvaluationTemplateService struct {
}
func NewEvaluationTemplateService() *EvaluationTemplateService {
newRoleService := &EvaluationTemplateService{}
return newRoleService
}
// Create 创建
func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := ruleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
}
linkNodes := make([]domain.LinkNode, 0)
linkNodes = append(linkNodes, domain.LinkNode{
Type: domain.LinkNodeAssessment,
Name: "填写自评反馈",
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, domain.LinkNode{
Type: domain.LinkNodeAllInvite,
Name: "360°邀请",
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, domain.LinkNode{
Type: domain.LinkNodeAssessment,
Name: "360°评估",
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, domain.LinkNode{
Type: domain.LinkNodeAssessment,
Name: "上级评估",
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, domain.LinkNode{
Type: domain.LinkNodeViewResult,
Name: "绩效结果查看",
KpiCycle: domain.KpiCycleDay,
})
newTemplate := &domain.EvaluationTemplate{
Id: 0,
Name: in.Name,
Describe: in.Describe,
CompanyId: in.CompanyId,
CreatorId: in.CreatorId,
State: domain.TemplateStateWaitConfig,
LinkNodes: linkNodes,
}
rule, err := ruleRepository.Insert(newTemplate)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return rule, nil
}
func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复(排除自己)
count, err := templateRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
}
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
template.Name = in.Name
template.Describe = in.Describe
template.LinkNodes = in.LinkNodes
template, err = templateRepository.Insert(template)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return template, nil
}
func (rs *EvaluationTemplateService) Get(in *command.GetTemplateCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return template, nil
}
func (rs *EvaluationTemplateService) Remove(in *command.DeleteTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := templateRepository.Remove(template); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return template, nil
}
func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), true)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, templates), nil
}
func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplateCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
count, templates, err := templateRepository.Find(map[string]interface{}{
"companyId": in.CompanyId,
"state": domain.TemplateStateEnable,
"offset": 0,
"limit": 9999999,
}, true)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, templates), nil
}
func (rs *EvaluationTemplateService) State(in *command.StateTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
template.State = in.State
template, err = templateRepository.Insert(template)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return template, nil
}
func (rs *EvaluationTemplateService) Copy(in *command.CopyTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// ID重置
template.Id = 0
// 如果拷贝已经启用的模板,默认先设置为待启用
if template.State == domain.TemplateStateEnable {
template.State = domain.TemplateStateWaitActive
}
template, err = templateRepository.Insert(template)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return template, nil
}
... ...
... ... @@ -12,11 +12,16 @@ const (
)
const (
LinkNodeSelfAssessment int = 1 // 环节-填写反馈自评
LinkNodeAllInvite int = 2 // 环节-360°邀请
LinkNodeAllAssessment int = 3 // 环节-360°评估
LinkNodeSuperiorAssessment int = 4 // 环节-上级评估
LinkNodeViewResult int = 5 // 环节-绩效结果查看
//LinkNodeSelfAssessment int = 1 // 环节-填写反馈自评
//LinkNodeAllInvite int = 2 // 环节-360°邀请
//LinkNodeAllAssessment int = 3 // 环节-360°评估
//LinkNodeSuperiorAssessment int = 4 // 环节-上级评估
//LinkNodeViewResult int = 5 // 环节-绩效结果查看
LinkNodeAssessment int = 1 // 环节-评估(自评、360°评估、上级评估)
LinkNodeAllInvite int = 2 // 环节-360°邀请
LinkNodeViewResult int = 3 // 环节-绩效结果查看
)
const (
... ... @@ -30,7 +35,8 @@ type EntryItem struct {
HintText string `json:"hintText" comment:"文本内容提示"`
}
type EvaluationContent struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
... ... @@ -39,23 +45,25 @@ type EvaluationContent struct {
EntryItems []EntryItem `json:"entryItems" comment:"填写项"`
}
type LinkNode struct {
Type int `json:"type" comment:"环节类型(1~5)"`
Name string `json:"name" comment:"环节名称"`
Describe string `json:"describe" comment:"环节描述"`
EvaluationContents []EvaluationContent `json:"evaluationContents" comment:"环节评估内容"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
// NodeAllInvite 360°邀请
type NodeAllInvite struct {
}
//type EvaluationLink struct {
// NodeSelfAssessment *LinkNode `json:"nodeSelfAssessment" comment:"填写反馈自评"`
// NodeAllInvite *LinkNode `json:"nodeAllInvite" comment:"360°邀请"`
// NodeAllAssessment *LinkNode `json:"nodeAllAssessment" comment:"360°评估"`
// NodeSuperiorAssessment *LinkNode `json:"nodeSuperiorAssessment" comment:"上级评估"`
// NodeViewResult *LinkNode `json:"nodeViewResult" comment:"绩效结果查看"`
//}
// NodeKpiResult 绩效结果查看
type NodeKpiResult struct {
}
type LinkNode struct {
Type int `json:"type" comment:"环节类型(1评估、2邀请、3绩效结果)"`
Name string `json:"name" comment:"环节名称"`
Describe string `json:"describe" comment:"环节描述"`
NodeContents []NodeContent `json:"nodeContents" comment:"环节-评估内容"`
NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"环节-360°邀请"`
NodeKpiResult *NodeKpiResult `json:"nodeKpiResult" comment:"环节-绩效结果"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
}
type EvaluationTemplate struct {
Id int64 `json:"id,string" comment:"ID"`
... ... @@ -64,17 +72,24 @@ type EvaluationTemplate struct {
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
Link []LinkNode `json:"links" comment:"评估流程"`
LinkNodes []LinkNode `json:"linkNodes" comment:"评估流程"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
//Link EvaluationLink `json:"link" comment:"评估流程"`
}
//type EvaluationLink struct {
// NodeSelfAssessment *LinkNode `json:"nodeSelfAssessment" comment:"填写反馈自评"`
// NodeAllInvite *LinkNode `json:"nodeAllInvite" comment:"360°邀请"`
// NodeAllAssessment *LinkNode `json:"nodeAllAssessment" comment:"360°评估"`
// NodeSuperiorAssessment *LinkNode `json:"nodeSuperiorAssessment" comment:"上级评估"`
// NodeViewResult *LinkNode `json:"nodeViewResult" comment:"绩效结果查看"`
//}
type EvaluationTemplateRepository interface {
Insert(template *EvaluationTemplate) (*EvaluationTemplate, error)
Remove(template *EvaluationTemplate) (*EvaluationTemplate, error)
FindOne(queryOptions map[string]interface{}) (*EvaluationTemplate, error)
Find(queryOptions map[string]interface{}) (int64, []*EvaluationTemplate, error)
Find(queryOptions map[string]interface{}, simplify bool) (int64, []*EvaluationTemplate, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
... ...
... ... @@ -13,7 +13,7 @@ type EvaluationTemplate struct {
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
Link []domain.LinkNode `comment:"评估流程"`
LinkNodes []domain.LinkNode `comment:"评估流程"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
... ...
... ... @@ -28,7 +28,7 @@ func (repo *EvaluationTemplateRepository) TransformToDomain(m *models.Evaluation
CompanyId: m.CompanyId,
CreatorId: m.CreatorId,
State: m.State,
Link: m.Link,
LinkNodes: m.LinkNodes,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
... ... @@ -43,7 +43,7 @@ func (repo *EvaluationTemplateRepository) TransformToModel(d *domain.EvaluationT
CompanyId: d.CompanyId,
CreatorId: d.CreatorId,
State: d.State,
Link: d.Link,
LinkNodes: d.LinkNodes,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
... ... @@ -112,7 +112,7 @@ func (repo *EvaluationTemplateRepository) FindOne(queryOptions map[string]interf
return &u, nil
}
func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationTemplate, error) {
func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}, simplify bool) (int64, []*domain.EvaluationTemplate, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationTemplate
query := tx.Model(&m).
... ... @@ -127,6 +127,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("company_id = ?", companyId)
}
if state, ok := queryOptions["state"]; ok {
query.Where("state = ?", state)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
... ... @@ -141,6 +145,9 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
var arrays []*domain.EvaluationTemplate
for _, v := range m {
d := repo.TransformToDomain(v)
if simplify { // 去掉流程数据避免数据量过大
d.LinkNodes = make([]domain.LinkNode, 0)
}
arrays = append(arrays, &d)
}
return int64(count), arrays, nil
... ... @@ -168,6 +175,10 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac
query.Where("company_id = ?", companyId)
}
if state, ok := queryOptions["state"]; ok {
query.Where("state = ?", state)
}
count, err := query.Count()
if err != nil {
return 0, err
... ...
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 *RoleController) 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 {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
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 {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
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{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *RuleController) ListRuleRelCreator() {
ruService := service.NewEvaluationRuleService()
in := &command.QueryRuleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRelCreator(in))
}
}
... ...
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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
type TemplateController struct {
beego.BaseController
}
func (controller *RoleController) CreateTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.CreateTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
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 {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
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{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *TemplateController) ListEnableTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.AllEnableTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForEnable(in))
}
}
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 {
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 {
controller.Response(ruService.Copy(in))
}
}
... ...