service_2.go 4.0 KB
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
func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (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()
	}()

	data, err := srv.CreateStaffAssessTask(transactionContext, param)
	if err != nil {
		return nil, err
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return data, nil
}

//保存员工绩效评估填写过程中即写即存的内容
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())
	}

	// 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
}

//获取员工绩效评估填写内容
//临时数据存在时就获取临时数据
//不存在就获取实际保存的数据
func (srv StaffAssessServeice) GetAssessContentTemp(param *command.SaveAssessInfoCommand) (*adapter.AssessInfoResp, error) {
	return nil, nil
}