543 lines
25 KiB
C#
543 lines
25 KiB
C#
|
||
using CloudBuilder.Core.DatabaseAccessor;
|
||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||
using CloudBuilder.Core.Extensions;
|
||
using CloudBuilder.Core.Policy;
|
||
using CloudBuilder.Core.Service;
|
||
using CloudBuilder.Master.Data;
|
||
using CloudBuilder.Master.Entity;
|
||
using CloudBuilder.Master.Policy;
|
||
using CloudBuilder.Master.SearchCriteria;
|
||
using CloudBuilder.Security.Entity;
|
||
using CloudBuilder.Security.Policy;
|
||
using CloudBuilder.Security.Service;
|
||
using CloudBuilder.Security.Utility;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Http.HttpResults;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using System.Diagnostics;
|
||
namespace CloudBuilder.Master.Service
|
||
{
|
||
public class PublishPhotoService : IPublishPhotoService
|
||
{
|
||
private readonly IApplicationService service;
|
||
|
||
private IRepository<PublishPhotoEntity> repository;
|
||
public PublishPhotoService(IApplicationService service)
|
||
{
|
||
this.service = service;
|
||
repository = service.GetRepository<IRepository<PublishPhotoEntity>>();
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Find)]
|
||
public PublishPhotoData FindByKey(string key)
|
||
{
|
||
PublishPhotoData data = new PublishPhotoData();
|
||
if (string.IsNullOrEmpty(key)) return data;
|
||
|
||
PublishPhotoEntity publish = repository.DetachedEntities.Where(x => x.PublishName == key).FirstOrDefault();
|
||
|
||
if (publish == null) return data;
|
||
|
||
IRepository<PublishPhotoFamilyGroupEntity> repositoryPublishPhotoFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||
IRepository<FamilyGroupEntity> repositoryFamilyGroup = repository.GetRepository<IRepository<FamilyGroupEntity>>();
|
||
|
||
|
||
IQueryable<PublishPhotoFamilyGroupDisplayData>? q = from e in repositoryPublishPhotoFamilyGroup.DetachedEntities
|
||
join fg in repositoryFamilyGroup.DetachedEntities on e.FamilyName equals fg.FamilyName
|
||
where e.PublishName == key
|
||
select new PublishPhotoFamilyGroupDisplayData(fg)
|
||
{
|
||
CreatedBy = e.CreatedBy,
|
||
CreatedDatetime = e.CreatedDatetime,
|
||
UpdatedBy = e.UpdatedBy,
|
||
UpdatedDatetime = e.UpdatedDatetime,
|
||
PublishName = e.PublishName,
|
||
};
|
||
|
||
data.FamilyGroups = q.ToArray();
|
||
|
||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||
|
||
//归属与群组身份:所有者全权;群管理员可删/改信息;群成员仅可改明细
|
||
data.IsOwner = publish.OwnerName == service.UserId;
|
||
data.IsMember = data.IsOwner;
|
||
data.IsManager = data.IsOwner;
|
||
if (!data.IsOwner && data.FamilyGroups.Length > 0)
|
||
{
|
||
string[] familyNames = data.FamilyGroups.Select(x => x.FamilyName).ToArray();
|
||
FamilyGroupManagerEntity[] mine = repositoryFamilyGroupManager.DetachedEntities
|
||
.Where(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName))
|
||
.ToArray();
|
||
|
||
data.IsMember = mine.Length > 0;
|
||
data.IsManager = mine.Any(x => x.ManagerIndc == YesNoPolicy.YES);
|
||
}
|
||
|
||
if (!data.IsOwner && !YesNoPolicy.IsYes(publish.OpenIndc) && !data.IsMember)
|
||
{
|
||
throw new ValidatedException("没有权限.");
|
||
}
|
||
|
||
data.PublishPhoto = publish;
|
||
|
||
IRepository<PublishPhotoDetailEntity> repositoryPublishPhotoDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
|
||
data.Details = repositoryPublishPhotoDetail.DetachedEntities.Where(x => x.PublishName == publish.PublishName).OrderBy(x => x.OrderBy).Select(x => new PublishPhotoDetailDisplayData(x)).ToArray();
|
||
|
||
bool isAttached = Debugger.IsAttached;
|
||
if (data.Details != null || data.Details.Length > 0)
|
||
foreach (var item in data.Details)
|
||
{
|
||
item.FormattedPic = PackImageScareFileName(isAttached, item.FileName);
|
||
item.FileName = PackImageFileName(isAttached, item.FileName);
|
||
}
|
||
|
||
|
||
return data;
|
||
}
|
||
|
||
private string PackImageScareFileName(bool isAttached, string fileName)
|
||
{
|
||
var phy = service.Configuration[ServiceSettingsPolicy.PhysicalFileDirectory] ?? "";
|
||
var backup = (ServiceSettingsPolicy.GetDmsFileBackupDirectory(service) ?? "").Replace(phy ?? "", "");
|
||
var scale = (ServiceSettingsPolicy.GetDmsFileScaleDirectory(service) ?? "").Replace(phy ?? "", "");
|
||
|
||
return (isAttached ? service.Configuration[AppsettingsPolicy.ApplicationUrl] : "")
|
||
+ fileName?.Replace("\\", "/").Replace(backup.Replace("\\", "/"), scale.Replace("\\", "/"));
|
||
}
|
||
|
||
private string PackImageFileName(bool isAttached, string fileName)
|
||
{
|
||
return (isAttached ? service.Configuration[AppsettingsPolicy.ApplicationUrl] : "")
|
||
+ fileName?.Replace("\\", "/");
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Find)]
|
||
public PublishPhotoResultData FindBySearchCriteria(PublishPhotoSearchCriteria criteria)
|
||
{
|
||
PublishPhotoResultData data = new PublishPhotoResultData();
|
||
PublishPhotoEntity[] list = null;
|
||
|
||
Int64 count = 0;
|
||
|
||
string sqlWhere = null;
|
||
|
||
if (criteria.Filter != null && criteria.Filter.Length > 0)
|
||
{
|
||
sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter);
|
||
}
|
||
|
||
sqlWhere = sqlWhere + string.Format(" and ({0} ='{1}' or {2} ='{3}') ",
|
||
PublishPhotoEntity.DB_OWNER_NAME, service.UserId,
|
||
PublishPhotoEntity.DB_OPEN_INDC, criteria.IsModal ? service.UserId : YesNoPolicy.YES);
|
||
|
||
PublishPhotoEntity entity = PublishPhotoEntity.GetInstance(repository.GetDbContext().Database.ProviderName);
|
||
string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere);
|
||
|
||
string err = null;
|
||
try
|
||
{
|
||
list = repository.FromSql(sql).ToArray();
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
err = ex.Message;
|
||
}
|
||
|
||
|
||
if (list != null && list.Length > 0)
|
||
{
|
||
sql = entity.GetSelectCountFrom(sqlWhere);
|
||
count = Convert.ToInt64(repository.ExecuteScalar(sql));
|
||
}
|
||
|
||
data.Limit = criteria.limit;
|
||
data.Page = criteria.page;
|
||
data.Publishs = list;
|
||
data.Total = count;
|
||
//data.Sql = sql;
|
||
data.ErrorMessage = err;
|
||
return data;
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Print)]
|
||
public dynamic PrintBySearchCriteria(PublishPhotoSearchCriteria criteria)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Insert)]
|
||
[UnitOfWork]
|
||
public PublishPhotoData Insert(PublishPhotoData data)
|
||
{
|
||
PublishPhotoEntity publishPhoto = repository.DetachedEntities.Where(x => x.PublishLocalName == data.PublishPhoto.PublishLocalName).FirstOrDefault();
|
||
if (publishPhoto != null)
|
||
{
|
||
throw new ValidatedException($"[{publishPhoto.PublishLocalName}]已发布.");
|
||
}
|
||
|
||
Validate(data.PublishPhoto);
|
||
|
||
if (data.PublishPhoto.DefaultIndc == YesNoPolicy.YES)
|
||
{
|
||
CancelDefaultIndc(null);
|
||
}
|
||
|
||
publishPhoto = new PublishPhotoEntity();
|
||
ObjectCopyHelper.Copy(data.PublishPhoto, publishPhoto);
|
||
|
||
ISecurityGeneratorNumberService securityGeneratorNumberService = service.ServiceProvider.GetService<ISecurityGeneratorNumberService>()!;
|
||
|
||
publishPhoto.PublishName = securityGeneratorNumberService.GetNo(MasterPrefixPolicy.PHOTO_PUBLISH, MasterPrefixPolicy.PHOTO_PUBLISH_PUBLISH_NAME, "PP", YesNoPolicy.YES, "yymmdd00000");
|
||
publishPhoto.OwnerName = service.UserId;
|
||
|
||
repository.InsertNow(publishPhoto);
|
||
|
||
SavePublishPhotoFamilyGroup(publishPhoto.PublishName, data.FamilyGroups);
|
||
|
||
return FindByKey(publishPhoto.PublishName);
|
||
}
|
||
|
||
public void CancelDefaultIndc(string publishLocalName)
|
||
{
|
||
PublishPhotoEntity[] orgs = repository.DetachedEntities.Where(x => x.PublishName != publishLocalName && x.OwnerName == service.UserId && x.DefaultIndc == YesNoPolicy.YES).ToArray();
|
||
foreach (PublishPhotoEntity org in orgs)
|
||
{
|
||
org.DefaultIndc = YesNoPolicy.NO;
|
||
}
|
||
|
||
if (orgs != null && orgs.Length > 0)
|
||
repository.UpdateNow(orgs);
|
||
}
|
||
|
||
private void Validate(PublishPhotoEntity publishPhoto)
|
||
{
|
||
List<SysTableSchemaViewEntity> sysTableSchemas = service.ServiceProvider.GetRequiredService<ISysTableSchemaViewService>().FindByTableName(PublishPhotoEntity.DB_NAME_PUBLISH_PHOTO);
|
||
ValidateHelper.ValidateString(publishPhoto, sysTableSchemas.ToArray());
|
||
}
|
||
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Update)]
|
||
[UnitOfWork]
|
||
public PublishPhotoData Update(PublishPhotoData data)
|
||
{
|
||
//归属校验:所有者可全改;公开群组管理员可改信息/群组;普通群成员只能改明细
|
||
PublishPhotoEntity original = repository.DetachedEntities.Where(x => x.PublishName == data.PublishPhoto.PublishName).FirstOrDefault();
|
||
if (original == null)
|
||
{
|
||
throw new ValidatedException("记录不存在.");
|
||
}
|
||
|
||
bool isOwner = original.OwnerName == service.UserId;
|
||
bool isManager = false;
|
||
bool isMember = false;
|
||
if (!isOwner)
|
||
{
|
||
IRepository<PublishPhotoFamilyGroupEntity> repositoryPublishPhotoFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||
|
||
string[] familyNames = repositoryPublishPhotoFamilyGroup.DetachedEntities
|
||
.Where(x => x.PublishName == original.PublishName)
|
||
.Select(x => x.FamilyName)
|
||
.ToArray();
|
||
if (familyNames.Length == 0)
|
||
{
|
||
throw new ValidatedException("没有权限.");
|
||
}
|
||
|
||
FamilyGroupManagerEntity[] mine = repositoryFamilyGroupManager.DetachedEntities
|
||
.Where(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName))
|
||
.ToArray();
|
||
isMember = mine.Length > 0;
|
||
isManager = mine.Any(x => x.ManagerIndc == YesNoPolicy.YES);
|
||
if (!isMember)
|
||
{
|
||
throw new ValidatedException("没有权限.");
|
||
}
|
||
}
|
||
|
||
//非所有者保留归属与建单信息,防客户端伪造
|
||
data.PublishPhoto.OwnerName = original.OwnerName;
|
||
data.PublishPhoto.CreatedBy = original.CreatedBy;
|
||
data.PublishPhoto.CreatedDatetime = original.CreatedDatetime;
|
||
if (!isOwner && !isManager)
|
||
{
|
||
//非所有者且非管理员(普通群成员)只能改明细:专辑展示字段一律以库中为准
|
||
data.PublishPhoto.PublishLocalName = original.PublishLocalName;
|
||
data.PublishPhoto.Notice = original.Notice;
|
||
data.PublishPhoto.OpenIndc = original.OpenIndc;
|
||
data.PublishPhoto.ExpireDatetime = original.ExpireDatetime;
|
||
data.PublishPhoto.OrderBy = original.OrderBy;
|
||
}
|
||
if (!isOwner)
|
||
{
|
||
//默认专辑是所有者个人偏好,群管理员也不能改
|
||
data.PublishPhoto.DefaultIndc = original.DefaultIndc;
|
||
}
|
||
|
||
ValidateHelper.Validate(service, data.PublishPhoto, PublishPhotoEntity.DB_NAME_PUBLISH_PHOTO);
|
||
|
||
if (isOwner && data.PublishPhoto.DefaultIndc == YesNoPolicy.YES)
|
||
{
|
||
CancelDefaultIndc(data.PublishPhoto.PublishName);
|
||
}
|
||
|
||
PublishPhotoEntity publishEntity = new PublishPhotoEntity();
|
||
ObjectCopyHelper.Copy(data.PublishPhoto, publishEntity);
|
||
|
||
repository.UpdateNow(publishEntity);
|
||
|
||
//只有删除和更新,没有插入
|
||
SavePublishPhotoDetails(publishEntity.PublishName, data.Details);
|
||
|
||
//群组增删只对所有者/群管理员开放;普通成员提交的 FamilyGroups 不落库
|
||
if (isOwner || isManager)
|
||
{
|
||
SavePublishPhotoFamilyGroup(publishEntity.PublishName, data.FamilyGroups);
|
||
}
|
||
|
||
return FindByKey(publishEntity.PublishName);
|
||
}
|
||
|
||
/// <summary>当前登录人是否为该相册任一公开群组的管理员(正式成员且 ManagerIndc=Y)</summary>
|
||
private bool IsGroupManagerOfPublish(string publishName)
|
||
{
|
||
IRepository<PublishPhotoFamilyGroupEntity> repositoryFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||
|
||
string[] familyNames = repositoryFamilyGroup.DetachedEntities
|
||
.Where(x => x.PublishName == publishName)
|
||
.Select(x => x.FamilyName)
|
||
.ToArray();
|
||
if (familyNames.Length == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
return repositoryFamilyGroupManager.DetachedEntities
|
||
.Any(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && x.ManagerIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName));
|
||
}
|
||
|
||
private void SavePublishPhotoFamilyGroup(string publishName, PublishPhotoFamilyGroupEntity[] familyGroups)
|
||
{
|
||
IRepository<PublishPhotoFamilyGroupEntity> repositoryPublishPhotoFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||
|
||
PublishPhotoFamilyGroupEntity[] olds = repositoryPublishPhotoFamilyGroup.Entities.Where(x => x.PublishName == publishName).ToArray();
|
||
if (olds != null && olds.Length > 0)
|
||
{
|
||
//存在更新,不存在删除
|
||
|
||
foreach (PublishPhotoFamilyGroupEntity old in olds)
|
||
{
|
||
if (familyGroups != null && familyGroups.Length > 0 && familyGroups.Where(x => x.FamilyName == old.FamilyName).Count() > 0)
|
||
{
|
||
//只有主键,无需更新
|
||
//repositoryPpf.UpdateNow(old);
|
||
}
|
||
else
|
||
{
|
||
repositoryPublishPhotoFamilyGroup.DeleteNow(old);
|
||
}
|
||
}
|
||
}
|
||
if (familyGroups != null && familyGroups.Length > 0)
|
||
foreach (PublishPhotoFamilyGroupEntity dto in familyGroups)
|
||
{
|
||
if (string.IsNullOrEmpty(dto.CreatedBy))
|
||
repositoryPublishPhotoFamilyGroup.InsertNow(new PublishPhotoFamilyGroupEntity()
|
||
{
|
||
PublishName = publishName,
|
||
FamilyName = dto.FamilyName,
|
||
});
|
||
}
|
||
}
|
||
|
||
private void SavePublishPhotoDetails(string publishName, PublishPhotoDetailEntity[] details)
|
||
{
|
||
if (details != null && details.Length > 0)
|
||
{
|
||
int i = 1;
|
||
foreach (PublishPhotoDetailEntity dtl in details)
|
||
{
|
||
dtl.OrderBy = i++;
|
||
}
|
||
}
|
||
|
||
IRepository<PublishPhotoDetailEntity> repositoryPublishPhotoDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
|
||
PublishPhotoDetailEntity[] olds = repositoryPublishPhotoDetail.Entities.Where(x => x.PublishName == publishName).ToArray();
|
||
if (olds != null && olds.Length > 0)
|
||
{
|
||
//存在更新,不存在删除
|
||
|
||
foreach (PublishPhotoDetailEntity old in olds)
|
||
{
|
||
if (details != null && details.Length > 0 && details.Where(x => x.DetailId == old.DetailId).Count() > 0)
|
||
{
|
||
PublishPhotoDetailEntity dtl = details.Where(x => x.DetailId == old.DetailId).FirstOrDefault();
|
||
|
||
old.OrderBy = dtl.OrderBy;
|
||
old.Notice = dtl.Notice;
|
||
|
||
repositoryPublishPhotoDetail.UpdateNow(old);
|
||
}
|
||
else
|
||
{
|
||
repositoryPublishPhotoDetail.DeleteNow(old);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishPhoto, operate: Operate.Delete)]
|
||
[UnitOfWork]
|
||
public void Delete(string key)
|
||
{
|
||
PublishPhotoEntity publishEntity = repository.DetachedEntities.Where(x => x.PublishName == key).FirstOrDefault();
|
||
if (publishEntity == null)
|
||
{
|
||
throw new ValidatedException("记录不存在.");
|
||
}
|
||
//删除相册:所有者或该相册任一公开群组的管理员
|
||
if (publishEntity.OwnerName != service.UserId && !IsGroupManagerOfPublish(key))
|
||
{
|
||
throw new ValidatedException("没有权限.");
|
||
}
|
||
|
||
repository.DeleteNow(publishEntity);
|
||
|
||
IRepository<PublishPhotoDetailEntity> repositoryDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
|
||
PublishPhotoDetailEntity[] detail = repositoryDetail.Entities.Where(x => x.PublishName == key).ToArray();
|
||
if (detail != null && detail.Length > 0)
|
||
{
|
||
foreach (PublishPhotoDetailEntity dtl in detail)
|
||
{
|
||
repositoryDetail.DeleteNow(dtl);
|
||
}
|
||
}
|
||
|
||
IRepository<PublishPhotoFamilyGroupEntity> repositoryFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||
|
||
PublishPhotoFamilyGroupEntity[] groups = repositoryFamilyGroup.Entities.Where(x => x.PublishName == key).ToArray();
|
||
if (groups != null && groups.Length > 0)
|
||
{
|
||
foreach (PublishPhotoFamilyGroupEntity gp in groups)
|
||
{
|
||
repositoryFamilyGroup.DeleteNow(gp);
|
||
}
|
||
}
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public PublishPhotoDetailDisplayData[] FindPublishPhotoDetailByPublishName(string publishName)
|
||
{
|
||
List<PublishPhotoDetailDisplayData> publishPhotoDetails = new List<PublishPhotoDetailDisplayData>();
|
||
if (string.IsNullOrEmpty(publishName)) return publishPhotoDetails.ToArray();
|
||
|
||
IRepository<PublishPhotoEntity> repositoryPublishPhoto = repository.GetRepository<IRepository<PublishPhotoEntity>>();
|
||
PublishPhotoEntity publishPhoto = repositoryPublishPhoto.DetachedEntities.Where(x => x.OwnerName == service.UserId && x.PublishName == publishName).FirstOrDefault();
|
||
|
||
if (publishPhoto == null)
|
||
return publishPhotoDetails.ToArray();
|
||
|
||
IRepository<PublishPhotoDetailEntity> repositoryPublishPhotoDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
PublishPhotoDetailDisplayData[] dtls = repositoryPublishPhotoDetail.DetachedEntities.Where(x => x.PublishName == publishName).OrderBy(x => x.OrderBy).Select(x => new PublishPhotoDetailDisplayData(x)).ToArray();
|
||
|
||
if (dtls == null || dtls.Length == 0) return publishPhotoDetails.ToArray();
|
||
|
||
bool isAttached = Debugger.IsAttached;
|
||
foreach (var item in dtls)
|
||
{
|
||
if (item.FileName.ToLower().StartsWith("http")) continue;
|
||
item.FormattedPic = PackImageScareFileName(isAttached, item.FileName);
|
||
item.FileName = PackImageFileName(isAttached, item.FileName);
|
||
}
|
||
|
||
return dtls;
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public PublishPhotoDetailDisplayData[] FindPublishPhotoDetail()
|
||
{
|
||
PublishPhotoEntity publishPhoto = repository.DetachedEntities.Where(x => x.OwnerName == service.UserId && x.DefaultIndc == YesNoPolicy.YES).FirstOrDefault();
|
||
List<PublishPhotoDetailDisplayData> publishPhotoDetails = new List<PublishPhotoDetailDisplayData>();
|
||
if (publishPhoto == null)
|
||
return publishPhotoDetails.ToArray();
|
||
|
||
IRepository<PublishPhotoDetailEntity> repositoryPublishPhotoDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
|
||
PublishPhotoDetailDisplayData[] dtls = repositoryPublishPhotoDetail.DetachedEntities.Where(x => x.PublishName == publishPhoto.PublishName).OrderBy(x => x.OrderBy).Select(x => new PublishPhotoDetailDisplayData(x)).ToArray();
|
||
|
||
if (dtls == null || dtls.Length == 0) return dtls;
|
||
|
||
bool isAttached = Debugger.IsAttached;
|
||
foreach (var item in dtls)
|
||
{
|
||
if (item.FileName.ToLower().StartsWith("http")) continue;
|
||
|
||
item.FormattedPic = PackImageScareFileName(isAttached, item.FileName);
|
||
item.FileName = (isAttached ? service.Configuration[AppsettingsPolicy.ApplicationUrl] : "") + item.FileName;
|
||
}
|
||
|
||
return dtls;
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishAudio, operate: Operate.Insert)]
|
||
public void InsertPublishPhotoDetail(PublishData publishData)
|
||
{
|
||
IRepository<DmsFileEntity> repositoryDmsFile = repository.GetRepository<IRepository<DmsFileEntity>>();
|
||
DmsFileEntity dmsFile = repositoryDmsFile.DetachedEntities.Where(x => x.FileId == publishData.FileId).FirstOrDefault();
|
||
|
||
if (dmsFile == null) return;
|
||
if (!FileTypePolicy.IsPhoto(dmsFile.OrderKey)) return;
|
||
|
||
InsertPublishPhotoDetail(dmsFile, publishData.PublishName);
|
||
}
|
||
|
||
[PermissionOperate(name: MasterPermissionPolicy.PublishAudio, operate: Operate.Insert)]
|
||
public void InsertPublishPhotoDetailByFamilyGroup(PublishData publishData)
|
||
{
|
||
IRepository<FamilyDmsFileViewEntity> repositoryDmsFile = repository.GetRepository<IRepository<FamilyDmsFileViewEntity>>();
|
||
FamilyDmsFileViewEntity dmsFile = repositoryDmsFile.DetachedEntities.Where(x => x.FileId == publishData.FileId).FirstOrDefault();
|
||
|
||
if (dmsFile == null) return;
|
||
if (!(dmsFile.OrderKey.ToLower().Contains(".jpg") || dmsFile.OrderKey.ToLower().Contains(".png") ||
|
||
dmsFile.OrderKey.ToLower().Contains(".gif") || dmsFile.OrderKey.ToLower().Contains(".jpeg"))) return;
|
||
|
||
DmsFileEntity dmsFileEntity = new DmsFileEntity();
|
||
ObjectCopyHelper.Copy(dmsFile, dmsFileEntity);
|
||
InsertPublishPhotoDetail(dmsFileEntity, publishData.PublishName);
|
||
}
|
||
|
||
private void InsertPublishPhotoDetail(DmsFileEntity dmsFile, string publishName)
|
||
{
|
||
IRepository<PublishPhotoDetailEntity> repositoryPublishPhotoDetail = repository.GetRepository<IRepository<PublishPhotoDetailEntity>>();
|
||
|
||
var webRootPath = service.Configuration[ServiceSettingsPolicy.RequestPath];
|
||
var phy = service.Configuration[ServiceSettingsPolicy.PhysicalFileDirectory];
|
||
var backup = ServiceSettingsPolicy.GetDmsFileBackupDirectory(service).Replace(phy, "").Substring(1);
|
||
|
||
var fileExtension = Path.GetExtension(dmsFile.OrderKey);
|
||
var filePathRel = Path.Combine(webRootPath.Substring(1), backup, dmsFile.CreatedBy, fileExtension.Replace(".", ""), "");
|
||
var filePath = '/' + filePathRel.Replace(Path.DirectorySeparatorChar, '/');
|
||
string path = Path.Combine(filePath, dmsFile.OrderKey);
|
||
|
||
|
||
PublishPhotoDetailEntity[] dtls = repositoryPublishPhotoDetail.DetachedEntities.Where(x => x.PublishName == publishName).ToArray();
|
||
|
||
if (dtls != null && dtls.Where(x => x.FileName == path).Count() > 0) return;
|
||
|
||
PublishPhotoDetailEntity dtl = new PublishPhotoDetailEntity();
|
||
dtl.PublishName = publishName;
|
||
dtl.OwnerName = dmsFile.OwerId;
|
||
if (dtls != null && dtls.Length > 0)
|
||
dtl.OrderBy = dtls.Sum(x => x.OrderBy) + 1;
|
||
dtl.FileName = path;
|
||
|
||
repositoryPublishPhotoDetail.InsertNow(dtl);
|
||
}
|
||
}
|
||
}
|