From 2d5b72c1cc9988ad148b4dd366f66b3bf6e058fe Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 23 Feb 2023 23:16:04 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95KeyParts?= =?UTF-8?q?=E6=9F=A5=E8=AF=A22=201.1.=E7=BB=84=E4=BB=B6=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9A=84=E6=A0=87=E9=A2=98=E6=94=B9=E7=94=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=201.2.=E6=9F=A5=E8=AF=A22=E9=87=87=E7=94=A8?= =?UTF-8?q?=E6=96=B0=E7=9A=84webapi=EF=BC=8CGetWipInfo4QRS017?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/QRSController.cs | 52 +++- AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 11 + .../Controllers/AMES/WipInfosController.cs | 291 +++++++++++++++++- 3 files changed, 348 insertions(+), 6 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/QRSController.cs b/AMESCoreStudio.Web/Controllers/QRSController.cs index 916bbdb5..38c1dc46 100644 --- a/AMESCoreStudio.Web/Controllers/QRSController.cs +++ b/AMESCoreStudio.Web/Controllers/QRSController.cs @@ -23,9 +23,10 @@ namespace AMESCoreStudio.Web.Controllers public readonly IBAS _basApi; public readonly IPCS _pcsApi; public readonly ISYS _sysApi; + public readonly IKCS _kcsApi; private readonly IWebHostEnvironment _env; - public QRSController(ILogger logger, IREP repApi, IPPS ppsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IWebHostEnvironment env) + public QRSController(ILogger logger, IREP repApi, IPPS ppsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IKCS kcsApi, IWebHostEnvironment env) { _logger = logger; _repApi = repApi; @@ -33,6 +34,7 @@ namespace AMESCoreStudio.Web.Controllers _basApi = basApi; _pcsApi = pcsApi; _sysApi = sysApi; + _kcsApi = kcsApi; _env = env; } @@ -1487,7 +1489,7 @@ namespace AMESCoreStudio.Web.Controllers { ViewData["Title"] = "查詢條件 - 工單號碼 : " + wipNO; - IResultModel result = await _pcsApi.GetWipInfo4QRS013(wipNO, null, 0, 10); + IResultModel result = await _pcsApi.GetWipInfo4QRS017(wipNO); string kpDataList = ""; if (result.DataTotal > 0) @@ -1524,6 +1526,50 @@ namespace AMESCoreStudio.Web.Controllers break; default: string kp_name = jp[i].Name.Replace("kP_", ""); + int kp_idx = kp_name.IndexOf("#"); + if (kp_idx > 0) + { + if (kp_name.StartsWith("MB") && kp_name.IndexOf("MAC") > 0) + { + string kp_no = kp_name.Replace("#", "_"); + var kp_item = await _kcsApi.GetItems(kp_no); + if (kp_item.Count > 0) + { + kpDataList = kpDataList + " " + kp_item[0].ItemName + ""; + } + else + { + kpDataList = kpDataList + " " + kp_no + ""; + } + } + else + { + string kp_no = kp_name.Substring(0, kp_idx); + var kp_item = await _kcsApi.GetItems(kp_no); + if (kp_item.Count > 0) + { + kpDataList = kpDataList + " " + kp_item[0].ItemName + ""; + } + else + { + kpDataList = kpDataList + " " + kp_no + ""; + } + } + } + else + { + var kp_item = await _kcsApi.GetItems(kp_name); + if (kp_item.Count > 0) + { + kpDataList = kpDataList + " " + kp_item[0].ItemName + ""; + } + else + { + kpDataList = kpDataList + " " + kp_name + ""; + } + + } + /* if (kp_name.IndexOf("_") > 0) { if (kp_name.StartsWith("MB") && kp_name.IndexOf("MAC") > 0) @@ -1541,6 +1587,8 @@ namespace AMESCoreStudio.Web.Controllers { kpDataList = kpDataList + " " + kp_name + ""; } + */ + break; } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index c5d59a6d..85fdb071 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -1057,6 +1057,17 @@ namespace AMESCoreStudio.Web #endregion + #region QRS017 查詢工單KeyParts + + /// + /// 查詢工單KeyParts資料QRS017 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetWipInfo4QRS017")] + ITask> GetWipInfo4QRS017(string wipNO); + + #endregion + #region QRS014 直通率 /// diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index c26679bf..bfb1d3ce 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -544,11 +544,22 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); { for (int m = 0; m < esun_table.Rows.Count; m++) { - try + if (dtItem.Rows.Count == 1) { - dtBarcode.Columns.Add("KP_MB" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()); + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "_MAC" + (m + 1).ToString()); + } + catch { } + } + else + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "_" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()); + } + catch { } } - catch { } } dtBarcode.AcceptChanges(); createMacCol = false; @@ -558,7 +569,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); for (int m = 0; m < esun_table.Rows.Count; m++) { mac = esun_table.Rows[m]["part_barcode"].ToString().Trim(); - dtBarcode.Rows[i]["KP_MB" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()] = mac; + if (dtItem.Rows.Count == 1) + { + dtBarcode.Rows[i]["KP_" + kp_no + "_MAC" + (m + 1).ToString()] = mac; + } + else + { + dtBarcode.Rows[i]["KP_" + kp_no + "_" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()] = mac; + } dtBarcode.AcceptChanges(); } } @@ -610,6 +628,271 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); return result; } + /// + /// 查詢工單KeyParts資料QRS017 + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetWipInfo4QRS017(string wipNO) + { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); + + DbConnection conn = _context.Database.GetDbConnection(); + if (conn.State != ConnectionState.Open) + { + await conn.OpenAsync(); + } + + string kp_sql = "select kp_no, count(kp_seq) as kp_qty from jhames.wip_kp where wip_no = '" + wipNO + "' group by kp_no"; + + DataTable dtKp = new DataTable(); + + using (var cmd = conn.CreateCommand()) + { + cmd.CommandText = kp_sql; + + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.HasRows) + { + dtKp = DataReaderToDataTable(reader); + } + } + } + + string sql = @" select c.wip_no as WipNo,b.barcode_no as BarcodeNo,b.extra_barcode_no as ExtraBarcodeNo,d.model_no as ModelNO,d.item_no as ItemNO"; + sql = sql + " from jhames.barcode_info b,jhames.wip_info c,jhames.wip_att d"; + sql = sql + " where b.wip_id = c.wip_id and c.wip_no = d.wip_no"; + sql = sql + " and c.wip_no = '" + wipNO + "'"; + + using (var barcode_cmd = conn.CreateCommand()) + { + barcode_cmd.CommandText = sql; + + using (var barcode_reader = await barcode_cmd.ExecuteReaderAsync()) + { + if (barcode_reader.HasRows) + { + List list = new List(); + DataTable dtBarcode = new DataTable(); + + dtBarcode = DataReaderToDataTable(barcode_reader); + + if (dtKp.Rows.Count > 0) + { + for (int i = 0; i < dtKp.Rows.Count; i++) + { + int kp_qty = int.Parse(dtKp.Rows[i]["KP_QTY"].ToString()); + string kp_no = dtKp.Rows[i]["KP_NO"].ToString(); + if (kp_qty > 1) + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no); + } + catch { } + + for (int j = 1; j < kp_qty; j++) + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#" + j.ToString()); + } + catch { } + } + } + else + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no); + } + catch { } + } + } + dtBarcode.AcceptChanges(); + + for (int i = 0; i < dtBarcode.Rows.Count; i++) + { + string barcode_no = dtBarcode.Rows[i]["BarcodeNo"].ToString(); + + //读取组件 + for (int j = 0; j < dtKp.Rows.Count; j++) + { + string kp_no = dtKp.Rows[j]["KP_NO"].ToString(); + + string barcode_item_sql = string.Format(@"select part_no from jhames.barcode_info a,jhames.barcode_item b where a.barcode_id = b.barcode_id +and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); + + using (var item_cmd = conn.CreateCommand()) + { + item_cmd.CommandText = barcode_item_sql; + + using (var item_reader = await item_cmd.ExecuteReaderAsync()) + { + if (item_reader.HasRows) + { + DataTable dtItem = new DataTable(); + dtItem = DataReaderToDataTable(item_reader); + + for (int k = 0; k < dtItem.Rows.Count; k++) + { + string part_no = dtItem.Rows[k]["PART_NO"].ToString(); + try + { + dtBarcode.Rows[i]["KP_" + kp_no + "#" + k.ToString()] = part_no; + } + catch + { + try + { + dtBarcode.Rows[i]["KP_" + kp_no] = part_no; + } + catch { } + } + + dtBarcode.AcceptChanges(); + + try + { + if (kp_no.StartsWith("MB") && !kp_no.StartsWith("MB_MAC")) + { + ESUNContext _esun_context = new ESUNContext(); + + //读取MAC + DbConnection esun_conn = _esun_context.Database.GetDbConnection(); + if (esun_conn.State != ConnectionState.Open) + { + await esun_conn.OpenAsync(); + } + + bool createMacCol = true; + + + //part_no = "91000237320038"; + + string mac_sql = string.Format(@"select distinct a.工單編號 as mo_id,e.客戶工單編號 as customer_moid,a.工單序號 as product_sn, + case substring(f.avalue_kp_typeid, 1, 3) when 'MAC' then isnull(z.item_prefix,'')+b.SUB_ITEM_SN else b.SUB_ITEM_SN end as part_barcode, + f.avalue_kp_typeid as class,c.material_id,d.r_stn as routeid,'' as workerid,rtrim(g.sn_date) + ' ' + rtrim(g.sn_time) as create_date + from or_sn_story a + left join sub_item_db b on a.工單編號 = b.or_sn and a.工單序號 = b.or_sal + left join jh_sub_item c on a.工單編號 = c.mo_id and b.class = c.part_typeid + left join jh_sub_item_prefix z on c.mo_id = z.mo_id + left join or_sub_db d on a.工單編號 = d.or_sn and b.class = d.class + join or_list e on a.工單編號 = e.工單編號 and e.[客戶] = 'EV' + left join jh_sub_item_mapping f on b.class = f.eversun_kp_typeid + join jh_sn_list g on a.工單序號 = g.sn + where g.sn_result = 'OK' + AND a.工單序號 = '{0}' + AND c.material_id LIKE 'MAC%'", part_no); + + using (var esun_cmd = esun_conn.CreateCommand()) + { + esun_cmd.CommandText = mac_sql; + esun_cmd.CommandTimeout = 0; + + using (var esun_reader = await esun_cmd.ExecuteReaderAsync()) + { + if (esun_reader.HasRows) + { + List esun_list = new List(); + DataTable esun_table = new DataTable(); + + esun_table = DataReaderToDataTable(esun_reader); + + if (esun_table.Rows.Count > 0) + { + if (createMacCol) + { + for (int m = 0; m < esun_table.Rows.Count; m++) + { + if (dtItem.Rows.Count == 1) + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#MAC" + (m + 1).ToString()); + } + catch { } + } + else + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()); + } + catch { } + } + } + dtBarcode.AcceptChanges(); + createMacCol = false; + } + + string mac = ""; + for (int m = 0; m < esun_table.Rows.Count; m++) + { + mac = esun_table.Rows[m]["part_barcode"].ToString().Trim(); + if (dtItem.Rows.Count == 1) + { + dtBarcode.Rows[i]["KP_" + kp_no + "#MAC" + (m + 1).ToString()] = mac; + } + else + { + dtBarcode.Rows[i]["KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()] = mac; + } + dtBarcode.AcceptChanges(); + } + } + } + } + } + + } + } + catch (Exception e1) + { + string err = e1.Message; + } + } + dtBarcode.AcceptChanges(); + } + } + } + } + } + } + + foreach (DataRow row in dtBarcode.Rows) + { + dynamic dyn = new ExpandoObject(); + list.Add(dyn); + foreach (DataColumn column in dtBarcode.Columns) + { + var dic = (IDictionary)dyn; + dic[column.ColumnName] = row[column]; + } + } + + result.DataTotal = list.Count(); + result.Data = list; + } + } + } + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 查詢工單KeyParts資料QRS013 ///