作者 tangxvhui

暂存

@@ -2,6 +2,10 @@ package service @@ -2,6 +2,10 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
  6 + "strings"
  7 + "time"
  8 +
5 "github.com/linmadan/egglib-go/core/application" 9 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 10 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/adapter" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/adapter"
@@ -11,9 +15,6 @@ import ( @@ -11,9 +15,6 @@ import (
11 taskService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service" 15 taskService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 16 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" 17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
14 - "strconv"  
15 - "strings"  
16 - "time"  
17 ) 18 )
18 19
19 type EvaluationProjectService struct { 20 type EvaluationProjectService struct {
@@ -870,7 +871,6 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo @@ -870,7 +871,6 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
870 } 871 }
871 872
872 func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContext application.TransactionContext, project *domain.EvaluationProject) error { 873 func (rs *EvaluationProjectService) generateEvaluationItemUsed(transactionContext application.TransactionContext, project *domain.EvaluationProject) error {
873 -  
874 var itemUsedList []*domain.EvaluationItemUsed 874 var itemUsedList []*domain.EvaluationItemUsed
875 nowTime := time.Now() 875 nowTime := time.Now()
876 for _, v := range project.Template.LinkNodes { 876 for _, v := range project.Template.LinkNodes {
@@ -948,3 +948,8 @@ outerLoop: @@ -948,3 +948,8 @@ outerLoop:
948 948
949 return map[string]interface{}{"indicatorTypeTask": indicatorTypeTask}, nil 949 return map[string]interface{}{"indicatorTypeTask": indicatorTypeTask}, nil
950 } 950 }
  951 +
  952 +// 生成指标任务
  953 +func (rs *EvaluationProjectService) generateEvaluationTask() error {
  954 + return nil
  955 +}
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 8
9 "github.com/linmadan/egglib-go/core/application" 9 "github.com/linmadan/egglib-go/core/application"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/adapter"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
13 ) 14 )
@@ -106,12 +107,89 @@ func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *comm @@ -106,12 +107,89 @@ func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *comm
106 // 获取关于任务里程碑异常的消息 107 // 获取关于任务里程碑异常的消息
107 // 每日一次 108 // 每日一次
108 func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) { 109 func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
  110 + transactionContext, err := factory.CreateTransactionContext(nil)
  111 + if err != nil {
  112 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  113 + }
  114 + if err := transactionContext.StartTransaction(); err != nil {
  115 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  116 + }
  117 + defer func() {
  118 + _ = transactionContext.RollbackTransaction()
  119 + }()
  120 +
  121 + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
  122 + "transactionContext": transactionContext,
  123 + })
  124 + cnt, _, err := messageRepo.Find(map[string]interface{}{
  125 + "types": domain.MessageTypesTaskStage,
  126 + "targetUserId": param.UserId,
  127 + "limit": 1,
  128 + })
  129 + if err != nil {
  130 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  131 + }
  132 + if cnt > 0 {
  133 + resp := map[string]interface{}{
  134 + "needNotify": false,
  135 + "list": []adapter.MessageListAdapter{},
  136 + }
  137 + return resp, nil
  138 + }
109 139
110 - return nil, nil 140 + // TDOD
  141 + if err := transactionContext.CommitTransaction(); err != nil {
  142 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  143 + }
  144 +
  145 + resp := map[string]interface{}{
  146 + "needNotify": false,
  147 + "list": []adapter.MessageListAdapter{},
  148 + }
  149 + return resp, nil
111 } 150 }
112 151
113 // 获取关于任务反馈碑异常的消息 152 // 获取关于任务反馈碑异常的消息
114 // 每日一次 153 // 每日一次
115 func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) { 154 func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
116 - return nil, nil 155 + transactionContext, err := factory.CreateTransactionContext(nil)
  156 + if err != nil {
  157 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  158 + }
  159 + if err := transactionContext.StartTransaction(); err != nil {
  160 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  161 + }
  162 + defer func() {
  163 + _ = transactionContext.RollbackTransaction()
  164 + }()
  165 +
  166 + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
  167 + "transactionContext": transactionContext,
  168 + })
  169 + cnt, _, err := messageRepo.Find(map[string]interface{}{
  170 + "types": domain.MessageTypesTaskStage,
  171 + "targetUserId": param.UserId,
  172 + "limit": 1,
  173 + })
  174 + if err != nil {
  175 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  176 + }
  177 + if cnt > 0 {
  178 + resp := map[string]interface{}{
  179 + "needNotify": false,
  180 + "list": []adapter.MessageListAdapter{},
  181 + }
  182 + return resp, nil
  183 + }
  184 +
  185 + // TODO
  186 + if err := transactionContext.CommitTransaction(); err != nil {
  187 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  188 + }
  189 +
  190 + resp := map[string]interface{}{
  191 + "needNotify": false,
  192 + "list": []adapter.MessageListAdapter{},
  193 + }
  194 + return resp, nil
