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.
254 lines
8.3 KiB
C#
254 lines
8.3 KiB
C#
using Admin.Core.IRepository;
|
|
using Admin.Core.IService;
|
|
using Admin.Core.Model;
|
|
using Microsoft.IdentityModel.Logging;
|
|
using System.Collections.Generic;
|
|
using System.Linq.Expressions;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using log4net;
|
|
using Org.BouncyCastle.Asn1.Tsp;
|
|
using System.Linq;
|
|
using Admin.Core.Common;
|
|
|
|
namespace Admin.Core.Service
|
|
{
|
|
public class RealTaskInfoServices : BaseServices<RealTaskInfo>, IRealTaskInfoServices
|
|
{
|
|
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RealTaskInfoServices));
|
|
private readonly IBaseRepository<RealTaskInfo> _dal;
|
|
private readonly IRealTaskInfoRepository _realTaskInfoRepository;
|
|
public RealTaskInfoServices(IBaseRepository<RealTaskInfo> dal, IRealTaskInfoRepository realTaskInfoRepository)
|
|
{
|
|
this._dal = dal;
|
|
base.BaseDal = dal;
|
|
_realTaskInfoRepository= realTaskInfoRepository;
|
|
}
|
|
|
|
public Task<RealTaskInfo> FirstAsync()
|
|
{
|
|
return _realTaskInfoRepository.FirstAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加任务信息
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AddTaskInfo(RealTaskInfo taskInfo)
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
int r =await _dal.AddAsync(taskInfo);
|
|
if (r > 0) { result=true; }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("添加任务信息异常", ex);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除任务信息
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
public async Task<bool> DeleteTaskInfo(string taskCode, string storeCode = null)
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
RealTaskInfo taskInfo =await GetTaskInfoByTaskCode(taskCode, storeCode);
|
|
if (taskInfo != null)
|
|
{
|
|
result = await _dal.DeleteAsync(taskInfo);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("删除任务信息异常", ex);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新任务信息
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> UpdateTaskInfo(RealTaskInfo taskInfo)
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
result =await _dal.UpdateAsync(taskInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("更新任务信息异常", ex);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量更新任务信息
|
|
/// </summary>
|
|
/// <param name="taskInfos"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> UpdateRangeTaskInfoAsync(List<RealTaskInfo> taskInfos)
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
result = await _dal.UpdateAsync(taskInfos);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("更新任务信息异常", ex);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过任务编号更新任务状态
|
|
/// </summary>
|
|
/// <param name="taskCode"></param>
|
|
/// <param name="taskStatus"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> UpdateTaskStatusByTaskCode(string taskCode, int taskStatus)
|
|
{
|
|
bool result = false;
|
|
RealTaskInfo taskInfo = null;
|
|
try
|
|
{
|
|
taskInfo =await _dal.FirstAsync(x => x.TaskCode == taskCode);
|
|
|
|
if (taskInfo != null)
|
|
{
|
|
taskInfo.TaskStatus = taskStatus;
|
|
result =await _dal.UpdateAsync(taskInfo);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("通过任务编号更新任务状态异常", ex);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过仓库编号获取待执行的任务信息,根据时间依次获取
|
|
/// </summary>
|
|
/// <param name="storeCode"></param>
|
|
/// <returns></returns>
|
|
public async Task<RealTaskInfo> GetTaskInfoByStoreCode(string storeCode, int taskType)
|
|
{
|
|
RealTaskInfo taskInfo = null;
|
|
try
|
|
{
|
|
taskInfo = (await _dal.QueryAsync(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 async Task<RealTaskInfo> GetTaskInfoByTaskCode(string taskCode, string storeCode)
|
|
{
|
|
RealTaskInfo taskInfo = null;
|
|
try
|
|
{
|
|
taskInfo =await _dal.FirstAsync(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 async Task<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 = await _dal.QueryAsync(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 async Task<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 =await _dal.QueryAsync(exp);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("获取指定状态的任务信息异常", ex);
|
|
}
|
|
return taskInfos;
|
|
}
|
|
|
|
public async Task<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 =await _dal.QueryAsync(exp);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("获取指定状态的任务信息异常", ex);
|
|
}
|
|
return taskInfos;
|
|
}
|
|
|
|
public async Task<bool> DeleteTaskInfoById(int id)
|
|
{
|
|
return await _dal.DeleteByIdAsync(id);
|
|
}
|
|
|
|
public Task<bool> UpdateRangeTaskInfo(List<RealTaskInfo> taskInfos)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |