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.
321 lines
9.6 KiB
321 lines
9.6 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>
|
|
/// 查詢工單資料QRS009
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("[action]")]
|
|
[HttpGet]
|
|
public async Task<ResultModel<dynamic>> GetWipInfo4QRS009()
|
|
{
|
|
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.CompleteQTY,
|
|
q1.UnitNO,
|
|
q1.LineID,
|
|
q1.FlowRuleID,
|
|
q1.StatusNO,
|
|
q1.CreateDate,
|
|
q2.ItemNO,
|
|
q3.LineDesc,
|
|
q4.UnitName
|
|
};
|
|
|
|
q = q.Where(w => w.StatusNO == "A");
|
|
|
|
|
|
//紀錄筆數
|
|
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>
|
|
/// 查詢工單資料 by SelectParameter
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("[action]")]
|
|
[HttpGet]
|
|
public async Task<ResultModel<dynamic>> GetWipInfoSelectParameter([FromQuery] WipInfoDto value, int page = 0, 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
|
|
join q5 in _context.FactoryInfos on q1.Werks equals q5.FactoryID.ToString()
|
|
//join q6 in _context.MaterialItems on q2.ItemNO equals q6.ItemNo
|
|
select new
|
|
{
|
|
q1.WipID,
|
|
q1.WipNO,
|
|
q1.PlanQTY,
|
|
q1.UnitNO,
|
|
q1.LineID,
|
|
q1.StatusNO,
|
|
q1.WipScheduleDate,
|
|
q1.WipDueDate,
|
|
q5.FactoryNameCh,
|
|
q1.Description,
|
|
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>
|
|
/// 查詢工單資料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>
|
|
[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.InnerException.Message;
|
|
}
|
|
return result;
|
|
|
|
//return CreatedAtAction("GetWipInfo", new { id = WipInfo.WipID }, WipInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新工單資本資料-狀態
|
|
/// </summary>
|
|
/// <param name="id">工單ID</param>
|
|
/// <param name="statusno">狀態</param>
|
|
/// <returns></returns>
|
|
[HttpPut("{id}/{statusno}")]
|
|
public async Task<ActionResult<WipInfo>> PutWipinfoToStatusNO(int id = 0, string statusno = null)
|
|
{
|
|
if (id == 0)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
WipInfo wipinfo = new WipInfo
|
|
{
|
|
WipID = id,
|
|
StatusNO = statusno,
|
|
UpdateDate = DateTime.Now
|
|
};
|
|
_context.WipInfos.Attach(wipinfo);
|
|
// 指定更新某個欄位
|
|
_context.Entry(wipinfo).Property(p => p.StatusNO).IsModified = true;
|
|
_context.Entry(wipinfo).Property(p => p.UpdateDate).IsModified = true;
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch (DbUpdateConcurrencyException)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return wipinfo;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新工單資本資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
public async Task<ResultModel<WipInfo>> PutWipinfo([FromBody] WipInfo wipInfo)
|
|
{
|
|
ResultModel<WipInfo> result = new ResultModel<WipInfo>();
|
|
_context.Entry(wipInfo).State = EntityState.Modified;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.InnerException.Message;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|