...
|
...
|
@@ -5,6 +5,7 @@ import ( |
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
|
...
|
...
|
@@ -18,25 +19,24 @@ func TaskSendSummaryEvaluationV2() error { |
|
|
str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
|
|
|
log.Logger.Info(str)
|
|
|
}()
|
|
|
var newPublisher summaryEvaluationPublisher
|
|
|
for {
|
|
|
projectList, err := getPrepareSummaryEvaluation()
|
|
|
cycleList, err := getPrepareEvaluationCycle()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if len(projectList) == 0 {
|
|
|
if len(cycleList) == 0 {
|
|
|
break
|
|
|
}
|
|
|
newPublisher = summaryEvaluationPublisher{}
|
|
|
for _, val := range projectList {
|
|
|
err = newPublisher.sendSummaryEvaluationV2(val)
|
|
|
err = sendSummaryEvaluationByCycle(cycleList[0])
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func getPrepareSummaryEvaluation() ([]*domain.EvaluationProject, error) {
|
|
|
// 获取周期
|
|
|
func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -47,56 +47,131 @@ func getPrepareSummaryEvaluation() ([]*domain.EvaluationProject, error) { |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
cycleList, err := cycleRepo.FindCycleEnd(1)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("获取可用的周期数据,%s", err)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return cycleList, nil
|
|
|
}
|
|
|
|
|
|
// 获取可用的项目
|
|
|
// func getPrepareSummaryEvaluation(cycleId int) ([]*domain.EvaluationProject, error) {
|
|
|
// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
// if err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// _ = transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
// // 获取项目数据总数
|
|
|
// _, projectList, err := projectRepo.Find(map[string]interface{}{
|
|
|
// "cycleId": cycleId,
|
|
|
// "summaryState": domain.ProjectSummaryStateNo,
|
|
|
// "state": domain.ProjectStateEnable,
|
|
|
// "limit": 200,
|
|
|
// }, "template")
|
|
|
// if err != nil {
|
|
|
// return nil, fmt.Errorf("获取可用的项目数据,%s", err)
|
|
|
// }
|
|
|
// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// return projectList, nil
|
|
|
// }
|
|
|
|
|
|
// 按周期下发 综合评估任务
|
|
|
func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
// 获取项目数据总数
|
|
|
_, projectList, err := projectRepo.Find(map[string]interface{}{
|
|
|
"endTime": time.Now(),
|
|
|
"cycleId": cycleParam.Id,
|
|
|
"summaryState": domain.ProjectSummaryStateNo,
|
|
|
"state": domain.ProjectStateEnable,
|
|
|
"limit": 200,
|
|
|
"limit": 500,
|
|
|
}, "template")
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("获取可用的项目数据,%s", err)
|
|
|
return fmt.Errorf("获取可用的项目数据,%s", err)
|
|
|
}
|
|
|
var newEvaluationList []domain.SummaryEvaluation
|
|
|
newPublisher := summaryEvaluationPublisher{}
|
|
|
for _, val := range projectList {
|
|
|
evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("按项目下发综合评估任务数据,%s", err)
|
|
|
}
|
|
|
newEvaluationList = append(newEvaluationList, evaluationList...)
|
|
|
}
|
|
|
// 回填周期的状态
|
|
|
cycleDao := dao.NewEvaluationCycleDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
err = cycleDao.UpdateSummaryState(cycleParam.Id, domain.ProjectSummaryStateYes)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("保存项目周期状态%s", err)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
return err
|
|
|
}
|
|
|
err = sendSmsEvalation(newEvaluationList)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("设置短信消息%s", err)
|
|
|
}
|
|
|
return projectList, nil
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 下发周期综合评估
|
|
|
type summaryEvaluationPublisher struct {
|
|
|
userCache map[int64]*domain.User
|
|
|
departCache map[int]*domain.Department
|
|
|
cycleCache map[int64]*domain.EvaluationCycle
|
|
|
}
|
|
|
|
|
|
func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *domain.EvaluationProject) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
|
|
|
transactionContext application.TransactionContext,
|
|
|
projectParam *domain.EvaluationProject, cycleData *domain.EvaluationCycle,
|
|
|
) ([]domain.SummaryEvaluation, error) {
|
|
|
// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
// if err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// _ = transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
_, evaluationItemList, err := evaluationItemRepo.Find(map[string]interface{}{
|
|
|
"evaluationProjectId": projectParam.Id,
|
|
|
"nodeType": int(domain.LinkNodeSelfAssessment),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(evaluationItemList) == 0 {
|
|
|
return nil
|
|
|
return nil, nil
|
|
|
}
|
|
|
nodeId := evaluationItemList[0].NodeId
|
|
|
executor360Map := map[int64]*domain.User{}
|
...
|
...
|
@@ -111,20 +186,12 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma |
|
|
}
|
|
|
user360, err := se.getUserData(userRepo, int64(v.EvaluatorId))
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("获取360用户%s", err)
|
|
|
return nil, fmt.Errorf("获取360用户%s", err)
|
|
|
}
|
|
|
executor360Map[user360.Id] = user360
|
|
|
}
|
|
|
//获取周期
|
|
|
cycleData, err := se.getCycleData(cycleRepo, projectParam.CycleId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if cycleData == nil {
|
|
|
return nil
|
|
|
}
|
|
|
if cycleData.TimeEnd == nil {
|
|
|
return fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
|
|
|
return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
|
|
|
}
|
|
|
//自评的时间范围
|
|
|
beginTimeSelf := *cycleData.TimeEnd
|
...
|
...
|
@@ -166,14 +233,14 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma |
|
|
}
|
|
|
targetUser, err := se.getUserData(userRepo, targetUserId)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("获取员工数据%s", err)
|
|
|
return nil, fmt.Errorf("获取员工数据%s", err)
|
|
|
}
|
|
|
if targetUser == nil {
|
|
|
continue
|
|
|
}
|
|
|
targetUserDepartment, err := se.getDepartmentData(departmentRepo, targetUser.DepartmentId)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("获取员工的部门数据%s", err)
|
|
|
return nil, fmt.Errorf("获取员工的部门数据%s", err)
|
|
|
}
|
|
|
evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
|
|
|
evaluationTemp.Types = domain.EvaluationSelf
|
...
|
...
|
@@ -254,39 +321,38 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma |
|
|
for i := range newEvaluationList {
|
|
|
err = summaryEvaluationRepo.Save(&newEvaluationList[i])
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("保存周期综合评估%s", err)
|
|
|
return nil, fmt.Errorf("保存周期综合评估%s", err)
|
|
|
}
|
|
|
}
|
|
|
//回填项目的状态
|
|
|
projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
err = projectDao.UpdateSummaryState(projectParam.Id, domain.ProjectSummaryStateYes)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("保存项目状态%s", err)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return err
|
|
|
return nil, fmt.Errorf("保存项目状态%s", err)
|
|
|
}
|
|
|
err = sendSmsEvalation(newEvaluationList)
|
|
|
return fmt.Errorf("设置短信发送%s", err)
|
|
|
// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
return newEvaluationList, fmt.Errorf("设置短信发送%s", err)
|
|
|
}
|
|
|
|
|
|
// 获取周期设置数据
|
|
|
func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {
|
|
|
var cycleData *domain.EvaluationCycle
|
|
|
if val, ok := se.cycleCache[cycleId]; ok {
|
|
|
cycleData = val
|
|
|
} else {
|
|
|
_, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(cycleList) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
cycleData = cycleList[0]
|
|
|
}
|
|
|
return cycleData, nil
|
|
|
}
|
|
|
// func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {
|
|
|
// var cycleData *domain.EvaluationCycle
|
|
|
// if val, ok := se.cycleCache[cycleId]; ok {
|
|
|
// cycleData = val
|
|
|
// } else {
|
|
|
// _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})
|
|
|
// if err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// if len(cycleList) == 0 {
|
|
|
// return nil, nil
|
|
|
// }
|
|
|
// cycleData = cycleList[0]
|
|
|
// }
|
|
|
// return cycleData, nil
|
|
|
// }
|
|
|
|
|
|
// 获取用户数据
|
|
|
func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) {
|
...
|
...
|
|