...
|
...
|
@@ -2,11 +2,12 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
...
|
...
|
@@ -373,7 +374,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf( |
|
|
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
beginDay := assessTemp.BeginTime.Format("2006-01-02")
|
|
|
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
|
|
|
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -419,7 +420,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( |
|
|
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
beginDay := assessTemp.BeginTime.Format("2006-01-02")
|
|
|
beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
|
|
|
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -1118,6 +1119,135 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// SaveSelfAssess 提交自评评估内容
|
|
|
func (srv StaffAssessServeice) SaveSelfAssess(in *command.SaveSelfAssessCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
// 获取员工的评估
|
|
|
assessData, err := assessReps.FindOne(map[string]interface{}{"id": in.AssessId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
|
|
|
}
|
|
|
// 检查截止时间
|
|
|
endTimeInt := assessData.EndTime.Unix()
|
|
|
if endTimeInt < time.Now().Unix() {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "当前环节已过截止时间,提交后无法修改内容")
|
|
|
}
|
|
|
// 检查执行人
|
|
|
if assessData.CompanyId != in.CompanyId || assessData.Executor.UserId != in.ExecutorId {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "当前用户不是评估的执行人")
|
|
|
}
|
|
|
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
|
|
|
//待更新的评估填写信息
|
|
|
var assessContentList []*domain.StaffAssessContent
|
|
|
// 已完成
|
|
|
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{"staffAssessId": assessData.Id})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
|
|
|
}
|
|
|
|
|
|
if len(assessContentList) == 0 {
|
|
|
// 未完成获取评估内容
|
|
|
assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 处理提交上来的数据
|
|
|
paramContentMap := map[string]domain.AssessContent{}
|
|
|
for i, v := range in.AssessContent {
|
|
|
key := fmt.Sprintf("%s-%s", v.Category, v.Name)
|
|
|
paramContentMap[key] = in.AssessContent[i]
|
|
|
}
|
|
|
//更新的评估填写信息
|
|
|
for _, v := range assessContentList {
|
|
|
key := fmt.Sprintf("%s-%s", v.Category, v.Name)
|
|
|
item, ok := paramContentMap[key]
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
if assessData.Types == domain.AssessSelf {
|
|
|
// 每日自评需要检查必填项
|
|
|
if v.Required == domain.NodeRequiredYes && len(item.Value) == 0 {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":必填项")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
v.Value = item.Value
|
|
|
if len(item.Value) > 0 {
|
|
|
// 转换填入的评估值
|
|
|
err = v.TransformValue()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
for ii := range v.Remark {
|
|
|
for _, vvv := range item.Remark {
|
|
|
if v.Remark[ii].Title == vvv.Title {
|
|
|
v.Remark[ii].RemarkText = vvv.RemarkText
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//保存信息
|
|
|
for i := range assessContentList {
|
|
|
_, err = assessContentRepo.Save(assessContentList[i])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估填写内容"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
assessData.Status = domain.StaffAssessCompleted
|
|
|
assessData.UpdatedAt = time.Now()
|
|
|
_, err = assessReps.Save(assessData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
|
|
|
}
|
|
|
|
|
|
// 删除缓存
|
|
|
cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
if _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessData.Id, "limit": 1}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for i := range caches {
|
|
|
if err = cacheRepository.Remove(caches[i].Id); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(in.AssessTaskStages) > 0 {
|
|
|
tsIds := make([]int, 0)
|
|
|
for i := range in.AssessTaskStages {
|
|
|
tsId := in.AssessTaskStages[i].TaskStageId
|
|
|
if tsId > 0 {
|
|
|
tsIds = append(tsIds, tsId)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 里程碑记录
|
|
|
//taskRecordRepository := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
//taskRecordRepository.Find()
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"assessId": assessData.Id,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 获取员工的上级是谁
|
|
|
func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) {
|
|
|
if targetUser.ParentId == 0 {
|
...
|
...
|
|