public Result CancelDeviceOperateSchedule([FromBody] DeviceOperateSchedule schedule)
        {
            var qId = schedule.Id;
            var old = DeviceOperateScheduleHelper.GetOpDetail(qId);

            if (old == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleNotExist));
            }
            //if (old.OperatorId != schedule.OperatorId)
            //{
            //    return Result.GenError<Result>(Error.DeviceOperateScheduleOperatorError);
            //}
            if (old.State != DeviceOperateScheduleState.未开始)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleNotWait));
            }

            var optor = schedule.OperatorId != 0 ? DeviceOperateOperatorHelper.GetDetail(schedule.OpId, schedule.OperatorId) : null;

            schedule.OperatorId = optor?.Id ?? 0;
            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            old.MarkedDateTime = markedDateTime;
            var log = ClassExtension.CopyTo <DeviceOperateScheduleDetail, DeviceOperateLog>(old);

            log.Type         = DeviceOperateLogType.延后;
            log.CreateUserId = userId;
            log.EndTime      = markedDateTime;
            DeviceOperateScheduleHelper.BackSchedule(old);
            DeviceOperateLogHelper.Instance.Add(log);
            return(Result.GenError <Result>(Error.Success));
        }
        public Result CompleteDeviceOperateSchedule([FromBody] DeviceOperateSchedule schedule)
        {
            var qId = schedule.Id;
            var old = DeviceOperateScheduleHelper.GetOpDetail(qId);

            if (old == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleNotExist));
            }
            var opr = DeviceOperateOperatorHelper.GetDetail(schedule.OpId, schedule.OperatorId);

            if (opr == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateOperatorNotExist));
            }
            schedule.OperatorId = opr.Id;
            if (old.OperatorId != schedule.OperatorId)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleOperatorError));
            }
            if (old.State == DeviceOperateScheduleState.未开始)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleNotStart));
            }

            var optor = DeviceOperateOperatorHelper.Instance.Get <DeviceOperateOperator>(schedule.OperatorId);

            if (optor == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateOperatorIsExist));
            }
            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            if (old.State == DeviceOperateScheduleState.进行中)
            {
                var total = (int)(markedDateTime - old.StartTime).TotalSeconds;
                old.OpCost += total;
            }
            else if (old.State == DeviceOperateScheduleState.已暂停)
            {
                var total = (int)(markedDateTime - old.StartTime).TotalSeconds;
                old.OpCost += total;
            }
            old.MarkedDateTime = markedDateTime;
            old.EndTime        = markedDateTime;
            old.EndCount++;
            var log = ClassExtension.CopyTo <DeviceOperateScheduleDetail, DeviceOperateLog>(old);

            log.CreateUserId = userId;
            log.Type         = DeviceOperateLogType.完成;
            old.LastLogId    = DeviceOperateLogHelper.Instance.AddBackId(log);
            DeviceOperateScheduleHelper.CompleteSchedule(old);
            return(Result.GenError <Result>(Error.Success));
        }
        public Result StartDeviceOperateSchedule([FromBody] DeviceOperateSchedule schedule)
        {
            var qId = schedule.Id;
            var old = DeviceOperateScheduleHelper.GetOpDetail(qId);

            if (old == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleNotExist));
            }
            var opr = DeviceOperateOperatorHelper.GetDetail(schedule.OpId, schedule.OperatorId);

            if (opr == null)
            {
                return(Result.GenError <Result>(Error.DeviceOperateOperatorNotExist));
            }
            schedule.OperatorId = opr.Id;
            if (old.OperatorId != schedule.OperatorId)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleOperatorError));
            }
            if (old.State == DeviceOperateScheduleState.进行中)
            {
                return(Result.GenError <Result>(Error.DeviceOperateScheduleDoing));
            }

            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            if (old.State == DeviceOperateScheduleState.已暂停)
            {
                var total = (int)(markedDateTime - old.PauseTime).TotalSeconds;
                old.PauseCost += total;
            }
            old.MarkedDateTime = markedDateTime;
            old.FirstStartTime = old.FirstStartTime == default(DateTime) ? markedDateTime : old.FirstStartTime;
            old.StartTime      = markedDateTime;
            old.StartCount++;
            old.Remark = schedule.Remark ?? old.Remark;
            var log = ClassExtension.CopyTo <DeviceOperateScheduleDetail, DeviceOperateLog>(old);

            log.CreateUserId = userId;
            log.Type         = DeviceOperateLogType.开始;
            DeviceOperateScheduleHelper.StartSchedule(old);
            DeviceOperateLogHelper.Instance.Add(log);
            return(Result.GenError <Result>(Error.Success));
        }