Files
shgx_tz_mes_backend_sync/ZR.Service/mes/wms/WmFgentryInspectService.cs
2024-06-07 11:05:58 +08:00

312 lines
12 KiB
C#

using Infrastructure.Attribute;
using SqlSugar;
using System;
using System.Linq;
using ZR.Model;
using ZR.Model.MES.pro;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using ZR.Repository;
using ZR.Service.mes.wms.IService;
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="workorder"></param>
/// <returns></returns>
public int TransformData(string workorder)
{
int sum = 0;
var inpects = Context.Queryable<WmPackingrecord>()
.Where(it => it.WorkOrderNum == workorder)
.GroupBy(it => it.PackingCode)
.Select(it => new WmFgentryInspect()
{
Workorder = SqlFunc.AggregateMax(it.WorkOrderNum),
Packcode = it.PackingCode,
Machine = SqlFunc.AggregateMax(it.Machine),
ProductionNum = SqlFunc.AggregateCount(it),
Partnumber = SqlFunc.AggregateMax(it.PartNum),
Bfilled = SqlFunc.ToInt32(SqlFunc.AggregateMax(it.BFilled)),
Result = 0,
Bitwm = 0,
CreatedBy = " ",
CreatedTime = DateTime.Now,
}).ToList();
var x = Context.Storageable(inpects)
.WhereColumns(it => new { it.Packcode, it.Workorder })
.ToStorage();
sum = x.AsInsertable.ExecuteCommand();//不存在插入
x.AsUpdateable.ExecuteCommand();//存在更新
return sum;
}
/// <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<WmFgentryInspect_parentDto> GetList_first(WmFgentryInspectQueryDto parm)
{
bool useTime = false;
if (string.IsNullOrEmpty(parm.Workorder) && string.IsNullOrEmpty(parm.Packcode) && string.IsNullOrEmpty(parm.Partnumber))
{
useTime = true;
}
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))
// XXX 调整搜索逻辑,当搜索工单号零件号或标签时,屏蔽时间的判定
.AndIF(useTime && parm.starttime > new DateTime(1999, 1, 1), it => it.CreatedTime > parm.starttime)
.AndIF(useTime && parm.endtime > new DateTime(1999, 1, 1), it => it.CreatedTime < parm.endtime)
;
List<WmFgentryInspect_parentDto> inspects = Queryable()
.Where(predicate.ToExpression())
.Where(it => it.Bitwm == 0)
.GroupBy(it => it.Workorder)
.Select(it => new WmFgentryInspect_parentDto()
{
Workorder = it.Workorder,
ProductionNum = SqlFunc.AggregateSum(it.ProductionNum ?? 0),
Packnum = SqlFunc.AggregateCount(it.Workorder),
Partnumber = SqlFunc.AggregateMax(it.Partnumber),
CreatedTime = SqlFunc.AggregateMax(it.CreatedTime),
})
.LeftJoin<ProWorkorder_v2>((s, w) => s.Workorder == w.ClientWorkorder)
.Select((s, w) => new WmFgentryInspect_parentDto
{
Workorder = s.Workorder,
ProductionNum = s.ProductionNum,
Partnumber = s.Partnumber,
CreatedTime = s.CreatedTime,
Packnum = s.Packnum,
ProductDescription = w.ProductDescription,
Specifications = w.Specifications,
PreviousNumber = w.PreviousNumber,
Colour = w.Colour,
Status = w.Status
})
.ToList();
foreach (var inspect in inspects)
{
inspect.Result_good = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 1).Count();
inspect.Result_bad = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 2).Count();
inspect.Result_null = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 0 || it.Result == null).Count();
// 描述来源调整为物料清单
WmMaterial material = Context.Queryable<WmMaterial>()
.Where(it => it.Partnumber == inspect.Partnumber)
.First();
if (material == null)
{
inspect.ProductDescription = "此零件号不在物料清单内!";
}
else
{
inspect.ProductDescription = !string.IsNullOrEmpty(material.Description) ? material.Description : material.ProductName;
}
}
//int totalPages = (int)Math.Ceiling((double)inspects.Count / parm.PageSize);
var pageProducts = inspects.Skip((parm.PageNum - 1) * parm.PageSize).Take(parm.PageSize).ToList();
PagedInfo<WmFgentryInspect_parentDto> response = new PagedInfo<WmFgentryInspect_parentDto>()
{
PageSize = parm.PageSize,
PageIndex = parm.PageNum,
TotalNum = inspects.Count,
Result = pageProducts
};
return response;
}
/// <summary>
/// 获取二级菜单
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<WmFgentryInspectDto> GetList_second(WmFgentryInspectQueryDto parm)
{
var predicate = Expressionable.Create<WmFgentryInspect>()
.AndIF(!string.IsNullOrEmpty(parm.Workorder), s => s.Workorder.Contains(parm.Workorder))
.AndIF(!string.IsNullOrEmpty(parm.Packcode), s => s.Packcode.Contains(parm.Packcode))
.AndIF(!string.IsNullOrEmpty(parm.Partnumber), s => s.Partnumber.Contains(parm.Partnumber))
.AndIF(parm.starttime != null && parm.starttime > new DateTime(1999, 1, 1), s => s.CreatedTime > parm.starttime)
.AndIF(parm.endtime != null && parm.endtime > new DateTime(1999, 1, 1), s => s.CreatedTime < parm.endtime)
;
var response = Queryable()
.LeftJoin<ProWorkorder_v2>((s, w) => s.Workorder == w.ClientWorkorder)
.Where(s => s.Bitwm == 0)
.Where(predicate.ToExpression())
.Select((s, w) => new WmFgentryInspectDto
{
Workorder = s.Workorder,
ProductionNum = s.ProductionNum,
Packcode = s.Packcode,
Machine = s.Machine,
Bfilled = s.Bfilled,
Partnumber = s.Partnumber,
Result = s.Result,
CreatedBy = s.CreatedBy,
CreatedTime = s.CreatedTime,
ProductDescription = w.ProductDescription,
Specifications = w.Specifications,
Colour = w.Colour
})
.ToPage<WmFgentryInspectDto, WmFgentryInspectDto>(parm);
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);
}
/// <summary>
/// 批量修改合格
/// </summary>
/// <param name="packcode_select"></param>
/// <returns></returns>
public int BatchQualified(string[] packcode_select, string updateby)
{
int sum = 0;
foreach (string packcode in packcode_select)
{
sum = sum + Context.Updateable<WmFgentryInspect>()
.Where(it => it.Packcode == packcode)
.SetColumns(it => it.Result == 1)
.ExecuteCommand();
}
return sum;
}
/// <summary>
/// 设置全部批量合格
/// </summary>
/// <param name="workorder_selected"></param>
/// <param name="updateby"></param>
/// <returns></returns>
public int SetAllQualified(string workorder_selected, string updateby)
{
return Context.Updateable<WmFgentryInspect>()
.SetColumns(it => it.Result == 1)
.Where(it => it.Workorder == workorder_selected)
.ExecuteCommand();
}
/// <summary>
/// 设置全部批量不合格
/// </summary>
/// <param name="workorder_selected"></param>
/// <param name="updateby"></param>
/// <returns></returns>
public int SetAllUnQualified(string workorder_selected, string updateby)
{
return Context.Updateable<WmFgentryInspect>()
.SetColumns(it => it.Result == 2)
.Where(it => it.Workorder == workorder_selected)
.ExecuteCommand();
}
/// <summary>
/// 批量修改合格
/// </summary>
/// <param name="packcode_select"></param>
/// <returns></returns>
public int BatchUnQualified(string[] packcode_select, string updateby)
{
int sum = 0;
foreach (string packcode in packcode_select)
{
sum = sum + Context.Updateable<WmFgentryInspect>()
.Where(it => it.Packcode == packcode)
.SetColumns(it => it.Result == 2)
.ExecuteCommand();
}
return sum;
}
}
}