1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Bowin.Common.Linq.Entity;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Z.EntityFramework.Plus;
- using System.Linq.Expressions;
- using System.Linq.Dynamic.Core;
- namespace YLShipBuildLandMap.Services.Common
- {
- public class FileService : IFileService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public FileService(YLShipBuildLandMapContext dbContext)
- {
- this.DbContext = dbContext;
- }
- public Task<int> AddFile(List<SysAttachment> fileList)
- {
- foreach (var file in fileList)
- {
- DbContext.SysAttachment.Add(file);
- }
- return DbContext.SaveChangesAsync();
- }
- private IQueryable<AttachmentView> GetFileQuery(Expression<Func<SysAttachment, bool>> exp, int? fileType)
- {
- var sql = from f in DbContext.SysAttachment.Where(exp).WhereIf(fileType.HasValue, f => f.Type == fileType)
- join disFileType in DbContext.SysDictionaryItem.Where(dis => dis.DictionaryCode == "FileType") on f.Type equals disFileType.Value into dbFileType
- from disFileType in dbFileType.DefaultIfEmpty()
- select new AttachmentView
- {
- AttachmentId = f.AttachmentId,
- Name = f.Name,
- Suffix = f.Suffix,
- Url = f.Url,
- ReferenceId = f.ReferenceId,
- Type = f.Type,
- FileTypeName = disFileType.Name,
- CreateTime = f.CreateTime,
- CreateUserId = f.CreateUserId
- };
- return sql;
- }
- public Task<IGridResultSet<AttachmentView>> GetFileList(int pageIndex, int pageSize, Guid fileRefId, int? fileType)
- {
- var list = GetFileQuery(x => x.ReferenceId == fileRefId, fileType);
- //var list = from f in DbContext.SysAttachment.Where(f => f.ReferenceId == fileRefId).WhereIf(fileType.HasValue, f => f.Type == fileType)
- // join disFileType in DbContext.SysDictionaryItem.Where(dis => dis.DictionaryCode == "FileType") on f.Type equals disFileType.Value into dbFileType
- // from disFileType in dbFileType.DefaultIfEmpty()
- // select new AttachmentView
- // {
- // AttachmentId = f.AttachmentId,
- // Name = f.Name,
- // Suffix = f.Suffix,
- // Url = f.Url,
- // ReferenceId = f.ReferenceId,
- // Type = f.Type,
- // FileTypeName = disFileType.Name,
- // CreateTime = f.CreateTime,
- // CreateUserId = f.CreateUserId
- // };
- return Task.FromResult(list.OrderBy(f => f.CreateTime).ToGridResultSet(pageIndex, pageSize));
- }
- public Task<IGridResultSet<AttachmentView>> GetFileList(int pageIndex, int pageSize, int? fileType, List<Guid> ids)
- {
- var list = GetFileQuery(x => ids.Contains(x.ReferenceId.Value), fileType);
- return Task.FromResult(list.OrderBy(f => f.CreateTime).ToGridResultSet(pageIndex, pageSize));
- }
- public Task<SysAttachment> GetFileById(Guid fileId)
- {
- return Task.FromResult(DbContext.SysAttachment.Where(f => f.AttachmentId == fileId).FirstOrDefault());
- }
- public Task<int> DeleteFileById(Guid fileId)
- {
- return Task.FromResult(DbContext.SysAttachment.Where(f => f.AttachmentId == fileId).Delete());
- }
- public Task<int> DelfileByRefID(Guid noDeleteFileId, Guid fileRefId, int? fileType)
- {
- return Task.FromResult(DbContext.SysAttachment.Where(f => f.ReferenceId == fileRefId && f.Type == fileType && f.AttachmentId != noDeleteFileId).Delete());
- }
- }
- }
|