using System.Threading.Tasks;
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 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;
}
}
}