216 lines
8.0 KiB
C#
216 lines
8.0 KiB
C#
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using DOAN.Service.huate_group.Recipe.IService;
|
|
using DOAN.Model.huate_group.recipe;
|
|
using DOAN.Model.huate_group.recipe.Dto;
|
|
using DOAN.Repository;
|
|
using Aliyun.OSS;
|
|
using DOAN.Model.Factory_Model;
|
|
using DOAN.Model.Factory_Model.Dto;
|
|
|
|
|
|
namespace DOAN.Service.huate_group.Recipe
|
|
{
|
|
/// <summary>
|
|
/// 配方表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IRecipeService), ServiceLifetime = LifeTime.Transient)]
|
|
public class RecipeService : BaseService<Recipee>, IRecipeService
|
|
{
|
|
/// <summary>
|
|
/// 查询配方表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<RecipeDto> GetList(RecipeQueryDto parm)
|
|
{
|
|
var predicate = QueryExp(parm);
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<Recipee, RecipeDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public Recipee GetInfo(int Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加配方表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public Recipee AddRecipe(Recipee model)
|
|
{
|
|
|
|
// 根据设备id 填充 company workshop line
|
|
BaseDeviceAccount account = Context.Queryable<BaseDeviceAccount>().Where(x => x.Id == model.FkDeviceId).First();
|
|
model.DeviceName = account.DeviceName;
|
|
if (account != null)
|
|
{
|
|
BaseProductionLine line = Context.Queryable<BaseProductionLine>()
|
|
.Where(it => it.Id == account.FkLineId).First();
|
|
if (line != null)
|
|
{
|
|
model.FkLineId = line.Id;
|
|
model.ProductlineName = line.LineName;
|
|
BaseWorkshop baseWorkshop = Context.Queryable<BaseWorkshop>().Where(it => it.Id == line.FkWorkshopId).First();
|
|
if (baseWorkshop != null)
|
|
{
|
|
model.FkWorkshopId = baseWorkshop.Id;
|
|
model.WorkshopName = baseWorkshop.WorkshopName;
|
|
BaseCompany company = Context.Queryable<BaseCompany>().Where(it => it.Id == baseWorkshop.FkCompanyId).First();
|
|
if (company != null)
|
|
{
|
|
model.FkCompanyId = company.Id;
|
|
model.CompanyName = company.CompanyName;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改配方表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateRecipe(Recipee model)
|
|
{
|
|
return Update(model, true);
|
|
}
|
|
|
|
|
|
public List<RecipeLimit> GetRecipebyLimit(int recipe_id)
|
|
{
|
|
return Context.Queryable<RecipeLimit>()
|
|
.Where(it => it.FkRecipeId == recipe_id)
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询导出表达式
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
private static Expressionable<Recipee> QueryExp(RecipeQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<Recipee>()
|
|
.AndIF(parm.FkTanantId > 0, it => it.FkTanantId == parm.FkTanantId)
|
|
.AndIF(parm.FkLineId > 0, it => it.FkLineId == parm.FkLineId)
|
|
.AndIF(parm.FkWorkshopId > 0, it => it.FkWorkshopId == parm.FkWorkshopId)
|
|
.AndIF(parm.FkDeviceId > 0, it => it.FkDeviceId == parm.FkDeviceId)
|
|
//.AndIF(parm != null && !string.IsNullOrEmpty(parm.Workshop), it => it.WorkshopName.Contains(parm.Workshop))
|
|
//.AndIF(parm != null && !string.IsNullOrEmpty(parm.Workstation), it => it.DeviceName.Contains(parm.Workstation))
|
|
//.AndIF(parm != null && !string.IsNullOrEmpty(parm.Vehiclemodel), it => it.Vehiclemodel.Contains(parm.Vehiclemodel))
|
|
//.AndIF(parm != null && !string.IsNullOrEmpty(parm.Partnumber), it => it.Partnumber.Contains(parm.Partnumber))
|
|
//.AndIF(parm != null && !string.IsNullOrEmpty(parm.Paramter), it => it.Paramter.Contains(parm.Paramter))
|
|
;
|
|
|
|
return predicate;
|
|
}
|
|
|
|
public List<BaseCompany> GetAllCompany()
|
|
{
|
|
return Context.Queryable<BaseCompany>().ToList();
|
|
}
|
|
|
|
public List<BaseWorkshop> GetWorkShopByCompany(int company_id)
|
|
{
|
|
return Context.Queryable<BaseWorkshop>().Where(it => it.FkCompanyId == company_id).ToList();
|
|
}
|
|
|
|
public List<ProductLineChildrenDevice> GetLineChildenDevice(int workshop_id)
|
|
{
|
|
List<ProductLineChildrenDevice> productLineChildrenDevices = new List<ProductLineChildrenDevice>();
|
|
//获取车间下所有产线
|
|
|
|
List<BaseProductionLine> lines = Context.Queryable<BaseProductionLine>().Where(it => it.FkWorkshopId == workshop_id).ToList();
|
|
if (lines != null && lines.Count() > 0)
|
|
{
|
|
foreach (BaseProductionLine line in lines)
|
|
{
|
|
|
|
ProductLineChildrenDevice LineItem = new ProductLineChildrenDevice();
|
|
|
|
LineItem.Id = line.Id;
|
|
LineItem.FkWorkshopId = line.FkWorkshopId;
|
|
LineItem.LineCode = line.LineCode;
|
|
LineItem.LineName = line.LineName;
|
|
LineItem.Status = line.Status;
|
|
|
|
|
|
// 获取产线所有设备
|
|
List<BaseDeviceAccount> accounts = Context.Queryable<BaseDeviceAccount>().Where(it => it.FkLineId == line.Id).ToList();
|
|
if (accounts != null && accounts.Count() > 0)
|
|
{
|
|
|
|
List<DevicecCombination> DevicecCombinationList = new List<DevicecCombination>();
|
|
// 获取每台设备的配方
|
|
foreach (BaseDeviceAccount device in accounts)
|
|
{
|
|
Recipee recipee = Context.Queryable<Recipee>()
|
|
.Where(it => it.FkDeviceId == device.Id)
|
|
.Where(it => it.IsSelected == true).First();
|
|
if (recipee != null)
|
|
{
|
|
DevicecCombination devicecCombination = new DevicecCombination();
|
|
devicecCombination._recipee = recipee;
|
|
devicecCombination._account = device;
|
|
DevicecCombinationList.Add(devicecCombination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LineItem.Children = DevicecCombinationList.ToArray();
|
|
}
|
|
productLineChildrenDevices.Add(LineItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
return productLineChildrenDevices;
|
|
}
|
|
|
|
public int SelectedRecipe(int recipe_id)
|
|
{
|
|
int result = 0;
|
|
UseTran2(() =>
|
|
{
|
|
Recipee recipee = Context.Queryable<Recipee>().Where(it => it.Id == recipe_id).First();
|
|
if (recipee != null)
|
|
{
|
|
Context.Updateable<Recipee>().Where(it => it.FkDeviceId == recipee.FkDeviceId).SetColumns(it => it.IsSelected == false).ExecuteCommand();
|
|
result = Context.Updateable<Recipee>().Where(it => it.Id == recipee.Id).SetColumns(it => it.IsSelected == true).ExecuteCommand();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |