作者 郑周

1. 增加权限字段

@@ -6,9 +6,11 @@ import ( @@ -6,9 +6,11 @@ import (
6 ) 6 )
7 7
8 type UpdatePermissionCommand struct { 8 type UpdatePermissionCommand struct {
9 - CompanyId int64 `cname:"公司Id"`  
10 - OptHrScore int `cname:"上级修改人资综评分数" json:"optHrScore" valid:"Required"`  
11 - OptEvalScore int `cname:"上级修改360°综评分数" json:"optEvalScore" valid:"Required"` 9 + CompanyId int64 `cname:"公司Id"`
  10 + OptHrScore int `cname:"上级修改人资综评分数" json:"optHrScore" valid:"Required"`
  11 + OptEvalScore int `cname:"上级修改360°综评分数" json:"optEvalScore" valid:"Required"`
  12 + OptConfirmPerf int `cname:"是否需要员工确认绩效" json:"optConfirmPerf"`
  13 + CycleDeadLine *domain.CycleDeadline `cname:"周期评估各业务截止时间" json:"cycleDeadline"`
12 } 14 }
13 15
14 func (in *UpdatePermissionCommand) Valid(validation *validation.Validation) { 16 func (in *UpdatePermissionCommand) Valid(validation *validation.Validation) {
@@ -64,10 +64,12 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm @@ -64,10 +64,12 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm
64 var permission *domain.Permission 64 var permission *domain.Permission
65 if len(permissions) == 0 { // 不存在时,新增权限配置 65 if len(permissions) == 0 { // 不存在时,新增权限配置
66 value := &domain.Permission{ 66 value := &domain.Permission{
67 - Id: 0,  
68 - CompanyId: in.CompanyId,  
69 - OptHrScore: domain.PermissionOff,  
70 - OptEvalScore: domain.PermissionOff, 67 + Id: 0,
  68 + CompanyId: in.CompanyId,
  69 + OptHrScore: domain.PermissionOff,
  70 + OptEvalScore: domain.PermissionOff,
  71 + OptConfirmPerf: domain.PermissionOff,
  72 + CycleDeadLine: rs.defaultCycleDeadline(),
71 } 73 }
72 permission, err = permissionRepository.Insert(value) 74 permission, err = permissionRepository.Insert(value)
73 if err != nil { 75 if err != nil {
@@ -75,9 +77,59 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm @@ -75,9 +77,59 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm
75 } 77 }
76 } else { 78 } else {
77 permission = permissions[0] 79 permission = permissions[0]
  80 + // 纠正数据
  81 + var isChange = false
  82 + if permission.OptHrScore == 0 {
  83 + isChange = true
  84 + permission.OptHrScore = domain.PermissionOff
  85 + }
  86 + if permission.OptEvalScore == 0 {
  87 + isChange = true
  88 + permission.OptEvalScore = domain.PermissionOff
  89 + }
  90 + if permission.OptConfirmPerf == 0 {
  91 + isChange = true
  92 + permission.OptConfirmPerf = domain.PermissionOff
  93 + }
  94 + if permission.CycleDeadLine == nil {
  95 + isChange = true
  96 + permission.CycleDeadLine = rs.defaultCycleDeadline()
  97 + }
  98 + if isChange {
  99 + permission, err = permissionRepository.Insert(permission)
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  102 + }
  103 + }
78 } 104 }
79 if err := transactionContext.CommitTransaction(); err != nil { 105 if err := transactionContext.CommitTransaction(); err != nil {
80 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 106 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
81 } 107 }
82 return permission, nil 108 return permission, nil
83 } 109 }
  110 +
  111 +// 创建默认周期截止时间
  112 +func (rs *PermissionService) defaultCycleDeadline() *domain.CycleDeadline {
  113 + return &domain.CycleDeadline{
  114 + AssessmentSelf: domain.DeadlineTime{
  115 + Hour: 3 * 24,
  116 + Minute: 0,
  117 + },
  118 + AssessmentAll: domain.DeadlineTime{
  119 + Hour: 5 * 24,
  120 + Minute: 0,
  121 + },
  122 + AssessmentHr: domain.DeadlineTime{
  123 + Hour: 5 * 24,
  124 + Minute: 0,
  125 + },
  126 + AssessmentSuperior: domain.DeadlineTime{
  127 + Hour: 7 * 24,
  128 + Minute: 0,
  129 + },
  130 + ViewMyPerf: domain.DeadlineTime{
  131 + Hour: 9 * 24,
  132 + Minute: 0,
  133 + },
  134 + }
  135 +}
