146 lines
3.8 KiB
C#
146 lines
3.8 KiB
C#
|
|
using WcsMain.ApiServe.Controllers.Dto.WcsDto.DB;
|
|||
|
|
using WcsMain.Common;
|
|||
|
|
using WcsMain.DataBase.TableEntity;
|
|||
|
|
using WcsMain.WcsAttribute.AutoFacAttribute;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace WcsMain.DataBase.Dao;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// tbl_app_db 表的增删改查
|
|||
|
|
/// </summary>
|
|||
|
|
[Component]
|
|||
|
|
public class AppDBDao
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 插入数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="appDB"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Insert(AppDB appDB)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
int insertResult = CommonTool.DbServe.Insertable(appDB).ExecuteCommand();
|
|||
|
|
return insertResult;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_ = ex;
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 更新数据,以主键为条件,主键 : DBName
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="appDB"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Update(AppDB appDB)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var sqlFuc = CommonTool.DbServe.Updateable(appDB).IgnoreColumns(ignoreAllNullColumns: true);
|
|||
|
|
return sqlFuc.ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_ = ex;
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除数据,以主键为条件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="appDB"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Delete(AppDB appDB)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var sqlFuc = CommonTool.DbServe.Deleteable(appDB);
|
|||
|
|
return sqlFuc.ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_ = ex;
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查找数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="appDB"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public List<AppDB>? Select(AppDB appDB)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var sqlFuc = CommonTool.DbServe.Queryable<AppDB>();
|
|||
|
|
if (appDB.DBName != null)
|
|||
|
|
{
|
|||
|
|
sqlFuc = sqlFuc.Where(w => w.DBName == appDB.DBName);
|
|||
|
|
}
|
|||
|
|
if (appDB.DBAddress != null)
|
|||
|
|
{
|
|||
|
|
sqlFuc = sqlFuc.Where(w => w.DBAddress == appDB.DBAddress);
|
|||
|
|
}
|
|||
|
|
if (appDB.IsSystem != null)
|
|||
|
|
{
|
|||
|
|
sqlFuc = sqlFuc.Where(w => w.IsSystem == appDB.IsSystem);
|
|||
|
|
}
|
|||
|
|
if (appDB.Remark != null)
|
|||
|
|
{
|
|||
|
|
sqlFuc = sqlFuc.Where(w => w.Remark == appDB.Remark);
|
|||
|
|
}
|
|||
|
|
return sqlFuc.OrderBy(o => new { o.PlcId, o.DBName }).ToList();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_ = ex;
|
|||
|
|
return default;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查找所有数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public List<AppDB>? Select() => Select(new AppDB());
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查询所有DB地址,同时返回PLC名称
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="appDB"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public List<GetDBWithPlcNameResponse>? QueryWithPlcName(AppDB appDB)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var sqlFuc = CommonTool.DbServe.Queryable<AppDB>()
|
|||
|
|
.LeftJoin<AppPLC>((db, plc) => db.PlcId == plc.PLCId)
|
|||
|
|
.WhereIF(!string.IsNullOrEmpty(appDB.DBName), db => db.DBName!.Contains(appDB.DBName!))
|
|||
|
|
.WhereIF(appDB.PlcId != default, db => db.PlcId == appDB.PlcId)
|
|||
|
|
.OrderBy(db => new { db.PlcId, db.DBName })
|
|||
|
|
.Select((db, plc) => new GetDBWithPlcNameResponse
|
|||
|
|
{
|
|||
|
|
PlcId = db.PlcId,
|
|||
|
|
PlcName = plc.PLCName,
|
|||
|
|
DBName = db.DBName,
|
|||
|
|
DBAddress = db.DBAddress,
|
|||
|
|
IsSystem = db.IsSystem,
|
|||
|
|
Remark = db.Remark,
|
|||
|
|
});
|
|||
|
|
return sqlFuc.ToList();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_ = ex;
|
|||
|
|
return default;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|