From fb1115a95a9585cc09f25480f1cefd4d530ceea6 Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 15 Jun 2023 22:13:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E7=94=9F=E7=94=A2=E7=9C=8B?= =?UTF-8?q?=E6=9D=BFRPT001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AMESCoreStudio.WebApi.csproj | 4 +- .../AMES/ExceptionWorktimesController.cs | 55 +++++ .../AMES/ProductionIndexesController.cs | 205 ++++++++++++++++++ .../AMES/WorkManPowersController.cs | 58 +++++ .../Controllers/BLL/RPTController.cs | 138 +++++++++++- .../Controllers/SYS/UserInfoesController.cs | 54 ++++- .../Models/AMES/ProductionIndex.cs | 116 ++++++++++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 5 + 8 files changed, 625 insertions(+), 10 deletions(-) create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/ProductionIndexesController.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/ProductionIndex.cs diff --git a/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj b/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj index bcfbce75..ae788849 100644 --- a/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj +++ b/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj @@ -39,8 +39,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs index 40f7cb9f..2f34aeb7 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs @@ -340,6 +340,61 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } + /// + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetExceptionWorktime4RPT001(string sdate, string edate) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.ExceptionWorktimes + select new + { + q1.ExceptionID, + q1.ExceptionDate, + q1.Time + + }; + + DateTime dateValue; + if (sdate != "*") + { + + if (DateTime.TryParse(sdate, out dateValue)) + { + q = q.Where(p => p.ExceptionDate >= DateTime.Parse(sdate)); + } + } + if (edate != "*") + { + if (DateTime.TryParse(edate, out dateValue)) + { + q = q.Where(p => p.ExceptionDate <= DateTime.Parse(edate)); + } + + } + + //紀錄筆數 + result.DataTotal = q.Count(); + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 異常工時查詢QuerybyWHS009 /// diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/ProductionIndexesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/ProductionIndexesController.cs new file mode 100644 index 00000000..626ddd0c --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/ProductionIndexesController.cs @@ -0,0 +1,205 @@ +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.AMES; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class ProductionIndexesController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public ProductionIndexesController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/ProductionIndexes + [HttpGet] + public async Task>> GetProductionIndex() + { + return await _context.ProductionIndexes.ToListAsync(); + } + + /// + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetProductionIndex4RPT001(string sdate, string edate) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.ProductionIndexes + select new + { + q1.ProductionID, + q1.ProductionDate, + q1.EA, + q1.EATime, + q1.AATime, + q1.ActualTime, + q1.OverTime, + q1.InvalidTime, + q1.Productivity, + q1.Efficiency, + q1.Attendance + + }; + DateTime dateValue; + if (sdate != "*") + { + + if (DateTime.TryParse(sdate, out dateValue)) + { + q = q.Where(p => p.ProductionDate >= DateTime.Parse(sdate)); + } + } + if (edate != "*") + { + if (DateTime.TryParse(edate, out dateValue)) + { + q = q.Where(p => p.ProductionDate <= DateTime.Parse(edate)); + } + + } + + //紀錄筆數 + result.DataTotal = q.Count(); + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // GET: api/ProductionIndexes/5 + [HttpGet("{id}")] + public async Task> GetProductionIndex(int id) + { + var productionIndex = await _context.ProductionIndexes.FindAsync(id); + + if (productionIndex == null) + { + return NotFound(); + } + + return productionIndex; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/ProductionIndexes/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task PutProductionIndex(int id, ProductionIndex productionIndex) + { + if (id != productionIndex.ProductionID) + { + return BadRequest(); + } + + _context.Entry(productionIndex).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ProductionIndexExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + /// + /// + /// + /// + /// + // POST: api/ProductionIndexes + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task> PostProductionIndex(ProductionIndex productionIndex) + { + _context.ProductionIndexes.Add(productionIndex); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetProductionIndex", new { id = productionIndex.ProductionID }, productionIndex); + } + + /// + /// + /// + /// + /// + // DELETE: api/ProductionIndexes/5 + [HttpDelete("{id}")] + public async Task> DeleteProductionIndex(int id) + { + var productionIndex = await _context.ProductionIndexes.FindAsync(id); + if (productionIndex == null) + { + return NotFound(); + } + + _context.ProductionIndexes.Remove(productionIndex); + await _context.SaveChangesAsync(); + + return productionIndex; + } + + private bool ProductionIndexExists(int id) + { + return _context.ProductionIndexes.Any(e => e.ProductionID == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs index 3c24682b..24a911cd 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs @@ -82,6 +82,64 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return workManPower; } + /// + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetWorkManPower4RPT001(string sdate, string edate) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.WorkManPowers + select new + { + q1.PowerID, + q1.PowerDate, + q1.FactWorkH, + q1.OvarH, + q1.UserNo, + q1.UserName + }; + + q = q.Where(p => p.UserNo.EndsWith("B")); + DateTime dateValue; + if (sdate != "*") + { + + if (DateTime.TryParse(sdate, out dateValue)) + { + q = q.Where(p => p.PowerDate >= DateTime.Parse(sdate)); + } + } + if (edate != "*") + { + if (DateTime.TryParse(edate, out dateValue)) + { + q = q.Where(p => p.PowerDate <= DateTime.Parse(edate)); + } + + } + + //紀錄筆數 + result.DataTotal = q.Count(); + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 每日工時查詢Query /// diff --git a/AMESCoreStudio.WebApi/Controllers/BLL/RPTController.cs b/AMESCoreStudio.WebApi/Controllers/BLL/RPTController.cs index 6a1f6fcf..d93ac166 100644 --- a/AMESCoreStudio.WebApi/Controllers/BLL/RPTController.cs +++ b/AMESCoreStudio.WebApi/Controllers/BLL/RPTController.cs @@ -15,6 +15,7 @@ using AMESCoreStudio.WebApi.DTO.AMES; using System.Data; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using AMESCoreStudio.WebApi.Controllers.SYS; namespace AMESCoreStudio.WebApi.Controllers.BLL { @@ -241,7 +242,142 @@ namespace AMESCoreStudio.WebApi.Controllers.BLL } result.fqc = double.Parse(sum_fqc_rate.ToString("0.00")); } - + + /* + //应出勤人数 + var ea = await new UserInfoesController(_context).GetUserData4EA(); + int eaTime = ea.DataTotal * 8; + + var g = await new WorkManPowersController(_context).GetWorkManPower4RPT001(sDate, eDate); + double sumAATime = 0.00, sumOverTime = 0.00; + double aaRate = 0.00; + + if (g.DataTotal > 0) + { + foreach (var item in g.Data) + { + //string str = item.ToString(); + //JObject jo = JObject.Parse(str.Replace("=", ":")); + + string str = item.ToString(); + string[] str2 = str.Replace("{", "").Replace("}", "").Split(','); + string str3 = ""; + for (int i = 0; i < str2.Length; i++) + { + string[] str21 = str2[i].Split("="); + str3 = str3 + str21[0].Trim() + ":" + "'" + str21[1].Trim() + "',"; + } + JObject jo = JObject.Parse("{" + str3.Substring(0, str3.Length - 1) + "}"); + + double aa_time = double.Parse(jo["FactWorkH"].ToString()); + double over_time = double.Parse(jo["OvarH"].ToString()); + + sumAATime = sumAATime + aa_time; + sumOverTime = sumOverTime + over_time; + + } + + if (eaTime > 0) + { + aaRate = sumAATime * 100.0 / (eaTime * g.DataTotal); + } + } + + //出勤率 + result.attendance = double.Parse(aaRate.ToString("0.00")); + //加班工时 + result.overtime = double.Parse(sumOverTime.ToString("0.00")); + + //异常工时 + var h = await new ExceptionWorktimesController(_context).GetExceptionWorktime4RPT001(sDate, eDate); + double sumExceptionTime = 0.00; + if (h.DataTotal > 0) + { + foreach (var item in h.Data) + { + string str = item.ToString(); + string[] str2 = str.Replace("{", "").Replace("}", "").Split(','); + string str3 = ""; + for (int i = 0; i < str2.Length; i++) + { + string[] str21 = str2[i].Split("="); + str3 = str3 + str21[0].Trim() + ":" + "'" + str21[1].Trim() + "',"; + } + JObject jo = JObject.Parse("{" + str3.Substring(0, str3.Length - 1) + "}"); + + double exception_time = double.Parse(jo["Time"].ToString()); + + sumExceptionTime = sumExceptionTime + exception_time; + } + } + + result.abnormalTime = double.Parse((sumExceptionTime / 60.0).ToString("0.00")); + */ + + var pi = await new ProductionIndexesController(_context).GetProductionIndex4RPT001(sDate, eDate); + + int sumPI_EA = 0; + double sumPI_EATime = 0.00, sumPI_AATime = 0.00, sumPI_InvalidTIme = 0.00, sumPI_OverTime = 0.00, sumPI_ActualTime = 0.00; + double PI_Attendance = 0.00, PI_Efficiency = 0.00, PI_Productivity = 0.00; + double attendance = 0.00, efficiency = 0.00, productivity = 0.00; + + if (pi.DataTotal > 0) + { + foreach (var item in pi.Data) + { + string str = item.ToString(); + string[] str2 = str.Replace("{", "").Replace("}", "").Split(','); + string str3 = ""; + for (int i = 0; i < str2.Length; i++) + { + string[] str21 = str2[i].Split("="); + str3 = str3 + str21[0].Trim() + ":" + "'" + str21[1].Trim() + "',"; + } + JObject jo = JObject.Parse("{" + str3.Substring(0, str3.Length - 1) + "}"); + + int pi_ea = int.Parse(jo["EA"].ToString()); + double pi_eatime = double.Parse(jo["EATime"].ToString()); + double pi_aatime = double.Parse(jo["AATime"].ToString()); + double pi_overtime = double.Parse(jo["OverTime"].ToString()); + double pi_invalidtime = double.Parse(jo["InvalidTime"].ToString()); + double pi_actualtime = double.Parse(jo["ActualTime"].ToString()); + double pi_efficiency = double.Parse(jo["Efficiency"].ToString()); + double pi_productivity = double.Parse(jo["Productivity"].ToString()); + double pi_attendance = double.Parse(jo["Attendance"].ToString()); + + sumPI_EA = sumPI_EA + pi_ea; + sumPI_EATime = sumPI_EATime + pi_eatime; + sumPI_AATime = sumPI_AATime + pi_aatime; + sumPI_InvalidTIme = sumPI_InvalidTIme + pi_invalidtime; + sumPI_OverTime = sumPI_OverTime + pi_overtime; + sumPI_ActualTime = sumPI_ActualTime + pi_actualtime; + + PI_Attendance = PI_Attendance + pi_attendance; + PI_Efficiency = PI_Efficiency + pi_efficiency; + PI_Productivity = PI_Productivity + pi_productivity; + } + + if (PI_Attendance > 0) + { + attendance = PI_Attendance / (pi.DataTotal * 1.0); + } + if (PI_Efficiency > 0) + { + efficiency = PI_Efficiency / (pi.DataTotal * 1.0); + } + if (PI_Productivity > 0) + { + productivity = PI_Productivity / (pi.DataTotal * 1.0); + } + } + + result.productivity = double.Parse(efficiency.ToString("0.00")); + result.attendance = double.Parse(attendance.ToString("0.00")); + result.productiveForces = double.Parse(productivity.ToString("0.00")); + + result.overtime = sumPI_OverTime; + result.invalidHours = sumPI_InvalidTIme; + return result; } } diff --git a/AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs b/AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs index d618bd7b..0da34ebe 100644 --- a/AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs @@ -105,13 +105,53 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS return result; } - /// - /// - /// - /// - /// - // GET: api/UserInfoes/5 - [HttpGet("{id}")] + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetUserData4EA() + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.UserInfoes + join q2 in _context.DeptInfoes on q1.DeptID equals q2.DeptID + select new + { + q1.UserID, + q1.UserNo, + q1.UserName, + q1.LoginNo, + q2.DeptID, + q2.DeptName + }; + q = q.Where(p => p.UserNo.EndsWith("B")); + q = q.Where(p => p.DeptName.Equals("製造部")); + + //紀錄筆數 + result.DataTotal = q.Count(); + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // GET: api/UserInfoes/5 + [HttpGet("{id}")] public async Task>> GetUserInfo(int id) { IQueryable q = _context.UserInfoes; diff --git a/AMESCoreStudio.WebApi/Models/AMES/ProductionIndex.cs b/AMESCoreStudio.WebApi/Models/AMES/ProductionIndex.cs new file mode 100644 index 00000000..dc56f03e --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/ProductionIndex.cs @@ -0,0 +1,116 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 每日生產指標資料 + /// + [Table("PRODUCTION_INDEX", Schema = "JHAMES")] + [DataContract] + public class ProductionIndex + { + /// + /// 生產指標ID + /// + [Key] + [Column("PRODUCTION_ID")] + [Required(ErrorMessage = "{0},不能空白")] + [DataMember] + public int ProductionID { get; set; } + + /// + /// 生產日期 + /// + [Column("PRODUCTION_DATE")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "生產日期")] + public DateTime ProductionDate { get; set; } + + /// + /// 出勤人數 + /// + [Column("EA")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "出勤人數")] + public int EA { get; set; } + + /// + /// 應出勤工時 + /// + [Column("EA_TIME")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "應出勤工時")] + public double EATime { get; set; } + + /// + /// 實際出勤工時 + /// + [Column("AA_TIME")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "實際出勤工時")] + public double AATime { get; set; } + + /// + /// 出勤率 + /// + [Column("ATTENDANCE")] + [DataMember] + [Display(Name = "出勤率")] + public double Attendance { get; set; } + + /// + /// 正常加班(H) + /// + [Column("OVER_TIME")] + [DataMember] + [Display(Name = "正常加班(H)")] + public double OverTime { get; set; } + + /// + /// 無效工時(H) + /// + [Column("INVALID")] + [DataMember] + [Display(Name = "無效工時(H)")] + public double InvalidTime { get; set; } + + /// + /// 報工工時 + /// + [Column("ACTUAL")] + [DataMember] + [Display(Name = "報工工時")] + public double ActualTime { get; set; } + + /// + /// 效率 + /// + [Column("EFFICIENCY")] + [DataMember] + [Display(Name = "效率")] + public double Efficiency { get; set; } + + /// + /// 生產力 + /// + [Column("PRODUCTIVITY")] + [DataMember] + [Display(Name = "生產力")] + public double Productivity { get; set; } + + /// + /// 建立日期 + /// + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "建立日期")] + public DateTime CreateDate { get; set; } + } +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 3a39f164..80fb8f2e 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -939,6 +939,11 @@ namespace AMESCoreStudio.WebApi /// PlmBom資料 /// public DbSet PlmBoms { get; set; } + + /// + /// PlmBom資料 + /// + public DbSet ProductionIndexes { get; set; } } }