295 lines
12 KiB
C#
295 lines
12 KiB
C#
using System;
|
|
using Infrastructure.Attribute;
|
|
using SqlSugar;
|
|
using ZR.Model;
|
|
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(IWmPolishQualityStatisticsService),
|
|
ServiceLifetime = LifeTime.Transient
|
|
)]
|
|
public class WmPolishQualityStatisticsService
|
|
: BaseService<WmPolishQualityStatistics>,
|
|
IWmPolishQualityStatisticsService
|
|
{
|
|
/// <summary>
|
|
/// 查询抛光管理-质量统计列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<WmPolishQualityStatisticsDto> GetList(
|
|
WmPolishQualityStatisticsQueryDto parm
|
|
)
|
|
{
|
|
var predicate = Expressionable
|
|
.Create<WmPolishQualityStatistics>()
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.WorkorderId),
|
|
it => it.WorkorderId.Contains(parm.WorkorderId)
|
|
)
|
|
.AndIF(!string.IsNullOrEmpty(parm.Team), it => it.Team.Contains(parm.Team))
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.Partnumber),
|
|
it => it.Partnumber.Contains(parm.Partnumber)
|
|
)
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.CreatedBy),
|
|
it => it.CreatedBy.Contains(parm.CreatedBy)
|
|
)
|
|
.AndIF(
|
|
parm.StartTime != null,
|
|
it => it.StartTime >= parm.StartTime.Value.ToLocalTime()
|
|
)
|
|
.AndIF(
|
|
parm.EndTime != null,
|
|
it => it.StartTime <= parm.EndTime.Value.ToLocalTime()
|
|
);
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<WmPolishQualityStatistics, WmPolishQualityStatisticsDto>(parm);
|
|
if (response.Result.Count > 0)
|
|
{
|
|
foreach (WmPolishQualityStatisticsDto item in response.Result)
|
|
{
|
|
WmMaterial material = Context
|
|
.Queryable<WmMaterial>()
|
|
.Where(it => it.Partnumber == item.Partnumber)
|
|
.Where(it => it.Type == 1)
|
|
.Where(it => it.Status == 1)
|
|
.First();
|
|
if (material == null)
|
|
{
|
|
item.Description = "此零件号不在物料清单内!";
|
|
continue;
|
|
}
|
|
item.QualifiedRateStr = Math.Ceiling(item.QualifiedRate).ToString() + "%";
|
|
item.Color = material.Color;
|
|
item.Specification = material.Specification;
|
|
item.Description = !string.IsNullOrEmpty(material.Description)
|
|
? material.Description
|
|
: material.ProductName;
|
|
}
|
|
}
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public WmPolishQualityStatistics GetInfo(string Id)
|
|
{
|
|
var response = Queryable().Where(x => x.Id == Id).First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加抛光管理-质量统计
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public WmPolishQualityStatistics AddWmPolishQualityStatistics(
|
|
WmPolishQualityStatistics model
|
|
)
|
|
{
|
|
try
|
|
{
|
|
Context.Ado.BeginTran();
|
|
if (
|
|
model.RequireNumber
|
|
!= (
|
|
model.QualifiedNumber
|
|
+ model.PaoguangTotal
|
|
+ model.DamoTotal
|
|
+ model.BaofeiTotal
|
|
)
|
|
)
|
|
{
|
|
throw new Exception("投入数与合格数,抛光总数,打磨数,报废数不符合,请检查");
|
|
}
|
|
model.Id = SnowFlakeSingle.instance.NextId().ToString();
|
|
model.Type = 0;
|
|
decimal qualifiedRate = 0.0m;
|
|
if (model.QualifiedNumber != 0)
|
|
{
|
|
qualifiedRate =
|
|
(decimal)model.QualifiedNumber / model.RequireNumber * 100 ?? 0.0m;
|
|
}
|
|
model.QualifiedRate = qualifiedRate;
|
|
WmPolishQualityStatistics res0 = Context.Insertable(model).ExecuteReturnEntity();
|
|
if (res0 == null)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("插入抛光质检记录失败");
|
|
}
|
|
WmPolishInventoryService inventoryService = new();
|
|
WmOneTimeInventoryService oneTimeService = new();
|
|
// 合格品检查是否是门把手,是进入成品库(仅出库),不是进入一次合格品库
|
|
bool isDoorknob = CheckIsDoorknob(model.Partnumber);
|
|
if (!isDoorknob && model.QualifiedNumber > 0)
|
|
{
|
|
WmOneTimeInventory wmOneTimeInventoryWarehousing =
|
|
new()
|
|
{
|
|
Partnumber = model.Partnumber,
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
Quantity = model.PaoguangTotal,
|
|
CreatedBy = model.CreatedBy,
|
|
ActionTime = DateTime.Now.ToLocalTime(),
|
|
Remark =
|
|
"抛光合格品入库,合格数:"
|
|
+ model.QualifiedNumber
|
|
+ "。记录时间:"
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
|
+ "[来源记录识别编号:"
|
|
+ res0.Id
|
|
+ "]"
|
|
};
|
|
int res1 = oneTimeService.DoWmOneTimeWarehousing(wmOneTimeInventoryWarehousing);
|
|
if (res1 == 0)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("抛光合格品入库失败");
|
|
}
|
|
}
|
|
|
|
//抛光品重新进入抛光仓库
|
|
if (model.PaoguangTotal > 0)
|
|
{
|
|
WmPolishInventory wmPolishInventory =
|
|
new()
|
|
{
|
|
Partnumber = model.Partnumber,
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
Quantity = model.PaoguangTotal,
|
|
CreatedBy = model.CreatedBy,
|
|
ActionTime = DateTime.Now.ToLocalTime(),
|
|
Remark =
|
|
"抛光质检记录入库,抛光数:"
|
|
+ model.PaoguangTotal
|
|
+ "。记录时间:"
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
|
+ "[来源记录识别编号:"
|
|
+ res0.Id
|
|
+ "]"
|
|
};
|
|
int res1 = inventoryService.DoWmPolishWarehousing(wmPolishInventory);
|
|
if (res1 == 0)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("抛光质检记录入库失败");
|
|
}
|
|
}
|
|
//合格品,报废,打磨品 扣除抛光仓库库存
|
|
if ((model.BaofeiTotal + model.DamoTotal + model.QualifiedNumber) > 0)
|
|
{
|
|
WmPolishInventory wmPolishInventory =
|
|
new()
|
|
{
|
|
Partnumber = model.Partnumber,
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
Quantity = (
|
|
model.BaofeiTotal + model.DamoTotal + model.QualifiedNumber
|
|
),
|
|
CreatedBy = model.CreatedBy,
|
|
ActionTime = DateTime.Now,
|
|
Remark =
|
|
"抛光质检记录出库,合格数:"
|
|
+ model.QualifiedNumber
|
|
+ "、打磨数:"
|
|
+ model.DamoTotal
|
|
+ "、报废数:"
|
|
+ model.BaofeiTotal
|
|
+ "。记录时间:"
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
|
+ "[来源记录识别编号:"
|
|
+ res0.Id
|
|
+ "]"
|
|
};
|
|
int res2 = inventoryService.DoWmPolishRetrieval(wmPolishInventory);
|
|
if (res2 == 0)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("抛光质检记录出库失败");
|
|
}
|
|
}
|
|
Context.Ado.CommitTran();
|
|
return res0;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改抛光管理-质量统计
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateWmPolishQualityStatistics(WmPolishQualityStatistics model)
|
|
{
|
|
try
|
|
{
|
|
if (
|
|
model.RequireNumber
|
|
!= (
|
|
model.QualifiedNumber
|
|
+ model.PaoguangTotal
|
|
+ model.DamoTotal
|
|
+ model.BaofeiTotal
|
|
)
|
|
)
|
|
{
|
|
throw new Exception("投入数与合格数,抛光数,打磨数,报废数不符合,请检查");
|
|
}
|
|
decimal qualifiedRate = 0.0m;
|
|
if (model.QualifiedNumber != 0)
|
|
{
|
|
qualifiedRate =
|
|
(decimal)model.QualifiedNumber / model.RequireNumber * 100 ?? 0.0m;
|
|
}
|
|
model.QualifiedRate = qualifiedRate;
|
|
return Update(model, true);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查零件号是否是门把手
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool CheckIsDoorknob(string partnumber)
|
|
{
|
|
string[] checkStrArray = { "T22", "T26", "A58", "A60", "C01", "B02", "V71", "T1EJ" };
|
|
var isDoorknobCheck = Expressionable.Create<WmMaterial>();
|
|
foreach (string checkStr in checkStrArray)
|
|
{
|
|
isDoorknobCheck.Or(it => it.Description.Contains(checkStr));
|
|
}
|
|
;
|
|
isDoorknobCheck
|
|
.And(it => it.Partnumber == partnumber)
|
|
.And(it => it.Type == 1)
|
|
.And(it => it.Status == 1)
|
|
.And(it => it.Description.Contains("门把手"));
|
|
return Context.Queryable<WmMaterial>().Where(isDoorknobCheck.ToExpression()).Any();
|
|
}
|
|
}
|
|
}
|