Compare commits

..

No commits in common. "fac79612d9d16c95201b40c84e28a8fdb920411d" and "1747f162cadcf445c21cc51ed3d37cb7979332f6" have entirely different histories.

View File

@ -2,14 +2,11 @@
using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Services.Services.FM; using APT.BaseData.Services.Services.FM;
using APT.Infrastructure.Core; using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.LR; using APT.MS.Domain.Entities.LR;
using APT.MS.Domain.Entities.SC.PT; using APT.MS.Domain.Entities.SC.PT;
using APT.MS.Domain.Entities.SK; using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Enums.SK; using APT.MS.Domain.Enums.SK;
using APT.Utility; using APT.Utility;
using Castle.Core.Internal;
using Google.Protobuf.WellKnownTypes;
using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Core;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -195,10 +192,10 @@ namespace APT.SK.WebApi.Controllers.Api
//获取数据 //获取数据
Dictionary<int, int> startRowIndexs = new Dictionary<int, int>(); Dictionary<int, int> startRowIndexs = new Dictionary<int, int>();
startRowIndexs.Add(0, 2);//根据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 = InsertModel3(dataTables.Tables[0], orgId, ref Msg); isOK = InsertModel2(dataTables.Tables[0], orgId, ref Msg);
try try
{ {
@ -580,11 +577,11 @@ namespace APT.SK.WebApi.Controllers.Api
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
public bool InsertModel3(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1) public bool InsertModel3(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1)
{ {
var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
if (dtSource == null || dtSource.Rows.Count < rowIndex) if (dtSource == null || dtSource.Rows.Count < rowIndex)
{ {
Msg = "未获取到导入数据"; Msg = "未获取到导入数据";
throw new Exception(Msg); throw new Exception(Msg);
} }
int rowAll = dtSource.Rows.Count; int rowAll = dtSource.Rows.Count;
if (rowAll == 1) if (rowAll == 1)
@ -593,12 +590,11 @@ namespace APT.SK.WebApi.Controllers.Api
} }
List<T_SK_CHECK_CONTENTS> contents = new List<T_SK_CHECK_CONTENTS>(); 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_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>(); List<T_SK_CHECK_QUESTION> qustionTemps = new List<T_SK_CHECK_QUESTION>();
var baseFilter = new BaseFilter(orgId); var baseFilter = new BaseFilter(orgId);
var productionUnits = this.GetEntities<T_FM_USER_PRODUCTION_UNIT_SET>(i => i.IS_DELETED == false, baseFilter); 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 oldContents = this.GetEntities<T_SK_CHECK_CONTENTS>(i => i.IS_DELETED == false, baseFilter);
var oldLaws = this.GetEntities<T_LR_LAW>(i => i.IS_DELETED == false, baseFilter); var oldHiddens = this.GetEntities<T_SK_CHECK_QUESTION>(i => i.IS_DELETED == false, baseFilter);
for (int i = 0; i < rowAll; i++) for (int i = 0; i < rowAll; i++)
{ {
@ -607,121 +603,68 @@ namespace APT.SK.WebApi.Controllers.Api
var unit = productionUnits.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim()); var unit = productionUnits.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim());
if (unit == null)//旧表已存在数据 if (unit == null)//旧表已存在数据
{ {
Msg = Msg +"第" + (i + 3) + "行生产单元:" + dtSource.Rows[i][0].ToString().Trim() + "不存在,请先到系统管理添加;"; 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);
} }
} }
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()) if (qustionTemps != null && qustionTemps.Any())
{ {
foreach (var item in qustionTemps) foreach (var item in qustionTemps)
{ {
T_SK_CHECK_CONTENTS content = new T_SK_CHECK_CONTENTS(); var conFirsts = item.CHECKCONTENT.Split("").ToList();
content.ORG_ID = orgId; var queFirsts = item.DESCREPTION.Split("。").ToList();
content.PRODUCTION_UNIT_ID = item.PRODUCTION_UNIT_ID; var mesFirsts = item.DEMAND.Split("。").ToList();
content.CHECKCONTENT = item.CHECKCONTENT; if (conFirsts != null && conFirsts.Any())
contents.Add(content);
if (!string.IsNullOrEmpty(item.DESCREPTION) && !string.IsNullOrEmpty(item.DEMAND))
{ {
var ques = item.DESCREPTION.Split("。").ToList(); foreach (var first in conFirsts)
var mess = item.DEMAND.Split("。").ToList();
if (ques != null && ques.Any())
{ {
foreach (var que in ques) if (!string.IsNullOrEmpty(first))
{ {
var quNum = que.Split("、")[0]; var num = first.Split("*")[0];
var mes = mess.FirstOrDefault(t => t.StartsWith(quNum)); var con = first.Split("*")[1];
T_SK_CHECK_QUESTION qu = new T_SK_CHECK_QUESTION(); T_SK_CHECK_CONTENTS content = new T_SK_CHECK_CONTENTS();
qu.CHECK_CONTENTS_ID = content.ID; content.ORG_ID = orgId;
qu.ORG_ID = orgId; content.PRODUCTION_UNIT_ID = item.PRODUCTION_UNIT_ID;
qu.DESCREPTION = que.Split('、')[1]; content.CHECKCONTENT = con;
qu.DEMAND = mes.Split("、")[1]; contents.Add(content);
qu.QUESTION_LEVEL = item.QUESTION_LEVEL; var ques = queFirsts.Where(t => t.StartsWith(num)).ToList();
qu.NUM = int.Parse(que.Split('、')[0]); if (ques != null && ques.Any())
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 basFirst = oldLaws.FirstOrDefault(t => t.NAME == bas); var j = 0;
T_SK_CHECK_CONTENTS_BASIC post = new T_SK_CHECK_CONTENTS_BASIC(); foreach (var que in ques)
post.ORG_ID = orgId; {
post.CHECK_CONTENTS_ID = content.ID; var quNum = que.Split("*")[0];
post.LAW_ID = basFirst.ID; var mes = mesFirsts.FirstOrDefault(t => t.StartsWith(quNum));
basics.Add(post); 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++;
}
} }
} }
} }
} }
} }
} }
if (!string.IsNullOrEmpty(Msg)) if (!string.IsNullOrEmpty(Msg))
{ {
@ -734,9 +677,7 @@ namespace APT.SK.WebApi.Controllers.Api
if (contents != null && contents.Any()) if (contents != null && contents.Any())
BantchSaveEntityNoCommit(contents); BantchSaveEntityNoCommit(contents);
if (qustions != null && qustions.Any()) if (qustions != null && qustions.Any())
BantchSaveEntityNoCommit(qustions); BantchSaveEntityNoCommit(qustions);
if (basics != null && basics.Any())
BantchSaveEntityNoCommit(basics);
}); });
Msg = "导入成功!"; Msg = "导入成功!";
} }