zhuangpei-mesbackend/DOAN.Service/MES/recipe/PfRecipeVersionService.cs
2025-12-05 17:31:24 +08:00

103 lines
3.4 KiB
C#

using Infrastructure.Attribute;
using Infrastructure.Extensions;
using DOAN.Model;
using DOAN.Model.MES.recipe;
using DOAN.Model.MES.recipe.Dto;
using DOAN.Repository;
using DOAN.Service.MES.recipe.IService;
namespace DOAN.Service.MES.recipe
{
/// <summary>
/// 配方版本控制表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IPfRecipeVersionService), ServiceLifetime = LifeTime.Transient)]
public class PfRecipeVersionService : BaseService<PfRecipeVersion>, IPfRecipeVersionService
{
private readonly PfRefProductRecipeService pfRefProductRecipeService = new PfRefProductRecipeService();
private readonly PfRecipeParametersService pfRecipeParametersService = new PfRecipeParametersService();
/// <summary>
/// 查询配方版本控制表列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<PfRecipeVersionDto> GetList(PfRecipeVersionQueryDto parm)
{
var predicate = QueryExp(parm);
var query = Context.Queryable<PfRecipeVersion, PfRefProductRecipe>((t, p) => new object[] {
JoinType.Inner, t.RecipeCode == p.RecipeCode })
.Where(predicate.ToExpression())
.Select((t, p) => new PfRecipeVersionDto
{
RecipeCode = t.RecipeCode,
Version = t.Version,
Status = t.Status,
ProductCode = p.Productcode,
ProductName = p.ProductName
});
var response = query.ToPage<PfRecipeVersionDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public PfRecipeVersion GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加配方版本控制表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PfRecipeVersion AddPfRecipeVersion(PfRecipeVersion model)
{
return Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改配方版本控制表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdatePfRecipeVersion(PfRecipeVersion model)
{
return Update(model, true);
}
/// <summary>
/// 查询导出表达式
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
private static Expressionable<PfRecipeVersion> QueryExp(PfRecipeVersionQueryDto parm)
{
var predicate = Expressionable.Create<PfRecipeVersion>();
if (parm != null)
{
if (!string.IsNullOrEmpty(parm.RecipeCode))
{
predicate.And(x => x.RecipeCode == parm.RecipeCode);
}
if (!string.IsNullOrEmpty(parm.Version))
{
predicate.And(x => x.Version == parm.Version);
}
if (!string.IsNullOrEmpty(parm.Status))
{
predicate.And(x => x.Status == parm.Status);
}
}
return predicate;
}
}
}