Files
shgx_tz_mes_backend_sync/ZR.Service/mes/wms/WmFgentryInspectService.cs
qianhao.xu 3debd6569c 提交
2024-04-20 10:45:47 +08:00

251 lines
9.4 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;
using System.Reflection.PortableExecutable;
using Microsoft.AspNetCore.Http.HttpResults;
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 => it.Packcode)
.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)
{
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)
;
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),
// Result= SqlFunc.AggregateSum(it.Result??0),
Partnumber = SqlFunc.AggregateMax(it.Partnumber)
}).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();
}
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,
TotalPage = totalPages,
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), 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(it => it.Bitwm == 0)
.Where(predicate.ToExpression())
.ToPage<WmFgentryInspect, 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="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;
}
}
}