| | |
| | | using System.Data; |
| | | using System.Xml; |
| | | using Masuit.Tools; |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.service; |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | using Tea.Utils; |
| | | using DbType = System.Data.DbType; |
| | | |
| | | |
| | |
| | | |
| | | var totalCount = 0; |
| | | |
| | | //var itemIds = GetQaItem(db, queryObj.createUser); |
| | | |
| | | var pageList = db.Queryable<LtsLlj>() |
| | | var pageList = db.Queryable<LtsLlj, IqcBefore, SysUser, |
| | | IqcBeforeFrom, SysUser, SysUser>((a, b, |
| | | e, f, g, i) => |
| | | new JoinQueryInfos(JoinType.Left, a.ItemId == b.ItemId, |
| | | JoinType.Left, a.CreateBy == e.Fcode, |
| | | JoinType.Left, f.Id == b.Pid, |
| | | JoinType.Left, f.Sid == Convert.ToDecimal(g.Fid), |
| | | JoinType.Left, f.CheckUser == i.Fcode |
| | | )) |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.result) && |
| | | "未完成".Equals(queryObj.result), |
| | | a => a.FcheckResu == null) |
| | | (a, b, |
| | | e, f, g, i) => a.FcheckResu == null) |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.result) && |
| | | !"未完成".Equals(queryObj.result), |
| | | a => a.FcheckResu != null) |
| | | .WhereIF(id > 0, a => a.Id == id) |
| | | (a, b, |
| | | e, f, g, i) => a.FcheckResu != null) |
| | | .WhereIF(id > 0, (a, b, |
| | | e, f, g, i) => a.Id == id) |
| | | .WhereIF(queryObj.createUser != "PL017" && queryObj.UserIndex == "0", (a, b, |
| | | e, f, g, i) => (g.Fcode == queryObj.createUser || i.Fcode == queryObj.createUser || |
| | | (g.Fcode == null && i.Fcode == null)))//判断此单的检验员,或者检验为空就显示此单据 |
| | | |
| | | //加筛选条件,根据供应商,物料编码,物料名称搜索 |
| | | //.WhereIF(queryObj.SearchValue!=null && queryObj.SearchValue!="", (a) => a.SuppName == queryObj.SearchValue|| a.ItemName == queryObj.SearchValue || a.ItemNo == queryObj.SearchValue ) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue), |
| | | a => a.SuppName.ToLower() |
| | | (a, b, |
| | | e, f, g, i) => a.SuppName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | | || a.ItemName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | |
| | | || a.LotNo.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | | || a.ReleaseNo.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | | || a.ItemModel.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower())) |
| | | .OrderByDescending(a => a.Id) |
| | | .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); |
| | | // .OrderByDescending((a, b, |
| | | |
| | | .OrderBy("CASE WHEN a.EMERGENCY = 1 THEN 0 ELSE 1 END, CASE WHEN a.STATUS = '已提交' THEN 0 ELSE 1 END, a.IQC_DATE desc, a.ID asc") |
| | | .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); |
| | | |
| | | var emergencyValues = pageList.Select(item => item.EMERGENCY).ToList(); |
| | | return (pageList, totalCount); |
| | | } |
| | | |
| | |
| | | return msg; |
| | | |
| | | } |
| | | //紧急放行 |
| | | //public string[] EmergencyRelease(int id) |
| | | //{ |
| | | // var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | |
| | | // int emergencyStatus = db.Queryable<MesQaItemsDetect01>() |
| | | // .Where(t => t.Id == id) |
| | | // .Select(t => t.EMERGENCY) |
| | | // .First(); |
| | | |
| | | // if (emergencyStatus != 0) |
| | | // { |
| | | // return new string[] { "1", "非紧急状态,无法执行紧急放行" }; |
| | | // } |
| | | |
| | | |
| | | // var outputResult = new SugarParameter("PO_RESULT", null, |
| | | // DbType.Int32, ParameterDirection.Output, 4000); |
| | | |
| | | // var outputMessage = new SugarParameter("PO_MSG", null, |
| | | // DbType.String, ParameterDirection.Output, 4000); |
| | | |
| | | // var parameters = new List<SugarParameter> |
| | | //{ |
| | | // new("P_ID", id, DbType.Int32, ParameterDirection.Input), |
| | | // outputResult, |
| | | // outputMessage |
| | | //}; |
| | | |
| | | // db.Ado.ExecuteCommand( |
| | | // "BEGIN prc_MES_QA_ITEMS_update1(:P_ID, :PO_RESULT, :PO_MSG); END;", |
| | | // parameters.ToArray()); |
| | | |
| | | // var lotNo1 = db.Queryable<MesQaItemsDetect01>() |
| | | // .Where(t => t.Id == id) |
| | | // .Select(t => t.LotNo1) |
| | | // .First(); |
| | | |
| | | // var resultValue = outputResult.Value?.ToString(); |
| | | // var messageValue = outputMessage.Value?.ToString(); |
| | | // return new string[] { resultValue, messageValue, lotNo1?.ToString() ?? "" }; |
| | | //} |
| | | |
| | | //public string[] WithdrawEmergencyRelease(int id) |
| | | //{ |
| | | // var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | |
| | | // int emergencyStatus = db.Queryable<MesQaItemsDetect01>() |
| | | // .Where(t => t.Id == id) |
| | | // .Select(t => t.EMERGENCY) |
| | | // .First(); |
| | | |
| | | // if (emergencyStatus != 0) |
| | | // { |
| | | // return new string[] { "1", "非紧急状态,无需撤回" }; |
| | | // } |
| | | |
| | | // var outputResult = new SugarParameter("PO_RESULT", null, |
| | | // DbType.Int32, ParameterDirection.Output, 4000); |
| | | |
| | | // var outputMessage = new SugarParameter("PO_MSG", null, |
| | | // DbType.String, ParameterDirection.Output, 4000); |
| | | |
| | | // var parameters = new List<SugarParameter> |
| | | //{ |
| | | // new("P_ID", id, DbType.Int32, ParameterDirection.Input), |
| | | // outputResult, |
| | | // outputMessage |
| | | //}; |
| | | |
| | | // db.Ado.ExecuteCommand( |
| | | // "BEGIN prc_MES_QA_ITEMS_update2(:P_ID, :PO_RESULT, :PO_MSG); END;", |
| | | // parameters.ToArray()); |
| | | |
| | | // var lotNo1 = db.Queryable<MesQaItemsDetect01>() |
| | | // .Where(t => t.Id == id) |
| | | // .Select(t => t.LotNo1) |
| | | // .First(); |
| | | |
| | | |
| | | // var resultValue = outputResult.Value?.ToString(); |
| | | // var messageValue = outputMessage.Value?.ToString(); |
| | | // return new string[] { resultValue, messageValue, lotNo1?.ToString() ?? "" }; |
| | | //} |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public string[] EmergencyRelease(int id) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | |
| | | int emergencyStatus = db.Queryable<MesQaItemsDetect01>() |
| | | .Where(t => t.Id == id) |
| | | .Select(t => t.EMERGENCY) |
| | | .First(); |
| | | |
| | | if (emergencyStatus != 0) |
| | | { |
| | | return new string[] { "1", "非紧急状态,无法执行紧急放行" }; |
| | | } |
| | | |
| | | |
| | | var outputResult = new SugarParameter("PO_RESULT", null, |
| | | DbType.Int32, ParameterDirection.Output, 4000); |
| | | |
| | | var outputMessage = new SugarParameter("PO_MSG", null, |
| | | DbType.String, ParameterDirection.Output, 4000); |
| | | |
| | | var parameters = new List<SugarParameter> |
| | | { |
| | | new("P_ID", id, DbType.Int32, ParameterDirection.Input), |
| | | outputResult, |
| | | outputMessage |
| | | }; |
| | | |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN prc_MES_QA_ITEMS_update1(:P_ID, :PO_RESULT, :PO_MSG); END;", |
| | | parameters.ToArray()); |
| | | |
| | | var lotNo1 = db.Queryable<MesQaItemsDetect01>() |
| | | .Where(t => t.Id == id) |
| | | .Select(t => t.LotNo1) |
| | | .First(); |
| | | |
| | | var resultValue = outputResult.Value?.ToString(); |
| | | var messageValue = outputMessage.Value?.ToString(); |
| | | return new string[] { resultValue, messageValue, lotNo1?.ToString() ?? "" }; |
| | | } |
| | | |
| | | public string[] WithdrawEmergencyRelease(int id) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | |
| | | int emergencyStatus = db.Queryable<MesQaItemsDetect01>() |
| | | .Where(t => t.Id == id) |
| | | .Select(t => t.EMERGENCY) |
| | | .First(); |
| | | |
| | | if (emergencyStatus != 0) |
| | | { |
| | | return new string[] { "1", "非紧急状态,无需撤回" }; |
| | | } |
| | | |
| | | var outputResult = new SugarParameter("PO_RESULT", null, |
| | | DbType.Int32, ParameterDirection.Output, 4000); |
| | | |
| | | var outputMessage = new SugarParameter("PO_MSG", null, |
| | | DbType.String, ParameterDirection.Output, 4000); |
| | | |
| | | var parameters = new List<SugarParameter> |
| | | { |
| | | new("P_ID", id, DbType.Int32, ParameterDirection.Input), |
| | | outputResult, |
| | | outputMessage |
| | | }; |
| | | |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN prc_MES_QA_ITEMS_update2(:P_ID, :PO_RESULT, :PO_MSG); END;", |
| | | parameters.ToArray()); |
| | | |
| | | var lotNo1 = db.Queryable<MesQaItemsDetect01>() |
| | | .Where(t => t.Id == id) |
| | | .Select(t => t.LotNo1) |
| | | .First(); |
| | | |
| | | |
| | | var resultValue = outputResult.Value?.ToString(); |
| | | var messageValue = outputMessage.Value?.ToString(); |
| | | return new string[] { resultValue, messageValue, lotNo1?.ToString() ?? "" }; |
| | | } |
| | | |
| | | private string ExtractSubstring(string input, char startChar, char endChar) |
| | | { |
| | |
| | | return input.Substring(startIndex + 1, length); |
| | | } |
| | | |
| | | public List<QamftpDto> GetAttachments(string ItemNo) |
| | | { |
| | | if (string.IsNullOrEmpty(ItemNo)) |
| | | { |
| | | throw new ArgumentException("检验单号不能为空"); |
| | | } |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | return db.Queryable<MesQamftp>() |
| | | .Where(x => x.ItemNo == ItemNo) |
| | | .OrderBy(x => x.Fdate, OrderByType.Desc) |
| | | // .ThenBy(x => x.CreateDate, OrderByType.Desc) |
| | | .Select(x => new QamftpDto |
| | | { |
| | | Id = x.Id, |
| | | itemNo = x.ItemNo, |
| | | Ftype = x.Ftype, |
| | | Fattach = x.Fattach, |
| | | Fversion = x.Fversion, |
| | | Fdate = x.Fdate, |
| | | CreateBy = x.CreateBy, |
| | | CreateDate = x.CreateDate, |
| | | Company = x.Company, |
| | | Factory = x.Factory, |
| | | |
| | | F_type = x.F_type, |
| | | LastupdateBy = x.LastupdateBy, |
| | | LastupdateDate = x.LastupdateDate, |
| | | ItemId = x.ItemId |
| | | }).ToList(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"查询附件信息失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer)) |
| | | { |
| | | throw new ArgumentException("参数不能为空: itemNo, fileName, ftpServer"); |
| | | } |
| | | |
| | | string ftpUser = "hm_ftp"; |
| | | string ftpPwd = "dell_123"; |
| | | |
| | | // 标准化FTP服务器地址 |
| | | string normalizedServer = NormalizeFtpServer(ftpServer); |
| | | |
| | | // 构建FTP文件路径 |
| | | string ftpPath = $"{normalizedServer}/IQC/{itemNo}/{fileName}"; |
| | | |
| | | try |
| | | { |
| | | var request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpPath); |
| | | request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; |
| | | request.Credentials = new System.Net.NetworkCredential(ftpUser, ftpPwd); |
| | | request.UseBinary = true; |
| | | request.UsePassive = false; |
| | | request.Timeout = 30000; // 30秒超时 |
| | | request.ReadWriteTimeout = 30000; |
| | | |
| | | using (var response = (System.Net.FtpWebResponse)request.GetResponse()) |
| | | using (var ftpStream = response.GetResponseStream()) |
| | | using (var ms = new System.IO.MemoryStream()) |
| | | { |
| | | if (ftpStream == null) |
| | | { |
| | | throw new Exception("FTP响应流为空"); |
| | | } |
| | | |
| | | ftpStream.CopyTo(ms); |
| | | var fileBytes = ms.ToArray(); |
| | | |
| | | if (fileBytes.Length == 0) |
| | | { |
| | | return null; // 文件为空或不存在 |
| | | } |
| | | |
| | | return fileBytes; |
| | | } |
| | | } |
| | | catch (System.Net.WebException ex) |
| | | { |
| | | if (ex.Response is System.Net.FtpWebResponse ftpResponse) |
| | | { |
| | | switch (ftpResponse.StatusCode) |
| | | { |
| | | case System.Net.FtpStatusCode.ActionNotTakenFileUnavailable: |
| | | return null; // 文件不存在 |
| | | case System.Net.FtpStatusCode.NotLoggedIn: |
| | | throw new Exception("FTP认证失败,请检查用户名和密码"); |
| | | case System.Net.FtpStatusCode.ActionNotTakenFilenameNotAllowed: |
| | | throw new Exception("文件名不被允许或路径无效"); |
| | | default: |
| | | throw new Exception($"FTP错误 ({ftpResponse.StatusCode}): {ftpResponse.StatusDescription}"); |
| | | } |
| | | } |
| | | |
| | | // 处理超时和网络错误 |
| | | if (ex.Status == System.Net.WebExceptionStatus.Timeout) |
| | | { |
| | | throw new Exception("FTP连接超时,请稍后重试"); |
| | | } |
| | | |
| | | throw new Exception($"FTP连接失败: {ex.Message}"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"获取文件失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | private string NormalizeFtpServer(string ftpServer) |
| | | { |
| | | if (string.IsNullOrEmpty(ftpServer)) |
| | | { |
| | | throw new ArgumentException("FTP服务器地址不能为空"); |
| | | } |
| | | |
| | | // 确保以ftp://开头 |
| | | string normalizedServer = ftpServer.StartsWith("ftp://") ? ftpServer : $"ftp://{ftpServer}"; |
| | | |
| | | // 特殊处理已知服务器地址 |
| | | if (normalizedServer == "ftp://36.26.21.214") |
| | | { |
| | | normalizedServer = "ftp://36.26.21.214:21"; |
| | | } |
| | | else if (!normalizedServer.Contains(":") && normalizedServer.StartsWith("ftp://")) |
| | | { |
| | | normalizedServer += ":21"; // 默认FTP端口 |
| | | } |
| | | |
| | | // 开发环境使用本地服务器 |
| | | normalizedServer = "ftp://192.168.1.22:21"; |
| | | |
| | | return normalizedServer; |
| | | } |
| | | |
| | | public string GetContentType(string fileName) |
| | | { |
| | | if (string.IsNullOrEmpty(fileName)) |
| | | return "application/octet-stream"; |
| | | |
| | | var extension = System.IO.Path.GetExtension(fileName).ToLower(); |
| | | |
| | | return extension switch |
| | | { |
| | | // PDF文件 |
| | | ".pdf" => "application/pdf", |
| | | |
| | | // 图片文件 |
| | | ".jpg" or ".jpeg" => "image/jpeg", |
| | | ".png" => "image/png", |
| | | ".gif" => "image/gif", |
| | | ".bmp" => "image/bmp", |
| | | ".webp" => "image/webp", |
| | | ".svg" => "image/svg+xml", |
| | | ".ico" => "image/x-icon", |
| | | |
| | | // 文本文件 |
| | | ".txt" => "text/plain; charset=utf-8", |
| | | ".log" => "text/plain; charset=utf-8", |
| | | ".md" => "text/markdown; charset=utf-8", |
| | | ".csv" => "text/csv; charset=utf-8", |
| | | ".xml" => "text/xml; charset=utf-8", |
| | | ".json" => "application/json; charset=utf-8", |
| | | |
| | | // Office文档 |
| | | ".doc" => "application/msword", |
| | | ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", |
| | | ".xls" => "application/vnd.ms-excel", |
| | | ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", |
| | | ".ppt" => "application/vnd.ms-powerpoint", |
| | | ".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", |
| | | |
| | | // 压缩文件 |
| | | ".zip" => "application/zip", |
| | | ".rar" => "application/x-rar-compressed", |
| | | ".7z" => "application/x-7z-compressed", |
| | | |
| | | // 其他常见格式 |
| | | ".dwg" => "application/acad", |
| | | ".dxf" => "application/dxf", |
| | | ".step" or ".stp" => "application/step", |
| | | ".iges" or ".igs" => "application/iges", |
| | | |
| | | // 默认二进制流 |
| | | _ => "application/octet-stream" |
| | | }; |
| | | } |
| | | public int saveItem(LLJDto rkjDto) |
| | | { |
| | | var items = rkjDto.items; |
| | |
| | | a.FreQty, |
| | | a.CheckQyt, |
| | | a.FcheckResu, |
| | | a.FcheckItemDesc |
| | | a.FcheckItemDesc, |
| | | a.Funit, |
| | | a.Meom |
| | | }).Select((a, b) => new MesQaItemsDetectDetail5 |
| | | { |
| | | Id = a.Id, |
| | |
| | | FenterQty = SqlFunc.AggregateCount(b.Id), |
| | | FcheckResu = a.FcheckResu, |
| | | // FcheckItemDesc = a.FcheckItemDesc |
| | | FcheckItemDesc = a.FspecRequ |
| | | FcheckItemDesc = a.FspecRequ, |
| | | Funit = a.Funit, |
| | | Meom = a.Meom, |
| | | }).ToList(); |
| | | } |
| | | |
| | |
| | | |
| | | return commit; |
| | | }); |
| | | |
| | | var isNull = db.Queryable<MesQaItemsDetectDetail5>() |
| | | //5.20xwt修改将更新主表检验结果字段放在IqcQaSubmit方法下 |
| | | /*var isNull = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == null) |
| | | .Count(); |
| | | |
| | |
| | | .SetColumns(s => s.LastupdateDate == DateTime.Now) |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo) |
| | | .ExecuteCommand(); |
| | | }); |
| | | });*/ |
| | | // if (FcheckResu.Equals("不合格")) |
| | | //自动生成入库检异常对策 |
| | | /// saveDetect02(detail.Id, detail.CreateBy); |
| | |
| | | return db.Updateable<MesQaItemsDetect01>() |
| | | .SetColumns(it => |
| | | it.FngDesc == dto.Remarks) //SetColumns是可以叠加的 写2个就2个字段赋值 |
| | | .SetColumns(it => it.PHSY == dto.PHSY)//破坏实验数 |
| | | .Where(it => it.ReleaseNo == dto.releaseNo) |
| | | .ExecuteCommand(); |
| | | }); |
| | |
| | | return SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | return db.Updateable<MesQaItemsDetectDetail5>() |
| | | .SetColumns(it => |
| | | it.Funit == dto.Remarks) //SetColumns是可以叠加的 写2个就2个字段赋值 |
| | | .SetColumns(it => new MesQaItemsDetectDetail5 |
| | | { |
| | | Funit = dto.Remarks, |
| | | Meom = dto.Meom |
| | | }) |
| | | .Where(it => it.Id == dto.pid) |
| | | .ExecuteCommand(); |
| | | }); |
| | |
| | | |
| | | if ("1".Equals(resultValue)) throw new Exception(messageValue); |
| | | |
| | | var sum = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == dto.releaseNo).Count(); |
| | | |
| | | if (sum == 0) return true; |
| | | |
| | | var icount = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == dto.releaseNo && s.FcheckResu == "合格") |
| | | .Count(); |
| | | |
| | | var FcheckResu = "不合格"; |
| | | |
| | | if (sum == icount) |
| | | FcheckResu = "合格"; |
| | | |
| | | var sysUser = db.Queryable<SysUser>() |
| | | .Where(s => s.Fcode == dto.userNo).First(); |
| | | |
| | | SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | return db.Updateable<MesQaItemsDetect01>() |
| | | .SetColumns(s => s.FcheckResu == FcheckResu) |
| | | .SetColumns(s => s.FcheckDate == DateTime.Now) |
| | | .SetColumns(s => s.FcheckBy == sysUser.Fname) |
| | | .SetColumns(s => s.LastupdateBy == dto.userNo) |
| | | .SetColumns(s => s.LastupdateDate == DateTime.Now) |
| | | .Where(s => s.ReleaseNo == dto.releaseNo) |
| | | .ExecuteCommand(); |
| | | }); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |