作者 tangxvhui

编辑加锁

... ... @@ -17,6 +17,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
... ... @@ -1008,6 +1009,14 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T
// 提交评估数据
func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
lock := xredis.NewLockStaffAssess(param.AssessId)
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())
... ... @@ -1135,6 +1144,14 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
// SaveSelfAssess 提交自评评估内容
func (srv StaffAssessServeice) SaveSelfAssess(in *command.SaveSelfAssessCommand) (map[string]interface{}, error) {
lock := xredis.NewLockStaffAssess(in.AssessId)
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ...
... ... @@ -44,3 +44,22 @@ func (lk *LockSummaryEvaluationId) Lock() error {
func (lk *LockSummaryEvaluationId) UnLock() (bool, error) {
return lk.m.Unlock()
}
type LockStaffAssess struct {
m *redsync.Mutex
}
func NewLockStaffAssess(staffAssessId int) *LockStaffAssess {
key := fmt.Sprintf("performance:staff_assess_id:%d", staffAssessId)
return &LockStaffAssess{
m: rsync.NewMutex(key),
}
}
func (lk *LockStaffAssess) Lock() error {
return lk.m.Lock()
}
func (lk *LockStaffAssess) UnLock() (bool, error) {
return lk.m.Unlock()
}
... ...