@@ -8,13 +8,29 @@ const ( @@ -8,13 +8,29 @@ const (
8 ) 8 )
9 9
10 type Permission struct { 10 type Permission struct {
11 - Id int64 `json:"id,string"`  
12 - CompanyId int64 `json:"companyId" comment:"公司ID" `  
13 - OptHrScore int `json:"optHrScore" comment:"上级是否可以修改人资综评分数"`  
14 - OptEvalScore int `json:"optEvalScore" comment:"上级是否可以修改360°综评分数"`  
15 - CreatedAt time.Time `json:"createdAt" comment:"创建时间"`  
16 - UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`  
17 - DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 11 + Id int64 `json:"id,string"`
  12 + CompanyId int64 `json:"companyId" comment:"公司ID" `
  13 + OptHrScore int `json:"optHrScore" comment:"上级是否可以修改人资综评分数"`
  14 + OptEvalScore int `json:"optEvalScore" comment:"上级是否可以修改360°综评分数"`
  15 + OptConfirmPerf int `json:"optConfirmPerf " comment:"是否需要员工确认绩效"`
  16 + CycleDeadLine *CycleDeadline `json:"cycleDeadline" comment:"周期评估各业务截止时间"`
  17 + CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
  18 + UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
  19 + DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
  20 +}
  21 +
  22 +// CycleDeadline 周期评估截止时间
  23 +type CycleDeadline struct {
  24 + AssessmentSelf DeadlineTime `json:"assessmentSelf" comment:"综合自评"`
  25 + AssessmentAll DeadlineTime `json:"assessmentAll" comment:"360评估"`
  26 + AssessmentHr DeadlineTime `json:"assessmentHr" comment:"人资评估"`
  27 + AssessmentSuperior DeadlineTime `json:"assessmentSuperior" comment:"上级评估"`
  28 + ViewMyPerf DeadlineTime `json:"viewMyPerf" comment:"查看我的绩效"`
  29 +}
  30 +
  31 +type DeadlineTime struct {
  32 + Hour int `json:"hour" comment:"时"`
  33 + Minute int `json:"minute" comment:"分"`
18 } 34 }
19 35
20 type PermissionRepository interface { 36 type PermissionRepository interface {
1 package models 1 package models
2 2
3 -import "time" 3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  5 + "time"
  6 +)
4 7
5 type Permission struct { 8 type Permission struct {
6 - tableName struct{} `comment:"配置权限" pg:"permission"`  
7 - Id int64 `comment:"ID" pg:"pk:id"`  
8 - CompanyId int64 `comment:"公司ID"`  
9 - OptHrScore int `comment:"上级是否可以修改人资综评分数"`  
10 - OptEvalScore int `comment:"上级是否可以修改360°综评分数"`  
11 - CreatedAt time.Time `comment:"创建时间"`  
12 - UpdatedAt time.Time `comment:"更新时间"`  
13 - DeletedAt *time.Time `comment:"删除时间"` 9 + tableName struct{} `comment:"配置权限" pg:"permission"`
  10 + Id int64 `comment:"ID" pg:"pk:id"`
  11 + CompanyId int64 `comment:"公司ID"`
  12 + OptHrScore int `comment:"上级是否可以修改人资综评分数"`
  13 + OptEvalScore int `comment:"上级是否可以修改360°综评分数"`
  14 + OptConfirmPerf int `comment:"是否需要员工确认绩效"`
  15 + CycleDeadLine *domain.CycleDeadline `comment:"周期评估各业务截止时间"`
  16 + CreatedAt time.Time `comment:"创建时间"`
  17 + UpdatedAt time.Time `comment:"更新时间"`
  18 + DeletedAt *time.Time `comment:"删除时间"`
14 } 19 }
@@ -22,25 +22,29 @@ func NewPermissionRepository(transactionContext *pgTransaction.TransactionContex @@ -22,25 +22,29 @@ func NewPermissionRepository(transactionContext *pgTransaction.TransactionContex
22 22
23 func (repo *PermissionRepository) TransformToDomain(m *models.Permission) domain.Permission { 23 func (repo *PermissionRepository) TransformToDomain(m *models.Permission) domain.Permission {
24 return domain.Permission{ 24 return domain.Permission{
25 - Id: m.Id,  
26 - CompanyId: m.CompanyId,  
27 - OptHrScore: m.OptHrScore,  
28 - OptEvalScore: m.OptEvalScore,  
29 - CreatedAt: m.CreatedAt.Local(),  
30 - UpdatedAt: m.UpdatedAt.Local(),  
31 - DeletedAt: m.DeletedAt, 25 + Id: m.Id,
  26 + CompanyId: m.CompanyId,
  27 + OptHrScore: m.OptHrScore,
  28 + OptEvalScore: m.OptEvalScore,
  29 + OptConfirmPerf: m.OptConfirmPerf,
  30 + CycleDeadLine: m.CycleDeadLine,
  31 + CreatedAt: m.CreatedAt.Local(),
  32 + UpdatedAt: m.UpdatedAt.Local(),
  33 + DeletedAt: m.DeletedAt,
32 } 34 }
33 } 35 }
34 36
35 func (repo *PermissionRepository) TransformToModel(d *domain.Permission) models.Permission { 37 func (repo *PermissionRepository) TransformToModel(d *domain.Permission) models.Permission {
36 return models.Permission{ 38 return models.Permission{
37 - Id: d.Id,  
38 - CompanyId: d.CompanyId,  
39 - OptHrScore: d.OptHrScore,  
40 - OptEvalScore: d.OptEvalScore,  
41 - CreatedAt: d.CreatedAt,  
42 - UpdatedAt: d.UpdatedAt,  
43 - DeletedAt: d.DeletedAt, 39 + Id: d.Id,
  40 + CompanyId: d.CompanyId,
  41 + OptHrScore: d.OptHrScore,
  42 + OptEvalScore: d.OptEvalScore,
  43 + OptConfirmPerf: d.OptConfirmPerf,
  44 + CycleDeadLine: d.CycleDeadLine,
  45 + CreatedAt: d.CreatedAt,
  46 + UpdatedAt: d.UpdatedAt,
  47 + DeletedAt: d.DeletedAt,
44 } 48 }
45 } 49 }
46 50
  1 +-- 权限表建新列
  2 +ALTER TABLE public."permission" ADD opt_confirm_perf int8 NULL DEFAULT 1;
  3 +COMMENT ON COLUMN public."permission".opt_confirm_perf IS '是否需要员工确认绩效';
  4 +
  5 +ALTER TABLE public."permission" ADD cycle_deadline jsonb NULL;
  6 +COMMENT ON COLUMN public."permission".cycle_deadline IS '周期评估各业务截止时间';
  7 +