using MES.Service.Models;
|
using Microsoft.IdentityModel.Tokens;
|
using NewPdaSqlServer.DB;
|
using NewPdaSqlServer.Dto.service;
|
using NewPdaSqlServer.entity;
|
using NewPdaSqlServer.util;
|
using SqlSugar;
|
using System.Data;
|
using System.Data.SqlClient;
|
using static Azure.Core.HttpHeader;
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
namespace NewPdaSqlServer.service.QC;
|
|
public class IpqcService : RepositoryNoEntity
|
{
|
public (List<VIpqcSj> item, int TotalCount) getPageSj(XJPageResult queryObj)
|
{
|
var parsedGuid = Guid.Empty;
|
if (!queryObj.id.IsNullOrEmpty())
|
{
|
var isValid = Guid.TryParse(queryObj.id, out parsedGuid);
|
if (!isValid)
|
throw new ApplicationException("GUID转换错误");
|
}
|
|
|
var totalCount = 0;
|
|
var pageList = Db.Queryable<VIpqcSj>()
|
.WhereIF(!string.IsNullOrWhiteSpace(queryObj.keyword), a =>
|
a.ItemNo.Contains(queryObj.keyword) ||
|
a.ItemName.Contains(queryObj.keyword) ||
|
a.Daa001.Contains(queryObj.keyword) ||
|
a.ReleaseNo.Contains(queryObj.keyword) ||
|
a.DepartmentName.Contains(queryObj.keyword )||
|
a.XtName.Contains(queryObj.keyword)
|
)
|
.WhereIF(UtilityHelper.CheckGuid(parsedGuid),
|
a => a.Guid == parsedGuid.ToString() )
|
.Where(a => (a.FSubmit ?? 0) == 0)
|
.OrderByDescending(a => a.CreateDate)
|
.ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
|
|
return (pageList, totalCount);
|
}
|
|
public List<MesQaItemsDetectDetail5> GetItems(string? releaseNo,
|
string? id)
|
{
|
var parsedGuid = Guid.Empty;
|
|
if (id != null)
|
{
|
var isValid = Guid.TryParse(id, out parsedGuid);
|
if (!isValid)
|
throw new ApplicationException("GUID转换错误");
|
}
|
|
var Ybsl_In = Db.Queryable<MesQaItemsDetectDetail5>()
|
.Where(a => a.ParentGuid == parsedGuid)
|
.Count();
|
|
return Db.Queryable<MesQaItemsDetectDetail5, MesQaItemsDetectDetail12>(
|
(a, b) =>
|
new JoinQueryInfos(JoinType.Left, a.Guid == b.ParentGuid))
|
.Where((a, b) => a.ReleaseNo == releaseNo)
|
.WhereIF(UtilityHelper.CheckGuid(parsedGuid),
|
(a, b) => a.Guid == parsedGuid)
|
.GroupBy((a, b) => new
|
{
|
a.Guid,
|
a.ParentGuid,
|
a.ReleaseNo,
|
a.FacLevel,
|
a.FcheckItem,
|
a.FcheckTool,
|
a.FdownAllow,
|
a.FcheckLevel,
|
a.Fstand,
|
a.FupAllow,
|
a.SampleSizeNo,
|
a.FspecRequ,
|
a.FreQty,
|
a.CheckQyt,
|
a.FcheckResu,
|
a.Order,
|
a.Ybsl,
|
a.ISRZXX,
|
a.IPQCRZXX
|
}).Select((a, b) => new MesQaItemsDetectDetail5
|
{
|
Guid = a.Guid,
|
ParentGuid = a.ParentGuid,
|
ReleaseNo = a.ReleaseNo,
|
CheckQyt = a.CheckQyt,
|
FacLevel = a.FacLevel,
|
FcheckItem = a.FcheckItem,
|
FcheckTool = a.FcheckTool,
|
FdownAllow = a.FdownAllow,
|
FcheckLevel = a.FcheckLevel,
|
Fstand = a.Fstand,
|
FupAllow = a.FupAllow,
|
SampleSizeNo = a.SampleSizeNo,
|
FspecRequ = a.FspecRequ,
|
FreQty = a.FreQty,
|
Factory = "1000",
|
Company = "1000",
|
FenterQty = SqlFunc.AggregateCount(b.Guid),
|
FcheckResu = a.FcheckResu,
|
Order = a.Order,
|
Ybsl = a.Ybsl,
|
YbslIn = Ybsl_In,
|
ISRZXX = a.ISRZXX,
|
IPQCRZXX = a.IPQCRZXX
|
}).OrderBy(a => a.Order)
|
.ToList();
|
}
|
|
|
public (List<VIpqcXj> item, int TotalCount) getPageXj(XJPageResult queryObj)
|
{
|
var parsedGuid = Guid.Empty;
|
if (!queryObj.id.IsNullOrEmpty())
|
{
|
var isValid = Guid.TryParse(queryObj.id, out parsedGuid);
|
if (!isValid)
|
throw new ApplicationException("GUID转换错误");
|
}
|
|
|
var totalCount = 0;
|
|
var pageList = Db.Queryable<VIpqcXj>()
|
.WhereIF(!string.IsNullOrWhiteSpace(queryObj.keyword), a =>
|
a.ItemNo.Contains(queryObj.keyword) ||
|
a.ItemName.Contains(queryObj.keyword) ||
|
a.Daa001.Contains(queryObj.keyword) ||
|
a.ReleaseNo.Contains(queryObj.keyword) ||
|
a.DepartmentName.Contains(queryObj.keyword) ||
|
a.xtName.Contains(queryObj.keyword)
|
)
|
.WhereIF(UtilityHelper.CheckGuid(parsedGuid),
|
a => a.Guid == parsedGuid.ToString())
|
.Where(a => (a.FSubmit ?? 0) == 0)
|
.OrderByDescending(a => a.CreateDate)
|
.ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
|
|
return (pageList, totalCount);
|
}
|
|
|
//更新不合格描述
|
public int updateIpqcRzxx(LLJDto dto)
|
{
|
if (dto == null) throw new ArgumentNullException(nameof(dto), "参数对象不能为 null");
|
|
// 参数校验(根据存储过程新增参数)
|
if (string.IsNullOrEmpty(dto.pid?.ToString()))
|
throw new ArgumentException("项目明细id存在问题,请联系管理员!", nameof(dto.pid));
|
|
var withOracle = Db.Updateable<MesQaItemsDetectDetail5>()
|
.SetColumns(s => s.IPQCRZXX == dto.inRzxxValue)
|
.Where(s => s.Guid.ToString() == dto.pid)
|
.ExecuteCommand();
|
|
return withOracle;
|
}
|
|
|
public dynamic CreateByWomdaa(dynamic query)
|
{
|
if (query == null) throw new ArgumentNullException(nameof(query));
|
|
if (string.IsNullOrEmpty(query.userAccount?.ToString()))
|
throw new ArgumentException("用户账号不能为空", nameof(query.userAccount));
|
|
if (string.IsNullOrEmpty(query.inOrderGuid1?.ToString()))
|
throw new ArgumentException("检验单GUID不能为空", nameof(query.inOrderGuid1));
|
|
if (string.IsNullOrEmpty(query.DAA001?.ToString()))
|
throw new ArgumentException("工单号不能为空", nameof(query.inOrderGuid1));
|
|
var _strMsg = "";
|
var _status = -1;
|
|
using (var conn = new SqlConnection(DbHelperSQL.strConn))
|
using (var cmd = new SqlCommand("ipqc_createByWomdaa", conn))
|
{
|
try
|
{
|
conn.Open();
|
cmd.CommandType = CommandType.StoredProcedure;
|
|
SqlParameter[] parameters =
|
{
|
new("@po_outMsg", SqlDbType.NVarChar, 150) { Direction = ParameterDirection.Output },
|
new("@po_outStatus", SqlDbType.Int) { Direction = ParameterDirection.Output },
|
new("@pi_user", SqlDbType.NVarChar, 150) { Value = query.userAccount },
|
new("@pi_OrderGuid1", SqlDbType.UniqueIdentifier) { Value = Guid.Parse(query.inOrderGuid1.ToString()) },
|
new("@pi_DAA001", SqlDbType.NVarChar, 150) { Value = query.DAA001.ToString() },
|
new("@pi_inP1", SqlDbType.NVarChar, 20) { Value = query.pi_inP1 ?? DBNull.Value },
|
new("@pi_inP2", SqlDbType.NVarChar, 20) { Value = query.pi_inP2 ?? DBNull.Value }
|
};
|
|
cmd.Parameters.AddRange(parameters);
|
cmd.ExecuteNonQuery();
|
|
_strMsg = parameters[0].Value?.ToString() ?? "";
|
_status = Convert.ToInt32(parameters[1].Value ?? -1);
|
|
if (_status <= 0) throw new Exception(_strMsg);
|
|
return new
|
{
|
message = _strMsg,
|
status = _status
|
};
|
}
|
catch (Exception ex)
|
{
|
throw new Exception($"检验单更新失败:{ex.Message}");
|
}
|
}
|
}
|
}
|