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 _mesRepository = new Repository("mes"); private LogHelper logHelper = LogHelper.Instance; /// /// 添加任务信息 /// /// /// public bool AddTaskInfo(RealTaskInfo taskInfo) { bool result = false; try { result = _mesRepository.Insert(taskInfo); } catch(Exception ex) { logHelper.Error("添加任务信息异常",ex); } return result; } /// /// 删除任务信息 /// /// 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; } /// /// 更新任务信息 /// /// /// public bool UpdateTaskInfo(RealTaskInfo taskInfo) { bool result = false; try { result = _mesRepository.Update(taskInfo); } catch (Exception ex) { logHelper.Error("更新任务信息异常", ex); } return result; } /// /// 通过任务编号更新任务状态 /// /// /// /// 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; } /// /// 通过仓库编号获取待执行的任务信息,根据时间依次获取 /// /// /// 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; } /// /// 根据任务号获取任务信息 /// /// /// public RealTaskInfo GetTaskInfoByTaskCode(string taskCode) { RealTaskInfo taskInfo = null; try { taskInfo = _mesRepository.GetFirst(x => x.taskCode == taskCode); } catch (Exception ex) { logHelper.Error("根据任务号获取任务信息异常", ex); } return taskInfo; } /// /// 通过仓库编号获取任务 /// /// /// /// public List GetTaskInfosByStoreCode(string[] storeCode, int taskType) { List taskInfos = null; try { Expression> 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; } /// /// 获取指定状态的任务列表,如果为0返回所有状态 /// /// /// /// /// public List GetTaskInfosByTaskStatus(string[] storeCode,int taskType, int taskStatus) { List taskInfos = null; try { Expression> 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; } } }