作者 tangxvhui

Merge branch 'test'

package service
import (
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
"time"
)
type EvaluationCycleService struct {
... ... @@ -356,7 +357,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
staffRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
summaryEvaluationRepository := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
// 删除周期
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
... ... @@ -380,11 +381,6 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
if _, err := projectRepository.Remove(projects[i]); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 删除项目已生成的周期评估数据
if err := staffRepository.RemoveByProjectId(int(projects[i].Id)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 删除周期下的所有定时任务
... ... @@ -398,6 +394,14 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 删除项目已生成的周期评估数据
if err := staffRepository.RemoveByCycleId(int(cycle.Id)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//
if err := summaryEvaluationRepository.RemoveByCycleId(cycle.Id); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -920,7 +920,7 @@ func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*ada
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
... ... @@ -1059,7 +1059,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
... ... @@ -1077,9 +1077,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
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 {
// 转换填入的评估值
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
... ... @@ -373,7 +374,7 @@ func (srv StaffAssessServeice) ListExecutorInviteAssessV2(param *query.ListExecu
continue
}
projectIdMap[assessList[i].EvaluationProjectId] = struct{}{}
assessContentListTemp, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessList[i])
assessContentListTemp, err := srv.getAssessInfoUncompletedV2(transactionContext, assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
... ... @@ -720,7 +721,7 @@ func (srv StaffAssessServeice) GetAssessSelfInfoV2(param *query.GetExecutorSelfA
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
... ... @@ -795,7 +796,7 @@ func (srv StaffAssessServeice) ListTargetUserInviteAssess(param *query.ListTarge
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var resultList []map[string]interface{}
resultList := []map[string]interface{}{}
for _, v := range assessList {
item := map[string]interface{}{
"id": v.Id,
... ... @@ -922,3 +923,65 @@ func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAsses
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
// 获取未完成的员工评估内容
func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext,
assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var evaluationItemList []*domain.EvaluationItemUsed
var err error
_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": assess.EvaluationProjectId,
"nodeId": assess.LinkNodeId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
if len(evaluationItemList) == 0 {
//如果当前节点没有评估内容,就去 使用自评节点的评估内容
_, evaluationItemList, err = evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": assess.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取自评项目填写内容"+err.Error())
}
}
var contentList []*domain.StaffAssessContent
nowTime := time.Now()
for i, v := range evaluationItemList {
item := &domain.StaffAssessContent{
Id: 0,
StaffAssessId: assess.Id,
SortBy: i + 1,
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
Remark: nil,
Value: "",
ReteResult: "",
CreatedAt: nowTime,
Weight: v.Weight,
Required: v.Required,
UpdatedAt: nowTime,
DeletedAt: nil,
Rule: v.Rule,
}
var remarks []domain.AssessContemtRemark
for _, vv := range v.EntryItems {
ritem := domain.AssessContemtRemark{
Title: vv.Title,
HintText: vv.HintText,
Definition: vv.Definition,
RemarkText: "",
}
remarks = append(remarks, ritem)
}
item.Remark = remarks
contentList = append(contentList, item)
}
return contentList, nil
}
... ...
... ... @@ -20,7 +20,7 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
//自评的时间范围
beginTimeSelf := project.EndTime
endTimeSelf := dayZeroTime(project.EndTime).Add(3*24*time.Hour - time.Second)
endTimeSelf := dayZeroTime(project.EndTime).Add(4*24*time.Hour - time.Second)
//人资、360评估的时间范围
beginTime360 := endTimeSelf
endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
... ...
... ... @@ -195,7 +195,8 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
}
//自评的时间范围
beginTimeSelf := *cycleData.TimeEnd
endTimeSelf := dayZeroTime(beginTimeSelf).Add(3*24*time.Hour - time.Second)
//修改 周期结束时间那天的第二天开始计算
endTimeSelf := dayZeroTime(beginTimeSelf).Add(4*24*time.Hour - time.Second)
//人资、360评估的时间范围
beginTime360 := endTimeSelf
endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
... ...
... ... @@ -42,4 +42,5 @@ type StaffAssessTaskRepository interface {
FindOne(queryOptions map[string]interface{}) (*StaffAssessTask, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessTask, error)
RemoveByProjectId(id int) error
RemoveByCycleId(id int) error
}
... ...
... ... @@ -68,6 +68,7 @@ type SummaryEvaluationRepository interface {
FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
RemoveByProjectId(id int) error
RemoveByCycleId(id int64) error
}
// 计算总分。TotalScore 保留1位小数
... ...
... ... @@ -1280,6 +1280,7 @@ func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds []
AND staff_assess.types = 'self'
AND staff_assess.evaluation_project_id IN (?)
AND staff_assess.status = 'uncompleted'
AND staff_assess.end_time < now()
GROUP BY
evaluation_project_id, target_user_id`
... ...
... ... @@ -125,6 +125,7 @@ and staff_assess.evaluation_project_id in (
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
withSql := `
set time zone 'PRC';
with
t_project_0 as(
select evaluation_project.id as project_id,
... ...
... ... @@ -40,6 +40,8 @@ func (d *SummaryEvaluationDao) GetExecutorCycleList(companyId int, executorId in
summary_evaluation.cycle_name
from summary_evaluation
where summary_evaluation.company_id=?
and summary_evaluation.begin_time <=now()
and summary_evaluation.deleted_at isnull
`
tx := d.transactionContext.PgTx
condition := []interface{}{
... ... @@ -64,7 +66,7 @@ func (d *SummaryEvaluationDao) CountExecutorCycleList(companyId int, executorId
distinct summary_evaluation.cycle_id
) as cnt
from summary_evaluation
where summary_evaluation.company_id=? `
where summary_evaluation.company_id=? and summary_evaluation.deleted_at isnull `
tx := d.transactionContext.PgTx
condition := []interface{}{
... ...
... ... @@ -93,6 +93,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
query.Where("node_type=?", v)
}
if v, ok := queryOptions["nodeId"]; ok {
query.Where("node_id=?", v)
}
if v, ok := queryOptions["evaluatorId"]; ok {
query.Where("evaluator_id=?", v)
}
... ...
... ... @@ -153,3 +153,13 @@ func (repo *StaffAssessTaskRepository) RemoveByProjectId(id int) error {
Update()
return err
}
func (repo *StaffAssessTaskRepository) RemoveByCycleId(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssessTask{}).
Where("cycle_id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
... ...
... ... @@ -197,3 +197,13 @@ func (repo *SummaryEvaluationRepository) RemoveByProjectId(id int) error {
Update()
return err
}
func (repo *SummaryEvaluationRepository) RemoveByCycleId(id int64) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.SummaryEvaluation{}).
Where("cycle_id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
... ...
-- 数据修复
-- 需备份 evaluation_item_used 表数据
WITH t1 AS (
SELECT
evaluation_project.company_id,
evaluation_project.id AS project_id,
jsonb_array_elements(evaluation_project."template" #> '{linkNodes}') AS nodes
FROM
evaluation_project
WHERE evaluation_project."template" #> '{linkNodes}'<>'null'
ORDER BY
id
),
t2 AS (
SELECT
t1.company_id,
t1.project_id,
t1.nodes ->> 'id' AS node_id,
t1.nodes ->> 'type' AS node_type,
jsonb_array_elements(t1.nodes #> '{nodeContents}') AS node_contents
FROM
t1
WHERE t1.nodes #> '{nodeContents}'<>'null'
),
t3 AS(
SELECT
t2.company_id,
t2.project_id,
cast(t2.node_id AS int8) AS node_id,
cast(t2.node_type AS int8) AS node_type,
t2.node_contents ->> 'category' AS "category",
t2.node_contents ->> 'name' AS "name",
cast(t2.node_contents ->> 'ruleId' AS int8) AS "rule_id"
FROM
t2
),
t4 as (
SELECT
t3.project_id,
t3.node_type,
t3."category",
t3."name",
row_to_json( "evaluation_rule".*) as "rule",
"evaluation_rule"."type" as rule_type
FROM t3
join "evaluation_rule" on t3.rule_id= "evaluation_rule".id
),
t5 as (
SELECT
evaluation_item_used."id",
evaluation_item_used.evaluation_project_id,
evaluation_item_used.node_type,
evaluation_item_used.category,
evaluation_item_used."name"
FROM evaluation_item_used
WHERE "rule"='{}' or "rule" ISNULL
),
t6 as (
SELECT t5."id" ,
t4."rule",
t4.rule_type
FROM t5 ,t4
WHERE t5.evaluation_project_id=t4.project_id
and t5.node_type=t4.node_type
and t5.category=t4.category
and t5."name"=t4."name"
)
update evaluation_item_used
set "rule"=t6."rule",
rule_type=t6."rule_type"
FROM t6
WHERE evaluation_item_used."id"=t6."id"
;
-- 修复数据
with t1 as
( SELECT
evaluation_rule.id::TEXT,
evaluation_rule."name",
evaluation_rule.remark,
evaluation_rule.company_id::TEXT as "companyId",
evaluation_rule.creator_id::TEXT as "creatorId",
evaluation_rule."type",
evaluation_rule.rating,
evaluation_rule.score,
evaluation_rule.sys_type as "sysType"
FROM evaluation_rule
),
t2 as (
SELECT t1.id, row_to_json(t1.*) as row_j FROM t1
),
t3 as (
SELECT evaluation_item_used.id, t2.row_j
FROM evaluation_item_used
join t2 on t2.id= evaluation_item_used."rule"->>'id'
WHERE evaluation_item_used."rule"->'companyId' ISNULL
and evaluation_item_used."rule"->'id' is not null
)
update evaluation_item_used
SET "rule"=t3.row_j
FROM t3
WHERE evaluation_item_used.id = t3.id
;
-- 修改开始结束时间
UPDATE summary_evaluation
set begin_time = '2023-03-31 23:59:00+08',
end_time = '2023-04-02 23:59:00+08'
WHERE id=36
;
UPDATE summary_evaluation
set begin_time = '2023-04-02 23:59:00+08',
end_time = '2023-04-04 23:59:00+08'
WHERE id=37
-- 修改数据summary_evaluation 表数据
with t1 as (
SELECT summary_evaluation.id,summary_evaluation.evaluation_project_id
FROM summary_evaluation
WHERE to_char( summary_evaluation.begin_time, 'YYYY-MM-DD') ='2023-03-31'
and to_char( summary_evaluation.end_time, 'YYYY-MM-DD') ='2023-04-02'
and company_id=1
)
update summary_evaluation
set end_time=end_time+'1 day'
FROM t1
WHERE summary_evaluation.evaluation_project_id=t1.evaluation_project_id
\ No newline at end of file
... ...
-- 调整旧数据
WITH t1 AS (
SELECT
evaluation_cycle.id AS cycle_id
FROM
evaluation_cycle
WHERE
deleted_at IS NOT NULL)
UPDATE
summary_evaluation
SET
deleted_at = now()
FROM
t1
WHERE
summary_evaluation.cycle_id = t1.cycle_id
... ...