978 lines
37 KiB
C#
978 lines
37 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;
|
||
|
||
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(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
||
checkItem.Blank.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
||
checkItem.program.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
});
|
||
checkItem.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
||
checkItem.Team.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.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(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
||
checkItem.Blank.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
||
checkItem.program.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
});
|
||
checkItem.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
||
checkItem.Team.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.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(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.Blank = Queryable().Where(it => it.InspectionModule == "毛坯").OrderBy(it => it.Id).ToList();
|
||
checkItem.Blank.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
|
||
});
|
||
checkItem.program = Queryable().Where(it => it.InspectionModule == "程序").OrderBy(it => it.Id).ToList();
|
||
checkItem.program.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.Counter = 0;
|
||
});
|
||
checkItem.Team = Queryable().Where(it => it.InspectionModule == "班组操作").OrderBy(it => it.Id).ToList();
|
||
checkItem.Team.ForEach(it =>
|
||
{
|
||
QcFirstinspectionRecord record = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.FKWorkorderId == workorderID && it.FKInpectionId == it.Id).First();
|
||
if (record != null)
|
||
{
|
||
it.Counter = record.Counter;
|
||
}
|
||
it.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 = 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()
|
||
{
|
||
//获取状态为1的生产工单列表
|
||
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
||
// 当前没有生产工单
|
||
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
||
{
|
||
Now_producting_Workorder = null;
|
||
return null;
|
||
}
|
||
else if (Now_producting_Workorder == null)
|
||
{
|
||
Now_producting_Workorder = Now_producting_WorkorderList[0];
|
||
return Now_producting_Workorder;
|
||
}
|
||
else
|
||
{
|
||
return Now_producting_Workorder;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取下一个生产工单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public QcCurrentWorkorderDto GetcurrentWorkorder_next()
|
||
{
|
||
|
||
//#region 清空已经完成工单的缓存
|
||
//// 获取状态为2的工单列表,然后清空缓存
|
||
//List<ProWorkorder_v2> workorders = Context.Queryable<ProWorkorder_v2>().Where(it => it.Remark3 == "是").Where(it => it.Status >1).OrderBy(it => it.Sort).ToList();
|
||
//if(workorders!=null&&workorders.Count>0)
|
||
//{
|
||
// foreach(ProWorkorder_v2 workorder_item in workorders)
|
||
// {
|
||
// // key值规则 workorderid + "_"+ checkid + "_v1";
|
||
// StringBuilder string_Key =new StringBuilder();
|
||
// string_Key.Append(workorder_item.ClientWorkorder);
|
||
// // 获取所有检测项
|
||
// List<QcInspectionitem> qcInspectionitems=Context.Queryable<QcInspectionitem>().ToList();
|
||
// foreach(QcInspectionitem qc in qcInspectionitems)
|
||
// {
|
||
// string_Key.Append(qc.Id);
|
||
// string_Key.Append("_v1");
|
||
// if (CacheHelper.Exists(string_Key.ToString()))
|
||
// {
|
||
// CacheHelper.Remove(string_Key.ToString());
|
||
// }
|
||
// string_Key.Append("_v2");
|
||
// if (CacheHelper.Exists(string_Key.ToString()))
|
||
// {
|
||
// CacheHelper.Remove(string_Key.ToString());
|
||
// }
|
||
// string_Key.Append("_v3");
|
||
// if (CacheHelper.Exists(string_Key.ToString()))
|
||
// {
|
||
// CacheHelper.Remove(string_Key.ToString());
|
||
// }
|
||
|
||
// }
|
||
|
||
// }
|
||
//}
|
||
|
||
|
||
|
||
//#endregion
|
||
|
||
|
||
//获取状态为1的生产工单列表
|
||
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
||
// 当前没有生产工单
|
||
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
||
{
|
||
Now_producting_Workorder = null;
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
|
||
// 当前没有生产工单
|
||
if (Now_producting_Workorder == null)
|
||
{
|
||
return null;
|
||
}
|
||
//获取上一个工单号 游标
|
||
int index = Now_producting_WorkorderList.FindIndex(x => x.ClientWorkorder == Now_producting_Workorder.ClientWorkorder);
|
||
if (index < 0)
|
||
{
|
||
// 逻辑异常
|
||
Now_producting_Workorder = Now_producting_WorkorderList[0];
|
||
return null;
|
||
}
|
||
if (index == Now_producting_WorkorderList.Count() - 1)
|
||
{
|
||
// 已经是最后一个了没有
|
||
|
||
|
||
return null;
|
||
|
||
}
|
||
else
|
||
{
|
||
Now_producting_Workorder = Now_producting_WorkorderList[index + 1];
|
||
return Now_producting_Workorder;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
/// <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="NotImplementedException"></exception>
|
||
|
||
public QcCurrentWorkorderDto GetcurrentWorkorder_previous()
|
||
{
|
||
//获取状态为1的生产工单列表
|
||
List<QcCurrentWorkorderDto> Now_producting_WorkorderList = GetNow_producting_WorkorderList();
|
||
// 当前没有生产工单
|
||
if (Now_producting_WorkorderList == null || Now_producting_WorkorderList.Count <= 0)
|
||
{
|
||
Now_producting_Workorder = null;
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
|
||
// 当前没有生产工单
|
||
if (Now_producting_Workorder == null)
|
||
{
|
||
return null;
|
||
}
|
||
//获取上一个工单号 游标
|
||
int index = Now_producting_WorkorderList.FindIndex(x => x.ClientWorkorder == Now_producting_Workorder.ClientWorkorder);
|
||
if (index < 0)
|
||
{
|
||
// 逻辑异常
|
||
Now_producting_Workorder = Now_producting_WorkorderList[0];
|
||
return null;
|
||
}
|
||
if (index == 0)
|
||
{
|
||
// 已经是最后一个了没有
|
||
return null;
|
||
|
||
}
|
||
else
|
||
{
|
||
Now_producting_Workorder = Now_producting_WorkorderList[index - 1];
|
||
return Now_producting_Workorder;
|
||
}
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 缺陷项目 累加 (首检)
|
||
/// </summary>
|
||
/// <param name="workorder_id"></param>
|
||
/// <param name="checkid"></param>
|
||
/// <param name="counter"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public int Accumulator_first(string workorder_id, int checkid, int counter, string name)
|
||
{
|
||
|
||
QcFirstinspectionRecord record = new QcFirstinspectionRecord();
|
||
record.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
||
record.FKWorkorderId = workorder_id;
|
||
record.FKInpectionId = checkid.ToString();
|
||
record.InspectionModule = "paint";
|
||
record.Counter = counter;
|
||
record.CreatedTime = DateTime.Now;
|
||
record.UpdatedTime = DateTime.Now;
|
||
record.CreatedBy = name;
|
||
record.UpdatedBy = name;
|
||
|
||
var x = Context.Storageable(record)
|
||
.WhereColumns(it => new { it.FKWorkorderId, it.FKInpectionId }).ToStorage();
|
||
int result = 0;
|
||
result += x.AsInsertable.ExecuteCommand();//不存在插入
|
||
result += x.AsUpdateable.UpdateColumns(it => new { it.Counter, it.UpdatedBy, it.UpdatedTime }).ExecuteCommand();//存在更新
|
||
|
||
|
||
|
||
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 counter, string name)
|
||
{
|
||
|
||
QcAgaininspectionRecord record = new QcAgaininspectionRecord();
|
||
record.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
||
record.FkWorkorderId = workorder_id;
|
||
record.FkInpectionId = checkid.ToString();
|
||
record.InspectionModule = "paint";
|
||
record.Counter = counter;
|
||
record.CreatedTime = DateTime.Now;
|
||
record.UpdatedTime = DateTime.Now;
|
||
record.CreatedBy = name;
|
||
record.UpdatedBy = name;
|
||
|
||
var x = Context.Storageable(record)
|
||
.WhereColumns(it => new { it.FkWorkorderId, it.FkInpectionId }).ToStorage();
|
||
int result = 0;
|
||
result += x.AsInsertable.ExecuteCommand();//不存在插入
|
||
result += x.AsUpdateable.UpdateColumns(it => new { it.Counter, it.UpdatedBy, it.UpdatedTime }).ExecuteCommand();//存在更新
|
||
|
||
|
||
|
||
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 counter, string name)
|
||
{
|
||
|
||
QcFinalinspectionRecord record = new QcFinalinspectionRecord();
|
||
record.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
||
record.FkWorkorderId = workorder_id;
|
||
record.FkInpectionId = checkid.ToString();
|
||
record.InspectionModule = "paint";
|
||
record.Counter = counter;
|
||
record.CreatedTime = DateTime.Now;
|
||
record.UpdatedTime = DateTime.Now;
|
||
record.CreatedBy = name;
|
||
record.UpdatedBy = name;
|
||
|
||
var x = Context.Storageable(record)
|
||
.WhereColumns(it => new { it.FkWorkorderId, it.FkInpectionId }).ToStorage();
|
||
int result = 0;
|
||
result += x.AsInsertable.ExecuteCommand();//不存在插入
|
||
result += x.AsUpdateable.UpdateColumns(it => new { it.Counter, it.UpdatedBy, it.UpdatedTime }).ExecuteCommand();//存在更新
|
||
|
||
|
||
|
||
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();
|
||
|
||
return list.sum;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 计算当前工单下的包装投入数==一次合格+抛光合格
|
||
/// </summary>
|
||
/// <param name="workorder_id"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
|
||
public int CalculatePackagingInvestment(string workorder_id)
|
||
{
|
||
|
||
//TODO 一次合格数=计划数-所有缺陷数
|
||
int OnePassNumber = 0;
|
||
int polishPassNumber = 0;
|
||
|
||
UseTran(() =>
|
||
{
|
||
var workorder = Context.Queryable<ProWorkorder_v2>().Where(it => it.ClientWorkorder == workorder_id).First();
|
||
var list = Context.Queryable<QcFirstinspectionRecord>()
|
||
.Where(it => it.Equals(workorder_id))
|
||
.GroupBy(it => it.FKWorkorderId)
|
||
.Select(it => new
|
||
{
|
||
sum = SqlFunc.AggregateSum(it.Counter ?? 0)
|
||
}).First();
|
||
OnePassNumber = workorder.PreviousNumber - list.sum;
|
||
|
||
//TODO 计算抛光合格=首检的抛光-抛光缺陷项
|
||
int polishNumber = CalculatePolishTotalNumber(workorder_id);
|
||
var polish_defect_Number = Context.Queryable<QcAgaininspectionRecord>()
|
||
.Where(it => it.Equals(workorder_id))
|
||
.GroupBy(it => it.FkWorkorderId)
|
||
.Select(it => new
|
||
{
|
||
sum = SqlFunc.AggregateSum(it.Counter ?? 0)
|
||
}).First();
|
||
|
||
|
||
polishPassNumber = polishNumber - polish_defect_Number.sum;
|
||
|
||
|
||
});
|
||
|
||
return OnePassNumber + polishPassNumber;
|
||
|
||
}
|
||
}
|
||
}
|