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.
176 lines
6.1 KiB
176 lines
6.1 KiB
using AutoMapper.Internal.Mappers;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shentun.Peis.ItemTemplates;
|
|
using Shentun.Peis.GuidTypes;
|
|
using Shentun.Peis.HelperDto;
|
|
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 Shentun.Peis.Models;
|
|
using Shentun.Peis.Asbitems;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace Shentun.Peis.ItemTemplates
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// 项目模板
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class ItemTemplateAppService : CrudAppService<
|
|
ItemTemplate, //The Book entity
|
|
ItemTemplateDto, //Used to show books
|
|
Guid, //Primary key of the book entity
|
|
PagedAndSortedResultRequestDto, //Used for paging/sorting
|
|
CreateItemTemplateDto,
|
|
UpdateItemTemplateDto>
|
|
{
|
|
private readonly IRepository<IdentityUser, Guid> _userRepository;
|
|
private readonly ItemTemplateManager _manager;
|
|
public ItemTemplateAppService(
|
|
IRepository<ItemTemplate, Guid> repository,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
ItemTemplateManager manager)
|
|
: base(repository)
|
|
{
|
|
this._userRepository = userRepository;
|
|
_manager = manager;
|
|
}
|
|
/// <summary>
|
|
/// 获取通过主键
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ItemTemplateDto> GetAsync(Guid id)
|
|
{
|
|
var userList = await _userRepository.GetListAsync();
|
|
var entityDto = await base.GetAsync(id);
|
|
entityDto.CreatorName = EntityHelper.GetUserNameNoSql(userList, entityDto.CreatorId);
|
|
entityDto.LastModifierName = EntityHelper.GetUserNameNoSql(userList, entityDto.LastModifierId);
|
|
|
|
return entityDto;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取列表 项目模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public override async Task<PagedResultDto<ItemTemplateDto>> GetListAsync(PagedAndSortedResultRequestDto input)
|
|
{
|
|
return await base.GetListAsync(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表 项目模板 带搜索
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagedResultDto<ItemTemplateDto>> GetListInFilterAsync(GetListInFilterDto input)
|
|
{
|
|
int totalCount = 0;
|
|
|
|
if (!string.IsNullOrEmpty(input.Filter))
|
|
totalCount = (await Repository.GetListAsync()).Where(m => m.DisplayName.Contains(input.Filter)).Count();
|
|
else
|
|
totalCount = await Repository.CountAsync();
|
|
|
|
|
|
var entlist = await PageHelper.GetPageListInFitler(Repository, _userRepository, input);
|
|
var userList = await _userRepository.GetListAsync();
|
|
var entdto = entlist.Select(s => new ItemTemplateDto
|
|
{
|
|
CreationTime = s.CreationTime,
|
|
CreatorId = s.CreatorId,
|
|
DisplayName = s.DisplayName,
|
|
DisplayOrder = s.DisplayOrder,
|
|
Id = s.Id,
|
|
LastModificationTime = s.LastModificationTime,
|
|
LastModifierId = s.LastModifierId,
|
|
SimpleCode = s.SimpleCode,
|
|
CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
|
|
LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
|
|
}).ToList();
|
|
|
|
return new PagedResultDto<ItemTemplateDto>(totalCount, entdto);
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ItemTemplateDto> CreateAsync(CreateItemTemplateDto input)
|
|
{
|
|
var createEntity = ObjectMapper.Map<CreateItemTemplateDto, ItemTemplate>(input);
|
|
var entity = await _manager.CreateAsync(createEntity);
|
|
entity = await Repository.InsertAsync(entity);
|
|
var dto = ObjectMapper.Map<ItemTemplate, ItemTemplateDto>(entity);
|
|
return dto;
|
|
}
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ItemTemplateDto> UpdateAsync(Guid id, UpdateItemTemplateDto input)
|
|
{
|
|
var entity = await Repository.GetAsync(id);
|
|
var sourceEntity = ObjectMapper.Map<UpdateItemTemplateDto, ItemTemplate>(input);
|
|
await _manager.UpdateAsync(sourceEntity, entity);
|
|
entity = await Repository.UpdateAsync(entity);
|
|
return ObjectMapper.Map<ItemTemplate, ItemTemplateDto>(entity);
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public override async Task DeleteAsync(Guid id)
|
|
{
|
|
await _manager.CheckAndDeleteAsync(id);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 修改排序 置顶,置底
|
|
/// </summary>
|
|
/// <param name="id">需要修改的ID</param>
|
|
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
|
|
/// <returns></returns>
|
|
[HttpPut("api/app/itemtemplate/updatemanysort")]
|
|
public async Task UpdateManySortAsync(Guid id, int SortType)
|
|
{
|
|
await _manager.UpdateManySortAsync(id, SortType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改排序 拖拽
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("api/app/itemtemplate/updatesortmany")]
|
|
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
|
|
{
|
|
await _manager.UpdateSortManyAsync(input);
|
|
}
|
|
}
|
|
}
|