137 lines
4.5 KiB
C#
137 lines
4.5 KiB
C#
using DOAN.Model;
|
|
using DOAN.Model.MES.recipe;
|
|
using DOAN.Model.MES.recipe.Dto;
|
|
using DOAN.Repository;
|
|
using DOAN.Service.MES.recipe.IService;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Model;
|
|
|
|
namespace DOAN.Service.MES.recipe
|
|
{
|
|
/// <summary>
|
|
/// 配方下达记录表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IPfRecipeIssueLogService), ServiceLifetime = LifeTime.Transient)]
|
|
public class PfRecipeIssueLogService : BaseService<PfRecipeIssueLog>, IPfRecipeIssueLogService
|
|
{
|
|
private readonly PfRecipeParametersService pfRecipeParametersService = new PfRecipeParametersService();
|
|
/// <summary>
|
|
/// 查询配方下达记录表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<PfRecipeIssueLogDto> GetList(PfRecipeIssueLogQueryDto parm)
|
|
{
|
|
var predicate = QueryExp(parm);
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<PfRecipeIssueLog, PfRecipeIssueLogDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public PfRecipeIssueLog GetInfo(int Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加配方下达记录表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public PfRecipeIssueLog AddPfRecipeIssueLog(PfRecipeIssueLog model)
|
|
{
|
|
return Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改配方下达记录表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdatePfRecipeIssueLog(PfRecipeIssueLog model)
|
|
{
|
|
return Update(model, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询导出表达式
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
private static Expressionable<PfRecipeIssueLog> QueryExp(PfRecipeIssueLogQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<PfRecipeIssueLog>();
|
|
if (parm != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(parm.RecipeCode))
|
|
{
|
|
predicate = predicate.And(it => it.RecipeCode == parm.RecipeCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(parm.Version))
|
|
{
|
|
predicate = predicate.And(it => it.Version == parm.Version);
|
|
}
|
|
if (parm.StartTime != null)
|
|
{
|
|
predicate = predicate.And(it => it.IssueTime >= parm.StartTime);
|
|
}
|
|
if (parm.EndTime != null)
|
|
{
|
|
predicate = predicate.And(it => it.IssueTime <= parm.EndTime);
|
|
}
|
|
}
|
|
return predicate;
|
|
}
|
|
|
|
public ApiResult IssueRecipe(PfRecipeIssueLog model)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(model.RecipeCode) || string.IsNullOrEmpty(model.Version))
|
|
{
|
|
return new ApiResult(210, "参数不可为空", -1);
|
|
}
|
|
var parmeterlist = pfRecipeParametersService.Queryable()
|
|
.Where(x => x.RecipeCode == model.RecipeCode && x.Version == model.Version).ToList();
|
|
if (!parmeterlist.Any())
|
|
{
|
|
return new ApiResult(210, "该配方未配置参数", -1);
|
|
}
|
|
bool bResult = sendRecipeByMqtt(parmeterlist);
|
|
if (!bResult)
|
|
{
|
|
return new ApiResult(210, "发送配方失败", -1);
|
|
}
|
|
else
|
|
{
|
|
int iResult = Insertable(model).ExecuteReturnIdentity();
|
|
return new ApiResult(200, "操作成功");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ApiResult(210,ex.ToString());
|
|
}
|
|
}
|
|
|
|
private bool sendRecipeByMqtt(List<PfRecipeParameters> parmeterlist)
|
|
{
|
|
//实现MQTT发送配方到上位机
|
|
return true;
|
|
}
|
|
}
|
|
} |