作者 tangxvhui

Merge branch 'test'

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "strconv"
  5 + "time"
  6 +
4 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
5 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/adapter" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/adapter"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
10 - "strconv"  
11 - "time"  
12 ) 13 )
13 14
14 type EvaluationCycleService struct { 15 type EvaluationCycleService struct {
@@ -356,7 +357,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf @@ -356,7 +357,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
356 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) 357 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
357 taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) 358 taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
358 staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) 359 staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
359 - 360 + summaryEvaluationRepository := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
360 // 删除周期 361 // 删除周期
361 cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id}) 362 cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
362 if err != nil { 363 if err != nil {
@@ -380,11 +381,6 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf @@ -380,11 +381,6 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
380 if _, err := projectRepository.Remove(projects[i]); err != nil { 381 if _, err := projectRepository.Remove(projects[i]); err != nil {
381 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 382 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
382 } 383 }
383 -  
384 - // 删除项目已生成的周期评估数据  
385 - if err := staffRepository.RemoveByProjectId(int(projects[i].Id)); err != nil {  
386 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
387 - }  
388 } 384 }
389 385
390 // 删除周期下的所有定时任务 386 // 删除周期下的所有定时任务
@@ -398,6 +394,14 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf @@ -398,6 +394,14 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
398 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 394 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
399 } 395 }
400 } 396 }
  397 + // 删除项目已生成的周期评估数据
  398 + if err := staffRepository.RemoveByCycleId(int(cycle.Id)); err != nil {
  399 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  400 + }
  401 + //
  402 + if err := summaryEvaluationRepository.RemoveByCycleId(cycle.Id); err != nil {
  403 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  404 + }
401 405
402 if err := transactionContext.CommitTransaction(); err != nil { 406 if err := transactionContext.CommitTransaction(); err != nil {
403 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 407 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -920,7 +920,7 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada @@ -920,7 +920,7 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada
920 } 920 }
921 } else if assessData.Status == domain.StaffAssessUncompleted { 921 } else if assessData.Status == domain.StaffAssessUncompleted {
922 //未完成 922 //未完成
923 - assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData) 923 + assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
924 if err != nil { 924 if err != nil {
925 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error()) 925 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
926 } 926 }
@@ -1059,7 +1059,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1059,7 +1059,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1059 } 1059 }
1060 } else if assessData.Status == domain.StaffAssessUncompleted { 1060 } else if assessData.Status == domain.StaffAssessUncompleted {
1061 //未完成 1061 //未完成
1062 - assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData) 1062 + assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
1063 if err != nil { 1063 if err != nil {
1064 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error()) 1064 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
1065 } 1065 }
@@ -1077,9 +1077,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1077,9 +1077,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1077 if !ok { 1077 if !ok {
1078 continue 1078 continue
1079 } 1079 }
  1080 + if assessData.Types == domain.AssessSelf {
  1081 + //每日自评需要检查必填项
1080 if v.Required == domain.NodeRequiredYes && len(item.Value) == 0 { 1082 if v.Required == domain.NodeRequiredYes && len(item.Value) == 0 {
1081 return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":必填项") 1083 return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":必填项")
1082 } 1084 }
  1085 + }
  1086 +
