作者 郑周

1. 优化时间以当天时间 0 点开始计算

... ... @@ -17,6 +17,7 @@ type EvaluationProjectAdapter struct {
}
func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User) {
adapter.RecipientList = make([]*UserAdapter, 0)
for i := range recipients {
adapter.RecipientList = append(adapter.RecipientList, &UserAdapter{
Id: recipients[i].Id,
... ... @@ -26,6 +27,7 @@ func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []
}
func (adapter *EvaluationProjectAdapter) TransformPmpAdapter(pms []*domain.User) {
adapter.PmpList = make([]*UserAdapter, 0)
for i := range pms {
adapter.PmpList = append(adapter.PmpList, &UserAdapter{
Id: pms[i].Id,
... ... @@ -46,6 +48,8 @@ func TransformProjectListAdapter(projects []*domain.EvaluationProject, users []*
epa := &EvaluationProjectAdapter{}
epa.EvaluationProject = project
epa.PmpList = make([]*UserAdapter, 0)
projectAdapters = append(projectAdapters, epa)
for j := range project.PmpIds {
... ...
... ... @@ -185,18 +185,20 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
// 重新计算
if task.NextSentAt == nil {
// 环节起始和截止本地时间
startLocal := task.TimeStart
endLocal := task.TimeEnd
startLocal := task.TimeStart.Local()
sYear, sMonth, sDay := startLocal.Date()
startLocal = time.Date(sYear, sMonth, sDay, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
endLocal := task.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(now) {
nextTime := utils.NextTime(nowO, startLocal, task.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = startLocal
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal.Local()) {
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
} else {
... ... @@ -435,6 +437,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
... ... @@ -456,8 +459,6 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
now := time.Now().Local()
nowO := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
... ... @@ -479,18 +480,20 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
}
// 环节起始和截止本地时间
startLocal := node.TimeStart
endLocal := node.TimeEnd
startLocal := task.TimeStart.Local()
sYear, sMonth, sDay := startLocal.Date()
startLocal = time.Date(sYear, sMonth, sDay, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
endLocal := task.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(now) {
nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = startLocal
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal.Local()) {
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
... ...
... ... @@ -87,7 +87,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
maxTime := task.TimeEnd.Local()
// 当前周起始时间和截止时间
var cycleTimeStart = task.NextSentAt
var cycleTimeStart = task.NextSentAt.Local()
var cycleTimeEnd time.Time
// 下个周期起始时间
... ...
... ... @@ -37,7 +37,7 @@ func ValidateCommand(commandType interface{}) error {
}
// NextTime 0点时刻为标准计算
func NextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
func NextTime(now0 time.Time, start time.Time, kpiCycle int) time.Time {
year, month, day := start.Date()
// 起始时间0点时刻
start0 := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
... ... @@ -141,7 +141,7 @@ func SubMonth(t1, t2 time.Time) (month int) {
}
// NextTimeInc 0点时刻为标准计算
func NextTimeInc(start *time.Time, kpiCycle int) time.Time {
func NextTimeInc(start time.Time, kpiCycle int) time.Time {
year, month, day := start.Date()
// 起始时间0点时刻
start0 := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
... ...