作者 郑周

1. 增加评估提交项 填写内容数据缓存

2. 获取【通用评估详情】和【自评详情】请求增加参数标记是否优先获取缓存
3. 通用评估数据提交后,删除缓存
4. 优化评估数据排序
... ... @@ -168,3 +168,11 @@ func CreateStaffAssessContentTempRepository(options map[string]interface{}) doma
}
return repository.NewStaffAssessContentTempRepository(transactionContext)
}
func CreateStaffAssessCacheRepository(options map[string]interface{}) domain.StaffAssessCacheRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessCacheRepository(transactionContext)
}
... ...
package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// SaveAssessCacheCommand 保存待提交的评估数据(缓存)
type SaveAssessCacheCommand struct {
AssessId int64 `cname:"评估项ID" json:"assessId,string"`
AssessContent []domain.AssessContent `cname:"评估数据" json:"assessContent"`
}
func (in *SaveAssessCacheCommand) Valid(validation *validation.Validation) {
if in.AssessId == 0 {
validation.SetError("assessId", "ID无效")
return
}
}
... ...
package command
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
//保存员工填写评估内容
type SaveAssessInfoCommand struct {
AssessId int `json:"assessId"` //
ExecutorId int `json:"executorId"` //填写人的id
CompanyId int `json:"companyId"` //公司id
AssessContent []AssesssContent `json:"assessContent"`
}
type AssesssContent struct {
Category string `json:"category"`
Name string `json:"name"`
Value string `json:"value"`
Remark []RemarkText `json:"remark"`
AssessContent []domain.AssessContent `json:"assessContent"`
}
type RemarkText struct {
Title string `json:"title"`
RemarkText string `json:"remarkText"`
}
//type AssessContent struct {
// Category string `json:"category"`
// Name string `json:"name"`
// Value string `json:"value"`
// Remark []RemarkText `json:"remark"`
//}
//
//type RemarkText struct {
// Title string `json:"title"`
// RemarkText string `json:"remarkText"`
//}
... ...
... ... @@ -2,6 +2,7 @@ package query
//获取评估任务详情
type AssessInfoQuery struct {
AssessId int `json:"assessId"` //
CompanyId int `json:"companyId"` //
AssessId int `json:"assessId"` // 评估项ID
CompanyId int `json:"companyId"` // 公司ID
AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据
}
... ...
... ... @@ -5,5 +5,5 @@ type AssessSelfInfoQuery struct {
AssessTaskId int `json:"assessTaskId"` //assessTaskId 的id
TargetUserId int `json:"targetUserId,string"` //被评估的人id
CompanyId int `json:"companyId"` //公司id
AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据
}
... ...
... ... @@ -6,4 +6,5 @@ type GetExecutorSelfAssessQuery struct {
TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填
CycleId int `json:"cycleId"` //评估周期id 必填
BeginDay string `json:"beginDay"` //评估任务的开始日期 2006-01-02
AcquireCache int `json:"acquireCache"` // 0不获取缓存数据,1获取缓存数据
}
... ...
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
}
... ...
... ... @@ -971,6 +971,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessSelfInfoQuer
}
}
// 恢复缓存数据
if param.AcquireCache != 0 {
srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
}
//获取员工描述
staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -1551,6 +1556,11 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada
}
}
// 恢复缓存数据
if param.AcquireCache != 0 {
srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
}
targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
if err != nil {
log.Logger.Error("获取员工描述" + err.Error())
... ... @@ -1713,7 +1723,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
}
}
//处理提交上来的数据
paramContentMap := map[string]command.AssesssContent{}
paramContentMap := map[string]domain.AssessContent{}
for i, v := range param.AssessContent {
key := fmt.Sprintf("%s-%s", v.Category, v.Name)
paramContentMap[key] = param.AssessContent[i]
... ... @@ -1726,7 +1736,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
continue
}
v.Value = item.Value
if v.Required == 1 {
if v.Required == domain.NodeRequiredYes {
//转换填入的评估值
err = v.TransformValue()
if err != nil {
... ... @@ -1755,6 +1765,19 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
// 删除缓存
cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext})
if _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessData.Id, "limit": 1}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for i := range caches {
if err = cacheRepository.Remove(caches[i].Id); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1884,3 +1907,29 @@ loop:
}
return chargeUserList, nil
}
func (srv StaffAssessServeice) recoverAssessCache(context application.TransactionContext, assessId int, dataArray []*domain.StaffAssessContent) {
cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": context})
_, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessId, "limit": 1})
if err != nil || len(caches) == 0 {
return
}
cacheArray := caches[0].AssessContent
cacheLen := len(cacheArray)
for i := range dataArray {
if cacheLen > i { // 避免数组越界
data := dataArray[i]
cache := cacheArray[i]
data.Value = cache.Value // 评估填写的值
cacheRemarkLen := len(cache.Remark)
for j := range data.Remark {
if cacheRemarkLen > j {
data.Remark[j].RemarkText = cache.Remark[j].RemarkText // 评估填写文本内容
}
}
}
}
}
... ...
... ... @@ -661,6 +661,11 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA
}
}
// 恢复缓存数据
if param.AcquireCache != 0 {
srv.recoverAssessCache(transactionContext, assessData.Id, assessContentList)
}
//获取员工描述
staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
if err := transactionContext.CommitTransaction(); err != nil {
... ...
package domain
import "time"
// StaffAssessCache 填写评估数据(缓存暂未提交)
type StaffAssessCache struct {
Id int64 `json:"id,string" comment:"ID"`
AssessId int64 `json:"assessId,string" comment:"评估项ID"`
AssessContent []AssessContent `json:"assessContent" comment:"评估项提交数据"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type AssessContent struct {
Category string `json:"category"`
Name string `json:"name"`
Value string `json:"value"`
Remark []RemarkText `json:"remark"`
}
type RemarkText struct {
Title string `json:"title"`
RemarkText string `json:"remarkText"`
}
type StaffAssessCacheRepository interface {
Save(param *StaffAssessCache) (*StaffAssessCache, error)
Remove(id int64) error
FindOne(queryOptions map[string]interface{}) (*StaffAssessCache, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessCache, error)
}
... ...
... ... @@ -93,6 +93,12 @@ func (content *StaffAssessContent) scoreValue() error {
return errors.New("评分填写的值错误")
}
//type StaffAssessContentSort []*StaffAssessContent
//
//func (a StaffAssessContentSort) Len() int { return len(a) }
//func (a StaffAssessContentSort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
//func (a StaffAssessContentSort) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy }
type StaffAssessContentRepository interface {
Save(param *StaffAssessContent) (*StaffAssessContent, error)
Remove(id int) error
... ...
... ... @@ -45,6 +45,7 @@ func init() {
&models.StaffAssess{},
&models.StaffAssessTask{},
&models.StaffAssessContent{},
&models.StaffAssessCache{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
package models
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// StaffAssessCache 提交评估项内容缓存
type StaffAssessCache struct {
tableName struct{} `comment:"评估项填写内容缓存" pg:"staff_assess_cache"`
Id int64 `comment:"ID" pg:",pk"`
AssessId int64 `comment:"评估项ID"`
AssessContent []domain.AssessContent `comment:"评估项提交数据"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
package repository
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type StaffAssessCacheRepository struct {
transactionContext *pgTransaction.TransactionContext
}
//var _ domain.StaffAssessCacheRepository = (*StaffAssessCacheRepository)(nil)
func NewStaffAssessCacheRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessCacheRepository {
return &StaffAssessCacheRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessCacheRepository) TransformToDomain(m *models.StaffAssessCache) domain.StaffAssessCache {
return domain.StaffAssessCache{
Id: m.Id,
AssessId: m.AssessId,
AssessContent: m.AssessContent,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
}
}
func (repo *StaffAssessCacheRepository) TransformToModel(d *domain.StaffAssessCache) models.StaffAssessCache {
return models.StaffAssessCache{
Id: d.Id,
AssessId: d.AssessId,
AssessContent: d.AssessContent,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *StaffAssessCacheRepository) nextIdentify() (int64, error) {
return utils.NewSnowflakeId()
}
func (repo *StaffAssessCacheRepository) Save(d *domain.StaffAssessCache) (*domain.StaffAssessCache, error) {
var isCreate = d.Id == 0
if isCreate {
id, err := repo.nextIdentify()
if err != nil {
return d, err
}
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
if isCreate {
_, err = tx.Model(&m).Returning("id").Insert()
} else {
_, err = tx.Model(&m).Returning("id").WherePK().Update() // 更新和删除必须增加条件
}
if err != nil {
return nil, err
}
d.Id = m.Id
return d, nil
}
func (repo *StaffAssessCacheRepository) Remove(id int64) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssessCache{}).Where("id=?", id).Set("deleted_at=?", nowTime).Update()
return err
}
func (repo *StaffAssessCacheRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessCache, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssessCache)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return &u, nil
}
func (repo *StaffAssessCacheRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessCache, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssessCache
query := tx.Model(&m).Where("deleted_at isnull")
if v, ok := queryOptions["assessId"]; ok {
query.Where("assess_id=?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssessCache
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, &d)
}
return count, arrays, nil
}
... ...
... ... @@ -128,6 +128,8 @@ func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["staffAssessId"]; ok {
query.Where("staff_assess_id=?", v)
}
query.Order("sort_by ASC")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -348,3 +348,14 @@ func (c *StaffAssessController) ExportAssessContentCycleDay() {
c.Ctx.Output.Header("Expires", "0")
data.Write(c.Ctx.ResponseWriter)
}
// SaveAssessCache 保存评估内容(缓存)
func (c *StaffAssessController) SaveAssessCache() {
cacheService := service.NewStaffAssessCacheService()
in := &command.SaveAssessCacheCommand{}
if err := c.Unmarshal(in); err != nil {
c.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
c.Response(cacheService.SaveAssessCache(in))
}
}
... ...
... ... @@ -30,6 +30,7 @@ func init() {
web.NSCtrlPost("/me/execute/supper/list", (*controllers.StaffAssessController).ListMeSupperAssess), //我要执行的360评估的用户列表
web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情
web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情
web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存)
web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表
web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我的上级评估的列表
web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情
... ...