作者 郑周

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

@@ -3,13 +3,9 @@ package command @@ -3,13 +3,9 @@ package command
3 import "github.com/beego/beego/v2/core/validation" 3 import "github.com/beego/beego/v2/core/validation"
4 4
5 type DeleteRuleCommand struct { 5 type DeleteRuleCommand struct {
6 - CompanyId int64 `cname:"公司ID" json:"companyId"`  
7 - Id int64 `cname:"规则ID" json:"id,string" valid:"Required"` 6 + Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
8 } 7 }
9 8
10 -func (in *DeleteRuleCommand) Valid(validation *validation.Validation) {  
11 - if in.CompanyId == 0 {  
12 - validation.SetError("companyId", "公司ID无效")  
13 - return  
14 - } 9 +func (in *DeleteRuleCommand) Valid(*validation.Validation) {
  10 +
15 } 11 }
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type GetRuleCommand struct {
  6 + Id int64 `cname:"规则Id" json:"id,string" valid:"Required"`
  7 +}
  8 +
  9 +func (in *GetRuleCommand) Valid(*validation.Validation) {
  10 +
  11 +}
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
10 ) 11 )
11 12
12 type EvaluationRuleService struct { 13 type EvaluationRuleService struct {
@@ -98,6 +99,23 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac @@ -98,6 +99,23 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
98 return rule, nil 99 return rule, nil
99 } 100 }
100 101
  102 +func (rs *EvaluationRuleService) Get(in *command.GetRuleCommand) (interface{}, error) {
  103 + // Get 不需要事务
  104 + if err := utils.ValidateCommand(in); err != nil {
  105 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  106 + }
  107 + transactionContext, err := factory.CreateTransactionContext(nil)
  108 + if err != nil {
  109 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  110 + }
  111 + ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
  112 + rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id})
  113 + if err != nil {
  114 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 + }
  116 + return rule, nil
  117 +}
  118 +
