|
|
using AutoMapper.Internal.Mappers;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using NPOI.OpenXmlFormats.Dml;using Shentun.Peis.CustomerOrgRegisters;using Shentun.Peis.CustomerOrgs;using Shentun.Peis.HelperDto;using Shentun.Peis.Models;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Volo.Abp;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.CustomerOrgRegisters{
/// <summary>
/// 单位体检次数
/// </summary>
[ApiExplorerSettings(GroupName = "Work")] [Authorize] public class CustomerOrgRegisterAppService : CrudAppService< CustomerOrgRegister, //The Book entity
CustomerOrgRegisterDto, //Used to show books
Guid, //Primary key of the book entity
PagedAndSortedResultRequestDto, //Used for paging/sorting
CreateCustomerOrgRegisterDto, UpdateCustomerOrgRegisterDto> { private readonly IRepository<IdentityUser, Guid> _userRepository; private readonly IRepository<CustomerOrg, Guid> _customerOrgRepository; private readonly CustomerOrgManager _customerOrgManager; private readonly CustomerOrgRegisterManager _manager; public CustomerOrgRegisterAppService( IRepository<CustomerOrgRegister, Guid> repository, IRepository<IdentityUser, Guid> userRepository, IRepository<CustomerOrg, Guid> customerOrgRepository, CustomerOrgManager customerOrgManager, CustomerOrgRegisterManager manager) : base(repository) { _userRepository = userRepository; this._customerOrgRepository = customerOrgRepository; this._customerOrgManager = customerOrgManager; _manager = manager; } /// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<CustomerOrgRegisterDto> GetAsync(Guid id) { return await base.GetAsync(id); } /// <summary>
/// 获取列表 团检体检登记 遗弃
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<CustomerOrgRegisterDto>> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); }
/// <summary>
/// 获取列表 团检体检登记 带搜索计划名称
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PagedResultDto<CustomerOrgRegisterDto>> GetListInFilterAsync(GetListInFilterDto input) { int totalCount = 0;
if (!string.IsNullOrEmpty(input.Filter)) totalCount = (await Repository.GetListAsync()).Where(m => m.RegisterName.Contains(input.Filter)).Count(); else totalCount = await Repository.CountAsync();
var entlist = await Repository.GetListAsync();
if (!string.IsNullOrEmpty(input.Filter)) entlist = entlist.Where(m => m.RegisterName.Contains(input.Filter)).ToList();
//分页
entlist = entlist.OrderBy(m => m.CreationTime).Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToList();
var userList = await _userRepository.GetListAsync();
var entdto = entlist.Select(s => new CustomerOrgRegisterDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, Id = s.Id, LastModificationTime = s.LastModificationTime, LastModifierId = s.LastModifierId, //BeginTime = s.BeginTime.ToDateTime(TimeOnly.MinValue),
//EndTime = s.EndTime.GetValueOrDefault().ToDateTime(TimeOnly.MinValue),
BeginTime = s.BeginTime.ToString("yyyy/MM/dd"), EndTime = s.EndTime.GetValueOrDefault().ToDateTime(TimeOnly.MinValue).ToString("yyyy/MM/dd"), RegisterName = s.RegisterName, RegisterNo = s.RegisterNo, MedicalTimes = s.MedicalTimes, IsComplete = s.IsComplete, CustomerOrgId = s.CustomerOrgId, CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId), LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId) }).ToList();
return new PagedResultDto<CustomerOrgRegisterDto>(totalCount, entdto);
}
/// <summary>
/// 创建 只传单位ID
/// </summary>
/// <param name="CustomerOrgId">单位ID</param>
/// <returns></returns>
[HttpPost("api/customerorgregister/createcustomerorgregister")] public async Task<CustomerOrgRegisterDto> CreateCustomerOrgRegisterAsync(Guid CustomerOrgId) { var CustomerOrgParenId = EntityHelper.GetParentNoSql(await _customerOrgRepository.GetListAsync(), CustomerOrgId); //获取一级单位ID
var entity = await _manager.CreateAsync(CustomerOrgParenId); entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map<CustomerOrgRegister, CustomerOrgRegisterDto>(entity); return dto; }
/// <summary>
/// 更新 是否完成状态
/// </summary>
/// <param name="id"></param>
/// <param name="IsComplete">是否完成(Y N)</param>
/// <returns></returns>
public async Task<CustomerOrgRegisterDto> UpdateStateAsync(Guid id, char IsComplete) { var entity = await _manager.UpdateStateAsync(id, IsComplete); return ObjectMapper.Map<CustomerOrgRegister, CustomerOrgRegisterDto>(entity); }
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<CustomerOrgRegisterDto> UpdateAsync(Guid id, UpdateCustomerOrgRegisterDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map<UpdateCustomerOrgRegisterDto, CustomerOrgRegister>(input); _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); return ObjectMapper.Map<CustomerOrgRegister, CustomerOrgRegisterDto>(entity); } /// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task DeleteAsync(Guid id) { await _manager.CheckAndDeleteAsync(id); }
/// <summary>
/// 获取团检体检登记列表,根据单位ID过滤查询
/// </summary>
/// <param name="CustomerOrgId"></param>
/// <returns></returns>
[HttpGet("api/app/customerorgregister/getlistincustomerorgid")] public async Task<List<CustomerOrgRegisterDto>> GetListInCustomerOrgIdAsync(Guid CustomerOrgId) {
var entlist = await Repository.GetListAsync();
//if (CustomerOrgId != Guid.Empty)
entlist = entlist.Where(m => m.CustomerOrgId == CustomerOrgId).ToList();
var userList = await _userRepository.GetListAsync();
var entdto = entlist.Select(s => new CustomerOrgRegisterDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, Id = s.Id, LastModificationTime = s.LastModificationTime, LastModifierId = s.LastModifierId, //BeginTime = s.BeginTime.ToDateTime(TimeOnly.MinValue),
//EndTime = s.EndTime.GetValueOrDefault().ToDateTime(TimeOnly.MinValue),
BeginTime = s.BeginTime.ToString("yyyy/MM/dd"), EndTime = s.EndTime.GetValueOrDefault().ToDateTime(TimeOnly.MinValue).ToString("yyyy/MM/dd"), RegisterName = s.RegisterName, RegisterNo = s.RegisterNo, MedicalTimes = s.MedicalTimes, IsComplete = s.IsComplete, CustomerOrgId = s.CustomerOrgId, CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId), LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId) }).OrderBy(o => o.MedicalTimes).ToList();
return entdto;
}
}}
|