using SqlSugar;
|
using System.Collections.Generic;
|
using System.Linq;
|
using TProduct.HttpClient;
|
|
namespace TProduct.DAL
|
{
|
/// <summary>
|
/// 测试记录
|
/// </summary>
|
public class ValveFeatTestRecord
|
{
|
#region Insert
|
|
/// <summary>
|
/// 插入指定对象到数据库中
|
/// </summary>
|
public long Insert(int Year, Entity.ValveFeatTestRecord entity)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
var id = db.Insertable(entity).ExecuteReturnSnowflakeId();
|
if (id > 0 && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
var dto = db.Queryable<Entity.ValveFeatTestRecord>().Single(x => x.ID == id);
|
HttpClientHelper.Build("ValveFeatTestRecord", "Insert@V1.0").Post<bool>(dto);
|
}
|
return id;
|
}
|
}
|
|
/// <summary>
|
/// 插入指定对象集合到数据库中
|
/// </summary>
|
public bool Inserts(int Year, List<Entity.ValveFeatTestRecord> list)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
try
|
{
|
db.Ado.BeginTran();
|
var snowflakeIds = db.Insertable(list).ExecuteReturnSnowflakeIdList();
|
if (snowflakeIds.Count < list.Count)
|
{
|
db.Ado.RollbackTran();
|
return default;
|
}
|
if (snowflakeIds == null || snowflakeIds.Count < 1)
|
{
|
db.Ado.RollbackTran();
|
return default;
|
}
|
db.Ado.CommitTran();
|
|
if (TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
var dtos = db.Queryable<Entity.ValveFeatTestRecord>().Where(x => snowflakeIds.Contains(x.ID));
|
HttpClientHelper.Build("ValveFeatTestRecord", "Inserts@V1.0").Post<bool>(dtos);
|
}
|
return true;
|
}
|
catch
|
{
|
db.Ado.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 插入并返回
|
/// </summary>
|
public List<long> InsertsR(int Year, List<Entity.ValveFeatTestRecord> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
try
|
{
|
db.Ado.BeginTran();
|
var snowflakeIds = db.Insertable(list).ExecuteReturnSnowflakeIdList();
|
if (snowflakeIds.Count < list.Count)
|
{
|
db.Ado.RollbackTran();
|
return default;
|
}
|
if (snowflakeIds == null || snowflakeIds.Count < 1)
|
{
|
db.Ado.RollbackTran();
|
return default;
|
}
|
db.Ado.CommitTran();
|
|
if (TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
var dtos = db.Queryable<Entity.ValveFeatTestRecord>().Where(x => snowflakeIds.Contains(x.ID));
|
HttpClientHelper.Build("ValveFeatTestRecord", "Inserts@V1.0").Post<bool>(dtos);
|
}
|
return snowflakeIds;
|
}
|
catch
|
{
|
db.Ado.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新对象属性到数据库中
|
/// </summary>
|
public bool Update(int Year, Entity.ValveFeatTestRecord entity)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
var result = db.Updateable(entity).ExecuteCommand() > 0;
|
if (result && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
HttpClientHelper.Build("ValveFeatTestRecord", "Update@V1.0").Put<bool>(entity);
|
}
|
return result;
|
}
|
}
|
|
/// <summary>
|
/// 更新部分
|
/// </summary>
|
public bool UpdatePart(int Year, Entity.ValveFeatTestRecord entity, List<string> pros)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
var result = db.Updateable(entity).UpdateColumns(pros.ToArray()).ExecuteCommand() > 0;
|
if (result && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
HttpClientHelper.Build("ValveFeatTestRecord", "Update@V1.0").Put<bool>(entity);
|
}
|
return result;
|
}
|
}
|
|
/// <summary>
|
/// 更新指定对象集合到数据库中
|
/// </summary>
|
public bool Updates(int Year, List<Entity.ValveFeatTestRecord> list)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
try
|
{
|
db.Ado.BeginTran();
|
var result = db.Updateable(list).ExecuteCommand() > 0;
|
db.Ado.CommitTran();
|
|
if (result && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
HttpClientHelper.Build("ValveFeatTestRecord", "Updates@V1.0").Put<bool>(list);
|
}
|
return result;
|
}
|
catch
|
{
|
db.Ado.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 批量更新部分
|
/// </summary>
|
public bool UpdatesPart(int Year, List<Entity.ValveFeatTestRecord> list, List<string> pros)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
try
|
{
|
db.Ado.BeginTran();
|
var result = db.Updateable(list).UpdateColumns(pros.ToArray()).ExecuteCommand() > 0;
|
db.Ado.CommitTran();
|
|
if (result && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
HttpClientHelper.Build("ValveFeatTestRecord", "Updates@V1.0").Put<bool>(list);
|
}
|
return result;
|
}
|
catch
|
{
|
db.Ado.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 从数据库中删除指定对象
|
/// </summary>
|
public bool ClearAllRecord(int Year, long ItemID)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
var delList = db.Queryable<Entity.ValveFeatTestRecord>().Where(it => it.TestItemID == ItemID).ToList();
|
if (delList != null && delList.Count > 0)
|
{
|
var result = db.Deleteable<Entity.ValveFeatTestRecord>(delList).ExecuteCommand();
|
if (result > 0 && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
var ids = delList.Select(x => x.ID);
|
var input = LongListHelper.ToString(ids);
|
HttpClientHelper.Build("ValveFeatTestRecord", $"DeleteByIds@V1.0?Ids={input}").Delete<bool>();
|
}
|
}
|
|
return true;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 根据指定对象的ID,从数据库中删除指定对象
|
/// </summary>
|
public bool DeleteByID(int Year, long ID)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
var delList = db.Queryable<Entity.ValveFeatTestRecord>().Where(it => it.ID == ID).ToList();
|
if (delList != null && delList.Count > 0)
|
{
|
var result = db.Deleteable<Entity.ValveFeatTestRecord>(delList).ExecuteCommand();
|
if (result > 0 && TProduct.CorpConfig.Instance.RealTimeRemoteService.IsSynMainData)
|
{
|
var ids = delList.Select(x => x.ID);
|
var input = LongListHelper.ToString(ids);
|
HttpClientHelper.Build("ValveFeatTestRecord", $"DeleteByIds@V1.0?Ids={input}").Delete<bool>();
|
}
|
}
|
return true;
|
}
|
}
|
|
|
#endregion
|
|
#region Query
|
|
|
/// <summary>
|
/// 查询数据库,返回指定ID的对象
|
/// </summary>
|
public List<Entity.ValveFeatTestRecord> GetByTestItemID(int Year, long TestItemID)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
return db.Queryable<Entity.ValveFeatTestRecord>().Where(x => x.TestItemID == TestItemID)?.ToList();
|
}
|
}
|
|
|
/// <summary>
|
/// 查询数据库,返回指定ID的对象
|
/// </summary>
|
public List<Entity.ValveFeatTestRecord> GetAllByYear(int Year)
|
{
|
using (ISqlSugarClient db = TProduct.DAL.SQLite.ConfigHelper.RecordConn(Year))
|
{
|
return db.Queryable<Entity.ValveFeatTestRecord>()?.ToList();
|
}
|
}
|
|
#endregion
|
|
|
|
|
}
|
}
|