| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System.Threading.Tasks; |
| | | using gdbg.Models; |
| | | using gdbg.Services; |
| | | using System.Collections.Generic; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Oracle.ManagedDataAccess.Client; |
| | | using gdbg.Models; |
| | | using System.Collections.Generic; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace gdbg.Controllers |
| | | { |
| | |
| | | try |
| | | { |
| | | // 修改 SQL 查询以返回更多字段 |
| | | string query = "SELECT ITEM_BARCODE, TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') AS PRINT_DATE, b.STAFF_NAME,a.quantity " + |
| | | "FROM MES_INV_ITEM_BARCODES a left join MES_STAFF b on a.CREATE_BY=b.STAFF_NO " + |
| | | string query = |
| | | |
| | | " SELECT a.ITEM_BARCODE, TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') AS PRINT_DATE, bgr.bgr, a.quantity " + |
| | | " FROM MES_INV_ITEM_BARCODES a left join(select case when sta.STAFF_NAME is null then a.CREATE_BY else sta.STAFF_NAME end bgr,a.ITEM_BARCODE " + |
| | | " from MES_WORK_PROD_C_DETAILS a left join mes_staff sta on a.CREATE_BY = sta.STAFF_NO) bgr on bgr.ITEM_BARCODE = a.ITEM_BARCODE " + |
| | | " left join MES_STAFF b on a.CREATE_BY = b.STAFF_NO " + |
| | | "WHERE BILL_NO = :orderNo and TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD')<=to_char(SYSDATE,'YYYY-MM-DD') and TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD')>=to_char(SYSDATE-2,'YYYY-MM-DD') " + |
| | | "order by a.CREATE_DATE desc"; |
| | | |
| | |
| | | // 其他 Oracle 错误 |
| | | return StatusCode(500, new |
| | | { |
| | | message = "数据库错误:" + ex.Message |
| | | // message = "数据库错误:" + ex.Message |
| | | message = ExtractErrorMessage(ex.Message) |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | // 如果无法匹配,则返回完整错误信息 |
| | | return oracleMessage; |
| | | }*/ |
| | | private static string ExtractErrorMessage(string oracleMessage) |
| | | /* private static string ExtractErrorMessage(string oracleMessage) |
| | | { |
| | | // 匹配多个 ORA-20002: 后的段落,提取最后一个 |
| | | var matches = System.Text.RegularExpressions.Regex.Matches( |
| | |
| | | |
| | | // 默认返回原始错误 |
| | | return oracleMessage; |
| | | }*/ |
| | | |
| | | |
| | | private static string ExtractErrorMessage(string oracleMessage) |
| | | { |
| | | // 匹配所有 ORA-20002: 错误段 |
| | | var matches = Regex.Matches(oracleMessage, @"ORA-20002:\s*(.*?)(?=(ORA-\d{5}:|$))", RegexOptions.Singleline); |
| | | |
| | | if (matches.Count > 0) |
| | | { |
| | | // 返回最里面一条(最后一个) |
| | | string raw = matches[matches.Count - 1].Groups[1].Value; |
| | | |
| | | // 去掉类似 "Error in PrintAndUpdate procedure:" 开头 |
| | | string cleaned = Regex.Replace(raw, @"^Error.*?:", "", RegexOptions.IgnoreCase).Trim(); |
| | | |
| | | return string.IsNullOrWhiteSpace(cleaned) ? raw.Trim() : cleaned; |
| | | } |
| | | |
| | | return oracleMessage; // fallback |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |