Browse Source

1.修改Helper,新增ID的最大值為Int32的最大值

2.修改系統資料維護(修改引用ResultModel)
3.修改系統模組維護(修改引用ResultModel)
4.修改流程規則維護(新增RULE_ID為PK)
PTD
Marvin 3 years ago
parent
commit
51ec88335a
  1. 30
      AMESCoreStudio.Web/Controllers/BASController.cs
  2. 33
      AMESCoreStudio.Web/Controllers/SYSController.cs
  3. 13
      AMESCoreStudio.Web/HttpApis/IBAS.cs
  4. 8
      AMESCoreStudio.Web/HttpApis/ISYS.cs
  5. 14
      AMESCoreStudio.Web/Views/BAS/BAS011.cshtml
  6. 4
      AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml
  7. 6
      AMESCoreStudio.WebApi/Code/Helper.cs
  8. 77
      AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs
  9. 60
      AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs
  10. 59
      AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs
  11. 2
      AMESCoreStudio.WebApi/Models/AMESContext.cs
  12. 14
      AMESCoreStudio.WebApi/Models/BAS/Rules.cs
  13. 8
      AMESCoreStudio.WebApi/Models/SYS/IDKey.cs

30
AMESCoreStudio.Web/Controllers/BASController.cs

@ -1413,28 +1413,29 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet] [HttpGet]
public async Task<IActionResult> BAS011UAsync(string id) public async Task<IActionResult> BAS011UAsync(string id)
{ {
int ruleStationID = int.Parse(id.Split('_')[0]); int ruleID = int.Parse(id);
string status = id.Split('_')[1]; var result = await _basApi.GetRules(ruleID);
int nextStationID = int.Parse(id.Split('_')[2]);
await GetFlowRuleList(); await GetFlowRuleList();
var result2 = await _basApi.GetRuleStation(ruleStationID);
//var result1 = await _basApi.GetRules(result[0].RuleStationID, result[0].RuleStatus, result[0].NextStationID);
var result2 = await _basApi.GetRuleStation(result[0].RuleStationID);
int flowId = result2[0].FlowRuleID; int flowId = result2[0].FlowRuleID;
await GetRuleStationList(flowId); await GetRuleStationList(flowId);
await GetNextStationList(flowId); await GetNextStationList(flowId);
var result = await _basApi.GetRules(ruleStationID, status, nextStationID);
if (result.Count == 0) if (result.Count == 0)
{ {
return View(); return View();
} }
return View(result[0]); return View(result[0]);
} }
public async Task<IActionResult> BAS011DAsync(int id,string status,int nextStationID) public async Task<IActionResult> BAS011DAsync(int id)
{ {
var result = await _basApi.DeleteRules(id, status, nextStationID); var result = await _basApi.DeleteRules(id);
return Json(new Result() { success = true, msg = "" }); return Json(new Result() { success = true, msg = "" });
} }
@ -1442,13 +1443,12 @@ namespace AMESCoreStudio.Web.Controllers
{ {
if (ids.Length > 0) if (ids.Length > 0)
{ {
int id = int.Parse(ids[0].Split('_')[0]); int id = int.Parse(ids[0]);
string status = ids[0].Split('_')[1];
int nextStationID = int.Parse(ids[0].Split('_')[2]); var result = await _basApi.DeleteRules(id);
var result = await _basApi.DeleteRules(id, status, nextStationID);
for (int i = 1; i < ids.Length; i++) for (int i = 1; i < ids.Length; i++)
{ {
result = await _basApi.DeleteRules(int.Parse(ids[i].Split('_')[0]), ids[i].Split('_')[1], int.Parse(ids[i].Split('_')[2])); result = await _basApi.DeleteRules(int.Parse(ids[i]));
} }
return Json(new Result() { success = true, msg = "" }); return Json(new Result() { success = true, msg = "" });
@ -1473,7 +1473,7 @@ namespace AMESCoreStudio.Web.Controllers
} }
else else
{ {
result = await _basApi.PutRules(model.RuleStationID, model.RuleStatus, model.NextStationID, JsonConvert.SerializeObject(model)); result = await _basApi.PutRules(model.RuleID, JsonConvert.SerializeObject(model));
} }
if (result.Success) if (result.Success)
@ -1485,7 +1485,7 @@ namespace AMESCoreStudio.Web.Controllers
} }
else else
{ {
if (result.Errors.Count > 0) if (result.Errors != null)
{ {
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
} }

33
AMESCoreStudio.Web/Controllers/SYSController.cs

@ -37,11 +37,11 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetSystemInfoes(); var result = await _sysApi.GetSystemInfoes();
var SystemItems = new List<SelectListItem>(); var SystemItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++) foreach (var item in result.Data)
{ {
//SystemItems.Add(new SelectListItem(result[i].SystemNo + result[i].SystemName, result[i].SystemID.ToString())); SystemItems.Add(new SelectListItem(item.SystemName, item.SystemID.ToString()));
SystemItems.Add(new SelectListItem(result[i].SystemName, result[i].SystemID.ToString()));
} }
ViewBag.SystemList = SystemItems; ViewBag.SystemList = SystemItems;
} }
@ -62,10 +62,11 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetModuleInfoesBySystem(id, 0, 10); var result = await _sysApi.GetModuleInfoesBySystem(id, 0, 10);
var ModuleItems = new List<SelectListItem>(); var ModuleItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++) foreach (var item in result.Data)
{ {
ModuleItems.Add(new SelectListItem(result[i].ModuleNo + result[i].ModuleName, result[i].ModuleID.ToString())); ModuleItems.Add(new SelectListItem(item.ModuleNo + item.ModuleName, item.ModuleID.ToString()));
} }
ViewBag.ModuleList = ModuleItems; ViewBag.ModuleList = ModuleItems;
} }
@ -125,9 +126,9 @@ namespace AMESCoreStudio.Web.Controllers
var item = new List<SelectListItem>(); var item = new List<SelectListItem>();
item.Add(new SelectListItem("全部", "0")); item.Add(new SelectListItem("全部", "0"));
for (int i = 0; i < result.Count; i++) foreach (var data in result.Data)
{ {
item.Add(new SelectListItem(result[i].ModuleNo + result[i].ModuleName, result[i].ModuleID.ToString())); item.Add(new SelectListItem(data.ModuleNo + data.ModuleName, data.ModuleID.ToString()));
} }
//将数据Json化并传到前台视图 //将数据Json化并传到前台视图
return Json(new { data = item }); return Json(new { data = item });
@ -198,14 +199,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutSystemInfo(model.SystemID, JsonConvert.SerializeObject(model)); result = await _sysApi.PutSystemInfo(model.SystemID, JsonConvert.SerializeObject(model));
} }
if (!result.Success) if (result.Success)
{ {
var _msg = model.SystemID == 0 ? "添加成功!" : "修改成功!"; var _msg = model.SystemID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg }); return RedirectToAction("Refresh", "Home", new { msg = _msg });
} }
else else
{ {
if (result.Errors.Count > 0) if (result.Errors != null)
{ {
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
} }
@ -227,11 +228,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetSystemInfoesAsync(int page = 0, int limit = 10) public async Task<IActionResult> GetSystemInfoesAsync(int page = 0, int limit = 10)
{ {
var result = await _sysApi.GetSystemInfoes(page,limit); var result = await _sysApi.GetSystemInfoes(page,limit);
var result_total = await _sysApi.GetSystemInfoes(0, limit);
if (result.Count > 0) if (result.DataTotal > 0)
{ {
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count }); return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
} }
return Json(new Table() { count = 0, data = null }); return Json(new Table() { count = 0, data = null });
@ -296,14 +296,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutModuleInfo(model.ModuleID, JsonConvert.SerializeObject(model)); result = await _sysApi.PutModuleInfo(model.ModuleID, JsonConvert.SerializeObject(model));
} }
if (!result.Success) if (result.Success)
{ {
var _msg = model.ModuleID == 0 ? "添加成功!" : "修改成功!"; var _msg = model.ModuleID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg }); return RedirectToAction("Refresh", "Home", new { msg = _msg });
} }
else else
{ {
if (result.Errors.Count > 0) if (result.Errors != null)
{ {
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
} }
@ -339,12 +339,11 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetModuleInfoesBySystemAsync(int systemID, int page = 0, int limit = 10) public async Task<IActionResult> GetModuleInfoesBySystemAsync(int systemID, int page = 0, int limit = 10)
{ {
var result = await _sysApi.GetModuleInfoesBySystem(systemID, page, limit); var result = await _sysApi.GetModuleInfoesBySystem(systemID, page, limit);
var result_total = await _sysApi.GetModuleInfoesBySystem(systemID, 0, limit);
if (result.Count > 0) if (result.DataTotal > 0)
{ {
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count }); return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
} }
return Json(new Table() { count = 0, data = null }); return Json(new Table() { count = 0, data = null });

13
AMESCoreStudio.Web/HttpApis/IBAS.cs

@ -436,20 +436,27 @@ namespace AMESCoreStudio.Web
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpPut("api/Rules/{id}")] [WebApiClient.Attributes.HttpPut("api/Rules/{id}")]
ITask<ResultModel<Rules>> PutRules(int id, string ruleStatus, int nextStationID, [FromBody, RawJsonContent] string model); ITask<ResultModel<Rules>> PutRules(int id, [FromBody, RawJsonContent] string model);
/// <summary> /// <summary>
/// 刪除流程站別 /// 刪除流程站別
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/Rules/{id}")] [WebApiClient.Attributes.HttpDelete("api/Rules/{id}")]
ITask<ResultModel<string>> DeleteRules(int id, string ruleStatus, int nextStationID); ITask<ResultModel<string>> DeleteRules(int id);
/// <summary> /// <summary>
/// 根據ID獲取指定流程站別資料 /// 根據規則ID獲取指定流程站別資料
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/Rules/{id}")] [WebApiClient.Attributes.HttpGet("api/Rules/{id}")]
ITask<List<Rules>> GetRules(int id);
/// <summary>
/// 根據ID獲取指定流程站別資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/Rules/GetRules")]
ITask<List<Rules>> GetRules(int id, string ruleStatus, int nextStationID); ITask<List<Rules>> GetRules(int id, string ruleStatus, int nextStationID);
/// <summary> /// <summary>

8
AMESCoreStudio.Web/HttpApis/ISYS.cs

@ -32,7 +32,7 @@ namespace AMESCoreStudio.Web
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/SystemInfoes/{id}")] [WebApiClient.Attributes.HttpDelete("api/SystemInfoes/{id}")]
ITask<ResultModel<string>> DeleteSystemInfo(int id); ITask<ResultModel<SystemInfo>> DeleteSystemInfo(int id);
/// <summary> /// <summary>
/// 根據ID獲取指定系統資料 /// 根據ID獲取指定系統資料
@ -46,7 +46,7 @@ namespace AMESCoreStudio.Web
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/SystemInfoes")] [WebApiClient.Attributes.HttpGet("api/SystemInfoes")]
ITask<List<SystemInfo>> GetSystemInfoes(int page = 0, int limit = 10); ITask<ResultModel<SystemInfo>> GetSystemInfoes(int page = 0, int limit = 10);
#endregion #endregion
@ -71,7 +71,7 @@ namespace AMESCoreStudio.Web
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/ModuleInfoes/{id}")] [WebApiClient.Attributes.HttpDelete("api/ModuleInfoes/{id}")]
ITask<ResultModel<string>> DeleteModuleInfo(int id); ITask<ResultModel<ModuleInfo>> DeleteModuleInfo(int id);
/// <summary> /// <summary>
/// 根據ID獲取指定模組資料 /// 根據ID獲取指定模組資料
@ -92,7 +92,7 @@ namespace AMESCoreStudio.Web
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/ModuleInfoes/System/{id}")] [WebApiClient.Attributes.HttpGet("api/ModuleInfoes/System/{id}")]
ITask<List<ModuleInfo>> GetModuleInfoesBySystem(int id, int page = 0, int limit = 10); ITask<ResultModel<ModuleInfo>> GetModuleInfoesBySystem(int id, int page = 0, int limit = 10);
#endregion #endregion

14
AMESCoreStudio.Web/Views/BAS/BAS011.cshtml

@ -76,7 +76,7 @@
var tableCols = [[ var tableCols = [[
{ type: 'checkbox' }, { type: 'checkbox' },
{ {
field: 'ruleStationID', field: 'ruleID',
width: 120, width: 120,
title: '编号', title: '编号',
sort: true sort: true
@ -124,17 +124,17 @@
]; ];
//通过行tool编辑,lay-event="edit" //通过行tool编辑,lay-event="edit"
function edit(obj) { function edit(obj) {
if (obj.data.ruleStationID) { if (obj.data.ruleID) {
hg.open('修改流程規則', '/BAS/BAS011U/' + obj.data.ruleStationID + '_' + obj.data.ruleStatus + '_' + obj.data.nextStationID, 600, 400); hg.open('修改流程規則', '/BAS/BAS011U/' + obj.data.ruleID, 600, 400);
} }
} }
//通过行tool删除,lay-event="del" //通过行tool删除,lay-event="del"
function del(obj) { function del(obj) {
if (obj.data.ruleStationID) { if (obj.data.ruleID) {
hg.confirm("流程規則:" + obj.data.nextStation['stationName'] + ",确定要删除吗?", function () { hg.confirm("流程規則:" + obj.data.nextStation['stationName'] + ",确定要删除吗?", function () {
$.ajax({ $.ajax({
url: '/BAS/BAS011D', url: '/BAS/BAS011D',
data: { id: obj.data.ruleStationID, status: obj.data.ruleStatus, nextStationID: obj.data.nextStationID }, data: { id: obj.data.ruleID },
type: 'POST', type: 'POST',
success: function (data) { success: function (data) {
if (data.success) { if (data.success) {
@ -159,12 +159,12 @@
class: 'layui-btn-danger', class: 'layui-btn-danger',
handler: function (obj, row) { handler: function (obj, row) {
if (obj.checkstatus && obj.checkstatus.data.length > 0) { if (obj.checkstatus && obj.checkstatus.data.length > 0) {
console.log(obj.checkstatus.data.map(function (x) { return x.ruleStationID + '_' + x.ruleStatus + '_' + x.nextStationID }).join(',')) console.log(obj.checkstatus.data.map(function (x) { return x.ruleID }).join(','))
hg.confirm("批量删除所有选中的数据,确定要删除吗?", function () { hg.confirm("批量删除所有选中的数据,确定要删除吗?", function () {
$.ajax({ $.ajax({
url: '/BAS/BAS011DAll', url: '/BAS/BAS011DAll',
data: { ids: obj.checkstatus.data.map(function (x) { return x.ruleStationID + '_' + x.ruleStatus + '_' + x.nextStationID }) }, data: { ids: obj.checkstatus.data.map(function (x) { return x.ruleID }) },
type: 'POST', type: 'POST',
success: function (data) { success: function (data) {
if (data.success) { if (data.success) {

4
AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml

@ -15,9 +15,9 @@
<div class="col-sm-12"> <div class="col-sm-12">
<form enctype="multipart/form-data" method="post" asp-action="BAS011Save"> <form enctype="multipart/form-data" method="post" asp-action="BAS011Save">
<div asp-validation-summary="ModelOnly" class="text-danger"></div> <div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="RuleID" />
<input type="hidden" asp-for="RuleStationID" /> <input type="hidden" asp-for="RuleStationID" />
<input type="hidden" asp-for="RuleStatus" /> <input type="hidden" asp-for="RuleStatus" />
<input type="hidden" asp-for="NextStationID" />
<input type="hidden" asp-for="CreateDate" /> <input type="hidden" asp-for="CreateDate" />
<div class="form-group form-inline my-sm-1"> <div class="form-group form-inline my-sm-1">
@ -46,7 +46,7 @@
</div> </div>
<div class="form-group form-inline my-sm-1"> <div class="form-group form-inline my-sm-1">
<label asp-for="NextStationID" class="control-label col-sm-3"></label> <label asp-for="NextStationID" class="control-label col-sm-3"></label>
<select asp-for="NextStationID" asp-items="@ViewBag.NextStationList" class="custom-select col-sm-9" disabled></select> <select asp-for="NextStationID" asp-items="@ViewBag.NextStationList" class="custom-select col-sm-9"></select>
<span asp-validation-for="NextStationID" class="text-danger offset-sm-3 my-sm-1"></span> <span asp-validation-for="NextStationID" class="text-danger offset-sm-3 my-sm-1"></span>
</div> </div>
<div class="form-group form-inline my-sm-1"> <div class="form-group form-inline my-sm-1">

6
AMESCoreStudio.WebApi/Code/Helper.cs

@ -36,7 +36,7 @@ namespace AMESCoreStudio.WebApi
IDKey aID = new IDKey(); IDKey aID = new IDKey();
aID.IDName = idName; aID.IDName = idName;
aID.StartNum = 1000; aID.StartNum = 1000;
aID.LimitNum = Int64.MaxValue; aID.LimitNum = Int32.MaxValue;
aID.CurrentNum = 1000; aID.CurrentNum = 1000;
aID.DeltaNum = 1; aID.DeltaNum = 1;
aID.CreateDateTime = DateTime.Now; aID.CreateDateTime = DateTime.Now;
@ -68,7 +68,7 @@ namespace AMESCoreStudio.WebApi
} }
idkey = await _context.IDKeys.Where(m => m.IDName == idName).FirstOrDefaultAsync(); idkey = await _context.IDKeys.Where(m => m.IDName == idName).FirstOrDefaultAsync();
key = (int)idkey.CurrentNum; key = Convert.ToInt32(idkey.CurrentNum);
return key; return key;
} }
@ -85,7 +85,7 @@ namespace AMESCoreStudio.WebApi
if (idkey == null) if (idkey == null)
return key; return key;
else else
return key = (int)idkey.CurrentNum; return key = Convert.ToInt32(idkey.CurrentNum);
} }
} }
} }

77
AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs

@ -129,6 +129,29 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
return rules; return rules;
} }
/// <summary>
/// 根據流程規則編號查詢指定單一資料
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/Rules/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<Rules>>> GetRules(int id)
{
IQueryable<Rules> q = _context.Ruleses;
q = q.Where(p => p.RuleID.Equals(id));
var rules = await q.ToListAsync();
if (rules == null)
{
return NotFound();
}
return rules;
}
/// <summary> /// <summary>
/// 根據流程站別ID+状态+下一站查詢指定單一資料 /// 根據流程站別ID+状态+下一站查詢指定單一資料
/// </summary> /// </summary>
@ -137,7 +160,8 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
/// <param name="nextStationId"></param> /// <param name="nextStationId"></param>
/// <returns></returns> /// <returns></returns>
// GET: api/Rules/5 // GET: api/Rules/5
[HttpGet("{id}")] [Route("[action]")]
[HttpGet]
public async Task<ActionResult<IEnumerable<Rules>>> GetRules(int id, string ruleStatus, int nextStationId) public async Task<ActionResult<IEnumerable<Rules>>> GetRules(int id, string ruleStatus, int nextStationId)
{ {
IQueryable<Rules> q = _context.Ruleses; IQueryable<Rules> q = _context.Ruleses;
@ -188,49 +212,47 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
/// 更新流程规则资料 /// 更新流程规则资料
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="ruleStatus"></param>
/// <param name="nextStationId"></param>
/// <param name="rules"></param> /// <param name="rules"></param>
/// <returns></returns> /// <returns></returns>
// PUT: api/Rules/5 // PUT: api/Rules/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for // 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. // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<ResultModel<Rules>> PutRules(int id, string ruleStatus, int nextStationId, [FromBody] Rules rules) public async Task<ResultModel<Rules>> PutRules(int id, [FromBody] Rules rules)
{ {
ResultModel<Rules> result = new ResultModel<Rules>(); ResultModel<Rules> result = new ResultModel<Rules>();
var rule = await _context.Ruleses.Where(p => p.RuleStationID.Equals(id) && p.RuleStatus.Equals(ruleStatus) && p.NextStationID.Equals(nextStationId)).FirstOrDefaultAsync(); if (id != rules.RuleID)
if (rule == null)
{ {
result.Msg = "流程規則編號錯誤";
result.Success = false; result.Success = false;
result.Msg = "流程站別規則不存在";
return result; return result;
} }
rule.RuleDesc = rules.RuleDesc; rules.UpdateDate = DateTime.Now;
rule.RuleSeq = rules.RuleSeq; _context.Entry(rules).State = EntityState.Modified;
rule.UpdateDate = DateTime.Now;
_context.Ruleses.Attach(rule);
// 指定更新某個欄位
_context.Entry(rule).Property(p => p.RuleDesc).IsModified = true;
_context.Entry(rule).Property(p => p.RuleSeq).IsModified = true;
try try
{ {
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
result.Success = true;
result.Msg = "OK";
} }
catch (Exception ex) catch (DbUpdateConcurrencyException)
{ {
result.Success = false; if (!RulesExists(id))
result.Msg = ex.InnerException.Message; {
result.Msg = "流程規則編號不存在";
result.Success = false;
return result;
}
else
{
throw;
}
} }
result.Msg = "OK";
result.Success = true;
return result; return result;
} }
@ -246,6 +268,9 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
public async Task<ResultModel<Rules>> PostRules([FromBody] Rules rules) public async Task<ResultModel<Rules>> PostRules([FromBody] Rules rules)
{ {
ResultModel<Rules> result = new ResultModel<Rules>(); ResultModel<Rules> result = new ResultModel<Rules>();
Helper helper = new Helper(_context);
rules.RuleID = helper.GetIDKey("RULE_ID").Result;
rules.CreateDate = DateTime.Now; rules.CreateDate = DateTime.Now;
_context.Ruleses.Add(rules); _context.Ruleses.Add(rules);
@ -271,16 +296,14 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
/// 删除流程规则 /// 删除流程规则
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="ruleStatus"></param>
/// <param name="nextStationId"></param>
/// <returns></returns> /// <returns></returns>
// DELETE: api/Rules/5 // DELETE: api/Rules/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<ResultModel<Rules>> DeleteRules(int id, string ruleStatus, int nextStationId) public async Task<ResultModel<Rules>> DeleteRules(int id)
{ {
ResultModel<Rules> result = new ResultModel<Rules>(); ResultModel<Rules> result = new ResultModel<Rules>();
var rules = await _context.Ruleses.Where(p => p.RuleStationID.Equals(id) && p.RuleStatus.Equals(ruleStatus) && p.NextStationID.Equals(nextStationId)).FirstOrDefaultAsync(); var rules = await _context.Ruleses.Where(p => p.RuleID.Equals(id)).FirstOrDefaultAsync();
if (rules == null) if (rules == null)
{ {
@ -305,5 +328,9 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
return result; return result;
} }
private bool RulesExists(int id)
{
return _context.Ruleses.Any(e => e.RuleID == id);
}
} }
} }

60
AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS; using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS namespace AMESCoreStudio.WebApi.Controllers.SYS
{ {
@ -52,14 +53,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns> /// <returns></returns>
// GET: api/ModuleInfoes/System/5 // GET: api/ModuleInfoes/System/5
[HttpGet("System/{id}")] [HttpGet("System/{id}")]
public async Task<ActionResult<IEnumerable<ModuleInfo>>> GetModuleInfoBySystem(int id, int page = 0, int limit = 10) public async Task<ResultModel<ModuleInfo>> GetModuleInfoBySystem(int id, int page = 0, int limit = 10)
{ {
ResultModel<ModuleInfo> result = new ResultModel<ModuleInfo>();
IQueryable<ModuleInfo> q = _context.ModuleInfoes; IQueryable<ModuleInfo> q = _context.ModuleInfoes;
if (id > 0) if (id > 0)
{ {
q = q.Where(p => p.SystemID.Equals(id)); q = q.Where(p => p.SystemID.Equals(id));
} }
result.DataTotal = q.ToList().Count;
if (page > 0) if (page > 0)
{ {
q = q.OrderBy(p => p.SortSeq).Skip((page - 1) * limit).Take(limit); q = q.OrderBy(p => p.SortSeq).Skip((page - 1) * limit).Take(limit);
@ -73,21 +78,28 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{ {
var moduleInfo = await q.ToListAsync(); var moduleInfo = await q.ToListAsync();
result.Data = moduleInfo;
if (moduleInfo == null) if (moduleInfo == null)
{ {
return NotFound(); result.Msg = "查無資料";
result.Success = false;
return result;
} }
return moduleInfo; result.Msg = "OK";
result.Success = true;
return result;
} }
catch (Exception e1) catch (Exception e1)
{ {
string msg = e1.Message; string msg = e1.Message;
} }
return NotFound();
result.Msg = "OK";
result.Success = true;
return result;
} }
@ -126,11 +138,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for // 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. // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<ActionResult<ModuleInfo>> PutModuleInfo(int id, [FromBody] ModuleInfo moduleInfo) public async Task<ResultModel<ModuleInfo>> PutModuleInfo(int id, [FromBody] ModuleInfo moduleInfo)
{ {
ResultModel<ModuleInfo> result = new ResultModel<ModuleInfo>();
if (id != moduleInfo.ModuleID) if (id != moduleInfo.ModuleID)
{ {
return BadRequest(); result.Msg = "模組編號錯誤";
result.Success = false;
return result;
} }
_context.Entry(moduleInfo).State = EntityState.Modified; _context.Entry(moduleInfo).State = EntityState.Modified;
@ -143,7 +159,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{ {
if (!ModuleInfoExists(id)) if (!ModuleInfoExists(id))
{ {
return NotFound(); result.Msg = "模組編號不存在";
result.Success = false;
return result;
} }
else else
{ {
@ -151,8 +169,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
} }
} }
return moduleInfo; result.Msg = "OK";
//return NoContent(); result.Success = true;
return result;
} }
/// <summary> /// <summary>
@ -164,8 +183,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for // 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. // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost] [HttpPost]
public async Task<ActionResult<ModuleInfo>> PostModuleInfo([FromBody] ModuleInfo moduleInfo) public async Task<ResultModel<ModuleInfo>> PostModuleInfo([FromBody] ModuleInfo moduleInfo)
{ {
ResultModel<ModuleInfo> result = new ResultModel<ModuleInfo>();
Helper helper = new Helper(_context); Helper helper = new Helper(_context);
moduleInfo.ModuleID = helper.GetIDKey("MODULE_ID").Result; moduleInfo.ModuleID = helper.GetIDKey("MODULE_ID").Result;
moduleInfo.CreateDateTime = DateTime.Now; moduleInfo.CreateDateTime = DateTime.Now;
@ -174,7 +195,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.ModuleInfoes.Add(moduleInfo); _context.ModuleInfoes.Add(moduleInfo);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return CreatedAtAction("GetModuleInfo", new { id = moduleInfo.ModuleID }, moduleInfo); result.Msg = "OK";
result.Success = true;
return result;
} }
/// <summary> /// <summary>
@ -184,19 +207,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns> /// <returns></returns>
// DELETE: api/ModuleInfoes/5 // DELETE: api/ModuleInfoes/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<ActionResult<ModuleInfo>> DeleteModuleInfo(int id) public async Task<ResultModel<ModuleInfo>> DeleteModuleInfo(int id)
{ {
//var moduleInfo = await _context.ModuleInfoes.FindAsync(id); ResultModel<ModuleInfo> result = new ResultModel<ModuleInfo>();
var moduleInfo = await _context.ModuleInfoes.Where(m => m.ModuleID == id).FirstOrDefaultAsync(); var moduleInfo = await _context.ModuleInfoes.Where(m => m.ModuleID == id).FirstOrDefaultAsync();
if (moduleInfo == null) if (moduleInfo == null)
{ {
return NotFound(); result.Msg = "模組編號不存在";
result.Success = false;
return result;
} }
_context.ModuleInfoes.Remove(moduleInfo); _context.ModuleInfoes.Remove(moduleInfo);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return moduleInfo; result.Msg = "OK";
result.Success = true;
return result;
} }
private bool ModuleInfoExists(int id) private bool ModuleInfoExists(int id)

59
AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS; using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS namespace AMESCoreStudio.WebApi.Controllers.SYS
{ {
@ -34,10 +35,13 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns> /// <returns></returns>
// GET: api/SystemInfoes // GET: api/SystemInfoes
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<SystemInfo>>> GetSystemInfo(int page = 0, int limit = 10) public async Task<ResultModel<SystemInfo>> GetSystemInfo(int page = 0, int limit = 10)
{ {
ResultModel<SystemInfo> result = new ResultModel<SystemInfo>();
IQueryable<SystemInfo> q = _context.SystemInfoes; IQueryable<SystemInfo> q = _context.SystemInfoes;
result.DataTotal = q.ToList().Count;
if (page > 0) if (page > 0)
{ {
q = q.OrderBy(p => p.SystemID).Skip((page - 1) * limit).Take(limit); ; q = q.OrderBy(p => p.SystemID).Skip((page - 1) * limit).Take(limit); ;
@ -47,13 +51,20 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
q = q.OrderBy(p => p.SystemID); q = q.OrderBy(p => p.SystemID);
} }
//q = q.OrderByDescending(p => p.SystemID);
var systemInfo = await q.ToListAsync(); var systemInfo = await q.ToListAsync();
//return await _context.SystemInfoes.ToListAsync(); result.Data = systemInfo;
return systemInfo; if (systemInfo == null)
{
result.Msg = "查無資料";
result.Success = false;
return result;
}
result.Success = true;
result.Msg = "OK";
return result;
} }
/// <summary> /// <summary>
@ -89,11 +100,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for // 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. // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<ActionResult<SystemInfo>> PutSystemInfo(int id, [FromBody] SystemInfo systemInfo) public async Task<ResultModel<SystemInfo>> PutSystemInfo(int id, [FromBody] SystemInfo systemInfo)
{ {
ResultModel<SystemInfo> result = new ResultModel<SystemInfo>();
if (id != systemInfo.SystemID) if (id != systemInfo.SystemID)
{ {
return BadRequest(); result.Success = false;
result.Msg = "系統編號錯誤";
return result;
} }
_context.Entry(systemInfo).State = EntityState.Modified; _context.Entry(systemInfo).State = EntityState.Modified;
@ -108,7 +123,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{ {
if (!SystemInfoExists(id)) if (!SystemInfoExists(id))
{ {
return NotFound(); result.Success = false;
result.Msg = "系統編號不存在";
return result;
} }
else else
{ {
@ -116,8 +133,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
} }
} }
return systemInfo; result.Success = true;
//return NoContent(); result.Msg = "OK";
return result;
} }
/// <summary> /// <summary>
@ -129,8 +147,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for // 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. // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost] [HttpPost]
public async Task<ActionResult<SystemInfo>> PostSystemInfo([FromBody] SystemInfo systemInfo) public async Task<ResultModel<SystemInfo>> PostSystemInfo([FromBody] SystemInfo systemInfo)
{ {
ResultModel<SystemInfo> result = new ResultModel<SystemInfo>();
Helper helper = new Helper(_context); Helper helper = new Helper(_context);
systemInfo.SystemID = helper.GetIDKey("SYSTEM_ID").Result; systemInfo.SystemID = helper.GetIDKey("SYSTEM_ID").Result;
systemInfo.CreateDateTime = DateTime.Now; systemInfo.CreateDateTime = DateTime.Now;
@ -139,7 +159,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.SystemInfoes.Add(systemInfo); _context.SystemInfoes.Add(systemInfo);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return CreatedAtAction("GetSystemInfo", new { id = systemInfo.SystemID }, systemInfo); result.Success = true;
result.Msg = "OK";
return result;
} }
/// <summary> /// <summary>
@ -149,19 +171,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns> /// <returns></returns>
// DELETE: api/SystemInfoes/5 // DELETE: api/SystemInfoes/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<ActionResult<SystemInfo>> DeleteSystemInfo(int id) public async Task<ResultModel<SystemInfo>> DeleteSystemInfo(int id)
{ {
//var systemInfo = await _context.SystemInfo.FindAsync(id); ResultModel<SystemInfo> result = new ResultModel<SystemInfo>();
var systemInfo = await _context.SystemInfoes.Where(m => m.SystemID == id).FirstOrDefaultAsync(); var systemInfo = await _context.SystemInfoes.Where(m => m.SystemID == id).FirstOrDefaultAsync();
if (systemInfo == null) if (systemInfo == null)
{ {
return NotFound(); result.Success = false;
result.Msg = "系統編號不存在";
return result;
} }
_context.SystemInfoes.Remove(systemInfo); _context.SystemInfoes.Remove(systemInfo);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return systemInfo; result.Success = true;
result.Msg = "OK";
return result;
} }
private bool SystemInfoExists(int id) private bool SystemInfoExists(int id)

2
AMESCoreStudio.WebApi/Models/AMESContext.cs

@ -36,7 +36,7 @@ namespace AMESCoreStudio.WebApi
.HasOne(m => m.Module); .HasOne(m => m.Module);
*/ */
modelBuilder.Entity<Rules>().HasKey(c => new { c.RuleStationID, c.RuleStatus, c.NextStationID }); modelBuilder.Entity<Rules>().HasKey(c => new { c.RuleID });
modelBuilder.Entity<WipBarcode>().HasKey(c => new { c.WipNO, c.StartNO, c.EndNO }); modelBuilder.Entity<WipBarcode>().HasKey(c => new { c.WipNO, c.StartNO, c.EndNO });
modelBuilder.Entity<WipLog>().HasKey(c => new { c.WipID, c.CreateDate }); modelBuilder.Entity<WipLog>().HasKey(c => new { c.WipID, c.CreateDate });
modelBuilder.Entity<PartMap>().HasKey(c => new { c.CorpSN }); modelBuilder.Entity<PartMap>().HasKey(c => new { c.CorpSN });

14
AMESCoreStudio.WebApi/Models/BAS/Rules.cs

@ -11,10 +11,18 @@ namespace AMESCoreStudio.WebApi.Models.BAS
[Table("RULES", Schema = "JHAMES")] [Table("RULES", Schema = "JHAMES")]
public class Rules public class Rules
{ {
/// <summary>
/// 流程規則編號
/// </summary>
[Key, Column("RULE_ID")]
[Display(Name = "流程規則編號")]
[DataMember]
public int RuleID { get; set; }
/// <summary> /// <summary>
/// 流程站別編號 /// 流程站別編號
/// </summary> /// </summary>
[Key,Column("RULE_STATION_ID",Order =0)] [Column("RULE_STATION_ID")]
[Display(Name = "流程站別編號")] [Display(Name = "流程站別編號")]
[DataMember] [DataMember]
public int RuleStationID { get; set; } public int RuleStationID { get; set; }
@ -32,7 +40,7 @@ namespace AMESCoreStudio.WebApi.Models.BAS
/// <summary> /// <summary>
/// 規則狀態 /// 規則狀態
/// </summary> /// </summary>
[Key,Column("RULE_STATUS",Order =1)] [Column("RULE_STATUS")]
[Display(Name = "規則狀態")] [Display(Name = "規則狀態")]
[DataMember] [DataMember]
public string RuleStatus { get; set; } public string RuleStatus { get; set; }
@ -40,7 +48,7 @@ namespace AMESCoreStudio.WebApi.Models.BAS
/// <summary> /// <summary>
/// 下一站別編號 /// 下一站別編號
/// </summary> /// </summary>
[Key,Column("NEXT_STATION_ID",Order =2)] [Column("NEXT_STATION_ID")]
[Display(Name = "下一站別編號")] [Display(Name = "下一站別編號")]
[DataMember] [DataMember]
public int NextStationID { get; set; } public int NextStationID { get; set; }

8
AMESCoreStudio.WebApi/Models/SYS/IDKey.cs

@ -26,28 +26,28 @@ namespace AMESCoreStudio.WebApi.Models.SYS
/// </summary> /// </summary>
[Column("CURRENT_NUM")] [Column("CURRENT_NUM")]
[Required] [Required]
public Int64 CurrentNum { get; set; } public int CurrentNum { get; set; }
/// <summary> /// <summary>
/// 初始值 /// 初始值
/// </summary> /// </summary>
[Column("START_NUM")] [Column("START_NUM")]
[Required] [Required]
public Int64 StartNum { get; set; } public int StartNum { get; set; }
/// <summary> /// <summary>
/// 最大值 /// 最大值
/// </summary> /// </summary>
[Column("LIMIT_NUM")] [Column("LIMIT_NUM")]
[Required] [Required]
public Int64 LimitNum { get; set; } public int LimitNum { get; set; }
/// <summary> /// <summary>
/// 增量 /// 增量
/// </summary> /// </summary>
[Column("DELTA_NUM")] [Column("DELTA_NUM")]
[Required] [Required]
public Int32 DeltaNum { get; set; } public int DeltaNum { get; set; }
/// <summary> /// <summary>
/// 建立時間 /// 建立時間

Loading…
Cancel
Save