ow
This commit is contained in:
1 parent
d2c2b3cf59
commit
4359903d9c
33 files changed
+2708
-246
No files matched your search
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
using CloudBuilder.Core.DatabaseAccessor;
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using CloudBuilder.Core.Service;
|
||||
@@ -6,7 +6,13 @@ using CloudBuilder.Master.Data;
|
||||
using CloudBuilder.Master.Entity;
|
||||
using CloudBuilder.Master.Policy;
|
||||
using CloudBuilder.Master.SearchCriteria;
|
||||
using CloudBuilder.Security.Data;
|
||||
using CloudBuilder.Security.Entity;
|
||||
using CloudBuilder.Security.Service;
|
||||
using CloudBuilder.Security.Utility;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace CloudBuilder.Master.Service
|
||||
{
|
||||
public class FamilyTreeService : IFamilyTreeService
|
||||
@@ -19,19 +25,62 @@ namespace CloudBuilder.Master.Service
|
||||
this.service = service;
|
||||
repository = service.GetRepository<IRepository<FamilyTreeEntity>>();
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeData FindByKey(string key)
|
||||
{
|
||||
return FindByCurrentPerson(key, null);
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeData FindByCurrentPerson(string key, string personId)
|
||||
{
|
||||
FamilyTreeData data = new FamilyTreeData();
|
||||
return data;// repository.DetachedEntities.Where(x => x.TreeId == key).FirstOrDefault()!;
|
||||
if (string.IsNullOrEmpty(key)) return data;
|
||||
|
||||
FamilyTreeEntity d = repository.DetachedEntities.Where(x => x.TreeId == key).FirstOrDefault();
|
||||
|
||||
if (d == null) return data;
|
||||
|
||||
data.FamilyTree = new FamilyTreeDisplayData(d);
|
||||
data.CurrentPerson = new FamilyPersonData();
|
||||
|
||||
IRepository<FamilyPersonEntity> repositoryFamilyPerson = repository.GetRepository<IRepository<FamilyPersonEntity>>();
|
||||
|
||||
var currentPerson = personId;
|
||||
if (string.IsNullOrEmpty(personId))
|
||||
{
|
||||
currentPerson = d.AncestorPersonId;
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == currentPerson).FirstOrDefault()!);
|
||||
|
||||
data.FamilyTree.AncestorPersonGenealogyName = data.CurrentPerson.FamilyPerson.GenealogyName;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == d.AncestorPersonId).FirstOrDefault()!);
|
||||
|
||||
data.FamilyTree.AncestorPersonGenealogyName = data.CurrentPerson.FamilyPerson.GenealogyName;
|
||||
|
||||
data.CurrentPerson.FamilyPerson = new FamilyPersonDisplayData(repositoryFamilyPerson.DetachedEntities.Where(x => x.PersonId == personId).FirstOrDefault()!);
|
||||
}
|
||||
|
||||
IRepository<FamilyTreeChildrenMapViewEntity> repositoryChildrenMap = repository.GetRepository<IRepository<FamilyTreeChildrenMapViewEntity>>();
|
||||
|
||||
IRepository<FamilyTreeSpouseMapViewEntity> repositorySpouseMap = repository.GetRepository<IRepository<FamilyTreeSpouseMapViewEntity>>();
|
||||
|
||||
data.CurrentPerson.FamilyTreeSpouseMaps = repositorySpouseMap.GetRepository<IRepository<FamilyTreeSpouseMapViewEntity>>().DetachedEntities.Where(x => x.PersonId == currentPerson).OrderBy(x => x.Orderby).ToArray();
|
||||
|
||||
//data.CurrentPerson.FamilyTreeParentMaps = repositoryChildrenMap.GetRepository<IRepository<FamilyTreeChildrenMapViewEntity>>().DetachedEntities.Where(x => x.ChildrenId == key).OrderBy(x => x.Orderby).ToArray();
|
||||
data.CurrentPerson.FamilyTreeChildrenMaps = repositoryChildrenMap.GetRepository<IRepository<FamilyTreeChildrenMapViewEntity>>().DetachedEntities.Where(x => x.PersonId == currentPerson).OrderBy(x => x.Orderby).ToArray();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Find)]
|
||||
public FamilyTreeResultData FindBySearchCriteria(FamilyTreeSearchCriteria criteria)
|
||||
{
|
||||
FamilyTreeResultData data = new FamilyTreeResultData();
|
||||
FamilyTreeEntity[] list = null;
|
||||
FamilyTreeViewEntity[] list = null;
|
||||
|
||||
int count = 0;
|
||||
|
||||
@@ -42,13 +91,15 @@ namespace CloudBuilder.Master.Service
|
||||
sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter);
|
||||
}
|
||||
|
||||
FamilyTreeEntity entity = FamilyTreeEntity.GetInstance(repository.GetDbContext().Database.ProviderName);
|
||||
FamilyTreeViewEntity entity = FamilyTreeViewEntity.GetInstance(repository.GetDbContext().Database.ProviderName);
|
||||
string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere);
|
||||
|
||||
IRepository<FamilyTreeViewEntity> repositoryView = repository.GetRepository<IRepository<FamilyTreeViewEntity>>();
|
||||
|
||||
string err = null;
|
||||
try
|
||||
{
|
||||
list = repository.FromSql(sql).ToArray();
|
||||
list = repositoryView.FromSql(sql).ToArray();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
@@ -81,14 +132,192 @@ namespace CloudBuilder.Master.Service
|
||||
[UnitOfWork]
|
||||
public FamilyTreeData Insert(FamilyTreeData data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
FamilyTreeEntity d = repository.DetachedEntities.Where(x => x.TreeName == data.FamilyTree.TreeName).FirstOrDefault();
|
||||
if (d != null)
|
||||
{
|
||||
throw new ValidatedException("家族名称已存在.");
|
||||
}
|
||||
|
||||
Validate(data.FamilyTree);
|
||||
|
||||
d = new FamilyTreeEntity();
|
||||
ObjectCopyHelper.Copy(data.FamilyTree, d);
|
||||
|
||||
|
||||
ISecurityGeneratorNumberService securityGeneratorNumberService = service.ServiceProvider.GetService<ISecurityGeneratorNumberService>()!;
|
||||
|
||||
d.TreeId = securityGeneratorNumberService.GetNo(MasterPrefixPolicy.FAMILY_TREE, MasterPrefixPolicy.FAMILY_TREE_TREE_ID, MasterPrefixPolicy.FAMILY_TREE_PREFIX, YesNoPolicy.NO, MasterPrefixPolicy.FAMILY_TREE_FORMAT);
|
||||
|
||||
repository.InsertNow(d);
|
||||
|
||||
var currentPerson = d.AncestorPersonId;
|
||||
|
||||
if (data.CurrentPerson != null && data.CurrentPerson.FamilyPerson != null && !string.IsNullOrEmpty(data.CurrentPerson.FamilyPerson.PersonId))
|
||||
{
|
||||
currentPerson = data.CurrentPerson.FamilyPerson.PersonId;
|
||||
}
|
||||
|
||||
if (data.CurrentPerson != null && data.CurrentPerson.FamilyTreeSpouseMaps != null && data.CurrentPerson.FamilyTreeSpouseMaps.Length > 0)
|
||||
data.CurrentPerson.FamilyTreeSpouseMaps.ToLookup(x => x.TreeId = d.TreeId);
|
||||
|
||||
if (data.CurrentPerson != null && data.CurrentPerson.FamilyTreeChildrenMaps != null && data.CurrentPerson.FamilyTreeChildrenMaps.Length > 0)
|
||||
data.CurrentPerson.FamilyTreeChildrenMaps.ToLookup(x => x.TreeId = d.TreeId);
|
||||
|
||||
SaveSpouseMaps(currentPerson, data.CurrentPerson.FamilyTreeSpouseMaps);
|
||||
//SaveParentMaps(data.CurrentPerson.FamilyPerson.PersonId, data.CurrentPerson.FamilyTreeParentMaps);
|
||||
SaveSonMaps(currentPerson, data.CurrentPerson.FamilyTreeChildrenMaps);
|
||||
|
||||
return FindByCurrentPerson(d.TreeId, currentPerson);
|
||||
}
|
||||
|
||||
private void SaveSpouseMaps(string personId, FamilyTreeSpouseMapViewEntity[] maps)
|
||||
{
|
||||
IRepository<FamilyTreeSpouseMapViewEntity> repositoryMapView = repository.GetRepository<IRepository<FamilyTreeSpouseMapViewEntity>>();
|
||||
IRepository<FamilyTreeSpouseMapEntity> repositoryMap = repository.GetRepository<IRepository<FamilyTreeSpouseMapEntity>>();
|
||||
|
||||
FamilyTreeSpouseMapViewEntity[] olds = repositoryMapView.Entities.Where(x => x.PersonId == personId).ToArray();
|
||||
if (olds != null && olds.Length > 0)
|
||||
{
|
||||
foreach (FamilyTreeSpouseMapViewEntity old in olds)
|
||||
{
|
||||
repositoryMap.DeleteNow(new FamilyTreeSpouseMapEntity()
|
||||
{
|
||||
TreeId = old.TreeId,
|
||||
PersonId = personId,
|
||||
SpouseId = old.SpouseId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (maps == null || maps.Length == 0) return;
|
||||
int i = 1;
|
||||
foreach (FamilyTreeSpouseMapViewEntity map in maps.OrderBy(x => x.Orderby).ToArray())
|
||||
{
|
||||
repositoryMap.InsertNow(new FamilyTreeSpouseMapEntity()
|
||||
{
|
||||
TreeId = map.TreeId,
|
||||
PersonId = personId,
|
||||
SpouseId = map.SpouseId,
|
||||
|
||||
MarryDateText = map.MarryDateText,
|
||||
MarryDate = map.MarryDate,
|
||||
DivorceDateText = map.DivorceDateText,
|
||||
DivorceDate = map.DivorceDate,
|
||||
MarryType = map.MarryType,
|
||||
IsCurrent = map.IsCurrent,
|
||||
Remark = map.Remark,
|
||||
Orderby = i++
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveParentMaps(string personId, FamilyTreeChildrenMapViewEntity[] maps)
|
||||
{
|
||||
IRepository<FamilyTreeChildrenMapViewEntity> repositoryMapView = repository.GetRepository<IRepository<FamilyTreeChildrenMapViewEntity>>();
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryMap = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
FamilyTreeChildrenMapViewEntity[] olds = repositoryMapView.Entities.Where(x => x.ChildrenId == personId).ToArray();
|
||||
if (olds != null && olds.Length > 0)
|
||||
{
|
||||
foreach (FamilyTreeChildrenMapViewEntity old in olds)
|
||||
{
|
||||
repositoryMap.DeleteNow(new FamilyTreeChildrenMapEntity()
|
||||
{
|
||||
TreeId = old.TreeId,
|
||||
ChildrenId = personId,
|
||||
PersonId = old.PersonId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (maps == null || maps.Length == 0) return;
|
||||
|
||||
int maxOrderBy = 0;
|
||||
foreach (FamilyTreeChildrenMapViewEntity map in maps)
|
||||
{
|
||||
FamilyTreeChildrenMapViewEntity[] oldMaps = repositoryMapView.Entities.Where(x => x.PersonId == map.PersonId).ToArray();
|
||||
|
||||
if (oldMaps != null && oldMaps.Count() > 0) maxOrderBy = oldMaps.Max(x => x.Orderby);
|
||||
|
||||
repositoryMap.InsertNow(new FamilyTreeChildrenMapEntity()
|
||||
{
|
||||
TreeId = map.TreeId,
|
||||
ChildrenId = personId,
|
||||
PersonId = map.PersonId,
|
||||
Orderby = oldMaps == null ? 1 : maxOrderBy + 1
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void SaveSonMaps(string personId, FamilyTreeChildrenMapViewEntity[] maps)
|
||||
{
|
||||
IRepository<FamilyTreeChildrenMapViewEntity> repositoryMapView = repository.GetRepository<IRepository<FamilyTreeChildrenMapViewEntity>>();
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryMap = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
|
||||
FamilyTreeChildrenMapViewEntity[] olds = repositoryMapView.Entities.Where(x => x.PersonId == personId).ToArray();
|
||||
if (olds != null && olds.Length > 0)
|
||||
{
|
||||
foreach (FamilyTreeChildrenMapViewEntity old in olds)
|
||||
{
|
||||
repositoryMap.DeleteNow(new FamilyTreeChildrenMapEntity()
|
||||
{
|
||||
TreeId = old.TreeId,
|
||||
PersonId = personId,
|
||||
ChildrenId = old.ChildrenId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (maps == null || maps.Length == 0) return;
|
||||
int i = 1;
|
||||
foreach (FamilyTreeChildrenMapViewEntity map in maps.OrderBy(x => x.Orderby).ToArray())
|
||||
{
|
||||
repositoryMap.InsertNow(new FamilyTreeChildrenMapEntity()
|
||||
{
|
||||
TreeId = map.TreeId,
|
||||
PersonId = personId,
|
||||
SpouseId = map.SpouseId,
|
||||
|
||||
ChildrenId = map.ChildrenId,
|
||||
RelationType = map.RelationType,
|
||||
Remark = map.Remark,
|
||||
Orderby = i++
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void Validate(FamilyTreeEntity d)
|
||||
{
|
||||
List<SysTableSchemaViewEntity> sysTableSchemas = service.ServiceProvider.GetRequiredService<ISysTableSchemaViewService>().FindByTableName(FamilyTreeEntity.DB_NAME_FAMILY_TREE);
|
||||
ValidateHelper.ValidateString(d, sysTableSchemas.ToArray());
|
||||
}
|
||||
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public FamilyTreeData Update(FamilyTreeData data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
FamilyTreeEntity d = repository.DetachedEntities.Where(x => x.TreeName == data.FamilyTree.TreeName).FirstOrDefault();
|
||||
if (d == null)
|
||||
{
|
||||
throw new ValidatedException("家族名称不存在.");
|
||||
}
|
||||
|
||||
Validate(data.FamilyTree);
|
||||
|
||||
ObjectCopyHelper.Copy(data.FamilyTree, d);
|
||||
|
||||
repository.UpdateNow(d);
|
||||
|
||||
var currentPerson = data.CurrentPerson != null ? data.CurrentPerson.FamilyPerson.PersonId : null;
|
||||
if (string.IsNullOrEmpty(currentPerson)) currentPerson = d.AncestorPersonId;
|
||||
|
||||
SaveSpouseMaps(data.CurrentPerson.FamilyPerson.PersonId, data.CurrentPerson.FamilyTreeSpouseMaps);
|
||||
//SaveParentMaps(data.CurrentPerson.FamilyPerson.PersonId, data.CurrentPerson.FamilyTreeParentMaps);
|
||||
SaveSonMaps(data.CurrentPerson.FamilyPerson.PersonId, data.CurrentPerson.FamilyTreeChildrenMaps);
|
||||
|
||||
return FindByCurrentPerson(data.FamilyTree.TreeId, currentPerson);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,8 +325,43 @@ namespace CloudBuilder.Master.Service
|
||||
[UnitOfWork]
|
||||
public void Delete(string key)
|
||||
{
|
||||
var ent= repository.DetachedEntities.Where(x => x.TreeId == key).FirstOrDefault()!;
|
||||
if (ent != null) { repository.DeleteNow(ent); }
|
||||
var ent = repository.DetachedEntities.Where(x => x.TreeId == key).FirstOrDefault()!;
|
||||
if (ent == null) return;
|
||||
repository.DeleteNow(ent);
|
||||
|
||||
DeleteSpouses(ent.AncestorPersonId);
|
||||
DeleteChildrens(ent.AncestorPersonId);
|
||||
}
|
||||
|
||||
private void DeleteSpouses(string personId)
|
||||
{
|
||||
IRepository<FamilyTreeSpouseMapEntity> repositoryMap = repository.GetRepository<IRepository<FamilyTreeSpouseMapEntity>>();
|
||||
|
||||
FamilyTreeSpouseMapEntity[] olds = repositoryMap.Entities.Where(x => x.PersonId == personId).ToArray();
|
||||
|
||||
if (olds != null && olds.Length > 0)
|
||||
{
|
||||
repositoryMap.DeleteNow(olds);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteChildrens(string personId)
|
||||
{
|
||||
IRepository<FamilyTreeChildrenMapEntity> repositoryMap = repository.GetRepository<IRepository<FamilyTreeChildrenMapEntity>>();
|
||||
|
||||
FamilyTreeChildrenMapEntity[] olds = repositoryMap.Entities.Where(x => x.PersonId == personId).ToArray();
|
||||
|
||||
if (olds != null && olds.Length > 0)
|
||||
{
|
||||
repositoryMap.DeleteNow(olds);
|
||||
}
|
||||
|
||||
foreach (FamilyTreeChildrenMapEntity old in olds)
|
||||
{
|
||||
DeleteChildrens(old.ChildrenId);
|
||||
|
||||
DeleteSpouses(old.ChildrenId);
|
||||
}
|
||||
}
|
||||
|
||||
[PermissionOperate(name: MasterPermissionPolicy.FamilyTree, operate: Operate.Delete)]
|
||||
|
||||
Reference in new issue
Block a user