117 } 195 }
  1 +package service
  2 +
  3 +import (
  4 + "sort"
  5 + "strconv"
  6 + "time"
  7 +
  8 + "github.com/linmadan/egglib-go/core/application"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
  12 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  13 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
  14 +)
  15 +
  16 +// 定时调用 ,按时下发员工的需要填写的评估
  17 +// 根据项目评估的配置,创建员工的评估任务
  18 +func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
  19 + log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
  20 + "param": param,
  21 + })
  22 + assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
  23 + "transactionContext": transactionContext,
  24 + })
  25 + taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
  26 + if err != nil {
  27 + return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
  28 + }
  29 + taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
  30 + if err != nil {
  31 + return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
  32 + }
  33 + nowTime := time.Now()
  34 +
  35 + assessTaskData := &domain.StaffAssessTask{
  36 + Id: 0,
  37 + CompanyId: param.CompanyId,
  38 + EvaluationProjectId: param.EvaluationProjectId,
  39 + EvaluationProjectName: param.EvaluationProjectName,
  40 + CycleId: param.CycleId,
  41 + CycleName: param.CycleName,
  42 + BeginTime: taskBeginTime,
  43 + EndTime: taskEndTime,
  44 + StepList: []domain.AssessTaskStep{},
  45 + ExecutorId: []int{},
  46 + CreatedAt: nowTime,
  47 + UpdatedAt: nowTime,
  48 + DeletedAt: nil,
  49 + BeginDay: taskBeginTime.Local().Format("2006-01-02"),
  50 + }
  51 + executorIds := []int{} //提取评估的参与人id
  52 + executorIdMap := map[int]struct{}{} //过滤重复的用户
  53 + //从入参中提取参与人
  54 + for _, v := range param.ExecutorId {
  55 + if _, ok := executorIdMap[v]; ok {
  56 + continue
  57 + }
  58 + executorIdMap[v] = struct{}{}
  59 + executorIds = append(executorIds, v)
  60 + }
  61 + assessTaskData.ExecutorId = executorIds
  62 + for _, v := range param.StepList {
  63 + stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
  64 + if err != nil {
  65 + return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
  66 + }
  67 + stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
  68 + if err != nil {
  69 + return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
  70 + }
  71 + step := domain.AssessTaskStep{
  72 + SortBy: v.SortBy,
  73 + LinkNodeId: v.LinkNodeId,
  74 + LinkNodeName: v.LinkNodeName,
  75 + LinkNodeType: v.LinkNodeType,
  76 + BeginTime: stepBeginTime,
  77 + EndTime: stepEndTime,
  78 + }
  79 + assessTaskData.StepList = append(assessTaskData.StepList, step)
  80 + }
  81 + //添加员工的节点任务
  82 + assessList, err := srv.buildStaffAssess(transactionContext, assessTaskData)
  83 + if err != nil {
  84 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
  85 + }
  86 +
  87 + //合并项目评估的新旧数据
  88 + _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
  89 + "evaluationProjectId": param.EvaluationProjectId,
  90 + "beginDay": taskBeginTime.Local().Format("2006-01-02"),
  91 + })
  92 + if err != nil {
  93 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
  94 + }
  95 +
  96 + if len(assassessTaskList) > 0 {
  97 + //旧数据中提取参与人
  98 + for _, v := range assassessTaskList[0].ExecutorId {
  99 + if _, ok := executorIdMap[v]; ok {
  100 + continue
  101 + }
  102 + executorIdMap[v] = struct{}{}
  103 + executorIds = append(executorIds, v)
  104 + }
  105 + assassessTaskList[0].UpdatedAt = time.Now()
  106 + assassessTaskList[0].ExecutorId = executorIds
  107 + //更新步骤
  108 + assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
  109 + for _, val := range assessTaskData.StepList {
  110 + hasFound := false
  111 + for _, val2 := range assassessTaskList[0].StepList {
  112 + if val.LinkNodeType == val2.LinkNodeType {
  113 + hasFound = true
  114 + break
  115 + }
  116 + }
  117 + if !hasFound {
  118 + assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
  119 + }
  120 + }
  121 + assessTaskData = assassessTaskList[0]
  122 + //排序流程环节
  123 + }
  124 + stepList := domain.SortTaskStep(assessTaskData.StepList)
  125 + sort.Sort(stepList)
  126 + _, err = assessTaskRepo.Save(assessTaskData)
  127 + if err != nil {
  128 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
  129 + }
  130 +
  131 + //保存 员工的需要填写的每日评估
  132 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  133 + "transactionContext": transactionContext,
  134 + })
  135 + for i := range assessList {
  136 + assessList[i].StaffAssessTaskId = assessTaskData.Id
  137 + _, err = assessRepo.Save(&assessList[i])
  138 + if err != nil {
  139 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
  140 + }
  141 + if assessList[i].Types == domain.AssessSelf {
  142 + //添加待发送的短信通知
  143 + notify.AddNotifyStaffAssess(&assessList[i])
  144 + //添加 指标任务
  145 + }
  146 + }
  147 + return map[string]interface{}{
  148 + "assessTaskId": assessTaskData.Id,
  149 + }, nil
  150 +}
  151 +
  152 +// 添加节点任务
  153 +func (srv StaffAssessServeice) buildStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
  154 + selfUserId := []int{} //评估的参与人
  155 + userIdMap := map[int]struct{}{} //过滤重复的用户
  156 + for _, v := range param.ExecutorId {
  157 + if _, ok := userIdMap[v]; ok {
  158 + continue
  159 + }
  160 + selfUserId = append(selfUserId, v)
  161 + }
  162 + // 获取用户的信息
  163 + if len(selfUserId) == 0 {
  164 + log.Logger.Error("createStaffAssess", map[string]interface{}{
  165 + "param": param,
  166 + })
  167 + return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
  168 + }
  169 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  170 + "transactionContext": transactionContext,
  171 + })
  172 + //获取员工信息
  173 + _, userList, err := userRepo.Find(map[string]interface{}{
  174 + "ids": selfUserId,
  175 + "status": 1,
  176 + })
  177 + if err != nil {
  178 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
  179 + }
  180 + departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
  181 + "transactionContext": transactionContext,
  182 + })
  183 + //获取用户的部门
  184 + userDepartmentMap := map[int64][]*domain.Department{}
  185 + for _, v := range userList {
  186 + if len(v.DepartmentId) == 0 {
  187 + continue
  188 + }
  189 + _, departmemtList, err := departmentRepo.Find(map[string]interface{}{
  190 + "ids": v.DepartmentId,
  191 + })
  192 + if err != nil {
  193 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
  194 + }
  195 + userDepartmentMap[v.Id] = departmemtList
  196 + }
  197 + assessList := []domain.StaffAssess{}
  198 + //数据样板
  199 + stepSelfTemp := domain.StaffAssess{
  200 + Id: 0,
  201 + CompanyId: param.CompanyId,
  202 + EvaluationProjectId: param.EvaluationProjectId,
  203 + EvaluationProjectName: param.EvaluationProjectName,
  204 + CycleId: param.CycleId,
  205 + CycleName: param.CycleName,
  206 + StaffAssessTaskId: param.Id,
  207 + // TargetUser: domain.StaffDesc{},
  208 + // TargetDepartment: nil,
  209 + // Executor: domain.StaffDesc{},
  210 + Types: "",
  211 + // LinkNodeId: v.LinkNodeId,
  212 + Status: domain.StaffAssessUncompleted,
  213 + // BeginTime: time.Time{},
  214 + // EndTime: time.Time{},
  215 + CreatedAt: param.CreatedAt,
  216 + UpdatedAt: param.UpdatedAt,
  217 + DeletedAt: nil,
  218 + }
  219 + for _, v := range param.StepList {
  220 + if v.LinkNodeType == domain.LinkNodeSelfAssessment {
  221 + //员工自评
  222 + stepSelfTemp.BeginTime = v.BeginTime
  223 + stepSelfTemp.EndTime = v.EndTime
  224 + stepSelfTemp.LinkNodeId = v.LinkNodeId
  225 + stepSelfTemp.LinkNodeName = v.LinkNodeName
  226 + stepSelfTemp.Types = domain.AssessSelf
  227 + assessListTemp, err := srv.buildStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
  228 + if err != nil {
  229 + return nil, err
  230 + }
  231 + assessList = append(assessList, assessListTemp...)
  232 + }
  233 + if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
  234 + // 创建上级评估
  235 + stepSelfTemp.BeginTime = v.BeginTime
  236 + stepSelfTemp.EndTime = v.EndTime
  237 + stepSelfTemp.LinkNodeId = v.LinkNodeId
  238 + stepSelfTemp.LinkNodeName = v.LinkNodeName
  239 + stepSelfTemp.Types = domain.AssessSuper
  240 + assessListTemp2, err := srv.buildStaffAssessSupper(stepSelfTemp, userList, userDepartmentMap)
  241 + if err != nil {
  242 + return nil, err
  243 + }
  244 + assessList = append(assessList, assessListTemp2...)
  245 + }
  246 + }
  247 + return assessList, nil
  248 +}
  249 +
  250 +// 构建员工自评
  251 +func (srv StaffAssessServeice) buildStaffAssessSelf(
  252 + assessTemp domain.StaffAssess,
  253 + userList []*domain.User,
  254 + userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
  255 + transactionContext, err := factory.CreateTransactionContext(nil)
  256 + if err != nil {
  257 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  258 + }
  259 + if err := transactionContext.StartTransaction(); err != nil {
  260 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  261 + }
  262 + defer func() {
  263 + _ = transactionContext.RollbackTransaction()
  264 + }()
  265 +
  266 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  267 + "transactionContext": transactionContext,
  268 + })
  269 + beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
  270 + _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
  271 + if err != nil {
  272 + return nil, err
  273 + }
  274 + userMapReal := map[int]*domain.User{}
  275 + for _, val := range userList {
  276 + userMapReal[int(val.Id)] = val
  277 + }
  278 + for _, val := range assessListOld {
  279 + delete(userMapReal, val.TargetUser.UserId)
  280 + }
  281 + assessListNew := []domain.StaffAssess{}
  282 + for _, usr := range userMapReal {
  283 + assessTemp.TargetUser = domain.StaffDesc{
  284 + UserId: int(usr.Id),
  285 + Account: usr.Account,
  286 + UserName: usr.Name,
  287 + }
  288 + assessTemp.Executor = domain.StaffDesc{
  289 + UserId: int(usr.Id),
  290 + Account: usr.Account,
  291 + UserName: usr.Name,
  292 + }
  293 + if depList, ok := userDepartmentMap[usr.Id]; ok {
  294 + for _, dep := range depList {
  295 + assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
  296 + DepartmentId: int(dep.Id),
  297 + DepartmentName: dep.Name,
  298 + })
  299 + }
  300 + }
  301 + assessListNew = append(assessListNew, assessTemp)
  302 + }
  303 + if err := transactionContext.CommitTransaction(); err != nil {
  304 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  305 + }
  306 + return assessListNew, nil
  307 +}
  308 +
  309 +// 构建员工的上级评估
  310 +func (srv StaffAssessServeice) buildStaffAssessSupper(
  311 + assessTemp domain.StaffAssess,
  312 + userList []*domain.User,
  313 + userDepartmentMap map[int64][]*domain.Department,
  314 +) ([]domain.StaffAssess, error) {
  315 +
  316 + transactionContext, err := factory.CreateTransactionContext(nil)
  317 + if err != nil {
  318 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  319 + }
  320 + if err := transactionContext.StartTransaction(); err != nil {
  321 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  322 + }
  323 + defer func() {
  324 + _ = transactionContext.RollbackTransaction()
  325 + }()
  326 + assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  327 + "transactionContext": transactionContext,
  328 + })
  329 + beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
  330 + _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
  331 + if err != nil {
  332 + return nil, err
  333 + }
  334 + userMapReal := map[int]*domain.User{}
  335 + for _, val := range userList {
  336 + userMapReal[int(val.Id)] = val
  337 + }
  338 + for _, val := range assessListOld {
  339 + delete(userMapReal, val.TargetUser.UserId)
  340 + }
  341 +
  342 + var assessListNew []domain.StaffAssess
  343 + for _, v := range userMapReal {
  344 + //获取上级
  345 + chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
  346 + if err != nil {
  347 + return nil, err
  348 + }
  349 + if len(chargeUserList) == 0 {
  350 + continue
  351 + }
  352 + for _, v2 := range chargeUserList {
  353 + assessTemp.TargetUser = domain.StaffDesc{
  354 + UserId: int(v.Id),
  355 + Account: v.Account,
  356 + UserName: v.Name,
  357 + }
  358 + assessTemp.Executor = domain.StaffDesc{
  359 + UserId: int(v2.Id),
  360 + Account: v2.Account,
  361 + UserName: v2.Name,
  362 + }
  363 + targetDepartment := []domain.StaffDepartment{}
  364 + if departmentList, ok := userDepartmentMap[v.Id]; ok {
  365 + for _, department := range departmentList {
  366 + targetDepartment = append(targetDepartment, domain.StaffDepartment{
  367 + DepartmentId: int(department.Id),
  368 + DepartmentName: department.Name,
  369 + })
  370 + }
  371 + }
  372 + assessTemp.TargetDepartment = targetDepartment
  373 + assessListNew = append(assessListNew, assessTemp)
  374 + }
  375 + }
  376 + if err := transactionContext.CommitTransaction(); err != nil {
  377 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  378 + }
  379 + return assessListNew, nil
  380 +}
  381 +
  382 +// 按照评估模板中指标类型,创建里程碑任务
  383 +// staffAssess 每日自评评估
  384 +func (srv StaffAssessCacheService) buildTaskRecord(staffAssess *domain.StaffAssess) ([]*domain.TaskRecord, error) {
  385 + transactionContext, err := factory.CreateTransactionContext(nil)
  386 + if err != nil {
  387 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  388 + }
  389 + if err := transactionContext.StartTransaction(); err != nil {
  390 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  391 + }
  392 + defer func() {
  393 + _ = transactionContext.RollbackTransaction()
  394 + }()
  395 + projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
  396 + "transactionContext": transactionContext,
  397 + })
  398 + itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  399 + "transactionContext": transactionContext,
  400 + })
  401 + projectData, err := projectRepo.FindOne(map[string]interface{}{"id": staffAssess.EvaluationProjectId})
  402 + if err != nil {
  403 + return nil, application.ThrowError(application.ARG_ERROR, "获取项目EvaluationProject信息"+err.Error())
  404 + }
  405 + // projectData.PrincipalId
  406 + userIdstr := strconv.Itoa(staffAssess.Executor.UserId)
  407 + if projectData.PrincipalId != userIdstr {
  408 + return nil, nil
  409 + }
  410 + _, evaluationItem, err := itemUsedRepo.Find(map[string]interface{}{
  411 + "indicatorType": domain.IndicatorTypeTask,
  412 + "evaluationProjectId": projectData.Id,
  413 + })
  414 +
  415 + if err != nil {
  416 + return nil, application.ThrowError(application.ARG_ERROR, "获取评估项EvaluationItemUsed信息"+err.Error())
  417 + }
  418 +
  419 + _ = evaluationItem
  420 +
  421 + if err := transactionContext.CommitTransaction(); err != nil {
  422 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  423 + }
  424 + return nil, nil
  425 +}
