diff --git a/APT.MS.Data/Mapping/T4/T4Map.cs b/APT.MS.Data/Mapping/T4/T4Map.cs index efe3778..f918765 100644 --- a/APT.MS.Data/Mapping/T4/T4Map.cs +++ b/APT.MS.Data/Mapping/T4/T4Map.cs @@ -12373,6 +12373,8 @@ builder.HasOne(t => t.Nav_Law).WithMany().HasForeignKey(t => t.LAW_ID).OnDelete( builder.Property(t => t.DESCREPTION).HasMaxLength(500); builder.Property(t => t.DEMAND).HasMaxLength(500); builder.Ignore(t => t.QUESTION_LEVEL_SHOW); +builder.Ignore(t => t.CHECKCONTENT); +builder.Ignore(t => t.PRODUCTION_UNIT_ID); } } #endregion diff --git a/APT.MS.Domain/Entities/SK/T_SK_CHECK_QUESTION.cs b/APT.MS.Domain/Entities/SK/T_SK_CHECK_QUESTION.cs index c15fbc4..befd94c 100644 --- a/APT.MS.Domain/Entities/SK/T_SK_CHECK_QUESTION.cs +++ b/APT.MS.Domain/Entities/SK/T_SK_CHECK_QUESTION.cs @@ -68,6 +68,15 @@ namespace APT.MS.Domain.Entities.SK /// [Description("排序号")] [FormFieldEdit] - public int NUM { get; set; } + public int NUM { get; set; } + + + [Description("检查内容")] + [DataFieldIngore] + public string CHECKCONTENT { get; set; } + + [Description("生产单元")] + [DataFieldIngore] + public Guid? PRODUCTION_UNIT_ID { get; set; } } } diff --git a/APT.MicroApi/APT.SK.WebApi/Controllers/Api/CheckContentsController.cs b/APT.MicroApi/APT.SK.WebApi/Controllers/Api/CheckContentsController.cs index 1cb0bc5..fa47517 100644 --- a/APT.MicroApi/APT.SK.WebApi/Controllers/Api/CheckContentsController.cs +++ b/APT.MicroApi/APT.SK.WebApi/Controllers/Api/CheckContentsController.cs @@ -10,12 +10,15 @@ using ICSharpCode.SharpZipLib.Core; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyModel; +using NPOI.SS.Formula.Functions; +using NPOI.Util; using Org.BouncyCastle.Asn1.Ess; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; +using System.Reflection.Metadata; using Ubiety.Dns.Core; namespace APT.SK.WebApi.Controllers.Api @@ -152,7 +155,7 @@ namespace APT.SK.WebApi.Controllers.Api startRowIndexs.Add(0, 1);//根据Excel格式数据赋值 var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); string Msg = string.Empty; - isOK = InsertModel(dataTables.Tables[0], orgId, ref Msg); + isOK = InsertModel2(dataTables.Tables[0], orgId, ref Msg); try { @@ -327,6 +330,124 @@ namespace APT.SK.WebApi.Controllers.Api Msg = "导入成功!"; } return true; + } + + /// + /// 导入 + /// + /// + /// + /// + /// + /// + /// + public bool InsertModel2(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; + if (rowAll == 1) + { + throw new Exception("导入必须两条以上,一条请直接新增"); + } + List contents = new List(); + List qustions = new List(); + var baseFilter = new BaseFilter(orgId); + var productionUnits = this.GetEntities(i => i.IS_DELETED == false, baseFilter); + var oldContents = this.GetEntities(i => i.IS_DELETED == false, baseFilter, "Nav_ListCheckQuestion"); + for (int i = 0; i < rowAll; i++) + { + if (!string.IsNullOrEmpty(dtSource.Rows[i][0].ToString().Trim())) + { + + var unit = productionUnits.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim()); + var first = oldContents.FirstOrDefault(x =>x.PRODUCTION_UNIT_ID == unit?.ID && x.CHECKCONTENT == dtSource.Rows[i][1].ToString().Trim()); + if (first != null)//旧表已存在数据 + { + T_SK_CHECK_QUESTION content = new T_SK_CHECK_QUESTION(); + content.ORG_ID = orgId; + content.CHECKCONTENT = dtSource.Rows[i][1].ToString().Trim(); + content.DESCREPTION = dtSource.Rows[i][2].ToString().Trim(); + content.QUESTION_LEVEL_SHOW = dtSource.Rows[i][3].ToString().Trim(); + content.QUESTION_LEVEL = content.QUESTION_LEVEL_SHOW == "重大" ? SKHiddenLevel.Major : SKHiddenLevel.General; + content.DEMAND = dtSource.Rows[i][4].ToString().Trim(); + content.PRODUCTION_UNIT_ID = unit?.ID; + content.CHECK_CONTENTS_ID = first.ID; + qustions.Add(content); + } + else + { + T_SK_CHECK_QUESTION content = new T_SK_CHECK_QUESTION(); + content.ORG_ID = orgId; + content.CHECKCONTENT = dtSource.Rows[i][1].ToString().Trim(); + content.DESCREPTION = dtSource.Rows[i][2].ToString().Trim(); + content.QUESTION_LEVEL_SHOW = dtSource.Rows[i][3].ToString().Trim(); + content.QUESTION_LEVEL = content.QUESTION_LEVEL_SHOW == "重大" ? SKHiddenLevel.Major : SKHiddenLevel.General; + content.DEMAND = dtSource.Rows[i][4].ToString().Trim(); + content.PRODUCTION_UNIT_ID = unit?.ID; + qustions.Add(content); + } + + + } + } + if (qustions != null && qustions.Any()) + { + var contentList2 = qustions.Where(m => m.CHECK_CONTENTS_ID != null).GroupBy(t => new { t.CHECK_CONTENTS_ID, t.PRODUCTION_UNIT_ID, t.CHECKCONTENT }).Distinct().ToList(); + if (contentList2 != null && contentList2.Any()) + { + foreach (var item in contentList2) + { + var qus = qustions.Where(t => t.CHECK_CONTENTS_ID == item.Key.CHECK_CONTENTS_ID && t.PRODUCTION_UNIT_ID == item.Key.PRODUCTION_UNIT_ID && t.CHECKCONTENT == item.Key.CHECKCONTENT).ToList(); + var j = 1; + foreach (var qu in qus) + { + qu.NUM = j; + j++; + } + } + } + var contentList = qustions.Where(m=>m.CHECK_CONTENTS_ID==null).GroupBy(t => new { t.PRODUCTION_UNIT_ID, t.CHECKCONTENT }).Distinct().ToList(); + if (contentList != null && contentList.Any()) + { + foreach (var item in contentList) + { + T_SK_CHECK_CONTENTS content = new T_SK_CHECK_CONTENTS(); + content.ORG_ID = orgId; + content.PRODUCTION_UNIT_ID = item.Key.PRODUCTION_UNIT_ID; + content.CHECKCONTENT = item.Key.CHECKCONTENT; + contents.Add(content); + var qus = qustions.Where(t => t.PRODUCTION_UNIT_ID == item.Key.PRODUCTION_UNIT_ID && t.CHECKCONTENT == item.Key.CHECKCONTENT).ToList(); + var j = 1; + foreach (var qu in qus) + { + qu.CHECK_CONTENTS_ID = content.ID; + qu.NUM = j; + j++; + } + } + } + } + if (!string.IsNullOrEmpty(Msg)) + { + throw new Exception(Msg); + } + else + { + UnifiedCommit(() => + { + if (contents != null && contents.Any()) + BantchSaveEntityNoCommit(contents); + if (qustions != null && qustions.Any()) + BantchSaveEntityNoCommit(qustions); + }); + Msg = "导入成功!"; + } + return true; } } }