作者 Your Name

更新

... ... @@ -6,8 +6,8 @@ type CreateStaffAssessTask struct {
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
BeginTime string `json:"beginTime"` //绩效考核开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //绩效考核截止时间 2006-01-02 15:04:05
StepList []AssessTaskStep `json:"steps"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
}
... ...
... ... @@ -341,7 +341,9 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
... ... @@ -351,24 +353,45 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
}
nowTime := time.Now()
//建立评估任务
assessTask := domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
var assessTaskData *domain.StaffAssessTask
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
"evaluationProjectId": param.EvaluationProjectId,
"beginDay": param.BeginTime,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error())
}
// 获取旧数据
if len(assassessTaskList) > 0 {
assessTaskData = assassessTaskList[0]
assessTaskData.UpdatedAt = nowTime
} else {
//建立评估任务
assessTaskData = &domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
}
}
//填充评估环节
for _, v := range param.StepList {
for _, vv := range assessTaskData.StepList {
if vv.LinkNodeType == v.LinkNodeType {
continue
}
}
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
... ... @@ -385,13 +408,10 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTask.StepList = append(assessTask.StepList, step)
assessTaskData.StepList = append(assessTaskData.StepList, step)
}
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessList, err := srv.createStaffAssess(transactionContext, &assessTask)
assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
... ... @@ -405,27 +425,35 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
}
executorIds = append(executorIds, v)
}
//过滤就数据
for _, v := range assessTaskData.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIds = append(executorIds, v)
}
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData.ExecutorId = executorIds
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
for i := range assessList {
assessList[i].StaffAssessTaskId = assessTaskData.Id
_, err = assessRepo.Save(&assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
}
assessTask.ExecutorId = executorIds
_, err = assessTaskRepo.Save(&assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return map[string]interface{}{
"assessTaskId": assessTask.Id,
"assessTaskId": assessTaskData.Id,
}, nil
}
... ...
... ... @@ -2,19 +2,6 @@ package domain
import "time"
//评估任务重复执行的方式
// type AssessTaskRepeatWay string
// const (
// AssessTaskRepeatDay AssessTaskRepeatWay = "day" //按天重复
// AssessTaskRepeatWeek AssessTaskRepeatWay = "week" //按周重复
// AssessTaskRepeatMonth AssessTaskRepeatWay = "month" //按月
// AssessTaskRepeatMonthDouble AssessTaskRepeatWay = "month_double" //按双月
// AssessTaskRepeatQuarter AssessTaskRepeatWay = "quarter" //按季度
// AssessTaskRepeatYearHalf AssessTaskRepeatWay = "year_half" //按半年
// AssessTaskRepeatYear AssessTaskRepeatWay = "year" //按年
// )
// 执行评估的任务列表
type StaffAssessTask struct {
Id int `json:"id"`
... ... @@ -23,6 +10,7 @@ type StaffAssessTask struct {
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginDay string `json:"beginDay"` //绩效考核日期
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"stepList"` //考评的流程
... ...
... ... @@ -17,6 +17,7 @@ type StaffAssessTask struct {
CycleName string //对应周期的名称
ExecutorId []int //参与考评的人
StepList []domain.AssessTaskStep `` //考评的流程
BeginDay string //日期 天 2006-01-02
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
... ...
... ... @@ -29,6 +29,7 @@ func (repo *StaffAssessTaskRepository) TransformToDomain(d *models.StaffAssessTa
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
BeginDay: d.BeginDay,
BeginTime: d.BeginTime,
EndTime: d.EndTime,
StepList: d.StepList,
... ... @@ -47,6 +48,7 @@ func (repo *StaffAssessTaskRepository) Save(d *domain.StaffAssessTask) (*domain.
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
BeginDay: d.BeginDay,
ExecutorId: d.ExecutorId,
StepList: d.StepList,
BeginTime: d.BeginTime,
... ... @@ -115,9 +117,15 @@ func (repo *StaffAssessTaskRepository) Find(queryOptions map[string]interface{})
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["beginDay"]; ok {
query.Where("begin_day=?", v)
}
if v, ok := queryOptions["executorId"].(int); ok && v > 0 {
query.Where(`executor_id @>'[?]'`, v)
}
if v, ok := queryOptions["evaluationProjectId"]; ok {
query.Where("evaluation_project_id=?", v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...