You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
9.0 KiB
288 lines
9.0 KiB
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.WebApi.DTO.AMES;
|
|
using AMESCoreStudio.CommonTools.Result;
|
|
using System.Data.Common;
|
|
using System.Reflection;
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES
|
|
{
|
|
/// <summary>
|
|
/// 工單各站數量資料檔
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class WipStationController : ControllerBase
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public WipStationController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 獲取全部工單各站數量資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/WipStation
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<WipStation>>> GetWipStations()
|
|
{
|
|
//方法2
|
|
List<WipStation> list = new List<WipStation>();
|
|
string tempName = string.Empty;
|
|
DbConnection conn = _context.Database.GetDbConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
await conn.OpenAsync();
|
|
}
|
|
|
|
using (var cmd = conn.CreateCommand())
|
|
{
|
|
cmd.CommandText = @"SELECT WIP_ID as WipID,RULE_STATION_ID as RuleStationID,RULE_STATUS as RuleStatus,FIRST_CNT as FirstCnt,
|
|
PASS_CNT as PassCnt,CREATE_USERID as CreateUserID,CREATE_DATE as CreateDate,UPDATE_DATE as UpdateDate
|
|
FROM JHAMES.WIP_STATION";
|
|
|
|
using (var reader = await cmd.ExecuteReaderAsync())
|
|
{
|
|
if (reader.HasRows)
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
WipStation row = new WipStation();
|
|
PropertyInfo[] propertys = row.GetType().GetProperties();
|
|
foreach (PropertyInfo pi in propertys)
|
|
{
|
|
var obj = new object();
|
|
try
|
|
{
|
|
obj = reader[pi.Name];
|
|
}
|
|
catch
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (obj == DBNull.Value || obj == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var si = pi.GetSetMethod();
|
|
if (si == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (obj is decimal)
|
|
{
|
|
pi.SetValue(row, Convert.ToInt32(obj), null);
|
|
}
|
|
else
|
|
{
|
|
pi.SetValue(row, obj, null);
|
|
}
|
|
}
|
|
list.Add(row);
|
|
}
|
|
reader.Close();
|
|
return list;
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
|
|
|
|
/*
|
|
//方法1
|
|
var wip_station = await _context.WipStations.FromSqlRaw("SELECT * FROM JHAMES.WIP_STATION").ToListAsync();
|
|
return wip_station;
|
|
*/
|
|
|
|
//return await _context.WipStations.ToListAsync();
|
|
}
|
|
|
|
// GET: api/WipStation/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<WipStation>> GetWipStation(int id)
|
|
{
|
|
var wipStation = await _context.WipStations.FindAsync(id);
|
|
|
|
if (wipStation == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return wipStation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 基本查詢
|
|
/// </summary>
|
|
/// <param name="wipID">工單ID</param>
|
|
/// <param name="ruleStationID">流程ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetWipStation4QRS009")]
|
|
public async Task<ActionResult<IEnumerable<WipStation>>> GetWipStation4QRS009(int wipID, int ruleStationID)
|
|
{
|
|
IQueryable<WipStation> q = _context.WipStations;
|
|
|
|
|
|
if (wipID != 0)
|
|
q = q.Where(w => w.WipID == wipID);
|
|
|
|
|
|
if (ruleStationID != 0)
|
|
q = q.Where(w => w.RuleStationID == ruleStationID);
|
|
|
|
var result = await q.ToListAsync();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 基本查詢
|
|
/// </summary>
|
|
/// <param name="wipID">工單ID</param>
|
|
/// <param name="ruleStationID">流程ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetWipStation4QRS009Group")]
|
|
public async Task<ResultModel<dynamic>> GetWipStation4QRS009Group(int wipID, int ruleStationID)
|
|
{
|
|
ResultModel<dynamic> result = new ResultModel<dynamic>();
|
|
|
|
IQueryable<WipStation> q = _context.WipStations;
|
|
|
|
|
|
if (wipID != 0)
|
|
q = q.Where(w => w.WipID == wipID);
|
|
|
|
|
|
if (ruleStationID != 0)
|
|
q = q.Where(w => w.RuleStationID == ruleStationID);
|
|
|
|
var g = q.GroupBy(x => new { x.RuleStationID, x.RuleStatus }).Select(x => new
|
|
{
|
|
RuleStationID = x.Key.RuleStationID,
|
|
RuleStatus = x.Key.RuleStatus,
|
|
FirstCnt = q.Where(j => j.RuleStationID == x.Key.RuleStationID && j.RuleStatus == x.Key.RuleStatus).Sum(k => k.FirstCnt)
|
|
});
|
|
|
|
//var result = await q.ToListAsync();
|
|
result.DataTotal = g.ToList().Count;
|
|
|
|
result.Data = await g.ToListAsync();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 基本查詢
|
|
/// </summary>
|
|
/// <param name="wipID">工單ID</param>
|
|
/// <param name="ruleStationID">流程ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("Query")]
|
|
public async Task<ActionResult<WipStation>> GetWipStation(int wipID , int ruleStationID)
|
|
{
|
|
IQueryable<WipStation> q = _context.WipStations;
|
|
|
|
|
|
if (wipID != 0)
|
|
q = q.Where(w => w.WipID == wipID);
|
|
|
|
|
|
if (ruleStationID != 0)
|
|
q = q.Where(w => w.RuleStationID == ruleStationID);
|
|
|
|
var result = await q.ToListAsync();
|
|
|
|
return result.FirstOrDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新工單各站數量
|
|
/// </summary>
|
|
/// <param name="wipStation"></param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<WipStation>> PutWipStation(WipStation wipStation)
|
|
{
|
|
ResultModel<WipStation> result = new ResultModel<WipStation>();
|
|
_context.Entry(wipStation).State = EntityState.Modified;
|
|
wipStation.UpdateDate = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增工單各站數量
|
|
/// </summary>
|
|
/// <param name="wipStation"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<WipStation>> PostWipStation(WipStation wipStation)
|
|
{
|
|
ResultModel<WipStation> result = new ResultModel<WipStation>();
|
|
_context.WipStations.Add(wipStation);
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// DELETE: api/WipStation/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<ActionResult<WipStation>> DeleteWipStation(int id)
|
|
{
|
|
var wipStation = await _context.WipStations.FindAsync(id);
|
|
if (wipStation == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
_context.WipStations.Remove(wipStation);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return wipStation;
|
|
}
|
|
|
|
private bool WipStationExists(int id)
|
|
{
|
|
return _context.WipStations.Any(e => e.WipID == id);
|
|
}
|
|
}
|
|
}
|
|
|