mh_jy_safe/APT.MicroApi/APT.SK.WebApi/Controllers/Api/EnterpriseLibraryTempController.cs

143 lines
7.0 KiB
C#
Raw Normal View History

2025-08-25 09:56:57 +08:00
using APT.BaseData.Services.DomainServices;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.FO;
using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Enums;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace APT.SK.WebApi.Controllers.Api
{
[Route("api/SK/SKEnterpriseLibraryTemp")]
public partial class EnterpriseLibraryTempController : AuthorizeApiController<T_SK_ENTERPRISE_LIBRARY_TEMP>
{
/// <summary>
/// 保存
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost, Route("FullUpdate")]
public JsonActionResult<bool> FullUpdate([FromBody] T_SK_ENTERPRISE_LIBRARY_TEMP entity)
{
return SafeExecute<bool>(() =>
{
var measures = entity.Nav_Measures;
entity.Nav_Measures = null;
var contents = entity.Nav_Contents;
entity.Nav_Contents = null;
var hiddens = entity.Nav_Hiddens;
entity.Nav_Hiddens = null;
List<T_SK_ENTERPRISE_LIBRARY_TEMP_MEASURE_DEPART> departList = new List<T_SK_ENTERPRISE_LIBRARY_TEMP_MEASURE_DEPART>();
List<T_SK_ENTERPRISE_LIBRARY_TEMP_CONTENT_DEPART> cdepartList = new List<T_SK_ENTERPRISE_LIBRARY_TEMP_CONTENT_DEPART>();
List<T_SK_ENTERPRISE_LIBRARY_TEMP_CONTENT_POST> postList = new List<T_SK_ENTERPRISE_LIBRARY_TEMP_CONTENT_POST>();
if (measures != null && measures.Any())
{
foreach (var item in measures)
{
if (item.Nav_Departs != null && item.Nav_Departs.Any())
{
foreach (var item2 in item.Nav_Departs)
{
item2.ORG_ID = entity.ORG_ID;
item2.ENTERPRISE_LIBRARY_TEMP_MEASURE_ID = item.ID;
item2.Nav_Measure = null;
departList.Add(item2);
}
}
item.ORG_ID = entity.ORG_ID;
item.ENTERPRISE_LIBRARY_TEMP_ID = entity.ID;
item.Nav_Departs = null;
}
}
if (contents != null && contents.Any())
{
foreach (var item in contents)
{
if (item.Nav_Departs != null && item.Nav_Departs.Any())
{
foreach (var item2 in item.Nav_Departs)
{
if (item2.Nav_Posts != null && item2.Nav_Posts.Any())
{
foreach (var item3 in item2.Nav_Posts)
{
item3.ORG_ID = entity.ORG_ID;
item3.ENTERPRISE_LIBRARY_TEMP_CONTENT_DEPART_ID = item2.ID;
postList.Add(item3);
}
}
item2.ORG_ID = entity.ORG_ID;
item2.ENTERPRISE_LIBRARY_TEMP_CONTENT_ID = item.ID;
item2.Nav_Posts = null;
cdepartList.Add(item2);
}
}
item.ORG_ID = entity.ORG_ID;
item.ENTERPRISE_LIBRARY_TEMP_ID = entity.ID;
item.Nav_Departs = null;
}
}
if (hiddens != null && hiddens.Any())
{
foreach (var item in hiddens)
{
item.ORG_ID = entity.ORG_ID;
item.ENTERPRISE_LIBRARY_TEMP_ID = entity.ID;
}
}
this.UnifiedCommit(() =>
{
if (entity != null)
UpdateEntityNoCommit(entity);
if (measures != null && measures.Any())
BantchSaveEntityNoCommit(measures);
if (departList != null && departList.Any())
BantchSaveEntityNoCommit(departList);
if (contents != null && contents.Any())
BantchSaveEntityNoCommit(contents);
if (cdepartList != null && cdepartList.Any())
BantchSaveEntityNoCommit(cdepartList);
if (postList != null && postList.Any())
BantchSaveEntityNoCommit(postList);
if (hiddens != null && hiddens.Any())
BantchSaveEntityNoCommit(hiddens);
});
return true;
});
}
/// <summary>
/// FullGet
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
[HttpPost, Route("FullGet")]
public JsonActionResult<T_SK_ENTERPRISE_LIBRARY_TEMP> FullGet([FromBody] KeywordFilter filter)
{
return SafeExecute(() => {
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
if (string.IsNullOrEmpty(id))
this.ThrowError("060010");
var entity = this.GetEntity<T_SK_ENTERPRISE_LIBRARY_TEMP>(id,
"Nav_Area", "Nav_Type");
if (entity != null)
{
var newFilter = new BaseFilter(filter.OrgId);
newFilter.SelectField = new List<string> { "ID", "NUM", "MEASURES_NAME", "EMERGENCY", "Nav_Departs", "Nav_Departs.Nav_User", "Nav_Departs.Nav_Department"};
var measures = this.GetEntities<T_SK_ENTERPRISE_LIBRARY_TEMP_MEASURE>(t => t.ENTERPRISE_LIBRARY_TEMP_ID == entity.ID, newFilter).ToList();
entity.Nav_Measures = measures;
newFilter.SelectField = new List<string> { "ID", "NUM", "Nav_Contents", "CHECK_CONTENT", "CHECK_BASIC", "CHECK_STANDARD", "Nav_Departs.Nav_Department", "Nav_Departs.Nav_CheckType", "Nav_Departs.Nav_Posts.Nav_Post" };
var contents = this.GetEntities<T_SK_ENTERPRISE_LIBRARY_TEMP_CONTENT>(t => t.ENTERPRISE_LIBRARY_TEMP_ID == entity.ID, newFilter).ToList();
entity.Nav_Contents = contents.OrderBy(t => t.NUM).ToList();
newFilter.SelectField = new List<string> { "ID", "NUM", "HIDDEN_DESCRIPTION", "HIDDEN_LEVEL", "RECTIFICATION_MEASURES" };
var hiddens = this.GetEntities<T_SK_ENTERPRISE_LIBRARY_TEMP_HIDDEN>(t => t.ENTERPRISE_LIBRARY_TEMP_ID == entity.ID, newFilter).ToList();
entity.Nav_Hiddens = hiddens.OrderBy(t => t.NUM).ToList();
}
return entity;
});
}
}
}