1083 v.Value = item.Value 1087 v.Value = item.Value
1084 if len(item.Value) > 0 { 1088 if len(item.Value) > 0 {
1085 // 转换填入的评估值 1089 // 转换填入的评估值
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "sort" 5 "sort"
6 "strconv" 6 "strconv"
  7 + "time"
7 8
8 "github.com/linmadan/egglib-go/core/application" 9 "github.com/linmadan/egglib-go/core/application"
9 "github.com/linmadan/egglib-go/utils/tool_funs" 10 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -373,7 +374,7 @@ func (srv StaffAssessServeice) ListExecutorInviteAssessV2(param *query.ListExecu @@ -373,7 +374,7 @@ func (srv StaffAssessServeice) ListExecutorInviteAssessV2(param *query.ListExecu
373 continue 374 continue
374 } 375 }
375 projectIdMap[assessList[i].EvaluationProjectId] = struct{}{} 376 projectIdMap[assessList[i].EvaluationProjectId] = struct{}{}
376 - assessContentListTemp, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessList[i]) 377 + assessContentListTemp, err := srv.getAssessInfoUncompletedV2(transactionContext, assessList[i])
377 if err != nil { 378 if err != nil {
378 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error()) 379 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
379 } 380 }
@@ -720,7 +721,7 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA @@ -720,7 +721,7 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA
720 } 721 }
721 } else if assessData.Status == domain.StaffAssessUncompleted { 722 } else if assessData.Status == domain.StaffAssessUncompleted {
722 //未完成 723 //未完成
723 - assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData) 724 + assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
724 if err != nil { 725 if err != nil {
725 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error()) 726 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
726 } 727 }
@@ -795,7 +796,7 @@ func (srv StaffAssessServeice) ListTargetUserInviteAssess(param *query.ListTarge @@ -795,7 +796,7 @@ func (srv StaffAssessServeice) ListTargetUserInviteAssess(param *query.ListTarge
795 if err := transactionContext.CommitTransaction(); err != nil { 796 if err := transactionContext.CommitTransaction(); err != nil {
796 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 797 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
797 } 798 }
798 - var resultList []map[string]interface{} 799 + resultList := []map[string]interface{}{}
799 for _, v := range assessList { 800 for _, v := range assessList {
800 item := map[string]interface{}{ 801 item := map[string]interface{}{
801 "id": v.Id, 802 "id": v.Id,
@@ -922,3 +923,65 @@ func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAsses @@ -922,3 +923,65 @@ func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAsses
922 } 923 }
923 return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil 924 return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
924 } 925 }
  926 +
  927 +// 获取未完成的员工评估内容
  928 +func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext,
  929 + assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
  930 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
  931 + "transactionContext": transactionContext,
  932 + })
  933 + var evaluationItemList []*domain.EvaluationItemUsed
  934 + var err error
  935 + _, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
  936 + "evaluationProjectId": assess.EvaluationProjectId,
  937 + "nodeId": assess.LinkNodeId,
  938 + })
  939 + if err != nil {
  940 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
  941 + }
  942 + if len(evaluationItemList) == 0 {
  943 + //如果当前节点没有评估内容,就去 使用自评节点的评估内容
  944 + _, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
  945 + "evaluationProjectId": assess.EvaluationProjectId,
  946 + "nodeType": domain.LinkNodeSelfAssessment,
  947 + })
  948 + if err != nil {
  949 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取自评项目填写内容"+err.Error())
  950 + }
  951 + }
  952 + var contentList []*domain.StaffAssessContent
  953 + nowTime := time.Now()
  954 + for i, v := range evaluationItemList {
  955 + item := &domain.StaffAssessContent{
  956 + Id: 0,
  957 + StaffAssessId: assess.Id,
  958 + SortBy: i + 1,
  959 + Category: v.Category,
  960 + Name: v.Name,
  961 + PromptTitle: v.PromptTitle,
  962 + PromptText: v.PromptText,
  963 + Remark: nil,
  964 + Value: "",
  965 + ReteResult: "",
  966 + CreatedAt: nowTime,
  967 + Weight: v.Weight,
  968 + Required: v.Required,
  969 + UpdatedAt: nowTime,
  970 + DeletedAt: nil,
  971 + Rule: v.Rule,
  972 + }
  973 + var remarks []domain.AssessContemtRemark
  974 + for _, vv := range v.EntryItems {
  975 + ritem := domain.AssessContemtRemark{
  976 + Title: vv.Title,
  977 + HintText: vv.HintText,
  978 + Definition: vv.Definition,
  979 + RemarkText: "",
  980 + }
  981 + remarks = append(remarks, ritem)
  982 + }
  983 + item.Remark = remarks
  984 + contentList = append(contentList, item)
  985 + }
  986 + return contentList, nil
  987 +}
