From 51ec88335add387071bda09c5b53727a474f96bc Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 31 Mar 2022 15:39:12 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9Helper,=E6=96=B0=E5=A2=9EID?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E5=80=BC=E7=82=BAInt32=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E5=80=BC=202.=E4=BF=AE=E6=94=B9=E7=B3=BB?= =?UTF-8?q?=E7=B5=B1=E8=B3=87=E6=96=99=E7=B6=AD=E8=AD=B7(=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=BC=95=E7=94=A8ResultModel)=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=B3=BB=E7=B5=B1=E6=A8=A1=E7=B5=84=E7=B6=AD=E8=AD=B7(?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=95=E7=94=A8ResultModel)=204.=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=B5=81=E7=A8=8B=E8=A6=8F=E5=89=87=E7=B6=AD=E8=AD=B7?= =?UTF-8?q?(=E6=96=B0=E5=A2=9ERULE=5FID=E7=82=BAPK)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BASController.cs | 30 ++++---- .../Controllers/SYSController.cs | 33 ++++---- AMESCoreStudio.Web/HttpApis/IBAS.cs | 13 +++- AMESCoreStudio.Web/HttpApis/ISYS.cs | 8 +- AMESCoreStudio.Web/Views/BAS/BAS011.cshtml | 14 ++-- AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml | 4 +- AMESCoreStudio.WebApi/Code/Helper.cs | 6 +- .../Controllers/BAS/RulesController.cs | 77 +++++++++++++------ .../Controllers/SYS/ModuleInfoesController.cs | 60 +++++++++++---- .../Controllers/SYS/SystemInfoesController.cs | 59 ++++++++++---- AMESCoreStudio.WebApi/Models/AMESContext.cs | 2 +- AMESCoreStudio.WebApi/Models/BAS/Rules.cs | 14 +++- AMESCoreStudio.WebApi/Models/SYS/IDKey.cs | 8 +- 13 files changed, 212 insertions(+), 116 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/BASController.cs b/AMESCoreStudio.Web/Controllers/BASController.cs index 80570f77..5fea0bd2 100644 --- a/AMESCoreStudio.Web/Controllers/BASController.cs +++ b/AMESCoreStudio.Web/Controllers/BASController.cs @@ -1413,28 +1413,29 @@ namespace AMESCoreStudio.Web.Controllers [HttpGet] public async Task BAS011UAsync(string id) { - int ruleStationID = int.Parse(id.Split('_')[0]); - string status = id.Split('_')[1]; - int nextStationID = int.Parse(id.Split('_')[2]); + int ruleID = int.Parse(id); + var result = await _basApi.GetRules(ruleID); 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; await GetRuleStationList(flowId); await GetNextStationList(flowId); - var result = await _basApi.GetRules(ruleStationID, status, nextStationID); - if (result.Count == 0) { return View(); } + return View(result[0]); } - public async Task BAS011DAsync(int id,string status,int nextStationID) + public async Task BAS011DAsync(int id) { - var result = await _basApi.DeleteRules(id, status, nextStationID); + var result = await _basApi.DeleteRules(id); return Json(new Result() { success = true, msg = "" }); } @@ -1442,13 +1443,12 @@ namespace AMESCoreStudio.Web.Controllers { if (ids.Length > 0) { - int id = int.Parse(ids[0].Split('_')[0]); - string status = ids[0].Split('_')[1]; - int nextStationID = int.Parse(ids[0].Split('_')[2]); - var result = await _basApi.DeleteRules(id, status, nextStationID); + int id = int.Parse(ids[0]); + + var result = await _basApi.DeleteRules(id); 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 = "" }); @@ -1473,7 +1473,7 @@ namespace AMESCoreStudio.Web.Controllers } 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) @@ -1485,7 +1485,7 @@ namespace AMESCoreStudio.Web.Controllers } else { - if (result.Errors.Count > 0) + if (result.Errors != null) { ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); } diff --git a/AMESCoreStudio.Web/Controllers/SYSController.cs b/AMESCoreStudio.Web/Controllers/SYSController.cs index 0b9d7a36..8d5a6aac 100644 --- a/AMESCoreStudio.Web/Controllers/SYSController.cs +++ b/AMESCoreStudio.Web/Controllers/SYSController.cs @@ -37,11 +37,11 @@ namespace AMESCoreStudio.Web.Controllers var result = await _sysApi.GetSystemInfoes(); var SystemItems = new List(); - 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(result[i].SystemName, result[i].SystemID.ToString())); + SystemItems.Add(new SelectListItem(item.SystemName, item.SystemID.ToString())); } + ViewBag.SystemList = SystemItems; } @@ -62,10 +62,11 @@ namespace AMESCoreStudio.Web.Controllers var result = await _sysApi.GetModuleInfoesBySystem(id, 0, 10); var ModuleItems = new List(); - 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; } @@ -125,9 +126,9 @@ namespace AMESCoreStudio.Web.Controllers var item = new List(); 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化并传到前台视图 return Json(new { data = item }); @@ -198,14 +199,14 @@ namespace AMESCoreStudio.Web.Controllers result = await _sysApi.PutSystemInfo(model.SystemID, JsonConvert.SerializeObject(model)); } - if (!result.Success) + if (result.Success) { var _msg = model.SystemID == 0 ? "添加成功!" : "修改成功!"; return RedirectToAction("Refresh", "Home", new { msg = _msg }); } else { - if (result.Errors.Count > 0) + if (result.Errors != null) { ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); } @@ -227,11 +228,10 @@ namespace AMESCoreStudio.Web.Controllers public async Task GetSystemInfoesAsync(int page = 0, int limit = 10) { 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 }); @@ -296,14 +296,14 @@ namespace AMESCoreStudio.Web.Controllers result = await _sysApi.PutModuleInfo(model.ModuleID, JsonConvert.SerializeObject(model)); } - if (!result.Success) + if (result.Success) { var _msg = model.ModuleID == 0 ? "添加成功!" : "修改成功!"; return RedirectToAction("Refresh", "Home", new { msg = _msg }); } else { - if (result.Errors.Count > 0) + if (result.Errors != null) { ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); } @@ -339,12 +339,11 @@ namespace AMESCoreStudio.Web.Controllers public async Task GetModuleInfoesBySystemAsync(int systemID, int page = 0, int limit = 10) { 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 }); diff --git a/AMESCoreStudio.Web/HttpApis/IBAS.cs b/AMESCoreStudio.Web/HttpApis/IBAS.cs index 451094c9..e4a8a2a8 100644 --- a/AMESCoreStudio.Web/HttpApis/IBAS.cs +++ b/AMESCoreStudio.Web/HttpApis/IBAS.cs @@ -436,20 +436,27 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpPut("api/Rules/{id}")] - ITask> PutRules(int id, string ruleStatus, int nextStationID, [FromBody, RawJsonContent] string model); + ITask> PutRules(int id, [FromBody, RawJsonContent] string model); /// /// 刪除流程站別 /// /// [WebApiClient.Attributes.HttpDelete("api/Rules/{id}")] - ITask> DeleteRules(int id, string ruleStatus, int nextStationID); + ITask> DeleteRules(int id); /// - /// 根據ID獲取指定流程站別資料 + /// 根據規則ID獲取指定流程站別資料 /// /// [WebApiClient.Attributes.HttpGet("api/Rules/{id}")] + ITask> GetRules(int id); + + /// + /// 根據ID獲取指定流程站別資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/Rules/GetRules")] ITask> GetRules(int id, string ruleStatus, int nextStationID); /// diff --git a/AMESCoreStudio.Web/HttpApis/ISYS.cs b/AMESCoreStudio.Web/HttpApis/ISYS.cs index 1200b578..04a03802 100644 --- a/AMESCoreStudio.Web/HttpApis/ISYS.cs +++ b/AMESCoreStudio.Web/HttpApis/ISYS.cs @@ -32,7 +32,7 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpDelete("api/SystemInfoes/{id}")] - ITask> DeleteSystemInfo(int id); + ITask> DeleteSystemInfo(int id); /// /// 根據ID獲取指定系統資料 @@ -46,7 +46,7 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpGet("api/SystemInfoes")] - ITask> GetSystemInfoes(int page = 0, int limit = 10); + ITask> GetSystemInfoes(int page = 0, int limit = 10); #endregion @@ -71,7 +71,7 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpDelete("api/ModuleInfoes/{id}")] - ITask> DeleteModuleInfo(int id); + ITask> DeleteModuleInfo(int id); /// /// 根據ID獲取指定模組資料 @@ -92,7 +92,7 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpGet("api/ModuleInfoes/System/{id}")] - ITask> GetModuleInfoesBySystem(int id, int page = 0, int limit = 10); + ITask> GetModuleInfoesBySystem(int id, int page = 0, int limit = 10); #endregion diff --git a/AMESCoreStudio.Web/Views/BAS/BAS011.cshtml b/AMESCoreStudio.Web/Views/BAS/BAS011.cshtml index 5fa4aee3..c01828bd 100644 --- a/AMESCoreStudio.Web/Views/BAS/BAS011.cshtml +++ b/AMESCoreStudio.Web/Views/BAS/BAS011.cshtml @@ -76,7 +76,7 @@ var tableCols = [[ { type: 'checkbox' }, { - field: 'ruleStationID', + field: 'ruleID', width: 120, title: '编号', sort: true @@ -124,17 +124,17 @@ ]; //通过行tool编辑,lay-event="edit" function edit(obj) { - if (obj.data.ruleStationID) { - hg.open('修改流程規則', '/BAS/BAS011U/' + obj.data.ruleStationID + '_' + obj.data.ruleStatus + '_' + obj.data.nextStationID, 600, 400); + if (obj.data.ruleID) { + hg.open('修改流程規則', '/BAS/BAS011U/' + obj.data.ruleID, 600, 400); } } //通过行tool删除,lay-event="del" function del(obj) { - if (obj.data.ruleStationID) { + if (obj.data.ruleID) { hg.confirm("流程規則:" + obj.data.nextStation['stationName'] + ",确定要删除吗?", function () { $.ajax({ url: '/BAS/BAS011D', - data: { id: obj.data.ruleStationID, status: obj.data.ruleStatus, nextStationID: obj.data.nextStationID }, + data: { id: obj.data.ruleID }, type: 'POST', success: function (data) { if (data.success) { @@ -159,12 +159,12 @@ class: 'layui-btn-danger', handler: function (obj, row) { 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 () { $.ajax({ 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', success: function (data) { if (data.success) { diff --git a/AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml b/AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml index 44ad2d50..8c8326bd 100644 --- a/AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml +++ b/AMESCoreStudio.Web/Views/BAS/BAS011U.cshtml @@ -15,9 +15,9 @@
+ -
@@ -46,7 +46,7 @@
- +
diff --git a/AMESCoreStudio.WebApi/Code/Helper.cs b/AMESCoreStudio.WebApi/Code/Helper.cs index 9fa704bf..ab0dc371 100644 --- a/AMESCoreStudio.WebApi/Code/Helper.cs +++ b/AMESCoreStudio.WebApi/Code/Helper.cs @@ -36,7 +36,7 @@ namespace AMESCoreStudio.WebApi IDKey aID = new IDKey(); aID.IDName = idName; aID.StartNum = 1000; - aID.LimitNum = Int64.MaxValue; + aID.LimitNum = Int32.MaxValue; aID.CurrentNum = 1000; aID.DeltaNum = 1; aID.CreateDateTime = DateTime.Now; @@ -68,7 +68,7 @@ namespace AMESCoreStudio.WebApi } idkey = await _context.IDKeys.Where(m => m.IDName == idName).FirstOrDefaultAsync(); - key = (int)idkey.CurrentNum; + key = Convert.ToInt32(idkey.CurrentNum); return key; } @@ -85,7 +85,7 @@ namespace AMESCoreStudio.WebApi if (idkey == null) return key; else - return key = (int)idkey.CurrentNum; + return key = Convert.ToInt32(idkey.CurrentNum); } } } diff --git a/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs b/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs index 02f1f241..cd4f6b7a 100644 --- a/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs @@ -129,6 +129,29 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS return rules; } + /// + /// 根據流程規則編號查詢指定單一資料 + /// + /// + /// + // GET: api/Rules/5 + [HttpGet("{id}")] + public async Task>> GetRules(int id) + { + IQueryable q = _context.Ruleses; + + q = q.Where(p => p.RuleID.Equals(id)); + + var rules = await q.ToListAsync(); + + if (rules == null) + { + return NotFound(); + } + + return rules; + } + /// /// 根據流程站別ID+状态+下一站查詢指定單一資料 /// @@ -137,7 +160,8 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS /// /// // GET: api/Rules/5 - [HttpGet("{id}")] + [Route("[action]")] + [HttpGet] public async Task>> GetRules(int id, string ruleStatus, int nextStationId) { IQueryable q = _context.Ruleses; @@ -188,49 +212,47 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS /// 更新流程规则资料 /// /// - /// - /// /// /// // PUT: api/Rules/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}")] - public async Task> PutRules(int id, string ruleStatus, int nextStationId, [FromBody] Rules rules) + public async Task> PutRules(int id, [FromBody] Rules rules) { ResultModel result = new ResultModel(); - var rule = await _context.Ruleses.Where(p => p.RuleStationID.Equals(id) && p.RuleStatus.Equals(ruleStatus) && p.NextStationID.Equals(nextStationId)).FirstOrDefaultAsync(); - - if (rule == null) + if (id != rules.RuleID) { + result.Msg = "流程規則編號錯誤"; result.Success = false; - result.Msg = "流程站別規則不存在"; return result; } - rule.RuleDesc = rules.RuleDesc; - rule.RuleSeq = rules.RuleSeq; - rule.UpdateDate = DateTime.Now; - - _context.Ruleses.Attach(rule); + rules.UpdateDate = DateTime.Now; + _context.Entry(rules).State = EntityState.Modified; - // 指定更新某個欄位 - _context.Entry(rule).Property(p => p.RuleDesc).IsModified = true; - _context.Entry(rule).Property(p => p.RuleSeq).IsModified = true; try { await _context.SaveChangesAsync(); - result.Success = true; - result.Msg = "OK"; } - catch (Exception ex) + catch (DbUpdateConcurrencyException) { - result.Success = false; - result.Msg = ex.InnerException.Message; + if (!RulesExists(id)) + { + result.Msg = "流程規則編號不存在"; + result.Success = false; + return result; + } + else + { + throw; + } } + result.Msg = "OK"; + result.Success = true; return result; } @@ -246,6 +268,9 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS public async Task> PostRules([FromBody] Rules rules) { ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); + rules.RuleID = helper.GetIDKey("RULE_ID").Result; + rules.CreateDate = DateTime.Now; _context.Ruleses.Add(rules); @@ -271,16 +296,14 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS /// 删除流程规则 /// /// - /// - /// /// // DELETE: api/Rules/5 [HttpDelete("{id}")] - public async Task> DeleteRules(int id, string ruleStatus, int nextStationId) + public async Task> DeleteRules(int id) { ResultModel result = new ResultModel(); - 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) { @@ -305,5 +328,9 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS return result; } + private bool RulesExists(int id) + { + return _context.Ruleses.Any(e => e.RuleID == id); + } } } diff --git a/AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs b/AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs index 09b3d872..9b8fb55b 100644 --- a/AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/SYS/ModuleInfoesController.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using AMESCoreStudio.WebApi.Models.SYS; +using AMESCoreStudio.CommonTools.Result; namespace AMESCoreStudio.WebApi.Controllers.SYS { @@ -52,14 +53,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS /// // GET: api/ModuleInfoes/System/5 [HttpGet("System/{id}")] - public async Task>> GetModuleInfoBySystem(int id, int page = 0, int limit = 10) + public async Task> GetModuleInfoBySystem(int id, int page = 0, int limit = 10) { + ResultModel result = new ResultModel(); + IQueryable q = _context.ModuleInfoes; if (id > 0) { q = q.Where(p => p.SystemID.Equals(id)); } + result.DataTotal = q.ToList().Count; + if (page > 0) { 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(); - + result.Data = moduleInfo; 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) { 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 // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. [HttpPut("{id}")] - public async Task> PutModuleInfo(int id, [FromBody] ModuleInfo moduleInfo) + public async Task> PutModuleInfo(int id, [FromBody] ModuleInfo moduleInfo) { + ResultModel result = new ResultModel(); + if (id != moduleInfo.ModuleID) { - return BadRequest(); + result.Msg = "模組編號錯誤"; + result.Success = false; + return result; } _context.Entry(moduleInfo).State = EntityState.Modified; @@ -143,7 +159,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS { if (!ModuleInfoExists(id)) { - return NotFound(); + result.Msg = "模組編號不存在"; + result.Success = false; + return result; } else { @@ -151,8 +169,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS } } - return moduleInfo; - //return NoContent(); + result.Msg = "OK"; + result.Success = true; + return result; } /// @@ -164,8 +183,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS // 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> PostModuleInfo([FromBody] ModuleInfo moduleInfo) + public async Task> PostModuleInfo([FromBody] ModuleInfo moduleInfo) { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); moduleInfo.ModuleID = helper.GetIDKey("MODULE_ID").Result; moduleInfo.CreateDateTime = DateTime.Now; @@ -174,7 +195,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS _context.ModuleInfoes.Add(moduleInfo); await _context.SaveChangesAsync(); - return CreatedAtAction("GetModuleInfo", new { id = moduleInfo.ModuleID }, moduleInfo); + result.Msg = "OK"; + result.Success = true; + return result; } /// @@ -184,19 +207,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS /// // DELETE: api/ModuleInfoes/5 [HttpDelete("{id}")] - public async Task> DeleteModuleInfo(int id) + public async Task> DeleteModuleInfo(int id) { - //var moduleInfo = await _context.ModuleInfoes.FindAsync(id); + ResultModel result = new ResultModel(); + var moduleInfo = await _context.ModuleInfoes.Where(m => m.ModuleID == id).FirstOrDefaultAsync(); if (moduleInfo == null) { - return NotFound(); + result.Msg = "模組編號不存在"; + result.Success = false; + return result; } _context.ModuleInfoes.Remove(moduleInfo); await _context.SaveChangesAsync(); - return moduleInfo; + result.Msg = "OK"; + result.Success = true; + return result; } private bool ModuleInfoExists(int id) diff --git a/AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs b/AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs index d9e1b3ba..e7b0ed95 100644 --- a/AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/SYS/SystemInfoesController.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using AMESCoreStudio.WebApi.Models.SYS; +using AMESCoreStudio.CommonTools.Result; namespace AMESCoreStudio.WebApi.Controllers.SYS { @@ -34,10 +35,13 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS /// // GET: api/SystemInfoes [HttpGet] - public async Task>> GetSystemInfo(int page = 0, int limit = 10) + public async Task> GetSystemInfo(int page = 0, int limit = 10) { + ResultModel result = new ResultModel(); IQueryable q = _context.SystemInfoes; + result.DataTotal = q.ToList().Count; + if (page > 0) { 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.OrderByDescending(p => p.SystemID); - 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; } /// @@ -89,11 +100,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS // 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}")] - public async Task> PutSystemInfo(int id, [FromBody] SystemInfo systemInfo) + public async Task> PutSystemInfo(int id, [FromBody] SystemInfo systemInfo) { + ResultModel result = new ResultModel(); + if (id != systemInfo.SystemID) { - return BadRequest(); + result.Success = false; + result.Msg = "系統編號錯誤"; + return result; } _context.Entry(systemInfo).State = EntityState.Modified; @@ -108,7 +123,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS { if (!SystemInfoExists(id)) { - return NotFound(); + result.Success = false; + result.Msg = "系統編號不存在"; + return result; } else { @@ -116,8 +133,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS } } - return systemInfo; - //return NoContent(); + result.Success = true; + result.Msg = "OK"; + return result; } /// @@ -129,8 +147,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS // 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> PostSystemInfo([FromBody] SystemInfo systemInfo) + public async Task> PostSystemInfo([FromBody] SystemInfo systemInfo) { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); systemInfo.SystemID = helper.GetIDKey("SYSTEM_ID").Result; systemInfo.CreateDateTime = DateTime.Now; @@ -139,7 +159,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS _context.SystemInfoes.Add(systemInfo); await _context.SaveChangesAsync(); - return CreatedAtAction("GetSystemInfo", new { id = systemInfo.SystemID }, systemInfo); + result.Success = true; + result.Msg = "OK"; + return result; } /// @@ -149,19 +171,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS /// // DELETE: api/SystemInfoes/5 [HttpDelete("{id}")] - public async Task> DeleteSystemInfo(int id) + public async Task> DeleteSystemInfo(int id) { - //var systemInfo = await _context.SystemInfo.FindAsync(id); + ResultModel result = new ResultModel(); + var systemInfo = await _context.SystemInfoes.Where(m => m.SystemID == id).FirstOrDefaultAsync(); if (systemInfo == null) { - return NotFound(); + result.Success = false; + result.Msg = "系統編號不存在"; + return result; } _context.SystemInfoes.Remove(systemInfo); await _context.SaveChangesAsync(); - return systemInfo; + result.Success = true; + result.Msg = "OK"; + return result; } private bool SystemInfoExists(int id) diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 40de7d55..19ac7d5a 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -36,7 +36,7 @@ namespace AMESCoreStudio.WebApi .HasOne(m => m.Module); */ - modelBuilder.Entity().HasKey(c => new { c.RuleStationID, c.RuleStatus, c.NextStationID }); + modelBuilder.Entity().HasKey(c => new { c.RuleID }); modelBuilder.Entity().HasKey(c => new { c.WipNO, c.StartNO, c.EndNO }); modelBuilder.Entity().HasKey(c => new { c.WipID, c.CreateDate }); modelBuilder.Entity().HasKey(c => new { c.CorpSN }); diff --git a/AMESCoreStudio.WebApi/Models/BAS/Rules.cs b/AMESCoreStudio.WebApi/Models/BAS/Rules.cs index e76b6035..bdd36c45 100644 --- a/AMESCoreStudio.WebApi/Models/BAS/Rules.cs +++ b/AMESCoreStudio.WebApi/Models/BAS/Rules.cs @@ -11,10 +11,18 @@ namespace AMESCoreStudio.WebApi.Models.BAS [Table("RULES", Schema = "JHAMES")] public class Rules { + /// + /// 流程規則編號 + /// + [Key, Column("RULE_ID")] + [Display(Name = "流程規則編號")] + [DataMember] + public int RuleID { get; set; } + /// /// 流程站別編號 /// - [Key,Column("RULE_STATION_ID",Order =0)] + [Column("RULE_STATION_ID")] [Display(Name = "流程站別編號")] [DataMember] public int RuleStationID { get; set; } @@ -32,7 +40,7 @@ namespace AMESCoreStudio.WebApi.Models.BAS /// /// 規則狀態 /// - [Key,Column("RULE_STATUS",Order =1)] + [Column("RULE_STATUS")] [Display(Name = "規則狀態")] [DataMember] public string RuleStatus { get; set; } @@ -40,7 +48,7 @@ namespace AMESCoreStudio.WebApi.Models.BAS /// /// 下一站別編號 /// - [Key,Column("NEXT_STATION_ID",Order =2)] + [Column("NEXT_STATION_ID")] [Display(Name = "下一站別編號")] [DataMember] public int NextStationID { get; set; } diff --git a/AMESCoreStudio.WebApi/Models/SYS/IDKey.cs b/AMESCoreStudio.WebApi/Models/SYS/IDKey.cs index 542d9288..f9c1d160 100644 --- a/AMESCoreStudio.WebApi/Models/SYS/IDKey.cs +++ b/AMESCoreStudio.WebApi/Models/SYS/IDKey.cs @@ -26,28 +26,28 @@ namespace AMESCoreStudio.WebApi.Models.SYS /// [Column("CURRENT_NUM")] [Required] - public Int64 CurrentNum { get; set; } + public int CurrentNum { get; set; } /// /// 初始值 /// [Column("START_NUM")] [Required] - public Int64 StartNum { get; set; } + public int StartNum { get; set; } /// /// 最大值 /// [Column("LIMIT_NUM")] [Required] - public Int64 LimitNum { get; set; } + public int LimitNum { get; set; } /// /// 增量 /// [Column("DELTA_NUM")] [Required] - public Int32 DeltaNum { get; set; } + public int DeltaNum { get; set; } /// /// 建立時間