作者 郑周

优化本地环节时间

... ... @@ -198,8 +198,8 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
minTime := time.Date(cycle.TimeStart.Year(), cycle.TimeStart.Month(), cycle.TimeStart.Day(), cycle.TimeStart.Hour(), cycle.TimeStart.Minute(), 0, 0, time.Local)
maxTime := time.Date(cycle.TimeEnd.Year(), cycle.TimeEnd.Month(), cycle.TimeEnd.Day(), cycle.TimeEnd.Hour(), cycle.TimeEnd.Minute(), 0, 0, time.Local)
minTime := cycle.TimeStart.Local()
maxTime := cycle.TimeEnd.Local()
if start.Before(minTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估起始时间不能超出周期起始时间")
... ... @@ -393,15 +393,20 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
TimeEnd: node.TimeEnd,
KpiCycle: node.KpiCycle,
}
// 环节起始和截止本地时间
startLocal := node.TimeStart.Local()
endLocal := node.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if node.TimeStart.Before(now) {
nextTime := utils.NextTime(nowO, node.TimeStart, node.KpiCycle)
if startLocal.Before(now) {
nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = node.TimeStart
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(*node.TimeEnd) {
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
... ...
... ... @@ -77,16 +77,15 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
// 项目
project, ok := projectIdsMap[task.ProjectId]
if ok {
// 环节截止时间
maxTime := time.Date(task.TimeEnd.Year(), task.TimeEnd.Month(), task.TimeEnd.Day(), task.TimeEnd.Hour(), task.TimeEnd.Minute(), 0, 0, time.Local)
maxTime := task.TimeEnd.Local()
// 当前周起始时间和截止时间
var cycleTimeStart = task.NextSentAt
var cycleTimeEnd *time.Time
var cycleTimeStart = task.NextSentAt.Local()
var cycleTimeEnd time.Time
// 下个周期起始时间
nextTime := utils.NextTimeInc(task.NextSentAt, task.KpiCycle)
nextTime := utils.NextTimeInc(cycleTimeStart, task.KpiCycle)
// 超过截止时间
if nextTime.After(maxTime) {
task.NextSentAt = nil
... ... @@ -96,14 +95,14 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
// 下个周期的起始时间=当前周期的截止时间
if task.NextSentAt == nil {
cycleTimeEnd = &maxTime
cycleTimeEnd = maxTime
} else {
cycleTimeEnd = task.NextSentAt
cycleTimeEnd = task.NextSentAt.Local()
}
// 格式化周期的起始和截止时间
fmCycleStartTime := cycleTimeStart.Local().Format("2006-1-2 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Local().Format("2006-1-2 15:04:05")
fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
... ...
... ... @@ -36,9 +36,10 @@ 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(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.Local)
start0 := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
var nextTime time.Time
switch kpiCycle {
... ... @@ -71,9 +72,10 @@ func NextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
}
// 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(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.Local)
start0 := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
var nextTime time.Time
switch kpiCycle {
... ...