101 func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interface{}, error) { 119 func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interface{}, error) {
102 transactionContext, err := factory.ValidateStartTransaction(in) 120 transactionContext, err := factory.ValidateStartTransaction(in)
103 if err != nil { 121 if err != nil {
@@ -132,9 +150,26 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{} @@ -132,9 +150,26 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}
132 transactionContext.RollbackTransaction() 150 transactionContext.RollbackTransaction()
133 }() 151 }()
134 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) 152 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
  153 + // FIXME 总数量是否使用Count获取一个总数量
  154 + count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
  155 + if err != nil {
  156 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  157 + }
  158 + return tool_funs.SimpleWrapGridMap(count, rules), nil
  159 +}
  160 +
  161 +func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) {
  162 + transactionContext, err := factory.StartTransaction()
  163 + if err != nil {
  164 + return nil, err
  165 + }
  166 + defer func() {
  167 + transactionContext.RollbackTransaction()
  168 + }()
  169 + ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
135 userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 170 userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
136 171
137 - // Fixme 总数量是否使用Count获取一个总数量 172 + // FIXME 总数量是否使用Count获取一个总数量
138 count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in)) 173 count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
139 if err != nil { 174 if err != nil {
140 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 175 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1 +package command
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 +)
  6 +
  7 +type CreateTemplateCommand struct {
  8 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  9 + CreatorId int64 `cname:"创建人ID" json:"creatorId"`
  10 + Name string `cname:"模板名称" json:"name" valid:"Required"`
  11 + Describe string `cname:"模板描述" json:"remark"`
  12 +}
  13 +
  14 +func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
  15 + if in.CompanyId == 0 {
  16 + validation.SetError("companyId", "公司ID无效")
  17 + return
  18 + }
  19 + if in.CreatorId == 0 {
  20 + validation.SetError("creatorId", "创建人ID无效")
  21 + return
  22 + }
  23 +
  24 + if len(in.Name) > 40 {
  25 + validation.SetError("name", "模板名称最大长度40个字符")
  26 + return
  27 + }
  28 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type DeleteTemplateCommand struct {
  6 + Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
  7 +}
  8 +
  9 +func (in *DeleteTemplateCommand) Valid(*validation.Validation) {
  10 +
  11 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type GetTemplateCommand struct {
  6 + Id int64 `cname:"模板Id" json:"id,string" valid:"Required"`
  7 +}
  8 +
  9 +func (in *GetTemplateCommand) Valid(validation *validation.Validation) {
  10 +
  11 +}
  1 +package command
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  6 +)
  7 +
  8 +type StateTemplateCommand struct {
  9 + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
  10 + State int `cname:"模板状态" json:"state"`
  11 +}
  12 +
  13 +type CopyTemplateCommand struct {
  14 + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
  15 +}
  16 +
  17 +func (in *StateTemplateCommand) Valid(validation *validation.Validation) {
  18 + switch in.State {
  19 + case domain.TemplateStateWaitConfig, domain.TemplateStateWaitActive, domain.TemplateStateEnable, domain.TemplateStateDisable:
  20 + default:
  21 + validation.SetError("state", "状态设置错误")
  22 + return
  23 + }
  24 +}
  25 +
  26 +func (in *CopyTemplateCommand) Valid(*validation.Validation) {
  27 +
  28 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type QueryTemplateCommand struct {
  6 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  7 + PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
  8 + PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
  9 +}
  10 +
  11 +func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
  12 + if in.CompanyId == 0 {
  13 + validation.SetError("companyId", "公司ID无效")
  14 + return
  15 + }
  16 +}
  17 +
  18 +// AllEnableTemplateCommand 查询所有已启用的模板
  19 +type AllEnableTemplateCommand struct {
  20 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  21 +}
  22 +
  23 +func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
  24 + if in.CompanyId == 0 {
  25 + validation.SetError("companyId", "公司ID无效")
  26 + return
  27 + }
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  6 +)
  7 +
  8 +type UpdateTemplateCommand struct {
  9 + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
  10 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  11 + CreatorId int64 `cname:"创建人ID" json:"creatorId"`
  12 + Name string `cname:"模板名称" json:"name" valid:"Required"`
  13 + Describe string `cname:"模板描述" json:"remark"`
  14 + LinkNodes []domain.LinkNode `cname:"评估流程" json:"linkNodes"`
  15 +}
  16 +
  17 +func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
  18 + if in.CompanyId == 0 {
  19 + validation.SetError("companyId", "公司ID无效")
  20 + return
  21 + }
  22 + if in.CreatorId == 0 {
  23 + validation.SetError("creatorId", "创建人ID无效")
  24 + return
  25 + }
  26 +
  27 + if len(in.Name) > 40 {
  28 + validation.SetError("name", "模板名称最大长度40个字符")
  29 + return
  30 + }
  31 +
  32 + if len(in.LinkNodes) == 0 {
  33 + validation.SetError("linkNodes", "评估模板流程不能为空")
  34 + return
  35 + }
  36 +
  37 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/tool_funs"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
  10 +)
  11 +
  12 +type EvaluationTemplateService struct {
  13 +}
  14 +
  15 +func NewEvaluationTemplateService() *EvaluationTemplateService {
  16 + newRoleService := &EvaluationTemplateService{}
  17 + return newRoleService
  18 +}
  19 +
  20 +// Create 创建
  21 +func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (interface{}, error) {
  22 + transactionContext, err := factory.ValidateStartTransaction(in)
  23 + if err != nil {
  24 + return nil, err
  25 + }
  26 + defer func() {
  27 + transactionContext.RollbackTransaction()
  28 + }()
  29 + ruleRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  30 +
  31 + // 检测名称重复
  32 + count, err := ruleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
  33 + if err != nil {
  34 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  35 + }
  36 + if count > 0 {
  37 + return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
  38 + }
  39 +
  40 + linkNodes := make([]domain.LinkNode, 0)
  41 + linkNodes = append(linkNodes, domain.LinkNode{
  42 + Type: domain.LinkNodeAssessment,
  43 + Name: "填写自评反馈",
  44 + KpiCycle: domain.KpiCycleDay,
  45 + })
  46 + linkNodes = append(linkNodes, domain.LinkNode{
  47 + Type: domain.LinkNodeAllInvite,
  48 + Name: "360°邀请",
  49 + KpiCycle: domain.KpiCycleDay,
  50 + })
  51 + linkNodes = append(linkNodes, domain.LinkNode{
  52 + Type: domain.LinkNodeAssessment,
  53 + Name: "360°评估",
  54 + KpiCycle: domain.KpiCycleDay,
  55 + })
  56 + linkNodes = append(linkNodes, domain.LinkNode{
  57 + Type: domain.LinkNodeAssessment,
  58 + Name: "上级评估",
  59 + KpiCycle: domain.KpiCycleDay,
  60 + })
  61 + linkNodes = append(linkNodes, domain.LinkNode{
  62 + Type: domain.LinkNodeViewResult,
  63 + Name: "绩效结果查看",
  64 + KpiCycle: domain.KpiCycleDay,
  65 + })
  66 +
  67 + newTemplate := &domain.EvaluationTemplate{
  68 + Id: 0,
  69 + Name: in.Name,
  70 + Describe: in.Describe,
  71 + CompanyId: in.CompanyId,
  72 + CreatorId: in.CreatorId,
  73 + State: domain.TemplateStateWaitConfig,
  74 + LinkNodes: linkNodes,
  75 + }
  76 + rule, err := ruleRepository.Insert(newTemplate)
  77 + if err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + }
  80 + if err := transactionContext.CommitTransaction(); err != nil {
  81 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  82 + }
  83 + return rule, nil
  84 +
  85 +}
  86 +
  87 +func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) (interface{}, error) {
  88 + transactionContext, err := factory.ValidateStartTransaction(in)
  89 + if err != nil {
  90 + return nil, err
  91 + }
  92 + defer func() {
  93 + transactionContext.RollbackTransaction()
  94 + }()
  95 +
  96 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  97 +
  98 + // 检测名称重复(排除自己)
  99 + count, err := templateRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  102 + }
  103 + if count > 0 {
  104 + return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
  105 + }
  106 +
  107 + template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
  108 + if err != nil {
  109 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  110 + }
  111 +
  112 + template.Name = in.Name
  113 + template.Describe = in.Describe
  114 + template.LinkNodes = in.LinkNodes
  115 +
  116 + template, err = templateRepository.Insert(template)
  117 + if err != nil {
  118 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  119 + }
  120 + if err := transactionContext.CommitTransaction(); err != nil {
  121 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  122 + }
  123 + return template, nil
  124 +}
  125 +
  126 +func (rs *EvaluationTemplateService) Get(in *command.GetTemplateCommand) (interface{}, error) {
  127 + // Get 不需要事务
  128 + if err := utils.ValidateCommand(in); err != nil {
  129 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  130 + }
  131 + transactionContext, err := factory.CreateTransactionContext(nil)
  132 + if err != nil {
  133 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  134 + }
  135 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  136 + template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
  137 + if err != nil {
  138 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  139 + }
  140 + return template, nil
  141 +}
  142 +
  143 +func (rs *EvaluationTemplateService) Remove(in *command.DeleteTemplateCommand) (interface{}, error) {
  144 + transactionContext, err := factory.ValidateStartTransaction(in)
  145 + if err != nil {
  146 + return nil, err
  147 + }
  148 + defer func() {
  149 + transactionContext.RollbackTransaction()
  150 + }()
  151 +
  152 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  153 +
  154 + template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
  155 + if err != nil {
  156 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  157 + }
  158 + if _, err := templateRepository.Remove(template); err != nil {
  159 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + }
  161 +
  162 + if err := transactionContext.CommitTransaction(); err != nil {
  163 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  164 + }
  165 + return template, nil
  166 +}
  167 +
  168 +func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (interface{}, error) {
  169 + transactionContext, err := factory.StartTransaction()
  170 + if err != nil {
  171 + return nil, err
  172 + }
  173 + defer func() {
  174 + transactionContext.RollbackTransaction()
  175 + }()
  176 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  177 + // FIXME 总数量是否使用Count获取一个总数量
  178 + count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), true)
  179 + if err != nil {
  180 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  181 + }
  182 + return tool_funs.SimpleWrapGridMap(count, templates), nil
  183 +}
  184 +
  185 +func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplateCommand) (interface{}, error) {
  186 + transactionContext, err := factory.StartTransaction()
  187 + if err != nil {
  188 + return nil, err
  189 + }
  190 + defer func() {
  191 + transactionContext.RollbackTransaction()
  192 + }()
  193 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  194 +
  195 + count, templates, err := templateRepository.Find(map[string]interface{}{
  196 + "companyId": in.CompanyId,
  197 + "state": domain.TemplateStateEnable,
  198 + "offset": 0,
  199 + "limit": 9999999,
  200 + }, true)
  201 + if err != nil {
  202 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  203 + }
  204 + return tool_funs.SimpleWrapGridMap(count, templates), nil
  205 +}
  206 +
  207 +func (rs *EvaluationTemplateService) State(in *command.StateTemplateCommand) (interface{}, error) {
  208 + transactionContext, err := factory.ValidateStartTransaction(in)
  209 + if err != nil {
  210 + return nil, err
  211 + }
  212 + defer func() {
  213 + transactionContext.RollbackTransaction()
  214 + }()
  215 +
  216 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  217 +
  218 + template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
  219 + if err != nil {
  220 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  221 + }
  222 +
  223 + template.State = in.State
  224 + template, err = templateRepository.Insert(template)
  225 + if err != nil {
  226 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  227 + }
  228 + if err := transactionContext.CommitTransaction(); err != nil {
  229 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  230 + }
  231 + return template, nil
  232 +}
  233 +
  234 +func (rs *EvaluationTemplateService) Copy(in *command.CopyTemplateCommand) (interface{}, error) {
  235 + transactionContext, err := factory.ValidateStartTransaction(in)
  236 + if err != nil {
  237 + return nil, err
  238 + }
  239 + defer func() {
  240 + transactionContext.RollbackTransaction()
  241 + }()
  242 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  243 + template, err := templateRepository.FindOne(map[string]interface{}{"id": in.Id})
  244 + if err != nil {
  245 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  246 + }
  247 + // ID重置
  248 + template.Id = 0
  249 + // 如果拷贝已经启用的模板,默认先设置为待启用
  250 + if template.State == domain.TemplateStateEnable {
  251 + template.State = domain.TemplateStateWaitActive
  252 + }
  253 + template, err = templateRepository.Insert(template)
  254 + if err != nil {
  255 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  256 + }
  257 + if err := transactionContext.CommitTransaction(); err != nil {
  258 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  259 + }
  260 + return template, nil
  261 +}
