using System.Threading.Tasks;
using WcsMain.ApiServe.Controllers.Dto.WcsDto.Convey;
using WcsMain.ApiServe.Controllers.Dto.WcsDto.ElTag;
using WcsMain.Common;
using WcsMain.DataBase.TableEntity;
using WcsMain.WcsAttribute.AutoFacAttribute;
namespace WcsMain.DataBase.Dao;
[Component]
public class AppConveyTaskDao
{
///
/// 插入数据
///
///
///
public int Insert(List conveyTasks) => Insert(conveyTasks.ToArray());
///
/// 插入数据
///
///
///
public int Insert(params AppConveyTask[] conveyTasks)
{
try
{
var sqlFuc = CommonTool.DbServe.Insertable(conveyTasks);
return sqlFuc.ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 条件查询
///
///
///
public List? Query(AppConveyTask conveyTask)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(conveyTask.TaskId != default, w => w.TaskId == conveyTask.TaskId)
.WhereIF(conveyTask.TaskGroup != default, w => w.TaskGroup == conveyTask.TaskGroup)
.WhereIF(conveyTask.VehicleNo != default, w => w.VehicleNo == conveyTask.VehicleNo)
.WhereIF(conveyTask.TaskType != default, w => w.TaskType == conveyTask.TaskType)
.WhereIF(conveyTask.TaskStatus != default, w => w.TaskStatus == conveyTask.TaskStatus)
.WhereIF(conveyTask.Location != default, w => w.Location == conveyTask.Location)
.WhereIF(conveyTask.ArriveLocation != default, w => w.ArriveLocation == conveyTask.ArriveLocation)
.WhereIF(conveyTask.CreatePerson != default, w => w.CreatePerson == conveyTask.CreatePerson)
.WhereIF(conveyTask.Remark != default, w => w.Remark == conveyTask.Remark);
return sqlFuc.ToList();
}
catch(Exception ex)
{
_ = ex;
return default;
}
}
///
/// 查询所有
///
///
public List? Query() => Query(new AppConveyTask());
///
/// 根据主键更新数据
///
///
///
public int Update(params AppConveyTask[] conveyTask)
{
try
{
var sqlFuc = CommonTool.DbServe.Updateable(conveyTask).IgnoreColumns(ignoreAllNullColumns: true);
return sqlFuc.ExecuteCommand();
}
catch(Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 分页查询箱式线任务表
///
///
///
public (List? conveyTasks, int totalRows) QueryConveyTaskWithPage(QueryConveyTaskWithPageRequest request)
{
try
{
int totalRows = 0;
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(!string.IsNullOrEmpty(request.SearchStr),
w => w.TaskId!.Contains(request.SearchStr!)
|| w.TaskGroup!.Contains(request.SearchStr!)
|| w.Location!.Contains(request.SearchStr!)
|| w.ArriveLocation!.Contains(request.SearchStr!)
|| w.VehicleNo!.Contains(request.SearchStr!)
|| w.Remark!.Contains(request.SearchStr!));
if (request.TaskType != default)
{
List taskTaskType = [];
request.TaskType.ForEach(item => taskTaskType.Add(item));
sqlFuc.Where(w => taskTaskType.Contains(w.TaskType));
}
if (request.TaskStatus != default)
{
List taskStatus = [];
request.TaskStatus.ForEach(item => taskStatus.Add(item));
sqlFuc.Where(w => taskStatus.Contains(w.TaskStatus));
}
if (request.TimeRange is { Count: 2 }) // 时间范围
{
sqlFuc.Where(w => w.CreateTime > request.TimeRange[0] && w.CreateTime < request.TimeRange[1]);
}
sqlFuc.OrderByDescending(o => new { o.CreateTime });
var queryResult = sqlFuc.ToPageList(request.Page!.PageIndex, request.Page!.PageSize, ref totalRows);
return (queryResult, totalRows);
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
/*************************************** 业务 **************************************************/
///
/// 清理数据
///
///
///
public int ClearData(int days)
{
try
{
var sqlFuc = CommonTool.DbServe.Deleteable()
.Where(w => w.CreateTime < DateTime.Now.AddDays(-days));
return sqlFuc.ExecuteCommand();
}
catch(Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 联表查询任务,带出站台号,区域
///
///
///
public List? QueryWithStandInfo(AppConveyTask conveyTask)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(conveyTask.TaskId != default, w => w.TaskId == conveyTask.TaskId)
.WhereIF(conveyTask.TaskGroup != default, w => w.TaskGroup == conveyTask.TaskGroup)
.WhereIF(conveyTask.VehicleNo != default, w => w.VehicleNo == conveyTask.VehicleNo)
.WhereIF(conveyTask.TaskType != default, w => w.TaskType == conveyTask.TaskType)
.WhereIF(conveyTask.TaskStatus != default, w => w.TaskStatus == conveyTask.TaskStatus)
.WhereIF(conveyTask.Location != default, w => w.Location == conveyTask.Location)
.WhereIF(conveyTask.ArriveLocation != default, w => w.ArriveLocation == conveyTask.ArriveLocation)
.WhereIF(conveyTask.CreatePerson != default, w => w.CreatePerson == conveyTask.CreatePerson)
.WhereIF(conveyTask.Remark != default, w => w.Remark == conveyTask.Remark)
.LeftJoin((ct, cs) => ct.Location == cs.StandId)
.OrderBy(ct => ct.CreateTime)
.Select((ct, cs) => new JoinAppConveyTaskAndAppConveyStand
{
TaskId = ct.TaskId,
TaskGroup = ct.TaskGroup,
VehicleNo = ct.VehicleNo,
TaskType = ct.TaskType,
TaskStatus = ct.TaskStatus,
Location = ct.Location,
ArriveLocation = ct.ArriveLocation,
CreatePerson = ct.CreatePerson,
CreateTime = ct.CreateTime,
MoveTime = ct.MoveTime,
CompleteTime = ct.CompleteTime,
Remark = ct.Remark,
StandId = cs.StandId,
StandType = cs.StandType,
});
return sqlFuc.ToList();
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
}