100 lines
3.6 KiB
C#
100 lines
3.6 KiB
C#
using Cowain.Bake.Common.Core;
|
||
using Cowain.Bake.Common.Enums;
|
||
using Cowain.Bake.Model;
|
||
using Cowain.Bake.Model.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using Unity;
|
||
|
||
|
||
namespace Cowain.Bake.BLL
|
||
{
|
||
public class TaskStepService : ServiceBase
|
||
{
|
||
public TaskStepService(IUnityContainer unityContainer) : base(unityContainer)
|
||
{
|
||
}
|
||
public int UpdateEndTime(int taskId, ETaskStep taskStep) //int taskId,
|
||
{
|
||
using (var Context = new BakingEntities())
|
||
{
|
||
var model = Context.Set<TTaskStep>().Where(x => x.StepId == (int)taskStep && x.TaskRecordId == taskId).FirstOrDefault();
|
||
if (model == null)
|
||
{
|
||
LogHelper.Instance.Warn($"查找步骤失败,任务ID:{taskId},步骤:{taskStep}");
|
||
return 0;
|
||
}
|
||
model.EndTime = DateTime.Now;
|
||
return Context.SaveChanges();
|
||
}
|
||
}
|
||
|
||
//会修改TTaskRecord的StepId值
|
||
public int UpdateStartTime(int taskId, int count, int taskStep)
|
||
{
|
||
using (var Context = new BakingEntities())
|
||
{
|
||
var model = Context.Set<TTaskStep>().Where(x => x.StepId == taskStep && x.TaskRecordId == taskId).FirstOrDefault();
|
||
|
||
if (null == model)
|
||
{
|
||
LogHelper.Instance.Fatal($"修改步时间出现过为空,任务ID:{taskId},步:{taskStep}");
|
||
return 0;
|
||
}
|
||
model.StartTime = DateTime.Now;
|
||
model.Count = count;
|
||
return Context.SaveChanges();
|
||
}
|
||
}
|
||
|
||
public List<TTaskStep> GetTaskStep(int taskRecodeId)
|
||
{
|
||
using (var Context = new BakingEntities())
|
||
{
|
||
return Context.Set<TTaskStep>().Where(x => x.TaskRecordId == taskRecodeId && x.Count != null).ToList();
|
||
}
|
||
}
|
||
|
||
public List<TTaskStep> GetTaskAllStep(int taskRecodeId)
|
||
{
|
||
using (var Context = new BakingEntities())
|
||
{
|
||
return Context.Set<TTaskStep>().Where(x => x.TaskRecordId == taskRecodeId).ToList();
|
||
}
|
||
}
|
||
|
||
//public TaskRecordStepModel GetLastStep()
|
||
//{
|
||
// using (var Context = new BakingEntities())
|
||
// {
|
||
// return (from tr in Context.Set<TTaskRecord>()
|
||
// join ts in Context.Set<TTaskStep>() on tr.Id equals ts.TaskRecordId into cs
|
||
// from ts in cs.DefaultIfEmpty() // 左连接 Scores
|
||
// where tr.Status != (int)ETaskStatus.ExecutionCompleted && ts.Count != null
|
||
// orderby ts.Id descending
|
||
// select new TaskRecordStepModel
|
||
// {
|
||
// Id = tr.Id,
|
||
// PalletId = tr.PalletId,
|
||
// TaskTypeId = tr.TaskTypeId,
|
||
// Source = tr.Source,
|
||
// Target = tr.Target,
|
||
// Status = tr.Status,
|
||
// BuildTime = tr.BuildTime,
|
||
// StartTime = tr.StartTime,
|
||
// EndTime = tr.EndTime,
|
||
|
||
// TaskStepId = ts.Id,
|
||
// Count = ts.Count,
|
||
// StepId = ts.StepId,
|
||
// StepStartTime = ts.StartTime,
|
||
// StepEndTime = ts.EndTime,
|
||
// }).FirstOrDefault();
|
||
|
||
// }
|
||
//}
|
||
}
|
||
}
|