service.go 3.7 KB
package service

import (
	"time"

	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/utils/tool_funs"
	"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/query"
)

type StaffAssessServeice struct {
}

// 获取我参与过的评估项目列表
func (srv StaffAssessServeice) SearchAssessMe(param *query.SearchAssessMeQuery) (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()
	}()
	cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	currentTime, err := time.ParseInLocation("2006-01-02", param.CurrentTime, time.Local)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, "时间条件填写错误")
	}
	//获取param.CurrentTime 对应的周期
	_, cycleList, err := cycleRepo.Find(map[string]interface{}{
		"companyId": param.CompanyId,
		"timeStart": currentTime,
		"timeEnd":   currentTime,
		"limit":     1,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
	}
	if len(cycleList) == 0 {
		listData := []adapter.SearchAssessMeResp{}
		return tool_funs.SimpleWrapGridMap(0, listData), nil
	}

	//更具周期和param.UserId 获取评估项目列表
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var cnt int64
	var listData []adapter.SearchAssessMeResp
	return tool_funs.SimpleWrapGridMap(cnt, listData), nil
}

// 获取项目评估进度描述
func (srv StaffAssessServeice) AssessTaskDesc(param query.AssessTaskDescQuery) (*adapter.AssessTaskDescResp, 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()
	}()

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

// 获取自评反馈列表
func (srv StaffAssessServeice) AssessSelfList(param query.AssessTaskDescQuery) (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()
	}()

	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	var cnt int64
	var listData []adapter.AssessSelfList
	var userInfo adapter.StaffInfo
	result := tool_funs.SimpleWrapGridMap(cnt, listData)
	result["userInfo"] = userInfo
	return result, nil
}