855 lines
37 KiB
C#
855 lines
37 KiB
C#
using APT.BaseData.Domain.ApiModel;
|
||
using APT.BaseData.Domain.Entities;
|
||
using APT.BaseData.Domain.Entities.FM;
|
||
using APT.BaseData.Domain.Enums.PF;
|
||
using APT.BaseData.Domain.IServices;
|
||
using APT.BaseData.Domain.IServices.FM;
|
||
using APT.BaseData.Domain.IServices.OP;
|
||
using APT.BaseData.Services.DomainServices;
|
||
using APT.BaseData.Services.Services.FM;
|
||
using APT.Infrastructure.Core;
|
||
using APT.Migrations;
|
||
using APT.MS.Domain.Entities.BS;
|
||
using APT.MS.Domain.Entities.FO;
|
||
using APT.MS.Domain.Entities.LR;
|
||
using APT.MS.Domain.Entities.SC.SC;
|
||
using APT.MS.Domain.Enums;
|
||
using APT.Utility;
|
||
using InfluxData.Net.InfluxDb.Models.Responses;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.CodeAnalysis;
|
||
using MySqlX.XDevAPI.Common;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Web;
|
||
using static NPOI.HSSF.Util.HSSFColor;
|
||
|
||
namespace APT.LR.WebApi.Controllers.Api
|
||
{
|
||
[Route("api/LR/LRLaw")]
|
||
public class LawController : AuthorizeApiController<T_LR_LAW>
|
||
{
|
||
IFMNotificationTaskService NotificationTaskService { get; set; }
|
||
IOPTenantDBConnService OPTenantDBConnService { get; set; }
|
||
public LawController(IFMNotificationTaskService notificationTaskService, IOPTenantDBConnService opTenantDBConnService)
|
||
{
|
||
NotificationTaskService = notificationTaskService;
|
||
OPTenantDBConnService = opTenantDBConnService;
|
||
}
|
||
/// <summary>
|
||
/// 保存
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("FullUpdate")]
|
||
public JsonActionResult<bool> FullUpdate([FromBody] T_LR_LAW entity)
|
||
{
|
||
return SafeExecute<bool>(() =>
|
||
{
|
||
T_FM_NOTIFICATION_TASK notice = null;
|
||
List<T_LR_LAW_VERSION_FILE> lawVersionFiles = new List<T_LR_LAW_VERSION_FILE>();
|
||
var lawSCSystem = entity.Nav_LawSCSystem;
|
||
var lawVersion = entity.Nav_LawVersion;
|
||
if (entity.USER_ID == Guid.Empty)
|
||
{
|
||
entity.USER_ID = (Guid)APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
||
}
|
||
entity.Nav_LawSCSystem = null;
|
||
entity.Nav_LawVersion = null;
|
||
|
||
if (lawVersion != null)
|
||
{
|
||
int noVersionCount = lawVersion.Count(t => t.VERSION_STATUS == 0);
|
||
if (lawVersion.Count() == noVersionCount)//都是废除状态
|
||
{
|
||
entity.LAW_STATUS = 0;
|
||
entity.VERSION_NUM = lawVersion.Where(t => t.UPDATE_TIME == lawVersion.Max(m => m.UPDATE_TIME)).FirstOrDefault().VERSION_NUM;//现行版本号
|
||
}
|
||
else //现行法律
|
||
{
|
||
int versionCount = lawVersion.Count(t => t.VERSION_STATUS == BSLawStatusEnum.现行 && t.IS_DELETED == false);
|
||
if (versionCount > 1)
|
||
{
|
||
throw new Exception("该法律为现行法律,必须只有一个版本现行!");
|
||
}
|
||
entity.LAW_STATUS = BSLawStatusEnum.现行;
|
||
entity.VERSION_NUM = lawVersion.Where(t => t.VERSION_STATUS == BSLawStatusEnum.现行).FirstOrDefault().VERSION_NUM;//现行版本号
|
||
entity.UPDATE_TIME = lawVersion.Where(t => t.VERSION_STATUS == BSLawStatusEnum.现行).FirstOrDefault().UPDATE_TIME;//现行版本制修订日期
|
||
entity.EXECUTE_TIME = lawVersion.Where(t => t.VERSION_STATUS == BSLawStatusEnum.现行).FirstOrDefault().EXECUTE_TIME;//现行版本施行
|
||
}
|
||
lawVersion.ForEach(t =>
|
||
{
|
||
if (t.Nav_Files != null && t.Nav_Files.Count() > 0)
|
||
{
|
||
t.Nav_Files.ForEach(nf =>
|
||
{
|
||
nf.VERSION_ID = t.ID;
|
||
});
|
||
lawVersionFiles.AddRange(t.Nav_Files);
|
||
t.Nav_Files = null;
|
||
}
|
||
else if (entity.LAW_STATUS == BSLawStatusEnum.现行)
|
||
{
|
||
throw new Exception("状态为现行,请上传法律法规附件!");
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
|
||
#region 安全检查库
|
||
|
||
bool isUndateBSMain = false;
|
||
string oldLAWName = string.Empty;
|
||
ICollection<Guid> listMainID = null;
|
||
|
||
//var checkLaw = GetEntity<T_LR_LAW>(entity.ID);
|
||
var checkLaw = GetEntity<T_SC_STANDARD_CREATE>(entity.ID);
|
||
if (checkLaw != null && checkLaw.NAME != entity.NAME)
|
||
{
|
||
BaseFilter filterCheck = new BaseFilter();
|
||
filterCheck.SelectField = new List<string> { "CHECK_MAIN_ID" };
|
||
var listMain = GetEntities<T_BS_CHECK_MAIN_LAW>(e => e.STANDARD_ID == entity.ID, filterCheck, null);
|
||
if (listMain != null && listMain.Any())
|
||
{
|
||
oldLAWName = checkLaw.NAME;
|
||
listMainID = listMain.Select(e => e.CHECK_MAIN_ID).Distinct().ToList();
|
||
isUndateBSMain = true;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
//判断法规库修改名称时,触发今日提醒给当前层级安全员
|
||
var oldEntity = GetEntity<T_LR_LAW>(entity.ID);
|
||
if (oldEntity != null && oldEntity.NAME != entity.NAME)
|
||
{
|
||
var depart = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == (Guid)APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID);
|
||
if (depart != null)
|
||
{
|
||
var param = "安全员";
|
||
if (depart.DEPARTMENT_TYPE == 5)
|
||
{
|
||
param = "安环部安全员";
|
||
}
|
||
if (depart.DEPARTMENT_TYPE == 20)
|
||
{
|
||
param = "负责人";
|
||
}
|
||
var user = this.GetEntity<T_FM_USER>(t => t.DEPARTMENT_ID == depart.ID && t.Nav_ApproveRole != null && t.Nav_ApproveRole.NAME.Contains(param));
|
||
if (user == null)
|
||
{
|
||
user = this.GetEntity<T_FM_USER>(t => t.DEPARTMENT_ID == depart.ID && t.Nav_ApproveRole != null && t.Nav_ApproveRole.NAME.Contains("负责人"));
|
||
}
|
||
if (user != null)
|
||
{
|
||
notice = NotificationTaskService.InsertUserNoticeTaskModel("法律法规名称有变更,请对企业库检查依据进行变更", entity.ID, entity.ORG_ID, user.ID, user.NAME, DateTime.Now, DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.今日提醒, "PF135");
|
||
}
|
||
}
|
||
}
|
||
|
||
entity.MODIFY_TIME = DateTime.Now;//作为数据同步的判断标记符
|
||
|
||
UnifiedCommit(() =>
|
||
{
|
||
UpdateEntityNoCommit(entity);
|
||
if (lawSCSystem != null)
|
||
BantchSaveEntityNoCommit(lawSCSystem);
|
||
if (lawVersion != null)
|
||
BantchSaveEntityNoCommit(lawVersion);
|
||
if (lawVersionFiles.Any())
|
||
BantchSaveEntityNoCommit(lawVersionFiles);
|
||
if (notice != null)
|
||
UpdateEntityNoCommit(notice);
|
||
});
|
||
|
||
|
||
#region 同步修改 依据
|
||
|
||
if (isUndateBSMain)
|
||
{
|
||
try
|
||
{
|
||
var listCheckMain = GetEntities<T_BS_CHECK_MAIN>(e => listMainID.Contains(e.ID), null, null);
|
||
List<string> listRoot = null;
|
||
foreach (var item in listCheckMain)
|
||
{
|
||
listRoot = item.CHECKPROOF.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
for (int i = 0; i < listRoot.Count; i++)
|
||
{
|
||
if (listRoot[i] == oldLAWName)
|
||
{
|
||
listRoot[i] = entity.NAME;
|
||
}
|
||
}
|
||
item.CHECKPROOF = String.Join(',', listRoot);
|
||
}
|
||
|
||
if (listCheckMain != null && listCheckMain.Any())
|
||
{
|
||
UnifiedCommit(() =>
|
||
{
|
||
BantchSaveEntityNoCommit(listCheckMain);
|
||
});
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
return true;
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 排序分页查询数据
|
||
/// </summary>
|
||
/// <param name="pageFilter">分页过滤实体</param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPaged")]
|
||
public PagedActionResult<T_LR_LAW> OrderPaged([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
Expression<Func<T_LR_LAW, bool>> uExpress = t => t.IS_DELETED == false;
|
||
if (pageFilter.Keyword != "")
|
||
{
|
||
List<Guid> ids = new List<Guid>();
|
||
var tempids = pageFilter.Keyword.Split(",");
|
||
foreach (var id in tempids)
|
||
{
|
||
ids.Add(Guid.Parse(id));
|
||
}
|
||
uExpress = uExpress.And(t => ids.Contains(t.TYPE_ID));
|
||
}
|
||
|
||
return WitOrderPaged(uExpress, pageFilter);
|
||
}
|
||
/// <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, 1);//根据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;
|
||
if (!string.IsNullOrEmpty(Msg))
|
||
{
|
||
throw new Exception(Msg);
|
||
}
|
||
List<T_LR_LAW> laws = new List<T_LR_LAW>();
|
||
List<T_LR_LAW_VERSION> lawVersions = new List<T_LR_LAW_VERSION>();
|
||
var lawTypess = GetEntities<T_LR_LAW_TYPE>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
||
DateTime dtNow = DateTime.Now;
|
||
for (int i = 0; i < rowAll; i++)
|
||
{
|
||
T_LR_LAW law = new T_LR_LAW();
|
||
law.ID = Guid.NewGuid();
|
||
law.VERSION_NUM = dtSource.Rows[i][2].ToString().Trim();
|
||
law.USER_ID = (Guid)userId;
|
||
if (!string.IsNullOrEmpty(dtSource.Rows[i][0].ToString().Trim()))
|
||
{
|
||
law.NAME = dtSource.Rows[i][0].ToString().Trim();
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("名称不能为空!");
|
||
}
|
||
if (!string.IsNullOrEmpty(dtSource.Rows[i][3].ToString().Trim()))
|
||
{
|
||
law.UPDATE_TIME = DateTime.Parse(dtSource.Rows[i][3].ToString().Trim());
|
||
}
|
||
if (lawTypess.FirstOrDefault(t => t.NAME == dtSource.Rows[i][1].ToString().Trim()) != null)
|
||
{
|
||
law.TYPE_ID = lawTypess.FirstOrDefault(t => t.NAME == dtSource.Rows[i][1].ToString().Trim()).ID;
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("需求类别:" + dtSource.Rows[i][1].ToString().Trim() + "未找到");
|
||
}
|
||
law.LAW_STATUS = BSLawStatusEnum.现行;
|
||
law.ORG_ID = orgId;
|
||
T_LR_LAW_VERSION lawVersion = new T_LR_LAW_VERSION
|
||
{
|
||
ID = Guid.NewGuid(),
|
||
LAW_ID = law.ID,
|
||
VERSION_NUM = dtSource.Rows[i][2].ToString().Trim(),
|
||
ENTER_TIME = dtNow,
|
||
VERSION_STATUS = BSLawStatusEnum.现行,
|
||
ORG_ID = orgId,
|
||
};
|
||
if (!string.IsNullOrEmpty(dtSource.Rows[i][3].ToString().Trim()))
|
||
{
|
||
lawVersion.UPDATE_TIME = DateTime.Parse(dtSource.Rows[i][3].ToString().Trim());
|
||
}
|
||
if (!string.IsNullOrEmpty(dtSource.Rows[i][4].ToString().Trim()))
|
||
{
|
||
lawVersion.EXECUTE_TIME = DateTime.Parse(dtSource.Rows[i][4].ToString().Trim());
|
||
}
|
||
laws.Add(law);
|
||
lawVersions.Add(lawVersion);
|
||
|
||
}
|
||
UnifiedCommit(() =>
|
||
{
|
||
if (laws != null && laws.Any())
|
||
BantchAddEntityNoCommit(laws);
|
||
if (lawVersions != null && lawVersions.Any())
|
||
BantchAddEntityNoCommit(lawVersions);
|
||
});
|
||
Msg = "导入成功!";
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序分页查询数据
|
||
/// </summary>
|
||
/// <param name="pageFilter">分页过滤实体</param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPagedHead")]
|
||
public PagedActionResult<T_LR_LAW> OrderPagedHead([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_LR_LAW> result)
|
||
{
|
||
string strConn = OPTenantDBConnService.GetConnByORGID(new Guid(FilePathHead.JY.GetDescription()));
|
||
try
|
||
{
|
||
using (var context = new MigrationContext(strConn))
|
||
{
|
||
Expression<Func<T_LR_LAW, bool>> expression = e => !e.IS_DELETED;
|
||
if (pageFilter.FilterGroup != null && pageFilter.FilterGroup.Rules != null && pageFilter.FilterGroup.Rules.Count() > 0)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Rules)
|
||
{
|
||
if (item.Field == "NAME")
|
||
{
|
||
expression = expression.And(e => e.NAME.Contains(item.Value.ToString()));
|
||
}
|
||
else if (item.Field == "LAW_STATUS" && item.Value != null)
|
||
{
|
||
try
|
||
{
|
||
BSLawStatusEnum LAW_STATUS = (BSLawStatusEnum)Convert.ToInt32(item.Value.ToString());
|
||
expression = expression.And(e => e.LAW_STATUS == LAW_STATUS);
|
||
}
|
||
catch { }
|
||
}
|
||
}
|
||
}
|
||
if (pageFilter.FilterGroup != null && pageFilter.FilterGroup.Groups != null && pageFilter.FilterGroup.Groups.Count() > 0)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Groups)
|
||
{
|
||
DateTime? UPDATE_TIMES = null;
|
||
DateTime? UPDATE_TIMEE = null;
|
||
if (item.Rules != null && item.Rules.Any() && item.Rules.Count() > 0)
|
||
{
|
||
foreach (var itemR in item.Rules)
|
||
{
|
||
if (itemR.Field == "UPDATE_TIME" && itemR.Operate == FilterOperate.GreaterThanOrEqual)
|
||
{
|
||
UPDATE_TIMES = Convert.ToDateTime(itemR.Value.ToString());
|
||
}
|
||
else if (itemR.Field == "UPDATE_TIME" && itemR.Operate == FilterOperate.LessThanOrEqual)
|
||
{
|
||
UPDATE_TIMEE = Convert.ToDateTime(itemR.Value.ToString());
|
||
}
|
||
}
|
||
}
|
||
if (UPDATE_TIMES != null)
|
||
{
|
||
expression = expression.And(e => e.UPDATE_TIME >= UPDATE_TIMES);
|
||
}
|
||
if (UPDATE_TIMEE != null)
|
||
{
|
||
expression = expression.And(e => e.UPDATE_TIME <= UPDATE_TIMEE);
|
||
}
|
||
}
|
||
}
|
||
Dictionary<string, DbOrder> orders = new Dictionary<string, DbOrder>();
|
||
orders.Add("CREATE_TIME", DbOrder.DESC);
|
||
PagedResultDto<T_LR_LAW> data = context.GetOrderPageEntities(expression, orders, null, pageFilter.Limit, pageFilter.Start, pageFilter.Include.ToArray());
|
||
result.TotalCount = data.TotalCount;
|
||
result.Data = data.Items;
|
||
List<Guid> ListLawID = null;
|
||
if (result.TotalCount > 0)
|
||
{
|
||
ListLawID = result.Data.Select(e => e.TYPE_ID).ToList();
|
||
var listLawType = context.GetEntities<T_LR_LAW_TYPE>(e => ListLawID.Contains(e.ID), null, null);
|
||
|
||
ListLawID = result.Data.Select(e => e.ID).ToList();
|
||
var listVersion = context.GetEntities<T_LR_LAW_VERSION>(e => ListLawID.Contains(e.LAW_ID), null, "Nav_Files.Nav_ImgFile.Nav_File");
|
||
foreach (var item in result.Data)
|
||
{
|
||
item.Nav_LawType = listLawType.FirstOrDefault(e => e.ID == item.TYPE_ID);
|
||
item.Nav_LawVersion = listVersion.Where(e => e.LAW_ID == item.ID).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch { }
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 集团法律法规同步到本地
|
||
/// </summary>
|
||
/// <param name="ids"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("SyncToLocal")]
|
||
public JsonActionResult<bool> SyncToLocal([FromBody] SyscList list)
|
||
{
|
||
return SafeExecute<bool>(() =>
|
||
{
|
||
//最终结果数据
|
||
List<T_LR_LAW> listLaw = new List<T_LR_LAW>();
|
||
List<T_LR_LAW_TYPE> listLawType = new List<T_LR_LAW_TYPE>();
|
||
List<T_LR_LAW_VERSION> listLawVersion = new List<T_LR_LAW_VERSION>();
|
||
List<T_LR_LAW_VERSION_FILE> listFiles = new List<T_LR_LAW_VERSION_FILE>();
|
||
List<T_PF_IMG_FILE> listImgFile = new List<T_PF_IMG_FILE>();
|
||
List<T_PF_FILE> listFile = new List<T_PF_FILE>();
|
||
|
||
//数据库查找数据
|
||
List<T_LR_LAW> listSourse = list.ListModel;
|
||
var listLawID = listSourse.Select(e => e.ID);
|
||
var listLawTypeID = listSourse.Select(e => e.TYPE_ID);
|
||
IEnumerable<T_LR_LAW> listLawData = null;
|
||
IEnumerable<T_LR_LAW_TYPE> listLawTypeData = null;
|
||
IEnumerable<T_LR_LAW_VERSION> listLawVersionData = null;
|
||
List<T_LR_LAW_VERSION_FILE> listLawVersionFileData = null;
|
||
List<T_PF_IMG_FILE> listImgFileData = null;
|
||
List<T_PF_FILE> listFileData = null;
|
||
|
||
if (listLawID != null && listLawID.Any())
|
||
{
|
||
listLawData = GetEntities<T_LR_LAW>(e => listLawID.Contains(e.ID), null, null);
|
||
listLawVersionData = GetEntities<T_LR_LAW_VERSION>(e => listLawID.Contains(e.LAW_ID), null, "Nav_Files.Nav_ImgFile.Nav_File").ToList();
|
||
}
|
||
if (listLawTypeID != null && listLawTypeID.Any())
|
||
{
|
||
listLawTypeData = GetEntities<T_LR_LAW_TYPE>(e => listLawTypeID.Contains(e.ID), null, null).ToList();
|
||
}
|
||
if (listLawVersionData != null && listLawVersionData.Count() > 0)
|
||
{
|
||
listLawVersionFileData = new List<T_LR_LAW_VERSION_FILE>();
|
||
foreach (var item in listLawVersionData)
|
||
{
|
||
if (item.Nav_Files == null || item.Nav_Files.Count() < 1)
|
||
continue;
|
||
listLawVersionFileData.AddRange(item.Nav_Files);
|
||
}
|
||
}
|
||
if (listLawVersionFileData != null && listLawVersionFileData.Count() > 0)
|
||
{
|
||
listImgFileData = new List<T_PF_IMG_FILE>();
|
||
foreach (var item in listLawVersionFileData)
|
||
listImgFileData.Add(item.Nav_ImgFile);
|
||
}
|
||
if (listImgFileData != null && listImgFileData.Count() > 0)
|
||
{
|
||
listFileData = new List<T_PF_FILE>();
|
||
foreach (var item in listImgFileData)
|
||
listFileData.Add(item.Nav_File);
|
||
}
|
||
|
||
Guid? LoginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
||
Guid? OrgID = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
|
||
DateTime dtNow = DateTime.Now.Date;
|
||
|
||
///数据组装和查验
|
||
List<T_LR_LAW_TYPE> Nav_LawType = new List<T_LR_LAW_TYPE>();
|
||
List<T_LR_LAW_VERSION> Nav_LawVersion = new List<T_LR_LAW_VERSION>();
|
||
List<T_LR_LAW_VERSION_FILE> Nav_Files = new List<T_LR_LAW_VERSION_FILE>();
|
||
List<T_PF_IMG_FILE> Nav_ImgFile = new List<T_PF_IMG_FILE>();
|
||
List<T_PF_FILE> Nav_File = new List<T_PF_FILE>();
|
||
T_LR_LAW modelCheck = null;
|
||
T_LR_LAW_TYPE modelCheckType = null;
|
||
T_LR_LAW_VERSION modelVersion = null;
|
||
T_LR_LAW_VERSION_FILE modelVersionFile = null;
|
||
T_PF_IMG_FILE modelImgFile = null;
|
||
T_PF_FILE modelFile = null;
|
||
|
||
Guid AdminID = new Guid("11111111-1111-1111-1111-111111111111");
|
||
#region 全部拆到组合中去再统一处理
|
||
|
||
foreach (var item in listSourse)
|
||
{
|
||
if (!Nav_LawType.Contains(item.Nav_LawType))
|
||
Nav_LawType.Add(item.Nav_LawType);
|
||
if (item.Nav_LawVersion != null && item.Nav_LawVersion.Count() > 0)
|
||
Nav_LawVersion.AddRange(item.Nav_LawVersion);
|
||
}
|
||
|
||
foreach (var item in Nav_LawVersion)
|
||
{
|
||
if (item.Nav_Files != null && item.Nav_Files.Count() > 0)
|
||
Nav_Files.AddRange(item.Nav_Files);
|
||
}
|
||
foreach (var item in Nav_Files)
|
||
{
|
||
if (item.Nav_ImgFile != null)
|
||
Nav_ImgFile.Add(item.Nav_ImgFile);
|
||
}
|
||
foreach (var item in Nav_ImgFile)
|
||
{
|
||
if (item.Nav_File != null)
|
||
Nav_File.Add(item.Nav_File);
|
||
}
|
||
#endregion
|
||
|
||
#region 数据判断处理
|
||
|
||
foreach (var item in listSourse)
|
||
{
|
||
modelCheck = listLawData.FirstOrDefault(e => e.ID == item.ID);
|
||
if (modelCheck == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelCheck != null)
|
||
{
|
||
item.NAME = modelCheck.NAME;
|
||
item.LAW_STATUS = modelCheck.LAW_STATUS;
|
||
item.UPDATE_TIME = modelCheck.UPDATE_TIME;
|
||
item.EXECUTE_TIME = modelCheck.EXECUTE_TIME;
|
||
}
|
||
item.USER_ID = AdminID;//融入人修改为 超管
|
||
listLaw.Add(item);
|
||
}
|
||
|
||
foreach (var item in Nav_LawType)
|
||
{
|
||
modelCheckType = listLawTypeData.FirstOrDefault(e => e.ID == item.ID);
|
||
if (modelCheckType != null)//如果已经有这种检查类型 直接跳过
|
||
continue;
|
||
|
||
if (listLawTypeData != null && listLawTypeData.Count() > 0)
|
||
{
|
||
modelCheckType = listLawTypeData.FirstOrDefault(e => e.ID == item.ID);
|
||
}
|
||
else
|
||
{
|
||
modelCheckType = null;
|
||
}
|
||
if (modelCheckType == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelCheckType != null)
|
||
{
|
||
item.NAME = modelCheckType.NAME;
|
||
item.CODE = modelCheckType.CODE;
|
||
}
|
||
listLawType.Add(item);
|
||
}
|
||
|
||
foreach (var item in Nav_LawVersion)
|
||
{
|
||
if (listLawVersionData != null && listLawVersionData.Count() > 0)
|
||
{
|
||
modelVersion = listLawVersionData.FirstOrDefault(e => e.ID == item.ID);
|
||
}
|
||
else
|
||
{
|
||
modelVersion = null;
|
||
}
|
||
if (modelVersion == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelVersion != null)
|
||
{
|
||
item.EXECUTE_TIME = modelVersion.EXECUTE_TIME;
|
||
item.UPDATE_TIME = modelVersion.UPDATE_TIME;
|
||
item.VERSION_NUM = modelVersion.VERSION_NUM;
|
||
item.VERSION_STATUS = modelVersion.VERSION_STATUS;
|
||
item.ENTER_TIME = modelVersion.ENTER_TIME;
|
||
}
|
||
listLawVersion.Add(item);
|
||
}
|
||
|
||
foreach (var item in Nav_Files)
|
||
{
|
||
if (listLawVersionFileData != null && listLawVersionFileData.Count() > 0)
|
||
{
|
||
modelVersionFile = listLawVersionFileData.FirstOrDefault(e => e.ID == item.ID);
|
||
}
|
||
else
|
||
{
|
||
modelVersionFile = null;
|
||
}
|
||
if (modelVersionFile == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelVersionFile != null)
|
||
{
|
||
item.IMG_FILE_ID = modelVersionFile.IMG_FILE_ID;
|
||
item.VERSION_ID = modelVersionFile.VERSION_ID;
|
||
}
|
||
listFiles.Add(item);
|
||
}
|
||
foreach (var item in Nav_ImgFile)
|
||
{
|
||
if (listImgFileData != null && listImgFileData.Count() > 0)
|
||
{
|
||
modelImgFile = listImgFileData.FirstOrDefault(e => e.ID == item.ID);
|
||
}
|
||
else
|
||
{
|
||
modelImgFile = null;
|
||
}
|
||
if (modelVersion == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelImgFile != null)
|
||
{
|
||
item.FILE_PATH = modelImgFile.FILE_PATH;
|
||
item.FILE_NAME = modelImgFile.FILE_NAME;
|
||
item.FILE_TYPE = modelImgFile.FILE_TYPE;
|
||
item.FILE_ID = modelImgFile.FILE_ID;
|
||
item.SRC_ID = modelImgFile.SRC_ID;
|
||
}
|
||
listImgFile.Add(item);
|
||
}
|
||
|
||
foreach (var item in Nav_File)
|
||
{
|
||
if (listFileData != null && listFileData.Count() > 0)
|
||
{
|
||
modelFile = listFileData.FirstOrDefault(e => e.ID == item.ID);
|
||
}
|
||
else
|
||
{
|
||
modelFile = null;
|
||
}
|
||
if (modelVersion == null)
|
||
{
|
||
item.CREATER_ID = LoginID;
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
else if (modelFile != null)
|
||
{
|
||
item.FILE_PATH = modelFile.FILE_PATH;
|
||
item.FILE_NAME = modelFile.FILE_NAME;
|
||
item.FILE_TYPE = modelFile.FILE_TYPE;
|
||
item.FILE_DATA = modelFile.FILE_DATA;
|
||
item.IS_TEMPORARY_FILE = modelFile.IS_TEMPORARY_FILE;
|
||
}
|
||
listFile.Add(item);
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 数据统一处理 CREATE_TIME MODIFY_TIME MODIFIER_ID 等
|
||
|
||
if (listLawVersion != null && listLawVersion.Any())
|
||
{
|
||
var listVersionOK = listLawVersion.Where(e => e.VERSION_STATUS == BSLawStatusEnum.现行).OrderBy(e => e.LAW_ID).ThenByDescending(e => e.ENTER_TIME).ToList();
|
||
if (listVersionOK != null && listVersionOK.Count > 0)
|
||
{
|
||
for (int i = 1; i < listVersionOK.Count; i++)
|
||
{
|
||
if (listVersionOK[i].LAW_ID == listVersionOK[i - 1].LAW_ID)
|
||
{
|
||
listVersionOK[i].VERSION_STATUS = BSLawStatusEnum.废止;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (listLaw != null && listLaw.Count() > 0)
|
||
{
|
||
foreach (var item in listLaw)
|
||
{
|
||
item.Nav_LawType = null;
|
||
item.Nav_LawVersion = null;
|
||
item.Nav_User = null;
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
|
||
if (listLawType != null && listLawType.Count() > 0)
|
||
{
|
||
foreach (var item in listLawType)
|
||
{
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
|
||
if (listLawVersion != null && listLawVersion.Count() > 0)
|
||
{
|
||
foreach (var item in listLawVersion)
|
||
{
|
||
item.Nav_Files = null;
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
|
||
if (listFiles != null && listFiles.Count() > 0)
|
||
{
|
||
foreach (var item in listFiles)
|
||
{
|
||
item.Nav_ImgFile = null;
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
|
||
if (listImgFile != null && listImgFile.Count() > 0)
|
||
{
|
||
foreach (var item in listImgFile)
|
||
{
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
|
||
if (listFile != null && listFile.Count() > 0)
|
||
{
|
||
foreach (var item in listFile)
|
||
{
|
||
item.ORG_ID = OrgID;
|
||
if (item.CREATER_ID == LoginID)
|
||
{
|
||
item.CREATE_TIME = dtNow;
|
||
}
|
||
item.MODIFY_TIME = dtNow;
|
||
item.MODIFIER_ID = LoginID;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 数据处理
|
||
|
||
UnifiedCommit(() =>
|
||
{
|
||
if (listLaw != null && listLaw.Any())
|
||
BantchSaveEntityNoCommit(listLaw);
|
||
if (listLawType != null && listLawType.Any())
|
||
BantchSaveEntityNoCommit(listLawType);
|
||
if (listLawVersion != null && listLawVersion.Any())
|
||
BantchSaveEntityNoCommit(listLawVersion);
|
||
if (listFiles != null && listFiles.Any())
|
||
BantchSaveEntityNoCommit(listFiles);
|
||
if (listImgFile != null && listImgFile.Any())
|
||
BantchSaveEntityNoCommit(listImgFile);
|
||
if (listFile != null && listFile.Any())
|
||
BantchSaveEntityNoCommit(listFile);
|
||
});
|
||
|
||
#endregion
|
||
return true;
|
||
});
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数据同步传参
|
||
/// </summary>
|
||
public class SyscList
|
||
{
|
||
public List<T_LR_LAW> ListModel { get; set; }//ICollection
|
||
}
|
||
} |