作者 tangxvhui

编辑加锁

@@ -17,6 +17,7 @@ import ( @@ -17,6 +17,7 @@ import (
17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
18 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 18 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
19 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 19 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  20 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
20 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" 21 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
21 ) 22 )
22 23
@@ -1008,6 +1009,14 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T @@ -1008,6 +1009,14 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T
1008 1009
1009 // 提交评估数据 1010 // 提交评估数据
1010 func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) { 1011 func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
  1012 + lock := xredis.NewLockStaffAssess(param.AssessId)
  1013 + err := lock.Lock()
  1014 + if err != nil {
  1015 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  1016 + }
  1017 + defer func() {
  1018 + lock.UnLock()
  1019 + }()
1011 transactionContext, err := factory.CreateTransactionContext(nil) 1020 transactionContext, err := factory.CreateTransactionContext(nil)
1012 if err != nil { 1021 if err != nil {
1013 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1022 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1135,6 +1144,14 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1135,6 +1144,14 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1135 1144
1136 // SaveSelfAssess 提交自评评估内容 1145 // SaveSelfAssess 提交自评评估内容
1137 func (srv StaffAssessServeice) SaveSelfAssess(in *command.SaveSelfAssessCommand) (map[string]interface{}, error) { 1146 func (srv StaffAssessServeice) SaveSelfAssess(in *command.SaveSelfAssessCommand) (map[string]interface{}, error) {
  1147 + lock := xredis.NewLockStaffAssess(in.AssessId)
  1148 + err := lock.Lock()
  1149 + if err != nil {
  1150 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
  1151 + }
  1152 + defer func() {
  1153 + lock.UnLock()
  1154 + }()
1138 transactionContext, err := factory.ValidateStartTransaction(in) 1155 transactionContext, err := factory.ValidateStartTransaction(in)
1139 if err != nil { 1156 if err != nil {
1140 return nil, err 1157 return nil, err
@@ -44,3 +44,22 @@ func (lk *LockSummaryEvaluationId) Lock() error { @@ -44,3 +44,22 @@ func (lk *LockSummaryEvaluationId) Lock() error {
44 func (lk *LockSummaryEvaluationId) UnLock() (bool, error) { 44 func (lk *LockSummaryEvaluationId) UnLock() (bool, error) {
45 return lk.m.Unlock() 45 return lk.m.Unlock()
46 } 46 }
  47 +
  48 +type LockStaffAssess struct {
  49 + m *redsync.Mutex
  50 +}
  51 +
  52 +func NewLockStaffAssess(staffAssessId int) *LockStaffAssess {
  53 + key := fmt.Sprintf("performance:staff_assess_id:%d", staffAssessId)
  54 + return &LockStaffAssess{
  55 + m: rsync.NewMutex(key),
  56 + }
  57 +}
  58 +
  59 +func (lk *LockStaffAssess) Lock() error {
  60 + return lk.m.Lock()
  61 +}
  62 +
  63 +func (lk *LockStaffAssess) UnLock() (bool, error) {
  64 + return lk.m.Unlock()
  65 +}