From d12d232dcd98e1175df94e49d1131ce83fe5c665 Mon Sep 17 00:00:00 2001 From: Yiru Date: Mon, 25 Mar 2024 22:24:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A0=B1=E5=B7=A5=E8=B3=87=E6=96=99=E6=9F=A5?= =?UTF-8?q?=E8=A9=A2=E6=98=8E=E7=B5=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/QRSController.cs | 21 ++ AMESCoreStudio.Web/HttpApis/AMES/IQRS.cs | 9 + AMESCoreStudio.Web/Views/QRS/QRS029.cshtml | 207 ++++++++++++++++++ .../Controllers/AMES/ActualTimeController.cs | 164 ++++++++++++++ 4 files changed, 401 insertions(+) create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS029.cshtml create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/ActualTimeController.cs diff --git a/AMESCoreStudio.Web/Controllers/QRSController.cs b/AMESCoreStudio.Web/Controllers/QRSController.cs index 7f2b1e15..ffe27173 100644 --- a/AMESCoreStudio.Web/Controllers/QRSController.cs +++ b/AMESCoreStudio.Web/Controllers/QRSController.cs @@ -11145,5 +11145,26 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } + + + public async Task QRS029() + { + return View(); + } + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task QRS029Query(string actualDate, int page = 0, int limit = 10) + { + IResultModel result = await _qrsApi.GetActualTimeDetails(ActualDate: actualDate, page: page, limit: limit); + + if (result.Data.Count() != 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + return Json(new Table() { code = 0, msg = "", data = null, count = 0 }); + } + } + + } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IQRS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IQRS.cs index 925b155a..b8346c57 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IQRS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IQRS.cs @@ -24,6 +24,15 @@ namespace AMESCoreStudio.Web #endregion + #region QRS029報工明細查詢 + /// + /// 獲取電動起子扭力紀錄表 + /// + /// + [WebApiClient.Attributes.HttpGet("api/ActualTime/GetActualTimeDetail")] + ITask> GetActualTimeDetails(string ActualDate, int page = 0, int limit = 10); + + #endregion } diff --git a/AMESCoreStudio.Web/Views/QRS/QRS029.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS029.cshtml new file mode 100644 index 00000000..69fd3476 --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS029.cshtml @@ -0,0 +1,207 @@ + +@{ + ViewData["Title"] = "報工明細查詢"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + + + +
+
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ + +@section Scripts{ + + +} + diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/ActualTimeController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/ActualTimeController.cs new file mode 100644 index 00000000..261f1695 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/ActualTimeController.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi; +using AMESCoreStudio.WebApi.Models.BAS; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; +using Microsoft.Extensions.Configuration; +using System.Net; +using System.Net.Mail; +using System.Data.Common; +using System.Data; +using System.Dynamic; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 報工資料檔 + /// + [Route("api/[controller]")] + [ApiController] + public class ActualTimeController : ControllerBase + { + private readonly AMESContext _context; + private readonly IConfiguration _config; + /// + /// + /// + /// + public ActualTimeController(AMESContext context) + { + _config = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); + _context = context; + } + + + /// + /// + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetActualTimeDetail(string ActualDate,int page = 0, int limit = 10) + { + DateTime date = System.DateTime.Now; + if (ActualDate != null) + date = DateTime.Parse(ActualDate); // 將字符串轉換為 DateTime 對象 + + // 獲取該月份的第一天 + DateTime firstDayOfMonth = new DateTime(date.Year, date.Month, 1); + + // 獲取該月份的最後一天 + DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); + + ResultModel result = new ResultModel(); + string sql = string.Format(@"select c.*,b.production_time as productiontime ,c.actualTimeDetail -b.production_time actualTimeDetailExcept,b.Production_cnt_sap productionCNTSAP + from ( + select a.actual_id ,To_char(a.Pass_datetime,'yyyy-mm-dd') actualDate , a.wip_no, + sum(a.a_ct) actualTime,sum(a.s_ct) ST,sum(a.rest_ct) restTime, + (sum(a.a_ct)- sum(a.rest_ct) + sum(a.s_CT)) actualTimeDetail, + case a.station_id when 0 then '人工手動' else '過站' end as TYPES,a.route + from jhames.actual_time_detail a + where to_char(a.pass_datetime ,'yyyy-MM-dd') >='{0}' and to_char(a.pass_datetime ,'yyyy-MM-dd') <='{1}' + group by a.actual_id ,To_char(a.Pass_datetime,'yyyy-mm-dd'),a.wip_no,case a.station_id when 0 then '人工手動' else '過站' end, a.route + ) c + , jhames.actual_time b where b.actual_id = c.actual_id and b.route = c.route + order by c.actualDate,c.wip_no,c.route", firstDayOfMonth.ToString("yyyy-MM-dd"), lastDayOfMonth.ToString("yyyy-MM-dd")); + + DbConnection conn = _context.Database.GetDbConnection(); + if (conn.State != System.Data.ConnectionState.Open) + { + await conn.OpenAsync(); + } + + using (var cmd = conn.CreateCommand()) + { + cmd.CommandText = sql; + + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.HasRows) + { + List list = new List(); + DataTable table = new DataTable(); + + table = DataReaderToDataTable(reader); + + foreach (DataRow row in table.Rows) + { + dynamic dyn = new ExpandoObject(); + list.Add(dyn); + foreach (DataColumn column in table.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; + } + + + + /// + /// + /// + /// + /// + public static DataTable DataReaderToDataTable(DbDataReader reader) + { + try + { + DataTable dt = new DataTable(); + int fieldCount = reader.FieldCount; + for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex) + { + dt.Columns.Add(reader.GetName(fieldIndex), reader.GetFieldType(fieldIndex)); + } + + dt.BeginLoadData(); + + object[] rowValues = new object[fieldCount]; + while (reader.Read()) + { + reader.GetValues(rowValues); + dt.LoadDataRow(rowValues, true); + } + reader.Close(); + dt.EndLoadData(); + + return dt; + + } + catch (Exception ex) + { + throw new Exception("DataReader Convert DataTable Error!", ex); + } + } + + } +}