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