diff --git a/DOAN.Admin.WebApi/Controllers/MES/quality/QcDefectCollectionController.cs b/DOAN.Admin.WebApi/Controllers/MES/quality/QcDefectCollectionController.cs
index e9550fe..8c5c123 100644
--- a/DOAN.Admin.WebApi/Controllers/MES/quality/QcDefectCollectionController.cs
+++ b/DOAN.Admin.WebApi/Controllers/MES/quality/QcDefectCollectionController.cs
@@ -4,6 +4,8 @@ using DOAN.Model.MES.quality;
using DOAN.Model.MES.quality.Dto;
using DOAN.Service.MES.quality;
using DOAN.Admin.WebApi.Filters;
+using DOAN.Infrastructure;
+using Aliyun.OSS;
//创建时间:2024-09-30
namespace DOAN.Admin.WebApi.Controllers
@@ -25,6 +27,20 @@ namespace DOAN.Admin.WebApi.Controllers
_QcDefectCollectionService = QcDefectCollectionService;
}
+ //TODO 生成指定产线和日期的 缺陷收集计划
+ [HttpGet("generate_defectCollection")]
+ public IActionResult GenerateDefectConllectionPlan(string line_code,DateTime dateTime)
+ {
+ dateTime= ConvertDateTime.ConvertLocalDate(dateTime);
+ if(string.IsNullOrEmpty(line_code)||dateTime== DateTime.MinValue)
+ {
+ throw new CustomException("请求数据为空");
+ }
+
+ var response = _QcDefectCollectionService.GenerateDefectConllectionPlan( line_code, dateTime,HttpContext.GetName());
+ return SUCCESS(response);
+ }
+
///
/// 查询缺陷收集列表
///
@@ -108,7 +124,7 @@ namespace DOAN.Admin.WebApi.Controllers
{
var response = _QcDefectCollectionService.GetAllLines();
- return ToResponse(response);
+ return SUCCESS(response);
}
diff --git a/DOAN.Model/MES/quality/Dto/QcDefectCollectionDto.cs b/DOAN.Model/MES/quality/Dto/QcDefectCollectionDto.cs
index 64820ba..cbf7b27 100644
--- a/DOAN.Model/MES/quality/Dto/QcDefectCollectionDto.cs
+++ b/DOAN.Model/MES/quality/Dto/QcDefectCollectionDto.cs
@@ -5,7 +5,7 @@ namespace DOAN.Model.MES.quality.Dto
///
/// 缺陷收集查询对象
///
- public class QcDefectCollectionQueryDto : PagerInfo
+ public class QcDefectCollectionQueryDto : PagerInfo
{
public string MaterialCode { get; set; }
@@ -13,7 +13,7 @@ namespace DOAN.Model.MES.quality.Dto
public DateTime? DateTime { get; set; }
- public string GroupCode { get; set; }
+
public string LineCode { get; set; }
@@ -25,9 +25,13 @@ namespace DOAN.Model.MES.quality.Dto
///
public class QcDefectCollectionDto
{
-
+ [Required(ErrorMessage = "id不能为空")]
public string Id { get; set; }
+ public string LineCode { get; set; }
+
+ public DateTime? DateTime { get; set; }
+
public string MaterialCode { get; set; }
public string MaterialName { get; set; }
@@ -36,14 +40,12 @@ namespace DOAN.Model.MES.quality.Dto
public string Unit { get; set; }
+ public decimal PlanNum { get; set; }
+
+ public decimal ActualNum { get; set; }
+
public decimal Quantity { get; set; }
- public DateTime? DateTime { get; set; }
-
- public string GroupCode { get; set; }
-
- public string LineCode { get; set; }
-
public string ProcessName { get; set; }
public string Superintendent { get; set; }
diff --git a/DOAN.Model/MES/quality/QcDefectCollection.cs b/DOAN.Model/MES/quality/QcDefectCollection.cs
index 7424626..7287591 100644
--- a/DOAN.Model/MES/quality/QcDefectCollection.cs
+++ b/DOAN.Model/MES/quality/QcDefectCollection.cs
@@ -1,4 +1,3 @@
-
namespace DOAN.Model.MES.quality
{
///
@@ -13,6 +12,18 @@ namespace DOAN.Model.MES.quality
[SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
public string Id { get; set; }
+ ///
+ /// 线别
+ ///
+ [SugarColumn(ColumnName = "line_code")]
+ public string LineCode { get; set; }
+
+ ///
+ /// 日期
+ ///
+ [SugarColumn(ColumnName = "date_time")]
+ public DateTime? DateTime { get; set; }
+
///
/// 物料编码
///
@@ -36,29 +47,26 @@ namespace DOAN.Model.MES.quality
///
public string Unit { get; set; }
+
+ public string Specification { get; set; }
+
///
- /// 数量
+ /// 计划数量
+ ///
+ [SugarColumn(ColumnName = "plan_num")]
+ public decimal PlanNum { get; set; }
+
+ ///
+ /// 实际数量
+ ///
+ [SugarColumn(ColumnName = "actual_num")]
+ public decimal ActualNum { get; set; }
+
+ ///
+ /// 缺陷数量
///
public decimal Quantity { get; set; }
- ///
- /// 日期
- ///
- [SugarColumn(ColumnName = "date_time")]
- public DateTime? DateTime { get; set; }
-
- ///
- /// 组别
- ///
- [SugarColumn(ColumnName = "group_code")]
- public string GroupCode { get; set; }
-
- ///
- /// 线别
- ///
- [SugarColumn(ColumnName = "line_code")]
- public string LineCode { get; set; }
-
///
/// 工序名称
///
diff --git a/DOAN.Service/MES/quality/IService/IQcDefectCollectionService.cs b/DOAN.Service/MES/quality/IService/IQcDefectCollectionService.cs
index 230ab43..0fab5a3 100644
--- a/DOAN.Service/MES/quality/IService/IQcDefectCollectionService.cs
+++ b/DOAN.Service/MES/quality/IService/IQcDefectCollectionService.cs
@@ -14,6 +14,8 @@ namespace DOAN.Service.MES.quality
///
public interface IQcDefectCollectionService : IBaseService
{
+
+ bool GenerateDefectConllectionPlan(string line_code, DateTime dateTime, string CreatedBy);
PagedInfo GetList(QcDefectCollectionQueryDto parm);
QcDefectCollection GetInfo(string Id);
@@ -22,7 +24,7 @@ namespace DOAN.Service.MES.quality
int UpdateQcDefectCollection(QcDefectCollection parm);
- List GetAllLines();
+ List GetAllLines();
}
}
diff --git a/DOAN.Service/MES/quality/QcDefectCollectionService.cs b/DOAN.Service/MES/quality/QcDefectCollectionService.cs
index 7910e8b..75f19b4 100644
--- a/DOAN.Service/MES/quality/QcDefectCollectionService.cs
+++ b/DOAN.Service/MES/quality/QcDefectCollectionService.cs
@@ -12,6 +12,10 @@ using System.Linq;
using DOAN.Model.Mobile.Dto;
using DOAN.Infrastructure;
using DOAN.Model.MES.base_;
+using DOAN.Model.MES.mm;
+using NPOI.SS.UserModel;
+using MathNet.Numerics.Distributions;
+using Microsoft.AspNetCore.Http.HttpResults;
namespace DOAN.Service.MES.quality
{
@@ -21,6 +25,62 @@ namespace DOAN.Service.MES.quality
[AppService(ServiceType = typeof(IQcDefectCollectionService), ServiceLifetime = LifeTime.Transient)]
public class QcDefectCollectionService : BaseService, IQcDefectCollectionService
{
+ ///
+ /// 生成指定产线和日期的 缺陷收集计划
+ ///
+ ///
+ ///
+ ///
+ public bool GenerateDefectConllectionPlan(string line_code, DateTime dateTime, string CreatedBy)
+ {
+ List qcDefectCollections = new List();
+ //1 查询 产线物料需求计划
+ List MmPreparationTaskLineList = Context.Queryable().Where(it => it.LineCode == line_code)
+ .Where(it => it.RequireDate == dateTime).ToList();
+ //2 算出每个物料实际派发数量
+ var ActualDistributionQuantityOfMaterials = Context.Queryable()
+ .LeftJoin((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
+ {
+ MaterialCode = i.MaterialCode,
+ 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;
+ var itemm = ActualDistributionQuantityOfMaterials.Where(it => it.MaterialCode == item.MaterialCode).First();
+ qcDefect.Specification = item.Specification;
+ qcDefect.Unit = item.Unit;
+ qcDefect.PlanNum = item.RequireNum;
+ qcDefect.ActualNum = itemm.ActualNum;
+ qcDefect.CreatedTime = item.CreatedTime;
+ qcDefect.CreatedBy = CreatedBy;
+ qcDefectCollections.Add(qcDefect);
+
+ }
+
+
+ int result = Context.Insertable(qcDefectCollections).ExecuteCommand();
+ if (result > 1)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+
///
/// 查询缺陷收集列表
///
@@ -32,7 +92,6 @@ namespace DOAN.Service.MES.quality
var predicate = Expressionable.Create()
.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.GroupCode), it => it.GroupCode.Contains(parm.GroupCode))
.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)
diff --git a/Infrastructure/WebExtensions/HttpContextExtension.cs b/Infrastructure/WebExtensions/HttpContextExtension.cs
index a6e42cf..1dc3a76 100644
--- a/Infrastructure/WebExtensions/HttpContextExtension.cs
+++ b/Infrastructure/WebExtensions/HttpContextExtension.cs
@@ -91,8 +91,6 @@ namespace Infrastructure.Extensions
{
var uid = context.User?.Identity?.Name;
-
-
return uid;
}