1363 lines
50 KiB
C#
1363 lines
50 KiB
C#
using AutoMapper.Configuration.Conventions;
|
|
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZR.Common;
|
|
using ZR.Model.mes.pro;
|
|
using ZR.Model.MES.pro;
|
|
using ZR.Model.MES.qc;
|
|
using ZR.Model.MES.qc.DTO;
|
|
using ZR.Model.MES.qu;
|
|
using ZR.Service.mes.qc.IService;
|
|
using ZR.Service.mes.qu.IService;
|
|
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace ZR.Service.mes.qc
|
|
{
|
|
|
|
[AppService(ServiceType = typeof(IFirstFQCService), ServiceLifetime = LifeTime.Transient)]
|
|
public class FirstFQCService : BaseService<QcInspectionitem>, IFirstFQCService
|
|
{
|
|
/// <summary>
|
|
/// 获取检测项 (首检)
|
|
/// </summary>
|
|
/// <param name="workorderID"></param>
|
|
/// <returns></returns>
|
|
|
|
public CheckItemTableDTO GetCheckItemTable_first(string workorderID)
|
|
{
|
|
CheckItemTableDTO checkItem = new CheckItemTableDTO();
|
|
|
|
|
|
checkItem.Paint = Queryable().Where(it => it.InspectionModule == "油漆").OrderBy(it => it.Id).ToList();
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
});
|
|
checkItem.device = Queryable().Where(it => it.InspectionModule == "设备").OrderBy(it => it.Id).ToList();
|
|
checkItem.device.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;
|
|
}
|
|
|
|
});
|
|
checkItem.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
|
checkItem.Blank.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;
|
|
}
|
|
|
|
});
|
|
checkItem.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
|
checkItem.program.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;
|
|
}
|
|
});
|
|
checkItem.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
|
checkItem.Team.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;
|
|
}
|
|
});
|
|
|
|
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();
|
|
checkItem.device.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.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
|
checkItem.Blank.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.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
|
checkItem.program.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.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
|
checkItem.Team.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;
|
|
}
|
|
});
|
|
|
|
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();
|
|
checkItem.device.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.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
|
checkItem.Blank.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.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
|
checkItem.program.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.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
|
checkItem.Team.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;
|
|
}
|
|
});
|
|
|
|
return checkItem;
|
|
|
|
}
|
|
|
|
|
|
/// <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_v1(string workorder_id, string InspectionModule, string checkid, int counter)
|
|
{
|
|
|
|
//更新实时记录表
|
|
QcFirstinspectionRecord record = new QcFirstinspectionRecord();
|
|
record.Id = DateTime.Now.ToString("YYMMddHHmmss");
|
|
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_v2(string workorder_id, string InspectionModule, string checkid, int counter)
|
|
{
|
|
//更新实时记录表
|
|
QcAgaininspectionRecord record = new QcAgaininspectionRecord();
|
|
record.Id = DateTime.Now.ToString("YYMMddHHmmss");
|
|
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();
|
|
record.Id = DateTime.Now.ToString("YYMMddHHmmss");
|
|
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.UpdateColumns(it => new { it.UpdatedBy, it.UpdatedTime, it.Counter }).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="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;
|
|
|
|
//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;
|
|
|
|
|
|
//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);
|
|
}
|
|
|
|
public static QcCurrentWorkorderDto Now_producting_Workorder_first = null; //当前生产工单 首检
|
|
public static QcCurrentWorkorderDto Now_producting_Workorder_again = null; //当前生产工单 二检
|
|
public static QcCurrentWorkorderDto Now_producting_Workorder_thirty = null; //当前生产工单 三检
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前_生产中_工单列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public List<QcCurrentWorkorderDto> GetNow_producting_WorkorderList()
|
|
{
|
|
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)
|
|
{
|
|
qcCurrentList.Add(new QcCurrentWorkorderDto()
|
|
{
|
|
ClientWorkorder = item.ClientWorkorder,
|
|
ProductDescription = item.ProductDescription,
|
|
FinishedPartNumber = item.FinishedPartNumber,
|
|
Specifications = item.Specifications,
|
|
Colour = item.Colour,
|
|
Team = "",
|
|
PreviousNumber = item.PreviousNumber,
|
|
FirstPassNumber = 0,
|
|
FirstPassRate = 0.0,
|
|
PolisheNumber = 0,
|
|
ScrapNumber = 0,
|
|
DefectNumber = 0
|
|
});
|
|
;
|
|
|
|
}
|
|
|
|
return qcCurrentList;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前生产工单 一检
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public QcCurrentWorkorderDto GetcurrentWorkorder_first()
|
|
{
|
|
//获取状态为1的生产工单列表
|
|
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
|
// 当前没有生产工单
|
|
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
|
{
|
|
Now_producting_Workorder_first = null;
|
|
return null;
|
|
}
|
|
else if (Now_producting_Workorder_first == null)
|
|
{
|
|
Now_producting_Workorder_first = Now_producting_WorkorderList[0];
|
|
return Now_producting_Workorder_first;
|
|
}
|
|
else
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前生产工单 三检
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public QcCurrentWorkorderDto GetcurrentWorkorder_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)
|
|
{
|
|
Now_producting_Workorder_thirty = Now_producting_WorkorderList[0];
|
|
return Now_producting_Workorder_thirty;
|
|
}
|
|
else
|
|
{
|
|
return Now_producting_Workorder_thirty;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取下一个生产工单 一检
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public QcCurrentWorkorderDto GetcurrentWorkorder_next_first()
|
|
{
|
|
|
|
|
|
|
|
|
|
//获取状态为1的生产工单列表
|
|
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
|
// 当前没有生产工单
|
|
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
|
{
|
|
Now_producting_Workorder_first = null;
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
|
|
// 当前没有生产工单
|
|
if (Now_producting_Workorder_first == null)
|
|
{
|
|
return null;
|
|
}
|
|
//获取上一个工单号 游标
|
|
int index = Now_producting_WorkorderList.FindIndex(x => x.ClientWorkorder == Now_producting_Workorder_first.ClientWorkorder);
|
|
if (index < 0)
|
|
{
|
|
// 逻辑异常
|
|
Now_producting_Workorder_first = Now_producting_WorkorderList[0];
|
|
return null;
|
|
}
|
|
if (index == Now_producting_WorkorderList.Count() - 1)
|
|
{
|
|
// 已经是最后一个了没有
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
else
|
|
{
|
|
Now_producting_Workorder_first = Now_producting_WorkorderList[index + 1];
|
|
return Now_producting_Workorder_first;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>()
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取上一个工单 首检
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref=""></exception>
|
|
|
|
public QcCurrentWorkorderDto GetcurrentWorkorder_previous_first()
|
|
{
|
|
//获取状态为1的生产工单列表
|
|
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
|
// 当前没有生产工单
|
|
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
|
{
|
|
Now_producting_Workorder_first = null;
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
|
|
// 当前没有生产工单
|
|
if (Now_producting_Workorder_first == null)
|
|
{
|
|
return null;
|
|
}
|
|
//获取上一个工单号 游标
|
|
int index = Now_producting_WorkorderList.FindIndex(x => x.ClientWorkorder == Now_producting_Workorder_first.ClientWorkorder);
|
|
if (index < 0)
|
|
{
|
|
// 逻辑异常
|
|
Now_producting_Workorder_first = Now_producting_WorkorderList[0];
|
|
return null;
|
|
}
|
|
if (index == 0)
|
|
{
|
|
// 已经是最后一个了没有
|
|
return null;
|
|
|
|
}
|
|
else
|
|
{
|
|
Now_producting_Workorder_first = Now_producting_WorkorderList[index - 1];
|
|
return Now_producting_Workorder_first;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取上一个工单 二检
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref=""></exception>
|
|
|
|
public QcCurrentWorkorderDto GetcurrentWorkorder_previous_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 == 0)
|
|
{
|
|
// 已经是最后一个了没有
|
|
return null;
|
|
|
|
}
|
|
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)
|
|
{
|
|
int result = 0;
|
|
//TODO 获取已知的的检测项 +1
|
|
QcFirstinspectionRecord exist_record= Context.Queryable<QcFirstinspectionRecord>()
|
|
.Where(it => it.FKWorkorderId == workorder_id && it.FKInpectionId == checkid.ToString())
|
|
.First();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 缺陷项目 累加 (二检)
|
|
/// </summary>
|
|
/// <param name="workorder_id"></param>
|
|
/// <param name="checkid"></param>
|
|
/// <param name="counter"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public int Accumulator_again(string workorder_id, int checkid, int number, string InspectionModule, string name)
|
|
{
|
|
|
|
|
|
int result = 0;
|
|
//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();
|
|
|
|
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<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;
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 缺陷项目 累加 (三检)
|
|
/// </summary>
|
|
/// <param name="workorder_id"></param>
|
|
/// <param name="checkid"></param>
|
|
/// <param name="counter"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public int Accumulator_thirty(string workorder_id, int checkid, int number, string InspectionModule, string name)
|
|
{
|
|
|
|
|
|
int result = 0;
|
|
//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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
if (list != null)
|
|
return list.sum;
|
|
else return 0;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 计算当前工单下的包装投入数==一次合格+抛光合格
|
|
/// </summary>
|
|
/// <param name="workorder_id"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
public int CalculatePackagingInvestment(string workorder_id)
|
|
{
|
|
|
|
|
|
int OnePassNumber = 0;
|
|
int polishPassNumber = 0;
|
|
|
|
UseTran(() =>
|
|
{
|
|
//TODO 一次合格数=计划数-所有缺陷数
|
|
var workorder = Context.Queryable<ProWorkorder_v2>().Where(it => it.ClientWorkorder == workorder_id).First();
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
//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();
|
|
|
|
if (polish_defect_Number != null)
|
|
{
|
|
polishPassNumber = polishNumber - polish_defect_Number.sum;
|
|
}
|
|
else
|
|
{
|
|
polishPassNumber = polishNumber - 0;
|
|
}
|
|
|
|
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}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return OnePassNumber + polishPassNumber;
|
|
|
|
}
|
|
/// <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();
|
|
}
|
|
}
|
|
}
|