@@ -2,7 +2,6 @@ package service @@ -2,7 +2,6 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "sort"  
6 "strconv" 5 "strconv"
7 "time" 6 "time"
8 7
@@ -12,7 +11,6 @@ import ( @@ -12,7 +11,6 @@ import (
12 "github.com/linmadan/egglib-go/core/application" 11 "github.com/linmadan/egglib-go/core/application"
13 "github.com/linmadan/egglib-go/utils/tool_funs" 12 "github.com/linmadan/egglib-go/utils/tool_funs"
14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
15 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"  
16 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter" 14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
17 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
18 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 16 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
@@ -135,342 +133,342 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) @@ -135,342 +133,342 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
135 } 133 }
136 134
137 // 根据项目评估的配置,创建员工的评估任务 135 // 根据项目评估的配置,创建员工的评估任务
138 -func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {  
139 - log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{  
140 - "param": param,  
141 - })  
142 - assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{  
143 - "transactionContext": transactionContext,  
144 - })  
145 - taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)  
146 - if err != nil {  
147 - return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)  
148 - }  
149 - taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)  
150 - if err != nil {  
151 - return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)  
152 - }  
153 - nowTime := time.Now()  
154 -  
155 - assessTaskData := &domain.StaffAssessTask{  
156 - Id: 0,  
157 - CompanyId: param.CompanyId,  
158 - EvaluationProjectId: param.EvaluationProjectId,  
159 - EvaluationProjectName: param.EvaluationProjectName,  
160 - CycleId: param.CycleId,  
161 - CycleName: param.CycleName,  
162 - BeginTime: taskBeginTime,  
163 - EndTime: taskEndTime,  
164 - StepList: []domain.AssessTaskStep{},  
165 - ExecutorId: []int{},  
166 - CreatedAt: nowTime,  
167 - UpdatedAt: nowTime,  
168 - DeletedAt: nil,  
169 - BeginDay: taskBeginTime.Local().Format("2006-01-02"),  
170 - }  
171 - executorIds := []int{} //提取评估的参与人id  
172 - executorIdMap := map[int]struct{}{} //过滤重复的用户  
173 - //从入参中提取参与人  
174 - for _, v := range param.ExecutorId {  
175 - if _, ok := executorIdMap[v]; ok {  
176 - continue  
177 - }  
178 - executorIdMap[v] = struct{}{}  
179 - executorIds = append(executorIds, v)  
180 - }  
181 - assessTaskData.ExecutorId = executorIds  
182 - for _, v := range param.StepList {  
183 - stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)  
184 - if err != nil {  
185 - return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)  
186 - }  
187 - stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)  
188 - if err != nil {  
189 - return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)  
190 - }  
191 - step := domain.AssessTaskStep{  
192 - SortBy: v.SortBy,  
193 - LinkNodeId: v.LinkNodeId,  
194 - LinkNodeName: v.LinkNodeName,  
195 - LinkNodeType: v.LinkNodeType,  
196 - BeginTime: stepBeginTime,  
197 - EndTime: stepEndTime,  
198 - }  
199 - assessTaskData.StepList = append(assessTaskData.StepList, step)  
200 - }  
201 - //添加员工的节点任务  
202 - assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)  
203 - if err != nil {  
204 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())  
205 - } 136 +// func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
  137 +// log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
  138 +// "param": param,
  139 +// })
  140 +// assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
  141 +// "transactionContext": transactionContext,
  142 +// })
  143 +// taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
  144 +// if err != nil {
  145 +// return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
  146 +// }
  147 +// taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
  148 +// if err != nil {
  149 +// return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
  150 +// }
  151 +// nowTime := time.Now()
  152 +
  153 +// assessTaskData := &domain.StaffAssessTask{
  154 +// Id: 0,
  155 +// CompanyId: param.CompanyId,
  156 +// EvaluationProjectId: param.EvaluationProjectId,
  157 +// EvaluationProjectName: param.EvaluationProjectName,
  158 +// CycleId: param.CycleId,
  159 +// CycleName: param.CycleName,
  160 +// BeginTime: taskBeginTime,
  161 +// EndTime: taskEndTime,
  162 +// StepList: []domain.AssessTaskStep{},
  163 +// ExecutorId: []int{},
  164 +// CreatedAt: nowTime,
  165 +// UpdatedAt: nowTime,
  166 +// DeletedAt: nil,
  167 +// BeginDay: taskBeginTime.Local().Format("2006-01-02"),
  168 +// }
  169 +// executorIds := []int{} //提取评估的参与人id
  170 +// executorIdMap := map[int]struct{}{} //过滤重复的用户
  171 +// //从入参中提取参与人
  172 +// for _, v := range param.ExecutorId {
  173 +// if _, ok := executorIdMap[v]; ok {
  174 +// continue
  175 +// }
  176 +// executorIdMap[v] = struct{}{}
  177 +// executorIds = append(executorIds, v)
  178 +// }
  179 +// assessTaskData.ExecutorId = executorIds
  180 +// for _, v := range param.StepList {
  181 +// stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
  182 +// if err != nil {
  183 +// return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
  184 +// }
  185 +// stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
  186 +// if err != nil {
  187 +// return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
  188 +// }
  189 +// step := domain.AssessTaskStep{
  190 +// SortBy: v.SortBy,
  191 +// LinkNodeId: v.LinkNodeId,
  192 +// LinkNodeName: v.LinkNodeName,
  193 +// LinkNodeType: v.LinkNodeType,
  194 +// BeginTime: stepBeginTime,
  195 +// EndTime: stepEndTime,
  196 +// }
  197 +// assessTaskData.StepList = append(assessTaskData.StepList, step)
  198 +// }
  199 +// //添加员工的节点任务
  200 +// assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
  201 +// if err != nil {
  202 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
  203 +// }
