检查内容导入
This commit is contained in:
		
							parent
							
								
									6e8f505d24
								
							
						
					
					
						commit
						46a1ca12d8
					
				@ -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.DESCREPTION).HasMaxLength(500);
 | 
				
			||||||
builder.Property(t => t.DEMAND).HasMaxLength(500);
 | 
					builder.Property(t => t.DEMAND).HasMaxLength(500);
 | 
				
			||||||
builder.Ignore(t => t.QUESTION_LEVEL_SHOW);
 | 
					builder.Ignore(t => t.QUESTION_LEVEL_SHOW);
 | 
				
			||||||
 | 
					builder.Ignore(t => t.CHECKCONTENT);
 | 
				
			||||||
 | 
					builder.Ignore(t => t.PRODUCTION_UNIT_ID);
 | 
				
			||||||
		} 
 | 
							} 
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
	 #endregion
 | 
						 #endregion
 | 
				
			||||||
 | 
				
			|||||||
@ -69,5 +69,14 @@ namespace APT.MS.Domain.Entities.SK
 | 
				
			|||||||
        [Description("排序号")]
 | 
					        [Description("排序号")]
 | 
				
			||||||
        [FormFieldEdit]
 | 
					        [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; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,12 +10,15 @@ using ICSharpCode.SharpZipLib.Core;
 | 
				
			|||||||
using Microsoft.AspNetCore.Http;
 | 
					using Microsoft.AspNetCore.Http;
 | 
				
			||||||
using Microsoft.AspNetCore.Mvc;
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
using Microsoft.Extensions.DependencyModel;
 | 
					using Microsoft.Extensions.DependencyModel;
 | 
				
			||||||
 | 
					using NPOI.SS.Formula.Functions;
 | 
				
			||||||
 | 
					using NPOI.Util;
 | 
				
			||||||
using Org.BouncyCastle.Asn1.Ess;
 | 
					using Org.BouncyCastle.Asn1.Ess;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Data;
 | 
					using System.Data;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Reflection.Metadata;
 | 
				
			||||||
using Ubiety.Dns.Core;
 | 
					using Ubiety.Dns.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace APT.SK.WebApi.Controllers.Api
 | 
					namespace APT.SK.WebApi.Controllers.Api
 | 
				
			||||||
@ -152,7 +155,7 @@ namespace APT.SK.WebApi.Controllers.Api
 | 
				
			|||||||
                    startRowIndexs.Add(0, 1);//根据Excel格式数据赋值
 | 
					                    startRowIndexs.Add(0, 1);//根据Excel格式数据赋值
 | 
				
			||||||
                    var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
 | 
					                    var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
 | 
				
			||||||
                    string Msg = string.Empty;
 | 
					                    string Msg = string.Empty;
 | 
				
			||||||
                    isOK = InsertModel(dataTables.Tables[0], orgId, ref Msg);
 | 
					                    isOK = InsertModel2(dataTables.Tables[0], orgId, ref Msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    try
 | 
					                    try
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -328,5 +331,123 @@ namespace APT.SK.WebApi.Controllers.Api
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 导入
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="dtSource"></param>
 | 
				
			||||||
 | 
					        /// <param name="orgId"></param>
 | 
				
			||||||
 | 
					        /// <param name="Msg"></param>
 | 
				
			||||||
 | 
					        /// <param name="rowIndex"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        /// <exception cref="Exception"></exception>
 | 
				
			||||||
 | 
					        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<T_SK_CHECK_CONTENTS> contents = new List<T_SK_CHECK_CONTENTS>();
 | 
				
			||||||
 | 
					            List<T_SK_CHECK_QUESTION> qustions = new List<T_SK_CHECK_QUESTION>();
 | 
				
			||||||
 | 
					            var baseFilter = new BaseFilter(orgId);
 | 
				
			||||||
 | 
					            var productionUnits = this.GetEntities<T_FM_USER_PRODUCTION_UNIT_SET>(i => i.IS_DELETED == false, baseFilter);
 | 
				
			||||||
 | 
					            var oldContents = this.GetEntities<T_SK_CHECK_CONTENTS>(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;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user