205 lines
7.0 KiB
C#
205 lines
7.0 KiB
C#
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;
|
||
|
||
/// <summary>
|
||
/// tbl_app_location 的库操作
|
||
/// </summary>
|
||
[Component]
|
||
public class AppLocationDao
|
||
{
|
||
|
||
/// <summary>
|
||
/// 增加一条记录
|
||
/// </summary>
|
||
/// <param name="appLocation"></param>
|
||
/// <returns></returns>
|
||
public int Insert(AppLocation appLocation)
|
||
{
|
||
try
|
||
{
|
||
return CommonTool.DbServe.Insertable(appLocation).ExecuteCommand();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_ = ex;
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 更新一条记录,根据主键,主键WcsLocation
|
||
/// </summary>
|
||
/// <param name="appLocation"></param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 删除一条记录,根据主键,主键WcsLocation
|
||
/// </summary>
|
||
/// <param name="appLocation"></param>
|
||
/// <returns></returns>
|
||
public int Delete(AppLocation appLocation)
|
||
{
|
||
try
|
||
{
|
||
var sqlFuc = CommonTool.DbServe.Deleteable(appLocation);
|
||
return sqlFuc.ExecuteCommand();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_ = ex;
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查找数据
|
||
/// </summary>
|
||
/// <param name="appLocation"></param>
|
||
/// <returns></returns>
|
||
/// <remarks>
|
||
/// 时间不在筛选行列
|
||
/// </remarks>
|
||
public List<AppLocation>? Select(AppLocation appLocation)
|
||
{
|
||
try
|
||
{
|
||
var sqlFuc = CommonTool.DbServe.Queryable<AppLocation>()
|
||
.WhereIF(appLocation.WcsLocation != default, w => w.WcsLocation == appLocation.WcsLocation)
|
||
.WhereIF(appLocation.WmsLocation != default, 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(appLocation.VehicleNo != default, 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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查找所有数据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<AppLocation>? Select() => Select(new AppLocation());
|
||
|
||
|
||
/// <summary>
|
||
/// 查询自起点索引后的多少条数据
|
||
/// </summary>
|
||
/// <param name="request"></param>
|
||
/// <returns></returns>
|
||
public (List<AppLocation>? locations, int totalRows) SelectPage(GetLocationWithPageRequest request)
|
||
{
|
||
try
|
||
{
|
||
int totalRows = 0;
|
||
var sqlFuc = CommonTool.DbServe.Queryable<AppLocation>()
|
||
.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<int?> locationStatus = [];
|
||
request.LocationStatus.ForEach(item => locationStatus.Add(item));
|
||
sqlFuc.Where(w => locationStatus.Contains(w.LocationStatus));
|
||
}
|
||
if (request.LocationType != default) // 查询点位类型
|
||
{
|
||
List<int?> 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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询一个堆垛机可用的站台
|
||
/// </summary>
|
||
/// <param name="stackerId"></param>
|
||
/// <param name="standType"></param>
|
||
/// <returns></returns>
|
||
public List<AppLocation>? QueryCanUseStand(int? stackerId, StandTypeEnum standType)
|
||
{
|
||
try
|
||
{
|
||
var sqlFuc = CommonTool.DbServe.Queryable<AppLocation>()
|
||
.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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查找所有的站台
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<AppLocation>? SelectStand()
|
||
{
|
||
try
|
||
{
|
||
var sqlFuc = CommonTool.DbServe.Queryable<AppLocation>()
|
||
.Where(w => w.LocationType != (int)StandTypeEnum.storageLocation)
|
||
.OrderBy(o => o.WcsLocation)
|
||
.ToList();
|
||
return sqlFuc;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_ = ex;
|
||
return default;
|
||
}
|
||
}
|
||
|
||
} |