1. 增加评估提交项 填写内容数据缓存
2. 获取【通用评估详情】和【自评详情】请求增加参数标记是否优先获取缓存 3. 通用评估数据提交后,删除缓存 4. 优化评估数据排序
正在显示
17 个修改的文件
包含
353 行增加
和
17 行删除
@@ -168,3 +168,11 @@ func CreateStaffAssessContentTempRepository(options map[string]interface{}) doma | @@ -168,3 +168,11 @@ func CreateStaffAssessContentTempRepository(options map[string]interface{}) doma | ||
168 | } | 168 | } |
169 | return repository.NewStaffAssessContentTempRepository(transactionContext) | 169 | return repository.NewStaffAssessContentTempRepository(transactionContext) |
170 | } | 170 | } |
171 | + | ||
172 | +func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.StaffAssessCacheRepository { | ||
173 | + var transactionContext *pg.TransactionContext | ||
174 | + if value, ok := options["transactionContext"]; ok { | ||
175 | + transactionContext = value.(*pg.TransactionContext) | ||
176 | + } | ||
177 | + return repository.NewStaffAssessCacheRepository(transactionContext) | ||
178 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/core/validation" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +// SaveAssessCacheCommand 保存待提交的评估数据(缓存) | ||
9 | +type SaveAssessCacheCommand struct { | ||
10 | + AssessId int64 `cname:"评估项ID" json:"assessId,string"` | ||
11 | + AssessContent []domain.AssessContent `cname:"评估数据" json:"assessContent"` | ||
12 | +} | ||
13 | + | ||
14 | +func (in *SaveAssessCacheCommand) Valid(validation *validation.Validation) { | ||
15 | + if in.AssessId == 0 { | ||
16 | + validation.SetError("assessId", "ID无效") | ||
17 | + return | ||
18 | + } | ||
19 | +} |
1 | package command | 1 | package command |
2 | 2 | ||
3 | +import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
4 | + | ||
3 | //保存员工填写评估内容 | 5 | //保存员工填写评估内容 |
4 | type SaveAssessInfoCommand struct { | 6 | type SaveAssessInfoCommand struct { |
5 | AssessId int `json:"assessId"` // | 7 | AssessId int `json:"assessId"` // |
6 | ExecutorId int `json:"executorId"` //填写人的id | 8 | ExecutorId int `json:"executorId"` //填写人的id |
7 | CompanyId int `json:"companyId"` //公司id | 9 | CompanyId int `json:"companyId"` //公司id |
8 | - AssessContent []AssesssContent `json:"assessContent"` | ||
9 | -} | ||
10 | - | ||
11 | -type AssesssContent struct { | ||
12 | - Category string `json:"category"` | ||
13 | - Name string `json:"name"` | ||
14 | - Value string `json:"value"` | ||
15 | - Remark []RemarkText `json:"remark"` | 10 | + AssessContent []domain.AssessContent `json:"assessContent"` |
16 | } | 11 | } |
17 | 12 | ||
18 | -type RemarkText struct { | ||
19 | - Title string `json:"title"` | ||
20 | - RemarkText string `json:"remarkText"` | ||
21 | -} | 13 | +//type AssessContent struct { |
14 | +// Category string `json:"category"` | ||
15 | +// Name string `json:"name"` | ||
16 | +// Value string `json:"value"` | ||
17 | +// Remark []RemarkText `json:"remark"` | ||
18 | +//} | ||
19 | +// | ||
20 | +//type RemarkText struct { | ||
21 | +// Title string `json:"title"` | ||
22 | +// RemarkText string `json:"remarkText"` | ||
23 | +//} |
@@ -2,6 +2,7 @@ package query | @@ -2,6 +2,7 @@ package query | ||
2 | 2 | ||
3 | //获取评估任务详情 | 3 | //获取评估任务详情 |
4 | type AssessInfoQuery struct { | 4 | type AssessInfoQuery struct { |
5 | - AssessId int `json:"assessId"` // | ||
6 | - CompanyId int `json:"companyId"` // | 5 | + AssessId int `json:"assessId"` // 评估项ID |
6 | + CompanyId int `json:"companyId"` // 公司ID | ||
7 | + AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据 | ||
7 | } | 8 | } |
@@ -5,5 +5,5 @@ type AssessSelfInfoQuery struct { | @@ -5,5 +5,5 @@ type AssessSelfInfoQuery struct { | ||
5 | AssessTaskId int `json:"assessTaskId"` //assessTaskId 的id | 5 | AssessTaskId int `json:"assessTaskId"` //assessTaskId 的id |
6 | TargetUserId int `json:"targetUserId,string"` //被评估的人id | 6 | TargetUserId int `json:"targetUserId,string"` //被评估的人id |
7 | CompanyId int `json:"companyId"` //公司id | 7 | CompanyId int `json:"companyId"` //公司id |
8 | - | 8 | + AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据 |
9 | } | 9 | } |
@@ -6,4 +6,5 @@ type GetExecutorSelfAssessQuery struct { | @@ -6,4 +6,5 @@ type GetExecutorSelfAssessQuery struct { | ||
6 | TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填 | 6 | TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填 |
7 | CycleId int `json:"cycleId"` //评估周期id 必填 | 7 | CycleId int `json:"cycleId"` //评估周期id 必填 |
8 | BeginDay string `json:"beginDay"` //评估任务的开始日期 2006-01-02 | 8 | BeginDay string `json:"beginDay"` //评估任务的开始日期 2006-01-02 |
9 | + AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据 | ||
9 | } | 10 | } |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +// StaffAssessCacheService 保存待提交的评估数据(缓存) | ||
11 | +type StaffAssessCacheService struct{} | ||
12 | + | ||
13 | +func NewStaffAssessCacheService() *StaffAssessCacheService { | ||
14 | + newService := &StaffAssessCacheService{} | ||
15 | + return newService | ||
16 | +} | ||
17 | + | ||
18 | +func (srv StaffAssessCacheService) SaveAssessCache(in *command.SaveAssessCacheCommand) (map[string]interface{}, error) { | ||
19 | + transactionContext, err := factory.ValidateStartTransaction(in) | ||
20 | + if err != nil { | ||
21 | + return nil, err | ||
22 | + } | ||
23 | + defer func() { | ||
24 | + transactionContext.RollbackTransaction() | ||
25 | + }() | ||
26 | + cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
27 | + _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": in.AssessId, "limit": 1}) | ||
28 | + if err != nil { | ||
29 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
30 | + } | ||
31 | + var cache *domain.StaffAssessCache | ||
32 | + if len(caches) == 0 { | ||
33 | + cache = &domain.StaffAssessCache{} | ||
34 | + cache.Id = 0 | ||
35 | + cache.AssessId = in.AssessId | ||
36 | + cache.AssessContent = in.AssessContent | ||
37 | + } else { | ||
38 | + cache = caches[0] | ||
39 | + cache.AssessContent = in.AssessContent | ||
40 | + } | ||
41 | + if _, err = cacheRepository.Save(cache); err != nil { | ||
42 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
43 | + } | ||
44 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
45 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
46 | + } | ||
47 | + return map[string]interface{}{"assessId": cache.Id}, nil | ||
48 | +} |
@@ -971,6 +971,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessSelfInfoQuer | @@ -971,6 +971,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessSelfInfoQuer | ||
971 | } | 971 | } |
972 | } | 972 | } |
973 | 973 | ||
974 | + // 恢复缓存数据 | ||
975 | + if param.AcquireCache != 0 { | ||
976 | + srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList) | ||
977 | + } | ||
978 | + | ||
974 | //获取员工描述 | 979 | //获取员工描述 |
975 | staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId)) | 980 | staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId)) |
976 | if err := transactionContext.CommitTransaction(); err != nil { | 981 | if err := transactionContext.CommitTransaction(); err != nil { |
@@ -1551,6 +1556,11 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada | @@ -1551,6 +1556,11 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada | ||
1551 | } | 1556 | } |
1552 | } | 1557 | } |
1553 | 1558 | ||
1559 | + // 恢复缓存数据 | ||
1560 | + if param.AcquireCache != 0 { | ||
1561 | + srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList) | ||
1562 | + } | ||
1563 | + | ||
1554 | targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId)) | 1564 | targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId)) |
1555 | if err != nil { | 1565 | if err != nil { |
1556 | log.Logger.Error("获取员工描述" + err.Error()) | 1566 | log.Logger.Error("获取员工描述" + err.Error()) |
@@ -1713,7 +1723,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1713,7 +1723,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
1713 | } | 1723 | } |
1714 | } | 1724 | } |
1715 | //处理提交上来的数据 | 1725 | //处理提交上来的数据 |
1716 | - paramContentMap := map[string]command.AssesssContent{} | 1726 | + paramContentMap := map[string]domain.AssessContent{} |
1717 | for i, v := range param.AssessContent { | 1727 | for i, v := range param.AssessContent { |
1718 | key := fmt.Sprintf("%s-%s", v.Category, v.Name) | 1728 | key := fmt.Sprintf("%s-%s", v.Category, v.Name) |
1719 | paramContentMap[key] = param.AssessContent[i] | 1729 | paramContentMap[key] = param.AssessContent[i] |
@@ -1726,7 +1736,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1726,7 +1736,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
1726 | continue | 1736 | continue |
1727 | } | 1737 | } |
1728 | v.Value = item.Value | 1738 | v.Value = item.Value |
1729 | - if v.Required == 1 { | 1739 | + if v.Required == domain.NodeRequiredYes { |
1730 | //转换填入的评估值 | 1740 | //转换填入的评估值 |
1731 | err = v.TransformValue() | 1741 | err = v.TransformValue() |
1732 | if err != nil { | 1742 | if err != nil { |
@@ -1755,6 +1765,19 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1755,6 +1765,19 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
1755 | if err != nil { | 1765 | if err != nil { |
1756 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) | 1766 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) |
1757 | } | 1767 | } |
1768 | + | ||
1769 | + // 删除缓存 | ||
1770 | + cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
1771 | + if _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessData.Id, "limit": 1}); err != nil { | ||
1772 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1773 | + } else { | ||
1774 | + for i := range caches { | ||
1775 | + if err = cacheRepository.Remove(caches[i].Id); err != nil { | ||
1776 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1777 | + } | ||
1778 | + } | ||
1779 | + } | ||
1780 | + | ||
1758 | if err := transactionContext.CommitTransaction(); err != nil { | 1781 | if err := transactionContext.CommitTransaction(); err != nil { |
1759 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 1782 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
1760 | } | 1783 | } |
@@ -1884,3 +1907,29 @@ loop: | @@ -1884,3 +1907,29 @@ loop: | ||
1884 | } | 1907 | } |
1885 | return chargeUserList, nil | 1908 | return chargeUserList, nil |
1886 | } | 1909 | } |
1910 | + | ||
1911 | +func (srv StaffAssessServeice) recoverAssessCache(context application.TransactionContext, assessId int, dataArray []*domain.StaffAssessContent) { | ||
1912 | + cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": context}) | ||
1913 | + _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessId, "limit": 1}) | ||
1914 | + if err != nil || len(caches) == 0 { | ||
1915 | + return | ||
1916 | + } | ||
1917 | + cacheArray := caches[0].AssessContent | ||
1918 | + cacheLen := len(cacheArray) | ||
1919 | + | ||
1920 | + for i := range dataArray { | ||
1921 | + if cacheLen > i { // 避免数组越界 | ||
1922 | + data := dataArray[i] | ||
1923 | + cache := cacheArray[i] | ||
1924 | + | ||
1925 | + data.Value = cache.Value // 评估填写的值 | ||
1926 | + cacheRemarkLen := len(cache.Remark) | ||
1927 | + | ||
1928 | + for j := range data.Remark { | ||
1929 | + if cacheRemarkLen > j { | ||
1930 | + data.Remark[j].RemarkText = cache.Remark[j].RemarkText // 评估填写文本内容 | ||
1931 | + } | ||
1932 | + } | ||
1933 | + } | ||
1934 | + } | ||
1935 | +} |
@@ -661,6 +661,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA | @@ -661,6 +661,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA | ||
661 | } | 661 | } |
662 | } | 662 | } |
663 | 663 | ||
664 | + // 恢复缓存数据 | ||
665 | + if param.AcquireCache != 0 { | ||
666 | + srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList) | ||
667 | + } | ||
668 | + | ||
664 | //获取员工描述 | 669 | //获取员工描述 |
665 | staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId)) | 670 | staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId)) |
666 | if err := transactionContext.CommitTransaction(); err != nil { | 671 | if err := transactionContext.CommitTransaction(); err != nil { |
pkg/domain/staff_assess_cache.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// StaffAssessCache 填写评估数据(缓存暂未提交) | ||
6 | +type StaffAssessCache struct { | ||
7 | + Id int64 `json:"id,string" comment:"ID"` | ||
8 | + AssessId int64 `json:"assessId,string" comment:"评估项ID"` | ||
9 | + AssessContent []AssessContent `json:"assessContent" comment:"评估项提交数据"` | ||
10 | + CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | ||
11 | + UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` | ||
12 | + DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | ||
13 | +} | ||
14 | + | ||
15 | +type AssessContent struct { | ||
16 | + Category string `json:"category"` | ||
17 | + Name string `json:"name"` | ||
18 | + Value string `json:"value"` | ||
19 | + Remark []RemarkText `json:"remark"` | ||
20 | +} | ||
21 | + | ||
22 | +type RemarkText struct { | ||
23 | + Title string `json:"title"` | ||
24 | + RemarkText string `json:"remarkText"` | ||
25 | +} | ||
26 | + | ||
27 | +type StaffAssessCacheRepository interface { | ||
28 | + Save(param *StaffAssessCache) (*StaffAssessCache, error) | ||
29 | + Remove(id int64) error | ||
30 | + FindOne(queryOptions map[string]interface{}) (*StaffAssessCache, error) | ||
31 | + Find(queryOptions map[string]interface{}) (int, []*StaffAssessCache, error) | ||
32 | +} |
@@ -93,6 +93,12 @@ func (content *StaffAssessContent) scoreValue() error { | @@ -93,6 +93,12 @@ func (content *StaffAssessContent) scoreValue() error { | ||
93 | return errors.New("评分填写的值错误") | 93 | return errors.New("评分填写的值错误") |
94 | } | 94 | } |
95 | 95 | ||
96 | +//type StaffAssessContentSort []*StaffAssessContent | ||
97 | +// | ||
98 | +//func (a StaffAssessContentSort) Len() int { return len(a) } | ||
99 | +//func (a StaffAssessContentSort) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
100 | +//func (a StaffAssessContentSort) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy } | ||
101 | + | ||
96 | type StaffAssessContentRepository interface { | 102 | type StaffAssessContentRepository interface { |
97 | Save(param *StaffAssessContent) (*StaffAssessContent, error) | 103 | Save(param *StaffAssessContent) (*StaffAssessContent, error) |
98 | Remove(id int) error | 104 | Remove(id int) error |
@@ -45,6 +45,7 @@ func init() { | @@ -45,6 +45,7 @@ func init() { | ||
45 | &models.StaffAssess{}, | 45 | &models.StaffAssess{}, |
46 | &models.StaffAssessTask{}, | 46 | &models.StaffAssessTask{}, |
47 | &models.StaffAssessContent{}, | 47 | &models.StaffAssessContent{}, |
48 | + &models.StaffAssessCache{}, | ||
48 | } | 49 | } |
49 | for _, model := range tables { | 50 | for _, model := range tables { |
50 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 51 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
7 | +) | ||
8 | + | ||
9 | +// StaffAssessCache 提交评估项内容缓存 | ||
10 | +type StaffAssessCache struct { | ||
11 | + tableName struct{} `comment:"评估项填写内容缓存" pg:"staff_assess_cache"` | ||
12 | + Id int64 `comment:"ID" pg:",pk"` | ||
13 | + AssessId int64 `comment:"评估项ID"` | ||
14 | + AssessContent []domain.AssessContent `comment:"评估项提交数据"` | ||
15 | + CreatedAt time.Time `comment:"创建时间"` | ||
16 | + UpdatedAt time.Time `comment:"更新时间"` | ||
17 | + DeletedAt *time.Time `comment:"删除时间"` | ||
18 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/go-pg/pg/v10" | ||
10 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
13 | +) | ||
14 | + | ||
15 | +type StaffAssessCacheRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +//var _ domain.StaffAssessCacheRepository = (*StaffAssessCacheRepository)(nil) | ||
20 | + | ||
21 | +func NewStaffAssessCacheRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessCacheRepository { | ||
22 | + return &StaffAssessCacheRepository{transactionContext: transactionContext} | ||
23 | +} | ||
24 | + | ||
25 | +func (repo *StaffAssessCacheRepository) TransformToDomain(m *models.StaffAssessCache) domain.StaffAssessCache { | ||
26 | + return domain.StaffAssessCache{ | ||
27 | + Id: m.Id, | ||
28 | + AssessId: m.AssessId, | ||
29 | + AssessContent: m.AssessContent, | ||
30 | + CreatedAt: m.CreatedAt, | ||
31 | + UpdatedAt: m.UpdatedAt, | ||
32 | + DeletedAt: m.DeletedAt, | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | +func (repo *StaffAssessCacheRepository) TransformToModel(d *domain.StaffAssessCache) models.StaffAssessCache { | ||
37 | + return models.StaffAssessCache{ | ||
38 | + Id: d.Id, | ||
39 | + AssessId: d.AssessId, | ||
40 | + AssessContent: d.AssessContent, | ||
41 | + CreatedAt: d.CreatedAt, | ||
42 | + UpdatedAt: d.UpdatedAt, | ||
43 | + DeletedAt: d.DeletedAt, | ||
44 | + } | ||
45 | +} | ||
46 | + | ||
47 | +func (repo *StaffAssessCacheRepository) nextIdentify() (int64, error) { | ||
48 | + return utils.NewSnowflakeId() | ||
49 | +} | ||
50 | + | ||
51 | +func (repo *StaffAssessCacheRepository) Save(d *domain.StaffAssessCache) (*domain.StaffAssessCache, error) { | ||
52 | + var isCreate = d.Id == 0 | ||
53 | + if isCreate { | ||
54 | + id, err := repo.nextIdentify() | ||
55 | + if err != nil { | ||
56 | + return d, err | ||
57 | + } | ||
58 | + d.Id = id | ||
59 | + d.CreatedAt = time.Now() | ||
60 | + d.UpdatedAt = d.CreatedAt | ||
61 | + } else { | ||
62 | + d.UpdatedAt = time.Now() | ||
63 | + } | ||
64 | + m := repo.TransformToModel(d) | ||
65 | + tx := repo.transactionContext.PgTx | ||
66 | + var err error | ||
67 | + if isCreate { | ||
68 | + _, err = tx.Model(&m).Returning("id").Insert() | ||
69 | + } else { | ||
70 | + _, err = tx.Model(&m).Returning("id").WherePK().Update() // 更新和删除必须增加条件 | ||
71 | + } | ||
72 | + if err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + d.Id = m.Id | ||
76 | + return d, nil | ||
77 | +} | ||
78 | + | ||
79 | +func (repo *StaffAssessCacheRepository) Remove(id int64) error { | ||
80 | + tx := repo.transactionContext.PgTx | ||
81 | + nowTime := time.Now() | ||
82 | + _, err := tx.Model(&models.StaffAssessCache{}).Where("id=?", id).Set("deleted_at=?", nowTime).Update() | ||
83 | + return err | ||
84 | +} | ||
85 | + | ||
86 | +func (repo *StaffAssessCacheRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessCache, error) { | ||
87 | + tx := repo.transactionContext.PgTx | ||
88 | + m := new(models.StaffAssessCache) | ||
89 | + query := tx.Model(m) | ||
90 | + query.Where("deleted_at isnull") | ||
91 | + if id, ok := queryOptions["id"]; ok { | ||
92 | + query.Where("id=?", id) | ||
93 | + } | ||
94 | + if err := query.First(); err != nil { | ||
95 | + if errors.Is(err, pg.ErrNoRows) { | ||
96 | + return nil, fmt.Errorf("没有此资源") | ||
97 | + } else { | ||
98 | + return nil, err | ||
99 | + } | ||
100 | + } | ||
101 | + u := repo.TransformToDomain(m) | ||
102 | + return &u, nil | ||
103 | +} | ||
104 | + | ||
105 | +func (repo *StaffAssessCacheRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessCache, error) { | ||
106 | + tx := repo.transactionContext.PgTx | ||
107 | + var m []*models.StaffAssessCache | ||
108 | + query := tx.Model(&m).Where("deleted_at isnull") | ||
109 | + | ||
110 | + if v, ok := queryOptions["assessId"]; ok { | ||
111 | + query.Where("assess_id=?", v) | ||
112 | + } | ||
113 | + | ||
114 | + if v, ok := queryOptions["limit"].(int); ok { | ||
115 | + query.Limit(v) | ||
116 | + } | ||
117 | + | ||
118 | + if v, ok := queryOptions["offset"].(int); ok { | ||
119 | + query.Offset(v) | ||
120 | + } | ||
121 | + | ||
122 | + count, err := query.SelectAndCount() | ||
123 | + if err != nil { | ||
124 | + return 0, nil, err | ||
125 | + } | ||
126 | + var arrays []*domain.StaffAssessCache | ||
127 | + for _, v := range m { | ||
128 | + d := repo.TransformToDomain(v) | ||
129 | + arrays = append(arrays, &d) | ||
130 | + } | ||
131 | + return count, arrays, nil | ||
132 | +} |
@@ -128,6 +128,8 @@ func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface | @@ -128,6 +128,8 @@ func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface | ||
128 | if v, ok := queryOptions["staffAssessId"]; ok { | 128 | if v, ok := queryOptions["staffAssessId"]; ok { |
129 | query.Where("staff_assess_id=?", v) | 129 | query.Where("staff_assess_id=?", v) |
130 | } | 130 | } |
131 | + | ||
132 | + query.Order("sort_by ASC") | ||
131 | count, err := query.SelectAndCount() | 133 | count, err := query.SelectAndCount() |
132 | if err != nil { | 134 | if err != nil { |
133 | return 0, nil, err | 135 | return 0, nil, err |
@@ -348,3 +348,14 @@ func (c *StaffAssessController) ExportAssessContentCycleDay() { | @@ -348,3 +348,14 @@ func (c *StaffAssessController) ExportAssessContentCycleDay() { | ||
348 | c.Ctx.Output.Header("Expires", "0") | 348 | c.Ctx.Output.Header("Expires", "0") |
349 | data.Write(c.Ctx.ResponseWriter) | 349 | data.Write(c.Ctx.ResponseWriter) |
350 | } | 350 | } |
351 | + | ||
352 | +// SaveAssessCache 保存评估内容(缓存) | ||
353 | +func (c *StaffAssessController) SaveAssessCache() { | ||
354 | + cacheService := service.NewStaffAssessCacheService() | ||
355 | + in := &command.SaveAssessCacheCommand{} | ||
356 | + if err := c.Unmarshal(in); err != nil { | ||
357 | + c.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | ||
358 | + } else { | ||
359 | + c.Response(cacheService.SaveAssessCache(in)) | ||
360 | + } | ||
361 | +} |
@@ -30,6 +30,7 @@ func init() { | @@ -30,6 +30,7 @@ func init() { | ||
30 | web.NSCtrlPost("/me/execute/supper/list", (*controllers.StaffAssessController).ListMeSupperAssess), //我要执行的360评估的用户列表 | 30 | web.NSCtrlPost("/me/execute/supper/list", (*controllers.StaffAssessController).ListMeSupperAssess), //我要执行的360评估的用户列表 |
31 | web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情 | 31 | web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情 |
32 | web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情 | 32 | web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情 |
33 | + web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存) | ||
33 | web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表 | 34 | web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表 |
34 | web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我的上级评估的列表 | 35 | web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我的上级评估的列表 |
35 | web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情 | 36 | web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情 |
-
请 注册 或 登录 后发表评论