You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
7.4 KiB

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.Models;
using Shentun.Peis.ReportFormats;
using Shentun.Peis.ReportFormatTemplates;
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.ReportPrinters
{
//[Authorize]
public class ReportPrinterAppService : ApplicationService
{
private readonly IRepository<ReportPrinter, string> _repository;
private readonly IRepository<IdentityUser, Guid> _userRepository;
private readonly ReportPrinterManager _manager;
public ReportPrinterAppService(
IRepository<ReportPrinter, string> repository,
IRepository<IdentityUser, Guid> userRepository,
ReportPrinterManager manager)
{
_repository = repository;
_userRepository = userRepository;
_manager = manager;
}
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("api/app/ReportPrinter/GetById")]
public async Task<ReportPrinterDto> GetByIdAsync(ReportPrinterIdDto input)
{
var entity = await _repository.GetAsync(input.Id);
var aEntity = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
var userList = await _userRepository.GetListAsync();
aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId);
aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId);
return aEntity;
}
[HttpPost("api/app/ReportPrinter/GetMaxId")]
public async Task<ReportPrinterDto> GetMaxIdAsync()
{
var ent = (await _repository.GetListAsync()).Max(x => x.Id);
var entdto = new ReportPrinterDto
{
Id = !string.IsNullOrEmpty(ent) ? ent : "0001"
};
return entdto;
}
[HttpPost("api/app/ReportPrinter/GetLocalPrinterByComputerName")]
public async Task<ReportPrinterDto> GetLocalPrinter(ComputerNameInputDto input)
{
var ent = (await _repository.GetListAsync()).Where(m => m.ReportId == input.ReportId && m.ComputerName.Equals(input.ComputerName)).FirstOrDefault();
if (ent != null)
{
var userList = await _userRepository.GetListAsync();
var dto = new ReportPrinterDto
{
CreationTime = ent.CreationTime,
CreatorId = ent.CreatorId,
ComputerName = ent.ComputerName,
Id = ent.Id,
ReportId = ent.ReportId,
LastModificationTime = ent.LastModificationTime,
LastModifierId = ent.LastModifierId,
PrinterName = ent.PrinterName,
CreatorName = EntityHelper.GetSurnameNoSql(userList, ent.CreatorId),
LastModifierName = EntityHelper.GetSurnameNoSql(userList, ent.LastModifierId)
};
return dto;
}
else
{
return null;
}
}
/// <summary>
/// 获取列表 项目
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportPrinter/GetList")]
public async Task<List<ReportPrinterDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{
var reportList = await _repository.GetListAsync();
List<ReportPrinterDto> formats = new List<ReportPrinterDto>();
foreach (var format in reportList)
{
var aEntity = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(format);
var userList = await _userRepository.GetListAsync();
aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, format.CreatorId);
aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, format.LastModifierId);
formats.Add(aEntity);
}
return formats;
}
[HttpPost("api/app/ReportPrinter/GetListByReportId")]
public async Task<PagedResultDto<ReportPrinterDto>> 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 ReportPrinterDto
{
CreationTime = s.CreationTime,
CreatorId = s.CreatorId,
ComputerName = s.ComputerName,
Id = s.Id,
ReportId = s.ReportId,
LastModificationTime = s.LastModificationTime,
LastModifierId = s.LastModifierId,
PrinterName = s.PrinterName,
CreatorName = EntityHelper.GetSurnameNoSql(userList, s.CreatorId),
LastModifierName = EntityHelper.GetSurnameNoSql(userList, s.LastModifierId)
}).ToList();
return new PagedResultDto<ReportPrinterDto>(totalCount, entdto);
}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportPrinter/Create")]
public async Task<ReportPrinterDto> CreateAsync(CreateReportPrinterDto input)
{
var createEntity = ObjectMapper.Map<CreateReportPrinterDto, ReportPrinter>(input);
var entity = await _manager.CreateAsync(createEntity);
entity = await _repository.InsertAsync(entity);
var dto = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
return dto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/ReportPrinter/Update")]
public async Task<ReportPrinterDto> UpdateAsync(string id, UpdateReportPrinterDto input)
{
var userList = await _userRepository.GetListAsync();
var entity = await _repository.GetAsync(id);
var sourceEntity = ObjectMapper.Map< UpdateReportPrinterDto, ReportPrinter>(input);
await _manager.UpdateAsync(sourceEntity, entity);
entity = await _repository.UpdateAsync(entity);
var dto= ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
dto.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId);
dto.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId);
return dto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("api/app/ReportPrinter/Delete")]
public Task DeleteAsync(ReportPrinterIdDto input)
{
return _repository.DeleteAsync(input.Id);
}
}
}