206 204
207 - //合并项目评估的新旧数据  
208 - _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{  
209 - "evaluationProjectId": param.EvaluationProjectId,  
210 - "beginDay": taskBeginTime.Local().Format("2006-01-02"),  
211 - })  
212 - if err != nil {  
213 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())  
214 - } 205 +// //合并项目评估的新旧数据
  206 +// _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
  207 +// "evaluationProjectId": param.EvaluationProjectId,
  208 +// "beginDay": taskBeginTime.Local().Format("2006-01-02"),
  209 +// })
  210 +// if err != nil {
  211 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
  212 +// }
215 213
216 - if len(assassessTaskList) > 0 {  
217 - //就数据中提取参与人  
218 - for _, v := range assessTaskData.ExecutorId {  
219 - if _, ok := executorIdMap[v]; ok {  
220 - continue  
221 - }  
222 - executorIdMap[v] = struct{}{}  
223 - executorIds = append(executorIds, v)  
224 - }  
225 - assassessTaskList[0].UpdatedAt = time.Now()  
226 - assassessTaskList[0].ExecutorId = executorIds  
227 - //更新步骤  
228 - assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)  
229 - for _, val := range assessTaskData.StepList {  
230 - hasFound := false  
231 - for _, val2 := range assassessTaskList[0].StepList {  
232 - if val.LinkNodeType == val2.LinkNodeType {  
233 - hasFound = true  
234 - break  
235 - }  
236 - }  
237 - if !hasFound {  
238 - assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)  
239 - }  
240 - }  
241 - assessTaskData = assassessTaskList[0]  
242 - //排序流程环节  
243 - }  
244 - stepList := domain.SortTaskStep(assessTaskData.StepList)  
245 - sort.Sort(stepList)  
246 - _, err = assessTaskRepo.Save(assessTaskData)  
247 - if err != nil {  
248 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())  
249 - } 214 +// if len(assassessTaskList) > 0 {
  215 +// //就数据中提取参与人
  216 +// for _, v := range assessTaskData.ExecutorId {
  217 +// if _, ok := executorIdMap[v]; ok {
  218 +// continue
  219 +// }
  220 +// executorIdMap[v] = struct{}{}
  221 +// executorIds = append(executorIds, v)
  222 +// }
  223 +// assassessTaskList[0].UpdatedAt = time.Now()
  224 +// assassessTaskList[0].ExecutorId = executorIds
  225 +// //更新步骤
  226 +// assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
  227 +// for _, val := range assessTaskData.StepList {
  228 +// hasFound := false
  229 +// for _, val2 := range assassessTaskList[0].StepList {
  230 +// if val.LinkNodeType == val2.LinkNodeType {
  231 +// hasFound = true
  232 +// break
  233 +// }
  234 +// }
  235 +// if !hasFound {
  236 +// assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
  237 +// }
  238 +// }
  239 +// assessTaskData = assassessTaskList[0]
  240 +// //排序流程环节
  241 +// }
  242 +// stepList := domain.SortTaskStep(assessTaskData.StepList)
  243 +// sort.Sort(stepList)
  244 +// _, err = assessTaskRepo.Save(assessTaskData)
  245 +// if err != nil {
  246 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
  247 +// }
