Merge branch 'master' of http://121.41.2.71:3000/wyw/mh_jy_safe
This commit is contained in:
commit
5cdff2aaf1
@ -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,
|
||||
@ -153,7 +153,7 @@ namespace APT.MS.Domain.Entities.HM
|
||||
public Guid? PARENT_ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改状态 数据库 = 0,修改=1,新增=2
|
||||
/// 修改状态 数据库 = 0,修改=1,新增=2,导入=3
|
||||
/// </summary>
|
||||
[Description("修改状态")]
|
||||
[EnumName("HMModifyEnum")]
|
||||
|
||||
@ -107,6 +107,10 @@ namespace APT.MS.Domain.Enums
|
||||
/// 新增
|
||||
/// </summary>
|
||||
新增 = 2,
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
导入 = 3,
|
||||
}
|
||||
/// <summary>
|
||||
/// 周期
|
||||
|
||||
@ -1,186 +1,668 @@
|
||||
using APT.BaseData.Domain.Entities.FM;
|
||||
using APT.BaseData.Domain.ApiModel;
|
||||
using APT.BaseData.Domain.Entities;
|
||||
using APT.BaseData.Services.Services.FM;
|
||||
using APT.Infrastructure.Core;
|
||||
using APT.MS.Domain.Entities.HM;
|
||||
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.Entities.FM;
|
||||
using APT.BaseData.Domain.Enums;
|
||||
using APT.MS.Domain.Entities.BS;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace APT.HM.WebApi.Controllers.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// 作业任务库
|
||||
/// </summary>
|
||||
[Route("api/HM/HMOperationLink")]
|
||||
public partial class OperationLinkController : AuthorizeApiController<T_HM_OPERATION_LINK>
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新或新增数据
|
||||
/// </summary>
|
||||
/// <param name="entity">对象实体</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("FullUpdate")]
|
||||
public JsonActionResult<bool> FullUpdate([FromBody] T_HM_OPERATION_LINK entity)
|
||||
{
|
||||
return SafeExecute(() =>
|
||||
{
|
||||
var history = this.GetEntity<T_HM_OPERATION_LINK>(t => t.OPERATION_STEP_ID == entity.OPERATION_STEP_ID && t.ID != entity.ID, "Nav_OperationStep");
|
||||
if (history != null)
|
||||
throw new Exception("已存在名为"+ history.Nav_OperationStep.NAME+"的数据,请修改作业名称");
|
||||
var details = entity.Nav_LinkPost;
|
||||
entity.Nav_OperationLinkEvaluateRisk = null;
|
||||
entity.Nav_LinkPost = null;
|
||||
var areas = entity.Nav_LinkArea;
|
||||
entity.Nav_LinkArea = null;
|
||||
if (areas != null && areas.Any())
|
||||
{
|
||||
areas.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
t.Nav_Area = null;
|
||||
});
|
||||
}
|
||||
if (details != null && details.Any())
|
||||
{
|
||||
details.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
t.Nav_Post = null;
|
||||
});
|
||||
var postName = details.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList();
|
||||
entity.POST = string.Join(",", postName);
|
||||
}
|
||||
var safeConfirms = entity.Nav_SafeConfirms;
|
||||
entity.Nav_SafeConfirms = null;
|
||||
if (safeConfirms != null && safeConfirms.Any())
|
||||
{
|
||||
safeConfirms.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
var safeMesasures = entity.Nav_SafeMeasures;
|
||||
entity.Nav_SafeMeasures = null;
|
||||
if (safeMesasures != null && safeMesasures.Any())
|
||||
{
|
||||
safeMesasures.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
var safeDeal = entity.Nav_DealMeasures;
|
||||
entity.Nav_DealMeasures = null;
|
||||
if (safeDeal != null && safeDeal.Any())
|
||||
{
|
||||
safeDeal.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
if (entity != null)
|
||||
this.UpdateEntityNoCommit(entity);
|
||||
if (details != null && details.Any())
|
||||
this.BantchSaveEntityNoCommit(details);
|
||||
if (areas != null && areas.Any())
|
||||
this.BantchSaveEntityNoCommit(areas);
|
||||
if (safeConfirms != null && safeConfirms.Any())
|
||||
this.BantchSaveEntityNoCommit(safeConfirms);
|
||||
if (safeMesasures != null && safeMesasures.Any())
|
||||
this.BantchSaveEntityNoCommit(safeMesasures);
|
||||
if (safeDeal != null && safeDeal.Any())
|
||||
this.BantchSaveEntityNoCommit(safeDeal);
|
||||
});
|
||||
return true;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("GetEdit")]
|
||||
public JsonActionResult<T_HM_OPERATION_LINK> GetEdit([FromBody] KeywordFilter filter)
|
||||
{
|
||||
return SafeExecute(() => {
|
||||
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
this.ThrowError("030017");
|
||||
var result = this.GetEntity<T_HM_OPERATION_LINK>(id, new string[] { "Nav_OperationStep", "Nav_WorkPermitType","Nav_LinkPost","Nav_LinkPost.Nav_Post",
|
||||
"Nav_SafeConfirms", "Nav_SafeMeasures", "Nav_DealMeasures", "Nav_Files","Nav_Unit" });
|
||||
if (result.Nav_LinkPost != null && result.Nav_LinkPost.Any())
|
||||
{
|
||||
var postName = result.Nav_LinkPost.Where(t=>t.Nav_Post!=null).Select(m => m.Nav_Post.NAME).Distinct().ToList();
|
||||
result.POST = string.Join(",", postName);
|
||||
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.MS.Domain.Enums.SK;
|
||||
using APT.Utility;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 作业任务库
|
||||
/// </summary>
|
||||
[Route("api/HM/HMOperationLink")]
|
||||
public partial class OperationLinkController : AuthorizeApiController<T_HM_OPERATION_LINK>
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新或新增数据
|
||||
/// </summary>
|
||||
/// <param name="entity">对象实体</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("FullUpdate")]
|
||||
public JsonActionResult<bool> FullUpdate([FromBody] T_HM_OPERATION_LINK entity)
|
||||
{
|
||||
return SafeExecute(() =>
|
||||
{
|
||||
var history = this.GetEntity<T_HM_OPERATION_LINK>(t => t.OPERATION_STEP_ID == entity.OPERATION_STEP_ID && t.ID != entity.ID, "Nav_OperationStep");
|
||||
if (history != null)
|
||||
throw new Exception("已存在名为"+ history.Nav_OperationStep.NAME+"的数据,请修改作业名称");
|
||||
var details = entity.Nav_LinkPost;
|
||||
entity.Nav_OperationLinkEvaluateRisk = null;
|
||||
entity.Nav_LinkPost = null;
|
||||
var areas = entity.Nav_LinkArea;
|
||||
entity.Nav_LinkArea = null;
|
||||
if (areas != null && areas.Any())
|
||||
{
|
||||
areas.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
t.Nav_Area = null;
|
||||
});
|
||||
}
|
||||
if (details != null && details.Any())
|
||||
{
|
||||
details.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
t.Nav_Post = null;
|
||||
});
|
||||
var postName = details.Where(x => x.Nav_Post != null).Select(m => m.Nav_Post.NAME).Distinct().ToList();
|
||||
entity.POST = string.Join(",", postName);
|
||||
}
|
||||
var safeConfirms = entity.Nav_SafeConfirms;
|
||||
entity.Nav_SafeConfirms = null;
|
||||
if (safeConfirms != null && safeConfirms.Any())
|
||||
{
|
||||
safeConfirms.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
var safeMesasures = entity.Nav_SafeMeasures;
|
||||
entity.Nav_SafeMeasures = null;
|
||||
if (safeMesasures != null && safeMesasures.Any())
|
||||
{
|
||||
safeMesasures.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
var safeDeal = entity.Nav_DealMeasures;
|
||||
entity.Nav_DealMeasures = null;
|
||||
if (safeDeal != null && safeDeal.Any())
|
||||
{
|
||||
safeDeal.ForEach(t =>
|
||||
{
|
||||
t.ORG_ID = entity.ORG_ID;
|
||||
t.OPERATION_LINK_ID = entity.ID;
|
||||
});
|
||||
}
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
if (entity != null)
|
||||
this.UpdateEntityNoCommit(entity);
|
||||
if (details != null && details.Any())
|
||||
this.BantchSaveEntityNoCommit(details);
|
||||
if (areas != null && areas.Any())
|
||||
this.BantchSaveEntityNoCommit(areas);
|
||||
if (safeConfirms != null && safeConfirms.Any())
|
||||
this.BantchSaveEntityNoCommit(safeConfirms);
|
||||
if (safeMesasures != null && safeMesasures.Any())
|
||||
this.BantchSaveEntityNoCommit(safeMesasures);
|
||||
if (safeDeal != null && safeDeal.Any())
|
||||
this.BantchSaveEntityNoCommit(safeDeal);
|
||||
});
|
||||
return true;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("GetEdit")]
|
||||
public JsonActionResult<T_HM_OPERATION_LINK> GetEdit([FromBody] KeywordFilter filter)
|
||||
{
|
||||
return SafeExecute(() => {
|
||||
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
this.ThrowError("030017");
|
||||
var result = this.GetEntity<T_HM_OPERATION_LINK>(id, new string[] { "Nav_OperationStep", "Nav_WorkPermitType","Nav_LinkPost","Nav_LinkPost.Nav_Post",
|
||||
"Nav_SafeConfirms", "Nav_SafeMeasures", "Nav_DealMeasures", "Nav_Files","Nav_Unit" });
|
||||
if (result.Nav_LinkPost != null && result.Nav_LinkPost.Any())
|
||||
{
|
||||
var postName = result.Nav_LinkPost.Where(t=>t.Nav_Post!=null).Select(m => m.Nav_Post.NAME).Distinct().ToList();
|
||||
result.POST = string.Join(",", postName);
|
||||
}
|
||||
if (result.Nav_SafeConfirms != null && result.Nav_SafeConfirms.Any())
|
||||
{
|
||||
result.Nav_SafeConfirms.OrderBy(t => t.NUM);
|
||||
}
|
||||
result.Nav_SafeConfirms = result.Nav_SafeConfirms.OrderBy(t => t.NUM).ToList();
|
||||
}
|
||||
if (result.Nav_SafeMeasures != null && result.Nav_SafeMeasures.Any())
|
||||
{
|
||||
result.Nav_SafeMeasures.OrderBy(t => t.NUM);
|
||||
}
|
||||
result.Nav_SafeMeasures = result.Nav_SafeMeasures.OrderBy(t => t.NUM).ToList();
|
||||
}
|
||||
if (result.Nav_DealMeasures != null && result.Nav_DealMeasures.Any())
|
||||
{
|
||||
result.Nav_DealMeasures.OrderBy(t => t.NUM);
|
||||
}
|
||||
return result;
|
||||
result.Nav_DealMeasures = result.Nav_DealMeasures.OrderBy(t => t.NUM).ToList();
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 排序分页查询数据
|
||||
/// </summary>
|
||||
/// <param name="pageFilter">分页过滤实体</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("FullOrderPaged")]
|
||||
public PagedActionResult<T_HM_OPERATION_LINK> FullOrderPaged([FromBody] KeywordPageFilter pageFilter)
|
||||
{
|
||||
KeywordPageFilter keywordPageFilter = new KeywordPageFilter();
|
||||
keywordPageFilter = pageFilter;
|
||||
var rule = keywordPageFilter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "POST");
|
||||
if (rule != null)
|
||||
keywordPageFilter.FilterGroup.Rules.Remove(rule);
|
||||
keywordPageFilter.IgnoreDataRule = true;
|
||||
keywordPageFilter.Include.Add("Nav_LinkPost");
|
||||
keywordPageFilter.Include.Add("Nav_LinkPost.Nav_Post");
|
||||
keywordPageFilter.Include.Add("Nav_SafeConfirms");
|
||||
keywordPageFilter.Include.Add("Nav_SafeMeasures");
|
||||
keywordPageFilter.Include.Add("Nav_DealMeasures");
|
||||
keywordPageFilter.SelectField.Add("Nav_LinkPost.Nav_Post.NAME");
|
||||
keywordPageFilter.SelectField.Add("Nav_SafeConfirms.NUM");
|
||||
keywordPageFilter.SelectField.Add("Nav_SafeConfirms.NAME");
|
||||
keywordPageFilter.SelectField.Add("Nav_SafeMeasures.NUM");
|
||||
keywordPageFilter.SelectField.Add("Nav_SafeMeasures.NAME");
|
||||
keywordPageFilter.SelectField.Add("Nav_DealMeasures.NUM");
|
||||
keywordPageFilter.SelectField.Add("Nav_DealMeasures.NAME");
|
||||
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 result = this.GetOrderPageEntities<T_HM_OPERATION_LINK>(expression, keywordPageFilter);
|
||||
if (result.TotalCount > 0)
|
||||
{
|
||||
result.Data.ForEach(t =>
|
||||
{
|
||||
if (t.Nav_LinkPost != null && t.Nav_LinkPost.Any())
|
||||
{
|
||||
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.OrderBy(m=>m.NUM))
|
||||
{
|
||||
if (safe!=null)
|
||||
{
|
||||
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.OrderBy(m => m.NUM))
|
||||
{
|
||||
if (safe != null)
|
||||
{
|
||||
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.OrderBy(m => m.NUM))
|
||||
{
|
||||
if (safe != null)
|
||||
{
|
||||
var safeTemp = safe.NUM + "、" + safe.NAME + ";";
|
||||
t.DealMeasuresStr = t.DealMeasuresStr + safeTemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (rule != null)
|
||||
{
|
||||
result.Data = result.Data.Where(t =>t.POST!=null && t.POST.Contains(rule.Value.ToString()));
|
||||
}
|
||||
}
|
||||
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));
|
||||
|
||||
//先做一次非空判断
|
||||
if (!string.IsNullOrEmpty(Msg))
|
||||
{
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
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 + 3) + "行生产单元,作业环节,任务类型,是否关键作业,作业周期,作业许可审批层级,作业许可类别,作业等级存在空数据,请先检查所有字段内容;";
|
||||
}
|
||||
}
|
||||
//基础数据判断
|
||||
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 + 3) + "行生产单元"+ proUnit + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
var step = dtSource.Rows[i][1].ToString().Trim();
|
||||
var stepFirst = steps.FirstOrDefault(t => t.NAME == step);
|
||||
if (stepFirst == null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业环节" + step + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
else
|
||||
{
|
||||
var linkFirst = links.FirstOrDefault(t => t.OPERATION_STEP_ID == stepFirst.ID);
|
||||
if (linkFirst != null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业环节" + step + "已存在库中,请勿重复导入;";
|
||||
}
|
||||
}
|
||||
var taskType = dtSource.Rows[i][2].ToString().Trim();
|
||||
if (taskType != "一般任务" && taskType != "关键任务非许可作业" && taskType != "许可作业")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行任务类型只能填写一般任务、关键任务非许可作业、许可作业,请修改" + taskType + ";";
|
||||
}
|
||||
var isNeed = dtSource.Rows[i][3].ToString().Trim();
|
||||
if (isNeed != "是" && isNeed != "否")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行是否关键任务只能填写是、否,请修改" + isNeed + ";";
|
||||
}
|
||||
var workCycle = dtSource.Rows[i][4].ToString().Trim();
|
||||
if (workCycle != "每日作业" && workCycle != "需求作业")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业周期只能填写每日作业、需求作业,请修改" + workCycle + ";";
|
||||
}
|
||||
var approveLevel = dtSource.Rows[i][5].ToString().Trim();
|
||||
if (approveLevel != "无审批层级" && approveLevel != "一级审批" && approveLevel != "二级审批" && approveLevel != "三级审批"
|
||||
&& approveLevel != "四级审批" && approveLevel != "特级审批" && approveLevel != "临时用电")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业审批层级只能填写无审批层级、一级审批、二级审批、三级审批、四级审批、特级审批、临时用电,请修改" + approveLevel + ";";
|
||||
}
|
||||
var workType = dtSource.Rows[i][6].ToString().Trim();
|
||||
var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType);
|
||||
if (workTypeFirst == null)
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业许可类别"+ workType + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
var workLevel = dtSource.Rows[i][7].ToString().Trim();
|
||||
if (workLevel != "重大风险" && workLevel != "较大风险" && workLevel != "一般风险" && workLevel != "低风险")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行作业等级只能填写重大风险、较大风险、一般风险、低风险,请修改" + workLevel + ";";
|
||||
}
|
||||
var status = dtSource.Rows[i][8].ToString().Trim();
|
||||
if (status != "启用" && status != "停用")
|
||||
{
|
||||
Msg = Msg + "第" + (i + 3) + "行状态只能填写启用、停用,请修改" + status + ";";
|
||||
}
|
||||
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 + 3) + "行岗位"+ item + "不存在,请先到系统管理维护;";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Msg))
|
||||
{
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
//导入
|
||||
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++)
|
||||
{
|
||||
var proUnit = dtSource.Rows[i][0].ToString().Trim();
|
||||
var proUnitFirst = proUnits.FirstOrDefault(t => t.NAME == proUnit);
|
||||
var step = dtSource.Rows[i][1].ToString().Trim();
|
||||
var stepFirst = steps.FirstOrDefault(t => t.NAME == step);
|
||||
var taskType = dtSource.Rows[i][2].ToString().Trim();
|
||||
var isNeed = dtSource.Rows[i][3].ToString().Trim();
|
||||
var workCycle = dtSource.Rows[i][4].ToString().Trim();
|
||||
var approveLevel = dtSource.Rows[i][5].ToString().Trim();
|
||||
var workType = dtSource.Rows[i][6].ToString().Trim();
|
||||
var workTypeFirst = workTypes.FirstOrDefault(t => t.NAME == workType);
|
||||
var workLevel = dtSource.Rows[i][7].ToString().Trim();
|
||||
var status = dtSource.Rows[i][8].ToString().Trim();
|
||||
var postList = dtSource.Rows[i][9].ToString().Trim();
|
||||
var conList = dtSource.Rows[i][10].ToString().Trim();
|
||||
var mesList = dtSource.Rows[i][11].ToString().Trim();
|
||||
var delList = dtSource.Rows[i][12].ToString().Trim();
|
||||
T_HM_OPERATION_LINK link = new T_HM_OPERATION_LINK();
|
||||
link.ORG_ID = orgId;
|
||||
link.UNIT_ID = proUnitFirst.ID;
|
||||
link.OPERATION_STEP_ID = stepFirst.ID;
|
||||
link.WORK_PERMIT_TYPE_ID = workTypeFirst.ID;
|
||||
link.CODE = DateTime.Now.ToString("yyyyMMddHH") + i.ToString().PadLeft(4, '0');
|
||||
link.NAME = stepFirst.NAME;
|
||||
link.MODIFY_TYPE = HMModifyEnum.导入;
|
||||
link.IS_RUN = DisableStatusEnum.否;
|
||||
switch (taskType)
|
||||
{
|
||||
case "一般任务":
|
||||
link.TASK_LEVEL = (int)HMTaskLevelEnum.一般任务;
|
||||
break;
|
||||
case "关键任务非许可作业":
|
||||
link.TASK_LEVEL = (int)HMTaskLevelEnum.关键任务非许可作业;
|
||||
break;
|
||||
case "许可作业":
|
||||
link.TASK_LEVEL = (int)HMTaskLevelEnum.许可作业;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
switch (isNeed)
|
||||
{
|
||||
case "是":
|
||||
link.IS_IMPORTANT = (int)ISImportantEnum.是;
|
||||
break;
|
||||
case "否":
|
||||
link.IS_IMPORTANT = (int)ISImportantEnum.否;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
switch (workCycle)
|
||||
{
|
||||
case "每日作业":
|
||||
link.CYCLE_TYPE = HMCycleTypeEnum.Day;
|
||||
break;
|
||||
case "需求作业":
|
||||
link.CYCLE_TYPE = HMCycleTypeEnum.Need;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
switch (approveLevel)
|
||||
{
|
||||
case "无审批层级":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.无审批层级;
|
||||
break;
|
||||
case "一级审批":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.一级审批;
|
||||
break;
|
||||
case "二级审批":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.二级审批;
|
||||
break;
|
||||
case "三级审批":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.三级审批;
|
||||
break;
|
||||
case "四级审批":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.四级审批;
|
||||
break;
|
||||
case "特级审批":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.特级审批;
|
||||
break;
|
||||
case "临时用电":
|
||||
link.AUDIT_LEVEL = (int)HMOperationTaskAuditEnum.临时用电;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
switch (workLevel)
|
||||
{
|
||||
case "重大风险":
|
||||
link.EVALUATE_LEVEL = SKEvaluateLevelEnum.重大风险;
|
||||
break;
|
||||
case "较大风险":
|
||||
link.EVALUATE_LEVEL = SKEvaluateLevelEnum.较大风险;
|
||||
break;
|
||||
case "一般风险":
|
||||
link.EVALUATE_LEVEL = SKEvaluateLevelEnum.一般风险;
|
||||
break;
|
||||
case "低风险":
|
||||
link.EVALUATE_LEVEL = SKEvaluateLevelEnum.低风险;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
switch (status)
|
||||
{
|
||||
case "启用":
|
||||
link.STATUS = (int)STATUSEnum.启用;
|
||||
break;
|
||||
case "停用":
|
||||
link.STATUS = (int)STATUSEnum.停用;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
linkList.Add(link);
|
||||
if (!string.IsNullOrEmpty(postList))
|
||||
{
|
||||
var lists = postList.Split(",").ToList();
|
||||
if (lists != null && lists.Any())
|
||||
{
|
||||
foreach (var item in lists)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
var postFirst = posts.FirstOrDefault(t => t.NAME == item);
|
||||
T_HM_OPERATION_LINK_POST post = new T_HM_OPERATION_LINK_POST();
|
||||
post.ORG_ID = orgId;
|
||||
post.OPERATION_LINK_ID = link.ID;
|
||||
post.POST_ID = postFirst.ID;
|
||||
linkPostList.Add(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(conList))
|
||||
{
|
||||
var lists = conList.Split(";").ToList();
|
||||
if (lists != null && lists.Any())
|
||||
{
|
||||
foreach (var item in lists)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
if (item.Contains("、"))
|
||||
{
|
||||
var num = item.Split("、")[0];
|
||||
var name = item.Split("、")[1];
|
||||
T_HM_OPERATION_TASK_SAFE_CONFIRM con = new T_HM_OPERATION_TASK_SAFE_CONFIRM();
|
||||
con.ORG_ID = orgId;
|
||||
con.OPERATION_LINK_ID = link.ID;
|
||||
con.NUM = string.IsNullOrEmpty(num)?null:int.Parse(num);
|
||||
con.NAME = name;
|
||||
linkConList.Add(con);
|
||||
}
|
||||
else
|
||||
{
|
||||
T_HM_OPERATION_TASK_SAFE_CONFIRM con = new T_HM_OPERATION_TASK_SAFE_CONFIRM();
|
||||
con.ORG_ID = orgId;
|
||||
con.OPERATION_LINK_ID = link.ID;
|
||||
con.NAME = item;
|
||||
linkConList.Add(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(mesList))
|
||||
{
|
||||
var lists = mesList.Split(";").ToList();
|
||||
if (lists != null && lists.Any())
|
||||
{
|
||||
foreach (var item in lists)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
if (item.Contains("、"))
|
||||
{
|
||||
var num = item.Split("、")[0];
|
||||
var name = item.Split("、")[1];
|
||||
T_HM_OPERATION_TASK_SAFE_MEASURE mes = new T_HM_OPERATION_TASK_SAFE_MEASURE();
|
||||
mes.ORG_ID = orgId;
|
||||
mes.OPERATION_LINK_ID = link.ID;
|
||||
mes.NUM = string.IsNullOrEmpty(num) ? null : int.Parse(num);
|
||||
mes.NAME = name;
|
||||
linkMeasList.Add(mes);
|
||||
}
|
||||
else
|
||||
{
|
||||
T_HM_OPERATION_TASK_SAFE_MEASURE mes = new T_HM_OPERATION_TASK_SAFE_MEASURE();
|
||||
mes.ORG_ID = orgId;
|
||||
mes.OPERATION_LINK_ID = link.ID;
|
||||
mes.NAME = item;
|
||||
linkMeasList.Add(mes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(delList))
|
||||
{
|
||||
var lists = delList.Split(";").ToList();
|
||||
if (lists != null && lists.Any())
|
||||
{
|
||||
foreach (var item in lists)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
if (item.Contains("、"))
|
||||
{
|
||||
var num = item.Split("、")[0];
|
||||
var name = item.Split("、")[1];
|
||||
T_HM_OPERATION_TASK_DEAL_MEASURE del = new T_HM_OPERATION_TASK_DEAL_MEASURE();
|
||||
del.ORG_ID = orgId;
|
||||
del.OPERATION_LINK_ID = link.ID;
|
||||
del.NUM = string.IsNullOrEmpty(num) ? null : int.Parse(num);
|
||||
del.NAME = name;
|
||||
linkDealList.Add(del);
|
||||
}
|
||||
else
|
||||
{
|
||||
T_HM_OPERATION_TASK_DEAL_MEASURE del = new T_HM_OPERATION_TASK_DEAL_MEASURE();
|
||||
del.ORG_ID = orgId;
|
||||
del.OPERATION_LINK_ID = link.ID;
|
||||
del.NAME = item;
|
||||
linkDealList.Add(del);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 排序分页查询数据
|
||||
/// </summary>
|
||||
/// <param name="pageFilter">分页过滤实体</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("FullOrderPaged")]
|
||||
public PagedActionResult<T_HM_OPERATION_LINK> FullOrderPaged([FromBody] KeywordPageFilter pageFilter)
|
||||
{
|
||||
KeywordPageFilter keywordPageFilter = new KeywordPageFilter();
|
||||
keywordPageFilter = pageFilter;
|
||||
var rule = keywordPageFilter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "POST");
|
||||
if (rule != null)
|
||||
keywordPageFilter.FilterGroup.Rules.Remove(rule);
|
||||
keywordPageFilter.IgnoreDataRule = true;
|
||||
//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 result = this.GetOrderPageEntities<T_HM_OPERATION_LINK>(expression, keywordPageFilter, null);
|
||||
if (result.TotalCount > 0)
|
||||
{
|
||||
result.Data.ForEach(t =>
|
||||
{
|
||||
if (t.Nav_LinkPost != null && t.Nav_LinkPost.Any())
|
||||
{
|
||||
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 (rule != null)
|
||||
{
|
||||
result.Data = result.Data.Where(t =>t.POST!=null && t.POST.Contains(rule.Value.ToString()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
Msg = "导入成功!";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user