From 3b3d2378bd52268dad426c70b853473eccee3b87 Mon Sep 17 00:00:00 2001 From: xwt <2740516069@qq.com> Date: 星期一, 15 九月 2025 09:24:03 +0800 Subject: [PATCH] 首检穴模数 --- StandardInterface/MES.Service/service/QC/XJService.cs | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 300 insertions(+), 57 deletions(-) diff --git a/StandardInterface/MES.Service/service/QC/XJService.cs b/StandardInterface/MES.Service/service/QC/XJService.cs index efcf669..0d1564e 100644 --- a/StandardInterface/MES.Service/service/QC/XJService.cs +++ b/StandardInterface/MES.Service/service/QC/XJService.cs @@ -71,21 +71,43 @@ }).OrderBy("b.LINE_NO").ToList(); } - public List<Womdaa> getDaa001(string daa020, string item) + public List<Womdaa> getDaa001(string daa020) { var db = SqlSugarHelper.GetInstance(); - return db.Queryable<Womdaa, MesItems>((a, b) => - new JoinQueryInfos(JoinType.Inner, a.Daa002 == b.Id.ToString())) - .Where((a, b) => - a.Daa015 == daa020 && - b.ItemNo == item && - statusArray.Contains(a.Daa018)) - .Select<Womdaa>(a => new Womdaa + return db.Queryable<Womdaa>() + .Where(a => a.Daa015 == daa020 && statusArray.Contains(a.Daa018)) + .Select(a => new Womdaa { Id = a.Id, Daa001 = a.Daa001, Daa003 = a.Daa003, Daa008 = a.Daa008 + }).ToList(); + } + + /// <summary> + /// 鑾峰彇宸ュ崟璇︾粏淇℃伅锛堝寘鍚墿鏂欎俊鎭級 + /// </summary> + /// <param name="daa020">绾夸綋缂栧彿</param> + /// <returns>宸ュ崟鍒楄〃锛堝寘鍚墿鏂欎俊鎭級</returns> + public List<WorkOrderWithItemDto> getWorkOrderWithItem(string daa020) + { + var db = SqlSugarHelper.GetInstance(); + return db.Queryable<Womdaa, MesItems>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.Daa002 == b.Id.ToString())) + .Where((a, b) => a.Daa015 == daa020 && statusArray.Contains(a.Daa018)) + .Select((a, b) => new WorkOrderWithItemDto + { + Id = a.Id, + Daa001 = a.Daa001, + Daa002 = a.Daa002, + Daa003 = a.Daa003, + Daa008 = a.Daa008, + Daa015 = a.Daa015, + Daa020 = a.Daa020, + ItemNo = b.ItemNo, + ItemName = b.ItemName, + ItemModel = b.ItemModel }).ToList(); } @@ -119,38 +141,56 @@ lineNo = _baseService.getUserLineNo(queryObj.createUser); var totalCount = 0; - var data = db + + // 鏋勫缓鍩虹鏌ヨ - 浣跨敤LEFT JOIN閬垮厤鍥犲叧鑱旀暟鎹己澶卞鑷存煡璇笉鍒� + var query = db .Queryable<QsQaItemXj, Womdaa, MesLine, MesItems>((s, a, c, b) => new JoinQueryInfos( - JoinType.Inner, s.BillNo == a.Daa001, + JoinType.Left, s.BillNo == a.Daa001, JoinType.Left, a.Daa015 == c.LineNo, JoinType.Left, s.ItemId == b.Id ) - ) - .WhereIF(lineNo != null && lineNo.Length > 0, - (s, a, c, b) => lineNo.Contains(c.LineNo)) - .WhereIF( - StringUtil.IsNotNullOrEmpty(queryObj.result) && - "鏈畬鎴�".Equals(queryObj.result), - (s, a, c, b) => s.Fsubmit == 0) - .WhereIF( - StringUtil.IsNotNullOrEmpty(queryObj.result) && - !"鏈畬鎴�".Equals(queryObj.result), - (s, a, c, b) => s.Fsubmit != 1) - .WhereIF(id > 0, (s, a, c, b) => s.Id == id) + ); + + // 娣诲姞绾夸綋绛涢�夋潯浠� + if (lineNo != null && lineNo.Length > 0) + { + query = query.Where((s, a, c, b) => lineNo.Contains(c.LineNo)); + } + + // 娣诲姞鐘舵�佺瓫閫夋潯浠� - 鏄庣‘鍖归厤鍓嶇浼犻�掔殑鍊� + if (StringUtil.IsNotNullOrEmpty(queryObj.result)) + { + if ("鏈畬鎴�".Equals(queryObj.result)) + { + query = query.Where((s, a, c, b) => s.Fsubmit == 0); + } + else if ("宸插畬鎴�".Equals(queryObj.result)) + { + query = query.Where((s, a, c, b) => s.Fsubmit == 1); + } + } + + // 娣诲姞ID绛涢�夋潯浠� + if (id > 0) + { + query = query.Where((s, a, c, b) => s.Id == id); + } + + var data = query .Select((s, a, c, b) => new QsQaItemXj { - Daa020 = c.LineNo, + Daa020 = SqlFunc.IsNull(c.LineNo, ""), Id = s.Id, - PlanQty = a.Daa008, + PlanQty = SqlFunc.IsNull(a.Daa008, 0), CreateBy = s.CreateBy, CreateDate = s.CreateDate, ReleaseNo = s.ReleaseNo, ItemNo = s.ItemNo, BillNo = s.BillNo, - ItemName = b.ItemName, - ItemModel = b.ItemModel, + ItemName = SqlFunc.IsNull(b.ItemName, ""), + ItemModel = SqlFunc.IsNull(b.ItemModel, ""), FcheckBy = s.FcheckBy, FcheckResu = s.FcheckResu, Remarks = s.Remarks @@ -259,6 +299,7 @@ xj.CreateBy = userNo; xj.CreateDate = DateTime.Now; + xj.Fsubmit = 0; // 璁剧疆榛樿鐘舵�佷负鏈彁浜� var pid = db.Insertable(xj).ExecuteReturnIdentity(); @@ -273,8 +314,10 @@ return commit; }); + // 閲嶆柊鑾峰彇妫�楠岄」鐩紙鍖呭惈ID锛� xjDto.items = getJYItem(xj.Id, null); + // 鑷姩涓烘病鏈変笂涓嬮檺鐨勬楠岄」鐩敓鎴愰粯璁ょ殑鍚堟牸璁板綍 xjDto.items.ForEach(s => { if (s.MaxValue != null || s.StandardValue != null || @@ -288,6 +331,9 @@ detail.count = (int?)s.LevelNum; SetQSItemDetail(detail); }); + + // 閲嶆柊鑾峰彇妫�楠岄」鐩紙鍖呭惈鑷姩鐢熸垚鐨勭粨鏋滐級 + xjDto.items = getJYItem(xj.Id, null); return Convert.ToInt32(xj.Id); } @@ -563,39 +609,24 @@ { try { - // 瀹氫箟杈撳嚭鍙傛暟 - var outputResult = new SugarParameter("c_res", null, - System.Data.DbType.Int32, ParameterDirection.Output, - 4000); - - var outputMessage = new SugarParameter("c_msg", null, - System.Data.DbType.String, - ParameterDirection.Output, 4000); - - // 瀹氫箟杈撳叆鍙傛暟锛屽浐瀹欶LAG涓�1锛堝鏍革級 - var parameters = new List<SugarParameter> - { - new("P_ID", dto.id, System.Data.DbType.Decimal, ParameterDirection.Input), - new("P_FLAG", 1, System.Data.DbType.Int32, ParameterDirection.Input), - new("P_USER", dto.userNo, System.Data.DbType.String, ParameterDirection.Input), - outputResult, - outputMessage - }; - var db = SqlSugarHelper.GetInstance(); + + // 鐩存帴鏇存柊Fsubmit瀛楁涓�1锛堝凡鎻愪氦鐘舵�侊級 + var result = db.Updateable<QsQaItemXj>() + .SetColumns(s => s.Fsubmit == 1) + .SetColumns(s => s.FsubmitBy == dto.userNo) + .SetColumns(s => s.FsubmitDate == DateTime.Now) + .Where(s => s.Id == dto.id) + .ExecuteCommand(); - // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼ - db.Ado.ExecuteCommand( - "BEGIN PRC_WOMDAA_XJ_UPDATE_RES(:P_ID, :P_FLAG, :P_USER, :c_res, :c_msg); END;", - parameters.ToArray()); - - // 鑾峰彇杈撳嚭鍙傛暟鐨勫�� - var resultValue = outputResult.Value?.ToString(); - var messageValue = outputMessage.Value?.ToString(); - - if ("1".Equals(resultValue)) throw new Exception(messageValue); - - return true; + if (result > 0) + { + return true; + } + else + { + throw new Exception("鎻愪氦澶辫触锛氭湭鎵惧埌瀵瑰簲鐨勬楠屽崟"); + } } catch (Exception ex) { @@ -672,4 +703,216 @@ .OrderBy(line => line.LineNo) .ToList(); } + + /// <summary> + /// 鑾峰彇闄勪欢淇℃伅 + /// </summary> + /// <param name="itemNo">鐗╂枡缂栫爜</param> + /// <returns>闄勪欢鍒楄〃</returns> + public List<QamftpDto> GetAttachments(string itemNo) + { + var db = SqlSugarHelper.GetInstance(); + try + { + return db.Queryable<MesQamftp>() + .Where(x => x.ItemNo == itemNo) + .OrderBy(x => x.Fdate, 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}"); + } + } + + /// <summary> + /// 浠嶧TP鏈嶅姟鍣ㄨ幏鍙栨枃浠讹紙宸℃浣跨敤OPC鐩綍锛� + /// </summary> + /// <param name="itemNo">鐗╂枡缂栫爜</param> + /// <param name="fileName">鏂囦欢鍚�</param> + /// <param name="ftpServer">FTP鏈嶅姟鍣ㄥ湴鍧�</param> + /// <returns>鏂囦欢瀛楄妭鏁扮粍</returns> + 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"; + + // 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧� + string normalizedServer = NormalizeFtpServer(ftpServer); + + // 鏋勫缓FTP鏂囦欢璺緞 - 宸℃浣跨敤OPC鐩綍 + string ftpPath = $"{normalizedServer}/OPC/{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}"); + } + } + + /// <summary> + /// 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧� + /// </summary> + /// <param name="ftpServer">FTP鏈嶅姟鍣ㄥ湴鍧�</param> + /// <returns>鏍囧噯鍖栧悗鐨凢TP鏈嶅姟鍣ㄥ湴鍧�</returns> + private string NormalizeFtpServer(string ftpServer) + { + if (string.IsNullOrEmpty(ftpServer)) + { + throw new ArgumentException("FTP鏈嶅姟鍣ㄥ湴鍧�涓嶈兘涓虹┖"); + } + + // 纭繚浠tp://寮�澶� + 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; + } + + /// <summary> + /// 鑾峰彇鏂囦欢鐨勫唴瀹圭被鍨� + /// </summary> + /// <param name="fileName">鏂囦欢鍚�</param> + /// <returns>MIME绫诲瀷</returns> + 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", + ".log" => "text/plain", + ".md" => "text/markdown", + ".html" or ".htm" => "text/html", + ".css" => "text/css", + ".js" => "application/javascript", + ".json" => "application/json", + ".xml" => "application/xml", + + // 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", + + // 鍏朵粬甯歌鏍煎紡 + ".csv" => "text/csv", + ".zip" => "application/zip", + ".rar" => "application/x-rar-compressed", + ".7z" => "application/x-7z-compressed", + ".tar" => "application/x-tar", + ".gz" => "application/gzip", + + // 榛樿 + _ => "application/octet-stream" + }; + } + + } \ No newline at end of file -- Gitblit v1.9.3