using AUCMA.STORE.Business.Interface;
using AUCMA.STORE.Common;
using AUCMA.STORE.Entity.DAO;
using AUCMA.STORE.Entity.DTO;
using AUCMA.STORE.Entity.Enums;
using AUCMA.STORE.SqlSugar;
using AUCMA.STORE.SqlSugar.serviceImpl;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AUCMA.STORE.Business.Implements
{
///
/// 出入库任务队列接口实现
///
public class BaseTaskQueueBusiness : IBaseTaskQueueBusiness
{
private readonly IBaseServices baseServices = new BaseServices();
///
/// 写入任务队列
///
///
public async Task WriteTaskQueue(TaskDTO taskDTO)
{
try
{
Mapper.Initialize(cret => cret.CreateMap());
BaseTaskQueue baseTaskQueue = Mapper.Map(taskDTO);
baseTaskQueue.uuid = System.Guid.NewGuid().ToString("N");
baseTaskQueue.recordTime = DateTime.Now;
var info = await baseServices.Add(baseTaskQueue);
return info;
}catch(Exception ex)
{
LogHelper.Error("写入任务队列异常", ex);
return 0;
}
}
///
/// 获取任务队列
///
///
///
public async Task GetTaskQueue(LocationArea locationArea, TaskType taskType, OperationType operationType)
{
try
{
Expression> exp = s1 => true;
Expression> order = (x) => x.recordTime;
//exp = exp.And(s1 => s1.locationArea == locationArea && s1.pilerTaskType == taskType && s1.operationType == operationType && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
exp = exp.And(s1 => s1.pilerTaskType == taskType && s1.operationType == operationType && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
if (taskType == TaskType.InStore)
{
exp = exp.And(s1 => s1.locationArea == locationArea);
}
if(taskType == TaskType.OutStore)
{
if(operationType == OperationType.ManualOperation)
{
exp = exp.And(s1 => s1.locationArea == locationArea);
}
}
//var outStoreType = iNIFile.IniReadValue("系统设置", "出库方式");
//if(outStoreType == "2")
//{
// if(taskType == TaskType.OutStore)
// {
// exp = exp.And(s1 => s1.locationArea == locationArea);
// }
//}
List baseTaskQueues = await baseServices.Query(exp, order, true);
return baseTaskQueues.FirstOrDefault();
}catch(Exception ex)
{
LogHelper.Error("获取任务队列异常", ex);
return new BaseTaskQueue();
}
}
///
/// 清除任务队列
///
///
///
public async Task DeleteTaskQueue(BaseTaskQueue baseTaskQueue)
{
try
{
return await baseServices.Delete(baseTaskQueue);
}catch(Exception ex)
{
LogHelper.Error("清除任务队列异常", ex);
return false;
}
}
///
/// 清除指定任务
///
///
///
public async Task DeleteAssignTask(string taskCode)
{
try
{
Expression> exp = s1 => true;
//Expression> order = (x) => x.recordTime;
exp = exp.And(s1 => s1.pilerTaskCode == taskCode && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
List baseTaskQueues = await baseServices.Query(exp);
baseTaskQueues.ForEach(x =>
{
baseServices.Delete(x);
});
return true;
}catch(Exception ex)
{
LogHelper.Error("清除指定任务异常", ex);
return false;
}
}
///
/// 获取所有符合条件的任务集合
///
///
///
///
public async Task> GetTaskQueueList()
{
Expression> exp = s1 => true;
exp = exp.And(x => x.storeCode.Equals(ConfigHelper.GetConfig("storeCode")));
List info = await baseServices.Query(exp);
info.ForEach(x =>
{
LogHelper.Info("队列初始化查询" + JsonChange.ModeToJson(x));
});
return info;
}
}
}