作者 郑周

1.周期模型 重构

  1 +package command
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 + "time"
  6 +)
  7 +
  8 +type CreateCycleCommand struct {
  9 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  10 + CreatorId int64 `cname:"创建人ID" json:"creatorId"`
  11 + Name string `cname:"周期名称" json:"name" valid:"Required"`
  12 + TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
  13 + TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
  14 + KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
  15 + TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
  16 +}
  17 +
  18 +func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
  19 + if in.CompanyId == 0 {
  20 + validation.SetError("companyId", "公司ID无效")
  21 + return
  22 + }
  23 + if in.CreatorId == 0 {
  24 + validation.SetError("creatorId", "创建人ID无效")
  25 + return
  26 + }
  27 + if len(in.Name) > 40 {
  28 + validation.SetError("name", "角色名称最大长度40个字符")
  29 + return
  30 + }
  31 + if in.TimeStart == nil {
  32 + validation.SetError("timeStart", "请选择考核周期的开始时间")
  33 + return
  34 + }
  35 + if in.TimeEnd == nil {
  36 + validation.SetError("timeEnd", "请选择考核周期的结束时间")
  37 + return
  38 + }
  39 + if len(in.TemplateIds) == 0 {
  40 + validation.SetError("templates", "请选择周期内使用的评估模板")
  41 + return
  42 + }
  43 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type DeleteCycleCommand struct {
  6 + Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
  7 +}
  8 +
  9 +func (in *DeleteCycleCommand) Valid(*validation.Validation) {
  10 +
  11 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type GetCycleCommand struct {
  6 + Id int64 `cname:"周期Id" json:"id,string" valid:"Required"`
  7 +}
  8 +
  9 +func (in *GetCycleCommand) Valid(*validation.Validation) {
  10 +
  11 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +type QueryCycleCommand 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 *QueryCycleCommand) Valid(validation *validation.Validation) {
  12 + if in.CompanyId == 0 {
  13 + validation.SetError("companyId", "公司ID无效")
  14 + return
  15 + }
  16 +}
  1 +package command
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 + "time"
  6 +)
  7 +
  8 +type UpdateCycleCommand struct {
  9 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  10 + Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
  11 + Name string `cname:"周期名称" json:"name" valid:"Required"`
  12 + TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
  13 + TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
  14 + KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
  15 + TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
  16 +}
  17 +
  18 +func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
  19 + if len(in.Name) > 40 {
  20 + validation.SetError("name", "角色名称最大长度40个字符")
  21 + return
  22 + }
  23 + if in.TimeStart == nil {
  24 + validation.SetError("timeStart", "请选择考核周期的开始时间")
  25 + return
  26 + }
  27 + if in.TimeEnd == nil {
  28 + validation.SetError("timeEnd", "请选择考核周期的结束时间")
  29 + return
  30 + }
  31 + if len(in.TemplateIds) == 0 {
  32 + validation.SetError("templates", "请选择周期内使用的评估模板")
  33 + return
  34 + }
  35 +}
  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_cycle/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 EvaluationCycleService struct {
  13 +}
  14 +
  15 +func NewEvaluationCycleService() *EvaluationCycleService {
  16 + newRoleService := &EvaluationCycleService{}
  17 + return newRoleService
  18 +}
  19 +
  20 +// Create 创建
  21 +func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (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 + cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  30 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  31 +
  32 + // 检测名称重复
  33 + count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
  34 + if err != nil {
  35 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  36 + }
  37 + if count > 0 {
  38 + return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
  39 + }
  40 +
  41 + _, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds})
  42 + if err != nil {
  43 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  44 + }
  45 + if len(templates) == 0 {
  46 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
  47 + }
  48 +
  49 + newCycle := &domain.EvaluationCycle{
  50 + Id: 0,
  51 + Name: in.Name,
  52 + TimeStart: in.TimeStart,
  53 + TimeEnd: in.TimeEnd,
  54 + CompanyId: in.CompanyId,
  55 + CreatorId: in.CreatorId,
  56 + KpiCycle: in.KpiCycle,
  57 + Templates: templates,
  58 + }
  59 + rule, err := cycleRepository.Insert(newCycle)
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  62 + }
  63 + if err := transactionContext.CommitTransaction(); err != nil {
  64 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  65 + }
  66 + return rule, nil
  67 +
  68 +}
  69 +
  70 +func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interface{}, error) {
  71 + transactionContext, err := factory.ValidateStartTransaction(in)
  72 + if err != nil {
  73 + return nil, err
  74 + }
  75 + defer func() {
  76 + transactionContext.RollbackTransaction()
  77 + }()
  78 +
  79 + cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  80 + templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  81 +
  82 + // 检测名称重复(排除自己)
  83 + count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
  84 + if err != nil {
  85 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  86 + }
  87 + if count > 0 {
  88 + return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
  89 + }
  90 +
  91 + cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
  92 + if err != nil {
  93 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  94 + }
  95 +
  96 + _, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds})
  97 + if err != nil {
  98 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  99 + }
  100 + if len(templates) == 0 {
  101 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
  102 + }
  103 + cycle.Name = in.Name
  104 + cycle.TimeStart = in.TimeStart
  105 + cycle.TimeEnd = in.TimeEnd
  106 + cycle.KpiCycle = in.KpiCycle
  107 + cycle.Templates = templates
  108 +
  109 + cycle, err = cycleRepository.Insert(cycle)
  110 + if err != nil {
  111 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  112 + }
  113 + if err := transactionContext.CommitTransaction(); err != nil {
  114 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  115 + }
  116 + return cycle, nil
  117 +}
  118 +
  119 +func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) {
  120 + // Get 不需要事务
  121 + if err := utils.ValidateCommand(in); err != nil {
  122 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  123 + }
  124 + transactionContext, err := factory.CreateTransactionContext(nil)
  125 + if err != nil {
  126 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  127 + }
  128 + cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  129 + cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
  130 + if err != nil {
  131 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  132 + }
  133 + return cycle, nil
  134 +}
  135 +
  136 +func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interface{}, error) {
  137 + transactionContext, err := factory.ValidateStartTransaction(in)
  138 + if err != nil {
  139 + return nil, err
  140 + }
  141 + defer func() {
  142 + transactionContext.RollbackTransaction()
  143 + }()
  144 +
  145 + cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  146 +
  147 + cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
  148 + if err != nil {
  149 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  150 + }
  151 + if _, err := cycleRepository.Remove(cycle); err != nil {
  152 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  153 + }
  154 +
  155 + if err := transactionContext.CommitTransaction(); err != nil {
  156 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  157 + }
  158 + return cycle, nil
  159 +}
  160 +
  161 +func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface{}, error) {
  162 + transactionContext, err := factory.StartTransaction()
  163 + if err != nil {
  164 + return nil, err
  165 + }
  166 + defer func() {
  167 + transactionContext.RollbackTransaction()
  168 + }()
  169 + cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  170 + // FIXME 总数量是否使用Count获取一个总数量
  171 + count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in), "templates")
  172 + if err != nil {
  173 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  174 + }
  175 + return tool_funs.SimpleWrapGridMap(count, cycles), nil
  176 +}
@@ -4,6 +4,7 @@ import "github.com/beego/beego/v2/core/validation" @@ -4,6 +4,7 @@ import "github.com/beego/beego/v2/core/validation"
4 4
5 type QueryRuleCommand struct { 5 type QueryRuleCommand struct {
6 CompanyId int64 `cname:"公司ID" json:"companyId"` 6 CompanyId int64 `cname:"公司ID" json:"companyId"`
  7 + NameOrRemark string `cname:"规则名称或备注" json:"nameOrRemark"`
7 PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"` 8 PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
8 PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"` 9 PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
9 } 10 }
@@ -150,8 +150,12 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{} @@ -150,8 +150,12 @@ func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}
150 transactionContext.RollbackTransaction() 150 transactionContext.RollbackTransaction()
151 }() 151 }()
152 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) 152 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
  153 + inMap := tool_funs.SimpleStructToMap(in)
  154 + if len(in.NameOrRemark) > 0 {
  155 + inMap["nameOrRemark"] = "%" + in.NameOrRemark + "%"
  156 + }
153 // FIXME 总数量是否使用Count获取一个总数量 157 // FIXME 总数量是否使用Count获取一个总数量
154 - count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in)) 158 + count, rules, err := ruleRepository.Find(inMap)
155 if err != nil { 159 if err != nil {
156 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 160 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
157 } 161 }
@@ -4,6 +4,7 @@ import "github.com/beego/beego/v2/core/validation" @@ -4,6 +4,7 @@ import "github.com/beego/beego/v2/core/validation"
4 4
5 type QueryTemplateCommand struct { 5 type QueryTemplateCommand struct {
6 CompanyId int64 `cname:"公司ID" json:"companyId"` 6 CompanyId int64 `cname:"公司ID" json:"companyId"`
  7 + Name string `cname:"模板名称" json:"name"`
7 PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"` 8 PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
8 PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"` 9 PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
9 } 10 }
@@ -11,7 +11,7 @@ type UpdateTemplateCommand struct { @@ -11,7 +11,7 @@ type UpdateTemplateCommand struct {
11 CreatorId int64 `cname:"创建人ID" json:"creatorId"` 11 CreatorId int64 `cname:"创建人ID" json:"creatorId"`
12 Name string `cname:"模板名称" json:"name" valid:"Required"` 12 Name string `cname:"模板名称" json:"name" valid:"Required"`
13 Describe string `cname:"模板描述" json:"remark"` 13 Describe string `cname:"模板描述" json:"remark"`
14 - LinkNodes []domain.LinkNode `cname:"评估流程" json:"linkNodes"` 14 + LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
15 } 15 }
16 16
17 func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) { 17 func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
@@ -37,28 +37,28 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) ( @@ -37,28 +37,28 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
37 return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在") 37 return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
38 } 38 }
39 39
40 - linkNodes := make([]domain.LinkNode, 0)  
41 - linkNodes = append(linkNodes, domain.LinkNode{ 40 + linkNodes := make([]*domain.LinkNode, 0)
  41 + linkNodes = append(linkNodes, &domain.LinkNode{
42 Type: domain.LinkNodeAssessment, 42 Type: domain.LinkNodeAssessment,
43 Name: "填写自评反馈", 43 Name: "填写自评反馈",
44 KpiCycle: domain.KpiCycleDay, 44 KpiCycle: domain.KpiCycleDay,
45 }) 45 })
46 - linkNodes = append(linkNodes, domain.LinkNode{ 46 + linkNodes = append(linkNodes, &domain.LinkNode{
47 Type: domain.LinkNodeAllInvite, 47 Type: domain.LinkNodeAllInvite,
48 Name: "360°邀请", 48 Name: "360°邀请",
49 KpiCycle: domain.KpiCycleDay, 49 KpiCycle: domain.KpiCycleDay,
50 }) 50 })
51 - linkNodes = append(linkNodes, domain.LinkNode{ 51 + linkNodes = append(linkNodes, &domain.LinkNode{
52 Type: domain.LinkNodeAssessment, 52 Type: domain.LinkNodeAssessment,
53 Name: "360°评估", 53 Name: "360°评估",
54 KpiCycle: domain.KpiCycleDay, 54 KpiCycle: domain.KpiCycleDay,
55 }) 55 })
56 - linkNodes = append(linkNodes, domain.LinkNode{ 56 + linkNodes = append(linkNodes, &domain.LinkNode{
57 Type: domain.LinkNodeAssessment, 57 Type: domain.LinkNodeAssessment,
58 Name: "上级评估", 58 Name: "上级评估",
59 KpiCycle: domain.KpiCycleDay, 59 KpiCycle: domain.KpiCycleDay,
60 }) 60 })
61 - linkNodes = append(linkNodes, domain.LinkNode{ 61 + linkNodes = append(linkNodes, &domain.LinkNode{
62 Type: domain.LinkNodeViewResult, 62 Type: domain.LinkNodeViewResult,
63 Name: "绩效结果查看", 63 Name: "绩效结果查看",
64 KpiCycle: domain.KpiCycleDay, 64 KpiCycle: domain.KpiCycleDay,
@@ -174,8 +174,13 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int @@ -174,8 +174,13 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
174 transactionContext.RollbackTransaction() 174 transactionContext.RollbackTransaction()
175 }() 175 }()
176 templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) 176 templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
  177 +
  178 + inMap := tool_funs.SimpleStructToMap(in)
  179 + if len(in.Name) > 0 {
  180 + inMap["name"] = "%" + in.Name + "%"
  181 + }
177 // FIXME 总数量是否使用Count获取一个总数量 182 // FIXME 总数量是否使用Count获取一个总数量
178 - count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), true) 183 + count, templates, err := templateRepository.Find(inMap, "linkNodes")
179 if err != nil { 184 if err != nil {
180 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 185 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
181 } 186 }
@@ -197,7 +202,7 @@ func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplate @@ -197,7 +202,7 @@ func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplate
197 "state": domain.TemplateStateEnable, 202 "state": domain.TemplateStateEnable,
198 "offset": 0, 203 "offset": 0,
199 "limit": 9999999, 204 "limit": 9999999,
200 - }, true) 205 + }, "linkNodes")
201 if err != nil { 206 if err != nil {
202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 207 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
203 } 208 }
@@ -12,7 +12,7 @@ type EvaluationCycle struct { @@ -12,7 +12,7 @@ type EvaluationCycle struct {
12 CompanyId int64 `json:"companyId,string" comment:"公司ID"` 12 CompanyId int64 `json:"companyId,string" comment:"公司ID"`
13 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"` 13 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
14 KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"` 14 KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
15 - Template []EvaluationTemplate `json:"template" comment:"周期使用模板"` 15 + Templates []*EvaluationTemplate `json:"templates" comment:"周期使用模板"`
16 CreatedAt time.Time `json:"createdAt" comment:"创建时间"` 16 CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
17 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` 17 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
18 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 18 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
@@ -22,6 +22,6 @@ type EvaluationCycleRepository interface { @@ -22,6 +22,6 @@ type EvaluationCycleRepository interface {
22 Insert(cycle *EvaluationCycle) (*EvaluationCycle, error) 22 Insert(cycle *EvaluationCycle) (*EvaluationCycle, error)
23 Remove(cycle *EvaluationCycle) (*EvaluationCycle, error) 23 Remove(cycle *EvaluationCycle) (*EvaluationCycle, error)
24 FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error) 24 FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error)
25 - Find(queryOptions map[string]interface{}) (int64, []*EvaluationCycle, error) 25 + Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*EvaluationCycle, error)
26 Count(queryOptions map[string]interface{}) (int64, error) 26 Count(queryOptions map[string]interface{}) (int64, error)
27 } 27 }
@@ -10,7 +10,7 @@ const ( @@ -10,7 +10,7 @@ const (
10 ) 10 )
11 11
12 type Rating struct { 12 type Rating struct {
13 - Levels []RatingLevel `json:"levels" comment:"配置等级"` 13 + Levels []*RatingLevel `json:"levels" comment:"配置等级"`
14 } 14 }
15 15
16 type RatingLevel struct { 16 type RatingLevel struct {
@@ -25,7 +25,7 @@ type Score struct { @@ -25,7 +25,7 @@ type Score struct {
25 Max float64 `json:"max" comment:"评分上限"` 25 Max float64 `json:"max" comment:"评分上限"`
26 IntervalState int `json:"intervalState" comment:"按分数子区间匹配等级(0关闭、1开启)"` 26 IntervalState int `json:"intervalState" comment:"按分数子区间匹配等级(0关闭、1开启)"`
27 DecimalPlaces int `json:"decimalPlaces" comment:"保留小数点(0不保留、1保留一位、以此类推)"` 27 DecimalPlaces int `json:"decimalPlaces" comment:"保留小数点(0不保留、1保留一位、以此类推)"`
28 - Levels []ScoreLevel `json:"levels" comment:"配置等级区间"` 28 + Levels []*ScoreLevel `json:"levels" comment:"配置等级区间"`
29 } 29 }
30 30
31 type ScoreLevel struct { 31 type ScoreLevel struct {
@@ -72,7 +72,7 @@ type EvaluationTemplate struct { @@ -72,7 +72,7 @@ type EvaluationTemplate struct {
72 CompanyId int64 `json:"companyId,string" comment:"公司ID"` 72 CompanyId int64 `json:"companyId,string" comment:"公司ID"`
73 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"` 73 CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
74 State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3停用)"` 74 State int `json:"state" comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
75 - LinkNodes []LinkNode `json:"linkNodes" comment:"评估流程"` 75 + LinkNodes []*LinkNode `json:"linkNodes" comment:"评估流程"`
76 CreatedAt time.Time `json:"createdAt" comment:"创建时间"` 76 CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
77 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` 77 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
78 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 78 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
@@ -90,6 +90,6 @@ type EvaluationTemplateRepository interface { @@ -90,6 +90,6 @@ type EvaluationTemplateRepository interface {
90 Insert(template *EvaluationTemplate) (*EvaluationTemplate, error) 90 Insert(template *EvaluationTemplate) (*EvaluationTemplate, error)
91 Remove(template *EvaluationTemplate) (*EvaluationTemplate, error) 91 Remove(template *EvaluationTemplate) (*EvaluationTemplate, error)
92 FindOne(queryOptions map[string]interface{}) (*EvaluationTemplate, error) 92 FindOne(queryOptions map[string]interface{}) (*EvaluationTemplate, error)
93 - Find(queryOptions map[string]interface{}, simplify bool) (int64, []*EvaluationTemplate, error) 93 + Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*EvaluationTemplate, error)
94 Count(queryOptions map[string]interface{}) (int64, error) 94 Count(queryOptions map[string]interface{}) (int64, error)
95 } 95 }
@@ -14,7 +14,7 @@ type EvaluationCycle struct { @@ -14,7 +14,7 @@ type EvaluationCycle struct {
14 CompanyId int64 `comment:"公司ID"` 14 CompanyId int64 `comment:"公司ID"`
15 CreatorId int64 `comment:"创建人ID"` 15 CreatorId int64 `comment:"创建人ID"`
16 KpiCycle int `comment:"考核周期(0日、1周、2月)"` 16 KpiCycle int `comment:"考核周期(0日、1周、2月)"`
17 - Template []domain.EvaluationTemplate `comment:"周期使用模板"` 17 + Templates []*domain.EvaluationTemplate `comment:"周期使用模板"`
18 CreatedAt time.Time `comment:"创建时间"` 18 CreatedAt time.Time `comment:"创建时间"`
19 UpdatedAt time.Time `comment:"更新时间"` 19 UpdatedAt time.Time `comment:"更新时间"`
20 DeletedAt *time.Time `comment:"删除时间"` 20 DeletedAt *time.Time `comment:"删除时间"`
@@ -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 - LinkNodes []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:"删除时间"`
@@ -29,7 +29,7 @@ func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCyc @@ -29,7 +29,7 @@ func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCyc
29 CompanyId: m.CompanyId, 29 CompanyId: m.CompanyId,
30 CreatorId: m.CreatorId, 30 CreatorId: m.CreatorId,
31 KpiCycle: m.KpiCycle, 31 KpiCycle: m.KpiCycle,
32 - Template: m.Template, 32 + Templates: m.Templates,
33 CreatedAt: m.CreatedAt, 33 CreatedAt: m.CreatedAt,
34 UpdatedAt: m.UpdatedAt, 34 UpdatedAt: m.UpdatedAt,
35 DeletedAt: m.DeletedAt, 35 DeletedAt: m.DeletedAt,
@@ -45,7 +45,7 @@ func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycl @@ -45,7 +45,7 @@ func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycl
45 CompanyId: d.CompanyId, 45 CompanyId: d.CompanyId,
46 CreatorId: d.CreatorId, 46 CreatorId: d.CreatorId,
47 KpiCycle: d.KpiCycle, 47 KpiCycle: d.KpiCycle,
48 - Template: d.Template, 48 + Templates: d.Templates,
49 CreatedAt: d.CreatedAt, 49 CreatedAt: d.CreatedAt,
50 UpdatedAt: d.UpdatedAt, 50 UpdatedAt: d.UpdatedAt,
51 DeletedAt: d.DeletedAt, 51 DeletedAt: d.DeletedAt,
@@ -114,12 +114,16 @@ func (repo *EvaluationCycleRepository) FindOne(queryOptions map[string]interface @@ -114,12 +114,16 @@ func (repo *EvaluationCycleRepository) FindOne(queryOptions map[string]interface
114 return &u, nil 114 return &u, nil
115 } 115 }
116 116
117 -func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationCycle, error) { 117 +func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*domain.EvaluationCycle, error) {
118 tx := repo.transactionContext.PgTx 118 tx := repo.transactionContext.PgTx
119 var m []*models.EvaluationCycle 119 var m []*models.EvaluationCycle
120 - query := tx.Model(&m).  
121 - Where("deleted_at isnull").  
122 - Limit(20) 120 +
  121 + // 排除掉保存模板的列[templates], 减少数据赋值
  122 + query := tx.Model(&m).Where("deleted_at isnull").Limit(20)
  123 +
  124 + if len(excludeColumns) > 0 {
  125 + query.ExcludeColumn(excludeColumns...)
  126 + }
123 127
124 if name, ok := queryOptions["name"]; ok { 128 if name, ok := queryOptions["name"]; ok {
125 query.Where("name = ?", name) 129 query.Where("name = ?", name)
@@ -119,6 +119,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{}) @@ -119,6 +119,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
119 var m []*models.EvaluationRule 119 var m []*models.EvaluationRule
120 query := tx.Model(&m).Where("deleted_at isnull").Limit(20) 120 query := tx.Model(&m).Where("deleted_at isnull").Limit(20)
121 121
  122 + if nameOrRemark, ok := queryOptions["nameOrRemark"]; ok && len(nameOrRemark.(string)) > 0 {
  123 + query.Where("name LIKE ? or remark LIKE ?", nameOrRemark, nameOrRemark)
  124 + }
  125 +
122 if name, ok := queryOptions["name"]; ok { 126 if name, ok := queryOptions["name"]; ok {
123 query.Where("name = ?", name) 127 query.Where("name = ?", name)
124 } 128 }
@@ -112,15 +112,23 @@ func (repo *EvaluationTemplateRepository) FindOne(queryOptions map[string]interf @@ -112,15 +112,23 @@ 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{}, simplify bool) (int64, []*domain.EvaluationTemplate, error) { 115 +func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (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).
119 Where("deleted_at isnull"). 119 Where("deleted_at isnull").
120 Limit(20) 120 Limit(20)
121 121
122 - if name, ok := queryOptions["name"]; ok {  
123 - query.Where("name = ?", name) 122 + if len(excludeColumns) > 0 {
  123 + query.ExcludeColumn(excludeColumns...)
  124 + }
  125 +
  126 + if v, ok := queryOptions["ids"]; ok {
  127 + query.Where("id in(?)", pg.In(v))
  128 + }
  129 +
  130 + if name, ok := queryOptions["name"]; ok && len(name.(string)) > 0 {
  131 + query.Where("name LIKE ?", name)
124 } 132 }
125 133
126 if companyId, ok := queryOptions["companyId"]; ok { 134 if companyId, ok := queryOptions["companyId"]; ok {
@@ -145,9 +153,6 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface @@ -145,9 +153,6 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
145 var arrays []*domain.EvaluationTemplate 153 var arrays []*domain.EvaluationTemplate
146 for _, v := range m { 154 for _, v := range m {
147 d := repo.TransformToDomain(v) 155 d := repo.TransformToDomain(v)
148 - if simplify { // 去掉流程数据避免数据量过大  
149 - d.LinkNodes = make([]domain.LinkNode, 0)  
150 - }  
151 arrays = append(arrays, &d) 156 arrays = append(arrays, &d)
152 } 157 }
153 return int64(count), arrays, nil 158 return int64(count), arrays, nil