作者 tangxvhui

调整一些逻辑

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())
... ...
... ... @@ -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位小数
... ...
... ... @@ -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,
... ...
... ... @@ -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
}
... ...
-- 调整旧数据
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
... ...