using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.Models; using Shentun.Peis.ReportPrinters; using Shentun.Peis.Reports; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Volo.Abp.ObjectMapping; namespace Shentun.Peis.ReportFormats { //[Authorize] public class ReportFormatAppService : ApplicationService { private readonly IRepository _userRepository; private readonly IRepository _repository; private readonly ReportFormatManager _manager; public ReportFormatAppService( IRepository repository, IRepository userRepository, ReportFormatManager manager) { _repository = repository; _userRepository = userRepository; _manager = manager; } /// /// 获取通过主键 /// /// /// [HttpPost("api/app/ReportFormat/GetById")] public async Task GeByIdtAsync(ReportFormatIdInputDto input) { var entity = await _repository.GetAsync(input.Id); var aEntity = ObjectMapper.Map(entity); var userList = await _userRepository.GetListAsync(); aEntity.IsDefaulted = entity.IsDefault.Equals('Y'); aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId); aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId); return aEntity; } [HttpPost("api/app/ReportFormat/GetMaxId")] public async Task GetMaxByIdAsync() { var ent = (await _repository.GetListAsync()).Max(x => x.Id); var entdto = new ReportFormatDto { Id = !string.IsNullOrEmpty(ent) ? ent : "0001" }; return entdto; } [HttpPost("api/app/ReportFormat/GetDefault")] public async Task GetDefaultAsync(string reportId) { var ent = await _manager.GetDefaultAsync(reportId); if (ent!=null) { var userList = await _userRepository.GetListAsync(); var entdto = new ReportFormatDto { CreationTime = ent.CreationTime, CreatorId = ent.CreatorId, DisplayName = ent.DisplayName, Id = ent.Id, ReportId = ent.ReportId, LastModificationTime = ent.LastModificationTime, LastModifierId = ent.LastModifierId, IsDefault = ent.IsDefault, IsDefaulted = ent.IsDefault.Equals('Y'), CreatorName = EntityHelper.GetSurnameNoSql(userList, ent.CreatorId), LastModifierName = EntityHelper.GetSurnameNoSql(userList, ent.LastModifierId) }; return entdto; } else { return null; } } /// /// 获取列表 项目 /// /// /// [HttpPost("api/app/ReportFormat/GetList")] public async Task> GetListAsync(PagedAndSortedResultRequestDto input) { var reportList = await _repository.GetListAsync(); List formats = new List(); foreach (var format in reportList) { var aEntity = ObjectMapper.Map(format); var userList = await _userRepository.GetListAsync(); aEntity.IsDefaulted = format.IsDefault.Equals('Y'); aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, format.CreatorId); aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, format.LastModifierId); formats.Add(aEntity); } return formats; } /// /// 获取列表 项目 可以带报表ID搜索 /// /// /// [HttpPost("api/app/ReportFormat/GetListByReportId")] public async Task> GetListByReportIdAsync(ReportIdInputDto input) { int totalCount = 0; var entlist = (await _repository.GetListAsync()).Where(m => m.ReportId == input.Id); totalCount = entlist.Count(); var userList = await _userRepository.GetListAsync(); var entdto = entlist.Select(s => new ReportFormatDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, DisplayName = s.DisplayName, Id = s.Id, ReportId=s.ReportId, LastModificationTime = s.LastModificationTime, LastModifierId = s.LastModifierId, IsDefault = s.IsDefault, IsDefaulted=s.IsDefault.Equals('Y'), CreatorName = EntityHelper.GetSurnameNoSql(userList, s.CreatorId), LastModifierName = EntityHelper.GetSurnameNoSql(userList, s.LastModifierId) }).ToList(); return new PagedResultDto(totalCount, entdto); } /// /// 创建 /// /// /// [HttpPost("api/app/ReportFormat/Create")] public async Task CreateAsync(CreateReportFormatDto input) { var createEntity = ObjectMapper.Map(input); var entity = await _manager.CreateAsync(createEntity); entity = await _repository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); return dto; } /// /// 更新 /// /// /// /// [HttpPost("api/app/ReportFormat/Update")] public async Task UpdateAsync(string id, UpdateReportFormatDto input) { var entity = await _repository.GetAsync(id); var userList = await _userRepository.GetListAsync(); var sourceEntity = ObjectMapper.Map(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await _repository.UpdateAsync(entity); var dto= ObjectMapper.Map(entity); dto.IsDefaulted= entity.IsDefault.Equals('Y'); dto.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId); dto.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId); return dto; } /// /// 删除 /// /// /// [HttpPost("api/app/ReportFormat/Delete")] public Task DeleteAsync(ReportFormatIdInputDto input) { return _repository.DeleteAsync(input.Id); } [HttpPut("api/app/ReportFormat/UpdateDefault")] public async Task UpdateDefaultAsync(ReportFormatIdInputDto input) { await _manager.UpdateDefaultAsync(input.Id); } } }