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.
305 lines
11 KiB
305 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
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 WipBarcodeOtherController : Controller
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public WipBarcodeOtherController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 獲取產品別資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/SystemInfoes
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<WipBarcodeOther>>> GetWipBarcodeOther()
|
|
{
|
|
IQueryable<WipBarcodeOther> q = _context.WipBarcodeOthers;
|
|
|
|
q = q.OrderBy(p => p.OtherID);
|
|
|
|
//q = q.OrderByDescending(p => p.SystemID);
|
|
|
|
var wipBarcodeOther = await q.ToListAsync();
|
|
|
|
//return await _context.SystemInfoes.ToListAsync();
|
|
|
|
return wipBarcodeOther;
|
|
}
|
|
|
|
[HttpGet("WipNo/{id}")]
|
|
public async Task<ActionResult<WipBarcodeOther>> GetWipBarcodeOtherByWipNo(string id)
|
|
{
|
|
IQueryable<WipBarcodeOther> q = _context.WipBarcodeOthers;
|
|
|
|
var wipBarcodeOther = await q.Where(p => p.WipNO == id).FirstOrDefaultAsync();
|
|
|
|
//if (wipBarcodeOther == null)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
return wipBarcodeOther;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抓工單出貨序號區間(多筆)
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("WipNos/{id}")]
|
|
public async Task<ActionResult<IEnumerable<WipBarcodeOther>>> GetWipBarcodeOtherByWipNos(string id)
|
|
{
|
|
IQueryable<WipBarcodeOther> q = _context.WipBarcodeOthers;
|
|
|
|
var wipBarcodeOther = await q.Where(p => p.WipNO == id).ToListAsync();
|
|
|
|
//if (wipBarcodeOther == null)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
return wipBarcodeOther;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查詢客戶區間
|
|
/// </summary>
|
|
/// <param name="wipNO">工單號碼</param>
|
|
/// <param name="No">序號</param>
|
|
/// <returns></returns>
|
|
[HttpGet("ByNo")]
|
|
public async Task<ActionResult<IEnumerable<WipBarcodeOther>>> CheckWipBarcodeOtherByNo(string wipNO, string No)
|
|
{
|
|
var wipBarcodeOther = _context.WipBarcodeOthers
|
|
.FromSqlInterpolated($" SELECT * FROM JHAMES.WIP_BARCODE_OTHER WHERE {No} BETWEEN START_NO AND END_NO AND length(START_NO) = length({No}) ")
|
|
.AsNoTracking().ToList();
|
|
|
|
wipBarcodeOther = wipBarcodeOther.Where(W => W.WipNO == wipNO).ToList();
|
|
|
|
//if (wipBarcodeOther == null)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
return wipBarcodeOther;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="WipNo"></param>
|
|
/// <param name="ItemNo"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("WipBarcodeOtherByItemNo")]
|
|
public async Task<ResultModel<WipBarcodeOtherDto>> GetWipBarcodeOtherByItemNo(string WipNo, string ItemNo)
|
|
{
|
|
var SerialRule = _context.SerialRuleDetails.Where(W => W.ItemNo == ItemNo);//.Select(s =>s.SerialRuleDetailID.ToString()).ToList();
|
|
|
|
var wipBarcodeOther = _context.WipBarcodeOthers.Where(W => W.WipNO == WipNo);
|
|
|
|
//查工單預計開工日
|
|
var wipinfo = _context.WipInfos.Where(w => w.WipNO == WipNo).OrderBy(o => o.WipScheduleDate).Select(s => s.WipScheduleDate).FirstOrDefault();
|
|
|
|
var q = from O in _context.WipBarcodeOthers
|
|
join W in _context.WipInfos.Where(w => w.WipScheduleDate >= wipinfo) on O.WipNO equals W.WipNO
|
|
join A in _context.WipAtts on O.WipNO equals A.WipNO
|
|
join D in _context.SerialRuleDetails on O.SerialRuleDetailID equals D.SerialRuleDetailID
|
|
where D.Rule == SerialRule.Select(s => s.Rule).FirstOrDefault()
|
|
|
|
select new WipBarcodeOtherDto
|
|
{
|
|
OtherID = O.OtherID,
|
|
WipNo = O.WipNO,
|
|
ItemNo = A.ItemNO,
|
|
PlanQTY = W.PlanQTY,
|
|
CompleteQTY = W.CompleteQTY,
|
|
StartNo = O.StartNO,
|
|
EndNo = O.EndNO,
|
|
CreateDate = O.CreateDate,
|
|
Rule = D.Rule,
|
|
ItemRule = D.ItemNo,
|
|
WipScheduleDate = W.WipScheduleDate,
|
|
SerialRuleDetailID = O.SerialRuleDetailID,
|
|
Wip_Status_NO = W.StatusNO
|
|
|
|
};
|
|
|
|
q = q.Distinct().OrderBy(o => o.CreateDate);
|
|
|
|
|
|
|
|
|
|
ResultModel<WipBarcodeOtherDto> result = new ResultModel<WipBarcodeOtherDto>();
|
|
if (ItemNo.Contains("OTHER"))
|
|
{
|
|
q = q.Where(w => w.ItemRule == ItemNo);
|
|
|
|
}
|
|
result.Data = await q.ToListAsync();
|
|
|
|
// result.Data = result.Data.Select(s => { s.Status = s.Status == "Y" ? "已投產" : s.Status == "N" ? "未投產" : "末知"; return s; })
|
|
// .ToList();
|
|
result.DataTotal = result.Data.Count();
|
|
|
|
// 紀錄筆數
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增工單出貨條碼區間設定檔
|
|
/// </summary>
|
|
/// <param name="wipBarcodeOther"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<WipBarcodeOther>> PostWipBarcodeOther([FromBody] WipBarcodeOther wipBarcodeOther)
|
|
{
|
|
ResultModel<WipBarcodeOther> result = new ResultModel<WipBarcodeOther>();
|
|
Helper helper = new Helper(_context);
|
|
wipBarcodeOther.OtherID = helper.GetIDKey("OTHER_ID").Result;
|
|
|
|
try
|
|
{
|
|
_context.WipBarcodeOthers.Add(wipBarcodeOther);
|
|
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="wipBarcodeOther"></param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<WipBarcodeOther>> PutWipBarcodeOther(WipBarcodeOther wipBarcodeOther)
|
|
{
|
|
ResultModel<WipBarcodeOther> result = new ResultModel<WipBarcodeOther>();
|
|
var wipNo = wipBarcodeOther.WipNO;
|
|
try
|
|
{
|
|
var result_old = _context.WipBarcodeOthers.Where(w => w.WipNO == wipNo).Select(s =>s.OtherID).ToList();
|
|
if (result_old.Count != 0)
|
|
{
|
|
_context.Entry(wipBarcodeOther).State = EntityState.Modified;
|
|
_context.Entry<WipBarcodeOther>(wipBarcodeOther).Property("CreateDate").IsModified = false;
|
|
_context.Entry<WipBarcodeOther>(wipBarcodeOther).Property("CreateUserID").IsModified = false;
|
|
}
|
|
else
|
|
{
|
|
_context.WipBarcodeOthers.Add(wipBarcodeOther);
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刪除工單出貨條碼區間
|
|
/// </summary>
|
|
/// <param name="id">工單號碼</param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{id}")]
|
|
public async Task<ResultModel<WipBarcodeOther>> DeleteWipBarcodeOther(string id)
|
|
{
|
|
ResultModel<WipBarcodeOther> result = new ResultModel<WipBarcodeOther>();
|
|
var wipBarcodeOther = await _context.WipBarcodeOthers.Where(w => w.WipNO.Trim().ToUpper() == id.ToUpper().Trim()).FirstOrDefaultAsync();
|
|
try
|
|
{
|
|
if (wipBarcodeOther != null)
|
|
{
|
|
_context.WipBarcodeOthers.Remove(wipBarcodeOther);
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
else
|
|
{
|
|
result.Success = true;
|
|
result.Msg = "找不到資料刪除";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 刪除工單出貨條碼區間
|
|
/// </summary>
|
|
/// <param name="id">工單號碼</param>
|
|
/// <returns></returns>
|
|
[HttpDelete("byOhterID/{id}")]
|
|
public async Task<ResultModel<WipBarcodeOther>> DeleteWipBarcodeOtherByOhterID(int id)
|
|
{
|
|
ResultModel<WipBarcodeOther> result = new ResultModel<WipBarcodeOther>();
|
|
var wipBarcodeOther = await _context.WipBarcodeOthers.Where(w => w.OtherID == id).FirstOrDefaultAsync();
|
|
try
|
|
{
|
|
if (wipBarcodeOther != null)
|
|
{
|
|
_context.WipBarcodeOthers.Remove(wipBarcodeOther);
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
else
|
|
{
|
|
result.Success = true;
|
|
result.Msg = "找不到資料刪除";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|