|
|
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<IdentityUser, Guid> _userRepository; private readonly IRepository<ReportFormat, string> _repository; private readonly ReportFormatManager _manager; public ReportFormatAppService( IRepository<ReportFormat, string> repository, IRepository<IdentityUser, Guid> userRepository, ReportFormatManager manager) { _repository = repository; _userRepository = userRepository; _manager = manager; }
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportFormat/GetById")] public async Task<ReportFormatDto> GeByIdtAsync(ReportFormatIdInputDto input) { var entity = await _repository.GetAsync(input.Id); var aEntity = ObjectMapper.Map<ReportFormat, ReportFormatDto>(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<ReportFormatDto> 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<ReportFormatDto> 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; } }
/// <summary>
/// 获取列表 项目
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportFormat/GetList")] public async Task<List<ReportFormatDto>> GetListAsync(PagedAndSortedResultRequestDto input) { var reportList = await _repository.GetListAsync();
List<ReportFormatDto> formats = new List<ReportFormatDto>();
foreach (var format in reportList) { var aEntity = ObjectMapper.Map<ReportFormat, ReportFormatDto>(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; }
/// <summary>
/// 获取列表 项目 可以带报表ID搜索
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportFormat/GetListByReportId")] public async Task<PagedResultDto<ReportFormatDto>> 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<ReportFormatDto>(totalCount, entdto);
}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportFormat/Create")] public async Task<ReportFormatDto> CreateAsync(CreateReportFormatDto input) { var createEntity = ObjectMapper.Map<CreateReportFormatDto, ReportFormat>(input); var entity = await _manager.CreateAsync(createEntity); entity = await _repository.InsertAsync(entity); var dto = ObjectMapper.Map<ReportFormat, ReportFormatDto>(entity); return dto; }
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportFormat/Update")] public async Task<ReportFormatDto> UpdateAsync(string id, UpdateReportFormatDto input) { var entity = await _repository.GetAsync(id); var userList = await _userRepository.GetListAsync(); var sourceEntity = ObjectMapper.Map<UpdateReportFormatDto, ReportFormat>(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await _repository.UpdateAsync(entity); var dto= ObjectMapper.Map<ReportFormat, ReportFormatDto>(entity); dto.IsDefaulted= entity.IsDefault.Equals('Y'); dto.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId); dto.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId); return dto; } /// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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); } }}
|