From f912d062ff629416f23d71669f5543085fba5659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=BE=8E=E8=8D=A3?= <10755671+mei-rong-he@user.noreply.gitee.com> Date: Tue, 17 Mar 2026 12:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=BB=BB=E5=8A=A1=E5=BA=93?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/HM/T_HM_OPERATION_LINK.cs | 2 +- APT.MS.Domain/Enums/HM/HMRiskEnum.cs | 4 + .../Api/OperationLinkController.cs | 903 ++++++++++++------ 3 files changed, 598 insertions(+), 311 deletions(-) diff --git a/APT.MS.Domain/Entities/HM/T_HM_OPERATION_LINK.cs b/APT.MS.Domain/Entities/HM/T_HM_OPERATION_LINK.cs index 3301695..cdb96f5 100644 --- a/APT.MS.Domain/Entities/HM/T_HM_OPERATION_LINK.cs +++ b/APT.MS.Domain/Entities/HM/T_HM_OPERATION_LINK.cs @@ -153,7 +153,7 @@ namespace APT.MS.Domain.Entities.HM public Guid? PARENT_ID { get; set; } /// - /// 修改状态 数据库 = 0,修改=1,新增=2 + /// 修改状态 数据库 = 0,修改=1,新增=2,导入=3 /// [Description("修改状态")] [EnumName("HMModifyEnum")] diff --git a/APT.MS.Domain/Enums/HM/HMRiskEnum.cs b/APT.MS.Domain/Enums/HM/HMRiskEnum.cs index 986d9cb..02000bb 100644 --- a/APT.MS.Domain/Enums/HM/HMRiskEnum.cs +++ b/APT.MS.Domain/Enums/HM/HMRiskEnum.cs @@ -107,6 +107,10 @@ namespace APT.MS.Domain.Enums /// 新增 /// 新增 = 2, + /// + /// 导入 + /// + 导入 = 3, } /// /// 周期 diff --git a/APT.MicroApi/APT.HM.WebApi/Controllers/Api/OperationLinkController.cs b/APT.MicroApi/APT.HM.WebApi/Controllers/Api/OperationLinkController.cs index 678537f..46e08bf 100644 --- a/APT.MicroApi/APT.HM.WebApi/Controllers/Api/OperationLinkController.cs +++ b/APT.MicroApi/APT.HM.WebApi/Controllers/Api/OperationLinkController.cs @@ -2,288 +2,309 @@ using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums; -using APT.BaseData.Services.Services.FM; -using APT.Infrastructure.Core; -using APT.MS.Domain.Entities.BS; -using APT.MS.Domain.Entities.HM; -using APT.MS.Domain.Entities.SC.PT; -using APT.MS.Domain.Enums; -using APT.Utility; -using Microsoft.AspNetCore.Mvc; -using NPOI.SS.Formula.Functions; -using System; -using System.Collections.Generic; -using System.Data; -using System.IO; -using System.Linq; -using System.Linq.Expressions; - -namespace APT.HM.WebApi.Controllers.Api -{ - /// - /// 作业任务库 - /// - [Route("api/HM/HMOperationLink")] - public partial class OperationLinkController : AuthorizeApiController - { - /// - /// 更新或新增数据 - /// - /// 对象实体 - /// - [HttpPost, Route("FullUpdate")] - public JsonActionResult FullUpdate([FromBody] T_HM_OPERATION_LINK entity) - { - return SafeExecute(() => - { - var history = this.GetEntity(t => t.OPERATION_STEP_ID == entity.OPERATION_STEP_ID && t.ID != entity.ID, "Nav_OperationStep"); - if (history != null) - throw new Exception("已存在名为"+ history.Nav_OperationStep.NAME+"的数据,请修改作业名称"); - var details = entity.Nav_LinkPost; - entity.Nav_OperationLinkEvaluateRisk = null; - entity.Nav_LinkPost = null; - var areas = entity.Nav_LinkArea; - entity.Nav_LinkArea = null; - if (areas != null && areas.Any()) - { - areas.ForEach(t => - { - t.ORG_ID = entity.ORG_ID; - t.OPERATION_LINK_ID = entity.ID; - t.Nav_Area = null; - }); - } - if (details != null && details.Any()) - { - details.ForEach(t => - { - t.ORG_ID = entity.ORG_ID; - t.OPERATION_LINK_ID = entity.ID; - t.Nav_Post = null; - }); - var postName = details.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); - entity.POST = string.Join(",", postName); - } - var safeConfirms = entity.Nav_SafeConfirms; - entity.Nav_SafeConfirms = null; - if (safeConfirms != null && safeConfirms.Any()) - { - safeConfirms.ForEach(t => - { - t.ORG_ID = entity.ORG_ID; - t.OPERATION_LINK_ID = entity.ID; - }); - } - var safeMesasures = entity.Nav_SafeMeasures; - entity.Nav_SafeMeasures = null; - if (safeMesasures != null && safeMesasures.Any()) - { - safeMesasures.ForEach(t => - { - t.ORG_ID = entity.ORG_ID; - t.OPERATION_LINK_ID = entity.ID; - }); - } - var safeDeal = entity.Nav_DealMeasures; - entity.Nav_DealMeasures = null; - if (safeDeal != null && safeDeal.Any()) - { - safeDeal.ForEach(t => - { - t.ORG_ID = entity.ORG_ID; - t.OPERATION_LINK_ID = entity.ID; - }); - } - UnifiedCommit(() => - { - if (entity != null) - this.UpdateEntityNoCommit(entity); - if (details != null && details.Any()) - this.BantchSaveEntityNoCommit(details); - if (areas != null && areas.Any()) - this.BantchSaveEntityNoCommit(areas); - if (safeConfirms != null && safeConfirms.Any()) - this.BantchSaveEntityNoCommit(safeConfirms); - if (safeMesasures != null && safeMesasures.Any()) - this.BantchSaveEntityNoCommit(safeMesasures); - if (safeDeal != null && safeDeal.Any()) - this.BantchSaveEntityNoCommit(safeDeal); - }); - return true; - }); - } - /// - /// 获取 - /// - /// - /// - [HttpPost, Route("GetEdit")] - public JsonActionResult GetEdit([FromBody] KeywordFilter filter) - { - return SafeExecute(() => { - var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString(); - if (string.IsNullOrEmpty(id)) - this.ThrowError("030017"); - var result = this.GetEntity(id, new string[] { "Nav_OperationStep", "Nav_WorkPermitType","Nav_LinkPost","Nav_LinkPost.Nav_Post", - "Nav_SafeConfirms", "Nav_SafeMeasures", "Nav_DealMeasures", "Nav_Files","Nav_Unit" }); - if (result.Nav_LinkPost != null && result.Nav_LinkPost.Any()) - { - var postName = result.Nav_LinkPost.Where(t=>t.Nav_Post!=null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); - result.POST = string.Join(",", postName); +using APT.BaseData.Services.Services.FM; +using APT.Infrastructure.Core; +using APT.MS.Domain.Entities.BS; +using APT.MS.Domain.Entities.HM; +using APT.MS.Domain.Entities.SC.PT; +using APT.MS.Domain.Enums; +using APT.MS.Domain.Enums.SK; +using APT.Utility; +using Google.Protobuf.WellKnownTypes; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Linq.Expressions; + +namespace APT.HM.WebApi.Controllers.Api +{ + /// + /// 作业任务库 + /// + [Route("api/HM/HMOperationLink")] + public partial class OperationLinkController : AuthorizeApiController + { + /// + /// 更新或新增数据 + /// + /// 对象实体 + /// + [HttpPost, Route("FullUpdate")] + public JsonActionResult FullUpdate([FromBody] T_HM_OPERATION_LINK entity) + { + return SafeExecute(() => + { + var history = this.GetEntity(t => t.OPERATION_STEP_ID == entity.OPERATION_STEP_ID && t.ID != entity.ID, "Nav_OperationStep"); + if (history != null) + throw new Exception("已存在名为"+ history.Nav_OperationStep.NAME+"的数据,请修改作业名称"); + var details = entity.Nav_LinkPost; + entity.Nav_OperationLinkEvaluateRisk = null; + entity.Nav_LinkPost = null; + var areas = entity.Nav_LinkArea; + entity.Nav_LinkArea = null; + if (areas != null && areas.Any()) + { + areas.ForEach(t => + { + t.ORG_ID = entity.ORG_ID; + t.OPERATION_LINK_ID = entity.ID; + t.Nav_Area = null; + }); + } + if (details != null && details.Any()) + { + details.ForEach(t => + { + t.ORG_ID = entity.ORG_ID; + t.OPERATION_LINK_ID = entity.ID; + t.Nav_Post = null; + }); + var postName = details.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); + entity.POST = string.Join(",", postName); + } + var safeConfirms = entity.Nav_SafeConfirms; + entity.Nav_SafeConfirms = null; + if (safeConfirms != null && safeConfirms.Any()) + { + safeConfirms.ForEach(t => + { + t.ORG_ID = entity.ORG_ID; + t.OPERATION_LINK_ID = entity.ID; + }); + } + var safeMesasures = entity.Nav_SafeMeasures; + entity.Nav_SafeMeasures = null; + if (safeMesasures != null && safeMesasures.Any()) + { + safeMesasures.ForEach(t => + { + t.ORG_ID = entity.ORG_ID; + t.OPERATION_LINK_ID = entity.ID; + }); + } + var safeDeal = entity.Nav_DealMeasures; + entity.Nav_DealMeasures = null; + if (safeDeal != null && safeDeal.Any()) + { + safeDeal.ForEach(t => + { + t.ORG_ID = entity.ORG_ID; + t.OPERATION_LINK_ID = entity.ID; + }); + } + UnifiedCommit(() => + { + if (entity != null) + this.UpdateEntityNoCommit(entity); + if (details != null && details.Any()) + this.BantchSaveEntityNoCommit(details); + if (areas != null && areas.Any()) + this.BantchSaveEntityNoCommit(areas); + if (safeConfirms != null && safeConfirms.Any()) + this.BantchSaveEntityNoCommit(safeConfirms); + if (safeMesasures != null && safeMesasures.Any()) + this.BantchSaveEntityNoCommit(safeMesasures); + if (safeDeal != null && safeDeal.Any()) + this.BantchSaveEntityNoCommit(safeDeal); + }); + return true; + }); + } + /// + /// 获取 + /// + /// + /// + [HttpPost, Route("GetEdit")] + public JsonActionResult GetEdit([FromBody] KeywordFilter filter) + { + return SafeExecute(() => { + var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString(); + if (string.IsNullOrEmpty(id)) + this.ThrowError("030017"); + var result = this.GetEntity(id, new string[] { "Nav_OperationStep", "Nav_WorkPermitType","Nav_LinkPost","Nav_LinkPost.Nav_Post", + "Nav_SafeConfirms", "Nav_SafeMeasures", "Nav_DealMeasures", "Nav_Files","Nav_Unit" }); + if (result.Nav_LinkPost != null && result.Nav_LinkPost.Any()) + { + var postName = result.Nav_LinkPost.Where(t=>t.Nav_Post!=null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); + result.POST = string.Join(",", postName); } if (result.Nav_SafeConfirms != null && result.Nav_SafeConfirms.Any()) { - result.Nav_SafeConfirms.OrderBy(t => t.NUM); - } + result.Nav_SafeConfirms = result.Nav_SafeConfirms.OrderBy(t => t.NUM).ToList(); + } if (result.Nav_SafeMeasures != null && result.Nav_SafeMeasures.Any()) { - result.Nav_SafeMeasures.OrderBy(t => t.NUM); - } + result.Nav_SafeMeasures = result.Nav_SafeMeasures.OrderBy(t => t.NUM).ToList(); + } if (result.Nav_DealMeasures != null && result.Nav_DealMeasures.Any()) { - result.Nav_DealMeasures.OrderBy(t => t.NUM); - } - return result; - }); - } - /// - /// 排序分页查询数据 - /// - /// 分页过滤实体 - /// - [HttpPost, Route("FullOrderPaged")] - public PagedActionResult FullOrderPaged([FromBody] KeywordPageFilter pageFilter) - { - KeywordPageFilter keywordPageFilter = new KeywordPageFilter(); - keywordPageFilter = pageFilter; - var rule = keywordPageFilter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "POST"); - if (rule != null) - keywordPageFilter.FilterGroup.Rules.Remove(rule); - keywordPageFilter.IgnoreDataRule = true; - //pageFilter.Include.Add("Nav_LinkPost"); - //pageFilter.Include.Add("Nav_LinkPost.Nav_Post"); - Expression> expression = e => !e.IS_DELETED; - //var mineType = APT.Infrastructure.Api.AppContext.CurrentSession.MineType; - //if (!string.IsNullOrEmpty(mineType)) - //{ - // var tempList = mineType.Split(",").ToList(); - // expression = expression.And(t => tempList.Contains(t.MineType.ToString())); - //} - var result = this.GetOrderPageEntities(expression, keywordPageFilter, null); - if (result.TotalCount > 0) - { - result.Data.ForEach(t => - { - if (t.Nav_LinkPost != null && t.Nav_LinkPost.Any()) - { - var postName = t.Nav_LinkPost.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); - t.POST = string.Join(",", postName); - } - if (t.Nav_SafeConfirms != null && t.Nav_SafeConfirms.Any()) - { - foreach (var safe in t.Nav_SafeConfirms) - { - var safeTemp = safe.NUM + safe.NAME + ";"; - t.SafeConfirmsStr = t.SafeConfirmsStr + safeTemp; - } - } - if (t.Nav_SafeMeasures != null && t.Nav_SafeMeasures.Any()) - { - foreach (var safe in t.Nav_SafeMeasures) - { - var safeTemp = safe.NUM + safe.NAME + ";"; - t.SafeMeasuresStr = t.SafeMeasuresStr + safeTemp; - } - } - if (t.Nav_DealMeasures != null && t.Nav_DealMeasures.Any()) - { - foreach (var safe in t.Nav_DealMeasures) - { - var safeTemp = safe.NUM + safe.NAME + ";"; - t.DealMeasuresStr = t.DealMeasuresStr + safeTemp; - } - } - }); - if (rule != null) - { - result.Data = result.Data.Where(t =>t.POST!=null && t.POST.Contains(rule.Value.ToString())); - } - } - return result; + result.Nav_DealMeasures = result.Nav_DealMeasures.OrderBy(t => t.NUM).ToList(); + } + return result; + }); } - /// - /// 获取导入数据 - /// 参考 [Route("api/PF/Import")] - /// - /// - [HttpPost, Route("GetImportData")] - public JsonActionResult GetImportData() - { - return SafeExecute(() => - { - var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; - var httpRequest = this.HttpContext.Request; - string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 - ImportDataModel result = new ImportDataModel(); - var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); - if (!Directory.Exists(dic)) - Directory.CreateDirectory(dic); - foreach (var key in httpRequest.Form.Files) // 文件键 - { - var postedFile = key; // 获取文件键对应的文件对象 - string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); - Byte[] fileData = new Byte[postedFile.Length]; - Stream sr = postedFile.OpenReadStream();//创建数据流对象 - sr.Read(fileData, 0, (int)postedFile.Length); - using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) - { - fs.Write(fileData, 0, fileData.Length); - fs.Flush(); - fs.Close(); - } - - //获取数据 - Dictionary startRowIndexs = new Dictionary(); - startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 - var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); - string Msg = string.Empty; - - bool isOK = InsertModel(dataTables.Tables[0], orgId, ref Msg); - - try - { - System.IO.File.Delete(filePath); - } - catch { } - - result.Data = Msg; - result.MessageList = new List { Msg }; - } - - return result; - }); - } - - /// - /// 数据插入 - /// - /// - /// - /// - /// - /// - /// - public bool InsertModel(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1) - { - var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; - if (dtSource == null || dtSource.Rows.Count < rowIndex) - { - Msg = "未获取到导入数据"; - throw new Exception(Msg); - } - int rowAll = dtSource.Rows.Count; - - //作业任务库 + /// + /// 排序分页查询数据 + /// + /// 分页过滤实体 + /// + [HttpPost, Route("FullOrderPaged")] + public PagedActionResult FullOrderPaged([FromBody] KeywordPageFilter pageFilter) + { + KeywordPageFilter keywordPageFilter = new KeywordPageFilter(); + keywordPageFilter = pageFilter; + var rule = keywordPageFilter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "POST"); + if (rule != null) + keywordPageFilter.FilterGroup.Rules.Remove(rule); + keywordPageFilter.IgnoreDataRule = true; + keywordPageFilter.Include.Add("Nav_LinkPost"); + keywordPageFilter.Include.Add("Nav_LinkPost.Nav_Post"); + keywordPageFilter.Include.Add("Nav_SafeConfirms"); + keywordPageFilter.Include.Add("Nav_SafeMeasures"); + keywordPageFilter.Include.Add("Nav_DealMeasures"); + keywordPageFilter.SelectField.Add("Nav_LinkPost.Nav_Post.NAME"); + keywordPageFilter.SelectField.Add("Nav_SafeConfirms.NUM"); + keywordPageFilter.SelectField.Add("Nav_SafeConfirms.NAME"); + keywordPageFilter.SelectField.Add("Nav_SafeMeasures.NUM"); + keywordPageFilter.SelectField.Add("Nav_SafeMeasures.NAME"); + keywordPageFilter.SelectField.Add("Nav_DealMeasures.NUM"); + keywordPageFilter.SelectField.Add("Nav_DealMeasures.NAME"); + Expression> expression = e => !e.IS_DELETED; + //var mineType = APT.Infrastructure.Api.AppContext.CurrentSession.MineType; + //if (!string.IsNullOrEmpty(mineType)) + //{ + // var tempList = mineType.Split(",").ToList(); + // expression = expression.And(t => tempList.Contains(t.MineType.ToString())); + //} + var result = this.GetOrderPageEntities(expression, keywordPageFilter); + if (result.TotalCount > 0) + { + result.Data.ForEach(t => + { + if (t.Nav_LinkPost != null && t.Nav_LinkPost.Any()) + { + var postName = t.Nav_LinkPost.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList(); + t.POST = string.Join(",", postName); + } + if (t.Nav_SafeConfirms != null && t.Nav_SafeConfirms.Any()) + { + foreach (var safe in t.Nav_SafeConfirms.OrderBy(m=>m.NUM)) + { + if (safe!=null) + { + var safeTemp = safe.NUM + "、" + safe.NAME + ";"; + t.SafeConfirmsStr = t.SafeConfirmsStr + safeTemp; + } + } + } + if (t.Nav_SafeMeasures != null && t.Nav_SafeMeasures.Any()) + { + foreach (var safe in t.Nav_SafeMeasures.OrderBy(m => m.NUM)) + { + if (safe != null) + { + var safeTemp = safe.NUM + "、" + safe.NAME + ";"; + t.SafeMeasuresStr = t.SafeMeasuresStr + safeTemp; + } + } + } + if (t.Nav_DealMeasures != null && t.Nav_DealMeasures.Any()) + { + foreach (var safe in t.Nav_DealMeasures.OrderBy(m => m.NUM)) + { + if (safe != null) + { + var safeTemp = safe.NUM + "、" + safe.NAME + ";"; + t.DealMeasuresStr = t.DealMeasuresStr + safeTemp; + } + } + } + }); + if (rule != null) + { + result.Data = result.Data.Where(t =>t.POST!=null && t.POST.Contains(rule.Value.ToString())); + } + } + return result; + } + /// + /// 获取导入数据 + /// 参考 [Route("api/PF/Import")] + /// + /// + [HttpPost, Route("GetImportData")] + public JsonActionResult GetImportData() + { + return SafeExecute(() => + { + var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; + var httpRequest = this.HttpContext.Request; + string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 + ImportDataModel result = new ImportDataModel(); + var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); + if (!Directory.Exists(dic)) + Directory.CreateDirectory(dic); + foreach (var key in httpRequest.Form.Files) // 文件键 + { + var postedFile = key; // 获取文件键对应的文件对象 + string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); + Byte[] fileData = new Byte[postedFile.Length]; + Stream sr = postedFile.OpenReadStream();//创建数据流对象 + sr.Read(fileData, 0, (int)postedFile.Length); + using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) + { + fs.Write(fileData, 0, fileData.Length); + fs.Flush(); + fs.Close(); + } + + //获取数据 + Dictionary startRowIndexs = new Dictionary(); + startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 + var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); + string Msg = string.Empty; + + bool isOK = InsertModel(dataTables.Tables[0], orgId, ref Msg); + + try + { + System.IO.File.Delete(filePath); + } + catch { } + + result.Data = Msg; + result.MessageList = new List { Msg }; + } + + return result; + }); + } + + /// + /// 数据插入 + /// + /// + /// + /// + /// + /// + /// + public bool InsertModel(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1) + { + var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; + if (dtSource == null || dtSource.Rows.Count < rowIndex) + { + Msg = "未获取到导入数据"; + throw new Exception(Msg); + } + int rowAll = dtSource.Rows.Count; + + //作业任务库 var links = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); //作业环节 var steps = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); @@ -292,58 +313,86 @@ namespace APT.HM.WebApi.Controllers.Api //生产单元 var proUnits = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); //人员岗位 - var posts = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); - List linkList = new List(); - List linkPostList = new List(); - List linkConList = new List(); - List linkMeasList = new List(); - List linkDealList = new List(); - for (int i = 0; i < rowAll; i++) + var posts = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); + + //先做一次非空判断 + if (!string.IsNullOrEmpty(Msg)) { - if (string.IsNullOrEmpty(dtSource.Rows[i][0].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][1].ToString().Trim()) - || string.IsNullOrEmpty(dtSource.Rows[i][2].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][3].ToString().Trim()) - || string.IsNullOrEmpty(dtSource.Rows[i][4].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][5].ToString().Trim()) - || string.IsNullOrEmpty(dtSource.Rows[i][6].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][7].ToString().Trim())) - { - Msg = Msg + "第" + (i + 2) + "行生产单元,作业环节,任务类型,是否关键作业,作业周期,作业许可审批层级,作业许可类别,作业等级存在空数据,请先检查所有字段内容;"; - } - } - //先做一次非空判断 - if (!string.IsNullOrEmpty(Msg)) - { - throw new Exception(Msg); + throw new Exception(Msg); } - for (int i = 0; i < rowAll; i++) + for (int i = 0; i < rowAll; i++) { - var proUnit = dtSource.Rows[i][0].ToString().Trim(); - var proUnitFirst = proUnits.FirstOrDefault(t => t.NAME == proUnit); + if (string.IsNullOrEmpty(dtSource.Rows[i][0].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][1].ToString().Trim()) + || string.IsNullOrEmpty(dtSource.Rows[i][2].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][3].ToString().Trim()) + || string.IsNullOrEmpty(dtSource.Rows[i][4].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][5].ToString().Trim()) + || string.IsNullOrEmpty(dtSource.Rows[i][6].ToString().Trim()) || string.IsNullOrEmpty(dtSource.Rows[i][7].ToString().Trim())) + { + Msg = Msg + "第" + (i + 3) + "行生产单元,作业环节,任务类型,是否关键作业,作业周期,作业许可审批层级,作业许可类别,作业等级存在空数据,请先检查所有字段内容;"; + } + } + //基础数据判断 + for (int i = 0; i < rowAll; i++) + { + var proUnit = dtSource.Rows[i][0].ToString().Trim(); + var proUnitFirst = proUnits.FirstOrDefault(t => t.NAME == proUnit); if (proUnitFirst == null) { - Msg = Msg + "第" + (i + 2) + "行生产单元"+ proUnit + "不存在,请先到系统管理维护;"; - } + Msg = Msg + "第" + (i + 3) + "行生产单元"+ proUnit + "不存在,请先到系统管理维护;"; + } var step = dtSource.Rows[i][1].ToString().Trim(); - var stepFirst = steps.FirstOrDefault(t => t.NAME == step); + var stepFirst = steps.FirstOrDefault(t => t.NAME == step); if (stepFirst == null) { - Msg = Msg + "第" + (i + 2) + "行作业环节" + step + "不存在,请先到系统管理维护;"; + Msg = Msg + "第" + (i + 3) + "行作业环节" + step + "不存在,请先到系统管理维护;"; } else { var linkFirst = links.FirstOrDefault(t => t.OPERATION_STEP_ID == stepFirst.ID); if (linkFirst != null) { - Msg = Msg + "第" + (i + 2) + "行作业环节" + step + "已存在库中,请勿重复导入;"; + Msg = Msg + "第" + (i + 3) + "行作业环节" + step + "已存在库中,请勿重复导入;"; } } + var taskType = dtSource.Rows[i][2].ToString().Trim(); + if (taskType != "一般任务" && taskType != "关键任务非许可作业" && taskType != "许可作业") + { + Msg = Msg + "第" + (i + 3) + "行任务类型只能填写一般任务、关键任务非许可作业、许可作业,请修改" + taskType + ";"; + } + var isNeed = dtSource.Rows[i][3].ToString().Trim(); + if (isNeed != "是" && isNeed != "否") + { + Msg = Msg + "第" + (i + 3) + "行是否关键任务只能填写是、否,请修改" + isNeed + ";"; + } + var workCycle = dtSource.Rows[i][4].ToString().Trim(); + if (workCycle != "每日作业" && workCycle != "需求作业") + { + Msg = Msg + "第" + (i + 3) + "行作业周期只能填写每日作业、需求作业,请修改" + workCycle + ";"; + } + var approveLevel = dtSource.Rows[i][5].ToString().Trim(); + if (approveLevel != "无审批层级" && approveLevel != "一级审批" && approveLevel != "二级审批" && approveLevel != "三级审批" + && approveLevel != "四级审批" && approveLevel != "特级审批" && approveLevel != "临时用电") + { + Msg = Msg + "第" + (i + 3) + "行作业审批层级只能填写无审批层级、一级审批、二级审批、三级审批、四级审批、特级审批、临时用电,请修改" + approveLevel + ";"; + } var workType = dtSource.Rows[i][6].ToString().Trim(); - var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType); + var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType); if (workTypeFirst == null) { - Msg = Msg + "第" + (i + 2) + "行作业许可类别"+ workType + "不存在,请先到系统管理维护;"; + Msg = Msg + "第" + (i + 3) + "行作业许可类别"+ workType + "不存在,请先到系统管理维护;"; + } + var workLevel = dtSource.Rows[i][7].ToString().Trim(); + if (workLevel != "重大风险" && workLevel != "较大风险" && workLevel != "一般风险" && workLevel != "低风险") + { + Msg = Msg + "第" + (i + 3) + "行作业等级只能填写重大风险、较大风险、一般风险、低风险,请修改" + workLevel + ";"; + } + var status = dtSource.Rows[i][8].ToString().Trim(); + if (status != "启用" && status != "停用") + { + Msg = Msg + "第" + (i + 3) + "行状态只能填写启用、停用,请修改" + status + ";"; } if (!string.IsNullOrEmpty(dtSource.Rows[i][9].ToString().Trim())) { - var lists = dtSource.Rows[i][9].ToString().Trim().Split(",").ToList(); + var lists = dtSource.Rows[i][9].ToString().Trim().Split(",").ToList(); if (lists!=null && lists.Any()) { foreach (var item in lists) @@ -353,18 +402,252 @@ namespace APT.HM.WebApi.Controllers.Api var postFirst = posts.FirstOrDefault(t => t.NAME == item); if (postFirst == null) { - Msg = Msg + "第" + (i + 2) + "行岗位"+ item + "不存在,请先到系统管理维护;"; + Msg = Msg + "第" + (i + 3) + "行岗位"+ item + "不存在,请先到系统管理维护;"; + } + } + } + } + } + + } + if (!string.IsNullOrEmpty(Msg)) + { + throw new Exception(Msg); + } + //导入 + List linkList = new List(); + List linkPostList = new List(); + List linkConList = new List(); + List linkMeasList = new List(); + List linkDealList = new List(); + for (int i = 0; i < rowAll; i++) + { + var proUnit = dtSource.Rows[i][0].ToString().Trim(); + var proUnitFirst = proUnits.FirstOrDefault(t => t.NAME == proUnit); + var step = dtSource.Rows[i][1].ToString().Trim(); + var stepFirst = steps.FirstOrDefault(t => t.NAME == step); + var taskType = dtSource.Rows[i][2].ToString().Trim(); + var isNeed = dtSource.Rows[i][3].ToString().Trim(); + var workCycle = dtSource.Rows[i][4].ToString().Trim(); + var approveLevel = dtSource.Rows[i][5].ToString().Trim(); + var workType = dtSource.Rows[i][6].ToString().Trim(); + var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType); + var workLevel = dtSource.Rows[i][7].ToString().Trim(); + var status = dtSource.Rows[i][8].ToString().Trim(); + var postList = dtSource.Rows[i][9].ToString().Trim(); + var conList = dtSource.Rows[i][10].ToString().Trim(); + var mesList = dtSource.Rows[i][11].ToString().Trim(); + var delList = dtSource.Rows[i][12].ToString().Trim(); + T_HM_OPERATION_LINK link = new T_HM_OPERATION_LINK(); + link.ORG_ID = orgId; + link.UNIT_ID = proUnitFirst.ID; + link.OPERATION_STEP_ID = stepFirst.ID; + link.WORK_PERMIT_TYPE_ID = workTypeFirst.ID; + link.CODE = DateTime.Now.ToString("yyyyMMddHH") + i.ToString().PadLeft(4, '0'); + link.NAME = stepFirst.NAME; + link.MODIFY_TYPE = HMModifyEnum.导入; + link.IS_RUN = DisableStatusEnum.否; + switch (taskType) + { + case "一般任务": + link.TASK_LEVEL = (int)HMTaskLevelEnum.一般任务; + break; + case "关键任务非许可作业": + link.TASK_LEVEL = (int)HMTaskLevelEnum.关键任务非许可作业; + break; + case "许可作业": + link.TASK_LEVEL = (int)HMTaskLevelEnum.许可作业; + break; + default:break; + } + switch (isNeed) + { + case "是": + link.IS_IMPORTANT = (int)ISImportantEnum.是; + break; + case "否": + link.IS_IMPORTANT = (int)ISImportantEnum.否; + break; + default: break; + } + switch (workCycle) + { + case "每日作业": + link.CYCLE_TYPE = HMCycleTypeEnum.Day; + break; + case "需求作业": + link.CYCLE_TYPE = HMCycleTypeEnum.Need; + break; + default: break; + } + switch (approveLevel) + { + case "无审批层级": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.无审批层级; + break; + case "一级审批": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.一级审批; + break; + case "二级审批": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.二级审批; + break; + case "三级审批": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.三级审批; + break; + case "四级审批": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.四级审批; + break; + case "特级审批": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.特级审批; + break; + case "临时用电": + link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.临时用电; + break; + default: break; + } + switch (workLevel) + { + case "重大风险": + link.EVALUATE_LEVEL = SKEvaluateLevelEnum.重大风险; + break; + case "较大风险": + link.EVALUATE_LEVEL = SKEvaluateLevelEnum.较大风险; + break; + case "一般风险": + link.EVALUATE_LEVEL = SKEvaluateLevelEnum.一般风险; + break; + case "低风险": + link.EVALUATE_LEVEL = SKEvaluateLevelEnum.低风险; + break; + default: break; + } + switch (status) + { + case "启用": + link.STATUS = (int)STATUSEnum.启用; + break; + case "停用": + link.STATUS = (int)STATUSEnum.停用; + break; + default: break; + } + linkList.Add(link); + if (!string.IsNullOrEmpty(postList)) + { + var lists = postList.Split(",").ToList(); + if (lists != null && lists.Any()) + { + foreach (var item in lists) + { + if (!string.IsNullOrEmpty(item)) + { + var postFirst = posts.FirstOrDefault(t => t.NAME == item); + T_HM_OPERATION_LINK_POST post = new T_HM_OPERATION_LINK_POST(); + post.ORG_ID = orgId; + post.OPERATION_LINK_ID = link.ID; + post.POST_ID = postFirst.ID; + linkPostList.Add(post); + } + } + } + } + if (!string.IsNullOrEmpty(conList)) + { + var lists = conList.Split(";").ToList(); + if (lists != null && lists.Any()) + { + foreach (var item in lists) + { + if (!string.IsNullOrEmpty(item)) + { + if (item.Contains("、")) + { + var num = item.Split("、")[0]; + var name = item.Split("、")[1]; + T_HM_OPERATION_TASK_SAFE_CONFIRM con = new T_HM_OPERATION_TASK_SAFE_CONFIRM(); + con.ORG_ID = orgId; + con.OPERATION_LINK_ID = link.ID; + con.NUM = string.IsNullOrEmpty(num)?null:int.Parse(num); + con.NAME = name; + linkConList.Add(con); + } + else + { + T_HM_OPERATION_TASK_SAFE_CONFIRM con = new T_HM_OPERATION_TASK_SAFE_CONFIRM(); + con.ORG_ID = orgId; + con.OPERATION_LINK_ID = link.ID; + con.NAME = item; + linkConList.Add(con); + } + } + } + } + } + if (!string.IsNullOrEmpty(mesList)) + { + var lists = mesList.Split(";").ToList(); + if (lists != null && lists.Any()) + { + foreach (var item in lists) + { + if (!string.IsNullOrEmpty(item)) + { + if (item.Contains("、")) + { + var num = item.Split("、")[0]; + var name = item.Split("、")[1]; + T_HM_OPERATION_TASK_SAFE_MEASURE mes = new T_HM_OPERATION_TASK_SAFE_MEASURE(); + mes.ORG_ID = orgId; + mes.OPERATION_LINK_ID = link.ID; + mes.NUM = string.IsNullOrEmpty(num) ? null : int.Parse(num); + mes.NAME = name; + linkMeasList.Add(mes); + } + else + { + T_HM_OPERATION_TASK_SAFE_MEASURE mes = new T_HM_OPERATION_TASK_SAFE_MEASURE(); + mes.ORG_ID = orgId; + mes.OPERATION_LINK_ID = link.ID; + mes.NAME = item; + linkMeasList.Add(mes); + } + } + } + } + } + if (!string.IsNullOrEmpty(delList)) + { + var lists = delList.Split(";").ToList(); + if (lists != null && lists.Any()) + { + foreach (var item in lists) + { + if (!string.IsNullOrEmpty(item)) + { + if (item.Contains("、")) + { + var num = item.Split("、")[0]; + var name = item.Split("、")[1]; + T_HM_OPERATION_TASK_DEAL_MEASURE del = new T_HM_OPERATION_TASK_DEAL_MEASURE(); + del.ORG_ID = orgId; + del.OPERATION_LINK_ID = link.ID; + del.NUM = string.IsNullOrEmpty(num) ? null : int.Parse(num); + del.NAME = name; + linkDealList.Add(del); + } + else + { + T_HM_OPERATION_TASK_DEAL_MEASURE del = new T_HM_OPERATION_TASK_DEAL_MEASURE(); + del.ORG_ID = orgId; + del.OPERATION_LINK_ID = link.ID; + del.NAME = item; + linkDealList.Add(del); } } } } } - } - if (!string.IsNullOrEmpty(Msg)) - { - throw new Exception(Msg); - } UnifiedCommit(() => { if (linkList != null && linkList.Any())