@@ -12,11 +12,16 @@ const ( @@ -12,11 +12,16 @@ const (
12 ) 12 )
13 13
14 const ( 14 const (
15 - LinkNodeSelfAssessment int = 1 // 环节-填写反馈自评  
16 - LinkNodeAllInvite int = 2 // 环节-360°邀请  
17 - LinkNodeAllAssessment int = 3 // 环节-360°评估  
18 - LinkNodeSuperiorAssessment int = 4 // 环节-上级评估  
19 - LinkNodeViewResult int = 5 // 环节-绩效结果查看 15 + //LinkNodeSelfAssessment int = 1 // 环节-填写反馈自评
  16 + //LinkNodeAllInvite int = 2 // 环节-360°邀请
  17 + //LinkNodeAllAssessment int = 3 // 环节-360°评估
  18 + //LinkNodeSuperiorAssessment int = 4 // 环节-上级评估
  19 + //LinkNodeViewResult int = 5 // 环节-绩效结果查看
  20 +
  21 + LinkNodeAssessment int = 1 // 环节-评估(自评、360°评估、上级评估)
  22 + LinkNodeAllInvite int = 2 // 环节-360°邀请
  23 + LinkNodeViewResult int = 3 // 环节-绩效结果查看
  24 +
20 ) 25 )
21 26
22 const ( 27 const (
@@ -30,7 +35,8 @@ type EntryItem struct { @@ -30,7 +35,8 @@ type EntryItem struct {
30 HintText string `json:"hintText" comment:"文本内容提示"` 35 HintText string `json:"hintText" comment:"文本内容提示"`
31 } 36 }
32 37
33 -type EvaluationContent struct { 38 +// NodeContent 评估内容
  39 +type NodeContent struct {
34 Category string `json:"category" comment:"类别"` 40 Category string `json:"category" comment:"类别"`
35 Name string `json:"name" comment:"名称"` 41 Name string `json:"name" comment:"名称"`
36 RuleId int64 `json:"ruleId" comment:"评估规则ID"` 42 RuleId int64 `json:"ruleId" comment:"评估规则ID"`
@@ -39,23 +45,25 @@ type EvaluationContent struct { @@ -39,23 +45,25 @@ type EvaluationContent struct {
39 EntryItems []EntryItem `json:"entryItems" comment:"填写项"` 45 EntryItems []EntryItem `json:"entryItems" comment:"填写项"`
40 } 46 }
41 47
42 -type LinkNode struct {  
43 - Type int `json:"type" comment:"环节类型(1~5)"`  
44 - Name string `json:"name" comment:"环节名称"`  
45 - Describe string `json:"describe" comment:"环节描述"`  
46 - EvaluationContents []EvaluationContent `json:"evaluationContents" comment:"环节评估内容"`  
47 - TimeStart *time.Time `json:"timeStart" comment:"起始时间"`  
48 - TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`  
49 - KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"` 48 +// NodeAllInvite 360°邀请
  49 +type NodeAllInvite struct {
50 } 50 }
51 51
52 -//type EvaluationLink struct {  
53 -// NodeSelfAssessment *LinkNode `json:"nodeSelfAssessment" comment:"填写反馈自评"`  
54 -// NodeAllInvite *LinkNode `json:"nodeAllInvite" comment:"360°邀请"`  
55 -// NodeAllAssessment *LinkNode `json:"nodeAllAssessment" comment:"360°评估"`  
56 -// NodeSuperiorAssessment *LinkNode `json:"nodeSuperiorAssessment" comment:"上级评估"`  
57 -// NodeViewResult *LinkNode `json:"nodeViewResult" comment:"绩效结果查看"`  
58 -//} 52 +// NodeKpiResult 绩效结果查看
  53 +type NodeKpiResult struct {
  54 +}
  55 +
  56 +type LinkNode struct {
  57 + Type int `json:"type" comment:"环节类型(1评估、2邀请、3绩效结果)"`
  58 + Name string `json:"name" comment:"环节名称"`
  59 + Describe string `json:"describe" comment:"环节描述"`
  60 + NodeContents []NodeContent `json:"nodeContents" comment:"环节-评估内容"`
  61 + NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"环节-360°邀请"`
  62 + NodeKpiResult *NodeKpiResult `json:"nodeKpiResult" comment:"环节-绩效结果"`
  63 + TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
  64 + TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
  65 + KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
  66 +}
59 67
60 type EvaluationTemplate struct { 68 type EvaluationTemplate struct {
61 Id int64 `json:"id,string" comment:"ID"` 69 Id int64 `json:"id,string" comment:"ID"`
@@ -64,17 +72,24 @@ type EvaluationTemplate struct { @@ -64,17 +72,24 @@ type EvaluationTemplate struct {
64 CompanyId int64 `json:"companyId,string" comment:"公司ID"` 72 CompanyId int64 `json:"companyId,string" comment:"公司ID"`
65 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"` 73 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
66 State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3停用)"` 74 State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
67 - Link []LinkNode `json:"links" comment:"评估流程"` 75 + LinkNodes []LinkNode `json:"linkNodes" comment:"评估流程"`
68 CreatedAt time.Time `json:"createdAt" comment:"创建时间"` 76 CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
69 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` 77 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
70 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 78 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
71 - //Link EvaluationLink `json:"link" comment:"评估流程"`  
72 } 79 }
73 80
  81 +//type EvaluationLink struct {
  82 +// NodeSelfAssessment *LinkNode `json:"nodeSelfAssessment" comment:"填写反馈自评"`
  83 +// NodeAllInvite *LinkNode `json:"nodeAllInvite" comment:"360°邀请"`
  84 +// NodeAllAssessment *LinkNode `json:"nodeAllAssessment" comment:"360°评估"`
  85 +// NodeSuperiorAssessment *LinkNode `json:"nodeSuperiorAssessment" comment:"上级评估"`
  86 +// NodeViewResult *LinkNode `json:"nodeViewResult" comment:"绩效结果查看"`
  87 +//}
  88 +
74 type EvaluationTemplateRepository interface { 89 type EvaluationTemplateRepository interface {
75 Insert(template *EvaluationTemplate) (*EvaluationTemplate, error) 90 Insert(template *EvaluationTemplate) (*EvaluationTemplate, error)
76 Remove(template *EvaluationTemplate) (*EvaluationTemplate, error) 91 Remove(template *EvaluationTemplate) (*EvaluationTemplate, error)
77 FindOne(queryOptions map[string]interface{}) (*EvaluationTemplate, error) 92 FindOne(queryOptions map[string]interface{}) (*EvaluationTemplate, error)
78 - Find(queryOptions map[string]interface{}) (int64, []*EvaluationTemplate, error) 93 + Find(queryOptions map[string]interface{}, simplify bool) (int64, []*EvaluationTemplate, error)
79 Count(queryOptions map[string]interface{}) (int64, error) 94 Count(queryOptions map[string]interface{}) (int64, error)
80 } 95 }
@@ -13,7 +13,7 @@ type EvaluationTemplate struct { @@ -13,7 +13,7 @@ type EvaluationTemplate struct {
13 CompanyId int64 `comment:"公司ID"` 13 CompanyId int64 `comment:"公司ID"`
14 CreatorId int64 `comment:"创建人ID"` 14 CreatorId int64 `comment:"创建人ID"`
15 State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"` 15 State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
16 - Link []domain.LinkNode `comment:"评估流程"` 16 + LinkNodes []domain.LinkNode `comment:"评估流程"`
17 CreatedAt time.Time `comment:"创建时间"` 17 CreatedAt time.Time `comment:"创建时间"`
18 UpdatedAt time.Time `comment:"更新时间"` 18 UpdatedAt time.Time `comment:"更新时间"`
19 DeletedAt *time.Time `comment:"删除时间"` 19 DeletedAt *time.Time `comment:"删除时间"`
@@ -28,7 +28,7 @@ func (repo *EvaluationTemplateRepository) TransformToDomain(m *models.Evaluation @@ -28,7 +28,7 @@ func (repo *EvaluationTemplateRepository) TransformToDomain(m *models.Evaluation
28 CompanyId: m.CompanyId, 28 CompanyId: m.CompanyId,
29 CreatorId: m.CreatorId, 29 CreatorId: m.CreatorId,
30 State: m.State, 30 State: m.State,
31 - Link: m.Link, 31 + LinkNodes: m.LinkNodes,
32 CreatedAt: m.CreatedAt, 32 CreatedAt: m.CreatedAt,
33 UpdatedAt: m.UpdatedAt, 33 UpdatedAt: m.UpdatedAt,
34 DeletedAt: m.DeletedAt, 34 DeletedAt: m.DeletedAt,
@@ -43,7 +43,7 @@ func (repo *EvaluationTemplateRepository) TransformToModel(d *domain.EvaluationT @@ -43,7 +43,7 @@ func (repo *EvaluationTemplateRepository) TransformToModel(d *domain.EvaluationT
43 CompanyId: d.CompanyId, 43 CompanyId: d.CompanyId,
44 CreatorId: d.CreatorId, 44 CreatorId: d.CreatorId,
45 State: d.State, 45 State: d.State,
46 - Link: d.Link, 46 + LinkNodes: d.LinkNodes,
47 CreatedAt: d.CreatedAt, 47 CreatedAt: d.CreatedAt,
48 UpdatedAt: d.UpdatedAt, 48 UpdatedAt: d.UpdatedAt,
49 DeletedAt: d.DeletedAt, 49 DeletedAt: d.DeletedAt,
@@ -112,7 +112,7 @@ func (repo *EvaluationTemplateRepository) FindOne(queryOptions map[string]interf @@ -112,7 +112,7 @@ func (repo *EvaluationTemplateRepository) FindOne(queryOptions map[string]interf
112 return &u, nil 112 return &u, nil
113 } 113 }
114 114
115 -func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationTemplate, error) { 115 +func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}, simplify bool) (int64, []*domain.EvaluationTemplate, error) {
116 tx := repo.transactionContext.PgTx 116 tx := repo.transactionContext.PgTx
117 var m []*models.EvaluationTemplate 117 var m []*models.EvaluationTemplate
118 query := tx.Model(&m). 118 query := tx.Model(&m).
@@ -127,6 +127,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface @@ -127,6 +127,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
127 query.Where("company_id = ?", companyId) 127 query.Where("company_id = ?", companyId)
128 } 128 }
129 129
  130 + if state, ok := queryOptions["state"]; ok {
  131 + query.Where("state = ?", state)
  132 + }
  133 +
130 if v, ok := queryOptions["limit"].(int); ok { 134 if v, ok := queryOptions["limit"].(int); ok {
131 query.Limit(v) 135 query.Limit(v)
132 } 136 }
@@ -141,6 +145,9 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface @@ -141,6 +145,9 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
141 var arrays []*domain.EvaluationTemplate 145 var arrays []*domain.EvaluationTemplate
142 for _, v := range m { 146 for _, v := range m {
143 d := repo.TransformToDomain(v) 147 d := repo.TransformToDomain(v)
  148 + if simplify { // 去掉流程数据避免数据量过大
  149 + d.LinkNodes = make([]domain.LinkNode, 0)
  150 + }
144 arrays = append(arrays, &d) 151 arrays = append(arrays, &d)
145 } 152 }
146 return int64(count), arrays, nil 153 return int64(count), arrays, nil
@@ -168,6 +175,10 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac @@ -168,6 +175,10 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac
168 query.Where("company_id = ?", companyId) 175 query.Where("company_id = ?", companyId)
169 } 176 }
170 177
  178 + if state, ok := queryOptions["state"]; ok {
  179 + query.Where("state = ?", state)
  180 + }
  181 +
171 count, err := query.Count() 182 count, err := query.Count()
172 if err != nil { 183 if err != nil {
173 return 0, err 184 return 0, err
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/web/beego"
  6 + service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
  9 +)
  10 +
  11 +type RuleController struct {
  12 + beego.BaseController
  13 +}
  14 +
  15 +func (controller *RoleController) CreateRule() {
  16 + ruService := service.NewEvaluationRuleService()
  17 + in := &command.CreateRuleCommand{}
  18 + if err := controller.Unmarshal(in); err != nil {
  19 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  20 + } else {
  21 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  22 + in.CreatorId = middlewares.GetUserId(controller.Ctx)
  23 + controller.Response(ruService.Create(in))
  24 + }
  25 +}
  26 +
  27 +func (controller *RuleController) UpdateRule() {
  28 + ruService := service.NewEvaluationRuleService()
  29 + in := &command.UpdateRuleCommand{}
  30 + if err := controller.Unmarshal(in); err != nil {
  31 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  32 + } else {
  33 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  34 + in.CreatorId = middlewares.GetUserId(controller.Ctx)
  35 + controller.Response(ruService.Update(in))
  36 + }
  37 +}
  38 +
  39 +func (controller *RuleController) GetRule() {
  40 + ruService := service.NewEvaluationRuleService()
  41 + in := &command.GetRuleCommand{}
  42 + if id, err := controller.GetInt64(":Id"); err != nil {
  43 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  44 + } else {
  45 + in.Id = id
  46 + controller.Response(ruService.Get(in))
  47 + }
  48 +}
  49 +
  50 +func (controller *RuleController) RemoveRule() {
  51 + ruService := service.NewEvaluationRuleService()
  52 + in := &command.DeleteRuleCommand{}
  53 + if err := controller.Unmarshal(in); err != nil {
  54 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  55 + } else {
  56 + controller.Response(ruService.Remove(in))
  57 + }
  58 +}
  59 +
  60 +func (controller *RuleController) ListRule() {
  61 + ruService := service.NewEvaluationRuleService()
  62 + in := &command.QueryRuleCommand{}
  63 + if err := controller.Unmarshal(in); err != nil {
  64 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  65 + } else {
  66 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  67 + controller.Response(ruService.List(in))
  68 + }
  69 +}
  70 +
  71 +func (controller *RuleController) ListRuleRelCreator() {
  72 + ruService := service.NewEvaluationRuleService()
  73 + in := &command.QueryRuleCommand{}
  74 + if err := controller.Unmarshal(in); err != nil {
  75 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  76 + } else {
  77 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  78 + controller.Response(ruService.ListRelCreator(in))
  79 + }
  80 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/web/beego"
  6 + service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
  9 +)
  10 +
  11 +type TemplateController struct {
  12 + beego.BaseController
  13 +}
  14 +
  15 +func (controller *RoleController) CreateTemplate() {
  16 + ruService := service.NewEvaluationTemplateService()
  17 + in := &command.CreateTemplateCommand{}
  18 + if err := controller.Unmarshal(in); err != nil {
  19 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  20 + } else {
  21 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  22 + in.CreatorId = middlewares.GetUserId(controller.Ctx)
  23 + controller.Response(ruService.Create(in))
  24 + }
  25 +}
  26 +
  27 +func (controller *TemplateController) UpdateTemplate() {
  28 + ruService := service.NewEvaluationTemplateService()
  29 + in := &command.UpdateTemplateCommand{}
  30 + if err := controller.Unmarshal(in); err != nil {
  31 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  32 + } else {
  33 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  34 + in.CreatorId = middlewares.GetUserId(controller.Ctx)
  35 + controller.Response(ruService.Update(in))
  36 + }
  37 +}
  38 +
  39 +func (controller *TemplateController) GetTemplate() {
  40 + ruService := service.NewEvaluationTemplateService()
  41 + in := &command.GetTemplateCommand{}
  42 + if id, err := controller.GetInt64(":Id"); err != nil {
  43 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  44 + } else {
  45 + in.Id = id
  46 + controller.Response(ruService.Get(in))
  47 + }
  48 +}
  49 +
  50 +func (controller *TemplateController) RemoveTemplate() {
  51 + ruService := service.NewEvaluationTemplateService()
  52 + in := &command.DeleteTemplateCommand{}
  53 + if err := controller.Unmarshal(in); err != nil {
  54 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  55 + } else {
  56 + controller.Response(ruService.Remove(in))
  57 + }
  58 +}
  59 +
  60 +func (controller *TemplateController) ListTemplate() {
  61 + ruService := service.NewEvaluationTemplateService()
  62 + in := &command.QueryTemplateCommand{}
  63 + if err := controller.Unmarshal(in); err != nil {
  64 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  65 + } else {
  66 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  67 + controller.Response(ruService.List(in))
  68 + }
  69 +}
  70 +
  71 +func (controller *TemplateController) ListEnableTemplate() {
  72 + ruService := service.NewEvaluationTemplateService()
  73 + in := &command.AllEnableTemplateCommand{}
  74 + if err := controller.Unmarshal(in); err != nil {
  75 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  76 + } else {
  77 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  78 + controller.Response(ruService.ListForEnable(in))
  79 + }
  80 +}
  81 +
  82 +func (controller *TemplateController) StateTemplate() {
  83 + ruService := service.NewEvaluationTemplateService()
  84 + in := &command.StateTemplateCommand{}
  85 + if err := controller.Unmarshal(in); err != nil {
  86 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  87 + } else {
  88 + controller.Response(ruService.State(in))
  89 + }
  90 +}
  91 +
  92 +func (controller *TemplateController) CopyTemplate() {
  93 + ruService := service.NewEvaluationTemplateService()
  94 + in := &command.CopyTemplateCommand{}
  95 + if err := controller.Unmarshal(in); err != nil {
  96 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  97 + } else {
  98 + controller.Response(ruService.Copy(in))
  99 + }
  100 +}