using Opsoft.Data;
using Opsoft.NetCore.O3App.Domain;
using Opsoft.NetCore.O3App.Domain.UnitOfWork.IPadReport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Opsoft.NetCore.O3App.Repositories.IPadReport
{
///
/// 模治具业务处理类
///
public static class MouldHandleRepository
{
#region 获取资源模具信息
///
/// 查询资源模具信息
///
///
///
///
///
public static List GetMouldInfos(APPServerContext context, string reportID, string fCode)
{
try
{
string sql = string.Format(@"
SELECT
S1.FINTERID
,S1.FNUMBER
,S1.FNAME
,S.FUPTIME AS FSTARTTIME
,S.FDOWNTIME AS FENDTIME
FROM T_SFC_REPORTENTRY4(NOLOCK) S
LEFT JOIN T_ENG_MOULDANDJIG(NOLOCK) S1 ON S1.FINTERID=S.FMOULDID
WHERE S.FINTERID='{0}' AND S.FCode='{1}' AND FDOWNTIME IS NULL
ORDER BY S.FUPTIME ASC ", reportID, fCode);
return context.Database.SqlQuery(sql);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新模具状态-上下模使用
///
/// 更新模具状态
///
///
///
///
///
public static async Task UpdateMouldStatus(APPServerContext context, string mouldStatus, List mouldData)
{
try
{
string sql = string.Format(@$" UPDATE T_ENG_MOULDANDJIG SET FMOULDSTATUS={mouldStatus} WHERE FINTERID IN ('" + string.Join("','", mouldData.Select(o => o.FID).ToList()) + "')");
await context.Database.SqlNonQueryAsync(sql);
}
catch
{
throw new O3AppException("更新模治具状态失败!", 500);
}
}
#endregion
#region 更新模具状态-汇报暂时使用
///
/// 更新模具状态-汇报暂时使用
///
///
///
///
///
public static async Task UpdateMouldStatusByReport(APPServerContext context, string mouldStatus, string reportId)
{
try
{
string sql = string.Format(@$" UPDATE T_ENG_MOULDANDJIG SET FMOULDSTATUS={mouldStatus} WHERE FINTERID IN (SELECT DISTINCT FMOULDID FROM T_SFC_REPORTENTRY4 WHERE FINTERID='{reportId}' AND FUPTIME IS NOT NULL )");
await context.Database.SqlNonQueryAsync(sql);
}
catch
{
throw new O3AppException("更新模治具状态失败!", 500);
}
}
#endregion
#region 更新模具状态-汇报时使用
///
/// 更新模具状态-汇报暂时使用
///
///
///
///
///
//public static async Task UpdateMouldByReport(APPServerContext context, ReportClass reportClass, string reportId)
//{
// try
// {
// string sql = string.Format(@$" UPDATE T_ENG_MOULDANDJIG
// SET FCOLUSELIFE=FCOLUSELIFE+{reportClass.FPassQty},
// FREMAINLIFE=FSTDUSELIFE-FCOLUSELIFE-{reportClass.FPassQty}
// WHERE FINTERID IN (SELECT DISTINCT FMOULDID FROM T_SFC_REPORTENTRY4 WHERE FINTERID='{reportId}' AND FUPTIME IS NOT NULL )");
// await context.Database.SqlNonQueryAsync(sql);
// }
// catch
// {
// throw new O3AppException("更新模治具使用寿命失败!", 500);
// }
//}
public static async Task UpdateMouldByReport(APPServerContext context, ReportClass reportClass, string reportId, string fCode)
{
try
{
string sql = string.Format(@$" UPDATE dbo.T_ENG_MOULDANDJIG
SET FREMAINLIFE = FREMAINLIFE - {reportClass.FPassQty + reportClass.FBadQty} * (CASE FNUMOFPOINTS
WHEN 0 THEN
1
ELSE
FNUMOFPOINTS
END
),
FCOLUSELIFE = FCOLUSELIFE +{reportClass.FPassQty + reportClass.FBadQty} * (CASE FNUMOFPOINTS
WHEN 0 THEN
1
ELSE
FNUMOFPOINTS
END
)
WHERE FINTERID IN
(
SELECT FMOULDID FROM dbo.T_SFC_REPORTENTRY4 WHERE FINTERID = '{reportId}' AND FCODE = '{fCode}'
);");
await context.Database.SqlNonQueryAsync(sql);
}
catch
{
throw new O3AppException("更新模治具使用寿命失败!", 500);
}
}
#endregion
}
}