using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.DAL
{
///
/// MsSqlDAL RepairRequestFile
///
public partial class ProductInspectionContentItem : CorpTraceDAL_Sorter
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get
{
return ConfigHelper.DefaultConnectionConfig;
}
}
///
///
///
///
///
///
public long Insert(Entity.ProductInspectionContentItem entity,List values)
{
if (entity == null)
return default;
if (entity.CorpID < 1)
return default;
entity.CreateTime = DateTime.Now;
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
var item_id = db.Insertable(entity).ExecuteReturnSnowflakeId();
if (values == null || values.Count == 0)
return item_id;
foreach(var v in values)
{
v.ItemID = item_id;
v.CreateTime = DateTime.Now;
}
if (db.Insertable(values).ExecuteReturnSnowflakeIdList().Count() > 0)
return item_id;
else
return 0;
}
}
///
/// 更新对象属性到数据库中
///
public bool Update(Entity.ProductInspectionContentItem entity, List values)
{
if (entity == null)
return default;
if (values == null)
values = new List();
entity.UpdateTime = DateTime.Now;
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
var values_old = db.Queryable()
.Where(x => x.ItemID == entity.ID).ToList();
db.Updateable(entity).IgnoreColumns(it => new { it.CreateTime, it.CreateUserID, it.CorpID }).ExecuteCommand() ;
foreach(var old in values_old)
{
var fff = values.Find(x => x.ID == old.ID);
if(fff == null)
{//删除
db.Deleteable().Where(x=>x.ID == fff.ID).ExecuteCommand() ;
}
}
foreach(var v in values)
{
if(v.ID == 0)
{
v.CreateTime = DateTime.Now;
db.Insertable(v);
}
else
{
v.UpdateTime = DateTime.Now;
db.Updateable(v).IgnoreColumns(it => new { it.CreateTime, it.CreateUserID, it.ItemID }).ExecuteCommand() ;
}
}
return true;
}
}
///
/// 通过ProductID获取
///
///
///
public List GetByProductID(IEnumerable ProductID)
{
if (ProductID == null || ProductID.Count() == 0)
return null;
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => ProductID.Contains(x.ProductID)).ToList();
}
}
///
/// ProductID
///
///
///
public List GetByGroupID(long GroupID)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.GroupID == GroupID).ToList();
}
}
///
/// ProductID
///
///
///
public List GetByProductID(long ProductID)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.ProductID == ProductID).ToList();
}
}
///
/// 更新使用状态
///
public virtual bool UpdateUseStatus(long CorpID, long ID, int UseStatus, long UpdateUserID, DateTime UpdateTime)
{
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable()
.SetColumns(x => x.UseStatus == UseStatus)
.SetColumns(x => x.UpdateUserID == UpdateUserID)
.SetColumns(x => x.UpdateTime == UpdateTime)
.Where(x => x.CorpID == CorpID && x.ID == ID)
.ExecuteCommandHasChange();
}
}
}
}