@@ -20,7 +20,7 @@ func sendSummaryEvaluation(project *domain.EvaluationProject, @@ -20,7 +20,7 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
20 userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) { 20 userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
21 //自评的时间范围 21 //自评的时间范围
22 beginTimeSelf := project.EndTime 22 beginTimeSelf := project.EndTime
23 - endTimeSelf := dayZeroTime(project.EndTime).Add(3*24*time.Hour - time.Second) 23 + endTimeSelf := dayZeroTime(project.EndTime).Add(4*24*time.Hour - time.Second)
24 //人资、360评估的时间范围 24 //人资、360评估的时间范围
25 beginTime360 := endTimeSelf 25 beginTime360 := endTimeSelf
26 endTime360 := endTimeSelf.Add(2 * 24 * time.Hour) 26 endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
@@ -195,7 +195,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2( @@ -195,7 +195,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
195 } 195 }
196 //自评的时间范围 196 //自评的时间范围
197 beginTimeSelf := *cycleData.TimeEnd 197 beginTimeSelf := *cycleData.TimeEnd
198 - endTimeSelf := dayZeroTime(beginTimeSelf).Add(3*24*time.Hour - time.Second) 198 + //修改 周期结束时间那天的第二天开始计算
  199 + endTimeSelf := dayZeroTime(beginTimeSelf).Add(4*24*time.Hour - time.Second)
199 //人资、360评估的时间范围 200 //人资、360评估的时间范围
200 beginTime360 := endTimeSelf 201 beginTime360 := endTimeSelf
201 endTime360 := endTimeSelf.Add(2 * 24 * time.Hour) 202 endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
@@ -42,4 +42,5 @@ type StaffAssessTaskRepository interface { @@ -42,4 +42,5 @@ type StaffAssessTaskRepository interface {
42 FindOne(queryOptions map[string]interface{}) (*StaffAssessTask, error) 42 FindOne(queryOptions map[string]interface{}) (*StaffAssessTask, error)
43 Find(queryOptions map[string]interface{}) (int, []*StaffAssessTask, error) 43 Find(queryOptions map[string]interface{}) (int, []*StaffAssessTask, error)
44 RemoveByProjectId(id int) error 44 RemoveByProjectId(id int) error
  45 + RemoveByCycleId(id int) error
45 } 46 }
@@ -68,6 +68,7 @@ type SummaryEvaluationRepository interface { @@ -68,6 +68,7 @@ type SummaryEvaluationRepository interface {
68 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error) 68 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
69 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error) 69 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
70 RemoveByProjectId(id int) error 70 RemoveByProjectId(id int) error
  71 + RemoveByCycleId(id int64) error
71 } 72 }
72 73
73 // 计算总分。TotalScore 保留1位小数 74 // 计算总分。TotalScore 保留1位小数
@@ -1280,6 +1280,7 @@ func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds [] @@ -1280,6 +1280,7 @@ func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds []
1280 AND staff_assess.types = 'self' 1280 AND staff_assess.types = 'self'
1281 AND staff_assess.evaluation_project_id IN (?) 1281 AND staff_assess.evaluation_project_id IN (?)
1282 AND staff_assess.status = 'uncompleted' 1282 AND staff_assess.status = 'uncompleted'
  1283 + AND staff_assess.end_time < now()
