检查内容导入

This commit is contained in:
何美荣 2026-03-26 14:58:02 +08:00
parent 0be8cc170f
commit 8052acd73f

View File

@ -2,11 +2,14 @@
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Services.Services.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.LR;
using APT.MS.Domain.Entities.SC.PT;
using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Enums.SK;
using APT.Utility;
using Castle.Core.Internal;
using Google.Protobuf.WellKnownTypes;
using ICSharpCode.SharpZipLib.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -192,10 +195,10 @@ namespace APT.SK.WebApi.Controllers.Api
//获取数据
Dictionary<int, int> startRowIndexs = new Dictionary<int, int>();
startRowIndexs.Add(0, 1);//根据Excel格式数据赋值
startRowIndexs.Add(0, 2);//根据Excel格式数据赋值
var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
string Msg = string.Empty;
isOK = InsertModel2(dataTables.Tables[0], orgId, ref Msg);
isOK = InsertModel3(dataTables.Tables[0], orgId, ref Msg);
try
{
@ -577,11 +580,11 @@ namespace APT.SK.WebApi.Controllers.Api
/// <exception cref="Exception"></exception>
public bool InsertModel3(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);
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)
@ -590,11 +593,12 @@ namespace APT.SK.WebApi.Controllers.Api
}
List<T_SK_CHECK_CONTENTS> contents = new List<T_SK_CHECK_CONTENTS>();
List<T_SK_CHECK_QUESTION> qustions = new List<T_SK_CHECK_QUESTION>();
List<T_SK_CHECK_CONTENTS_BASIC> basics = new List<T_SK_CHECK_CONTENTS_BASIC>();
List<T_SK_CHECK_QUESTION> qustionTemps = 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);
var oldHiddens = this.GetEntities<T_SK_CHECK_QUESTION>(i => i.IS_DELETED == false, baseFilter);
var oldLaws = this.GetEntities<T_LR_LAW>(i => i.IS_DELETED == false, baseFilter);
for (int i = 0; i < rowAll; i++)
{
@ -603,68 +607,121 @@ namespace APT.SK.WebApi.Controllers.Api
var unit = productionUnits.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim());
if (unit == null)//旧表已存在数据
{
Msg = Msg + "生产单元:" + dtSource.Rows[i][0].ToString().Trim() + "不存在,请先到系统管理添加;";
}
else
{
T_SK_CHECK_QUESTION content = new T_SK_CHECK_QUESTION();
content.ORG_ID = orgId;
content.CHECKCONTENT = dtSource.Rows[i][1].ToString().Replace("\n","").Trim();
content.CHECK_BASICS = dtSource.Rows[i][2].ToString().Replace("\n", "").Trim();
content.CHECK_STANDARD = dtSource.Rows[i][3].ToString().Replace("\n", "").Trim();
content.DESCREPTION = dtSource.Rows[i][4].ToString().Replace("\n", "").Trim();
content.QUESTION_LEVEL = SKHiddenLevel.General;
content.DEMAND = dtSource.Rows[i][6].ToString().Replace("\n", "").Trim();
content.PRODUCTION_UNIT_ID = unit?.ID;
qustionTemps.Add(content);
Msg = Msg +"第" + (i + 3) + "行生产单元:" + dtSource.Rows[i][0].ToString().Trim() + "不存在,请先到系统管理添加;";
}
}
}
else
{
Msg = Msg + "第" + (i + 3) + "行生产单元不能为空;";
}
if (!string.IsNullOrEmpty(dtSource.Rows[i][1].ToString().Trim()))
{
var conFirst = oldContents.FirstOrDefault(t => t.CHECKCONTENT == dtSource.Rows[i][1].ToString().Trim());
if (conFirst != null)
{
Msg = Msg + "第" + (i + 3) + "行检查内容" + dtSource.Rows[i][1].ToString().Trim() + "已存在,请勿重复导入;";
}
}
else
{
Msg = Msg + "第" + (i + 3) + "行检查内容不能为空;";
}
if (!string.IsNullOrEmpty(dtSource.Rows[i][2].ToString().Trim()))
{
var lists = dtSource.Rows[i][2].ToString().Trim().Split("").ToList();
if (lists != null && lists.Any())
{
foreach (var item in lists)
{
if (!string.IsNullOrEmpty(item))
{
var conFirst = oldLaws.FirstOrDefault(t => t.NAME == item);
if (conFirst == null)
{
Msg = Msg + "第" + (i + 3) + "行检查依据" + item + "不存在,请先到知识库法律法规库维护;";
}
}
}
}
}
var hiddenLevel = dtSource.Rows[i][5].ToString().Trim();
if (!string.IsNullOrEmpty(hiddenLevel))
{
if (hiddenLevel != "一般" && hiddenLevel != "重大")
{
Msg = Msg + "第" + (i + 3) + "行隐患等级只能填写一般或重大;";
}
}
}
if (!string.IsNullOrEmpty(Msg))
{
throw new Exception(Msg);
}
for (int i = 0; i < rowAll; i++)
{
var unit = productionUnits.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim());
T_SK_CHECK_QUESTION content = new T_SK_CHECK_QUESTION();
content.ORG_ID = orgId;
content.CHECKCONTENT = dtSource.Rows[i][1].ToString().Replace("\n", "").Trim();
content.CHECK_BASICS = dtSource.Rows[i][2].ToString().Replace("\n", "").Trim();
content.CHECK_STANDARD = dtSource.Rows[i][3].ToString().Replace("\n", "").Trim();
content.DESCREPTION = dtSource.Rows[i][4].ToString().Replace("\n", "").Trim();
content.QUESTION_LEVEL = dtSource.Rows[i][5].ToString().Trim() == "重大" ? SKHiddenLevel.Major : SKHiddenLevel.General;
content.DEMAND = dtSource.Rows[i][6].ToString().Replace("\n", "").Trim();
content.PRODUCTION_UNIT_ID = unit?.ID;
qustionTemps.Add(content);
}
if (qustionTemps != null && qustionTemps.Any())
{
foreach (var item in qustionTemps)
{
var conFirsts = item.CHECKCONTENT.Split("").ToList();
var queFirsts = item.DESCREPTION.Split("。").ToList();
var mesFirsts = item.DEMAND.Split("。").ToList();
if (conFirsts != null && conFirsts.Any())
T_SK_CHECK_CONTENTS content = new T_SK_CHECK_CONTENTS();
content.ORG_ID = orgId;
content.PRODUCTION_UNIT_ID = item.PRODUCTION_UNIT_ID;
content.CHECKCONTENT = item.CHECKCONTENT;
contents.Add(content);
if (!string.IsNullOrEmpty(item.DESCREPTION) && !string.IsNullOrEmpty(item.DEMAND))
{
foreach (var first in conFirsts)
var ques = item.DESCREPTION.Split("。").ToList();
var mess = item.DEMAND.Split("。").ToList();
if (ques != null && ques.Any())
{
if (!string.IsNullOrEmpty(first))
foreach (var que in ques)
{
var num = first.Split("*")[0];
var con = first.Split("*")[1];
T_SK_CHECK_CONTENTS content = new T_SK_CHECK_CONTENTS();
content.ORG_ID = orgId;
content.PRODUCTION_UNIT_ID = item.PRODUCTION_UNIT_ID;
content.CHECKCONTENT = con;
contents.Add(content);
var ques = queFirsts.Where(t => t.StartsWith(num)).ToList();
if (ques != null && ques.Any())
var quNum = que.Split("、")[0];
var mes = mess.FirstOrDefault(t => t.StartsWith(quNum));
T_SK_CHECK_QUESTION qu = new T_SK_CHECK_QUESTION();
qu.CHECK_CONTENTS_ID = content.ID;
qu.ORG_ID = orgId;
qu.DESCREPTION = que.Split('、')[1];
qu.DEMAND = mes.Split("、")[1];
qu.QUESTION_LEVEL = item.QUESTION_LEVEL;
qu.NUM = int.Parse(que.Split('、')[0]);
qustions.Add(qu);
}
}
}
if (!string.IsNullOrEmpty(item.CHECK_BASICS))
{
var lists = item.CHECK_BASICS.Split("").ToList();
if (lists != null && lists.Any())
{
foreach (var bas in lists)
{
if (!string.IsNullOrEmpty(bas))
{
var j = 0;
foreach (var que in ques)
{
var quNum = que.Split("*")[0];
var mes = mesFirsts.FirstOrDefault(t => t.StartsWith(quNum));
T_SK_CHECK_QUESTION qu = new T_SK_CHECK_QUESTION();
qu.CHECK_CONTENTS_ID = content.ID;
qu.ORG_ID = orgId;
qu.DESCREPTION = que.Split('*')[1];
qu.DEMAND = mes.Split("*")[1];
qu.QUESTION_LEVEL = item.QUESTION_LEVEL;
qu.NUM = j;
qustions.Add(qu);
j++;
}
var basFirst = oldLaws.FirstOrDefault(t => t.NAME == bas);
T_SK_CHECK_CONTENTS_BASIC post = new T_SK_CHECK_CONTENTS_BASIC();
post.ORG_ID = orgId;
post.CHECK_CONTENTS_ID = content.ID;
post.LAW_ID = basFirst.ID;
basics.Add(post);
}
}
}
}
}
}
}
if (!string.IsNullOrEmpty(Msg))
{
@ -677,7 +734,9 @@ namespace APT.SK.WebApi.Controllers.Api
if (contents != null && contents.Any())
BantchSaveEntityNoCommit(contents);
if (qustions != null && qustions.Any())
BantchSaveEntityNoCommit(qustions);
BantchSaveEntityNoCommit(qustions);
if (basics != null && basics.Any())
BantchSaveEntityNoCommit(basics);
});
Msg = "导入成功!";
}