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

446 lines
15 KiB
C#

using Aucma.Scada.Model.domain;
using HighWayIot.Common;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
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, 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>
/// <summary>
6 months ago
public List<RealTaskInfo> GetAllInstoreTaskByStoreCode(string storeCode, string spaceCode, int taskType, int status)
{
List<RealTaskInfo> taskList = null;
6 months ago
try
{
6 months ago
taskList = _mesRepository.GetList(x => x.storeCode == storeCode && x.spaceCode == spaceCode && x.taskType == taskType && x.taskStatus == status);
}
catch (Exception ex)
{
logHelper.Error("通过仓库编号获取待执行的任务信息异常", ex);
}
return taskList;
}
/// <summary>
/// 泡后库出库删除所有任务信息
/// </summary>
/// <param name="taskInfo"></param>
/// <summary>
public bool DeleteAllTaskByStoreCode(string storeCode, int taskType)
{
List<RealTaskInfo> taskList = null;
bool result = false;
try
{
taskList = _mesRepository.GetList(x => x.storeCode == storeCode && x.taskType == taskType);
if (taskList != null)
{
result = _mesRepository.Delete(taskList);
}
}
catch (Exception ex)
{
logHelper.Error("通过仓库编号获取待执行的任务信息异常", ex);
}
return result;
}
/// <summary>
/// 泡后库出库删除任务信息,根据时间删除第一条
/// </summary>
/// <param name="taskInfo"></param>
/// <summary>
public bool DeleteFirstTaskByStoreCode(string storeCode, int taskType)
{
RealTaskInfo taskInfo = null;
bool result = false;
try
{
List<RealTaskInfo> taskList = _mesRepository.GetList(x => x.storeCode == storeCode && x.taskType == taskType && x.taskStatus == 2);
6 months ago
if (taskList != null && taskList.Count > 0)
{
taskInfo = taskList.OrderBy(x => x.createTime).FirstOrDefault();
result = _mesRepository.Delete(taskInfo);
}
6 months ago
}
catch (Exception ex)
{
logHelper.Error("通过仓库编号获取待执行的任务信息异常", ex);
}
return result;
}
/// <summary>
/// 泡后库出库删除任务信息
/// </summary>
/// <param name="taskInfo"></param>
public bool DeleteTaskInfoByCode(RealTaskInfo taskInfo)
{
bool result = false;
try
{
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="storeCode"></param>
/// <returns></returns>
public List<RealTaskInfo> GetAllTaskInfoByStoreCode(string storeCode, int taskType)
{
List<RealTaskInfo> taskInfo = null;
try
{
taskInfo = _mesRepository.GetList(x => x.storeCode == storeCode && x.taskStatus == 1 && x.taskType == taskType);
}
catch (Exception ex)
{
logHelper.Error("通过仓库编号获取待执行的任务信息异常", ex);
}
return taskInfo;
}
/// <summary>
/// 根据条码获取该型号出库任务按照时间排序第一条信息
/// </summary>
/// <param name="taskCode"></param>
/// <returns></returns>
public RealTaskInfo GetTaskInfoByTaskCode(string materialType, string storeCode, int taskType)
{
RealTaskInfo taskInfo = null;
try
{
6 months ago
List<RealTaskInfo> list = _mesRepository.GetList(x => x.storeCode == storeCode && x.taskType == taskType && x.materialType == materialType);
if (list.Count > 0)
{
taskInfo = list.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, 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);
}
catch (Exception ex)
{
logHelper.Error("获取指定状态的任务信息异常", ex);
}
return taskInfos;
}
/// <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 进行分组
6 months ago
.Select(group => group.OrderBy(rti => rti.createTime).First())
.ToList();
}
catch (Exception ex)
{
logHelper.Error("获取指定状态的任务信息异常", ex);
}
return filteredList;
}
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);
}
/// <summary>
/// 根据货道号找到对应的入库任务
/// </summary>
/// <param name="spaceCode"></param>
/// <returns></returns>
6 months ago
public List<RealTaskInfo> GetTaskInfosBySpaceCode(string storeCode, string spaceCode, 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);
exp = exp.And(x => x.spaceCode == spaceCode);
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;
}
}
}