Browse Source

1.修改生產看板RPT001

PTD
Marvin 2 years ago
parent
commit
fb1115a95a
  1. 4
      AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj
  2. 55
      AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs
  3. 205
      AMESCoreStudio.WebApi/Controllers/AMES/ProductionIndexesController.cs
  4. 58
      AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs
  5. 136
      AMESCoreStudio.WebApi/Controllers/BLL/RPTController.cs
  6. 40
      AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs
  7. 116
      AMESCoreStudio.WebApi/Models/AMES/ProductionIndex.cs
  8. 5
      AMESCoreStudio.WebApi/Models/AMESContext.cs

4
AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj

@ -39,8 +39,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.32" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.32">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

55
AMESCoreStudio.WebApi/Controllers/AMES/ExceptionWorktimesController.cs

@ -340,6 +340,61 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
}
/// <summary>
///
/// </summary>
/// <param name="sdate"></param>
/// <param name="edate"></param>
/// <returns></returns>
[Route("[action]")]
[HttpGet]
public async Task<ResultModel<dynamic>> GetExceptionWorktime4RPT001(string sdate, string edate)
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
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;
}
/// <summary>
/// 異常工時查詢QuerybyWHS009
/// </summary>

205
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
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class ProductionIndexesController : ControllerBase
{
private readonly AMESContext _context;
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public ProductionIndexesController(AMESContext context)
{
_context = context;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
// GET: api/ProductionIndexes
[HttpGet]
public async Task<ActionResult<IEnumerable<ProductionIndex>>> GetProductionIndex()
{
return await _context.ProductionIndexes.ToListAsync();
}
/// <summary>
///
/// </summary>
/// <param name="sdate"></param>
/// <param name="edate"></param>
/// <returns></returns>
[Route("[action]")]
[HttpGet]
public async Task<ResultModel<dynamic>> GetProductionIndex4RPT001(string sdate, string edate)
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
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;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/ProductionIndexes/5
[HttpGet("{id}")]
public async Task<ActionResult<ProductionIndex>> GetProductionIndex(int id)
{
var productionIndex = await _context.ProductionIndexes.FindAsync(id);
if (productionIndex == null)
{
return NotFound();
}
return productionIndex;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="productionIndex"></param>
/// <returns></returns>
// 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<IActionResult> 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();
}
/// <summary>
///
/// </summary>
/// <param name="productionIndex"></param>
/// <returns></returns>
// 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<ActionResult<ProductionIndex>> PostProductionIndex(ProductionIndex productionIndex)
{
_context.ProductionIndexes.Add(productionIndex);
await _context.SaveChangesAsync();
return CreatedAtAction("GetProductionIndex", new { id = productionIndex.ProductionID }, productionIndex);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// DELETE: api/ProductionIndexes/5
[HttpDelete("{id}")]
public async Task<ActionResult<ProductionIndex>> 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);
}
}
}

58
AMESCoreStudio.WebApi/Controllers/AMES/WorkManPowersController.cs

@ -82,6 +82,64 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
return workManPower;
}
/// <summary>
///
/// </summary>
/// <param name="sdate"></param>
/// <param name="edate"></param>
/// <returns></returns>
[Route("[action]")]
[HttpGet]
public async Task<ResultModel<dynamic>> GetWorkManPower4RPT001(string sdate, string edate)
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
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;
}
/// <summary>
/// 每日工時查詢Query
/// </summary>

136
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
{
@ -242,6 +243,141 @@ 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;
}
}

40
AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs

@ -105,6 +105,46 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
return result;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[Route("[action]")]
[HttpGet]
public async Task<ResultModel<dynamic>> GetUserData4EA()
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
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;
}
/// <summary>
///
/// </summary>

116
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
{
/// <summary>
/// 每日生產指標資料
/// </summary>
[Table("PRODUCTION_INDEX", Schema = "JHAMES")]
[DataContract]
public class ProductionIndex
{
/// <summary>
/// 生產指標ID
/// </summary>
[Key]
[Column("PRODUCTION_ID")]
[Required(ErrorMessage = "{0},不能空白")]
[DataMember]
public int ProductionID { get; set; }
/// <summary>
/// 生產日期
/// </summary>
[Column("PRODUCTION_DATE")]
[DataMember]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "生產日期")]
public DateTime ProductionDate { get; set; }
/// <summary>
/// 出勤人數
/// </summary>
[Column("EA")]
[DataMember]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "出勤人數")]
public int EA { get; set; }
/// <summary>
/// 應出勤工時
/// </summary>
[Column("EA_TIME")]
[DataMember]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "應出勤工時")]
public double EATime { get; set; }
/// <summary>
/// 實際出勤工時
/// </summary>
[Column("AA_TIME")]
[DataMember]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "實際出勤工時")]
public double AATime { get; set; }
/// <summary>
/// 出勤率
/// </summary>
[Column("ATTENDANCE")]
[DataMember]
[Display(Name = "出勤率")]
public double Attendance { get; set; }
/// <summary>
/// 正常加班(H)
/// </summary>
[Column("OVER_TIME")]
[DataMember]
[Display(Name = "正常加班(H)")]
public double OverTime { get; set; }
/// <summary>
/// 無效工時(H)
/// </summary>
[Column("INVALID")]
[DataMember]
[Display(Name = "無效工時(H)")]
public double InvalidTime { get; set; }
/// <summary>
/// 報工工時
/// </summary>
[Column("ACTUAL")]
[DataMember]
[Display(Name = "報工工時")]
public double ActualTime { get; set; }
/// <summary>
/// 效率
/// </summary>
[Column("EFFICIENCY")]
[DataMember]
[Display(Name = "效率")]
public double Efficiency { get; set; }
/// <summary>
/// 生產力
/// </summary>
[Column("PRODUCTIVITY")]
[DataMember]
[Display(Name = "生產力")]
public double Productivity { get; set; }
/// <summary>
/// 建立日期
/// </summary>
[Column("CREATE_DATE")]
[DataMember]
[Display(Name = "建立日期")]
public DateTime CreateDate { get; set; }
}
}

5
AMESCoreStudio.WebApi/Models/AMESContext.cs

@ -939,6 +939,11 @@ namespace AMESCoreStudio.WebApi
/// PlmBom資料
/// </summary>
public DbSet<PlmBom> PlmBoms { get; set; }
/// <summary>
/// PlmBom資料
/// </summary>
public DbSet<ProductionIndex> ProductionIndexes { get; set; }
}
}

Loading…
Cancel
Save