assess_cache_service.go
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// StaffAssessCacheService 保存待提交的评估数据(缓存)
type StaffAssessCacheService struct{}
func NewStaffAssessCacheService() *StaffAssessCacheService {
newService := &StaffAssessCacheService{}
return newService
}
func (srv StaffAssessCacheService) SaveAssessCache(in *command.SaveAssessCacheCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext})
_, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": in.AssessId, "limit": 1})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var cache *domain.StaffAssessCache
if len(caches) == 0 {
cache = &domain.StaffAssessCache{}
cache.Id = 0
cache.AssessId = in.AssessId
cache.AssessContent = in.AssessContent
} else {
cache = caches[0]
cache.AssessContent = in.AssessContent
}
if _, err = cacheRepository.Save(cache); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"assessId": cache.Id}, nil
}