|
|
|
|
using Aucma.Scada.Model.domain;
|
|
|
|
|
using HighWayIot.Common;
|
|
|
|
|
using HighWayIot.Log4net;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
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="storeCode"></param>
|
|
|
|
|
/// <param name="taskType"></param>
|
|
|
|
|
/// <param name="taskStatus"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<RealTaskInfo> GetTaskInfosForInstore(string storeCode, int taskType, int taskStatus)
|
|
|
|
|
{
|
|
|
|
|
List<RealTaskInfo> realTaskInfos = null;
|
|
|
|
|
List<RealTaskInfo> filteredList = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<RealTaskInfo, bool>> exp = s1 => true;
|
|
|
|
|
exp = exp.And(x => x.taskType == taskType && storeCode.Contains(x.storeCode));
|
|
|
|
|
exp = exp.And(x => x.taskStatus == taskStatus);
|
|
|
|
|
realTaskInfos = _mesRepository.GetList(exp);
|
|
|
|
|
|
|
|
|
|
if (realTaskInfos == null || realTaskInfos.Count == 0) return null;
|
|
|
|
|
|
|
|
|
|
filteredList = realTaskInfos.GroupBy(rti => rti.spaceCode) // 按照 spaceCode 进行分组
|
|
|
|
|
.Select(group => group.OrderBy(rti => rti.createTime).First())
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("获取指定状态的任务信息异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return filteredList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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, string storeCode = null)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo taskInfo = GetTaskInfoByTaskCode(taskCode, storeCode);
|
|
|
|
|
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);
|
|
|
|
|
new ArgumentNullException($"通过仓库编号获取待执行的任务信息异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
return taskInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据任务号获取任务信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public RealTaskInfo GetTaskInfoByTaskCode(string taskCode, string storeCode)
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo taskInfo = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
taskInfo = _mesRepository.GetFirst(x => x.storeCode == storeCode && 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);
|
|
|
|
|
if(taskInfos.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
taskInfos.OrderBy(x => x.createTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("获取指定状态的任务信息异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return taskInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RealTaskInfo> GetTaskInfosByTaskCode(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
List<RealTaskInfo> taskInfos = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<RealTaskInfo, bool>> exp = s1 => true;
|
|
|
|
|
exp = exp.And(x => x.taskCode == taskCode);
|
|
|
|
|
taskInfos = _mesRepository.GetList(exp);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("获取指定状态的任务信息异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return taskInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteTaskInfoById(int id)
|
|
|
|
|
{
|
|
|
|
|
return _mesRepository.DeleteById(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|