using WcsMain.Common;
using WcsMain.DataBase.TableEntity;
using WcsMain.WcsAttribute.AutoFacAttribute;
namespace WcsMain.DataBase.Dao;
[Component]
public class AppTcpDao
{
///
/// 查询所有socket数据
///
///
public List? Query() => Query(new AppTcp());
///
/// 条件查询
///
///
///
public List? Query(AppTcp socket)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable()
.WhereIF(socket.TcpId != default, w => w.TcpId == socket.TcpId)
.WhereIF(socket.TcpIp != default, w => w.TcpIp == socket.TcpIp)
.WhereIF(socket.TcpPort != default, w => w.TcpPort == socket.TcpPort)
.WhereIF(socket.TcpType != default, w => w.TcpType == socket.TcpType)
.WhereIF(socket.TcpStatus != default, w => w.TcpStatus == socket.TcpStatus)
.WhereIF(socket.DisplayName != default, w => w.DisplayName == socket.DisplayName)
.WhereIF(socket.Remark != default, w => w.Remark == socket.Remark);
return sqlFuc.ToList();
}
catch (Exception ex)
{
_ = ex;
}
return default;
}
///
/// 插入一条记录
///
///
///
public int Insert(AppTcp socket)
{
try
{
int insertRows = CommonTool.DbServe.Insertable(socket).ExecuteCommand();
return insertRows;
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 根据主键更新记录,忽略 null
///
///
///
public int Update(AppTcp socket)
{
try
{
int insertRows = CommonTool.DbServe.Updateable(socket).IgnoreColumns(ignoreAllNullColumns: true)
.ExecuteCommand();
return insertRows;
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 删除一条记录 ---- 根据主键
///
///
///
public int Delete(AppTcp socket)
{
try
{
int insertRows = CommonTool.DbServe.Deleteable(socket).ExecuteCommand();
return insertRows;
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 根据状态查询 socket 数据
///
///
///
public List? GetNeedUseSocket(int status)
{
try
{
List sockets = CommonTool.DbServe.Queryable().Where(w => w.TcpStatus == status).ToList();
return sockets;
}
catch (Exception ex)
{
_ = ex;
}
return default;
}
}