1283 GROUP BY 1284 GROUP BY
1284 evaluation_project_id, target_user_id` 1285 evaluation_project_id, target_user_id`
1285 1286
@@ -125,6 +125,7 @@ and staff_assess.evaluation_project_id in ( @@ -125,6 +125,7 @@ and staff_assess.evaluation_project_id in (
125 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填) 125 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
126 func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string { 126 func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
127 withSql := ` 127 withSql := `
  128 + set time zone 'PRC';
128 with 129 with
129 t_project_0 as( 130 t_project_0 as(
130 select evaluation_project.id as project_id, 131 select evaluation_project.id as project_id,
@@ -40,6 +40,8 @@ func (d *SummaryEvaluationDao) GetExecutorCycleList(companyId int, executorId in @@ -40,6 +40,8 @@ func (d *SummaryEvaluationDao) GetExecutorCycleList(companyId int, executorId in
40 summary_evaluation.cycle_name 40 summary_evaluation.cycle_name
41 from summary_evaluation 41 from summary_evaluation
42 where summary_evaluation.company_id=? 42 where summary_evaluation.company_id=?
  43 + and summary_evaluation.begin_time <=now()
  44 + and summary_evaluation.deleted_at isnull
43 ` 45 `
44 tx := d.transactionContext.PgTx 46 tx := d.transactionContext.PgTx
45 condition := []interface{}{ 47 condition := []interface{}{
@@ -64,7 +66,7 @@ func (d *SummaryEvaluationDao) CountExecutorCycleList(companyId int, executorId @@ -64,7 +66,7 @@ func (d *SummaryEvaluationDao) CountExecutorCycleList(companyId int, executorId
64 distinct summary_evaluation.cycle_id 66 distinct summary_evaluation.cycle_id
65 ) as cnt 67 ) as cnt
66 from summary_evaluation 68 from summary_evaluation
67 - where summary_evaluation.company_id=? ` 69 + where summary_evaluation.company_id=? and summary_evaluation.deleted_at isnull `
68 70
69 tx := d.transactionContext.PgTx 71 tx := d.transactionContext.PgTx
70 condition := []interface{}{ 72 condition := []interface{}{
@@ -93,6 +93,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface @@ -93,6 +93,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
93 query.Where("node_type=?", v) 93 query.Where("node_type=?", v)
94 } 94 }
95 95
  96 + if v, ok := queryOptions["nodeId"]; ok {
  97 + query.Where("node_id=?", v)
  98 + }
  99 +
96 if v, ok := queryOptions["evaluatorId"]; ok { 100 if v, ok := queryOptions["evaluatorId"]; ok {
97 query.Where("evaluator_id=?", v) 101 query.Where("evaluator_id=?", v)
98 } 102 }
@@ -153,3 +153,13 @@ func (repo *StaffAssessTaskRepository) RemoveByProjectId(id int) error { @@ -153,3 +153,13 @@ func (repo *StaffAssessTaskRepository) RemoveByProjectId(id int) error {
153 Update() 153 Update()
154 return err 154 return err
155 } 155 }
  156 +
  157 +func (repo *StaffAssessTaskRepository) RemoveByCycleId(id int) error {
  158 + tx := repo.transactionContext.PgTx
  159 + nowTime := time.Now()
  160 + _, err := tx.Model(&models.StaffAssessTask{}).
  161 + Where("cycle_id=?", id).
  162 + Set("deleted_at=?", nowTime).
  163 + Update()
  164 + return err
  165 +}
@@ -197,3 +197,13 @@ func (repo *SummaryEvaluationRepository) RemoveByProjectId(id int) error { @@ -197,3 +197,13 @@ func (repo *SummaryEvaluationRepository) RemoveByProjectId(id int) error {
197 Update() 197 Update()
198 return err 198 return err
199 } 199 }
  200 +
  201 +func (repo *SummaryEvaluationRepository) RemoveByCycleId(id int64) error {
  202 + tx := repo.transactionContext.PgTx
  203 + nowTime := time.Now()
  204 + _, err := tx.Model(&models.SummaryEvaluation{}).
  205 + Where("cycle_id=?", id).
  206 + Set("deleted_at=?", nowTime).
  207 + Update()
  208 + return err
  209 +}
  1 +-- 数据修复
  2 +-- 需备份 evaluation_item_used 表数据
  3 +
  4 +WITH t1 AS (
  5 + SELECT
  6 + evaluation_project.company_id,
  7 + evaluation_project.id AS project_id,
  8 + jsonb_array_elements(evaluation_project."template" #> '{linkNodes}') AS nodes
  9 + FROM
  10 + evaluation_project
  11 + WHERE evaluation_project."template" #> '{linkNodes}'<>'null'
  12 + ORDER BY
  13 + id
  14 +),
  15 +t2 AS (
  16 + SELECT
  17 + t1.company_id,
  18 + t1.project_id,
  19 + t1.nodes ->> 'id' AS node_id,
  20 + t1.nodes ->> 'type' AS node_type,
  21 + jsonb_array_elements(t1.nodes #> '{nodeContents}') AS node_contents
  22 + FROM
  23 + t1
  24 + WHERE t1.nodes #> '{nodeContents}'<>'null'
  25 + ),
  26 +t3 AS(
  27 + SELECT
  28 + t2.company_id,
  29 + t2.project_id,
  30 + cast(t2.node_id AS int8) AS node_id,
  31 + cast(t2.node_type AS int8) AS node_type,
  32 + t2.node_contents ->> 'category' AS "category",
  33 + t2.node_contents ->> 'name' AS "name",
  34 + cast(t2.node_contents ->> 'ruleId' AS int8) AS "rule_id"
  35 + FROM
  36 + t2
  37 +),
  38 +t4 as (
  39 + SELECT
  40 + t3.project_id,
  41 + t3.node_type,
  42 + t3."category",
  43 + t3."name",
  44 + row_to_json( "evaluation_rule".*) as "rule",
  45 + "evaluation_rule"."type" as rule_type
  46 + FROM t3
  47 + join "evaluation_rule" on t3.rule_id= "evaluation_rule".id
  48 +),
  49 +t5 as (
  50 + SELECT
  51 + evaluation_item_used."id",
  52 + evaluation_item_used.evaluation_project_id,
  53 + evaluation_item_used.node_type,
  54 + evaluation_item_used.category,
  55 + evaluation_item_used."name"
  56 + FROM evaluation_item_used
  57 + WHERE "rule"='{}' or "rule" ISNULL
  58 +),
  59 +t6 as (
  60 + SELECT t5."id" ,
  61 + t4."rule",
  62 + t4.rule_type
  63 + FROM t5 ,t4
  64 + WHERE t5.evaluation_project_id=t4.project_id
  65 + and t5.node_type=t4.node_type
  66 + and t5.category=t4.category
  67 + and t5."name"=t4."name"
  68 +)
  69 +update evaluation_item_used
  70 +set "rule"=t6."rule",
  71 +rule_type=t6."rule_type"
  72 +FROM t6
  73 +WHERE evaluation_item_used."id"=t6."id"
  74 +;
  75 +
  76 +-- 修复数据
  77 +
  78 +with t1 as
  79 +( SELECT
  80 +evaluation_rule.id::TEXT,
  81 +evaluation_rule."name",
  82 +evaluation_rule.remark,
  83 +evaluation_rule.company_id::TEXT as "companyId",
  84 +evaluation_rule.creator_id::TEXT as "creatorId",
  85 +evaluation_rule."type",
  86 +evaluation_rule.rating,
  87 +evaluation_rule.score,
  88 +evaluation_rule.sys_type as "sysType"
  89 +FROM evaluation_rule
  90 +),
  91 +t2 as (
  92 +SELECT t1.id, row_to_json(t1.*) as row_j FROM t1
  93 +),
  94 +t3 as (
  95 +SELECT evaluation_item_used.id, t2.row_j
  96 +FROM evaluation_item_used
  97 +join t2 on t2.id= evaluation_item_used."rule"->>'id'
  98 +WHERE evaluation_item_used."rule"->'companyId' ISNULL
  99 +and evaluation_item_used."rule"->'id' is not null
  100 +)
  101 +update evaluation_item_used
  102 +SET "rule"=t3.row_j
  103 +FROM t3
  104 +WHERE evaluation_item_used.id = t3.id
  105 +;
  106 +-- 修改开始结束时间
  107 +UPDATE summary_evaluation
  108 +set begin_time = '2023-03-31 23:59:00+08',
  109 +end_time = '2023-04-02 23:59:00+08'
  110 +WHERE id=36
  111 +;
  112 +
  113 +UPDATE summary_evaluation
  114 +set begin_time = '2023-04-02 23:59:00+08',
  115 +end_time = '2023-04-04 23:59:00+08'
  116 +WHERE id=37
  117 +
  118 +-- 修改数据summary_evaluation 表数据
  119 +with t1 as (
  120 +SELECT summary_evaluation.id,summary_evaluation.evaluation_project_id
  121 +FROM summary_evaluation
  122 +WHERE to_char( summary_evaluation.begin_time, 'YYYY-MM-DD') ='2023-03-31'
  123 +and to_char( summary_evaluation.end_time, 'YYYY-MM-DD') ='2023-04-02'
  124 +and company_id=1
  125 +)
  126 +update summary_evaluation
  127 +set end_time=end_time+'1 day'
  128 +FROM t1
  129 +WHERE summary_evaluation.evaluation_project_id=t1.evaluation_project_id
  1 +-- 调整旧数据
  2 +WITH t1 AS (
  3 + SELECT
  4 + evaluation_cycle.id AS cycle_id
  5 + FROM
  6 + evaluation_cycle
  7 + WHERE
  8 + deleted_at IS NOT NULL)
  9 +UPDATE
  10 + summary_evaluation
  11 +SET
  12 + deleted_at = now()
  13 +FROM
  14 + t1
  15 +WHERE
  16 + summary_evaluation.cycle_id = t1.cycle_id