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.
292 lines
9.2 KiB
292 lines
9.2 KiB
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using AMESCoreStudio.WebApi.Models.AMES;
|
|
using AMESCoreStudio.WebApi.DTO.AMES;
|
|
using AMESCoreStudio.CommonTools.Result;
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class WipInfosController : Controller
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public WipInfosController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查詢工單資料Info
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/SystemInfoes
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<WipInfo>>> GetWipInfo()
|
|
{
|
|
IQueryable<WipInfo> q = _context.WipInfos;
|
|
|
|
q = q.OrderBy(p => p.WipNO);
|
|
|
|
//q = q.OrderByDescending(p => p.SystemID);
|
|
|
|
var WipInfo = await q.ToListAsync();
|
|
|
|
//return await _context.SystemInfoes.ToListAsync();
|
|
|
|
return WipInfo;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查詢工單資料 by SelectParameter
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("[action]")]
|
|
[HttpGet]
|
|
public async Task<ResultModel<dynamic>> GetWipInfoSelectParameter([FromQuery] WipInfoDto value, int page = 1, int limit = 10)
|
|
{
|
|
ResultModel<dynamic> result = new ResultModel<dynamic>();
|
|
var q = from q1 in _context.WipInfos
|
|
join q2 in _context.WipAtts on q1.WipNO equals q2.WipNO
|
|
join q3 in _context.LineInfoes on q1.LineID equals q3.LineID
|
|
join q4 in _context.FactoryUnits on q1.UnitNO equals q4.UnitNo
|
|
select new
|
|
{
|
|
q1.WipID,
|
|
q1.WipNO,
|
|
q1.PlanQTY,
|
|
q1.UnitNO,
|
|
q1.LineID,
|
|
q1.StatusNO,
|
|
q1.CreateDate,
|
|
q2.ItemNO,
|
|
q3.LineDesc,
|
|
q4.UnitName
|
|
};
|
|
|
|
if (!string.IsNullOrWhiteSpace(value.unitno))
|
|
{
|
|
q = q.Where(w => w.UnitNO == value.unitno);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(value.wipno))
|
|
{
|
|
q = q.Where(w => w.WipNO == value.wipno);
|
|
}
|
|
|
|
if (value.lineid != 0)
|
|
{
|
|
q = q.Where(w => w.LineID == value.lineid);
|
|
}
|
|
|
|
if (value.date_str != null)
|
|
{
|
|
q = q.Where(w => w.CreateDate >= value.date_str);
|
|
}
|
|
|
|
if (value.date_end != null)
|
|
{
|
|
q = q.Where(w => w.CreateDate <= value.date_end);
|
|
}
|
|
|
|
if (value.itemno != null)
|
|
{
|
|
q = q.Where(w => w.ItemNO == value.itemno);
|
|
}
|
|
|
|
// 紀錄筆數
|
|
result.DataTotal = q.Count();
|
|
|
|
// Table 頁數
|
|
if (page > 0)
|
|
{
|
|
q = q.Skip((page - 1) * limit).Take(limit);
|
|
}
|
|
|
|
result.Data = await q.ToListAsync();
|
|
|
|
if (result == null)
|
|
{
|
|
result.Msg = "查無資料";
|
|
result.Success = false;
|
|
return result;
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查詢工單資料+是否過站 by SelectParameter
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//[Route("[action]")]
|
|
//[HttpGet]
|
|
//public async Task<ResultModel<dynamic>> GetWipInfoSelectParameterInBarCodeStation([FromQuery] WipInfoDto value, int page = 1, int limit = 10)
|
|
//{
|
|
|
|
//ResultModel<dynamic> result = new ResultModel<dynamic>();
|
|
//var result = GetWipInfoSelectParameter(value, page, limit);
|
|
//// 判斷是否已經有過站紀錄
|
|
//BarcodeStationController barcodeStation = new BarcodeStationController(_context);
|
|
//var WipArray = result.Result.Data.GroupBy(o => o.WipNO)
|
|
// .Select(s => new
|
|
// {
|
|
// s.Key,
|
|
// WipID = result.Result.Data.Where(w => w.WipNO == s.Key)
|
|
// .Select(s1 => (decimal)s1.WipID).ToList()
|
|
// }).ToList();
|
|
|
|
//foreach (var item in WipArray)
|
|
//{
|
|
// var q1 = barcodeStation.GetBarcodeStationByWipIDList(item.WipID);
|
|
// if (q1 == null)
|
|
// {
|
|
// result.Result.Data = result.Result.Data.Where(w => w.WipNO == item.Key)
|
|
// .Select(s => new { s , BarcodeStation = "N"}).ToList();
|
|
// }
|
|
// else
|
|
// {
|
|
// result.Result.Data = result.Result.Data.Where(w => w.WipNO == item.Key)
|
|
// .Select(s => { s.BarcodeStation = "Y"; return s; }).ToList();
|
|
// }
|
|
//}
|
|
|
|
//if (result.Result.Data == null)
|
|
//{
|
|
// result.Result.Msg = "查無資料";
|
|
// result.Result.Success = false;
|
|
// return await result;
|
|
//}
|
|
|
|
//result.Result.Success = true;
|
|
//result.Result.Msg = "OK";
|
|
//return;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 查詢工單資料Info By WipID
|
|
/// </summary>
|
|
/// <param name="id">WipID</param>
|
|
/// <returns></returns>
|
|
// GET: api/RoleModules/Role/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<IEnumerable<WipInfo>>> GetWipInfo(int id)
|
|
{
|
|
IQueryable<WipInfo> q = _context.WipInfos.Where(w => w.WipID == id);
|
|
|
|
var WipInfo = await q.ToListAsync();
|
|
|
|
if (WipInfo == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return WipInfo;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查詢工單資料Info By WipNO
|
|
/// </summary>
|
|
/// <param name="wipno">工單號碼</param>
|
|
/// <returns></returns>
|
|
// GET: api/RoleModules/Role/5
|
|
[HttpGet("WipInfoByWipNo/{wipno}")]
|
|
public async Task<ActionResult<IEnumerable<WipInfo>>> GetWipInfoByWipNo(string wipno)
|
|
{
|
|
IQueryable<WipInfo> q = _context.WipInfos.Where(w => w.WipNO == wipno);
|
|
|
|
var WipInfo = await q.ToListAsync();
|
|
|
|
if (WipInfo == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return WipInfo;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增工單資料
|
|
/// </summary>
|
|
/// <param name="WipInfo"></param>
|
|
/// <returns></returns>
|
|
// POST: api/SystemInfoes
|
|
// 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<ResultModel<WipInfo>> PostWipInfo([FromBody] WipInfo WipInfo)
|
|
{
|
|
ResultModel<WipInfo> result = new ResultModel<WipInfo>();
|
|
Helper helper = new Helper(_context);
|
|
WipInfo.WipID = helper.GetIDKey("WIP_ID").Result;
|
|
WipInfo.CreateUserID = 0;
|
|
|
|
_context.WipInfos.Add(WipInfo);
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = WipInfo.WipID.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.Message;
|
|
}
|
|
return result;
|
|
|
|
//return CreatedAtAction("GetWipInfo", new { id = WipInfo.WipID }, WipInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新工單資本資料-狀態
|
|
/// </summary>
|
|
/// <param name="id">工單ID</param>
|
|
/// <param name="statusno">狀態</param>
|
|
/// <returns></returns>
|
|
// PUT: api/RuleStations/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}/{statusno}")]
|
|
public async Task<ActionResult<WipInfo>> PutWipinfoToStatusNO(int id = 0, string statusno = null)
|
|
{
|
|
if (id == 0)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
WipInfo wipinfo = new WipInfo();
|
|
wipinfo.WipID = id;
|
|
wipinfo.StatusNO = statusno;
|
|
wipinfo.UpdateDate = DateTime.Now;
|
|
// 指定更新某個欄位
|
|
_context.Entry(wipinfo).Property(p => p.StatusNO).IsModified = true;
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch (DbUpdateConcurrencyException)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return wipinfo;
|
|
}
|
|
|
|
}
|
|
}
|
|
|