250 248
251 - //保存 员工的评估任务  
252 - assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{  
253 - "transactionContext": transactionContext,  
254 - })  
255 - for i := range assessList {  
256 - assessList[i].StaffAssessTaskId = assessTaskData.Id  
257 - _, err = assessRepo.Save(&assessList[i])  
258 - if err != nil {  
259 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())  
260 - }  
261 - if assessList[i].Types == domain.AssessSelf {  
262 - //添加待发送的短信通知  
263 - notify.AddNotifyStaffAssess(&assessList[i])  
264 - }  
265 - }  
266 - return map[string]interface{}{  
267 - "assessTaskId": assessTaskData.Id,  
268 - }, nil  
269 -} 249 +// //保存 员工的评估任务
  250 +// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  251 +// "transactionContext": transactionContext,
  252 +// })
  253 +// for i := range assessList {
  254 +// assessList[i].StaffAssessTaskId = assessTaskData.Id
  255 +// _, err = assessRepo.Save(&assessList[i])
  256 +// if err != nil {
  257 +// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
  258 +// }
  259 +// if assessList[i].Types == domain.AssessSelf {
  260 +// //添加待发送的短信通知
  261 +// notify.AddNotifyStaffAssess(&assessList[i])
  262 +// }
  263 +// }
  264 +// return map[string]interface{}{
  265 +// "assessTaskId": assessTaskData.Id,
  266 +// }, nil
  267 +// }
