| | |
| | | // 添加评审状态 |
| | | PSZT = a.PSZT, |
| | | // 添加检验项目维护状态 |
| | | Jyxm = a.Jyxm |
| | | Jyxm = a.Jyxm, |
| | | // 添加版本号(用于FTP路径) |
| | | Fversion = a.Fversion |
| | | }) |
| | | .OrderBy("IQC_DATE DESC") |
| | | .OrderBy("CASE WHEN EMERGENCY = 1 THEN 0 ELSE 1 END") |
| | |
| | | // 添加评审状态 |
| | | PSZT = a.PSZT, |
| | | // 添加检验项目维护状态 |
| | | Jyxm = a.Jyxm |
| | | Jyxm = a.Jyxm, |
| | | // 添加版本号(用于FTP路径) |
| | | Fversion = a.Fversion |
| | | }) |
| | | .OrderBy("IQC_DATE DESC") |
| | | .OrderBy("CASE WHEN EMERGENCY = 1 THEN 0 ELSE 1 END") |
| | |
| | | return input.Substring(startIndex + 1, length); |
| | | } |
| | | |
| | | public List<QamftpDto> GetAttachments(string ItemNo) |
| | | /// <summary> |
| | | /// 获取附件信息 |
| | | /// </summary> |
| | | /// <param name="ItemNo">物料编码</param> |
| | | /// <param name="fversion">版本号(可选,用于过滤)</param> |
| | | /// <returns>附件列表</returns> |
| | | public List<QamftpDto> GetAttachments(string ItemNo, string fversion = null) |
| | | { |
| | | //if (string.IsNullOrEmpty(ItemNo)) |
| | | //{ |
| | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | return db.Queryable<MesQamftp>() |
| | | var query = db.Queryable<MesQamftp>() |
| | | .Where(x => x.ItemNo == ItemNo) |
| | | .Where(x => x.Ftype == "来料检"); // 添加FTYPE = '来料检'的限制 |
| | | |
| | | // 如果传入了fversion,则按Fversion过滤 |
| | | if (!string.IsNullOrEmpty(fversion)) |
| | | { |
| | | query = query.Where(x => x.Fversion == fversion); |
| | | } |
| | | |
| | | return query |
| | | .OrderBy(x => x.Fdate, OrderByType.Desc) |
| | | // .ThenBy(x => x.CreateDate, OrderByType.Desc) |
| | | .Select(x => new QamftpDto |
| | |
| | | } |
| | | } |
| | | |
| | | public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer) |
| | | public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer, string fversion = null) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer)) |
| | |
| | | // 标准化FTP服务器地址 |
| | | string normalizedServer = NormalizeFtpServer(ftpServer); |
| | | |
| | | // 构建FTP文件路径 |
| | | string ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fileName}"; |
| | | // 构建FTP文件路径 - 来料检使用IQC目录,使用fversion作为子目录 |
| | | string ftpPath; |
| | | if (!string.IsNullOrEmpty(fversion)) |
| | | { |
| | | ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fversion}/{fileName}"; |
| | | } |
| | | else |
| | | { |
| | | ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fileName}"; |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据二维码查询物料信息 |
| | | /// </summary> |
| | | /// <param name="itemBarcode">二维码内容</param> |
| | | /// <param name="currentBillNo">当前检验单的到货单号(已废弃,保留参数兼容性)</param> |
| | | /// <returns>物料信息</returns> |
| | | public List<MaterialInfoDto> GetMaterialByBarcode(string itemBarcode, string currentBillNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | // 使用JOIN查询MES_INV_ITEM_BARCODES和MES_ITEMS表 |
| | | var materialInfo = db.Queryable<MesInvItemBarcodes>() |
| | | .LeftJoin<MesItems>((b, m) => b.ItemId == m.Id) |
| | | .Where((b, m) => b.ItemBarcode == itemBarcode && b.ComeFlg == 1) |
| | | .Select((b, m) => new MaterialInfoDto |
| | | { |
| | | ItemNo = b.ItemNo, // 物料编码 |
| | | OldQty = b.Oldqty, // 数量 |
| | | ItemId = b.ItemId, // 物料ID |
| | | ItemName = m.ItemName, // 物料名称 |
| | | ItemModel = m.ItemModel, // 规格型号 |
| | | BillNo = b.BillNo // 到货单号 |
| | | }) |
| | | .ToList(); |
| | | // 移除到货单号校验,直接返回查询结果 |
| | | return materialInfo; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"查询物料信息失败: {ex.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 查询破坏实验记录是否存在 |
| | | /// </summary> |
| | | /// <param name="billNo">到货单号</param> |
| | | /// <param name="releaseNo">检验单号</param> |
| | | /// <returns>是否存在记录</returns> |
| | | public bool CheckPhsyRecordExists(string billNo, string releaseNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | var count = db.Queryable<MesInvPhsy>() |
| | | .Where(x => x.BillNo == billNo && x.ReleaseNo == releaseNo) |
| | | .Count(); |
| | | |
| | | return count > 0; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"查询破坏实验记录失败: {ex.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 获取破坏实验记录详细信息 |
| | | /// </summary> |
| | | /// <param name="billNo">到货单号</param> |
| | | /// <param name="releaseNo">检验单号</param> |
| | | /// <returns>破坏实验记录信息</returns> |
| | | public List<PhsyRecordInfoDto> GetPhsyRecordInfo(string billNo, string releaseNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | // 先查询破坏实验记录 |
| | | var phsyRecords = db.Queryable<MesInvPhsy>() |
| | | .Where(x => x.BillNo == billNo && x.ReleaseNo == releaseNo) |
| | | .ToList(); |
| | | var result = new List<PhsyRecordInfoDto>(); |
| | | |
| | | foreach (var record in phsyRecords) |
| | | { |
| | | // 尝试通过条码查询物料信息 |
| | | var materialInfo = db.Queryable<MesInvItemBarcodes>() |
| | | .LeftJoin<MesItems>((b, m) => b.ItemId == m.Id) |
| | | .Where((b, m) => b.ItemBarcode == record.ItemBarcode) |
| | | .Select((b, m) => new { |
| | | ItemNo = b.ItemNo, |
| | | ItemName = m.ItemName, |
| | | ItemModel = m.ItemModel |
| | | }) |
| | | .First(); |
| | | var dto = new PhsyRecordInfoDto |
| | | { |
| | | ItemBarcode = record.ItemBarcode, |
| | | ItemNo = materialInfo?.ItemNo ?? record.ItemBarcode, |
| | | ItemName = materialInfo?.ItemName ?? "已记录物料", |
| | | ItemModel = materialInfo?.ItemModel ?? "已记录规格", |
| | | BillNo = record.BillNo, |
| | | Yqty = record.Yqty, |
| | | Cqty = record.Cqty, |
| | | CreateDate = record.CreateDate |
| | | }; |
| | | |
| | | result.Add(dto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"获取破坏实验记录信息失败: {ex.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 调用破坏实验存储过程 |
| | | /// </summary> |
| | | /// <param name="itemBarcode">扫描的条码值</param> |
| | | /// <param name="yqty">扫码查询出来的条码数量</param> |
| | | /// <param name="cqty">填写的破坏实验数量</param> |
| | | /// <param name="billNo">查询到的到货单号</param> |
| | | /// <param name="lx">操作类型:1新增,2修改,3删除</param> |
| | | /// <param name="releaseNo">检验单号</param> |
| | | /// <param name="itemId">物料ID</param> |
| | | /// <returns>执行结果</returns> |
| | | public (int result, string message) CallPhsyUpdateProcedure(string itemBarcode, decimal yqty, decimal cqty, string billNo, int lx, string releaseNo, decimal? itemId = null) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | // 定义输入参数 |
| | | var inputParam1 = new SugarParameter("P_ITEM_BARCODE", itemBarcode, DbType.String, ParameterDirection.Input); |
| | | var inputParam2 = new SugarParameter("P_YQTY", yqty, DbType.Decimal, ParameterDirection.Input); |
| | | var inputParam3 = new SugarParameter("P_CQTY", cqty, DbType.Decimal, ParameterDirection.Input); |
| | | var inputParam4 = new SugarParameter("P_BILL_NO", billNo, DbType.String, ParameterDirection.Input); |
| | | var inputParam5 = new SugarParameter("P_LX", lx, DbType.Int32, ParameterDirection.Input); |
| | | var inputParam6 = new SugarParameter("ITEM_ID", itemId ?? 0, DbType.Decimal, ParameterDirection.Input); |
| | | var inputParam7 = new SugarParameter("P_RELEASE_NO", releaseNo, DbType.String, ParameterDirection.Input); |
| | | |
| | | // 定义输出参数 |
| | | var outputResult = new SugarParameter("PO_RESULT", null, DbType.Int32, ParameterDirection.Output); |
| | | var outputMessage = new SugarParameter("PO_MSG", null, DbType.String, ParameterDirection.Output, 4000); |
| | | // 使用SqlSugar执行存储过程 |
| | | db.Ado.ExecuteCommand("BEGIN PRC_INV_PHSYUPDATE(:P_ITEM_BARCODE, :P_YQTY, :P_CQTY, :P_BILL_NO, :P_LX, :ITEM_ID, :P_RELEASE_NO, :PO_RESULT, :PO_MSG); END;", |
| | | inputParam1, inputParam2, inputParam3, inputParam4, inputParam5, inputParam6, inputParam7, outputResult, outputMessage); |
| | | // 获取输出参数的值 |
| | | var result = outputResult.Value == null ? 1 : Convert.ToInt32(outputResult.Value); |
| | | var message = outputMessage.Value?.ToString() ?? ""; |
| | | return (result, message); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"调用存储过程失败: {ex.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 设置堵穴信息 |
| | | /// </summary> |
| | | /// <param name="releaseNo">检验单号</param> |
| | | /// <param name="blockedHoles">堵穴信息,格式如"1,2,3"</param> |
| | | /// <param name="itemId">检验项目ID</param> |
| | | /// <returns>执行结果</returns> |
| | | public (int result, string message) SetBlockedHoles(string releaseNo, string blockedHoles, decimal itemId) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | // 解析堵穴信息 |
| | | var blockedHolesList = blockedHoles.Split(',', ',') |
| | | .Select(s => s.Trim()) |
| | | .Where(s => !string.IsNullOrEmpty(s)) |
| | | .Select(s => int.Parse(s)) |
| | | .ToList(); |
| | | // 获取检验项目信息 |
| | | var item = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(x => x.Id == itemId && x.ReleaseNo == releaseNo) |
| | | .First(); |
| | | if (item == null) |
| | | { |
| | | return (1, "检验项目不存在"); |
| | | } |
| | | // 解析开穴数 |
| | | var holeCount = ParseHoleCount(item.FcheckItem); |
| | | if (holeCount == 0) |
| | | { |
| | | return (1, "该检验项目没有穴数信息"); |
| | | } |
| | | // 验证堵穴数量不能大于等于开穴数 |
| | | if (blockedHolesList.Count >= holeCount) |
| | | { |
| | | return (1, $"堵穴数量不能大于等于开穴数({holeCount})"); |
| | | } |
| | | // 验证堵穴号是否在有效范围内 |
| | | foreach (var hole in blockedHolesList) |
| | | { |
| | | if (hole < 1 || hole > holeCount) |
| | | { |
| | | return (1, $"堵穴号必须在1-{holeCount}之间"); |
| | | } |
| | | } |
| | | // 计算新的检验数量 |
| | | var newCheckQyt = item.CheckQyt - (item.CheckQyt / holeCount) * blockedHolesList.Count; |
| | | // 更新数据库 |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | return db.Updateable<MesQaItemsDetectDetail5>() |
| | | .SetColumns(x => x.Dnum == blockedHoles) |
| | | .SetColumns(x => x.CheckQyt == newCheckQyt) |
| | | .Where(x => x.Id == itemId && x.ReleaseNo == releaseNo) |
| | | .ExecuteCommand(); |
| | | }); |
| | | if (result > 0) |
| | | { |
| | | return (0, "堵穴设置成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "堵穴设置失败"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"设置堵穴失败: {ex.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 解析检验项目名称中的穴数 |
| | | /// </summary> |
| | | /// <param name="checkItemName">检验项目名称</param> |
| | | /// <returns>穴数,如果没有穴数信息返回0</returns> |
| | | private int ParseHoleCount(string checkItemName) |
| | | { |
| | | if (string.IsNullOrEmpty(checkItemName)) |
| | | return 0; |
| | | // 匹配格式:尺寸检查(5穴)或 尺寸检查(5穴) |
| | | var match = System.Text.RegularExpressions.Regex.Match(checkItemName, @"[((](\d+)穴[))]"); |
| | | return match.Success ? int.Parse(match.Groups[1].Value) : 0; |
| | | } |
| | | |
| | | } |