|
@@ -2,12 +2,21 @@
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using System.Linq.Expressions;
|
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
using Business.EntityFrameworkCore.SqlRepositories;
|
|
using Business.EntityFrameworkCore.SqlRepositories;
|
|
|
|
|
+using Business.StructuredDB;
|
|
|
using Business.StructuredDB.Sqe;
|
|
using Business.StructuredDB.Sqe;
|
|
|
|
|
+using MathNet.Numerics.Statistics;
|
|
|
|
|
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
|
|
|
+using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
|
|
+using NPOI.XWPF.UserModel;
|
|
|
|
|
+using RazorEngine.Compilation.ImpromptuInterface.Optimization;
|
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
|
|
|
|
namespace Business.VSM
|
|
namespace Business.VSM
|
|
|
{
|
|
{
|
|
@@ -22,8 +31,10 @@ namespace Business.VSM
|
|
|
private readonly ISqeRepository<sqe_cto_process_data> _sqe_cto_process_data;
|
|
private readonly ISqeRepository<sqe_cto_process_data> _sqe_cto_process_data;
|
|
|
private readonly ISqeRepository<sqe_cto_process_standard> _sqe_cto_process_standard;
|
|
private readonly ISqeRepository<sqe_cto_process_standard> _sqe_cto_process_standard;
|
|
|
private readonly ISqeRepository<sqe_cto_test> _sqe_cto_test;
|
|
private readonly ISqeRepository<sqe_cto_test> _sqe_cto_test;
|
|
|
|
|
+ private readonly ISqeRepository<sqe_cto_test_avg> _sqe_cto_test_avg;
|
|
|
private readonly ISqeRepository<sqe_cto_test_data> _sqe_cto_test_data;
|
|
private readonly ISqeRepository<sqe_cto_test_data> _sqe_cto_test_data;
|
|
|
private readonly ISqeRepository<sqe_cto_test_standard> _sqe_cto_test_standard;
|
|
private readonly ISqeRepository<sqe_cto_test_standard> _sqe_cto_test_standard;
|
|
|
|
|
+ private readonly ISqeRepository<sqe_cto_test_statistics> _sqe_cto_test_statistics;
|
|
|
private readonly ISqeRepository<sqe_file_data> _sqe_file_data;
|
|
private readonly ISqeRepository<sqe_file_data> _sqe_file_data;
|
|
|
private readonly ISqeRepository<sqe_file_upload> _sqe_file_upload;
|
|
private readonly ISqeRepository<sqe_file_upload> _sqe_file_upload;
|
|
|
private readonly ISqeRepository<sqe_oqc> _sqe_oqc;
|
|
private readonly ISqeRepository<sqe_oqc> _sqe_oqc;
|
|
@@ -36,6 +47,9 @@ namespace Business.VSM
|
|
|
private readonly ISqeRepository<sqe_op_data_detail> _sqe_op_data_detail;
|
|
private readonly ISqeRepository<sqe_op_data_detail> _sqe_op_data_detail;
|
|
|
private readonly ISqeRepository<sqe_fct> _sqe_fct;
|
|
private readonly ISqeRepository<sqe_fct> _sqe_fct;
|
|
|
private readonly ISqeRepository<sqe_fct_data> _sqe_fct_data;
|
|
private readonly ISqeRepository<sqe_fct_data> _sqe_fct_data;
|
|
|
|
|
+ private readonly ISqeRepository<v_sqe_cto_test_data> _v_sqe_cto_test_data;
|
|
|
|
|
+ private readonly ISqeRepository<v_sqe_op_data_detail> _v_sqe_op_data_detail;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
public SqeExcelService(
|
|
public SqeExcelService(
|
|
@@ -43,8 +57,10 @@ namespace Business.VSM
|
|
|
ISqeRepository<sqe_cto_process_data> sqe_cto_process_data,
|
|
ISqeRepository<sqe_cto_process_data> sqe_cto_process_data,
|
|
|
ISqeRepository<sqe_cto_process_standard> sqe_cto_process_standard,
|
|
ISqeRepository<sqe_cto_process_standard> sqe_cto_process_standard,
|
|
|
ISqeRepository<sqe_cto_test> sqe_cto_test,
|
|
ISqeRepository<sqe_cto_test> sqe_cto_test,
|
|
|
|
|
+ ISqeRepository<sqe_cto_test_avg> sqe_cto_test_avg,
|
|
|
ISqeRepository<sqe_cto_test_data> sqe_cto_test_data,
|
|
ISqeRepository<sqe_cto_test_data> sqe_cto_test_data,
|
|
|
ISqeRepository<sqe_cto_test_standard> sqe_cto_test_standard,
|
|
ISqeRepository<sqe_cto_test_standard> sqe_cto_test_standard,
|
|
|
|
|
+ ISqeRepository<sqe_cto_test_statistics> sqe_cto_test_statistics,
|
|
|
ISqeRepository<sqe_file_data> sqe_file_data,
|
|
ISqeRepository<sqe_file_data> sqe_file_data,
|
|
|
ISqeRepository<sqe_file_upload> sqe_file_upload,
|
|
ISqeRepository<sqe_file_upload> sqe_file_upload,
|
|
|
ISqeRepository<sqe_oqc> sqe_oqc,
|
|
ISqeRepository<sqe_oqc> sqe_oqc,
|
|
@@ -56,7 +72,9 @@ namespace Business.VSM
|
|
|
ISqeRepository<sqe_op_data> sqe_op_data,
|
|
ISqeRepository<sqe_op_data> sqe_op_data,
|
|
|
ISqeRepository<sqe_op_data_detail> sqe_op_data_detail,
|
|
ISqeRepository<sqe_op_data_detail> sqe_op_data_detail,
|
|
|
ISqeRepository<sqe_fct> sqe_fct,
|
|
ISqeRepository<sqe_fct> sqe_fct,
|
|
|
- ISqeRepository<sqe_fct_data> sqe_fct_data
|
|
|
|
|
|
|
+ ISqeRepository<sqe_fct_data> sqe_fct_data,
|
|
|
|
|
+ ISqeRepository<v_sqe_cto_test_data> v_sqe_cto_test_data,
|
|
|
|
|
+ ISqeRepository<v_sqe_op_data_detail> v_sqe_op_data_detail
|
|
|
)
|
|
)
|
|
|
{
|
|
{
|
|
|
WLLog = new LoggerHelper();
|
|
WLLog = new LoggerHelper();
|
|
@@ -64,8 +82,10 @@ namespace Business.VSM
|
|
|
_sqe_cto_process_data = sqe_cto_process_data;
|
|
_sqe_cto_process_data = sqe_cto_process_data;
|
|
|
_sqe_cto_process_standard = sqe_cto_process_standard;
|
|
_sqe_cto_process_standard = sqe_cto_process_standard;
|
|
|
_sqe_cto_test = sqe_cto_test;
|
|
_sqe_cto_test = sqe_cto_test;
|
|
|
|
|
+ _sqe_cto_test_avg = sqe_cto_test_avg;
|
|
|
_sqe_cto_test_data = sqe_cto_test_data;
|
|
_sqe_cto_test_data = sqe_cto_test_data;
|
|
|
_sqe_cto_test_standard = sqe_cto_test_standard;
|
|
_sqe_cto_test_standard = sqe_cto_test_standard;
|
|
|
|
|
+ _sqe_cto_test_statistics = sqe_cto_test_statistics;
|
|
|
_sqe_file_data = sqe_file_data;
|
|
_sqe_file_data = sqe_file_data;
|
|
|
_sqe_file_upload = sqe_file_upload;
|
|
_sqe_file_upload = sqe_file_upload;
|
|
|
_sqe_oqc = sqe_oqc;
|
|
_sqe_oqc = sqe_oqc;
|
|
@@ -79,6 +99,8 @@ namespace Business.VSM
|
|
|
_sqe_fct = sqe_fct;
|
|
_sqe_fct = sqe_fct;
|
|
|
_sqe_fct_data = sqe_fct_data;
|
|
_sqe_fct_data = sqe_fct_data;
|
|
|
|
|
|
|
|
|
|
+ _v_sqe_cto_test_data = v_sqe_cto_test_data;
|
|
|
|
|
+ _v_sqe_op_data_detail = v_sqe_op_data_detail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///// <summary>
|
|
///// <summary>
|
|
@@ -515,6 +537,25 @@ namespace Business.VSM
|
|
|
// return tables;
|
|
// return tables;
|
|
|
//}
|
|
//}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 依据上传文件标识,获取上传文件对象
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="upload_id"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public sqe_file_upload Get_Sqe_file_upload(int upload_id)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ List<sqe_file_upload> uploads = _sqe_file_upload.Select(a => a.id == upload_id);
|
|
|
|
|
+ sqe_file_upload _Upload = _sqe_file_upload.Select(a => a.id == upload_id).First();
|
|
|
|
|
+ return _Upload;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -530,7 +571,7 @@ namespace Business.VSM
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
|
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
|
if (datas == null || datas.Count == 0)
|
|
if (datas == null || datas.Count == 0)
|
|
|
{
|
|
{
|
|
@@ -591,6 +632,10 @@ namespace Business.VSM
|
|
|
return stringBuilder.ToString();
|
|
return stringBuilder.ToString();
|
|
|
}
|
|
}
|
|
|
_sqe_cto_test_data.Insert(test_Datas);
|
|
_sqe_cto_test_data.Insert(test_Datas);
|
|
|
|
|
+
|
|
|
|
|
+ sqe_File_Upload.item_no = test.item_no;
|
|
|
|
|
+ sqe_File_Upload.item_name = test.item_name;
|
|
|
|
|
+ _sqe_file_upload.Update(sqe_File_Upload);
|
|
|
_sqe_cto_test.CommitTransaction();
|
|
_sqe_cto_test.CommitTransaction();
|
|
|
_sqe_cto_test_standard.CommitTransaction();
|
|
_sqe_cto_test_standard.CommitTransaction();
|
|
|
}
|
|
}
|
|
@@ -624,10 +669,12 @@ namespace Business.VSM
|
|
|
sqe_cto_test model = new sqe_cto_test();
|
|
sqe_cto_test model = new sqe_cto_test();
|
|
|
DateTime timeValue;
|
|
DateTime timeValue;
|
|
|
decimal realValuel;
|
|
decimal realValuel;
|
|
|
|
|
+ int intValue;
|
|
|
if (datas != null && datas.Count >= 5)
|
|
if (datas != null && datas.Count >= 5)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ model.file_id = datas[0].file_id;
|
|
|
sqe_file_data data = datas[1];
|
|
sqe_file_data data = datas[1];
|
|
|
if (DateTime.TryParse(data.c2, out timeValue))
|
|
if (DateTime.TryParse(data.c2, out timeValue))
|
|
|
{
|
|
{
|
|
@@ -663,9 +710,9 @@ namespace Business.VSM
|
|
|
data = datas[4];
|
|
data = datas[4];
|
|
|
model.device_name = data.c2;
|
|
model.device_name = data.c2;
|
|
|
model.device_no = data.c4;
|
|
model.device_no = data.c4;
|
|
|
- if (decimal.TryParse(data.c8, out realValuel))
|
|
|
|
|
|
|
+ if (int.TryParse(data.c8, out intValue))
|
|
|
{
|
|
{
|
|
|
- model.sampling_number = realValuel;
|
|
|
|
|
|
|
+ model.sampling_number = intValue;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -1445,7 +1492,7 @@ namespace Business.VSM
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
|
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
|
if (datas == null || datas.Count == 0)
|
|
if (datas == null || datas.Count == 0)
|
|
|
{
|
|
{
|
|
@@ -1507,6 +1554,10 @@ namespace Business.VSM
|
|
|
return stringBuilder.ToString();
|
|
return stringBuilder.ToString();
|
|
|
}
|
|
}
|
|
|
_sqe_cto_process_data.Insert(test_Datas);
|
|
_sqe_cto_process_data.Insert(test_Datas);
|
|
|
|
|
+ sqe_File_Upload.item_no = test.item_no;
|
|
|
|
|
+ sqe_File_Upload.item_name = test.item_name;
|
|
|
|
|
+ _sqe_file_upload.Update(sqe_File_Upload);
|
|
|
|
|
+
|
|
|
_sqe_cto_process.CommitTransaction();
|
|
_sqe_cto_process.CommitTransaction();
|
|
|
_sqe_cto_process_standard.CommitTransaction();
|
|
_sqe_cto_process_standard.CommitTransaction();
|
|
|
}
|
|
}
|
|
@@ -1533,6 +1584,7 @@ namespace Business.VSM
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ model.file_id = datas[0].file_id;
|
|
|
sqe_file_data data = datas[1];
|
|
sqe_file_data data = datas[1];
|
|
|
if (DateTime.TryParse(data.c2, out timeValue))
|
|
if (DateTime.TryParse(data.c2, out timeValue))
|
|
|
{
|
|
{
|
|
@@ -2326,6 +2378,7 @@ namespace Business.VSM
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
|
|
|
|
|
|
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
|
if (datas == null || datas.Count == 0)
|
|
if (datas == null || datas.Count == 0)
|
|
@@ -2381,6 +2434,9 @@ namespace Business.VSM
|
|
|
return stringBuilder.ToString();
|
|
return stringBuilder.ToString();
|
|
|
}
|
|
}
|
|
|
_sqe_op_data_detail.Insert(test_Datas);
|
|
_sqe_op_data_detail.Insert(test_Datas);
|
|
|
|
|
+ sqe_File_Upload.item_no = standards[0].item_no;
|
|
|
|
|
+ sqe_File_Upload.item_name = standards[0].item_name;
|
|
|
|
|
+ _sqe_file_upload.Update(sqe_File_Upload);
|
|
|
_sqe_op.CommitTransaction();
|
|
_sqe_op.CommitTransaction();
|
|
|
_sqe_op_data.CommitTransaction();
|
|
_sqe_op_data.CommitTransaction();
|
|
|
}
|
|
}
|
|
@@ -2411,6 +2467,10 @@ namespace Business.VSM
|
|
|
model.create_by = create_by;
|
|
model.create_by = create_by;
|
|
|
model.create_date = create_date;
|
|
model.create_date = create_date;
|
|
|
model.create_org = create_org;
|
|
model.create_org = create_org;
|
|
|
|
|
+ if (datas != null && datas.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ model.file_id = datas[0].file_id;
|
|
|
|
|
+ }
|
|
|
errorMsg = string.Empty;
|
|
errorMsg = string.Empty;
|
|
|
errorMsg = "";
|
|
errorMsg = "";
|
|
|
return model;
|
|
return model;
|
|
@@ -2606,6 +2666,7 @@ namespace Business.VSM
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
|
|
|
|
|
|
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
|
if (datas == null || datas.Count == 0)
|
|
if (datas == null || datas.Count == 0)
|
|
@@ -2666,6 +2727,9 @@ namespace Business.VSM
|
|
|
}
|
|
}
|
|
|
_sqe_fpy_data.BeginTransaction();
|
|
_sqe_fpy_data.BeginTransaction();
|
|
|
_sqe_fpy_data.Insert(standards);
|
|
_sqe_fpy_data.Insert(standards);
|
|
|
|
|
+ sqe_File_Upload.item_no = standards[0].item_no;
|
|
|
|
|
+ sqe_File_Upload.item_name = standards[0].item_name;
|
|
|
|
|
+ _sqe_file_upload.Update(sqe_File_Upload);
|
|
|
|
|
|
|
|
_sqe_fpy.CommitTransaction();
|
|
_sqe_fpy.CommitTransaction();
|
|
|
_sqe_fpy_data.CommitTransaction();
|
|
_sqe_fpy_data.CommitTransaction();
|
|
@@ -2697,6 +2761,10 @@ namespace Business.VSM
|
|
|
model.create_by = create_by;
|
|
model.create_by = create_by;
|
|
|
model.create_date = create_date;
|
|
model.create_date = create_date;
|
|
|
model.create_org = create_org;
|
|
model.create_org = create_org;
|
|
|
|
|
+ if (datas != null && datas.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ model.file_id = datas[0].file_id;
|
|
|
|
|
+ }
|
|
|
errorMsg = string.Empty;
|
|
errorMsg = string.Empty;
|
|
|
errorMsg = "";
|
|
errorMsg = "";
|
|
|
return model;
|
|
return model;
|
|
@@ -2786,6 +2854,7 @@ namespace Business.VSM
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
|
|
|
|
|
|
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
List<sqe_file_data> datas = LoadData_file_data(upload_id);
|
|
|
if (datas == null || datas.Count == 0)
|
|
if (datas == null || datas.Count == 0)
|
|
@@ -2846,6 +2915,10 @@ namespace Business.VSM
|
|
|
return stringBuilder.ToString();
|
|
return stringBuilder.ToString();
|
|
|
}
|
|
}
|
|
|
_sqe_oqc_data.Insert(test_Datas);
|
|
_sqe_oqc_data.Insert(test_Datas);
|
|
|
|
|
+ sqe_File_Upload.item_no = test.item_no;
|
|
|
|
|
+ sqe_File_Upload.item_name = test.item_name;
|
|
|
|
|
+ _sqe_file_upload.Update(sqe_File_Upload);
|
|
|
|
|
+
|
|
|
_sqe_oqc.CommitTransaction();
|
|
_sqe_oqc.CommitTransaction();
|
|
|
_sqe_oqc_standard.CommitTransaction();
|
|
_sqe_oqc_standard.CommitTransaction();
|
|
|
}
|
|
}
|
|
@@ -2881,6 +2954,7 @@ namespace Business.VSM
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ model.file_id = datas[0].file_id;
|
|
|
sqe_file_data data = datas[1];
|
|
sqe_file_data data = datas[1];
|
|
|
model.supp_no = data.c2;
|
|
model.supp_no = data.c2;
|
|
|
model.item_name = data.c4;
|
|
model.item_name = data.c4;
|
|
@@ -3244,5 +3318,470 @@ namespace Business.VSM
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion Fct
|
|
#endregion Fct
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 依据上传文件id,生成该文件上传的数据统计
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="upload_id"></param>
|
|
|
|
|
+ /// <param name="create_by"></param>
|
|
|
|
|
+ /// <param name="create_date"></param>
|
|
|
|
|
+ /// <param name="create_org"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public string Compute_Test(int upload_id, string create_by, DateTime create_date, string create_org)
|
|
|
|
|
+ {
|
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
+
|
|
|
|
|
+ //查询原始记录
|
|
|
|
|
+ List<sqe_cto_test> tests = _sqe_cto_test.Select(a => a.file_id == upload_id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ if (tests == null || tests.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ stringBuilder.AppendLine("该id对应的上传数据记录不存在!");
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ sqe_cto_test test = tests[0];
|
|
|
|
|
+ List<sqe_cto_test_standard> test_standards = _sqe_cto_test_standard.Select(a => a.test_id == test.id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ if (test_standards == null || test_standards.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ stringBuilder.AppendLine("该id对应的检验标准数据记录不存在!");
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ //Compute_Test_id(upload_id, "1号尺寸", create_by, create_date, create_org);
|
|
|
|
|
+ Compute_Test_id(upload_id, test_standards[0].standard_no, create_by, create_date, create_org);
|
|
|
|
|
+
|
|
|
|
|
+ List<sqe_cto_test_data> test_datas = _sqe_cto_test_data.Select(a => a.test_id == test.id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+
|
|
|
|
|
+ //生成统计信息
|
|
|
|
|
+ List<sqe_cto_test_avg> test_avgs = _sqe_cto_test_avg.Select(a => a.cto_test_id == test.id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ if (test_avgs != null && test_avgs.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ stringBuilder.AppendLine("该id的数据统计已经完成!");
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ int sample_count = test.sampling_number;
|
|
|
|
|
+ for (int i = 0; i <= test_datas.Count - sample_count; i += sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public string Compute_Test_id(int test_id, string standard_no, string create_by, DateTime create_date, string create_org)
|
|
|
|
|
+ {
|
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
+
|
|
|
|
|
+ //查询原始记录
|
|
|
|
|
+ List<sqe_cto_test> tests = _sqe_cto_test.Select(a => a.id == test_id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ if (tests == null || tests.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ stringBuilder.AppendLine("该id对应的上传数据记录不存在!");
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ sqe_cto_test test = tests[0];
|
|
|
|
|
+
|
|
|
|
|
+ List<v_sqe_cto_test_data> test_datas = _v_sqe_cto_test_data.Select(a => a.test_id == test.id && a.standard_no == standard_no && a.data_value != null).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ //List<v_sqe_cto_test_data> test_datas = _v_sqe_cto_test_data.Select(a => a.standard_no == standard_no && a.data_value != null).OrderBy(a => a.id).ToList();
|
|
|
|
|
+
|
|
|
|
|
+ //生成统计信息
|
|
|
|
|
+ List<sqe_cto_test_avg> test_avgs = _sqe_cto_test_avg.Select(a => a.cto_test_id == test.id).OrderBy(a => a.id).ToList();
|
|
|
|
|
+ if (test_avgs != null && test_avgs.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ stringBuilder.AppendLine("该id的数据统计已经完成!");
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int sample_count = test.sampling_number;
|
|
|
|
|
+ double[] data = new double[sample_count];
|
|
|
|
|
+ double[] dataAll = new double[test_datas.Count / sample_count * sample_count];
|
|
|
|
|
+ double[] dataRange = new double[test_datas.Count / sample_count];
|
|
|
|
|
+ for (int i = 0; i <= test_datas.Count - sample_count; i += sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ sqe_cto_test_avg obj = new sqe_cto_test_avg();
|
|
|
|
|
+ for (int j = 0; j < sample_count; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ data[j] = (double)test_datas[i + j].data_value.Value;
|
|
|
|
|
+ dataAll[i + j] = data[j];
|
|
|
|
|
+ }
|
|
|
|
|
+ obj.create_by = create_by;
|
|
|
|
|
+ obj.create_date = create_date;
|
|
|
|
|
+ obj.create_org = create_org;
|
|
|
|
|
+ obj.standard_no = standard_no;
|
|
|
|
|
+ obj.sampling_number = sample_count;
|
|
|
|
|
+ obj.mean_value = (decimal)data.Average();
|
|
|
|
|
+ obj.range_value = (decimal)(data.Max() - data.Min());
|
|
|
|
|
+ dataRange[i / sample_count] = (double)obj.range_value;
|
|
|
|
|
+ obj.cto_test_id = test_id;
|
|
|
|
|
+ test_avgs.Add(obj);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ decimal a2 = (decimal)GetA2(sample_count);
|
|
|
|
|
+ decimal d2 = (decimal)GetD2(sample_count);
|
|
|
|
|
+ decimal d3 = (decimal)GetD3(sample_count);
|
|
|
|
|
+ decimal d4 = (decimal)GetD4(sample_count);
|
|
|
|
|
+
|
|
|
|
|
+ //开始计算统计结果
|
|
|
|
|
+ sqe_cto_test_statistics model = new sqe_cto_test_statistics();
|
|
|
|
|
+ model.create_by = create_by;
|
|
|
|
|
+ model.create_date = create_date;
|
|
|
|
|
+ model.create_org = create_org;
|
|
|
|
|
+ model.cto_test_id = test.id;
|
|
|
|
|
+ model.standard_no = standard_no;
|
|
|
|
|
+ model.value_count = test_datas.Count;
|
|
|
|
|
+ model.standard_min = test_datas[0].standard_min;
|
|
|
|
|
+ model.standard_max = test_datas[0].standard_max;
|
|
|
|
|
+ model.standard_value = (model.standard_min + model.standard_max) / 2;
|
|
|
|
|
+ model.value_sum = (decimal)dataAll.Sum();
|
|
|
|
|
+ model.value_avg = (decimal)dataAll.Average();
|
|
|
|
|
+ model.value_max = (decimal)dataAll.Max();
|
|
|
|
|
+ model.value_min = (decimal)dataAll.Min();
|
|
|
|
|
+ model.value_below = dataAll.Count(x => x < (double)model.standard_min);
|
|
|
|
|
+ model.value_above = dataAll.Count(x => x > (double)model.standard_max);
|
|
|
|
|
+ model.avg_range = (decimal)dataRange.Average();
|
|
|
|
|
+ model.value_d2 = d2;
|
|
|
|
|
+ model.value_cpu = (model.standard_max - model.value_avg) / (3 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cpl = (model.value_avg - model.standard_min) / (3 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cp = (model.standard_max - model.standard_min) / (6 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cpk = model.value_cpu < model.value_cpl ? model.value_cpu : model.value_cpl;
|
|
|
|
|
+ model.value_cr = (decimal)1.0 / model.value_cp;
|
|
|
|
|
+ model.value_stdev = (decimal)dataAll.StandardDeviation();
|
|
|
|
|
+ model.value_stdevp = (decimal)dataAll.PopulationStandardDeviation();
|
|
|
|
|
+ model.value_var = (decimal)dataAll.Variance();
|
|
|
|
|
+ model.value_varp = (decimal)dataAll.PopulationVariance();
|
|
|
|
|
+ model.value_pp = (model.standard_max - model.standard_min) / (6 * model.value_stdev);
|
|
|
|
|
+ model.value_ppu = (model.standard_max - model.value_avg) / (3 * model.value_stdev);
|
|
|
|
|
+ model.value_ppl = (model.value_avg - model.standard_min) / (3 * model.value_stdev);
|
|
|
|
|
+ model.value_ppk = model.value_ppu < model.value_ppl ? model.value_ppu : model.value_ppl;
|
|
|
|
|
+
|
|
|
|
|
+ //更新均值方差数据表信息
|
|
|
|
|
+ foreach (var item in test_avgs)
|
|
|
|
|
+ {
|
|
|
|
|
+ item.mean_value_all = model.value_avg;
|
|
|
|
|
+ item.range_value_all = model.avg_range;
|
|
|
|
|
+ item.value_uclx = item.mean_value_all + item.range_value_all * a2;
|
|
|
|
|
+ item.value_lclx = item.mean_value_all - item.range_value_all * a2;
|
|
|
|
|
+ item.value_uclr = item.range_value_all * d4;
|
|
|
|
|
+ item.value_lclr = item.range_value_all * d3;
|
|
|
|
|
+ }
|
|
|
|
|
+ _sqe_cto_test_avg.Update(test_avgs);
|
|
|
|
|
+ _sqe_cto_test_statistics.Update(model);
|
|
|
|
|
+ return stringBuilder.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 计算A2系数
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="sample_count"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public double GetA2(int sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ return 2.659574468;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ return 1.88;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ return 1.023;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ return 0.729;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ return 0.577;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public double GetD2(int sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ return 1.128;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ return 1.128;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ return 1.693;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ return 2.059;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ return 2.326;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public double GetD4(int sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ return 3.267;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ return 3.267;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ return 2.574;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ return 2.282;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ return 2.114;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public double GetD3(int sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ //switch (sample_count)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // case 1:
|
|
|
|
|
+ // return 1.128;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case 2:
|
|
|
|
|
+ // return 1.128;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case 3:
|
|
|
|
|
+ // return 1.693;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case 4:
|
|
|
|
|
+ // return 2.059;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case 5:
|
|
|
|
|
+ // return 2.326;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ //}
|
|
|
|
|
+ //return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public string Compute_Test(string startDate, string endDate, string item_no, string item_batch, string org, string standard_no, int sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ #region 查询条件
|
|
|
|
|
+ // 动态条件
|
|
|
|
|
+ var conditions = new List<Expression<Func<v_sqe_cto_test_data, bool>>>();
|
|
|
|
|
+ conditions.Add(p => p.data_value != null);
|
|
|
|
|
+ if (!string.IsNullOrEmpty(startDate))
|
|
|
|
|
+ {
|
|
|
|
|
+ DateTime dateTime;
|
|
|
|
|
+ if (DateTime.TryParse(startDate, out dateTime))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_date >= dateTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(endDate))
|
|
|
|
|
+ {
|
|
|
|
|
+ DateTime dateTime;
|
|
|
|
|
+ if (DateTime.TryParse(endDate, out dateTime))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_date <= dateTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(item_no))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.item_no == item_no);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(item_batch))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.item_batch == item_batch);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(org))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_org == org);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(standard_no))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.standard_no == standard_no);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 组合条件
|
|
|
|
|
+ var combinedCondition = PredicateBuilder.New<v_sqe_cto_test_data>();
|
|
|
|
|
+ foreach (var condition in conditions)
|
|
|
|
|
+ {
|
|
|
|
|
+ combinedCondition = combinedCondition.And(condition);
|
|
|
|
|
+ }
|
|
|
|
|
+ var query = _v_sqe_cto_test_data.GetDbContext().v_sqe_cto_test_data.AsQueryable();
|
|
|
|
|
+
|
|
|
|
|
+ // 应用条件
|
|
|
|
|
+ if (combinedCondition.Body != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ query = query.Where(combinedCondition);
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion 查询条件
|
|
|
|
|
+
|
|
|
|
|
+ // 执行查询
|
|
|
|
|
+ List<v_sqe_cto_test_data> test_datas = query.ToList();
|
|
|
|
|
+
|
|
|
|
|
+ //int sample_count = test_datas != null && test_datas.Count > 0 ? test_datas[0].sampling_count : -1;
|
|
|
|
|
+ //if (sample_count == -1)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
|
|
|
|
|
+ // return JsonConvert.SerializeObject(resultError);
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ double[] data = new double[sample_count];
|
|
|
|
|
+ double[] dataAll = new double[test_datas.Count / sample_count * sample_count];
|
|
|
|
|
+ double[] dataRange = new double[test_datas.Count / sample_count];
|
|
|
|
|
+ for (int i = 0; i <= test_datas.Count - sample_count; i += sample_count)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int j = 0; j < sample_count; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ data[j] = (double)test_datas[i + j].data_value.Value;
|
|
|
|
|
+ dataAll[i + j] = data[j];
|
|
|
|
|
+ }
|
|
|
|
|
+ dataRange[i / sample_count] = data.Max() - data.Min();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ decimal a2 = (decimal)GetA2(sample_count);
|
|
|
|
|
+ decimal d2 = (decimal)GetD2(sample_count);
|
|
|
|
|
+ decimal d3 = (decimal)GetD3(sample_count);
|
|
|
|
|
+ decimal d4 = (decimal)GetD4(sample_count);
|
|
|
|
|
+
|
|
|
|
|
+ //开始计算统计结果
|
|
|
|
|
+ sqe_cto_test_statistics model = new sqe_cto_test_statistics();
|
|
|
|
|
+ model.standard_no = standard_no;
|
|
|
|
|
+ model.value_count = test_datas.Count;
|
|
|
|
|
+ model.standard_min = test_datas[0].standard_min;
|
|
|
|
|
+ model.standard_max = test_datas[0].standard_max;
|
|
|
|
|
+ model.standard_value = (model.standard_min + model.standard_max) / 2;
|
|
|
|
|
+ model.value_sum = (decimal)dataAll.Sum();
|
|
|
|
|
+ model.value_avg = (decimal)dataAll.Average();
|
|
|
|
|
+ model.value_max = (decimal)dataAll.Max();
|
|
|
|
|
+ model.value_min = (decimal)dataAll.Min();
|
|
|
|
|
+ model.value_below = dataAll.Count(x => x < (double)model.standard_min);
|
|
|
|
|
+ model.value_above = dataAll.Count(x => x > (double)model.standard_max);
|
|
|
|
|
+ model.avg_range = (decimal)dataRange.Average();
|
|
|
|
|
+ model.value_d2 = d2;
|
|
|
|
|
+ model.value_cpu = (model.standard_max - model.value_avg) / (3 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cpl = (model.value_avg - model.standard_min) / (3 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cp = (model.standard_max - model.standard_min) / (6 * model.avg_range / model.value_d2);
|
|
|
|
|
+ model.value_cpk = model.value_cpu < model.value_cpl ? model.value_cpu : model.value_cpl;
|
|
|
|
|
+ model.value_cr = (decimal)1.0 / model.value_cp;
|
|
|
|
|
+ model.value_stdev = (decimal)dataAll.StandardDeviation();
|
|
|
|
|
+ model.value_stdevp = (decimal)dataAll.PopulationStandardDeviation();
|
|
|
|
|
+ model.value_var = (decimal)dataAll.Variance();
|
|
|
|
|
+ model.value_varp = (decimal)dataAll.PopulationVariance();
|
|
|
|
|
+ model.value_pp = (model.standard_max - model.standard_min) / (6 * model.value_stdev);
|
|
|
|
|
+ model.value_ppu = (model.standard_max - model.value_avg) / (3 * model.value_stdev);
|
|
|
|
|
+ model.value_ppl = (model.value_avg - model.standard_min) / (3 * model.value_stdev);
|
|
|
|
|
+ model.value_ppk = model.value_ppu < model.value_ppl ? model.value_ppu : model.value_ppl;
|
|
|
|
|
+
|
|
|
|
|
+ ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, model, ResultCode.Success, null);
|
|
|
|
|
+ return JsonConvert.SerializeObject(result);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
|
|
|
|
|
+ return JsonConvert.SerializeObject(resultError);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 依据查询条件,统计工序的不良情况
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="startDate"></param>
|
|
|
|
|
+ /// <param name="endDate"></param>
|
|
|
|
|
+ /// <param name="item_no"></param>
|
|
|
|
|
+ /// <param name="item_batch"></param>
|
|
|
|
|
+ /// <param name="org"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public string Compute_op_query(string startDate, string endDate, string item_no, string item_batch, string org)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ #region 查询条件
|
|
|
|
|
+ // 动态条件
|
|
|
|
|
+ var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
|
|
|
|
|
+ if (!string.IsNullOrEmpty(startDate))
|
|
|
|
|
+ {
|
|
|
|
|
+ DateTime dateTime;
|
|
|
|
|
+ if (DateTime.TryParse(startDate, out dateTime))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_date >= dateTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(endDate))
|
|
|
|
|
+ {
|
|
|
|
|
+ DateTime dateTime;
|
|
|
|
|
+ if (DateTime.TryParse(endDate, out dateTime))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_date <= dateTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(item_no))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.item_no == item_no);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(item_batch))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.batch_no == item_batch);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(org))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 添加条件1:Name 包含 "searchTerm"
|
|
|
|
|
+ conditions.Add(p => p.create_org == org);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 组合条件
|
|
|
|
|
+ var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
|
|
|
|
|
+ //此处是所有的条件都and。
|
|
|
|
|
+ foreach (var condition in conditions)
|
|
|
|
|
+ {
|
|
|
|
|
+ combinedCondition = combinedCondition.And(condition);
|
|
|
|
|
+ }
|
|
|
|
|
+ var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
|
|
|
|
|
+
|
|
|
|
|
+ // 应用条件
|
|
|
|
|
+ if (conditions.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ query = query.Where(combinedCondition);
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion 查询条件
|
|
|
|
|
+
|
|
|
|
|
+ // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
|
|
|
|
|
+ var groupBy = query.GroupBy(p => new { p.bad_type, p.op_no })
|
|
|
|
|
+ .Select(g => new
|
|
|
|
|
+ {
|
|
|
|
|
+ bad_type = g.Key.bad_type,
|
|
|
|
|
+ op_no = g.Key.op_no,
|
|
|
|
|
+ bad_qty = g.Sum(p => p.bad_qty)
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //增加排序条件,此处多个条件,op_no,bad_type
|
|
|
|
|
+ var test_datas = groupBy.OrderBy(p => p.op_no).ThenBy(p => p.bad_type).ToList();
|
|
|
|
|
+ ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, test_datas, ResultCode.Success, null);
|
|
|
|
|
+ return JsonConvert.SerializeObject(result);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
|
|
|
|
|
+ return JsonConvert.SerializeObject(resultError);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|