270 268
271 // 添加节点任务 269 // 添加节点任务
272 -func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {  
273 - selfUserId := []int{} //评估的参与人  
274 - userIdMap := map[int]struct{}{} //过滤重复的用户  
275 - for _, v := range param.ExecutorId {  
276 - if _, ok := userIdMap[v]; ok {  
277 - continue  
278 - }  
279 - selfUserId = append(selfUserId, v)  
280 - }  
281 - // 获取用户的信息  
282 - if len(selfUserId) == 0 {  
283 - log.Logger.Error("createStaffAssess", map[string]interface{}{  
284 - "param": param,  
285 - })  
286 - return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")  
287 - }  
288 - userRepo := factory.CreateUserRepository(map[string]interface{}{  
289 - "transactionContext": transactionContext,  
290 - })  
291 - //获取员工信息  
292 - _, userList, err := userRepo.Find(map[string]interface{}{  
293 - "ids": selfUserId,  
294 - "status": 1,  
295 - })  
296 - if err != nil {  
297 - return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())  
298 - }  
299 - departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{  
300 - "transactionContext": transactionContext,  
301 - })  
302 - //获取用户的部门  
303 - userDepartmentMap := map[int64][]*domain.Department{}  
304 - for _, v := range userList {  
305 - if len(v.DepartmentId) == 0 {  
306 - continue  
307 - }  
308 - _, departmemtList, err := departmentRepo.Find(map[string]interface{}{  
309 - "ids": v.DepartmentId,  
310 - })  
311 - if err != nil {  
312 - return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())  
313 - }  
314 - userDepartmentMap[v.Id] = departmemtList  
315 - }  
316 - assessList := []domain.StaffAssess{}  
317 - //数据样板  
318 - stepSelfTemp := domain.StaffAssess{  
319 - Id: 0,  
320 - CompanyId: param.CompanyId,  
321 - EvaluationProjectId: param.EvaluationProjectId,  
322 - EvaluationProjectName: param.EvaluationProjectName,  
323 - CycleId: param.CycleId,  
324 - CycleName: param.CycleName,  
325 - StaffAssessTaskId: param.Id,  
326 - // TargetUser: domain.StaffDesc{},  
327 - // TargetDepartment: nil,  
328 - // Executor: domain.StaffDesc{},  
329 - Types: "",  
330 - // LinkNodeId: v.LinkNodeId,  
331 - Status: domain.StaffAssessUncompleted,  
332 - // BeginTime: time.Time{},  
333 - // EndTime: time.Time{},  
334 - CreatedAt: param.CreatedAt,  
335 - UpdatedAt: param.UpdatedAt,  
336 - DeletedAt: nil,  
337 - }  
338 - for _, v := range param.StepList {  
339 - if v.LinkNodeType == domain.LinkNodeSelfAssessment {  
340 - //员工自评  
341 - stepSelfTemp.BeginTime = v.BeginTime  
342 - stepSelfTemp.EndTime = v.EndTime  
343 - stepSelfTemp.LinkNodeId = v.LinkNodeId  
344 - stepSelfTemp.LinkNodeName = v.LinkNodeName  
345 - stepSelfTemp.Types = domain.AssessSelf  
346 - assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)  
347 - if err != nil {  
348 - return nil, err  
349 - }  
350 - assessList = append(assessList, assessListTemp...)  
351 - }  
352 - if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {  
353 - // 创建上级评估  
354 - stepSelfTemp.BeginTime = v.BeginTime  
355 - stepSelfTemp.EndTime = v.EndTime  
356 - stepSelfTemp.LinkNodeId = v.LinkNodeId  
357 - stepSelfTemp.LinkNodeName = v.LinkNodeName  
358 - stepSelfTemp.Types = domain.AssessSuper  
359 - assessListTemp2, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)  
360 - if err != nil {  
361 - return nil, err  
362 - }  
363 - assessList = append(assessList, assessListTemp2...)  
364 - }  
365 - }  
366 - return assessList, nil  
367 -} 270 +// func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
  271 +// selfUserId := []int{} //评估的参与人
  272 +// userIdMap := map[int]struct{}{} //过滤重复的用户
  273 +// for _, v := range param.ExecutorId {
  274 +// if _, ok := userIdMap[v]; ok {
  275 +// continue
  276 +// }
  277 +// selfUserId = append(selfUserId, v)
  278 +// }
  279 +// // 获取用户的信息
  280 +// if len(selfUserId) == 0 {
  281 +// log.Logger.Error("createStaffAssess", map[string]interface{}{
  282 +// "param": param,
  283 +// })
  284 +// return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
  285 +// }
  286 +// userRepo := factory.CreateUserRepository(map[string]interface{}{
  287 +// "transactionContext": transactionContext,
  288 +// })
  289 +// //获取员工信息
  290 +// _, userList, err := userRepo.Find(map[string]interface{}{
  291 +// "ids": selfUserId,
  292 +// "status": 1,
  293 +// })
  294 +// if err != nil {
  295 +// return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
  296 +// }
  297 +// departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
  298 +// "transactionContext": transactionContext,
  299 +// })
  300 +// //获取用户的部门
  301 +// userDepartmentMap := map[int64][]*domain.Department{}
  302 +// for _, v := range userList {
  303 +// if len(v.DepartmentId) == 0 {
  304 +// continue
  305 +// }
  306 +// _, departmemtList, err := departmentRepo.Find(map[string]interface{}{
  307 +// "ids": v.DepartmentId,
  308 +// })
  309 +// if err != nil {
  310 +// return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
  311 +// }
  312 +// userDepartmentMap[v.Id] = departmemtList
  313 +// }
  314 +// assessList := []domain.StaffAssess{}
  315 +// //数据样板
  316 +// stepSelfTemp := domain.StaffAssess{
  317 +// Id: 0,
  318 +// CompanyId: param.CompanyId,
  319 +// EvaluationProjectId: param.EvaluationProjectId,
  320 +// EvaluationProjectName: param.EvaluationProjectName,
  321 +// CycleId: param.CycleId,
  322 +// CycleName: param.CycleName,
  323 +// StaffAssessTaskId: param.Id,
  324 +// // TargetUser: domain.StaffDesc{},
  325 +// // TargetDepartment: nil,
  326 +// // Executor: domain.StaffDesc{},
  327 +// Types: "",
  328 +// // LinkNodeId: v.LinkNodeId,
  329 +// Status: domain.StaffAssessUncompleted,
  330 +// // BeginTime: time.Time{},
  331 +// // EndTime: time.Time{},
  332 +// CreatedAt: param.CreatedAt,
  333 +// UpdatedAt: param.UpdatedAt,
  334 +// DeletedAt: nil,
  335 +// }
  336 +// for _, v := range param.StepList {
  337 +// if v.LinkNodeType == domain.LinkNodeSelfAssessment {
  338 +// //员工自评
  339 +// stepSelfTemp.BeginTime = v.BeginTime
  340 +// stepSelfTemp.EndTime = v.EndTime
  341 +// stepSelfTemp.LinkNodeId = v.LinkNodeId
  342 +// stepSelfTemp.LinkNodeName = v.LinkNodeName
  343 +// stepSelfTemp.Types = domain.AssessSelf
  344 +// assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)
  345 +// if err != nil {
  346 +// return nil, err
  347 +// }
  348 +// assessList = append(assessList, assessListTemp...)
  349 +// }
  350 +// if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
  351 +// // 创建上级评估
  352 +// stepSelfTemp.BeginTime = v.BeginTime
  353 +// stepSelfTemp.EndTime = v.EndTime
  354 +// stepSelfTemp.LinkNodeId = v.LinkNodeId
  355 +// stepSelfTemp.LinkNodeName = v.LinkNodeName
  356 +// stepSelfTemp.Types = domain.AssessSuper
  357 +// assessListTemp2, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
  358 +// if err != nil {
  359 +// return nil, err
  360 +// }
  361 +// assessList = append(assessList, assessListTemp2...)
  362 +// }
  363 +// }
  364 +// return assessList, nil
  365 +// }
