作者 郑周

增加环节顺序,

消息发送优化
... ... @@ -177,12 +177,12 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 启动时,需要激活定时任务
if in.Activate == 1 {
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
project.State = domain.ProjectStateEnable
if cycleTemplate == nil || cycleTemplate.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
}
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
... ... @@ -209,6 +209,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
//// FIXME 启动时,需要激活定时任务
//if in.Activate == 1 {
// project.State = domain.ProjectStateEnable
//} else {
// project.State = domain.ProjectStateWaitActive
//}
project.State = domain.ProjectStateWaitActive
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
for i := range project.Template.LinkNodes {
... ... @@ -348,7 +356,9 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
if project.State == domain.TemplateStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
}
//cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -378,6 +388,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
NodeType: node.Type,
NodeName: node.Name,
NodeDescribe: node.Describe,
NodeSort: i + 1,
TimeStart: node.TimeStart,
TimeEnd: node.TimeEnd,
KpiCycle: node.KpiCycle,
... ...
... ... @@ -39,9 +39,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
//ttaffAssessRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
//
projectIdsMap := map[int64]*domain.EvaluationProject{}
cycleIdsMap := map[int64]*domain.EvaluationCycle{}
for i := range tasks {
... ... @@ -74,7 +71,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
cycleIdsMap[cycles[i].Id] = cycles[i]
}
staffAssessTaskMap := map[int64]*command.CreateStaffAssessTask{}
staffAssessService := service.NewStaffAssessServeice()
for i := range tasks {
task := tasks[i]
// 项目
... ... @@ -108,47 +105,44 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
var csat, staffOk = staffAssessTaskMap[task.ProjectId]
if !staffOk {
csat = &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
EvaluationProjectId: int(project.Id),
EvaluationProjectName: project.Name,
CycleId: project.CycleId,
}
// 周期名称
if cycle, ok := cycleIdsMap[project.CycleId]; ok {
csat.CycleName = cycle.Name
}
// 接收人
csat.ExecutorId = make([]int, 0)
for rIndex := range project.Recipients {
vInt, _ := strconv.Atoi(project.Recipients[rIndex])
csat.ExecutorId = append(csat.ExecutorId, vInt)
}
// FIXME 这里设置时间可能会有歧义,目前原型设计时间均一致,所以直接选取第一个获取到的周期时间,作为本周期的起止和截止时间
csat.BeginTime = fmCycleStartTime
csat.EndTime = fmCycleTimeEnd
staffAssessTaskMap[task.ProjectId] = csat
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
EvaluationProjectId: int(project.Id),
EvaluationProjectName: project.Name,
CycleId: project.CycleId,
StepList: make([]command.AssessTaskStep, 0),
}
// 周期名称
if cycle, ok := cycleIdsMap[project.CycleId]; ok {
csat.CycleName = cycle.Name
}
if csat.StepList == nil {
csat.StepList = make([]command.AssessTaskStep, 0)
// 接收人
csat.ExecutorId = make([]int, 0)
for rIndex := range project.Recipients {
vInt, _ := strconv.Atoi(project.Recipients[rIndex])
csat.ExecutorId = append(csat.ExecutorId, vInt)
}
csat.BeginTime = fmCycleStartTime
csat.EndTime = fmCycleTimeEnd
csat.StepList = append(csat.StepList, command.AssessTaskStep{
SortBy: i,
SortBy: task.NodeSort,
LinkNodeId: int(task.NodeId),
LinkNodeName: task.NodeName,
LinkNodeType: task.NodeType,
BeginTime: fmCycleStartTime,
EndTime: fmCycleTimeEnd,
})
// 创建发送任务
_, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
task.NextSentAt = nil
task.NextSentAt = nil // 项目不存在,取消周期任务发送
}
task, err := taskRepository.Insert(task)
... ... @@ -157,15 +151,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
}
}
staffAssessService := service.NewStaffAssessServeice()
for i := range staffAssessTaskMap {
staffAssessTask := staffAssessTaskMap[i]
_, err := staffAssessService.CreateStaffAssessTask(transactionContext, staffAssessTask)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -13,6 +13,7 @@ type NodeTask struct {
NodeType int `json:"nodeType" comment:"环节类型"`
NodeName string `json:"nodeName" comment:"环节名称"`
NodeDescribe string `json:"nodeDescribe" comment:"环节描述"`
NodeSort int `json:"nodeSort" comment:"环节顺序"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
... ...
... ... @@ -14,6 +14,7 @@ type NodeTask struct {
NodeType int `comment:"环节类型"`
NodeName string `comment:"环节名称"`
NodeDescribe string `comment:"环节描述"`
NodeSort int `comment:"环节顺序"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
... ...
... ... @@ -123,6 +123,10 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Where("name LIKE ?", v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
... ...
... ... @@ -131,6 +131,10 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
query.ExcludeColumn(excludeColumns...)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -30,6 +30,7 @@ func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.Nod
NodeType: m.NodeType,
NodeName: m.NodeName,
NodeDescribe: m.NodeDescribe,
NodeSort: m.NodeSort,
TimeStart: m.TimeStart,
TimeEnd: m.TimeEnd,
KpiCycle: m.KpiCycle,
... ... @@ -50,6 +51,7 @@ func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.Node
NodeType: d.NodeType,
NodeName: d.NodeName,
NodeDescribe: d.NodeDescribe,
NodeSort: d.NodeSort,
TimeStart: d.TimeStart,
TimeEnd: d.TimeEnd,
KpiCycle: d.KpiCycle,
... ...
... ... @@ -43,7 +43,7 @@ func NextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
var nextTime time.Time
switch kpiCycle {
case domain.KpiCycleDay:
nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天开始发送
nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天0点开始发送
break
case domain.KpiCycleWeek:
offsetSeconds := int64(now0.Sub(start0).Seconds())
... ...