You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aucma.Scada/HighWayIot.Repository/service/Impl/RealTaskInfoServiceImpl.cs

213 lines
6.7 KiB
C#

using HighWayIot.Common;
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class RealTaskInfoServiceImpl : IRealTaskInfoService
{
private Repository<RealTaskInfo> _mesRepository = new Repository<RealTaskInfo>("mes");
private LogHelper logHelper = LogHelper.Instance;
/// <summary>
/// 添加任务信息
/// </summary>
/// <param name="taskInfo"></param>
/// <returns></returns>
public bool AddTaskInfo(RealTaskInfo taskInfo)
{
bool result = false;
try
{
result = _mesRepository.Insert(taskInfo);
}
catch(Exception ex)
{
logHelper.Error("添加任务信息异常",ex);
}
return result;
}
/// <summary>
/// 删除任务信息
/// </summary>
/// <param name="taskInfo"></param>
public bool DeleteTaskInfo(string taskCode)
{
bool result = false;
try
{
RealTaskInfo taskInfo = GetTaskInfoByTaskCode(taskCode);
if(taskInfo != null)
{
result = _mesRepository.Delete(taskInfo);
}
}
catch (Exception ex)
{
logHelper.Error("删除任务信息异常", ex);
}
return result;
}
/// <summary>
/// 更新任务信息
/// </summary>
/// <param name="taskInfo"></param>
/// <returns></returns>
public bool UpdateTaskInfo(RealTaskInfo taskInfo)
{
bool result = false;
try
{
result = _mesRepository.Update(taskInfo);
}
catch (Exception ex)
{
logHelper.Error("更新任务信息异常", ex);
}
return result;
}
/// <summary>
/// 批量更新任务信息
/// </summary>
/// <param name="taskInfos"></param>
/// <returns></returns>
public bool UpdateRangeTaskInfo(List<RealTaskInfo> taskInfos)
{
bool result = false;
try
{
result = _mesRepository.UpdateRange(taskInfos);
}
catch (Exception ex)
{
logHelper.Error("更新任务信息异常", ex);
}
return result;
}
/// <summary>
/// 通过任务编号更新任务状态
/// </summary>
/// <param name="taskCode"></param>
/// <param name="taskStatus"></param>
/// <returns></returns>
public bool UpdateTaskStatusByTaskCode(string taskCode, int taskStatus)
{
bool result = false;
RealTaskInfo taskInfo = null;
try
{
taskInfo = _mesRepository.GetFirst(x => x.taskCode == taskCode);
if (taskInfo != null)
{
taskInfo.taskStatus = taskStatus;
result = _mesRepository.Update(taskInfo);
}
}catch(Exception ex)
{
logHelper.Error("通过任务编号更新任务状态异常", ex);
}
return result;
}
/// <summary>
/// 通过仓库编号获取待执行的任务信息,根据时间依次获取
/// </summary>
/// <param name="storeCode"></param>
/// <returns></returns>
public RealTaskInfo GetTaskInfoByStoreCode(string storeCode,int taskType)
{
RealTaskInfo taskInfo = null;
try
{
taskInfo = _mesRepository.GetList(x => x.storeCode == storeCode && x.taskStatus == 1 && x.taskType == taskType).OrderBy(x=>x.createTime).FirstOrDefault();
}
catch (Exception ex)
{
logHelper.Error("通过仓库编号获取待执行的任务信息异常", ex);
}
return taskInfo;
}
/// <summary>
/// 根据任务号获取任务信息
/// </summary>
/// <param name="taskCode"></param>
/// <returns></returns>
public RealTaskInfo GetTaskInfoByTaskCode(string taskCode)
{
RealTaskInfo taskInfo = null;
try
{
taskInfo = _mesRepository.GetFirst(x => x.taskCode == taskCode);
}
catch (Exception ex)
{
logHelper.Error("根据任务号获取任务信息异常", ex);
}
return taskInfo;
}
/// <summary>
/// 通过仓库编号获取任务
/// </summary>
/// <param name="storeCode"></param>
/// <param name="taskType"></param>
/// <returns></returns>
public List<RealTaskInfo> GetTaskInfosByStoreCode(string[] storeCode, int taskType)
{
List<RealTaskInfo> taskInfos = null;
try
{
Expression<Func<RealTaskInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.taskType == taskType && x.taskStatus != 3 && storeCode.Contains(x.storeCode));
taskInfos = _mesRepository.GetList(exp);
}
catch (Exception ex)
{
logHelper.Error("根据任务号获取任务信息异常", ex);
}
return taskInfos;
}
/// <summary>
/// 获取指定状态的任务列表,如果为0返回所有状态
/// </summary>
/// <param name="storeCode"></param>
/// <param name="taskType"></param>
/// <param name="taskStatus"></param>
/// <returns></returns>
public List<RealTaskInfo> GetTaskInfosByTaskStatus(string[] storeCode,int taskType, int taskStatus)
{
List<RealTaskInfo> taskInfos = null;
try
{
Expression<Func<RealTaskInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.taskType == taskType && storeCode.Contains(x.storeCode)) ;
if(taskStatus != 0)
{
exp = exp.And(x => x.taskStatus == taskStatus);
}
taskInfos = _mesRepository.GetList(exp);
}
catch (Exception ex)
{
logHelper.Error("获取指定状态的任务信息异常", ex);
}
return taskInfos;
}
}
}