8 changed files with 625 additions and 10 deletions
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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; } |
|||
} |
|||
} |
Loading…
Reference in new issue