using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using Model.ModelDto.BllSoDto;
|
using Model.ModelDto.LogDto;
|
using SqlSugar;
|
using WMS.DAL;
|
using WMS.Entity.Context;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ILogServer;
|
|
namespace WMS.BLL.LogServer
|
{
|
public class TaskServer:DbHelper<LogTask>,ITaskServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
public TaskServer():base(Db)
|
{
|
}
|
|
|
public List<TaskDto> GetTaskList(List<string> orderType, string type, string status, string taskNo, int isSuccess, string palletNo, string msg, int page, int limit, out int count)
|
{
|
try
|
{
|
Expression<Func<LogTask, bool>> item = Expressionable.Create<LogTask>()
|
.AndIF( orderType.Count>0, it => orderType.Contains(it.OrderType))
|
.AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
|
.AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
|
.AndIF(!string.IsNullOrWhiteSpace(taskNo), it => it.TaskNo.Contains(taskNo.Trim()))
|
.AndIF(isSuccess != -1, it => it.IsSuccess == isSuccess)
|
.AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(msg), it => it.Msg.Contains(msg.Trim()))
|
.ToExpression();//注意 这一句 不能少
|
var total = 0;
|
var data = GetAllWhereAsync(item)
|
.LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id).
|
Select((a, b) => new TaskDto()
|
{
|
Id = a.Id,
|
TaskNo = a.TaskNo,
|
Sender = a.Sender,
|
Receiver = a.Receiver,
|
IsSuccess = a.IsSuccess,
|
Information = a.Information,
|
SendDate = a.SendDate,
|
BackDate = a.BackDate,
|
StartLocat = a.StartLocat,
|
EndLocat = a.EndLocat,
|
MessageDate = a.MessageDate,
|
PalletNo = a.PalletNo,
|
Msg = a.Msg,
|
IsSend = a.IsSend,
|
IsCancel = a.IsCancel,
|
IsFinish = a.IsFinish,
|
Status = a.Status,
|
Type = a.Type,
|
OrderType = a.OrderType,
|
|
LotNo = a.LotNo,
|
|
CancelDate = a.CancelDate,
|
FinishDate = a.FinishDate,
|
|
CreateUserName = b.RealName,
|
CreateTime = a.CreateTime
|
})
|
.OrderByDescending(a => a.TaskNo)
|
.ToOffsetPage(page, limit, ref total);
|
count = total;
|
|
return data.OrderByDescending(m=>m.TaskNo).ToList();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
//修改任务下发状态为成功
|
public void EditTaskIssueOk(List<string> taskNo, DateTime sendTime, DateTime backTime)
|
{
|
try
|
{
|
var list = GetAllWhereAsync(m => taskNo.Contains(m.TaskNo)).ToList();
|
foreach (var item in list)
|
{
|
item.IsSuccess = 1;
|
item.Status = "1";
|
item.SendDate = sendTime;
|
item.BackDate = backTime;
|
}
|
|
Db.Updateable(list).ExecuteCommand();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
//修改任务下发状态为失败异常信息
|
public void EditTaskIssueNo(List<string> taskNo, DateTime sendTime, DateTime backTime, string information)
|
{
|
try
|
{
|
var list = GetAllWhereAsync(m => taskNo.Contains(m.TaskNo)).ToList();
|
foreach (var item in list)
|
{
|
item.SendDate = sendTime;
|
item.BackDate = backTime;
|
item.Information = information;
|
}
|
|
Db.Updateable(list).ExecuteCommand();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public string GetTaskOrderType(string taskNo)
|
{
|
try
|
{
|
var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo);
|
if (task == null)
|
{
|
throw new Exception($"未查询到{taskNo}任务号的任务信息");
|
}
|
|
return task.OrderType;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public LogTask GetTaskType(string taskNo)
|
{
|
try
|
{
|
var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo);
|
if (task == null)
|
{
|
throw new Exception($"未查询到{taskNo}任务号的任务信息");
|
}
|
|
return task;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
#region 数据归档
|
/// <summary>
|
/// 获取任务列表-数据归档
|
/// </summary>
|
/// <returns></returns>
|
public List<TaskDto> GetArchivingTaskList(List<string> orderType, string type, string status, string taskNo, int isSuccess, string palletNo,
|
string msg, int page, int limit, out int count)
|
{
|
try
|
{
|
string sqlString = string.Empty;
|
string sqlCount = string.Empty;
|
string sqlPub = string.Empty;
|
sqlCount += "SELECT COUNT(tb1.ID) FROM ArchivingTask AS tb1 ";
|
sqlString += "select tb1.*,tb2.RealName as CreateUserName from ArchivingTask as tb1 ";
|
sqlPub += "left join SysUserInfor as tb2 on tb1.CreateUser=tb2.Id ";
|
sqlPub += $"where 1=1 ";
|
if (orderType.Count > 0)
|
{
|
string orderTypeStr = string.Join(",", orderType);
|
sqlPub += $"AND tb1.OrderType in ({orderTypeStr}) ";
|
}
|
if (!string.IsNullOrEmpty(type))
|
{
|
sqlPub += $"AND tb1.Type = '{type}' ";
|
}
|
if (!string.IsNullOrEmpty(status))
|
{
|
sqlPub += $"AND tb1.Status = '{status}' ";
|
}
|
if (!string.IsNullOrEmpty(taskNo))
|
{
|
sqlPub += $"AND tb1.TaskNo like '%{taskNo.Trim()}%' ";
|
}
|
if (isSuccess != -1)
|
{
|
sqlPub += $"AND tb1.IsSuccess = {isSuccess} ";
|
}
|
if (!string.IsNullOrEmpty(palletNo))
|
{
|
sqlPub += $"AND tb1.PalletNo like '%{palletNo.Trim()}%' ";
|
}
|
if (!string.IsNullOrEmpty(msg))
|
{
|
sqlPub += $"AND tb1.Msg like '%{msg.Trim()}%' ";
|
}
|
sqlCount += sqlPub;
|
sqlPub += " order by tb1.TaskNo desc ";
|
if (page == 0)
|
{
|
page = 1;
|
}
|
sqlString += sqlPub + $" offset {((page - 1) * limit)} rows fetch next {limit} rows only;";
|
|
var com = new Common();
|
count = com.GetRowCount(sqlCount);
|
|
var modelList = Db.Ado.SqlQuery<TaskDto>(sqlString);
|
|
return modelList;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
#endregion
|
}
|
}
|