2024-08-08 17:14:03 +08:00
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
using SqlSugar;
|
2025-07-28 15:40:59 +08:00
|
|
|
using System;
|
2024-08-08 17:14:03 +08:00
|
|
|
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>
|
2024-10-18 20:08:12 +08:00
|
|
|
/// 抛光管理-抛光操作Service业务层处理(抛光)
|
2024-08-08 17:14:03 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[AppService(
|
|
|
|
|
ServiceType = typeof(IWmPolishWorkQualityStatisticsService),
|
|
|
|
|
ServiceLifetime = LifeTime.Transient
|
|
|
|
|
)]
|
|
|
|
|
public class WmPolishWorkQualityStatisticsService
|
|
|
|
|
: BaseService<WmPolishWorkQualityStatistics>,
|
|
|
|
|
IWmPolishWorkQualityStatisticsService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询抛光管理-质量统计列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public PagedInfo<WmPolishWorkQualityStatisticsDto> GetList(
|
|
|
|
|
WmPolishWorkQualityStatisticsQueryDto parm
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
var predicate = Expressionable
|
|
|
|
|
.Create<WmPolishWorkQualityStatistics>()
|
|
|
|
|
.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)
|
|
|
|
|
)
|
2024-10-18 20:08:12 +08:00
|
|
|
.AndIF(
|
|
|
|
|
parm.Type != -1,
|
|
|
|
|
it => it.Type == parm.Type
|
|
|
|
|
)
|
2024-08-08 17:14:03 +08:00
|
|
|
.AndIF(
|
|
|
|
|
parm.StartTime != null,
|
|
|
|
|
it => it.StartTime >= parm.StartTime.Value.ToLocalTime()
|
|
|
|
|
)
|
|
|
|
|
.AndIF(
|
|
|
|
|
parm.EndTime != null,
|
2024-08-09 13:16:17 +08:00
|
|
|
it => it.StartTime <= parm.EndTime.Value.ToLocalTime()
|
2024-08-08 17:14:03 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
.Where(predicate.ToExpression())
|
|
|
|
|
.ToPage<WmPolishWorkQualityStatistics, WmPolishWorkQualityStatisticsDto>(parm);
|
|
|
|
|
if (response.Result.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (WmPolishWorkQualityStatisticsDto 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 WmPolishWorkQualityStatistics GetInfo(string Id)
|
|
|
|
|
{
|
|
|
|
|
var response = Queryable().Where(x => x.Id == Id).First();
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加抛光管理-质量统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public WmPolishWorkQualityStatistics AddWmPolishWorkQualityStatistics(
|
|
|
|
|
WmPolishWorkQualityStatistics model
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Context.Ado.BeginTran();
|
|
|
|
|
if (
|
|
|
|
|
model.RequireNumber
|
|
|
|
|
!= (model.QualifiedNumber + model.DamoTotal + model.BaofeiTotal)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("投入数与合格数,打磨数,报废数不符合,请检查");
|
|
|
|
|
}
|
|
|
|
|
model.Id = SnowFlakeSingle.instance.NextId().ToString();
|
2025-07-28 15:40:59 +08:00
|
|
|
|
|
|
|
|
if (model.IsOutbound)
|
2024-10-24 10:31:37 +08:00
|
|
|
{
|
|
|
|
|
model.Type = 1;
|
2024-10-25 19:01:06 +08:00
|
|
|
model.Remark += "[跳过后道]";
|
2024-10-24 10:31:37 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.Type = 0;
|
|
|
|
|
}
|
2024-08-08 17:14:03 +08:00
|
|
|
decimal qualifiedRate = 0.0m;
|
|
|
|
|
if (model.QualifiedNumber != 0)
|
|
|
|
|
{
|
|
|
|
|
qualifiedRate =
|
|
|
|
|
(decimal)model.QualifiedNumber / model.RequireNumber * 100 ?? 0.0m;
|
|
|
|
|
}
|
|
|
|
|
model.QualifiedRate = qualifiedRate;
|
2024-08-09 13:16:17 +08:00
|
|
|
WmPolishWorkQualityStatistics res0 = Context
|
|
|
|
|
.Insertable(model)
|
|
|
|
|
.ExecuteReturnEntity();
|
|
|
|
|
if (res0 == null)
|
|
|
|
|
{
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
throw new Exception("插入抛光操作记录失败");
|
|
|
|
|
}
|
2024-10-24 10:31:37 +08:00
|
|
|
// TODO 20241023 不再变动抛光仓库盘点数据
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
return res0;
|
2024-08-08 17:14:03 +08:00
|
|
|
WmPolishInventoryService inventoryService = new();
|
2024-10-18 20:08:12 +08:00
|
|
|
WmOneTimeInventoryService oneTimeService = new();
|
|
|
|
|
//抛光品直接出库到GP12
|
|
|
|
|
if (model.QualifiedNumber > 0 && model.IsOutbound)
|
2024-08-08 17:14:03 +08:00
|
|
|
{
|
|
|
|
|
WmPolishInventory wmPolishInventory =
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Partnumber = model.Partnumber,
|
|
|
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
|
|
|
Quantity = model.QualifiedNumber,
|
|
|
|
|
CreatedBy = model.CreatedBy,
|
2024-08-09 13:16:17 +08:00
|
|
|
ActionTime = DateTime.Now.ToLocalTime(),
|
2024-08-08 17:14:03 +08:00
|
|
|
Remark =
|
2024-10-18 20:08:12 +08:00
|
|
|
"抛光操作记录跳过后道出库,合格数:"
|
2024-08-08 17:14:03 +08:00
|
|
|
+ model.QualifiedNumber
|
2024-08-09 13:16:17 +08:00
|
|
|
+ "。记录时间:"
|
2024-08-08 17:14:03 +08:00
|
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
2024-08-09 13:16:17 +08:00
|
|
|
+ "[来源记录识别编号:"
|
|
|
|
|
+ res0.Id
|
|
|
|
|
+ "]"
|
2024-08-08 17:14:03 +08:00
|
|
|
};
|
2024-10-18 20:08:12 +08:00
|
|
|
int res1 = inventoryService.DoWmPolishRetrieval(wmPolishInventory);
|
2024-08-08 17:14:03 +08:00
|
|
|
if (res1 == 0)
|
|
|
|
|
{
|
|
|
|
|
Context.Ado.RollbackTran();
|
2024-10-18 20:08:12 +08:00
|
|
|
throw new Exception("抛光操作记录出库失败");
|
|
|
|
|
}
|
|
|
|
|
WmOneTimeInventory wmOneTimeInventoryWarehousing =
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Partnumber = model.Partnumber,
|
|
|
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
|
|
|
Quantity = model.QualifiedNumber,
|
|
|
|
|
CreatedBy = model.CreatedBy,
|
|
|
|
|
ActionTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
Remark =
|
|
|
|
|
"抛光操作合格品入一次合格库,合格数:"
|
|
|
|
|
+ model.QualifiedNumber
|
|
|
|
|
+ "。记录时间:"
|
|
|
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
|
|
|
|
+ "[来源记录识别编号:"
|
|
|
|
|
+ res0.Id
|
|
|
|
|
+ "]"
|
|
|
|
|
};
|
|
|
|
|
int res2 = oneTimeService.DoWmOneTimeWarehousing(wmOneTimeInventoryWarehousing);
|
|
|
|
|
if (res2 == 0)
|
|
|
|
|
{
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
throw new Exception("抛光合格品一次合格入库失败");
|
2024-08-08 17:14:03 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//报废,打磨品 扣除抛光仓库库存
|
|
|
|
|
if ((model.BaofeiTotal + model.DamoTotal) > 0)
|
|
|
|
|
{
|
|
|
|
|
WmPolishInventory wmPolishInventory =
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Partnumber = model.Partnumber,
|
|
|
|
|
Type = model.IsReturnWorkpiece ? 2 : 1,
|
|
|
|
|
Quantity = (model.BaofeiTotal + model.DamoTotal),
|
|
|
|
|
CreatedBy = model.CreatedBy,
|
2024-08-09 13:16:17 +08:00
|
|
|
ActionTime = DateTime.Now.ToLocalTime(),
|
2024-08-08 17:14:03 +08:00
|
|
|
Remark =
|
2024-10-18 20:08:12 +08:00
|
|
|
"抛光操作记录打磨报废出库:打磨数"
|
2024-08-08 17:14:03 +08:00
|
|
|
+ model.DamoTotal
|
|
|
|
|
+ "、报废数"
|
|
|
|
|
+ model.BaofeiTotal
|
|
|
|
|
+ "。记录时间"
|
|
|
|
|
+ model.CreatedTime.Value.ToLocalTime().ToString()
|
2024-08-09 13:16:17 +08:00
|
|
|
+ "[来源记录识别编号:"
|
|
|
|
|
+ res0.Id
|
|
|
|
|
+ "]"
|
2024-08-08 17:14:03 +08:00
|
|
|
};
|
2024-08-09 13:16:17 +08:00
|
|
|
int res2 = inventoryService.DoWmPolishRetrieval(wmPolishInventory);
|
|
|
|
|
if (res2 == 0)
|
2024-08-08 17:14:03 +08:00
|
|
|
{
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
throw new Exception("抛光操作记录出库失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Context.Ado.CommitTran();
|
2024-08-09 13:16:17 +08:00
|
|
|
return res0;
|
2024-08-08 17:14:03 +08:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改抛光管理-质量统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int UpdateWmPolishWorkQualityStatistics(WmPolishWorkQualityStatistics model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
model.RequireNumber
|
|
|
|
|
!= (model.QualifiedNumber + 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;
|
2024-10-24 10:31:37 +08:00
|
|
|
if (model.IsOutbound)
|
|
|
|
|
{
|
|
|
|
|
model.Type = 1;
|
2024-10-25 19:01:06 +08:00
|
|
|
model.Remark = "[跳过后道]";
|
2024-10-24 10:31:37 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.Type = 0;
|
|
|
|
|
}
|
2024-08-08 17:14:03 +08:00
|
|
|
return Update(model, true);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|