2024-09-30 15:31:21 +08:00
|
|
|
using System;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using DOAN.Model;
|
|
|
|
|
using DOAN.Model.Dto;
|
|
|
|
|
using DOAN.Repository;
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
2024-09-30 15:40:14 +08:00
|
|
|
using DOAN.Model.Mobile.Dto;
|
|
|
|
|
using DOAN.Infrastructure;
|
2024-09-30 16:04:32 +08:00
|
|
|
using DOAN.Model.MES.base_;
|
2024-10-08 11:49:38 +08:00
|
|
|
using DOAN.Model.MES.mm;
|
|
|
|
|
using NPOI.SS.UserModel;
|
|
|
|
|
using MathNet.Numerics.Distributions;
|
|
|
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
2024-10-12 16:30:09 +08:00
|
|
|
using DOAN.Service.MES.quality.IPQC.IService;
|
|
|
|
|
using DOAN.Model.MES.quality.IPQC.Dto;
|
|
|
|
|
using DOAN.Model.MES.quality.IPQC;
|
2024-09-30 15:31:21 +08:00
|
|
|
|
2024-10-12 16:30:09 +08:00
|
|
|
namespace DOAN.Service.MES.quality.IPQC
|
2024-09-30 15:31:21 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 缺陷收集Service业务层处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
[AppService(ServiceType = typeof(IQcDefectCollectionService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
public class QcDefectCollectionService : BaseService<QcDefectCollection>, IQcDefectCollectionService
|
|
|
|
|
{
|
2024-10-08 11:49:38 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 生成指定产线和日期的 缺陷收集计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line_code"></param>
|
|
|
|
|
/// <param name="dateTime"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool GenerateDefectConllectionPlan(string line_code, DateTime dateTime, string CreatedBy)
|
|
|
|
|
{
|
2024-10-08 14:09:28 +08:00
|
|
|
bool isGenerate = Context.Queryable<QcDefectCollection>().Where(it => it.LineCode == line_code).Where(it => it.DateTime == dateTime).Any();
|
2024-10-08 13:06:49 +08:00
|
|
|
if (isGenerate) { return false; }
|
2024-10-08 11:49:38 +08:00
|
|
|
List<QcDefectCollection> qcDefectCollections = new List<QcDefectCollection>();
|
|
|
|
|
//1 查询 产线物料需求计划
|
|
|
|
|
List<MmRequirePlanByline> MmPreparationTaskLineList = Context.Queryable<MmRequirePlanByline>().Where(it => it.LineCode == line_code)
|
|
|
|
|
.Where(it => it.RequireDate == dateTime).ToList();
|
|
|
|
|
//2 算出每个物料实际派发数量
|
|
|
|
|
var ActualDistributionQuantityOfMaterials = Context.Queryable<MmPreparationTaskLine>()
|
|
|
|
|
.LeftJoin<MmTaskMaterialInfoByLine>((t, i) => t.TaskCode == i.FkTaskCode)
|
|
|
|
|
.Where((t, i) => t.LineCode == line_code && t.TaskDate == dateTime)
|
|
|
|
|
.GroupBy((t, i) => i.MaterialCode)
|
|
|
|
|
.Select((t, i) => new
|
|
|
|
|
{
|
2024-10-12 16:30:09 +08:00
|
|
|
i.MaterialCode,
|
2024-10-08 11:49:38 +08:00
|
|
|
ActualNum = SqlFunc.AggregateSum(i.Quantity)
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var item in MmPreparationTaskLineList)
|
|
|
|
|
{
|
|
|
|
|
QcDefectCollection qcDefect = new QcDefectCollection();
|
|
|
|
|
qcDefect.Id = XueHua;
|
|
|
|
|
qcDefect.LineCode = line_code;
|
|
|
|
|
qcDefect.DateTime = dateTime;
|
|
|
|
|
qcDefect.MaterialCode = item.MaterialCode;
|
|
|
|
|
qcDefect.MaterialName = item.MaterialName;
|
2024-10-08 14:09:28 +08:00
|
|
|
var itemm = ActualDistributionQuantityOfMaterials.Where(it => it.MaterialCode == item.MaterialCode).FirstOrDefault();
|
2024-10-08 11:49:38 +08:00
|
|
|
qcDefect.Specification = item.Specification;
|
|
|
|
|
qcDefect.Unit = item.Unit;
|
|
|
|
|
qcDefect.PlanNum = item.RequireNum;
|
2024-10-08 13:17:40 +08:00
|
|
|
qcDefect.ActualNum = itemm?.ActualNum ?? 0;
|
2024-10-08 11:49:38 +08:00
|
|
|
qcDefect.CreatedTime = item.CreatedTime;
|
|
|
|
|
qcDefect.CreatedBy = CreatedBy;
|
|
|
|
|
qcDefectCollections.Add(qcDefect);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int result = Context.Insertable(qcDefectCollections).ExecuteCommand();
|
|
|
|
|
if (result > 1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-30 15:31:21 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 查询缺陷收集列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public PagedInfo<QcDefectCollectionDto> GetList(QcDefectCollectionQueryDto parm)
|
|
|
|
|
{
|
2024-09-30 15:45:30 +08:00
|
|
|
parm.DateTime = ConvertDateTime.ConvertLocalDate(parm.DateTime ?? DateTime.MinValue);
|
2024-09-30 15:40:14 +08:00
|
|
|
var predicate = Expressionable.Create<QcDefectCollection>()
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.MaterialCode), it => it.MaterialCode.Contains(parm.MaterialCode))
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.MaterialName), it => it.MaterialName.Contains(parm.MaterialName))
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.LineCode), it => it.LineCode.Contains(parm.LineCode))
|
|
|
|
|
.AndIF(parm.DateTime != null && parm.DateTime > DateTime.MinValue.AddYears(1), it => it.DateTime == parm.DateTime)
|
|
|
|
|
.AndIF(parm.Tqm != null, it => it.Tqm == parm.Tqm)
|
|
|
|
|
;
|
2024-09-30 15:31:21 +08:00
|
|
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
.Where(predicate.ToExpression())
|
2024-10-08 14:09:28 +08:00
|
|
|
.OrderBy(it => it.MaterialCode)
|
2024-09-30 15:31:21 +08:00
|
|
|
.ToPage<QcDefectCollection, QcDefectCollectionDto>(parm);
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public QcDefectCollection GetInfo(string Id)
|
|
|
|
|
{
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
.Where(x => x.Id == Id)
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加缺陷收集
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public QcDefectCollection AddQcDefectCollection(QcDefectCollection model)
|
|
|
|
|
{
|
2024-09-30 15:40:14 +08:00
|
|
|
model.Id = XueHua;
|
2024-09-30 15:31:21 +08:00
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:09:28 +08:00
|
|
|
|
|
|
|
|
public bool CopySameMaterial(string id)
|
|
|
|
|
{
|
|
|
|
|
QcDefectCollection qcDefect = Context.Queryable<QcDefectCollection>().Where(it => it.Id == id).First();
|
|
|
|
|
QcDefectCollection newqcDefect = new QcDefectCollection();
|
|
|
|
|
newqcDefect.Id = XueHua;
|
|
|
|
|
newqcDefect.LineCode = qcDefect.LineCode;
|
|
|
|
|
newqcDefect.DateTime = qcDefect.DateTime;
|
|
|
|
|
newqcDefect.MaterialCode = qcDefect.MaterialCode;
|
|
|
|
|
newqcDefect.MaterialName = qcDefect.MaterialName;
|
|
|
|
|
newqcDefect.Unit = qcDefect.Unit;
|
|
|
|
|
newqcDefect.Specification = qcDefect.Specification;
|
|
|
|
|
newqcDefect.PlanNum = qcDefect.PlanNum;
|
|
|
|
|
newqcDefect.ActualNum = qcDefect.ActualNum;
|
|
|
|
|
newqcDefect.CreatedBy = qcDefect.CreatedBy;
|
2024-10-12 16:30:09 +08:00
|
|
|
newqcDefect.CreatedTime = DateTime.Now;
|
2024-10-08 14:09:28 +08:00
|
|
|
int result = Context.Insertable(newqcDefect).ExecuteCommand();
|
|
|
|
|
if (result == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 15:31:21 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 修改缺陷收集
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int UpdateQcDefectCollection(QcDefectCollection model)
|
|
|
|
|
{
|
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new QcDefectCollection()
|
|
|
|
|
//{
|
|
|
|
|
// MaterialCode = model.MaterialCode,
|
|
|
|
|
// MaterialName = model.MaterialName,
|
|
|
|
|
// BatchNumber = model.BatchNumber,
|
|
|
|
|
// Unit = model.Unit,
|
|
|
|
|
// Quantity = model.Quantity,
|
|
|
|
|
// DateTime = model.DateTime,
|
|
|
|
|
// GroupCode = model.GroupCode,
|
|
|
|
|
// LineCode = model.LineCode,
|
|
|
|
|
// ProcessName = model.ProcessName,
|
|
|
|
|
// Superintendent = model.Superintendent,
|
|
|
|
|
// DefectDescription = model.DefectDescription,
|
|
|
|
|
// Tqm = model.Tqm,
|
|
|
|
|
// Remark = model.Remark,
|
|
|
|
|
// CreatedBy = model.CreatedBy,
|
|
|
|
|
// CreatedTime = model.CreatedTime,
|
|
|
|
|
// UpdatedBy = model.UpdatedBy,
|
|
|
|
|
// UpdatedTime = model.UpdatedTime,
|
|
|
|
|
//});
|
|
|
|
|
//return response;
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 16:04:32 +08:00
|
|
|
public List<BaseWorkRoute> GetAllLines()
|
|
|
|
|
{
|
|
|
|
|
return Context.Queryable<BaseWorkRoute>().Where(it => it.Status == 1).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 14:49:16 +08:00
|
|
|
|
|
|
|
|
public List<BaseSupplier> GetAllSuppliers(string supplier_str)
|
|
|
|
|
{
|
|
|
|
|
return Context.Queryable<BaseSupplier>()
|
2024-11-04 15:01:12 +08:00
|
|
|
.WhereIF(!string.IsNullOrEmpty(supplier_str),it=>it.SupplierNo.Contains(supplier_str))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(supplier_str),it=>it.SupplierName.Contains(supplier_str))
|
2024-11-04 14:56:09 +08:00
|
|
|
.Where(it=>it.Status == 1).Take(40).ToList();
|
2024-11-04 14:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-30 15:31:21 +08:00
|
|
|
}
|
|
|
|
|
}
|