作者 tangxvhui

优化编辑周期综合评估,加锁

... ... @@ -490,7 +490,14 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
// 编辑综合自评详情
func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -1091,6 +1098,14 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
// EditEvaluationSuper 更新上级评估内容
func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -14,6 +14,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
)
// Evaluation360List 获取360综评列表
... ... @@ -337,6 +338,14 @@ func (srv *SummaryEvaluationService) GetEvaluation360Complete(param *command.Que
// EditEvaluation360 编辑提交360综评
func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -704,6 +713,14 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
// EditEvaluationHRBP 编辑提交人资综评
func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
package domain
import "time"
// 任务
type Task struct {
Id int
Name string
StageList []TaskStage
}
// 任务阶段
type TaskStage struct {
Id int
Name string
PlanCompleteAt time.Time
}
... ...
package domain
... ...
... ... @@ -11,7 +11,7 @@ type LockSummaryEvaluation struct {
}
func NewLockSummaryEvaluation(targetUserId int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation:%d", targetUserId)
key := fmt.Sprintf("performance:summary_evaluation_targetuser:%d", targetUserId)
return &LockSummaryEvaluation{
m: rsync.NewMutex(key),
... ... @@ -25,3 +25,22 @@ func (lk *LockSummaryEvaluation) Lock() error {
func (lk *LockSummaryEvaluation) UnLock() (bool, error) {
return lk.m.Unlock()
}
type LockSummaryEvaluationId struct {
m *redsync.Mutex
}
func NewLockSummaryEvaluationId(summaryEvaluationId int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation_id:%d", summaryEvaluationId)
return &LockSummaryEvaluation{
m: rsync.NewMutex(key),
}
}
func (lk *LockSummaryEvaluationId) Lock() error {
return lk.m.Lock()
}
func (lk *LockSummaryEvaluationId) UnLock() (bool, error) {
return lk.m.Unlock()
}
... ...
-- 清理重复的数
DELETE FROM summary_evaluation_value
WHERE id IN (1720, 1721, 1708, 1723, 1724, 1711, 1712, 1727, 1728, 1715, 1730, 1717, 1732, 1719);
DELETE FROM summary_evaluation_value
WHERE id IN (2299, 2302, 2303, 2304, 2309, 2308, 2313, 2312, 2314, 2316, 2318, 2322, 2324, 2325);
... ...