作业任务库导入
This commit is contained in:
parent
1dbbb01394
commit
6ed5aeca88
@ -3622,9 +3622,9 @@ builder.HasOne(t => t.Nav_ImgFile).WithMany().HasForeignKey(t => t.IMG_FILE_ID).
|
||||
builder.Property(t => t.NAME).HasMaxLength(50);
|
||||
builder.HasOne(t => t.Nav_OperationStep).WithMany().HasForeignKey(t => t.OPERATION_STEP_ID).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne(t => t.Nav_WorkPermitType).WithMany().HasForeignKey(t => t.WORK_PERMIT_TYPE_ID).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.Property(t => t.SafeConfirmsStr).HasMaxLength(500);
|
||||
builder.Property(t => t.SafeMeasuresStr).HasMaxLength(500);
|
||||
builder.Property(t => t.DealMeasuresStr).HasMaxLength(500);
|
||||
builder.Property(t => t.SafeConfirmsStr).HasMaxLength(2000);
|
||||
builder.Property(t => t.SafeMeasuresStr).HasMaxLength(2000);
|
||||
builder.Property(t => t.DealMeasuresStr).HasMaxLength(2000);
|
||||
builder.Property(t => t.POST).HasMaxLength(500);
|
||||
builder.HasOne(t => t.Nav_Unit).WithMany().HasForeignKey(t => t.UNIT_ID).OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ namespace APT.MS.Domain.Entities.HM
|
||||
/// </summary>
|
||||
[Description("作业前安全确认")]
|
||||
[FormFieldEdit]
|
||||
[DataFieldLength(500)]
|
||||
[DataFieldLength(2000)]
|
||||
public string SafeConfirmsStr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -98,7 +98,7 @@ namespace APT.MS.Domain.Entities.HM
|
||||
/// </summary>
|
||||
[Description("作业流程及安全措施")]
|
||||
[FormFieldEdit]
|
||||
[DataFieldLength(500)]
|
||||
[DataFieldLength(2000)]
|
||||
public string SafeMeasuresStr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -106,7 +106,7 @@ namespace APT.MS.Domain.Entities.HM
|
||||
/// </summary>
|
||||
[Description("作业后处理措施")]
|
||||
[FormFieldEdit]
|
||||
[DataFieldLength(500)]
|
||||
[DataFieldLength(2000)]
|
||||
public string DealMeasuresStr { get; set; }
|
||||
/// <summary>
|
||||
/// 状态 作废 = 1,有效 = 0,
|
||||
|
||||
@ -1,16 +1,21 @@
|
||||
using APT.BaseData.Domain.Entities.FM;
|
||||
using APT.BaseData.Domain.ApiModel;
|
||||
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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using APT.BaseData.Domain.Enums;
|
||||
using APT.MS.Domain.Entities.BS;
|
||||
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
|
||||
@ -158,12 +163,12 @@ namespace APT.HM.WebApi.Controllers.Api
|
||||
//pageFilter.Include.Add("Nav_LinkPost");
|
||||
//pageFilter.Include.Add("Nav_LinkPost.Nav_Post");
|
||||
Expression<Func<T_HM_OPERATION_LINK, bool>> 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 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<T_HM_OPERATION_LINK>(expression, keywordPageFilter, null);
|
||||
if (result.TotalCount > 0)
|
||||
{
|
||||
@ -174,6 +179,30 @@ namespace APT.HM.WebApi.Controllers.Api
|
||||
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)
|
||||
{
|
||||
@ -182,5 +211,175 @@ namespace APT.HM.WebApi.Controllers.Api
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取导入数据
|
||||
/// 参考 [Route("api/PF/Import")]
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("GetImportData")]
|
||||
public JsonActionResult<ImportDataModel> GetImportData()
|
||||
{
|
||||
return SafeExecute<ImportDataModel>(() =>
|
||||
{
|
||||
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<int, int> startRowIndexs = new Dictionary<int, int>();
|
||||
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<string> { Msg };
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/// <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 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_HM_OPERATION_LINK>(t => !t.IS_DELETED, new BaseFilter(orgId));
|
||||
//作业环节
|
||||
var steps = this.GetEntities<T_HM_OPERATION_STEP>(t => !t.IS_DELETED, new BaseFilter(orgId));
|
||||
//作业许可类别
|
||||
var workTypes = this.GetEntities<T_HM_WORK_PERMIT_TYPE>(t => !t.IS_DELETED, new BaseFilter(orgId));
|
||||
//生产单元
|
||||
var proUnits = this.GetEntities<T_FM_USER_PRODUCTION_UNIT_SET>(t => !t.IS_DELETED, new BaseFilter(orgId));
|
||||
//人员岗位
|
||||
var posts = this.GetEntities<T_FM_USER_POST>(t => !t.IS_DELETED, new BaseFilter(orgId));
|
||||
List<T_HM_OPERATION_LINK> linkList = new List<T_HM_OPERATION_LINK>();
|
||||
List<T_HM_OPERATION_LINK_POST> linkPostList = new List<T_HM_OPERATION_LINK_POST>();
|
||||
List<T_HM_OPERATION_TASK_SAFE_CONFIRM> linkConList = new List<T_HM_OPERATION_TASK_SAFE_CONFIRM>();
|
||||
List<T_HM_OPERATION_TASK_SAFE_MEASURE> linkMeasList = new List<T_HM_OPERATION_TASK_SAFE_MEASURE>();
|
||||
List<T_HM_OPERATION_TASK_DEAL_MEASURE> linkDealList = new List<T_HM_OPERATION_TASK_DEAL_MEASURE>();
|
||||
for (int i = 0; i < rowAll; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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 + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
var step = dtSource.Rows[i][1].ToString().Trim();
|
||||
var stepFirst = steps.FirstOrDefault(t => t.NAME == step);
|
||||
if (stepFirst == null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 2) + "行作业环节" + step + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
else
|
||||
{
|
||||
var linkFirst = links.FirstOrDefault(t => t.OPERATION_STEP_ID == stepFirst.ID);
|
||||
if (linkFirst != null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 2) + "行作业环节" + step + "已存在库中,请勿重复导入;";
|
||||
}
|
||||
}
|
||||
var workType = dtSource.Rows[i][6].ToString().Trim();
|
||||
var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType);
|
||||
if (workTypeFirst == null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 2) + "行作业许可类别"+ workType + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dtSource.Rows[i][9].ToString().Trim()))
|
||||
{
|
||||
var lists = dtSource.Rows[i][9].ToString().Trim().Split(",").ToList();
|
||||
if (lists!=null && lists.Any())
|
||||
{
|
||||
foreach (var item in lists)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
var postFirst = posts.FirstOrDefault(t => t.NAME == item);
|
||||
if (postFirst == null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 2) + "行岗位"+ item + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Msg))
|
||||
{
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
if (linkList != null && linkList.Any())
|
||||
BantchAddEntityNoCommit(linkList);
|
||||
if (linkPostList != null && linkPostList.Any())
|
||||
BantchAddEntityNoCommit(linkPostList);
|
||||
if (linkConList != null && linkConList.Any())
|
||||
BantchAddEntityNoCommit(linkConList);
|
||||
if (linkMeasList != null && linkMeasList.Any())
|
||||
BantchAddEntityNoCommit(linkMeasList);
|
||||
if (linkDealList != null && linkDealList.Any())
|
||||
BantchAddEntityNoCommit(linkDealList);
|
||||
});
|
||||
Msg = "导入成功!";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user