368 366
369 // 构建员工自评 367 // 构建员工自评
370 -func (srv StaffAssessServeice) createStaffAssessSelf(  
371 - transactionContext application.TransactionContext,  
372 - assessTemp domain.StaffAssess,  
373 - userList []*domain.User,  
374 - userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {  
375 - assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{  
376 - "transactionContext": transactionContext,  
377 - })  
378 - beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")  
379 - _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})  
380 - if err != nil {  
381 - return nil, err  
382 - }  
383 - userMapReal := map[int]*domain.User{}  
384 - for _, val := range userList {  
385 - userMapReal[int(val.Id)] = val  
386 - }  
387 - for _, val := range assessListOld {  
388 - delete(userMapReal, val.TargetUser.UserId)  
389 - }  
390 - assessListNew := []domain.StaffAssess{}  
391 - for _, usr := range userMapReal {  
392 - assessTemp.TargetUser = domain.StaffDesc{  
393 - UserId: int(usr.Id),  
394 - Account: usr.Account,  
395 - UserName: usr.Name,  
396 - }  
397 - assessTemp.Executor = domain.StaffDesc{  
398 - UserId: int(usr.Id),  
399 - Account: usr.Account,  
400 - UserName: usr.Name,  
401 - }  
402 - if depList, ok := userDepartmentMap[usr.Id]; ok {  
403 - for _, dep := range depList {  
404 - assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{  
405 - DepartmentId: int(dep.Id),  
406 - DepartmentName: dep.Name,  
407 - })  
408 - }  
409 - }  
410 - assessListNew = append(assessListNew, assessTemp)  
411 - }  
412 - return assessListNew, nil  
413 -} 368 +// func (srv StaffAssessServeice) createStaffAssessSelf(
  369 +// transactionContext application.TransactionContext,
  370 +// assessTemp domain.StaffAssess,
  371 +// userList []*domain.User,
  372 +// userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
  373 +// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  374 +// "transactionContext": transactionContext,
  375 +// })
  376 +// beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
  377 +// _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
  378 +// if err != nil {
  379 +// return nil, err
  380 +// }
  381 +// userMapReal := map[int]*domain.User{}
  382 +// for _, val := range userList {
  383 +// userMapReal[int(val.Id)] = val
  384 +// }
  385 +// for _, val := range assessListOld {
  386 +// delete(userMapReal, val.TargetUser.UserId)
  387 +// }
  388 +// assessListNew := []domain.StaffAssess{}
  389 +// for _, usr := range userMapReal {
  390 +// assessTemp.TargetUser = domain.StaffDesc{
  391 +// UserId: int(usr.Id),
  392 +// Account: usr.Account,
  393 +// UserName: usr.Name,
  394 +// }
  395 +// assessTemp.Executor = domain.StaffDesc{
  396 +// UserId: int(usr.Id),
  397 +// Account: usr.Account,
  398 +// UserName: usr.Name,
  399 +// }
  400 +// if depList, ok := userDepartmentMap[usr.Id]; ok {
  401 +// for _, dep := range depList {
  402 +// assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
  403 +// DepartmentId: int(dep.Id),
  404 +// DepartmentName: dep.Name,
  405 +// })
  406 +// }
  407 +// }
  408 +// assessListNew = append(assessListNew, assessTemp)
  409 +// }
  410 +// return assessListNew, nil
  411 +// }
