19 changed files with 254 additions and 1399 deletions
@ -1,196 +0,0 @@ |
|||||
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; |
|
||||
using System.Text.RegularExpressions; |
|
||||
using Dapper; |
|
||||
using AMESCoreStudio.WebApi.Extensions; |
|
||||
using System.Data; |
|
||||
|
|
||||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// FQC檢驗項目群組名稱設定檔
|
|
||||
/// </summary>
|
|
||||
[Route("api/[controller]")]
|
|
||||
[ApiController] |
|
||||
public class FqcItemGroupController : ControllerBase |
|
||||
{ |
|
||||
private readonly AMESContext _context; |
|
||||
|
|
||||
public FqcItemGroupController(AMESContext context) |
|
||||
{ |
|
||||
_context = context; |
|
||||
} |
|
||||
|
|
||||
[HttpGet] |
|
||||
public async Task<ActionResult<IEnumerable<FqcItemGroup>>> GetFqcItemGroups() |
|
||||
{ |
|
||||
return await _context.FqcItemGroups.ToListAsync(); |
|
||||
} |
|
||||
|
|
||||
[HttpGet("{id}")] |
|
||||
public async Task<ActionResult<FqcItemGroup>> GetFqcItemGroup(int id) |
|
||||
{ |
|
||||
var fqcItemGroup = await _context.FqcItemGroups.FindAsync(id); |
|
||||
return fqcItemGroup; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// FQC檢驗項目群組名稱設定檔 By Query
|
|
||||
/// </summary>
|
|
||||
/// <param name="no">群組代號</param>
|
|
||||
/// <param name="name">群組名稱</param>
|
|
||||
/// <param name="desc">群組描述</param>
|
|
||||
/// <param name="itemNo">料號</param>
|
|
||||
/// <param name="page">頁數</param>
|
|
||||
/// <param name="limit">筆數</param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpGet("FqcItemGroupQuery")] |
|
||||
public async Task<ResultModel<FqcItemGroup>> GetFqcItemGroupQuery(string no, string name, string desc, string itemNo, int page = 0, int limit = 10) |
|
||||
{ |
|
||||
ResultModel<FqcItemGroup> result = new ResultModel<FqcItemGroup>(); |
|
||||
|
|
||||
var query = @$" SELECT DISTINCT
|
|
||||
G.FQC_ITEM_GROUP_ID AS fqcItemGroupId , |
|
||||
G.ITEM_GROUP_NO AS itemGroupNo , |
|
||||
G.ITEM_GROUP_NAME AS itemGroupName , |
|
||||
G.ITEM_GROUP_DESC AS itemGroupDesc |
|
||||
FROM JHAMES.FQC_ITEM_GROUP G |
|
||||
LEFT JOIN JHAMES.FQC_ITEM_GROUP_MATERIAL GM ON G.FQC_ITEM_GROUP_ID = GM.GROUP_ID |
|
||||
LEFT JOIN JHAMES.MATERIAL_ITEM M ON GM.ITEM_ID = M.ITEM_ID |
|
||||
WHERE 1 = 1 ";
|
|
||||
|
|
||||
DynamicParameters p = new DynamicParameters(); |
|
||||
if (!string.IsNullOrWhiteSpace(no)) |
|
||||
{ |
|
||||
query += " AND UPPER(G.ITEM_GROUP_NO) LIKE :No "; |
|
||||
p.Add("No", $"%{no.Trim().ToUpper()}%", DbType.String); |
|
||||
} |
|
||||
|
|
||||
if (!string.IsNullOrWhiteSpace(name)) |
|
||||
{ |
|
||||
query += " AND G.ITEM_GROUP_NAME LIKE :Name "; |
|
||||
p.Add("Name", $"%{name.Trim().ToUpper()}%", DbType.String); |
|
||||
} |
|
||||
|
|
||||
if (!string.IsNullOrWhiteSpace(desc)) |
|
||||
{ |
|
||||
query += " AND G.ITEM_GROUP_DESC LIKE :GroupDesc "; |
|
||||
p.Add("GroupDesc", $"%{desc.Trim().ToUpper()}%", DbType.String); |
|
||||
} |
|
||||
|
|
||||
if (!string.IsNullOrWhiteSpace(itemNo)) |
|
||||
{ |
|
||||
query += " AND UPPER(M.ITEM_NO) LIKE :ItemNo "; |
|
||||
p.Add("ItemNo", $"%{itemNo.Trim().ToUpper()}%", DbType.String); |
|
||||
} |
|
||||
|
|
||||
var q = await _context.Database.DapperQueryAsync<FqcItemGroup>(query, p); |
|
||||
|
|
||||
// 紀錄筆數
|
|
||||
result.DataTotal = q.Count(); |
|
||||
|
|
||||
// Table 頁數
|
|
||||
if (page > 0) |
|
||||
{ |
|
||||
q = q.Skip((page - 1) * limit).Take(limit); |
|
||||
} |
|
||||
result.Data = q; |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 更新FQC檢驗項目群組名稱設定檔
|
|
||||
/// </summary>
|
|
||||
/// <param name="fqcItemGroup"></param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpPut] |
|
||||
public async Task<ResultModel<FqcItemGroup>> PutFqcItemGroup(FqcItemGroup fqcItemGroup) |
|
||||
{ |
|
||||
ResultModel<FqcItemGroup> result = new ResultModel<FqcItemGroup>(); |
|
||||
_context.Entry(fqcItemGroup).State = EntityState.Modified; |
|
||||
_context.Entry<FqcItemGroup>(fqcItemGroup).Property("CreateDate").IsModified = false; |
|
||||
_context.Entry<FqcItemGroup>(fqcItemGroup).Property("CreateUserID").IsModified = false; |
|
||||
fqcItemGroup.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>
|
|
||||
/// 新增FQC檢驗項目群組名稱設定檔
|
|
||||
/// </summary>
|
|
||||
/// <param name="fqcItemGroup"></param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpPost] |
|
||||
public async Task<ResultModel<FqcItemGroup>> PostFqcItemGroup(FqcItemGroup fqcItemGroup) |
|
||||
{ |
|
||||
ResultModel<FqcItemGroup> result = new ResultModel<FqcItemGroup>(); |
|
||||
Helper helper = new Helper(_context); |
|
||||
fqcItemGroup.FqcItemGroupId = helper.GetIDKey("FQC_ITEM_GROUP_ID").Result; |
|
||||
_context.FqcItemGroups.Add(fqcItemGroup); |
|
||||
try |
|
||||
{ |
|
||||
await _context.SaveChangesAsync(); |
|
||||
result.Success = true; |
|
||||
result.Msg = "OK"; |
|
||||
} |
|
||||
catch (Exception ex) |
|
||||
{ |
|
||||
result.Success = false; |
|
||||
result.Msg = ex.InnerException.Message; |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
[HttpDelete("{id}")] |
|
||||
public async Task<ResultModel<string>> DeleteFqcItemGroup(int id) |
|
||||
{ |
|
||||
ResultModel<string> result = new ResultModel<string>(); |
|
||||
var fqcItemGroup = await _context.FqcItemGroups.FindAsync(id); |
|
||||
var fqcItem = await _context.FqcItems.Where(w => w.GroupId == id).ToListAsync(); |
|
||||
var fqcItemGroupMaterial = await _context.FqcItemGroupMaterials |
|
||||
.Where(w => w.GroupId == id).ToListAsync(); |
|
||||
try |
|
||||
{ |
|
||||
if (fqcItemGroup == null) |
|
||||
{ |
|
||||
result.Success = false; |
|
||||
result.Msg = "找不到要刪除資料"; |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
_context.FqcItemGroups.Remove(fqcItemGroup); |
|
||||
_context.FqcItems.RemoveRange(fqcItem); |
|
||||
_context.FqcItemGroupMaterials.RemoveRange(fqcItemGroupMaterial); |
|
||||
await _context.SaveChangesAsync(); |
|
||||
result.Success = true; |
|
||||
result.Msg = "OK"; |
|
||||
} |
|
||||
} |
|
||||
catch (Exception ex) |
|
||||
{ |
|
||||
result.Success = false; |
|
||||
result.Msg = ex.InnerException.Message; |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,159 +0,0 @@ |
|||||
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; |
|
||||
using System.Text.RegularExpressions; |
|
||||
using Dapper; |
|
||||
using AMESCoreStudio.WebApi.Extensions; |
|
||||
|
|
||||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// FQC檢驗項目群組指定料號設定檔
|
|
||||
/// </summary>
|
|
||||
[Route("api/[controller]")]
|
|
||||
[ApiController] |
|
||||
public class FqcItemGroupMaterialController : ControllerBase |
|
||||
{ |
|
||||
private readonly AMESContext _context; |
|
||||
|
|
||||
public FqcItemGroupMaterialController(AMESContext context) |
|
||||
{ |
|
||||
_context = context; |
|
||||
} |
|
||||
|
|
||||
[HttpGet] |
|
||||
public async Task<ActionResult<IEnumerable<FqcItemGroupMaterial>>> GetFqcItemGroupMaterials() |
|
||||
{ |
|
||||
return await _context.FqcItemGroupMaterials.ToListAsync(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// By GroupId 查詢
|
|
||||
/// </summary>
|
|
||||
/// <param name="id">GroupId</param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpGet("ByGroupId/{id}")] |
|
||||
public async Task<ActionResult<IEnumerable<FqcItemGroupMaterial>>> GetFqcItemGroupMaterialByGroupId(int id) |
|
||||
{ |
|
||||
var query = @" SELECT
|
|
||||
F.GROUP_ID AS groupId , |
|
||||
M.ITEM_ID AS itemId , |
|
||||
M.ITEM_NO AS itemNo , |
|
||||
M.ITEM_DESC AS itemDesc , |
|
||||
F.CREATE_USERID AS createUserID , |
|
||||
F.CREATE_DATE AS createDate , |
|
||||
F.UPDATE_USERID AS updateUserID , |
|
||||
F.UPDATE_DATE AS updateDate |
|
||||
FROM JHAMES.FQC_ITEM_GROUP_MATERIAL F |
|
||||
INNER JOIN JHAMES.MATERIAL_ITEM M ON F.ITEM_ID = M.ITEM_ID |
|
||||
WHERE F.GROUP_ID = :GroupId";
|
|
||||
DynamicParameters p = new DynamicParameters(); |
|
||||
p.Add("GroupId", id); |
|
||||
var result = await _context.Database.DapperQueryAsync<FqcItemGroupMaterial>(query, p); |
|
||||
return result.ToList(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// By ItemId 查詢
|
|
||||
/// </summary>
|
|
||||
/// <param name="id">ItemId</param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpGet("ByItemId/{id}")] |
|
||||
public async Task<ActionResult<IEnumerable<FqcItemGroupMaterial>>> GetFqcItemGroupMaterialByItemId(int id) |
|
||||
{ |
|
||||
var query = @" SELECT
|
|
||||
F.GROUP_ID AS groupId , |
|
||||
M.ITEM_ID AS itemId , |
|
||||
M.ITEM_NO AS itemNo , |
|
||||
M.ITEM_DESC AS itemDesc , |
|
||||
F.CREATE_USERID AS createUserID , |
|
||||
F.CREATE_DATE AS createDate , |
|
||||
F.UPDATE_USERID AS updateUserID , |
|
||||
F.UPDATE_DATE AS updateDate |
|
||||
FROM JHAMES.FQC_ITEM_GROUP_MATERIAL F |
|
||||
INNER JOIN JHAMES.MATERIAL_ITEM M ON F.ITEM_ID = M.ITEM_ID |
|
||||
WHERE F.ITEM_ID = :ItemId";
|
|
||||
DynamicParameters p = new DynamicParameters(); |
|
||||
p.Add("ItemId", id); |
|
||||
var result = await _context.Database.DapperQueryAsync<FqcItemGroupMaterial>(query, p); |
|
||||
return result.ToList(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 更新檢驗群組指定料號設定檔
|
|
||||
/// </summary>
|
|
||||
/// <param name="fqcItemGroupMaterial"></param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpPut] |
|
||||
public async Task<ResultModel<FqcItemGroupMaterial>> PutFqcItemGroupMaterial(FqcItemGroupMaterial fqcItemGroupMaterial) |
|
||||
{ |
|
||||
ResultModel<FqcItemGroupMaterial> result = new ResultModel<FqcItemGroupMaterial>(); |
|
||||
_context.Entry(fqcItemGroupMaterial).State = EntityState.Modified; |
|
||||
_context.Entry<FqcItemGroupMaterial>(fqcItemGroupMaterial).Property("CreateDate").IsModified = false; |
|
||||
_context.Entry<FqcItemGroupMaterial>(fqcItemGroupMaterial).Property("CreateUserID").IsModified = false; |
|
||||
fqcItemGroupMaterial.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="fqcItemGroupMaterial"></param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpPost] |
|
||||
public async Task<ResultModel<FqcItemGroupMaterial>> PostFqcItemGroupMaterial(FqcItemGroupMaterial fqcItemGroupMaterial) |
|
||||
{ |
|
||||
ResultModel<FqcItemGroupMaterial> result = new ResultModel<FqcItemGroupMaterial>(); |
|
||||
_context.FqcItemGroupMaterials.Add(fqcItemGroupMaterial); |
|
||||
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="id">GroupId</param>
|
|
||||
/// <param name="id1">itemId</param>
|
|
||||
/// <returns></returns>
|
|
||||
[HttpDelete("{id}/{id1}")] |
|
||||
public async Task<ActionResult<int>> DeleteFqcItemGroupMaterial(int id, int id1) |
|
||||
{ |
|
||||
var query = @" DELETE JHAMES.FQC_ITEM_GROUP_MATERIAL WHERE GROUP_ID =:id
|
|
||||
AND ITEM_ID = :id1";
|
|
||||
DynamicParameters p = new DynamicParameters(); |
|
||||
p.Add("id", id); |
|
||||
p.Add("id1", id1); |
|
||||
var result = await _context.Database.DapperExecuteAsync(query, p); |
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue