Files
shgx_tz_mes_backend_sync/ZR.Service/mes/wms/WmFgentryInspectService.cs
qianhao.xu c918e0734b 提交
2024-04-18 09:18:22 +08:00

129 lines
4.7 KiB
C#

using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Repository;
using System.Linq;
using ZR.Service.mes.wms.IService;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using Mapster;
namespace ZR.Service.mes.wms
{
/// <summary>
/// 成品入库检验Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IWmFgentryInspectService), ServiceLifetime = LifeTime.Transient)]
public class WmFgentryInspectService : BaseService<WmFgentryInspect>, IWmFgentryInspectService
{
/// <summary>
/// 查询成品入库检验列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<WmFgentryInspectDto> GetList(WmFgentryInspectQueryDto parm)
{
var predicate = Expressionable.Create<WmFgentryInspect>();
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage<WmFgentryInspect, WmFgentryInspectDto>(parm);
return response;
}
/// <summary>
/// 查询成品入库检验列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<WmFgentryInspectDto> GetList_first(WmFgentryInspectQueryDto parm)
{
var predicate = Expressionable.Create<WmFgentryInspect>()
.AndIF(!string.IsNullOrEmpty(parm.Workorder), it => it.Workorder.Contains(parm.Workorder))
.AndIF(!string.IsNullOrEmpty(parm.Packcode), it => it.Packcode.Contains(parm.Packcode))
.AndIF(!string.IsNullOrEmpty(parm.Partnumber), it => it.Partnumber.Contains(parm.Partnumber))
.AndIF(parm.starttime!=null&&parm.starttime>new DateTime(1999,1,1), it => it.CreatedTime>parm.starttime)
.AndIF(parm.endtime!=null&&parm.endtime>new DateTime(1999,1,1), it => it.CreatedTime<parm.endtime)
;
//var response = Queryable()
// .Where(predicate.ToExpression())
// .ToPage<WmFgentryInspect, WmFgentryInspectDto>(parm);
List<WmFgentryInspect> inspects = Queryable()
.Where(predicate.ToExpression()).GroupBy(it => it.Workorder)
.Select(it => new WmFgentryInspect()
{
Workorder = it.Workorder,
ProductionNum = SqlFunc.AggregateSum(it.ProductionNum ?? 0),
Partnumber = SqlFunc.AggregateMax(it.Partnumber)
}).ToList();
int totalPages = (int)Math.Ceiling((double)inspects.Count / parm.PageSize);
var pageProducts = inspects.Skip((parm.PageNum - 1) * parm.PageSize).Take(parm.PageSize);
PagedInfo<WmFgentryInspectDto> response = new PagedInfo<WmFgentryInspectDto>()
{
PageSize = parm.PageSize,
PageIndex = parm.PageNum,
TotalPage = totalPages,
Result= pageProducts.Adapt<List<WmFgentryInspectDto>>()
};
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public WmFgentryInspect GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加成品入库检验
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public WmFgentryInspect AddWmFgentryInspect(WmFgentryInspect model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改成品入库检验
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateWmFgentryInspect(WmFgentryInspect model)
{
//var response = Update(w => w.Id == model.Id, it => new WmFgentryInspect()
//{
// Workorder = model.Workorder,
// Machine = model.Machine,
// ProductionNum = model.ProductionNum,
// Partnumber = model.Partnumber,
// Bfilled = model.Bfilled,
// Result = model.Result,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}