2024-01-29 16:55:45 +08:00
using AutoMapper.Configuration.Conventions ;
using Infrastructure.Attribute ;
using Microsoft.AspNetCore.Http ;
2023-12-01 15:39:07 +08:00
using Microsoft.Extensions.DependencyInjection ;
2023-12-18 16:01:17 +08:00
using SqlSugar ;
2023-12-01 15:39:07 +08:00
using System ;
2023-12-12 22:26:20 +08:00
using System.Collections ;
2023-12-01 15:39:07 +08:00
using System.Collections.Generic ;
using System.Diagnostics ;
2024-01-26 16:59:00 +08:00
using System.Drawing ;
2023-12-01 15:39:07 +08:00
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2024-01-29 16:55:45 +08:00
using ZR.Common ;
using ZR.Model.mes.pro ;
2024-01-26 16:59:00 +08:00
using ZR.Model.MES.pro ;
2023-12-12 22:26:20 +08:00
using ZR.Model.MES.qc ;
2023-12-01 15:39:07 +08:00
using ZR.Model.MES.qc.DTO ;
using ZR.Model.MES.qu ;
using ZR.Service.mes.qc.IService ;
using ZR.Service.mes.qu.IService ;
2023-12-18 16:01:17 +08:00
using static Microsoft . Extensions . Logging . EventSource . LoggingEventSource ;
2024-01-31 17:51:45 +08:00
using static System . Runtime . InteropServices . JavaScript . JSType ;
2023-12-01 15:39:07 +08:00
namespace ZR.Service.mes.qc
{
[AppService(ServiceType = typeof(IFirstFQCService), ServiceLifetime = LifeTime.Transient)]
public class FirstFQCService : BaseService < QcInspectionitem > , IFirstFQCService
{
2024-01-29 16:55:45 +08:00
/// <summary>
/// 获取检测项 (首检)
/// </summary>
/// <param name="workorderID"></param>
/// <returns></returns>
public CheckItemTableDTO GetCheckItemTable_first ( string workorderID )
2023-12-01 15:39:07 +08:00
{
2023-12-12 22:26:20 +08:00
CheckItemTableDTO checkItem = new CheckItemTableDTO ( ) ;
checkItem . Paint = Queryable ( ) . Where ( it = > it . InspectionModule = = "油漆" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-29 16:55:45 +08:00
checkItem . Paint . ForEach ( item = >
{
QcFirstinspectionRecord record = Context . Queryable < QcFirstinspectionRecord > ( )
. Where ( it = > it . FKWorkorderId = = workorderID & & it . FKInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
if ( record ! = null )
{
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
}
} ) ;
2023-12-01 15:39:07 +08:00
checkItem . device = Queryable ( ) . Where ( it = > it . InspectionModule = = "设备" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . device . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
QcFirstinspectionRecord record = Context . Queryable < QcFirstinspectionRecord > ( )
2024-01-31 17:51:45 +08:00
. Where ( it = > it . FKWorkorderId = = workorderID & & it . FKInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
2023-12-01 15:39:07 +08:00
checkItem . Blank = Queryable ( ) . Where ( it = > it . InspectionModule = = "毛坯" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Blank . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
QcFirstinspectionRecord record = Context . Queryable < QcFirstinspectionRecord > ( )
2024-01-31 17:51:45 +08:00
. Where ( it = > it . FKWorkorderId = = workorderID & & it . FKInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . program = Queryable ( ) . Where ( it = > it . InspectionModule = = "程序" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . program . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
QcFirstinspectionRecord record = Context . Queryable < QcFirstinspectionRecord > ( )
2024-01-31 17:51:45 +08:00
. Where ( it = > it . FKWorkorderId = = workorderID & & it . FKInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . Team = Queryable ( ) . Where ( it = > it . InspectionModule = = "班组操作" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Team . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
QcFirstinspectionRecord record = Context . Queryable < QcFirstinspectionRecord > ( )
2024-01-31 17:51:45 +08:00
. Where ( it = > it . FKWorkorderId = = workorderID & & it . FKInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
return checkItem ;
}
/// <summary>
/// 获取检测项 (二检)
/// </summary>
/// <param name="workorderID"></param>
/// <returns></returns>
public CheckItemTableDTO GetCheckItemTable_again ( string workorderID )
{
CheckItemTableDTO checkItem = new CheckItemTableDTO ( ) ;
checkItem . Paint = Queryable ( ) . Where ( it = > it . InspectionModule = = "油漆" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
checkItem . Paint . ForEach ( item = >
{
QcAgaininspectionRecord record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
if ( record ! = null )
{
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
}
} ) ;
checkItem . device = Queryable ( ) . Where ( it = > it . InspectionModule = = "设备" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . device . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcAgaininspectionRecord record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . Blank = Queryable ( ) . Where ( it = > it . InspectionModule = = "毛坯" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Blank . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcAgaininspectionRecord record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . program = Queryable ( ) . Where ( it = > it . InspectionModule = = "程序" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . program . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcAgaininspectionRecord record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . Team = Queryable ( ) . Where ( it = > it . InspectionModule = = "班组操作" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Team . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcAgaininspectionRecord record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
return checkItem ;
}
/// <summary>
/// 获取检测项 (三检)
/// </summary>
/// <param name="workorderID"></param>
/// <returns></returns>
public CheckItemTableDTO GetCheckItemTable_thirty ( string workorderID )
{
CheckItemTableDTO checkItem = new CheckItemTableDTO ( ) ;
checkItem . Paint = Queryable ( ) . Where ( it = > it . InspectionModule = = "油漆" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
checkItem . Paint . ForEach ( item = >
{
QcFinalinspectionRecord record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
if ( record ! = null )
{
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
}
} ) ;
checkItem . device = Queryable ( ) . Where ( it = > it . InspectionModule = = "设备" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . device . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcFinalinspectionRecord record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
checkItem . Blank = Queryable ( ) . Where ( it = > it . InspectionModule = = "毛坯" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Blank . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcFinalinspectionRecord record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
2023-12-01 15:39:07 +08:00
checkItem . program = Queryable ( ) . Where ( it = > it . InspectionModule = = "程序" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . program . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcFinalinspectionRecord record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
2023-12-01 15:39:07 +08:00
checkItem . Team = Queryable ( ) . Where ( it = > it . InspectionModule = = "班组操作" ) . OrderBy ( it = > it . Id ) . ToList ( ) ;
2024-01-31 17:51:45 +08:00
checkItem . Team . ForEach ( item = >
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
QcFinalinspectionRecord record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorderID & & it . FkInpectionId = = item . Id . ToString ( ) ) . First ( ) ;
2024-01-29 16:55:45 +08:00
if ( record ! = null )
{
2024-01-31 17:51:45 +08:00
item . Counter = record . Counter ;
}
else
{
item . Counter = 0 ;
2024-01-29 16:55:45 +08:00
}
} ) ;
2023-12-01 15:39:07 +08:00
return checkItem ;
}
2023-12-12 22:26:20 +08:00
2024-01-29 16:55:45 +08:00
2023-12-12 22:26:20 +08:00
/// <summary>
2023-12-18 16:01:17 +08:00
/// 保存首次检测结果
2023-12-12 22:26:20 +08:00
/// </summary>
2023-12-18 16:01:17 +08:00
/// <param name="workorder_id">工单</param>
/// <param name="InspectionModule">模块</param>
/// <param name="inspectItem">检测项</param>
/// <param name="counter">数量</param>
2023-12-12 22:26:20 +08:00
/// <returns></returns>
2023-12-18 16:01:17 +08:00
public async Task SaveinspectItem_v1 ( string workorder_id , string InspectionModule , string checkid , int counter )
2023-12-12 22:26:20 +08:00
{
2024-01-29 16:55:45 +08:00
2023-12-12 22:26:20 +08:00
//更新实时记录表
QcFirstinspectionRecord record = new QcFirstinspectionRecord ( ) ;
2024-01-26 16:59:00 +08:00
record . Id = DateTime . Now . ToString ( "YYMMddHHmmss" ) ;
2023-12-12 22:26:20 +08:00
record . InspectionModule = InspectionModule ;
record . FKWorkorderId = workorder_id ;
2023-12-18 16:01:17 +08:00
record . FKInpectionId = checkid . Substring ( 0 , 3 ) ;
record . Counter = counter ;
record . UpdatedTime = DateTime . Now ;
var x = Context . Storageable ( record )
. WhereColumns ( it = > new { it . FKInpectionId , it . FKWorkorderId , it . InspectionModule } )
. ToStorage ( ) ;
x . AsInsertable . ExecuteCommandAsync ( ) ; //执行插入
x . AsUpdateable . ExecuteCommandAsync ( ) ; //执行更新
////更新初检报废表
//if (Convert.ToInt32(checkid) / 10 % 10==3)
//{
// QcAgaininspectionUselessnum scrap =new QcAgaininspectionUselessnum();
// scrap.Id = "scrap" + DateTime.Now.ToString("MMddHHmmss");
// scrap.FkInspectionitemId = checkid;
// scrap.FkFqcId = "";
// scrap.ProductName = "";
// scrap.Number= 1;
//}
////更新初检xiazi表
//if (Convert.ToInt32(checkid) / 10 % 10 == 1)
//{
//}
}
/// <summary>
/// 保存二次检测结果
/// </summary>
/// <param name="workorder_id">工单</param>
/// <param name="InspectionModule">模块</param>
/// <param name="inspectItem">检测项</param>
/// <param name="counter">数量</param>
/// <returns></returns>
public async Task SaveinspectItem_v2 ( string workorder_id , string InspectionModule , string checkid , int counter )
{
//更新实时记录表
QcAgaininspectionRecord record = new QcAgaininspectionRecord ( ) ;
2024-01-26 16:59:00 +08:00
record . Id = DateTime . Now . ToString ( "YYMMddHHmmss" ) ;
2023-12-18 16:01:17 +08:00
record . InspectionModule = InspectionModule ;
record . FkWorkorderId = workorder_id ;
record . FkInpectionId = checkid . Substring ( 0 , 3 ) ;
record . Counter = counter ;
record . UpdatedTime = DateTime . Now ;
var x = Context . Storageable ( record )
. WhereColumns ( it = > new { it . FkInpectionId , it . FkWorkorderId , it . InspectionModule } )
. ToStorage ( ) ;
x . AsInsertable . ExecuteCommandAsync ( ) ; //执行插入
x . AsUpdateable . ExecuteCommandAsync ( ) ; //执行更新
////更新初检报废表
//if (Convert.ToInt32(checkid) / 10 % 10==3)
//{
// QcAgaininspectionUselessnum scrap =new QcAgaininspectionUselessnum();
// scrap.Id = "scrap" + DateTime.Now.ToString("MMddHHmmss");
// scrap.FkInspectionitemId = checkid;
// scrap.FkFqcId = "";
// scrap.ProductName = "";
// scrap.Number= 1;
//}
////更新初检xiazi表
//if (Convert.ToInt32(checkid) / 10 % 10 == 1)
//{
//}
}
/// <summary>
/// 保存最终检测结果
/// </summary>
/// <param name="workorder_id">工单</param>
/// <param name="InspectionModule">模块</param>
/// <param name="inspectItem">检测项</param>
/// <param name="counter">数量</param>
/// <returns></returns>
public async Task SaveinspectItem_v3 ( string workorder_id , string InspectionModule , string checkid , int counter )
{
//更新实时记录表
QcFinalinspectionRecord record = new QcFinalinspectionRecord ( ) ;
2024-01-26 16:59:00 +08:00
record . Id = DateTime . Now . ToString ( "YYMMddHHmmss" ) ;
2023-12-18 16:01:17 +08:00
record . InspectionModule = InspectionModule ;
record . FkWorkorderId = workorder_id ;
record . FkInpectionId = checkid . Substring ( 0 , 3 ) ;
2023-12-12 22:26:20 +08:00
record . Counter = counter ;
2023-12-18 16:01:17 +08:00
record . UpdatedTime = DateTime . Now ;
2023-12-12 22:26:20 +08:00
var x = Context . Storageable ( record )
2023-12-18 16:01:17 +08:00
. WhereColumns ( it = > new { it . FkInpectionId , it . FkWorkorderId , it . InspectionModule } )
2023-12-12 22:26:20 +08:00
. ToStorage ( ) ;
2023-12-18 16:01:17 +08:00
x . AsInsertable . ExecuteCommandAsync ( ) ; //执行插入
2024-01-29 16:55:45 +08:00
x . AsUpdateable . UpdateColumns ( it = > new { it . UpdatedBy , it . UpdatedTime , it . Counter } ) . ExecuteCommandAsync ( ) ; //执行更新
2023-12-12 22:26:20 +08:00
////更新初检报废表
//if (Convert.ToInt32(checkid) / 10 % 10==3)
//{
// QcAgaininspectionUselessnum scrap =new QcAgaininspectionUselessnum();
// scrap.Id = "scrap" + DateTime.Now.ToString("MMddHHmmss");
// scrap.FkInspectionitemId = checkid;
// scrap.FkFqcId = "";
// scrap.ProductName = "";
// scrap.Number= 1;
//}
////更新初检xiazi表
//if (Convert.ToInt32(checkid) / 10 % 10 == 1)
//{
//}
}
2023-12-18 16:01:17 +08:00
/// <summary>
/// 当产品切换时,完成质量统计分析
/// </summary>
/// <param name="workorderid">工单</param>
/// <param name="productName">产品名称</param>
/// <param name="leftRight">左右</param>
/// <param name="color">颜色</param>
/// <param name="team">班组</param>
/// <param name="inputNum">投入数</param>
public void quailtyStatics ( string workorderid , string productName , string leftRight , string color , string team , int inputNum )
{
QcFqc record = new QcFqc ( ) ;
record . Id = DateTime . Now . ToString ( "MMddHHmmss" ) ;
record . ProductName = productName ;
record . LeftRight = leftRight ;
record . Color = color ;
record . Team = team ;
//TODO 1. 处理首检
//1.1 首检合格数=投入数-抛光数-打磨数-报废数
List < QcFirstinspectionRecord > qcFirstinspections = Context . Queryable < QcFirstinspectionRecord > ( ) . Where ( it = > it . FKWorkorderId = = workorderid ) . ToList ( ) ;
int NoQualifiedNum01 = 0 ;
qcFirstinspections . ForEach ( it = >
{
NoQualifiedNum01 + = ( int ) it . Counter ;
} ) ;
record . QualifiedNum01 = inputNum - NoQualifiedNum01 ;
//1.2 首检抛光数
List < QcFirstinspectionRecord > defectNum01RecordList = Context . Queryable < QcFirstinspectionRecord > ( ) . Where ( it = > it . FKWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 1 + "_" } ) . ToList ( ) ;
int defectNum01RecordSum = 0 ;
defectNum01RecordList . ForEach ( it = >
{
defectNum01RecordSum + = ( int ) it . Counter ;
} ) ;
record . DefectNum01 = defectNum01RecordSum ;
//1.3 首检打磨数
List < QcFirstinspectionRecord > polishNum01RecordList = Context . Queryable < QcFirstinspectionRecord > ( ) . Where ( it = > it . FKWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 2 + "_" } ) . ToList ( ) ;
int polishNum01RecordSum = 0 ;
polishNum01RecordList . ForEach ( it = >
{
polishNum01RecordSum + = ( int ) it . Counter ;
} ) ;
record . PolishNum01 = polishNum01RecordSum ;
2023-12-12 22:26:20 +08:00
2023-12-18 16:01:17 +08:00
//1.4 首检报废数
List < QcFirstinspectionRecord > scrapNum01RecordList = Context . Queryable < QcFirstinspectionRecord > ( ) . Where ( it = > it . FKWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 3 + "_" } ) . ToList ( ) ;
int scrapNum01RecordSum = 0 ;
scrapNum01RecordList . ForEach ( it = >
{
scrapNum01RecordSum + = ( int ) it . Counter ;
} ) ;
record . PolishNum01 = scrapNum01RecordSum ;
2023-12-12 22:26:20 +08:00
2023-12-18 16:01:17 +08:00
//TODO 2. 处理二检
//2.1 二检的合格数 = 首检的抛光数 - 二检打磨 - 二检报废
List < QcAgaininspectionRecord > qcAgaininspections = Context . Queryable < QcAgaininspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . ToList ( ) ;
int NoQualifiedNum02 = 0 ;
qcAgaininspections . ForEach ( it = >
{
NoQualifiedNum02 + = ( int ) it . Counter ;
} ) ;
record . QualifiedNum02 = defectNum01RecordSum - NoQualifiedNum02 ;
//2.2 二检打磨数
List < QcAgaininspectionRecord > polishNum02RecordList = Context . Queryable < QcAgaininspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 2 + "_" } ) . ToList ( ) ;
int polishNum02RecordSum = 0 ;
polishNum02RecordList . ForEach ( it = >
{
polishNum02RecordSum + = ( int ) it . Counter ;
} ) ;
record . PolishNum02 = polishNum02RecordSum ;
//2.3 二检报废
List < QcAgaininspectionRecord > scrapNum02RecordList = Context . Queryable < QcAgaininspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 3 + "_" } ) . ToList ( ) ;
int scrapNum02RecordSum = 0 ;
scrapNum02RecordList . ForEach ( it = >
{
scrapNum02RecordSum + = ( int ) it . Counter ;
} ) ;
record . ScrapNum02 = scrapNum02RecordSum ;
//TODO 3. 处理三检
// 3.1 三检合格数=(一检合格数 + 二检合格数) - (三检打磨数+三检报废数)
List < QcFinalinspectionRecord > qcFinalinspections = Context . Queryable < QcFinalinspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . ToList ( ) ;
int NoQualifiedNum03 = 0 ;
qcAgaininspections . ForEach ( it = >
{
NoQualifiedNum03 + = ( int ) it . Counter ;
} ) ;
record . QualifiedNum03 = ( record . QualifiedNum01 + record . QualifiedNum02 ) - NoQualifiedNum03 ;
//3.2 三检打磨数
List < QcFinalinspectionRecord > polishNum03RecordList = Context . Queryable < QcFinalinspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 2 + "_" } ) . ToList ( ) ;
int polishNum03RecordSum = 0 ;
polishNum03RecordList . ForEach ( it = >
{
polishNum03RecordSum + = ( int ) it . Counter ;
} ) ;
record . PolishNum03 = polishNum03RecordSum ;
//3.3 三检报废数
List < QcFinalinspectionRecord > scrapNum03RecordList = Context . Queryable < QcFinalinspectionRecord > ( ) . Where ( it = > it . FkWorkorderId = = workorderid ) . Where ( "FKInpectionId like @FKInpectionId" , new { FKInpectionId = "_" + 3 + "_" } ) . ToList ( ) ;
int scrapNum03RecordSum = 0 ;
scrapNum03RecordList . ForEach ( it = >
{
scrapNum03RecordSum + = ( int ) it . Counter ;
} ) ;
record . ScrapNum03 = scrapNum03RecordSum ;
//TODO 4 统计分析
// 4.1 一次合格率
record . FirstgoodNum = record . QualifiedNum01 ;
record . FirstgoodRate = CalculatePercentage ( ( int ) record . FirstgoodNum , inputNum ) ;
// 4.2 最终合格率
record . FinalgoodNum = record . QualifiedNum03 / inputNum ;
record . FinalgoodRate = CalculatePercentage ( ( int ) record . FinalgoodNum , inputNum ) ;
// 4.3 报废率
record . ScrapNum = record . ScrapNum01 + record . ScrapNum02 + record . ScrapNum03 ;
record . ScrapRate = CalculatePercentage ( ( int ) record . ScrapNum , inputNum ) ;
record . CreatedTime = DateTime . Now ;
Context . Insertable < QcFqc > ( record ) . ExecuteCommand ( ) ;
}
/// <summary>
/// 计算百分比
/// </summary>
/// <param name="num1"></param>
/// <param name="num2"></param>
/// <returns></returns>
static double CalculatePercentage ( int num1 , int num2 )
{
double percentage = ( ( double ) num1 / num2 ) * 100 ;
return Math . Round ( percentage , 2 ) ;
}
2024-01-26 16:59:00 +08:00
2024-01-31 17:51:45 +08:00
public static QcCurrentWorkorderDto Now_producting_Workorder_first = null ; //当前生产工单 首检
public static QcCurrentWorkorderDto Now_producting_Workorder_again = null ; //当前生产工单 二检
public static QcCurrentWorkorderDto Now_producting_Workorder_thirty = null ; //当前生产工单 三检
2024-01-26 16:59:00 +08:00
/// <summary>
/// 获取当前_生产中_工单列表
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
2024-01-29 16:55:45 +08:00
public List < QcCurrentWorkorderDto > GetNow_producting_WorkorderList ( )
2024-01-26 16:59:00 +08:00
{
2024-01-29 16:55:45 +08:00
List < ProWorkorder_v2 > workorders = Context . Queryable < ProWorkorder_v2 > ( ) . Where ( it = > it . Remark3 = = "是" ) . Where ( it = > it . Status = = 1 ) . OrderBy ( it = > it . Sort ) . ToList ( ) ;
List < QcCurrentWorkorderDto > qcCurrentList = new List < QcCurrentWorkorderDto > ( ) ;
foreach ( ProWorkorder_v2 item in workorders )
2024-01-26 16:59:00 +08:00
{
qcCurrentList . Add ( new QcCurrentWorkorderDto ( )
{
ClientWorkorder = item . ClientWorkorder ,
ProductDescription = item . ProductDescription ,
FinishedPartNumber = item . FinishedPartNumber ,
Specifications = item . Specifications ,
Colour = item . Colour ,
2024-02-04 16:07:27 +08:00
Team = "A" ,
2024-01-29 16:55:45 +08:00
PreviousNumber = item . PreviousNumber ,
FirstPassNumber = 0 ,
FirstPassRate = 0.0 ,
PolisheNumber = 0 ,
2024-01-26 16:59:00 +08:00
ScrapNumber = 0 ,
DefectNumber = 0
} ) ;
2024-01-29 16:55:45 +08:00
;
2024-01-26 16:59:00 +08:00
}
return qcCurrentList ;
}
/// <summary>
2024-01-31 17:51:45 +08:00
/// 获取当前生产工单 一检
2024-01-26 16:59:00 +08:00
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
2024-01-31 17:51:45 +08:00
public QcCurrentWorkorderDto GetcurrentWorkorder_first ( )
2024-01-26 16:59:00 +08:00
{
//获取状态为1的生产工单列表
2024-01-29 16:55:45 +08:00
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
2024-01-26 16:59:00 +08:00
// 当前没有生产工单
2024-01-29 16:55:45 +08:00
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
2024-01-26 16:59:00 +08:00
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = null ;
2024-01-26 16:59:00 +08:00
return null ;
}
2024-01-31 17:51:45 +08:00
else if ( Now_producting_Workorder_first = = null )
2024-01-26 16:59:00 +08:00
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = Now_producting_WorkorderList [ 0 ] ;
return Now_producting_Workorder_first ;
2024-01-26 16:59:00 +08:00
}
else
{
2024-01-31 17:51:45 +08:00
return Now_producting_Workorder_first ;
}
}
/// <summary>
/// 获取当前生产工单 二检
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_again ( )
{
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_again = null ;
return null ;
}
else if ( Now_producting_Workorder_again = = null )
{
Now_producting_Workorder_again = Now_producting_WorkorderList [ 0 ] ;
return Now_producting_Workorder_again ;
}
else
{
return Now_producting_Workorder_again ;
2024-01-26 16:59:00 +08:00
}
2024-01-29 16:55:45 +08:00
2024-01-26 16:59:00 +08:00
}
2024-01-29 16:55:45 +08:00
2024-01-26 16:59:00 +08:00
/// <summary>
2024-01-31 17:51:45 +08:00
/// 获取当前生产工单 三检
2024-01-26 16:59:00 +08:00
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
2024-01-31 17:51:45 +08:00
public QcCurrentWorkorderDto GetcurrentWorkorder_thirty ( )
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_thirty = null ;
return null ;
}
else if ( Now_producting_Workorder_thirty = = null )
{
Now_producting_Workorder_thirty = Now_producting_WorkorderList [ 0 ] ;
return Now_producting_Workorder_thirty ;
}
else
{
return Now_producting_Workorder_thirty ;
}
}
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
/// <summary>
/// 获取下一个生产工单 一检
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_next_first ( )
{
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
2024-01-29 16:55:45 +08:00
2024-01-26 16:59:00 +08:00
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = null ;
2024-01-26 16:59:00 +08:00
return null ;
}
else
{
// 当前没有生产工单
2024-01-31 17:51:45 +08:00
if ( Now_producting_Workorder_first = = null )
2024-01-26 16:59:00 +08:00
{
return null ;
}
//获取上一个工单号 游标
2024-01-31 17:51:45 +08:00
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_first . ClientWorkorder ) ;
2024-01-26 16:59:00 +08:00
if ( index < 0 )
{
// 逻辑异常
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = Now_producting_WorkorderList [ 0 ] ;
2024-01-26 16:59:00 +08:00
return null ;
}
2024-01-29 16:55:45 +08:00
if ( index = = Now_producting_WorkorderList . Count ( ) - 1 )
2024-01-26 16:59:00 +08:00
{
// 已经是最后一个了没有
2024-01-29 16:55:45 +08:00
2024-01-26 16:59:00 +08:00
return null ;
}
else
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = Now_producting_WorkorderList [ index + 1 ] ;
return Now_producting_Workorder_first ;
2024-01-26 16:59:00 +08:00
}
2024-01-29 16:55:45 +08:00
}
}
2024-01-31 17:51:45 +08:00
/// <summary>
/// 获取下一个生产工单 二检
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_next_again ( )
{
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_again = null ;
return null ;
}
else
{
// 当前没有生产工单
if ( Now_producting_Workorder_again = = null )
{
return null ;
}
//获取上一个工单号 游标
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_again . ClientWorkorder ) ;
if ( index < 0 )
{
// 逻辑异常
Now_producting_Workorder_again = Now_producting_WorkorderList [ 0 ] ;
return null ;
}
if ( index = = Now_producting_WorkorderList . Count ( ) - 1 )
{
// 已经是最后一个了没有
return null ;
}
else
{
Now_producting_Workorder_again = Now_producting_WorkorderList [ index + 1 ] ;
return Now_producting_Workorder_again ;
}
}
}
/// <summary>
/// 获取下一个生产工单 三检
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_next_thirty ( )
{
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_thirty = null ;
return null ;
}
else
{
// 当前没有生产工单
if ( Now_producting_Workorder_thirty = = null )
{
return null ;
}
//获取上一个工单号 游标
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_thirty . ClientWorkorder ) ;
if ( index < 0 )
{
// 逻辑异常
Now_producting_Workorder_thirty = Now_producting_WorkorderList [ 0 ] ;
return null ;
}
if ( index = = Now_producting_WorkorderList . Count ( ) - 1 )
{
// 已经是最后一个了没有
return null ;
}
else
{
Now_producting_Workorder_thirty = Now_producting_WorkorderList [ index + 1 ] ;
return Now_producting_Workorder_thirty ;
}
}
}
2024-01-29 16:55:45 +08:00
/// <summary>
/// 记录检测项结果
/// </summary>
/// <param name="workorder_id">工单</param>
/// <param name="inspectionList">检测结果</param>
private void Record_inspect_result ( string workorder_id , List < QcInspectionitem > inspectionList , string createBy )
{
if ( inspectionList ! = null & & inspectionList . Count > 0 )
{
foreach ( var item in inspectionList )
{
QcFirstinspectionRecord record = new QcFirstinspectionRecord ( ) ;
record . Id = DateTime . Now . ToString ( "yyMMddHHmmss" ) + inspectionList . IndexOf ( item ) ;
record . FKWorkorderId = workorder_id ;
record . FKInpectionId = item . Id . ToString ( ) ;
record . InspectionModule = item . InspectionModule ;
record . Counter = item . Counter ;
record . CreatedBy = createBy ;
//Context.Storageable<QcInspectionitem>()
}
2024-01-26 16:59:00 +08:00
}
2024-01-29 16:55:45 +08:00
2024-01-26 16:59:00 +08:00
}
2024-01-31 17:51:45 +08:00
2024-01-26 16:59:00 +08:00
/// <summary>
2024-01-31 17:51:45 +08:00
/// 获取上一个工单 首检
2024-01-26 16:59:00 +08:00
/// </summary>
/// <returns></returns>
2024-01-31 17:51:45 +08:00
/// <exception cref=""></exception>
2024-01-26 16:59:00 +08:00
2024-01-31 17:51:45 +08:00
public QcCurrentWorkorderDto GetcurrentWorkorder_previous_first ( )
2024-01-26 16:59:00 +08:00
{
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = null ;
2024-01-26 16:59:00 +08:00
return null ;
}
else
{
// 当前没有生产工单
2024-01-31 17:51:45 +08:00
if ( Now_producting_Workorder_first = = null )
2024-01-26 16:59:00 +08:00
{
return null ;
}
//获取上一个工单号 游标
2024-01-31 17:51:45 +08:00
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_first . ClientWorkorder ) ;
2024-01-26 16:59:00 +08:00
if ( index < 0 )
{
// 逻辑异常
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = Now_producting_WorkorderList [ 0 ] ;
2024-01-26 16:59:00 +08:00
return null ;
}
if ( index = = 0 )
{
// 已经是最后一个了没有
return null ;
}
else
{
2024-01-31 17:51:45 +08:00
Now_producting_Workorder_first = Now_producting_WorkorderList [ index - 1 ] ;
return Now_producting_Workorder_first ;
2024-01-26 16:59:00 +08:00
}
}
}
2024-01-31 17:51:45 +08:00
2024-01-29 16:55:45 +08:00
/// <summary>
2024-01-31 17:51:45 +08:00
/// 获取上一个工单 二检
2024-01-29 16:55:45 +08:00
/// </summary>
/// <returns></returns>
2024-01-31 17:51:45 +08:00
/// <exception cref=""></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_previous_again ( )
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_again = null ;
return null ;
}
else
{
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
// 当前没有生产工单
if ( Now_producting_Workorder_again = = null )
{
return null ;
}
//获取上一个工单号 游标
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_again . ClientWorkorder ) ;
if ( index < 0 )
{
// 逻辑异常
Now_producting_Workorder_again = Now_producting_WorkorderList [ 0 ] ;
return null ;
}
if ( index = = 0 )
{
// 已经是最后一个了没有
return null ;
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
}
else
{
Now_producting_Workorder_again = Now_producting_WorkorderList [ index - 1 ] ;
return Now_producting_Workorder_again ;
}
}
}
/// <summary>
/// 获取上一个工单 三检
/// </summary>
/// <returns></returns>
/// <exception cref=""></exception>
public QcCurrentWorkorderDto GetcurrentWorkorder_previous_thirty ( )
{
//获取状态为1的生产工单列表
List < QcCurrentWorkorderDto > Now_producting_WorkorderList = GetNow_producting_WorkorderList ( ) ;
// 当前没有生产工单
if ( Now_producting_WorkorderList = = null | | Now_producting_WorkorderList . Count < = 0 )
{
Now_producting_Workorder_thirty = null ;
return null ;
}
else
{
// 当前没有生产工单
if ( Now_producting_Workorder_thirty = = null )
{
return null ;
}
//获取上一个工单号 游标
int index = Now_producting_WorkorderList . FindIndex ( x = > x . ClientWorkorder = = Now_producting_Workorder_thirty . ClientWorkorder ) ;
if ( index < 0 )
{
// 逻辑异常
Now_producting_Workorder_thirty = Now_producting_WorkorderList [ 0 ] ;
return null ;
}
if ( index = = 0 )
{
// 已经是最后一个了没有
return null ;
}
else
{
Now_producting_Workorder_thirty = Now_producting_WorkorderList [ index - 1 ] ;
return Now_producting_Workorder_thirty ;
}
}
}
/// <summary>
/// 缺陷项目 累加 (首检)
/// </summary>
/// <param name="workorder_id">工单id</param>
/// <param name="checkid">缺陷项</param>
/// <param name="number">要累加的值</param>
/// <returns> 最终累加的值</returns>
/// <exception cref="NotImplementedException"></exception>
public int Accumulator_first ( string workorder_id , int checkid , int number , string InspectionModule , string name )
{
2024-01-29 16:55:45 +08:00
int result = 0 ;
2024-01-31 17:51:45 +08:00
//TODO 获取已知的的检测项 +1
QcFirstinspectionRecord exist_record = Context . Queryable < QcFirstinspectionRecord > ( )
. Where ( it = > it . FKWorkorderId = = workorder_id & & it . FKInpectionId = = checkid . ToString ( ) )
. First ( ) ;
2024-01-26 16:59:00 +08:00
2024-01-31 17:51:45 +08:00
if ( exist_record = = null )
{
QcFirstinspectionRecord record = new QcFirstinspectionRecord ( ) ;
record . Id = SnowFlakeSingle . Instance . NextId ( ) . ToString ( ) ;
record . FKWorkorderId = workorder_id ;
record . FKInpectionId = checkid . ToString ( ) ;
record . InspectionModule = InspectionModule ;
record . Counter = number ;
record . CreatedTime = DateTime . Now ;
record . UpdatedTime = DateTime . Now ;
record . CreatedBy = name ;
record . UpdatedBy = name ;
Context . Insertable ( record ) . ExecuteCommand ( ) ;
result = 1 ;
}
else
{
result = Context . Updateable < QcFirstinspectionRecord > ( )
. SetColumns ( it = > it . Counter = = ( exist_record . Counter + number ) )
. SetColumns ( it = > it . UpdatedTime = = DateTime . Now )
. SetColumns ( it = > it . UpdatedBy = = name )
. Where ( it = > it . FKInpectionId = = checkid . ToString ( ) & & it . FKWorkorderId = = workorder_id )
. ExecuteCommand ( ) ;
result = ( int ) exist_record . Counter + number ;
}
2024-01-26 16:59:00 +08:00
2024-01-29 16:55:45 +08:00
return result ;
}
/// <summary>
/// 缺陷项目 累加 (二检)
/// </summary>
/// <param name="workorder_id"></param>
/// <param name="checkid"></param>
/// <param name="counter"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
2024-01-31 17:51:45 +08:00
public int Accumulator_again ( string workorder_id , int checkid , int number , string InspectionModule , string name )
2024-01-29 16:55:45 +08:00
{
2024-01-31 17:51:45 +08:00
2024-01-29 16:55:45 +08:00
int result = 0 ;
2024-01-31 17:51:45 +08:00
//TODO 获取已知的的检测项 +1
QcAgaininspectionRecord exist_record = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorder_id & & it . FkInpectionId = = checkid . ToString ( ) )
. First ( ) ;
if ( exist_record = = null )
{
QcAgaininspectionRecord record = new QcAgaininspectionRecord ( ) ;
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
record . Id = SnowFlakeSingle . Instance . NextId ( ) . ToString ( ) ;
record . FkWorkorderId = workorder_id ;
record . FkInpectionId = checkid . ToString ( ) ;
record . InspectionModule = InspectionModule ;
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
record . Counter = number ;
record . CreatedTime = DateTime . Now ;
record . UpdatedTime = DateTime . Now ;
record . CreatedBy = name ;
record . UpdatedBy = name ;
Context . Insertable ( record ) . ExecuteCommand ( ) ;
result = 1 ;
}
else
{
result = Context . Updateable < QcAgaininspectionRecord > ( )
. SetColumns ( it = > it . Counter = = ( exist_record . Counter + number ) )
. SetColumns ( it = > it . UpdatedTime = = DateTime . Now )
. SetColumns ( it = > it . UpdatedBy = = name )
. Where ( it = > it . FkInpectionId = = checkid . ToString ( ) & & it . FkWorkorderId = = workorder_id )
. ExecuteCommand ( ) ;
result = ( int ) exist_record . Counter + number ;
}
2024-01-29 16:55:45 +08:00
return result ;
}
/// <summary>
/// 缺陷项目 累加 (三检)
/// </summary>
/// <param name="workorder_id"></param>
/// <param name="checkid"></param>
/// <param name="counter"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
2024-01-31 17:51:45 +08:00
public int Accumulator_thirty ( string workorder_id , int checkid , int number , string InspectionModule , string name )
2024-01-29 16:55:45 +08:00
{
int result = 0 ;
2024-01-31 17:51:45 +08:00
//TODO 获取已知的的检测项 +1
QcFinalinspectionRecord exist_record = Context . Queryable < QcFinalinspectionRecord > ( )
. Where ( it = > it . FkWorkorderId = = workorder_id & & it . FkInpectionId = = checkid . ToString ( ) )
. First ( ) ;
if ( exist_record = = null )
{
QcFinalinspectionRecord record = new QcFinalinspectionRecord ( ) ;
record . Id = SnowFlakeSingle . Instance . NextId ( ) . ToString ( ) ;
record . FkWorkorderId = workorder_id ;
record . FkInpectionId = checkid . ToString ( ) ;
record . InspectionModule = InspectionModule ;
record . Counter = number ;
record . CreatedTime = DateTime . Now ;
record . UpdatedTime = DateTime . Now ;
record . CreatedBy = name ;
record . UpdatedBy = name ;
Context . Insertable ( record ) . ExecuteCommand ( ) ;
result = 1 ;
}
else
{
result = Context . Updateable < QcFinalinspectionRecord > ( )
. SetColumns ( it = > it . Counter = = ( exist_record . Counter + number ) )
. SetColumns ( it = > it . UpdatedTime = = DateTime . Now )
. SetColumns ( it = > it . UpdatedBy = = name )
. Where ( it = > it . FkInpectionId = = checkid . ToString ( ) & & it . FkWorkorderId = = workorder_id )
. ExecuteCommand ( ) ;
result = ( int ) exist_record . Counter + number ;
}
2024-01-29 16:55:45 +08:00
return result ;
}
/// <summary>
/// 计算当前工单下所有抛光总数
/// </summary>
/// <param name="workorder_id"></param>
/// <returns></returns>
public int CalculatePolishTotalNumber ( string workorder_id )
{
var list = Context . Queryable < QcFirstinspectionRecord > ( )
. Where ( it = > it . FKWorkorderId = = workorder_id )
. Where ( "fk_inpection_id like @fk_inpection_id" , new { fk_inpection_id = "_" + 1 + "_" } )
. GroupBy ( it = > it . FKWorkorderId )
. Select ( it = > new
{
sum = SqlFunc . AggregateSum ( it . Counter ? ? 0 )
} ) . First ( ) ;
2024-01-31 17:51:45 +08:00
if ( list ! = null )
return list . sum ;
else return 0 ;
2024-01-29 16:55:45 +08:00
}
/// <summary>
/// 计算当前工单下的包装投入数==一次合格+抛光合格
/// </summary>
/// <param name="workorder_id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public int CalculatePackagingInvestment ( string workorder_id )
{
2024-01-31 17:51:45 +08:00
2024-01-29 16:55:45 +08:00
int OnePassNumber = 0 ;
int polishPassNumber = 0 ;
UseTran ( ( ) = >
{
2024-01-31 17:51:45 +08:00
//TODO 一次合格数=计划数-所有缺陷数
2024-01-29 16:55:45 +08:00
var workorder = Context . Queryable < ProWorkorder_v2 > ( ) . Where ( it = > it . ClientWorkorder = = workorder_id ) . First ( ) ;
2024-01-31 17:51:45 +08:00
if ( workorder ! = null )
{
var list = Context . Queryable < QcFirstinspectionRecord > ( )
. Where ( it = > it . FKWorkorderId . Equals ( workorder_id ) )
. GroupBy ( it = > it . FKWorkorderId )
. Select ( it = > new
{
sum = SqlFunc . AggregateSum ( it . Counter ? ? 0 )
} ) . First ( ) ;
if ( list ! = null )
{
OnePassNumber = workorder . PreviousNumber - list . sum ;
}
else
{
OnePassNumber = workorder . PreviousNumber - 0 ;
}
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
//TODO 计算抛光合格=首检的抛光-抛光缺陷项
int polishNumber = CalculatePolishTotalNumber ( workorder_id ) ;
var polish_defect_Number = Context . Queryable < QcAgaininspectionRecord > ( )
. Where ( it = > it . FkWorkorderId . Equals ( workorder_id ) )
. GroupBy ( it = > it . FkWorkorderId )
. Select ( it = > new
{
sum = SqlFunc . AggregateSum ( it . Counter ? ? 0 )
} ) . First ( ) ;
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
if ( polish_defect_Number ! = null )
{
polishPassNumber = polishNumber - polish_defect_Number . sum ;
}
else
{
polishPassNumber = polishNumber - 0 ;
}
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
Console . ForegroundColor = ConsoleColor . Green ;
Console . WriteLine ( $"打印工单{workorder_id} 一次合格数{OnePassNumber}=计划数{workorder.PreviousNumber}-----所有缺陷数{list?.sum} " ) ;
Console . ForegroundColor = ConsoleColor . Green ;
Console . WriteLine ( $"打印工单{workorder_id} 计算抛光合格{polishPassNumber}=首检的抛光{polishNumber}-----抛光缺陷项{polish_defect_Number?.sum}" ) ;
Console . ForegroundColor = ConsoleColor . Green ;
Console . WriteLine ( $"打印工单{workorder_id} 包装投入数{OnePassNumber + polishPassNumber}" ) ;
2024-01-29 16:55:45 +08:00
2024-01-31 17:51:45 +08:00
}
} ) ;
2024-01-29 16:55:45 +08:00
return OnePassNumber + polishPassNumber ;
}
2024-01-31 17:51:45 +08:00
/// <summary>
/// 更改工单为完成态
/// </summary>
/// <param name="workorder_id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public int UpdateWorkorderStatus ( string workorder_id )
{
return Context . Updateable < ProWorkorder_v2 > ( )
. SetColumns ( it = > it . Status = = 2 )
. Where ( it = > it . ClientWorkorder = = workorder_id )
. ExecuteCommand ( ) ;
}
2023-12-01 15:39:07 +08:00
}
}