143 lines
5.3 KiB
C#
143 lines
5.3 KiB
C#
|
|
using System.Linq;
|
||
|
|
using Infrastructure.Attribute;
|
||
|
|
using SqlSugar;
|
||
|
|
using ZR.Model;
|
||
|
|
using ZR.Model.MES.mm;
|
||
|
|
using ZR.Model.MES.mm.Dto;
|
||
|
|
using ZR.Model.MES.wms;
|
||
|
|
using ZR.Repository;
|
||
|
|
using ZR.Service.mes.mm.IService;
|
||
|
|
using ZR.Service.mes.wms;
|
||
|
|
|
||
|
|
namespace ZR.Service.mes.mm
|
||
|
|
{
|
||
|
|
[AppService(
|
||
|
|
ServiceType = typeof(IMmInventoryReportService),
|
||
|
|
ServiceLifetime = LifeTime.Transient
|
||
|
|
)]
|
||
|
|
public class MmInventoryReportService : BaseService<WmGoodsRecord>, IMmInventoryReportService
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 按时间、物料号、物料名称、操作人获取分页数据
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="query">查询参数</param>
|
||
|
|
/// <param name="pagerInfo">分页信息</param>
|
||
|
|
/// <returns>分页结果</returns>
|
||
|
|
public PagedInfo<WmGoodsRecordReport> GetInventoryReportByPage(
|
||
|
|
WmGoodsRecordReportQueryDto query
|
||
|
|
)
|
||
|
|
{
|
||
|
|
// 添加查询条件
|
||
|
|
var predicate = Expressionable
|
||
|
|
.Create<WmGoodsRecord, WmMaterial>()
|
||
|
|
.AndIF(query.StartTime.HasValue, (gr, m) => gr.ActionTime >= query.StartTime)
|
||
|
|
.AndIF(query.EndTime.HasValue, (gr, m) => gr.ActionTime <= query.EndTime)
|
||
|
|
.AndIF(
|
||
|
|
!string.IsNullOrEmpty(query.PartNumber),
|
||
|
|
(gr, m) => gr.Partnumber.Contains(query.PartNumber)
|
||
|
|
)
|
||
|
|
.AndIF(
|
||
|
|
!string.IsNullOrEmpty(query.Source),
|
||
|
|
(gr, m) => gr.Code.Contains(query.Source)
|
||
|
|
)
|
||
|
|
.AndIF(
|
||
|
|
!string.IsNullOrEmpty(query.MaterialName),
|
||
|
|
(gr, m) => m.Description.Contains(query.MaterialName)
|
||
|
|
)
|
||
|
|
.AndIF(
|
||
|
|
!string.IsNullOrEmpty(query.Operator),
|
||
|
|
(gr, m) => gr.CreatedBy.Contains(query.Operator)
|
||
|
|
)
|
||
|
|
.And((gr, m) => gr.ChangeType == 1); // 入库记录
|
||
|
|
|
||
|
|
// 按零件号分组并计算ChangeQuantity合计
|
||
|
|
var result = Context
|
||
|
|
.Queryable<WmGoodsRecord, WmMaterial>(
|
||
|
|
(gr, m) => new JoinQueryInfos(JoinType.Left, gr.Partnumber == m.Partnumber)
|
||
|
|
)
|
||
|
|
.Where(predicate.ToExpression())
|
||
|
|
.GroupBy(
|
||
|
|
(gr, m) =>
|
||
|
|
new
|
||
|
|
{
|
||
|
|
gr.Partnumber,
|
||
|
|
m.ProductName,
|
||
|
|
m.Color,
|
||
|
|
m.Specification,
|
||
|
|
m.Description,
|
||
|
|
m.Unit,
|
||
|
|
gr.CreatedBy
|
||
|
|
}
|
||
|
|
)
|
||
|
|
.Select(
|
||
|
|
(gr, m) =>
|
||
|
|
new WmGoodsRecordReport
|
||
|
|
{
|
||
|
|
Code = gr.Code,
|
||
|
|
Partnumber = gr.Partnumber,
|
||
|
|
ProductName = m.ProductName,
|
||
|
|
Color = m.Color,
|
||
|
|
Specification = m.Specification,
|
||
|
|
Description = m.Description,
|
||
|
|
Unit = m.Unit,
|
||
|
|
ChangePackage = SqlFunc.AggregateSum(gr.ChangePackage),
|
||
|
|
ChangeQuantity = SqlFunc.AggregateSum(gr.ChangeQuantity),
|
||
|
|
CreatedBy = gr.CreatedBy,
|
||
|
|
}
|
||
|
|
)
|
||
|
|
.ToPage(query);
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据ID获取详细数据清单
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="id">记录ID</param>
|
||
|
|
/// <returns>详细数据</returns>
|
||
|
|
public WmGoodsRecordReport GetInventoryReportDetail(string id)
|
||
|
|
{
|
||
|
|
// 获取原始记录
|
||
|
|
var record = this.GetId(id);
|
||
|
|
if (record == null)
|
||
|
|
return null;
|
||
|
|
|
||
|
|
// 创建报表模型实例
|
||
|
|
var report = new WmGoodsRecordReport
|
||
|
|
{
|
||
|
|
Id = record.Id,
|
||
|
|
FkInventoryId = record.FkInventoryId,
|
||
|
|
Code = record.Code,
|
||
|
|
Partnumber = record.Partnumber,
|
||
|
|
BlankNum = record.BlankNum,
|
||
|
|
ChangeType = record.ChangeType,
|
||
|
|
ChangeQuantity = record.ChangeQuantity,
|
||
|
|
ActionTime = record.ActionTime,
|
||
|
|
Status = record.Status,
|
||
|
|
Remark = record.Remark,
|
||
|
|
CreatedBy = record.CreatedBy,
|
||
|
|
CreatedTime = record.CreatedTime,
|
||
|
|
UpdatedBy = record.UpdatedBy,
|
||
|
|
UpdatedTime = record.UpdatedTime
|
||
|
|
};
|
||
|
|
|
||
|
|
// 如果有零件号,尝试获取物料信息
|
||
|
|
if (!string.IsNullOrEmpty(record.Partnumber))
|
||
|
|
{
|
||
|
|
var materialService = new WmMaterialService();
|
||
|
|
var material = materialService.GetFirst(it => it.Partnumber == record.Partnumber);
|
||
|
|
if (material != null)
|
||
|
|
{
|
||
|
|
report.ProductName = material.ProductName;
|
||
|
|
report.Color = material.Color;
|
||
|
|
report.Specification = material.Specification;
|
||
|
|
report.Description = material.Description;
|
||
|
|
report.Unit = material.Unit;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return report;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|