414 412
415 // 构建员工的上级评估 413 // 构建员工的上级评估
416 -func (srv StaffAssessServeice) createStaffAssessSupper(  
417 - transactionContext application.TransactionContext,  
418 - assessTemp domain.StaffAssess,  
419 - userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,  
420 -) ([]domain.StaffAssess, error) {  
421 - assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{  
422 - "transactionContext": transactionContext,  
423 - })  
424 - beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")  
425 - _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})  
426 - if err != nil {  
427 - return nil, err  
428 - }  
429 - userMapReal := map[int]*domain.User{}  
430 - for _, val := range userList {  
431 - userMapReal[int(val.Id)] = val  
432 - }  
433 - for _, val := range assessListOld {  
434 - delete(userMapReal, val.TargetUser.UserId)  
435 - } 414 +// func (srv StaffAssessServeice) createStaffAssessSupper(
  415 +// transactionContext application.TransactionContext,
  416 +// assessTemp domain.StaffAssess,
  417 +// userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
  418 +// ) ([]domain.StaffAssess, error) {
  419 +// assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
  420 +// "transactionContext": transactionContext,
  421 +// })
  422 +// beginDay := assessTemp.BeginTime.Local().Format("2006-01-02")
  423 +// _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
  424 +// if err != nil {
  425 +// return nil, err
  426 +// }
  427 +// userMapReal := map[int]*domain.User{}
  428 +// for _, val := range userList {
  429 +// userMapReal[int(val.Id)] = val
  430 +// }
  431 +// for _, val := range assessListOld {
  432 +// delete(userMapReal, val.TargetUser.UserId)
  433 +// }
436 434
437 - var assessListNew []domain.StaffAssess  
438 - for _, v := range userMapReal {  
439 - //获取上级  
440 - chargeUserList, err := srv.getStaffSuper(transactionContext, *v)  
441 - if err != nil {  
442 - return nil, err  
443 - }  
444 - if len(chargeUserList) == 0 {  
445 - continue  
446 - }  
447 - for _, v2 := range chargeUserList {  
448 - assessTemp.TargetUser = domain.StaffDesc{  
449 - UserId: int(v.Id),  
450 - Account: v.Account,  
451 - UserName: v.Name,  
452 - }  
453 - assessTemp.Executor = domain.StaffDesc{  
454 - UserId: int(v2.Id),  
455 - Account: v2.Account,  
456 - UserName: v2.Name,  
457 - }  
458 - targetDepartment := []domain.StaffDepartment{}  
459 - if departmentList, ok := userDepartmentMap[v.Id]; ok {  
460 - for _, department := range departmentList {  
461 - targetDepartment = append(targetDepartment, domain.StaffDepartment{  
462 - DepartmentId: int(department.Id),  
463 - DepartmentName: department.Name,  
464 - })  
465 - }  
466 - }  
467 - assessTemp.TargetDepartment = targetDepartment  
468 - assessListNew = append(assessListNew, assessTemp)  
469 - } 435 +// var assessListNew []domain.StaffAssess
  436 +// for _, v := range userMapReal {
  437 +// //获取上级
  438 +// chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
  439 +// if err != nil {
  440 +// return nil, err
  441 +// }
  442 +// if len(chargeUserList) == 0 {
  443 +// continue
  444 +// }
  445 +// for _, v2 := range chargeUserList {
  446 +// assessTemp.TargetUser = domain.StaffDesc{
  447 +// UserId: int(v.Id),
  448 +// Account: v.Account,
  449 +// UserName: v.Name,
  450 +// }
  451 +// assessTemp.Executor = domain.StaffDesc{
  452 +// UserId: int(v2.Id),
  453 +// Account: v2.Account,
  454 +// UserName: v2.Name,
  455 +// }
  456 +// targetDepartment := []domain.StaffDepartment{}
  457 +// if departmentList, ok := userDepartmentMap[v.Id]; ok {
  458 +// for _, department := range departmentList {
  459 +// targetDepartment = append(targetDepartment, domain.StaffDepartment{
  460 +// DepartmentId: int(department.Id),
  461 +// DepartmentName: department.Name,
  462 +// })
  463 +// }
  464 +// }
  465 +// assessTemp.TargetDepartment = targetDepartment
  466 +// assessListNew = append(assessListNew, assessTemp)
  467 +// }
470 468
471 - }  
472 - return assessListNew, nil  
473 -} 469 +// }
  470 +// return assessListNew, nil
  471 +// }
474 472
475 // 获取某个员工360评估邀请的人员 473 // 获取某个员工360评估邀请的人员
476 // func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) { 474 // func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
@@ -10,7 +10,7 @@ type EvaluationItemUsed struct { @@ -10,7 +10,7 @@ type EvaluationItemUsed struct {
10 CompanyId int //公司id 10 CompanyId int //公司id
11 EvaluationProjectId int //对应的项目id 11 EvaluationProjectId int //对应的项目id
12 NodeId int //填写评估评估节点对应id 12 NodeId int //填写评估评估节点对应id
13 - NodeType int //填写评估评估节点对应类型同evaluation_template.go->LinkNode.Type, 13 + NodeType int //填写评估评估节点对应类型,同evaluation_template.go->LinkNode.Type,
14 SortBy int //排序 14 SortBy int //排序
15 Category string //类别 15 Category string //类别
16 Name string //名称 16 Name string //名称
@@ -22,7 +22,7 @@ type EvaluationItemUsed struct { @@ -22,7 +22,7 @@ type EvaluationItemUsed struct {
22 Weight float64 //"权重" 22 Weight float64 //"权重"
23 Required int //必填项 同 NodeContent.Required 23 Required int //必填项 同 NodeContent.Required
24 EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 员工的id ) 24 EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 员工的id )
25 - IndicatorType int //指标类型 25 + IndicatorType int //指标类型,值同 evaluation_template.go->NodeContent.IndicatorType
26 CreatedAt time.Time //数据创建时间 26 CreatedAt time.Time //数据创建时间
27 UpdatedAt time.Time //数据更新时间 27 UpdatedAt time.Time //数据更新时间
28 } 28 }
@@ -102,6 +102,9 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface @@ -102,6 +102,9 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
102 if v, ok := queryOptions["evaluatorId"]; ok { 102 if v, ok := queryOptions["evaluatorId"]; ok {
103 query.Where("evaluator_id=?", v) 103 query.Where("evaluator_id=?", v)
104 } 104 }
  105 + if v, ok := queryOptions["indicatorType"]; ok {
  106 + query.Where("indicator_type=?", v)
  107 + }
105 query.Order("sort_by") 108 query.Order("sort_by")
106 109
107 count, err := query.SelectAndCount() 110 count, err := query.SelectAndCount()