using WcsMain.ApiServe.Controllers.Dto.WcsDto.Location;
using WcsMain.Common;
using WcsMain.DataBase.TableEntity;
using WcsMain.Enum;
using WcsMain.Enum.Location;
using WcsMain.WcsAttribute.AutoFacAttribute;
namespace WcsMain.DataBase.Dao;
///
/// tbl_app_location 的库操作
///
[Component]
public class AppLocationDao
{
///
/// 增加一条记录
///
///
///
public int Insert(AppLocation appLocation)
{
try
{
return CommonTool.DbServe.Insertable(appLocation).ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 更新一条记录,根据主键,主键WcsLocation
///
///
///
public int Update(params AppLocation[] appLocation)
{
try
{
var sqlFuc = CommonTool.DbServe.Updateable(appLocation).IgnoreColumns(ignoreAllNullColumns: true);
return sqlFuc.ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 删除一条记录,根据主键,主键WcsLocation
///
///
///
public int Delete(AppLocation appLocation)
{
try
{
var sqlFuc = CommonTool.DbServe.Deleteable(appLocation);
return sqlFuc.ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 查找数据
///
///
///
///
/// 时间不在筛选行列
///
public List? Select(AppLocation appLocation)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(!string.IsNullOrEmpty(appLocation.WcsLocation),
w => w.WcsLocation == appLocation.WcsLocation)
.WhereIF(!string.IsNullOrEmpty(appLocation.WmsLocation),
w => w.WmsLocation == appLocation.WmsLocation)
.WhereIF(appLocation.LocationType != null, w => w.LocationType == appLocation.LocationType)
.WhereIF(appLocation.TunnelNo != null, w => w.TunnelNo == appLocation.TunnelNo)
.WhereIF(appLocation.EquipmentId != null, w => w.EquipmentId == appLocation.EquipmentId)
.WhereIF(appLocation.LocationStatus != null, w => w.LocationStatus == appLocation.LocationStatus)
.WhereIF(appLocation.Queue != null, w => w.Queue == appLocation.Queue)
.WhereIF(appLocation.Line != null, w => w.Line == appLocation.Line)
.WhereIF(appLocation.Layer != null, w => w.Layer == appLocation.Layer)
.WhereIF(appLocation.Depth != null, w => w.Depth == appLocation.Depth)
.WhereIF(appLocation.InterveneLocation != default, w => w.InterveneLocation == appLocation.InterveneLocation)
.WhereIF(appLocation.VehicleType == default, w => w.VehicleType == appLocation.VehicleType)
.WhereIF(!string.IsNullOrEmpty(appLocation.VehicleNo), w => w.VehicleNo == appLocation.VehicleNo)
.OrderBy(o => new { o.Queue, o.Line, o.Layer, o.Depth })
.ToList();
return sqlFuc;
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
///
/// 查找所有数据
///
///
public List? Select() => Select(new AppLocation());
///
/// 查询自起点索引后的多少条数据
///
///
///
public (List? locations, int totalRows) SelectPage(GetLocationWithPageRequest request)
{
try
{
int totalRows = 0;
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(!string.IsNullOrEmpty(request.SearchStr),
w => w.WcsLocation!.Contains(request.SearchStr!)
|| w.WmsLocation!.Contains(request.SearchStr!)
|| w.VehicleNo!.Contains(request.SearchStr!)
|| w.Remark!.Contains(request.SearchStr!));
if (request.LocationStatus != default) // 查询点位状态
{
List locationStatus = [];
request.LocationStatus.ForEach(item => locationStatus.Add(item));
sqlFuc.Where(w => locationStatus.Contains(w.LocationStatus));
}
if (request.LocationType != default) // 查询点位类型
{
List locationTypes = [];
request.LocationType.ForEach(item => locationTypes.Add(item));
sqlFuc.Where(w => locationTypes.Contains(w.LocationType));
}
sqlFuc.OrderBy(o => new { o.EquipmentId, o.Queue, o.Line, o.Layer, o.Depth });
var queryResult = sqlFuc.ToPageList(request.Page!.PageIndex, request.Page!.PageSize, ref totalRows);
return (queryResult, totalRows);
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
///
/// 查询一个堆垛机可用的站台
///
///
///
///
public List? QueryCanUseStand(int? stackerId, StandTypeEnum standType)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(stackerId != null, w => w.EquipmentId == stackerId)
.Where(w => w.LocationType.ToString()!.Contains(standType.ToString()))
.Where(w => w.LocationStatus == (int)LocationStatusEnum.empty)
.OrderBy(o => new { o.Queue, o.Line, o.Layer, o.Depth });
//var ss = sqlFuc.ToSql();
return sqlFuc.ToList();
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
///
/// 查找所有的站台
///
///
public List? SelectStand()
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.Where(w => w.LocationType != (int)StandTypeEnum.storageLocation)
.OrderBy(o => o.WcsLocation)
.ToList();
return sqlFuc;
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
}