export.go 2.8 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/xuri/excelize/v2"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)

// 数据导出
func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAssess2Commad) (*excelize.File, 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()
	}()
	hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	assessDao := dao.NewStaffAssessDao(map[string]interface{}{
		"transactionContext": transactionContext,
	})
	// 按照cycleId获取项目的指标项
	evaluationItemList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
		param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
	// 按照项目获取填写的内容
	assessContentList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
		param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}

	return nil, nil
}

// 处理原始数据,方便进行 excel导出
type exportData3 struct {
	sheetList   []string                //excel的sheet列表
	tableHeader map[string]*HeaderLevel //表头数据
}

func (e *exportData3) FormatTableHead(param []dao.DataEvaluationItemUsed2) {
	userNameMap := map[string]struct{}{} //员工名字过滤
	userProjcetMap := map[string]map[string]string{}
	userIdName := map[string]string{} //员工id=> 员工名称
	sheetMap := HeaderLevel{}
	for _, val := range param {
		// child := sheetMap.addChild(val.TargetUserId)
		// _ = child.addChild(val.EvaluationProjectId)
		if _, ok := userNameMap[val.TargetUserId]; !ok {
			userProjcetMap[val.TargetUserId] = map[string]string{}
		}
		userProjcetMap[val.TargetUserId][val.EvaluationProjectId] = ""
		if _, ok := userIdName[val.TargetUserId]; !ok {
			userIdName[val.TargetUserId] = val.TargetUserName
			userNameMap[val.TargetUserName] = struct{}{}
		}
	}

	for _, val := range sheetMap.Child {

	}
}

func (e *exportData3) FormatListValue(param []dao.DataStaffAssessContent2) {

}

func (e *exportData3) DataKey(userName string, projectId string, beginDay string, category string, weight string, contentName string) string {
	return ""
}