| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using Abp.Application.Services.Dto;
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Runtime.Caching;
- using WePlatform.BaseInfo;
- using WePlatform.BaseSystem.AttachFile.Dto;
- using WePlatform.CommonManager.AttachFiles;
- using IwbZero.AppServiceBase;
- using WePlatform.Configuration;
- namespace WePlatform.BaseSystem.AttachFile
- {
- [AbpAuthorize]
- public class AttachFilesAppService : IwbAsyncCrudAppService<SysAttachFile, AttachFileDto, int, IwbPagedRequestDto>
- , IAttachFilesAppService
- {
- public AttachFilesAppService(
- ICacheManager cacheManager,
- IRepository<SysAttachFile, int> repository) : base(repository, "AttachNo")
- {
- CacheManager = cacheManager;
- }
- protected override bool KeyIsAuto { get; set; } = true;
- #region GetSelect
- [DisableAuditing]
- public override async Task<List<SelectListItem>> GetSelectList()
- {
- var list = await Repository.GetAllListAsync();
- var sList = new List<SelectListItem> { new SelectListItem { Text = @"请选择...", Value = "", Selected = true } };
- foreach (var l in list)
- {
- sList.Add(new SelectListItem { Text = l.AttachNo, Value = l.FileTitle });
- }
- return sList;
- }
- [DisableAuditing]
- public override async Task<string> GetSelectStr()
- {
- var list = await Repository.GetAllListAsync();
- string str = "<option value=\"\" selected>请选择...</option>";
- foreach (var l in list)
- {
- str += $"<option value=\"{l.AttachNo}\">{l.FileTitle}</option>";
- }
- return str;
- }
- [DisableAuditing]
- public async Task<List<SelectListItem>> GetTableSelectList(string tableName, string colName)
- {
- var list = await Repository.GetAllListAsync(a => a.TableName == tableName && a.ColumnName == colName);
- var sList = new List<SelectListItem> { new SelectListItem { Text = @"请选择...", Value = "", Selected = true } };
- foreach (var l in list)
- {
- sList.Add(new SelectListItem { Text = l.AttachNo, Value = l.FileTitle });
- }
- return sList;
- }
- [DisableAuditing]
- public async Task<string> GetTableSelectStr(string tableName, string colName)
- {
- var list = await Repository.GetAllListAsync(a => a.TableName == tableName && a.ColumnName == colName);
- string str = "<option value=\"\" selected>请选择...</option>";
- foreach (var l in list)
- {
- str += $"<option value=\"{l.AttachNo}\">{l.FileTitle}</option>";
- }
- return str;
- }
- #endregion
- #region CURD
- /// <summary>
- /// 上传附件
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [DisableAuditing]
- public Task FileUpload(AttachFileCreateDto input)
- {
- return AttachFileManager.FileUpload(input);
- }
- /// <summary>
- /// 查询附件
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<List<AttachFileDto>> QueryAttaches(QueryAttachDto input)
- {
- var entities = await Repository.GetAllListAsync(a =>
- a.TableName == input.TableName && a.ColumnName == input.ColName && a.SourceKey == input.Key);
- return entities.Select(MapToEntityDto).ToList();
- }
- /// <summary>
- /// 查询附件
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<AttachFileDto> QueryAttach(QueryAttachDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a =>
- a.TableName == input.TableName && a.ColumnName == input.ColName && a.SourceKey == input.Key);
- return MapToEntityDto(entity);
- }
- [DisableAuditing]
- public override async Task<PagedResultDto<AttachFileDto>> GetAll(IwbPagedRequestDto input)
- {
- CheckGetAllPermission();
- var query = CreateFilteredQuery(input);
- query = ApplyFilter(query, input);
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = ApplySorting(query, input);
- query = ApplyPaging(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtos = new PagedResultDto<AttachFileDto>(
- totalCount,
- entities.Select(MapToEntityDto).ToList()
- );
- return dtos;
- }
- #endregion
- }
- }
|