作者 tangxvhui

暂存

... ... @@ -160,3 +160,11 @@ func CreateStaffAssessTaskRepository(options map[string]interface{}) domain.Staf
}
return repository.NewStaffAssessTaskRepository(transactionContext)
}
func CreateStaffAssessContentTempRepository(options map[string]interface{}) domain.StaffAssessContentTempRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessContentTempRepository(transactionContext)
}
... ...
package service
import (
"time"
"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/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//调试用,手动调用CreateStaffAssessTask
... ... @@ -31,9 +34,72 @@ func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateS
}
//保存员工绩效评估填写过程中即写即存的内容
func (srv StaffAssessServeice) SaveAssessContentTemp(param *command.SaveAssessInfoCommand) error {
func (srv StaffAssessServeice) SaveAssessContentTemp(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取旧的临时数据内容
contentTempRepo := factory.CreateStaffAssessContentTempRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取评估填写的内容
// assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessData, err := assessRepo.FindOne(map[string]interface{}{
"id": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
return nil
// staffAssessId
_, contentTempList, err := contentTempRepo.Find(map[string]interface{}{
"staffAssessId": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取临时保存的内容"+err.Error())
}
nowTime := time.Now()
if len(contentTempList) == 0 {
//获取评估模板
assessContentList, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估模板,"+err.Error())
}
//转填入临时的数据
for _, v := range assessContentList {
item := &domain.StaffAssessContentTemp{
Id: 0,
StaffAssessId: v.StaffAssessId,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
Remark: v.Remark,
Value: "",
CreatedAt: nowTime,
UpdatedAt: nowTime,
}
contentTempList = append(contentTempList, item)
}
}
//更新assessConten
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
//获取员工绩效评估填写内容
... ...
... ... @@ -13,7 +13,6 @@ type StaffAssessContentTemp struct {
Value string `json:"value"` //评估填写的值
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"`
}
type StaffAssessContentTempRepository interface {
... ...
... ... @@ -8,20 +8,14 @@ import (
// 填写的评估内容
type StaffAssessContentTemp struct {
tableName struct{} `pg:"staff_assess_content_temp" comment:"填写的评估项"`
Id int `pg:",pk"` //id
StaffAssessId int //用户需要的评估项id
SortBy int //排序
Category string //类别
Name string //名称
PromptTitle string //问题标题
PromptText string //提示项正文
Value string //评估填写的值
ReteResult string //评估的结果
Rule domain.EvaluationRule
Remark []domain.AssessContemtRemark
Weight int //权重
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt *time.Time
tableName struct{} `pg:"staff_assess_content_temp" comment:"临时填写的评估项"`
Id int `pg:",pk"` //id
StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Name string `json:"name"` //名称
Remark []domain.AssessContemtRemark `json:"remark"` //填写的反馈
Value string `json:"value"` //评估填写的值
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
}
... ...
... ... @@ -3,7 +3,6 @@ package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -15,49 +14,37 @@ type StaffAssessContentTempRepository struct {
transactionContext *pgTransaction.TransactionContext
}
// var _ domain.StaffAssessContentRepository = (*StaffAssessContentTempRepository)(nil)
var _ domain.StaffAssessContentTempRepository = (*StaffAssessContentTempRepository)(nil)
func NewStaffAssessContentTempRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentTempRepository {
return &StaffAssessContentTempRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessContentTempRepository) TransformToDomain(d *models.StaffAssessContent) *domain.StaffAssessContent {
return &domain.StaffAssessContent{
func (repo *StaffAssessContentTempRepository) TransformToDomain(d *models.StaffAssessContentTemp) *domain.StaffAssessContentTemp {
return &domain.StaffAssessContentTemp{
Id: d.Id,
StaffAssessId: d.StaffAssessId,
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
PromptTitle: d.PromptTitle,
PromptText: d.PromptText,
Remark: d.Remark,
Value: d.Value,
ReteResult: d.ReteResult,
Rule: d.Rule,
Weight: d.Weight,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: nil,
}
}
func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContent) (*domain.StaffAssessContent, error) {
saveModel := models.StaffAssessContent{
func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContentTemp) (*domain.StaffAssessContentTemp, error) {
saveModel := models.StaffAssessContentTemp{
Id: d.Id,
StaffAssessId: d.StaffAssessId,
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
PromptTitle: d.PromptTitle,
PromptText: d.PromptText,
Remark: d.Remark,
Value: d.Value,
ReteResult: d.ReteResult,
Rule: d.Rule,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
Weight: d.Weight,
DeletedAt: nil,
}
tx := repo.transactionContext.PgTx
var err error
... ... @@ -78,19 +65,15 @@ func (repo *StaffAssessContentTempRepository) Save(d *domain.StaffAssessContent)
func (repo *StaffAssessContentTempRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssessContent{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
_, err := tx.Model(&models.StaffAssessContentTemp{}).
Where("id=?", id).Delete()
return err
}
func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContent, error) {
func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContentTemp, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssessContent)
m := new(models.StaffAssessContentTemp)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
... ... @@ -105,20 +88,13 @@ func (repo *StaffAssessContentTempRepository) FindOne(queryOptions map[string]in
return u, nil
}
func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContent, error) {
func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContentTemp, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssessContent
query := tx.Model(&m).
Where("deleted_at isnull")
var m []*models.StaffAssessContentTemp
query := tx.Model(&m)
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["staffAssessId"]; ok {
query.Where("staff_assess_id=?", v)
}
... ... @@ -126,7 +102,7 @@ func (repo *StaffAssessContentTempRepository) Find(queryOptions map[string]inter
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssessContent
var arrays []*domain.StaffAssessContentTemp
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, d)
... ...